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