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