|
1 /* |
|
2 * Copyright (c) 1999, 2017, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 * |
|
23 */ |
|
24 |
|
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 "memory/resourceArea.hpp" |
|
34 #include "oops/oop.inline.hpp" |
|
35 #include "oops/fieldStreams.hpp" |
|
36 #include "runtime/fieldDescriptor.hpp" |
|
37 |
|
38 // ciInstanceKlass |
|
39 // |
|
40 // This class represents a Klass* in the HotSpot virtual machine |
|
41 // whose Klass part in an InstanceKlass. |
|
42 |
|
43 // ------------------------------------------------------------------ |
|
44 // ciInstanceKlass::ciInstanceKlass |
|
45 // |
|
46 // Loaded instance klass. |
|
47 ciInstanceKlass::ciInstanceKlass(Klass* k) : |
|
48 ciKlass(k) |
|
49 { |
|
50 assert(get_Klass()->is_instance_klass(), "wrong type"); |
|
51 assert(get_instanceKlass()->is_loaded(), "must be at least loaded"); |
|
52 InstanceKlass* ik = get_instanceKlass(); |
|
53 |
|
54 AccessFlags access_flags = ik->access_flags(); |
|
55 _flags = ciFlags(access_flags); |
|
56 _has_finalizer = access_flags.has_finalizer(); |
|
57 _has_subklass = ik->subklass() != NULL; |
|
58 _init_state = ik->init_state(); |
|
59 _nonstatic_field_size = ik->nonstatic_field_size(); |
|
60 _has_nonstatic_fields = ik->has_nonstatic_fields(); |
|
61 _has_nonstatic_concrete_methods = ik->has_nonstatic_concrete_methods(); |
|
62 _is_anonymous = ik->is_anonymous(); |
|
63 _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields: |
|
64 _has_injected_fields = -1; |
|
65 _implementor = NULL; // we will fill these lazily |
|
66 |
|
67 Thread *thread = Thread::current(); |
|
68 if (ciObjectFactory::is_initialized()) { |
|
69 _loader = JNIHandles::make_local(thread, ik->class_loader()); |
|
70 _protection_domain = JNIHandles::make_local(thread, |
|
71 ik->protection_domain()); |
|
72 _is_shared = false; |
|
73 } else { |
|
74 Handle h_loader(thread, ik->class_loader()); |
|
75 Handle h_protection_domain(thread, ik->protection_domain()); |
|
76 _loader = JNIHandles::make_global(h_loader); |
|
77 _protection_domain = JNIHandles::make_global(h_protection_domain); |
|
78 _is_shared = true; |
|
79 } |
|
80 |
|
81 // Lazy fields get filled in only upon request. |
|
82 _super = NULL; |
|
83 _java_mirror = NULL; |
|
84 |
|
85 if (is_shared()) { |
|
86 if (k != SystemDictionary::Object_klass()) { |
|
87 super(); |
|
88 } |
|
89 //compute_nonstatic_fields(); // done outside of constructor |
|
90 } |
|
91 |
|
92 _field_cache = NULL; |
|
93 } |
|
94 |
|
95 // Version for unloaded classes: |
|
96 ciInstanceKlass::ciInstanceKlass(ciSymbol* name, |
|
97 jobject loader, jobject protection_domain) |
|
98 : ciKlass(name, T_OBJECT) |
|
99 { |
|
100 assert(name->byte_at(0) != '[', "not an instance klass"); |
|
101 _init_state = (InstanceKlass::ClassState)0; |
|
102 _nonstatic_field_size = -1; |
|
103 _has_nonstatic_fields = false; |
|
104 _nonstatic_fields = NULL; |
|
105 _has_injected_fields = -1; |
|
106 _is_anonymous = false; |
|
107 _loader = loader; |
|
108 _protection_domain = protection_domain; |
|
109 _is_shared = false; |
|
110 _super = NULL; |
|
111 _java_mirror = NULL; |
|
112 _field_cache = NULL; |
|
113 } |
|
114 |
|
115 |
|
116 |
|
117 // ------------------------------------------------------------------ |
|
118 // ciInstanceKlass::compute_shared_is_initialized |
|
119 void ciInstanceKlass::compute_shared_init_state() { |
|
120 GUARDED_VM_ENTRY( |
|
121 InstanceKlass* ik = get_instanceKlass(); |
|
122 _init_state = ik->init_state(); |
|
123 ) |
|
124 } |
|
125 |
|
126 // ------------------------------------------------------------------ |
|
127 // ciInstanceKlass::compute_shared_has_subklass |
|
128 bool ciInstanceKlass::compute_shared_has_subklass() { |
|
129 GUARDED_VM_ENTRY( |
|
130 InstanceKlass* ik = get_instanceKlass(); |
|
131 _has_subklass = ik->subklass() != NULL; |
|
132 return _has_subklass; |
|
133 ) |
|
134 } |
|
135 |
|
136 // ------------------------------------------------------------------ |
|
137 // ciInstanceKlass::loader |
|
138 oop ciInstanceKlass::loader() { |
|
139 ASSERT_IN_VM; |
|
140 return JNIHandles::resolve(_loader); |
|
141 } |
|
142 |
|
143 // ------------------------------------------------------------------ |
|
144 // ciInstanceKlass::loader_handle |
|
145 jobject ciInstanceKlass::loader_handle() { |
|
146 return _loader; |
|
147 } |
|
148 |
|
149 // ------------------------------------------------------------------ |
|
150 // ciInstanceKlass::protection_domain |
|
151 oop ciInstanceKlass::protection_domain() { |
|
152 ASSERT_IN_VM; |
|
153 return JNIHandles::resolve(_protection_domain); |
|
154 } |
|
155 |
|
156 // ------------------------------------------------------------------ |
|
157 // ciInstanceKlass::protection_domain_handle |
|
158 jobject ciInstanceKlass::protection_domain_handle() { |
|
159 return _protection_domain; |
|
160 } |
|
161 |
|
162 // ------------------------------------------------------------------ |
|
163 // ciInstanceKlass::field_cache |
|
164 // |
|
165 // Get the field cache associated with this klass. |
|
166 ciConstantPoolCache* ciInstanceKlass::field_cache() { |
|
167 if (is_shared()) { |
|
168 return NULL; |
|
169 } |
|
170 if (_field_cache == NULL) { |
|
171 assert(!is_java_lang_Object(), "Object has no fields"); |
|
172 Arena* arena = CURRENT_ENV->arena(); |
|
173 _field_cache = new (arena) ciConstantPoolCache(arena, 5); |
|
174 } |
|
175 return _field_cache; |
|
176 } |
|
177 |
|
178 // ------------------------------------------------------------------ |
|
179 // ciInstanceKlass::get_canonical_holder |
|
180 // |
|
181 ciInstanceKlass* ciInstanceKlass::get_canonical_holder(int offset) { |
|
182 #ifdef ASSERT |
|
183 if (!(offset >= 0 && offset < layout_helper())) { |
|
184 tty->print("*** get_canonical_holder(%d) on ", offset); |
|
185 this->print(); |
|
186 tty->print_cr(" ***"); |
|
187 }; |
|
188 assert(offset >= 0 && offset < layout_helper(), "offset must be tame"); |
|
189 #endif |
|
190 |
|
191 if (offset < instanceOopDesc::base_offset_in_bytes()) { |
|
192 // All header offsets belong properly to java/lang/Object. |
|
193 return CURRENT_ENV->Object_klass(); |
|
194 } |
|
195 |
|
196 ciInstanceKlass* self = this; |
|
197 for (;;) { |
|
198 assert(self->is_loaded(), "must be loaded to have size"); |
|
199 ciInstanceKlass* super = self->super(); |
|
200 if (super == NULL || super->nof_nonstatic_fields() == 0 || |
|
201 !super->contains_field_offset(offset)) { |
|
202 return self; |
|
203 } else { |
|
204 self = super; // return super->get_canonical_holder(offset) |
|
205 } |
|
206 } |
|
207 } |
|
208 |
|
209 // ------------------------------------------------------------------ |
|
210 // ciInstanceKlass::is_java_lang_Object |
|
211 // |
|
212 // Is this klass java.lang.Object? |
|
213 bool ciInstanceKlass::is_java_lang_Object() const { |
|
214 return equals(CURRENT_ENV->Object_klass()); |
|
215 } |
|
216 |
|
217 // ------------------------------------------------------------------ |
|
218 // ciInstanceKlass::uses_default_loader |
|
219 bool ciInstanceKlass::uses_default_loader() const { |
|
220 // Note: We do not need to resolve the handle or enter the VM |
|
221 // in order to test null-ness. |
|
222 return _loader == NULL; |
|
223 } |
|
224 |
|
225 // ------------------------------------------------------------------ |
|
226 |
|
227 /** |
|
228 * Return basic type of boxed value for box klass or T_OBJECT if not. |
|
229 */ |
|
230 BasicType ciInstanceKlass::box_klass_type() const { |
|
231 if (uses_default_loader() && is_loaded()) { |
|
232 return SystemDictionary::box_klass_type(get_Klass()); |
|
233 } else { |
|
234 return T_OBJECT; |
|
235 } |
|
236 } |
|
237 |
|
238 /** |
|
239 * Is this boxing klass? |
|
240 */ |
|
241 bool ciInstanceKlass::is_box_klass() const { |
|
242 return is_java_primitive(box_klass_type()); |
|
243 } |
|
244 |
|
245 /** |
|
246 * Is this boxed value offset? |
|
247 */ |
|
248 bool ciInstanceKlass::is_boxed_value_offset(int offset) const { |
|
249 BasicType bt = box_klass_type(); |
|
250 return is_java_primitive(bt) && |
|
251 (offset == java_lang_boxing_object::value_offset_in_bytes(bt)); |
|
252 } |
|
253 |
|
254 // ------------------------------------------------------------------ |
|
255 // ciInstanceKlass::is_in_package |
|
256 // |
|
257 // Is this klass in the given package? |
|
258 bool ciInstanceKlass::is_in_package(const char* packagename, int len) { |
|
259 // To avoid class loader mischief, this test always rejects application classes. |
|
260 if (!uses_default_loader()) |
|
261 return false; |
|
262 GUARDED_VM_ENTRY( |
|
263 return is_in_package_impl(packagename, len); |
|
264 ) |
|
265 } |
|
266 |
|
267 bool ciInstanceKlass::is_in_package_impl(const char* packagename, int len) { |
|
268 ASSERT_IN_VM; |
|
269 |
|
270 // If packagename contains trailing '/' exclude it from the |
|
271 // prefix-test since we test for it explicitly. |
|
272 if (packagename[len - 1] == '/') |
|
273 len--; |
|
274 |
|
275 if (!name()->starts_with(packagename, len)) |
|
276 return false; |
|
277 |
|
278 // Test if the class name is something like "java/lang". |
|
279 if ((len + 1) > name()->utf8_length()) |
|
280 return false; |
|
281 |
|
282 // Test for trailing '/' |
|
283 if ((char) name()->byte_at(len) != '/') |
|
284 return false; |
|
285 |
|
286 // Make sure it's not actually in a subpackage: |
|
287 if (name()->index_of_at(len+1, "/", 1) >= 0) |
|
288 return false; |
|
289 |
|
290 return true; |
|
291 } |
|
292 |
|
293 // ------------------------------------------------------------------ |
|
294 // ciInstanceKlass::print_impl |
|
295 // |
|
296 // Implementation of the print method. |
|
297 void ciInstanceKlass::print_impl(outputStream* st) { |
|
298 ciKlass::print_impl(st); |
|
299 GUARDED_VM_ENTRY(st->print(" loader=" INTPTR_FORMAT, p2i((address)loader()));) |
|
300 if (is_loaded()) { |
|
301 st->print(" loaded=true initialized=%s finalized=%s subklass=%s size=%d flags=", |
|
302 bool_to_str(is_initialized()), |
|
303 bool_to_str(has_finalizer()), |
|
304 bool_to_str(has_subklass()), |
|
305 layout_helper()); |
|
306 |
|
307 _flags.print_klass_flags(); |
|
308 |
|
309 if (_super) { |
|
310 st->print(" super="); |
|
311 _super->print_name(); |
|
312 } |
|
313 if (_java_mirror) { |
|
314 st->print(" mirror=PRESENT"); |
|
315 } |
|
316 } else { |
|
317 st->print(" loaded=false"); |
|
318 } |
|
319 } |
|
320 |
|
321 // ------------------------------------------------------------------ |
|
322 // ciInstanceKlass::super |
|
323 // |
|
324 // Get the superklass of this klass. |
|
325 ciInstanceKlass* ciInstanceKlass::super() { |
|
326 assert(is_loaded(), "must be loaded"); |
|
327 if (_super == NULL && !is_java_lang_Object()) { |
|
328 GUARDED_VM_ENTRY( |
|
329 Klass* super_klass = get_instanceKlass()->super(); |
|
330 _super = CURRENT_ENV->get_instance_klass(super_klass); |
|
331 ) |
|
332 } |
|
333 return _super; |
|
334 } |
|
335 |
|
336 // ------------------------------------------------------------------ |
|
337 // ciInstanceKlass::java_mirror |
|
338 // |
|
339 // Get the instance of java.lang.Class corresponding to this klass. |
|
340 // Cache it on this->_java_mirror. |
|
341 ciInstance* ciInstanceKlass::java_mirror() { |
|
342 if (is_shared()) { |
|
343 return ciKlass::java_mirror(); |
|
344 } |
|
345 if (_java_mirror == NULL) { |
|
346 _java_mirror = ciKlass::java_mirror(); |
|
347 } |
|
348 return _java_mirror; |
|
349 } |
|
350 |
|
351 // ------------------------------------------------------------------ |
|
352 // ciInstanceKlass::unique_concrete_subklass |
|
353 ciInstanceKlass* ciInstanceKlass::unique_concrete_subklass() { |
|
354 if (!is_loaded()) return NULL; // No change if class is not loaded |
|
355 if (!is_abstract()) return NULL; // Only applies to abstract classes. |
|
356 if (!has_subklass()) return NULL; // Must have at least one subklass. |
|
357 VM_ENTRY_MARK; |
|
358 InstanceKlass* ik = get_instanceKlass(); |
|
359 Klass* up = ik->up_cast_abstract(); |
|
360 assert(up->is_instance_klass(), "must be InstanceKlass"); |
|
361 if (ik == up) { |
|
362 return NULL; |
|
363 } |
|
364 return CURRENT_THREAD_ENV->get_instance_klass(up); |
|
365 } |
|
366 |
|
367 // ------------------------------------------------------------------ |
|
368 // ciInstanceKlass::has_finalizable_subclass |
|
369 bool ciInstanceKlass::has_finalizable_subclass() { |
|
370 if (!is_loaded()) return true; |
|
371 VM_ENTRY_MARK; |
|
372 return Dependencies::find_finalizable_subclass(get_instanceKlass()) != NULL; |
|
373 } |
|
374 |
|
375 // ------------------------------------------------------------------ |
|
376 // ciInstanceKlass::get_field_by_offset |
|
377 ciField* ciInstanceKlass::get_field_by_offset(int field_offset, bool is_static) { |
|
378 if (!is_static) { |
|
379 for (int i = 0, len = nof_nonstatic_fields(); i < len; i++) { |
|
380 ciField* field = _nonstatic_fields->at(i); |
|
381 int field_off = field->offset_in_bytes(); |
|
382 if (field_off == field_offset) |
|
383 return field; |
|
384 if (field_off > field_offset) |
|
385 break; |
|
386 // could do binary search or check bins, but probably not worth it |
|
387 } |
|
388 return NULL; |
|
389 } |
|
390 VM_ENTRY_MARK; |
|
391 InstanceKlass* k = get_instanceKlass(); |
|
392 fieldDescriptor fd; |
|
393 if (!k->find_field_from_offset(field_offset, is_static, &fd)) { |
|
394 return NULL; |
|
395 } |
|
396 ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd); |
|
397 return field; |
|
398 } |
|
399 |
|
400 // ------------------------------------------------------------------ |
|
401 // ciInstanceKlass::get_field_by_name |
|
402 ciField* ciInstanceKlass::get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static) { |
|
403 VM_ENTRY_MARK; |
|
404 InstanceKlass* k = get_instanceKlass(); |
|
405 fieldDescriptor fd; |
|
406 Klass* def = k->find_field(name->get_symbol(), signature->get_symbol(), is_static, &fd); |
|
407 if (def == NULL) { |
|
408 return NULL; |
|
409 } |
|
410 ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd); |
|
411 return field; |
|
412 } |
|
413 |
|
414 |
|
415 static int sort_field_by_offset(ciField** a, ciField** b) { |
|
416 return (*a)->offset_in_bytes() - (*b)->offset_in_bytes(); |
|
417 // (no worries about 32-bit overflow...) |
|
418 } |
|
419 |
|
420 // ------------------------------------------------------------------ |
|
421 // ciInstanceKlass::compute_nonstatic_fields |
|
422 int ciInstanceKlass::compute_nonstatic_fields() { |
|
423 assert(is_loaded(), "must be loaded"); |
|
424 |
|
425 if (_nonstatic_fields != NULL) |
|
426 return _nonstatic_fields->length(); |
|
427 |
|
428 if (!has_nonstatic_fields()) { |
|
429 Arena* arena = CURRENT_ENV->arena(); |
|
430 _nonstatic_fields = new (arena) GrowableArray<ciField*>(arena, 0, 0, NULL); |
|
431 return 0; |
|
432 } |
|
433 assert(!is_java_lang_Object(), "bootstrap OK"); |
|
434 |
|
435 // Size in bytes of my fields, including inherited fields. |
|
436 int fsize = nonstatic_field_size() * heapOopSize; |
|
437 |
|
438 ciInstanceKlass* super = this->super(); |
|
439 GrowableArray<ciField*>* super_fields = NULL; |
|
440 if (super != NULL && super->has_nonstatic_fields()) { |
|
441 int super_fsize = super->nonstatic_field_size() * heapOopSize; |
|
442 int super_flen = super->nof_nonstatic_fields(); |
|
443 super_fields = super->_nonstatic_fields; |
|
444 assert(super_flen == 0 || super_fields != NULL, "first get nof_fields"); |
|
445 // See if I am no larger than my super; if so, I can use his fields. |
|
446 if (fsize == super_fsize) { |
|
447 _nonstatic_fields = super_fields; |
|
448 return super_fields->length(); |
|
449 } |
|
450 } |
|
451 |
|
452 GrowableArray<ciField*>* fields = NULL; |
|
453 GUARDED_VM_ENTRY({ |
|
454 fields = compute_nonstatic_fields_impl(super_fields); |
|
455 }); |
|
456 |
|
457 if (fields == NULL) { |
|
458 // This can happen if this class (java.lang.Class) has invisible fields. |
|
459 if (super_fields != NULL) { |
|
460 _nonstatic_fields = super_fields; |
|
461 return super_fields->length(); |
|
462 } else { |
|
463 return 0; |
|
464 } |
|
465 } |
|
466 |
|
467 int flen = fields->length(); |
|
468 |
|
469 // Now sort them by offset, ascending. |
|
470 // (In principle, they could mix with superclass fields.) |
|
471 fields->sort(sort_field_by_offset); |
|
472 _nonstatic_fields = fields; |
|
473 return flen; |
|
474 } |
|
475 |
|
476 GrowableArray<ciField*>* |
|
477 ciInstanceKlass::compute_nonstatic_fields_impl(GrowableArray<ciField*>* |
|
478 super_fields) { |
|
479 ASSERT_IN_VM; |
|
480 Arena* arena = CURRENT_ENV->arena(); |
|
481 int flen = 0; |
|
482 GrowableArray<ciField*>* fields = NULL; |
|
483 InstanceKlass* k = get_instanceKlass(); |
|
484 for (JavaFieldStream fs(k); !fs.done(); fs.next()) { |
|
485 if (fs.access_flags().is_static()) continue; |
|
486 flen += 1; |
|
487 } |
|
488 |
|
489 // allocate the array: |
|
490 if (flen == 0) { |
|
491 return NULL; // return nothing if none are locally declared |
|
492 } |
|
493 if (super_fields != NULL) { |
|
494 flen += super_fields->length(); |
|
495 } |
|
496 fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, NULL); |
|
497 if (super_fields != NULL) { |
|
498 fields->appendAll(super_fields); |
|
499 } |
|
500 |
|
501 for (JavaFieldStream fs(k); !fs.done(); fs.next()) { |
|
502 if (fs.access_flags().is_static()) continue; |
|
503 fieldDescriptor& fd = fs.field_descriptor(); |
|
504 ciField* field = new (arena) ciField(&fd); |
|
505 fields->append(field); |
|
506 } |
|
507 assert(fields->length() == flen, "sanity"); |
|
508 return fields; |
|
509 } |
|
510 |
|
511 bool ciInstanceKlass::compute_injected_fields_helper() { |
|
512 ASSERT_IN_VM; |
|
513 InstanceKlass* k = get_instanceKlass(); |
|
514 |
|
515 for (InternalFieldStream fs(k); !fs.done(); fs.next()) { |
|
516 if (fs.access_flags().is_static()) continue; |
|
517 return true; |
|
518 } |
|
519 return false; |
|
520 } |
|
521 |
|
522 void ciInstanceKlass::compute_injected_fields() { |
|
523 assert(is_loaded(), "must be loaded"); |
|
524 |
|
525 int has_injected_fields = 0; |
|
526 if (super() != NULL && super()->has_injected_fields()) { |
|
527 has_injected_fields = 1; |
|
528 } else { |
|
529 GUARDED_VM_ENTRY({ |
|
530 has_injected_fields = compute_injected_fields_helper() ? 1 : 0; |
|
531 }); |
|
532 } |
|
533 // may be concurrently initialized for shared ciInstanceKlass objects |
|
534 assert(_has_injected_fields == -1 || _has_injected_fields == has_injected_fields, "broken concurrent initialization"); |
|
535 _has_injected_fields = has_injected_fields; |
|
536 } |
|
537 |
|
538 // ------------------------------------------------------------------ |
|
539 // ciInstanceKlass::find_method |
|
540 // |
|
541 // Find a method in this klass. |
|
542 ciMethod* ciInstanceKlass::find_method(ciSymbol* name, ciSymbol* signature) { |
|
543 VM_ENTRY_MARK; |
|
544 InstanceKlass* k = get_instanceKlass(); |
|
545 Symbol* name_sym = name->get_symbol(); |
|
546 Symbol* sig_sym= signature->get_symbol(); |
|
547 |
|
548 Method* m = k->find_method(name_sym, sig_sym); |
|
549 if (m == NULL) return NULL; |
|
550 |
|
551 return CURRENT_THREAD_ENV->get_method(m); |
|
552 } |
|
553 |
|
554 // ------------------------------------------------------------------ |
|
555 // ciInstanceKlass::is_leaf_type |
|
556 bool ciInstanceKlass::is_leaf_type() { |
|
557 assert(is_loaded(), "must be loaded"); |
|
558 if (is_shared()) { |
|
559 return is_final(); // approximately correct |
|
560 } else { |
|
561 return !_has_subklass && (nof_implementors() == 0); |
|
562 } |
|
563 } |
|
564 |
|
565 // ------------------------------------------------------------------ |
|
566 // ciInstanceKlass::implementor |
|
567 // |
|
568 // Report an implementor of this interface. |
|
569 // Note that there are various races here, since my copy |
|
570 // of _nof_implementors might be out of date with respect |
|
571 // to results returned by InstanceKlass::implementor. |
|
572 // This is OK, since any dependencies we decide to assert |
|
573 // will be checked later under the Compile_lock. |
|
574 ciInstanceKlass* ciInstanceKlass::implementor() { |
|
575 ciInstanceKlass* impl = _implementor; |
|
576 if (impl == NULL) { |
|
577 // Go into the VM to fetch the implementor. |
|
578 { |
|
579 VM_ENTRY_MARK; |
|
580 Klass* k = get_instanceKlass()->implementor(); |
|
581 if (k != NULL) { |
|
582 if (k == get_instanceKlass()) { |
|
583 // More than one implementors. Use 'this' in this case. |
|
584 impl = this; |
|
585 } else { |
|
586 impl = CURRENT_THREAD_ENV->get_instance_klass(k); |
|
587 } |
|
588 } |
|
589 } |
|
590 // Memoize this result. |
|
591 if (!is_shared()) { |
|
592 _implementor = impl; |
|
593 } |
|
594 } |
|
595 return impl; |
|
596 } |
|
597 |
|
598 ciInstanceKlass* ciInstanceKlass::host_klass() { |
|
599 assert(is_loaded(), "must be loaded"); |
|
600 if (is_anonymous()) { |
|
601 VM_ENTRY_MARK |
|
602 Klass* host_klass = get_instanceKlass()->host_klass(); |
|
603 return CURRENT_ENV->get_instance_klass(host_klass); |
|
604 } |
|
605 return NULL; |
|
606 } |
|
607 |
|
608 // Utility class for printing of the contents of the static fields for |
|
609 // use by compilation replay. It only prints out the information that |
|
610 // could be consumed by the compiler, so for primitive types it prints |
|
611 // out the actual value. For Strings it's the actual string value. |
|
612 // For array types it it's first level array size since that's the |
|
613 // only value which statically unchangeable. For all other reference |
|
614 // types it simply prints out the dynamic type. |
|
615 |
|
616 class StaticFinalFieldPrinter : public FieldClosure { |
|
617 outputStream* _out; |
|
618 const char* _holder; |
|
619 public: |
|
620 StaticFinalFieldPrinter(outputStream* out, const char* holder) : |
|
621 _out(out), |
|
622 _holder(holder) { |
|
623 } |
|
624 void do_field(fieldDescriptor* fd) { |
|
625 if (fd->is_final() && !fd->has_initial_value()) { |
|
626 ResourceMark rm; |
|
627 oop mirror = fd->field_holder()->java_mirror(); |
|
628 _out->print("staticfield %s %s %s ", _holder, fd->name()->as_quoted_ascii(), fd->signature()->as_quoted_ascii()); |
|
629 switch (fd->field_type()) { |
|
630 case T_BYTE: _out->print_cr("%d", mirror->byte_field(fd->offset())); break; |
|
631 case T_BOOLEAN: _out->print_cr("%d", mirror->bool_field(fd->offset())); break; |
|
632 case T_SHORT: _out->print_cr("%d", mirror->short_field(fd->offset())); break; |
|
633 case T_CHAR: _out->print_cr("%d", mirror->char_field(fd->offset())); break; |
|
634 case T_INT: _out->print_cr("%d", mirror->int_field(fd->offset())); break; |
|
635 case T_LONG: _out->print_cr(INT64_FORMAT, (int64_t)(mirror->long_field(fd->offset()))); break; |
|
636 case T_FLOAT: { |
|
637 float f = mirror->float_field(fd->offset()); |
|
638 _out->print_cr("%d", *(int*)&f); |
|
639 break; |
|
640 } |
|
641 case T_DOUBLE: { |
|
642 double d = mirror->double_field(fd->offset()); |
|
643 _out->print_cr(INT64_FORMAT, *(int64_t*)&d); |
|
644 break; |
|
645 } |
|
646 case T_ARRAY: { |
|
647 oop value = mirror->obj_field_acquire(fd->offset()); |
|
648 if (value == NULL) { |
|
649 _out->print_cr("null"); |
|
650 } else { |
|
651 typeArrayOop ta = (typeArrayOop)value; |
|
652 _out->print("%d", ta->length()); |
|
653 if (value->is_objArray()) { |
|
654 objArrayOop oa = (objArrayOop)value; |
|
655 const char* klass_name = value->klass()->name()->as_quoted_ascii(); |
|
656 _out->print(" %s", klass_name); |
|
657 } |
|
658 _out->cr(); |
|
659 } |
|
660 break; |
|
661 } |
|
662 case T_OBJECT: { |
|
663 oop value = mirror->obj_field_acquire(fd->offset()); |
|
664 if (value == NULL) { |
|
665 _out->print_cr("null"); |
|
666 } else if (value->is_instance()) { |
|
667 if (value->is_a(SystemDictionary::String_klass())) { |
|
668 _out->print("\""); |
|
669 _out->print_raw(java_lang_String::as_quoted_ascii(value)); |
|
670 _out->print_cr("\""); |
|
671 } else { |
|
672 const char* klass_name = value->klass()->name()->as_quoted_ascii(); |
|
673 _out->print_cr("%s", klass_name); |
|
674 } |
|
675 } else { |
|
676 ShouldNotReachHere(); |
|
677 } |
|
678 break; |
|
679 } |
|
680 default: |
|
681 ShouldNotReachHere(); |
|
682 } |
|
683 } |
|
684 } |
|
685 }; |
|
686 |
|
687 |
|
688 void ciInstanceKlass::dump_replay_data(outputStream* out) { |
|
689 ResourceMark rm; |
|
690 |
|
691 InstanceKlass* ik = get_instanceKlass(); |
|
692 ConstantPool* cp = ik->constants(); |
|
693 |
|
694 // Try to record related loaded classes |
|
695 Klass* sub = ik->subklass(); |
|
696 while (sub != NULL) { |
|
697 if (sub->is_instance_klass()) { |
|
698 out->print_cr("instanceKlass %s", sub->name()->as_quoted_ascii()); |
|
699 } |
|
700 sub = sub->next_sibling(); |
|
701 } |
|
702 |
|
703 // Dump out the state of the constant pool tags. During replay the |
|
704 // tags will be validated for things which shouldn't change and |
|
705 // classes will be resolved if the tags indicate that they were |
|
706 // resolved at compile time. |
|
707 out->print("ciInstanceKlass %s %d %d %d", ik->name()->as_quoted_ascii(), |
|
708 is_linked(), is_initialized(), cp->length()); |
|
709 for (int index = 1; index < cp->length(); index++) { |
|
710 out->print(" %d", cp->tags()->at(index)); |
|
711 } |
|
712 out->cr(); |
|
713 if (is_initialized()) { |
|
714 // Dump out the static final fields in case the compilation relies |
|
715 // on their value for correct replay. |
|
716 StaticFinalFieldPrinter sffp(out, ik->name()->as_quoted_ascii()); |
|
717 ik->do_local_static_fields(&sffp); |
|
718 } |
|
719 } |