Mercurial > hg > graal-compiler
annotate src/share/vm/ci/ciInstanceKlass.cpp @ 3668:46f211fe010c
Removed global handle usage in ci interface.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Fri, 18 Nov 2011 13:30:47 +0100 |
parents | 75a99b4f1c98 |
children | 04b9a2566eec |
rev | line source |
---|---|
0 | 1 /* |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2244
diff
changeset
|
2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1142
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1142
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1142
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "ci/ciField.hpp" | |
27 #include "ci/ciInstance.hpp" | |
28 #include "ci/ciInstanceKlass.hpp" | |
29 #include "ci/ciUtilities.hpp" | |
30 #include "classfile/systemDictionary.hpp" | |
31 #include "memory/allocation.hpp" | |
32 #include "memory/allocation.inline.hpp" | |
33 #include "oops/oop.inline.hpp" | |
34 #include "runtime/fieldDescriptor.hpp" | |
0 | 35 |
36 // ciInstanceKlass | |
37 // | |
38 // This class represents a klassOop in the HotSpot virtual machine | |
39 // whose Klass part in an instanceKlass. | |
40 | |
41 // ------------------------------------------------------------------ | |
42 // ciInstanceKlass::ciInstanceKlass | |
43 // | |
44 // Loaded instance klass. | |
44
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
45 ciInstanceKlass::ciInstanceKlass(KlassHandle h_k) : |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
46 ciKlass(h_k), _non_static_fields(NULL) |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
47 { |
0 | 48 assert(get_Klass()->oop_is_instance(), "wrong type"); |
2244
4f26f535a225
6354181: nsk.logging.stress.threads.scmhml001 fails assertion in "src/share/vm/oops/instanceKlass.cpp, 111"
never
parents:
2177
diff
changeset
|
49 assert(get_instanceKlass()->is_loaded(), "must be at least loaded"); |
0 | 50 instanceKlass* ik = get_instanceKlass(); |
51 | |
52 AccessFlags access_flags = ik->access_flags(); | |
53 _flags = ciFlags(access_flags); | |
54 _has_finalizer = access_flags.has_finalizer(); | |
55 _has_subklass = ik->subklass() != NULL; | |
1645
3941674cc7fa
6958668: repeated uncommon trapping for new of klass which is being initialized
never
parents:
1604
diff
changeset
|
56 _init_state = (instanceKlass::ClassState)ik->get_init_state(); |
0 | 57 _nonstatic_field_size = ik->nonstatic_field_size(); |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
58 _has_nonstatic_fields = ik->has_nonstatic_fields(); |
0 | 59 _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields: |
60 | |
61 _nof_implementors = ik->nof_implementors(); | |
62 for (int i = 0; i < implementors_limit; i++) { | |
63 _implementors[i] = NULL; // we will fill these lazily | |
64 } | |
65 | |
66 Thread *thread = Thread::current(); | |
3668
46f211fe010c
Removed global handle usage in ci interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
2891
diff
changeset
|
67 if (ciObjectFactory::is_initialized()) { |
0 | 68 _loader = JNIHandles::make_local(thread, ik->class_loader()); |
1422
3483ec571caf
* using reflected objects instead of oops
Lukas Stadler <lukas.stadler@oracle.com>
parents:
1142
diff
changeset
|
69 _protection_domain = JNIHandles::make_local(thread, ik->protection_domain()); |
0 | 70 _is_shared = false; |
71 } else { | |
72 Handle h_loader(thread, ik->class_loader()); | |
73 Handle h_protection_domain(thread, ik->protection_domain()); | |
74 _loader = JNIHandles::make_global(h_loader); | |
75 _protection_domain = JNIHandles::make_global(h_protection_domain); | |
1478
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1422
diff
changeset
|
76 _is_shared = !ciObjectFactory::is_initialized(); |
0 | 77 } |
78 | |
79 // Lazy fields get filled in only upon request. | |
80 _super = NULL; | |
81 _java_mirror = NULL; | |
82 | |
83 if (is_shared()) { | |
1142 | 84 if (h_k() != SystemDictionary::Object_klass()) { |
0 | 85 super(); |
86 } | |
87 //compute_nonstatic_fields(); // done outside of constructor | |
88 } | |
89 | |
90 _field_cache = NULL; | |
91 } | |
92 | |
93 // Version for unloaded classes: | |
94 ciInstanceKlass::ciInstanceKlass(ciSymbol* name, | |
95 jobject loader, jobject protection_domain) | |
96 : ciKlass(name, ciInstanceKlassKlass::make()) | |
97 { | |
98 assert(name->byte_at(0) != '[', "not an instance klass"); | |
1645
3941674cc7fa
6958668: repeated uncommon trapping for new of klass which is being initialized
never
parents:
1604
diff
changeset
|
99 _init_state = (instanceKlass::ClassState)0; |
0 | 100 _nonstatic_field_size = -1; |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
101 _has_nonstatic_fields = false; |
0 | 102 _nonstatic_fields = NULL; |
103 _nof_implementors = -1; | |
104 _loader = loader; | |
105 _protection_domain = protection_domain; | |
106 _is_shared = false; | |
107 _super = NULL; | |
108 _java_mirror = NULL; | |
109 _field_cache = NULL; | |
110 } | |
111 | |
112 | |
113 | |
114 // ------------------------------------------------------------------ | |
115 // ciInstanceKlass::compute_shared_is_initialized | |
1645
3941674cc7fa
6958668: repeated uncommon trapping for new of klass which is being initialized
never
parents:
1604
diff
changeset
|
116 void ciInstanceKlass::compute_shared_init_state() { |
0 | 117 GUARDED_VM_ENTRY( |
118 instanceKlass* ik = get_instanceKlass(); | |
1645
3941674cc7fa
6958668: repeated uncommon trapping for new of klass which is being initialized
never
parents:
1604
diff
changeset
|
119 _init_state = (instanceKlass::ClassState)ik->get_init_state(); |
0 | 120 ) |
121 } | |
122 | |
123 // ------------------------------------------------------------------ | |
124 // ciInstanceKlass::compute_shared_has_subklass | |
125 bool ciInstanceKlass::compute_shared_has_subklass() { | |
126 GUARDED_VM_ENTRY( | |
127 instanceKlass* ik = get_instanceKlass(); | |
128 _has_subklass = ik->subklass() != NULL; | |
129 return _has_subklass; | |
130 ) | |
131 } | |
132 | |
133 // ------------------------------------------------------------------ | |
134 // ciInstanceKlass::compute_shared_nof_implementors | |
135 int ciInstanceKlass::compute_shared_nof_implementors() { | |
136 // We requery this property, since it is a very old ciObject. | |
137 GUARDED_VM_ENTRY( | |
138 instanceKlass* ik = get_instanceKlass(); | |
139 _nof_implementors = ik->nof_implementors(); | |
140 return _nof_implementors; | |
141 ) | |
142 } | |
143 | |
144 // ------------------------------------------------------------------ | |
145 // ciInstanceKlass::loader | |
146 oop ciInstanceKlass::loader() { | |
147 ASSERT_IN_VM; | |
148 return JNIHandles::resolve(_loader); | |
149 } | |
150 | |
151 // ------------------------------------------------------------------ | |
152 // ciInstanceKlass::loader_handle | |
153 jobject ciInstanceKlass::loader_handle() { | |
154 return _loader; | |
155 } | |
156 | |
157 // ------------------------------------------------------------------ | |
158 // ciInstanceKlass::protection_domain | |
159 oop ciInstanceKlass::protection_domain() { | |
160 ASSERT_IN_VM; | |
161 return JNIHandles::resolve(_protection_domain); | |
162 } | |
163 | |
164 // ------------------------------------------------------------------ | |
165 // ciInstanceKlass::protection_domain_handle | |
166 jobject ciInstanceKlass::protection_domain_handle() { | |
167 return _protection_domain; | |
168 } | |
169 | |
170 // ------------------------------------------------------------------ | |
171 // ciInstanceKlass::field_cache | |
172 // | |
173 // Get the field cache associated with this klass. | |
174 ciConstantPoolCache* ciInstanceKlass::field_cache() { | |
175 if (is_shared()) { | |
176 return NULL; | |
177 } | |
178 if (_field_cache == NULL) { | |
179 assert(!is_java_lang_Object(), "Object has no fields"); | |
180 Arena* arena = CURRENT_ENV->arena(); | |
181 _field_cache = new (arena) ciConstantPoolCache(arena, 5); | |
182 } | |
183 return _field_cache; | |
184 } | |
185 | |
186 // ------------------------------------------------------------------ | |
187 // ciInstanceKlass::get_canonical_holder | |
188 // | |
189 ciInstanceKlass* ciInstanceKlass::get_canonical_holder(int offset) { | |
190 #ifdef ASSERT | |
191 if (!(offset >= 0 && offset < layout_helper())) { | |
192 tty->print("*** get_canonical_holder(%d) on ", offset); | |
193 this->print(); | |
194 tty->print_cr(" ***"); | |
195 }; | |
196 assert(offset >= 0 && offset < layout_helper(), "offset must be tame"); | |
197 #endif | |
198 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
199 if (offset < instanceOopDesc::base_offset_in_bytes()) { |
0 | 200 // All header offsets belong properly to java/lang/Object. |
201 return CURRENT_ENV->Object_klass(); | |
202 } | |
203 | |
204 ciInstanceKlass* self = this; | |
205 for (;;) { | |
206 assert(self->is_loaded(), "must be loaded to have size"); | |
207 ciInstanceKlass* super = self->super(); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
208 if (super == NULL || super->nof_nonstatic_fields() == 0 || |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
209 !super->contains_field_offset(offset)) { |
0 | 210 return self; |
211 } else { | |
212 self = super; // return super->get_canonical_holder(offset) | |
213 } | |
214 } | |
215 } | |
216 | |
217 // ------------------------------------------------------------------ | |
218 // ciInstanceKlass::is_java_lang_Object | |
219 // | |
220 // Is this klass java.lang.Object? | |
221 bool ciInstanceKlass::is_java_lang_Object() { | |
222 return equals(CURRENT_ENV->Object_klass()); | |
223 } | |
224 | |
225 // ------------------------------------------------------------------ | |
226 // ciInstanceKlass::uses_default_loader | |
227 bool ciInstanceKlass::uses_default_loader() { | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
228 // Note: We do not need to resolve the handle or enter the VM |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
229 // in order to test null-ness. |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
230 return _loader == NULL; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
231 } |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
232 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
233 // ------------------------------------------------------------------ |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
234 // ciInstanceKlass::is_in_package |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
235 // |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
236 // Is this klass in the given package? |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
237 bool ciInstanceKlass::is_in_package(const char* packagename, int len) { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
238 // To avoid class loader mischief, this test always rejects application classes. |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
239 if (!uses_default_loader()) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
240 return false; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
241 GUARDED_VM_ENTRY( |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
242 return is_in_package_impl(packagename, len); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
243 ) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
244 } |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
245 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
246 bool ciInstanceKlass::is_in_package_impl(const char* packagename, int len) { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
247 ASSERT_IN_VM; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
248 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
249 // If packagename contains trailing '/' exclude it from the |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
250 // prefix-test since we test for it explicitly. |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
251 if (packagename[len - 1] == '/') |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
252 len--; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
253 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
254 if (!name()->starts_with(packagename, len)) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
255 return false; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
256 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
257 // Test if the class name is something like "java/lang". |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
258 if ((len + 1) > name()->utf8_length()) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
259 return false; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
260 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
261 // Test for trailing '/' |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
262 if ((char) name()->byte_at(len) != '/') |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
263 return false; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
264 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
265 // Make sure it's not actually in a subpackage: |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
266 if (name()->index_of_at(len+1, "/", 1) >= 0) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
267 return false; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
268 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1080
diff
changeset
|
269 return true; |
0 | 270 } |
271 | |
272 // ------------------------------------------------------------------ | |
273 // ciInstanceKlass::print_impl | |
274 // | |
275 // Implementation of the print method. | |
276 void ciInstanceKlass::print_impl(outputStream* st) { | |
277 ciKlass::print_impl(st); | |
278 GUARDED_VM_ENTRY(st->print(" loader=0x%x", (address)loader());) | |
279 if (is_loaded()) { | |
280 st->print(" loaded=true initialized=%s finalized=%s subklass=%s size=%d flags=", | |
281 bool_to_str(is_initialized()), | |
282 bool_to_str(has_finalizer()), | |
283 bool_to_str(has_subklass()), | |
284 layout_helper()); | |
285 | |
286 _flags.print_klass_flags(); | |
287 | |
288 if (_super) { | |
289 st->print(" super="); | |
290 _super->print_name(); | |
291 } | |
292 if (_java_mirror) { | |
293 st->print(" mirror=PRESENT"); | |
294 } | |
295 } else { | |
296 st->print(" loaded=false"); | |
297 } | |
298 } | |
299 | |
300 // ------------------------------------------------------------------ | |
301 // ciInstanceKlass::super | |
302 // | |
303 // Get the superklass of this klass. | |
304 ciInstanceKlass* ciInstanceKlass::super() { | |
305 assert(is_loaded(), "must be loaded"); | |
306 if (_super == NULL && !is_java_lang_Object()) { | |
307 GUARDED_VM_ENTRY( | |
308 klassOop super_klass = get_instanceKlass()->super(); | |
309 _super = CURRENT_ENV->get_object(super_klass)->as_instance_klass(); | |
310 ) | |
311 } | |
312 return _super; | |
313 } | |
314 | |
315 // ------------------------------------------------------------------ | |
316 // ciInstanceKlass::java_mirror | |
317 // | |
318 // Get the instance of java.lang.Class corresponding to this klass. | |
1604
b918d354830a
6960865: ldc of unloaded class throws an assert in ciTypeFlow
jrose
parents:
1602
diff
changeset
|
319 // Cache it on this->_java_mirror. |
0 | 320 ciInstance* ciInstanceKlass::java_mirror() { |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2244
diff
changeset
|
321 if (is_shared()) { |
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2244
diff
changeset
|
322 return ciKlass::java_mirror(); |
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2244
diff
changeset
|
323 } |
0 | 324 if (_java_mirror == NULL) { |
1604
b918d354830a
6960865: ldc of unloaded class throws an assert in ciTypeFlow
jrose
parents:
1602
diff
changeset
|
325 _java_mirror = ciKlass::java_mirror(); |
0 | 326 } |
327 return _java_mirror; | |
328 } | |
329 | |
330 // ------------------------------------------------------------------ | |
331 // ciInstanceKlass::unique_concrete_subklass | |
332 ciInstanceKlass* ciInstanceKlass::unique_concrete_subklass() { | |
333 if (!is_loaded()) return NULL; // No change if class is not loaded | |
334 if (!is_abstract()) return NULL; // Only applies to abstract classes. | |
335 if (!has_subklass()) return NULL; // Must have at least one subklass. | |
336 VM_ENTRY_MARK; | |
337 instanceKlass* ik = get_instanceKlass(); | |
338 Klass* up = ik->up_cast_abstract(); | |
339 assert(up->oop_is_instance(), "must be instanceKlass"); | |
340 if (ik == up) { | |
341 return NULL; | |
342 } | |
343 return CURRENT_THREAD_ENV->get_object(up->as_klassOop())->as_instance_klass(); | |
344 } | |
345 | |
346 // ------------------------------------------------------------------ | |
347 // ciInstanceKlass::has_finalizable_subclass | |
348 bool ciInstanceKlass::has_finalizable_subclass() { | |
349 if (!is_loaded()) return true; | |
350 VM_ENTRY_MARK; | |
351 return Dependencies::find_finalizable_subclass(get_instanceKlass()) != NULL; | |
352 } | |
353 | |
354 // ------------------------------------------------------------------ | |
355 // ciInstanceKlass::get_field_by_offset | |
356 ciField* ciInstanceKlass::get_field_by_offset(int field_offset, bool is_static) { | |
357 if (!is_static) { | |
358 for (int i = 0, len = nof_nonstatic_fields(); i < len; i++) { | |
359 ciField* field = _nonstatic_fields->at(i); | |
360 int field_off = field->offset_in_bytes(); | |
361 if (field_off == field_offset) | |
362 return field; | |
363 if (field_off > field_offset) | |
364 break; | |
365 // could do binary search or check bins, but probably not worth it | |
366 } | |
367 return NULL; | |
368 } | |
369 VM_ENTRY_MARK; | |
370 instanceKlass* k = get_instanceKlass(); | |
371 fieldDescriptor fd; | |
372 if (!k->find_field_from_offset(field_offset, is_static, &fd)) { | |
373 return NULL; | |
374 } | |
375 ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd); | |
376 return field; | |
377 } | |
378 | |
44
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
379 // ------------------------------------------------------------------ |
1080
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
380 // ciInstanceKlass::get_field_by_name |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
381 ciField* ciInstanceKlass::get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static) { |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
382 VM_ENTRY_MARK; |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
383 instanceKlass* k = get_instanceKlass(); |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
384 fieldDescriptor fd; |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
385 klassOop def = k->find_field(name->get_symbol(), signature->get_symbol(), is_static, &fd); |
1080
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
386 if (def == NULL) { |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
387 return NULL; |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
388 } |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
389 ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd); |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
390 return field; |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
391 } |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
392 |
7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
never
parents:
196
diff
changeset
|
393 // ------------------------------------------------------------------ |
44
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
394 // ciInstanceKlass::non_static_fields. |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
395 |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
396 class NonStaticFieldFiller: public FieldClosure { |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
397 GrowableArray<ciField*>* _arr; |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
398 ciEnv* _curEnv; |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
399 public: |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
400 NonStaticFieldFiller(ciEnv* curEnv, GrowableArray<ciField*>* arr) : |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
401 _curEnv(curEnv), _arr(arr) |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
402 {} |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
403 void do_field(fieldDescriptor* fd) { |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
404 ciField* field = new (_curEnv->arena()) ciField(fd); |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
405 _arr->append(field); |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
406 } |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
407 }; |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
408 |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
409 GrowableArray<ciField*>* ciInstanceKlass::non_static_fields() { |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
410 if (_non_static_fields == NULL) { |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
411 VM_ENTRY_MARK; |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
412 ciEnv* curEnv = ciEnv::current(); |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
413 instanceKlass* ik = get_instanceKlass(); |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
414 int max_n_fields = ik->fields()->length()/instanceKlass::next_offset; |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
415 |
1685 | 416 Arena* arena = curEnv->arena(); |
44
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
417 _non_static_fields = |
1685 | 418 new (arena) GrowableArray<ciField*>(arena, max_n_fields, 0, NULL); |
44
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
419 NonStaticFieldFiller filler(curEnv, _non_static_fields); |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
420 ik->do_nonstatic_fields(&filler); |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
421 } |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
422 return _non_static_fields; |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
423 } |
52fed2ec0afb
6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents:
0
diff
changeset
|
424 |
0 | 425 static int sort_field_by_offset(ciField** a, ciField** b) { |
426 return (*a)->offset_in_bytes() - (*b)->offset_in_bytes(); | |
427 // (no worries about 32-bit overflow...) | |
428 } | |
429 | |
430 // ------------------------------------------------------------------ | |
431 // ciInstanceKlass::compute_nonstatic_fields | |
432 int ciInstanceKlass::compute_nonstatic_fields() { | |
433 assert(is_loaded(), "must be loaded"); | |
434 | |
435 if (_nonstatic_fields != NULL) | |
436 return _nonstatic_fields->length(); | |
437 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
438 if (!has_nonstatic_fields()) { |
0 | 439 Arena* arena = CURRENT_ENV->arena(); |
440 _nonstatic_fields = new (arena) GrowableArray<ciField*>(arena, 0, 0, NULL); | |
441 return 0; | |
442 } | |
443 assert(!is_java_lang_Object(), "bootstrap OK"); | |
444 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
445 // Size in bytes of my fields, including inherited fields. |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
113
diff
changeset
|
446 int fsize = nonstatic_field_size() * heapOopSize; |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
447 |
0 | 448 ciInstanceKlass* super = this->super(); |
449 GrowableArray<ciField*>* super_fields = NULL; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
450 if (super != NULL && super->has_nonstatic_fields()) { |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
113
diff
changeset
|
451 int super_fsize = super->nonstatic_field_size() * heapOopSize; |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
452 int super_flen = super->nof_nonstatic_fields(); |
0 | 453 super_fields = super->_nonstatic_fields; |
454 assert(super_flen == 0 || super_fields != NULL, "first get nof_fields"); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
455 // See if I am no larger than my super; if so, I can use his fields. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
456 if (fsize == super_fsize) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
457 _nonstatic_fields = super_fields; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
458 return super_fields->length(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
459 } |
0 | 460 } |
461 | |
462 GrowableArray<ciField*>* fields = NULL; | |
463 GUARDED_VM_ENTRY({ | |
464 fields = compute_nonstatic_fields_impl(super_fields); | |
465 }); | |
466 | |
467 if (fields == NULL) { | |
468 // This can happen if this class (java.lang.Class) has invisible fields. | |
469 _nonstatic_fields = super_fields; | |
470 return super_fields->length(); | |
471 } | |
472 | |
473 int flen = fields->length(); | |
474 | |
475 // Now sort them by offset, ascending. | |
476 // (In principle, they could mix with superclass fields.) | |
477 fields->sort(sort_field_by_offset); | |
478 #ifdef ASSERT | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
479 int last_offset = instanceOopDesc::base_offset_in_bytes(); |
0 | 480 for (int i = 0; i < fields->length(); i++) { |
481 ciField* field = fields->at(i); | |
482 int offset = field->offset_in_bytes(); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
44
diff
changeset
|
483 int size = (field->_type == NULL) ? heapOopSize : field->size_in_bytes(); |
1846 | 484 assert(last_offset <= offset, err_msg("no field overlap: %d <= %d", last_offset, offset)); |
0 | 485 if (last_offset > (int)sizeof(oopDesc)) |
486 assert((offset - last_offset) < BytesPerLong, "no big holes"); | |
487 // Note: Two consecutive T_BYTE fields will be separated by wordSize-1 | |
488 // padding bytes if one of them is declared by a superclass. | |
489 // This is a minor inefficiency classFileParser.cpp. | |
490 last_offset = offset + size; | |
491 } | |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
113
diff
changeset
|
492 assert(last_offset <= (int)instanceOopDesc::base_offset_in_bytes() + fsize, "no overflow"); |
0 | 493 #endif |
494 | |
495 _nonstatic_fields = fields; | |
496 return flen; | |
497 } | |
498 | |
499 GrowableArray<ciField*>* | |
500 ciInstanceKlass::compute_nonstatic_fields_impl(GrowableArray<ciField*>* | |
501 super_fields) { | |
502 ASSERT_IN_VM; | |
503 Arena* arena = CURRENT_ENV->arena(); | |
504 int flen = 0; | |
505 GrowableArray<ciField*>* fields = NULL; | |
506 instanceKlass* k = get_instanceKlass(); | |
507 typeArrayOop fields_array = k->fields(); | |
508 for (int pass = 0; pass <= 1; pass++) { | |
509 for (int i = 0, alen = fields_array->length(); i < alen; i += instanceKlass::next_offset) { | |
510 fieldDescriptor fd; | |
511 fd.initialize(k->as_klassOop(), i); | |
512 if (fd.is_static()) continue; | |
513 if (pass == 0) { | |
514 flen += 1; | |
515 } else { | |
516 ciField* field = new (arena) ciField(&fd); | |
517 fields->append(field); | |
518 } | |
519 } | |
520 | |
521 // Between passes, allocate the array: | |
522 if (pass == 0) { | |
523 if (flen == 0) { | |
524 return NULL; // return nothing if none are locally declared | |
525 } | |
526 if (super_fields != NULL) { | |
527 flen += super_fields->length(); | |
528 } | |
529 fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, NULL); | |
530 if (super_fields != NULL) { | |
531 fields->appendAll(super_fields); | |
532 } | |
533 } | |
534 } | |
535 assert(fields->length() == flen, "sanity"); | |
536 return fields; | |
537 } | |
538 | |
539 // ------------------------------------------------------------------ | |
540 // ciInstanceKlass::find_method | |
541 // | |
542 // Find a method in this klass. | |
543 ciMethod* ciInstanceKlass::find_method(ciSymbol* name, ciSymbol* signature) { | |
544 VM_ENTRY_MARK; | |
545 instanceKlass* k = get_instanceKlass(); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
546 Symbol* name_sym = name->get_symbol(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
547 Symbol* sig_sym= signature->get_symbol(); |
0 | 548 |
549 methodOop m = k->find_method(name_sym, sig_sym); | |
550 if (m == NULL) return NULL; | |
551 | |
552 return CURRENT_THREAD_ENV->get_object(m)->as_method(); | |
553 } | |
554 | |
555 // ------------------------------------------------------------------ | |
556 // ciInstanceKlass::is_leaf_type | |
557 bool ciInstanceKlass::is_leaf_type() { | |
558 assert(is_loaded(), "must be loaded"); | |
559 if (is_shared()) { | |
560 return is_final(); // approximately correct | |
561 } else { | |
562 return !_has_subklass && (_nof_implementors == 0); | |
563 } | |
564 } | |
565 | |
566 // ------------------------------------------------------------------ | |
567 // ciInstanceKlass::implementor | |
568 // | |
569 // Report an implementor of this interface. | |
570 // Returns NULL if exact information is not available. | |
571 // Note that there are various races here, since my copy | |
572 // of _nof_implementors might be out of date with respect | |
573 // to results returned by instanceKlass::implementor. | |
574 // This is OK, since any dependencies we decide to assert | |
575 // will be checked later under the Compile_lock. | |
576 ciInstanceKlass* ciInstanceKlass::implementor(int n) { | |
1924 | 577 if (n >= implementors_limit) { |
0 | 578 return NULL; |
579 } | |
580 ciInstanceKlass* impl = _implementors[n]; | |
581 if (impl == NULL) { | |
582 if (_nof_implementors > implementors_limit) { | |
583 return NULL; | |
584 } | |
585 // Go into the VM to fetch the implementor. | |
586 { | |
587 VM_ENTRY_MARK; | |
588 klassOop k = get_instanceKlass()->implementor(n); | |
589 if (k != NULL) { | |
590 impl = CURRENT_THREAD_ENV->get_object(k)->as_instance_klass(); | |
591 } | |
592 } | |
593 // Memoize this result. | |
594 if (!is_shared()) { | |
595 _implementors[n] = (impl == NULL)? this: impl; | |
596 } | |
597 } else if (impl == this) { | |
598 impl = NULL; // memoized null result from a VM query | |
599 } | |
600 return impl; | |
601 } |