1 /*
   2  * Copyright (c) 1999, 2015, 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()->is_instance_klass(), "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   _is_anonymous = ik->is_anonymous();
  62   _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields:
  63   _has_injected_fields = -1;
  64   _implementor = NULL; // we will fill these lazily
  65 
  66   Thread *thread = Thread::current();
  67   if (ciObjectFactory::is_initialized()) {
  68     _loader = JNIHandles::make_local(thread, ik->class_loader());
  69     _protection_domain = JNIHandles::make_local(thread,
  70                                                 ik->protection_domain());
  71     _is_shared = false;
  72   } else {
  73     Handle h_loader(thread, ik->class_loader());
  74     Handle h_protection_domain(thread, ik->protection_domain());
  75     _loader = JNIHandles::make_global(h_loader);
  76     _protection_domain = JNIHandles::make_global(h_protection_domain);
  77     _is_shared = true;
  78   }
  79 
  80   // Lazy fields get filled in only upon request.
  81   _super  = NULL;
  82   _java_mirror = NULL;
  83 
  84   if (is_shared()) {
  85     if (h_k() != SystemDictionary::Object_klass()) {
  86       super();
  87     }
  88     //compute_nonstatic_fields();  // done outside of constructor
  89   }
  90 
  91   _field_cache = NULL;
  92 }
  93 
  94 // Version for unloaded classes:
  95 ciInstanceKlass::ciInstanceKlass(ciSymbol* name,
  96                                  jobject loader, jobject protection_domain)
  97   : ciKlass(name, T_OBJECT)
  98 {
  99   assert(name->byte_at(0) != '[', "not an instance klass");
 100   _init_state = (InstanceKlass::ClassState)0;
 101   _nonstatic_field_size = -1;
 102   _has_nonstatic_fields = false;
 103   _nonstatic_fields = NULL;
 104   _has_injected_fields = -1;
 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())) {
 183     tty->print("*** get_canonical_holder(%d) on ", offset);
 184     this->print();
 185     tty->print_cr(" ***");
 186   };
 187   assert(offset >= 0 && offset < layout_helper(), "offset must be tame");
 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->is_instance_klass(), "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_type_by_offset
 401 ciType* ciInstanceKlass::get_field_type_by_offset(int field_offset) {
 402   ASSERT_IN_VM;
 403   fieldDescriptor fd;
 404   InstanceKlass* klass = get_instanceKlass();
 405   // Important: We cannot get the field type via get_field_by_offset() because if the field
 406   // is another value type, the offset would refer to the first field of that value type due
 407   // to flattening. Instead, do a SystemDictionary lookup for the type of the declared field.
 408   bool found = klass->find_field_from_offset(field_offset, false, &fd);
 409   assert(found, "field not found");
 410   BasicType field_type = fd.field_type();
 411   if (is_java_primitive(field_type)) {
 412     // Primitive type
 413     return ciType::make(field_type);
 414   } else {
 415     // Do a SystemDictionary lookup for the type
 416     ciEnv* env = CURRENT_ENV;
 417     ciSymbol* signature = env->get_symbol(fd.signature());
 418     return env->get_klass_by_name_impl(this, constantPoolHandle(), signature, false);
 419   }
 420 }
 421 
 422 // ------------------------------------------------------------------
 423 // ciInstanceKlass::get_field_by_name
 424 ciField* ciInstanceKlass::get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static) {
 425   VM_ENTRY_MARK;
 426   InstanceKlass* k = get_instanceKlass();
 427   fieldDescriptor fd;
 428   Klass* def = k->find_field(name->get_symbol(), signature->get_symbol(), is_static, &fd);
 429   if (def == NULL) {
 430     return NULL;
 431   }
 432   ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
 433   return field;
 434 }
 435 
 436 
 437 static int sort_field_by_offset(ciField** a, ciField** b) {
 438   return (*a)->offset_in_bytes() - (*b)->offset_in_bytes();
 439   // (no worries about 32-bit overflow...)
 440 }
 441 
 442 // ------------------------------------------------------------------
 443 // ciInstanceKlass::compute_nonstatic_fields
 444 int ciInstanceKlass::compute_nonstatic_fields() {
 445   assert(is_loaded(), "must be loaded");
 446 
 447   if (_nonstatic_fields != NULL)
 448     return _nonstatic_fields->length();
 449 
 450   if (!has_nonstatic_fields()) {
 451     Arena* arena = CURRENT_ENV->arena();
 452     _nonstatic_fields = new (arena) GrowableArray<ciField*>(arena, 0, 0, NULL);
 453     return 0;
 454   }
 455   assert(!is_java_lang_Object(), "bootstrap OK");
 456 
 457   // Size in bytes of my fields, including inherited fields.
 458   int fsize = nonstatic_field_size() * heapOopSize;
 459 
 460   ciInstanceKlass* super = this->super();
 461   GrowableArray<ciField*>* super_fields = NULL;
 462   if (super != NULL && super->has_nonstatic_fields()) {
 463     int super_fsize  = super->nonstatic_field_size() * heapOopSize;
 464     int super_flen   = super->nof_nonstatic_fields();
 465     super_fields = super->_nonstatic_fields;
 466     assert(super_flen == 0 || super_fields != NULL, "first get nof_fields");
 467     // See if I am no larger than my super; if so, I can use his fields.
 468     if (fsize == super_fsize) {
 469       _nonstatic_fields = super_fields;
 470       return super_fields->length();
 471     }
 472   }
 473 
 474   GrowableArray<ciField*>* fields = NULL;
 475   GUARDED_VM_ENTRY({
 476       fields = compute_nonstatic_fields_impl(super_fields);
 477     });
 478 
 479   if (fields == NULL) {
 480     // This can happen if this class (java.lang.Class) has invisible fields.
 481     if (super_fields != NULL) {
 482       _nonstatic_fields = super_fields;
 483       return super_fields->length();
 484     } else {
 485       return 0;
 486     }
 487   }
 488 
 489   int flen = fields->length();
 490 
 491   // Now sort them by offset, ascending.
 492   // (In principle, they could mix with superclass fields.)
 493   fields->sort(sort_field_by_offset);
 494   _nonstatic_fields = fields;
 495   return flen;
 496 }
 497 
 498 GrowableArray<ciField*>*
 499 ciInstanceKlass::compute_nonstatic_fields_impl(GrowableArray<ciField*>*
 500                                                super_fields) {
 501   ASSERT_IN_VM;
 502   Arena* arena = CURRENT_ENV->arena();
 503   int flen = 0;
 504   GrowableArray<ciField*>* fields = NULL;
 505   InstanceKlass* k = get_instanceKlass();
 506   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
 507     if (fs.access_flags().is_static())  continue;
 508     flen += 1;
 509   }
 510 
 511   // allocate the array:
 512   if (flen == 0) {
 513     return NULL;  // return nothing if none are locally declared
 514   }
 515   if (super_fields != NULL) {
 516     flen += super_fields->length();
 517   }
 518   fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, NULL);
 519   if (super_fields != NULL) {
 520     fields->appendAll(super_fields);
 521   }
 522 
 523   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
 524     if (fs.access_flags().is_static())  continue;
 525     fieldDescriptor& fd = fs.field_descriptor();
 526     if (fd.field_type() == T_VALUETYPE) {
 527       // Value type fields are embedded
 528       int field_offset = fd.offset();
 529       // Get ValueKlass and adjust number of fields
 530       ciValueKlass* vk = get_field_type_by_offset(field_offset)->as_value_klass();
 531       flen += vk->get_field_count() - 1;
 532       // Iterate over fields of flattened value type and copy them to 'this'
 533       for (int i = 0; i < vk->nof_nonstatic_fields(); ++i) {
 534         ciField* flattened_field = vk->nonstatic_field_at(i);
 535         // Adjust offset to account for missing oop header
 536         int offset = field_offset + (flattened_field->offset() - vk->get_first_field_offset());
 537         bool is_final = is_valuetype(); // flattened fields are final if holder is a value type
 538         ciField* field = new (arena) ciField(flattened_field, this, offset, is_final);
 539         fields->append(field);
 540       }
 541     } else {
 542       ciField* field = new (arena) ciField(&fd);
 543       fields->append(field);
 544     }
 545   }
 546   assert(fields->length() == flen, "sanity");
 547   return fields;
 548 }
 549 
 550 bool ciInstanceKlass::compute_injected_fields_helper() {
 551   ASSERT_IN_VM;
 552   InstanceKlass* k = get_instanceKlass();
 553 
 554   for (InternalFieldStream fs(k); !fs.done(); fs.next()) {
 555     if (fs.access_flags().is_static())  continue;
 556     return true;
 557   }
 558   return false;
 559 }
 560 
 561 void ciInstanceKlass::compute_injected_fields() {
 562   assert(is_loaded(), "must be loaded");
 563 
 564   int has_injected_fields = 0;
 565   if (super() != NULL && super()->has_injected_fields()) {
 566     has_injected_fields = 1;
 567   } else {
 568     GUARDED_VM_ENTRY({
 569         has_injected_fields = compute_injected_fields_helper() ? 1 : 0;
 570       });
 571   }
 572   // may be concurrently initialized for shared ciInstanceKlass objects
 573   assert(_has_injected_fields == -1 || _has_injected_fields == has_injected_fields, "broken concurrent initialization");
 574   _has_injected_fields = has_injected_fields;
 575 }
 576 
 577 // ------------------------------------------------------------------
 578 // ciInstanceKlass::find_method
 579 //
 580 // Find a method in this klass.
 581 ciMethod* ciInstanceKlass::find_method(ciSymbol* name, ciSymbol* signature) {
 582   VM_ENTRY_MARK;
 583   InstanceKlass* k = get_instanceKlass();
 584   Symbol* name_sym = name->get_symbol();
 585   Symbol* sig_sym= signature->get_symbol();
 586 
 587   Method* m = k->find_method(name_sym, sig_sym);
 588   if (m == NULL)  return NULL;
 589 
 590   return CURRENT_THREAD_ENV->get_method(m);
 591 }
 592 
 593 // ------------------------------------------------------------------
 594 // ciInstanceKlass::is_leaf_type
 595 bool ciInstanceKlass::is_leaf_type() {
 596   assert(is_loaded(), "must be loaded");
 597   if (is_shared()) {
 598     return is_final();  // approximately correct
 599   } else {
 600     return !_has_subklass && (nof_implementors() == 0);
 601   }
 602 }
 603 
 604 // ------------------------------------------------------------------
 605 // ciInstanceKlass::implementor
 606 //
 607 // Report an implementor of this interface.
 608 // Note that there are various races here, since my copy
 609 // of _nof_implementors might be out of date with respect
 610 // to results returned by InstanceKlass::implementor.
 611 // This is OK, since any dependencies we decide to assert
 612 // will be checked later under the Compile_lock.
 613 ciInstanceKlass* ciInstanceKlass::implementor() {
 614   ciInstanceKlass* impl = _implementor;
 615   if (impl == NULL) {
 616     // Go into the VM to fetch the implementor.
 617     {
 618       VM_ENTRY_MARK;
 619       Klass* k = get_instanceKlass()->implementor();
 620       if (k != NULL) {
 621         if (k == get_instanceKlass()) {
 622           // More than one implementors. Use 'this' in this case.
 623           impl = this;
 624         } else {
 625           impl = CURRENT_THREAD_ENV->get_instance_klass(k);
 626         }
 627       }
 628     }
 629     // Memoize this result.
 630     if (!is_shared()) {
 631       _implementor = impl;
 632     }
 633   }
 634   return impl;
 635 }
 636 
 637 // Utility class for printing of the contents of the static fields for
 638 // use by compilation replay.  It only prints out the information that
 639 // could be consumed by the compiler, so for primitive types it prints
 640 // out the actual value.  For Strings it's the actual string value.
 641 // For array types it it's first level array size since that's the
 642 // only value which statically unchangeable.  For all other reference
 643 // types it simply prints out the dynamic type.
 644 
 645 class StaticFinalFieldPrinter : public FieldClosure {
 646   outputStream* _out;
 647   const char*   _holder;
 648  public:
 649   StaticFinalFieldPrinter(outputStream* out, const char* holder) :
 650     _out(out),
 651     _holder(holder) {
 652   }
 653   void do_field(fieldDescriptor* fd) {
 654     if (fd->is_final() && !fd->has_initial_value()) {
 655       ResourceMark rm;
 656       oop mirror = fd->field_holder()->java_mirror();
 657       _out->print("staticfield %s %s %s ", _holder, fd->name()->as_quoted_ascii(), fd->signature()->as_quoted_ascii());
 658       switch (fd->field_type()) {
 659         case T_BYTE:    _out->print_cr("%d", mirror->byte_field(fd->offset()));   break;
 660         case T_BOOLEAN: _out->print_cr("%d", mirror->bool_field(fd->offset()));   break;
 661         case T_SHORT:   _out->print_cr("%d", mirror->short_field(fd->offset()));  break;
 662         case T_CHAR:    _out->print_cr("%d", mirror->char_field(fd->offset()));   break;
 663         case T_INT:     _out->print_cr("%d", mirror->int_field(fd->offset()));    break;
 664         case T_LONG:    _out->print_cr(INT64_FORMAT, (int64_t)(mirror->long_field(fd->offset())));   break;
 665         case T_FLOAT: {
 666           float f = mirror->float_field(fd->offset());
 667           _out->print_cr("%d", *(int*)&f);
 668           break;
 669         }
 670         case T_DOUBLE: {
 671           double d = mirror->double_field(fd->offset());
 672           _out->print_cr(INT64_FORMAT, *(int64_t*)&d);
 673           break;
 674         }
 675         case T_ARRAY: {
 676           oop value =  mirror->obj_field_acquire(fd->offset());
 677           if (value == NULL) {
 678             _out->print_cr("null");
 679           } else {
 680             typeArrayOop ta = (typeArrayOop)value;
 681             _out->print("%d", ta->length());
 682             if (value->is_objArray()) {
 683               objArrayOop oa = (objArrayOop)value;
 684               const char* klass_name  = value->klass()->name()->as_quoted_ascii();
 685               _out->print(" %s", klass_name);
 686             }
 687             _out->cr();
 688           }
 689           break;
 690         }
 691         case T_OBJECT: {
 692           oop value =  mirror->obj_field_acquire(fd->offset());
 693           if (value == NULL) {
 694             _out->print_cr("null");
 695           } else if (value->is_instance()) {
 696             if (value->is_a(SystemDictionary::String_klass())) {
 697               _out->print("\"");
 698               _out->print_raw(java_lang_String::as_quoted_ascii(value));
 699               _out->print_cr("\"");
 700             } else {
 701               const char* klass_name  = value->klass()->name()->as_quoted_ascii();
 702               _out->print_cr("%s", klass_name);
 703             }
 704           } else {
 705             ShouldNotReachHere();
 706           }
 707           break;
 708         }
 709         default:
 710           ShouldNotReachHere();
 711         }
 712     }
 713   }
 714 };
 715 
 716 
 717 void ciInstanceKlass::dump_replay_data(outputStream* out) {
 718   ResourceMark rm;
 719 
 720   InstanceKlass* ik = get_instanceKlass();
 721   ConstantPool*  cp = ik->constants();
 722 
 723   // Try to record related loaded classes
 724   Klass* sub = ik->subklass();
 725   while (sub != NULL) {
 726     if (sub->is_instance_klass()) {
 727       out->print_cr("instanceKlass %s", sub->name()->as_quoted_ascii());
 728     }
 729     sub = sub->next_sibling();
 730   }
 731 
 732   // Dump out the state of the constant pool tags.  During replay the
 733   // tags will be validated for things which shouldn't change and
 734   // classes will be resolved if the tags indicate that they were
 735   // resolved at compile time.
 736   out->print("ciInstanceKlass %s %d %d %d", ik->name()->as_quoted_ascii(),
 737              is_linked(), is_initialized(), cp->length());
 738   for (int index = 1; index < cp->length(); index++) {
 739     out->print(" %d", cp->tags()->at(index));
 740   }
 741   out->cr();
 742   if (is_initialized()) {
 743     //  Dump out the static final fields in case the compilation relies
 744     //  on their value for correct replay.
 745     StaticFinalFieldPrinter sffp(out, ik->name()->as_quoted_ascii());
 746     ik->do_local_static_fields(&sffp);
 747   }
 748 }