Thu, 12 Nov 2009 09:24:21 -0800
6892658: C2 should optimize some stringbuilder patterns
Reviewed-by: kvn, twisti
1 /*
2 * Copyright 1999-2008 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
25 // ciInstanceKlass
26 //
27 // This class represents a klassOop in the HotSpot virtual machine
28 // whose Klass part is an instanceKlass. It may or may not
29 // be loaded.
30 class ciInstanceKlass : public ciKlass {
31 CI_PACKAGE_ACCESS
32 friend class ciEnv;
33 friend class ciMethod;
34 friend class ciField;
35 friend class ciBytecodeStream;
37 private:
38 jobject _loader;
39 jobject _protection_domain;
41 bool _is_shared;
42 bool _is_initialized;
43 bool _is_linked;
44 bool _has_finalizer;
45 bool _has_subklass;
46 bool _has_nonstatic_fields;
48 ciFlags _flags;
49 jint _nonstatic_field_size;
50 jint _nonstatic_oop_map_size;
52 // Lazy fields get filled in only upon request.
53 ciInstanceKlass* _super;
54 ciInstance* _java_mirror;
56 ciConstantPoolCache* _field_cache; // cached map index->field
57 GrowableArray<ciField*>* _nonstatic_fields;
59 enum { implementors_limit = instanceKlass::implementors_limit };
60 ciInstanceKlass* _implementors[implementors_limit];
61 jint _nof_implementors;
63 GrowableArray<ciField*>* _non_static_fields;
65 protected:
66 ciInstanceKlass(KlassHandle h_k);
67 ciInstanceKlass(ciSymbol* name, jobject loader, jobject protection_domain);
69 instanceKlass* get_instanceKlass() const {
70 return (instanceKlass*)get_Klass();
71 }
73 oop loader();
74 jobject loader_handle();
76 oop protection_domain();
77 jobject protection_domain_handle();
79 const char* type_string() { return "ciInstanceKlass"; }
81 void print_impl(outputStream* st);
83 ciConstantPoolCache* field_cache();
85 bool is_shared() { return _is_shared; }
87 bool compute_shared_is_initialized();
88 bool compute_shared_is_linked();
89 bool compute_shared_has_subklass();
90 int compute_shared_nof_implementors();
91 int compute_nonstatic_fields();
92 GrowableArray<ciField*>* compute_nonstatic_fields_impl(GrowableArray<ciField*>* super_fields);
94 public:
95 // Has this klass been initialized?
96 bool is_initialized() {
97 if (_is_shared && !_is_initialized) {
98 return is_loaded() && compute_shared_is_initialized();
99 }
100 return _is_initialized;
101 }
102 // Has this klass been linked?
103 bool is_linked() {
104 if (_is_shared && !_is_linked) {
105 return is_loaded() && compute_shared_is_linked();
106 }
107 return _is_linked;
108 }
110 // General klass information.
111 ciFlags flags() {
112 assert(is_loaded(), "must be loaded");
113 return _flags;
114 }
115 bool has_finalizer() {
116 assert(is_loaded(), "must be loaded");
117 return _has_finalizer; }
118 bool has_subklass() {
119 assert(is_loaded(), "must be loaded");
120 if (_is_shared && !_has_subklass) {
121 if (flags().is_final()) {
122 return false;
123 } else {
124 return compute_shared_has_subklass();
125 }
126 }
127 return _has_subklass;
128 }
129 jint size_helper() {
130 return (Klass::layout_helper_size_in_bytes(layout_helper())
131 >> LogHeapWordSize);
132 }
133 jint nonstatic_field_size() {
134 assert(is_loaded(), "must be loaded");
135 return _nonstatic_field_size; }
136 jint has_nonstatic_fields() {
137 assert(is_loaded(), "must be loaded");
138 return _has_nonstatic_fields; }
139 jint nonstatic_oop_map_size() {
140 assert(is_loaded(), "must be loaded");
141 return _nonstatic_oop_map_size; }
142 ciInstanceKlass* super();
143 jint nof_implementors() {
144 assert(is_loaded(), "must be loaded");
145 if (_is_shared) return compute_shared_nof_implementors();
146 return _nof_implementors;
147 }
149 ciInstanceKlass* get_canonical_holder(int offset);
150 ciField* get_field_by_offset(int field_offset, bool is_static);
151 ciField* get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static);
153 GrowableArray<ciField*>* non_static_fields();
155 // total number of nonstatic fields (including inherited):
156 int nof_nonstatic_fields() {
157 if (_nonstatic_fields == NULL)
158 return compute_nonstatic_fields();
159 else
160 return _nonstatic_fields->length();
161 }
162 // nth nonstatic field (presented by ascending address)
163 ciField* nonstatic_field_at(int i) {
164 assert(_nonstatic_fields != NULL, "");
165 return _nonstatic_fields->at(i);
166 }
168 ciInstanceKlass* unique_concrete_subklass();
169 bool has_finalizable_subclass();
171 bool contains_field_offset(int offset) {
172 return instanceOopDesc::contains_field_offset(offset, nonstatic_field_size());
173 }
175 // Get the instance of java.lang.Class corresponding to
176 // this klass. This instance is used for locking of
177 // synchronized static methods of this klass.
178 ciInstance* java_mirror();
180 // Java access flags
181 bool is_public () { return flags().is_public(); }
182 bool is_final () { return flags().is_final(); }
183 bool is_super () { return flags().is_super(); }
184 bool is_interface () { return flags().is_interface(); }
185 bool is_abstract () { return flags().is_abstract(); }
187 ciMethod* find_method(ciSymbol* name, ciSymbol* signature);
188 // Note: To find a method from name and type strings, use ciSymbol::make,
189 // but consider adding to vmSymbols.hpp instead.
191 bool is_leaf_type();
192 ciInstanceKlass* implementor(int n);
194 // Is the defining class loader of this class the default loader?
195 bool uses_default_loader();
197 bool is_java_lang_Object();
199 // What kind of ciObject is this?
200 bool is_instance_klass() { return true; }
201 bool is_java_klass() { return true; }
202 };