< prev index next >

src/hotspot/share/ci/ciInstanceKlass.cpp

Print this page




  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.inline.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.inline.hpp"
  37 #include "runtime/handles.inline.hpp"
  38 #include "runtime/jniHandles.inline.hpp"
  39 
  40 // ciInstanceKlass
  41 //
  42 // This class represents a Klass* in the HotSpot virtual machine
  43 // whose Klass part in an InstanceKlass.
  44 
  45 
  46 // ------------------------------------------------------------------
  47 // ciInstanceKlass::ciInstanceKlass
  48 //
  49 // Loaded instance klass.
  50 ciInstanceKlass::ciInstanceKlass(Klass* k) :
  51   ciKlass(k)
  52 {
  53   assert(get_Klass()->is_instance_klass(), "wrong type");
  54   assert(get_instanceKlass()->is_loaded(), "must be at least loaded");
  55   InstanceKlass* ik = get_instanceKlass();
  56 
  57   AccessFlags access_flags = ik->access_flags();
  58   _flags = ciFlags(access_flags);
  59   _has_finalizer = access_flags.has_finalizer();
  60   _has_subklass = flags().is_final() ? subklass_false : subklass_unknown;
  61   _init_state = ik->init_state();
  62   _nonstatic_field_size = ik->nonstatic_field_size();
  63   _has_nonstatic_fields = ik->has_nonstatic_fields();
  64   _has_nonstatic_concrete_methods = ik->has_nonstatic_concrete_methods();
  65   _is_unsafe_anonymous = ik->is_unsafe_anonymous();
  66   _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields:
  67   _has_injected_fields = -1;

  68   _implementor = NULL; // we will fill these lazily
  69 
  70   // Ensure that the metadata wrapped by the ciMetadata is kept alive by GC.
  71   // This is primarily useful for metadata which is considered as weak roots
  72   // by the GC but need to be strong roots if reachable from a current compilation.
  73   // InstanceKlass are created for both weak and strong metadata.  Ensuring this metadata
  74   // alive covers the cases where there are weak roots without performance cost.
  75   oop holder = ik->klass_holder();
  76   if (ik->is_unsafe_anonymous()) {
  77     // Though ciInstanceKlass records class loader oop, it's not enough to keep
  78     // VM unsafe anonymous classes alive (loader == NULL). Klass holder should
  79     // be used instead. It is enough to record a ciObject, since cached elements are never removed
  80     // during ciObjectFactory lifetime. ciObjectFactory itself is created for
  81     // every compilation and lives for the whole duration of the compilation.
  82     assert(holder != NULL, "holder of unsafe anonymous class is the mirror which is never null");
  83     (void)CURRENT_ENV->get_object(holder);
  84   }
  85 
  86   Thread *thread = Thread::current();
  87   if (ciObjectFactory::is_initialized()) {


  96     _protection_domain = JNIHandles::make_global(h_protection_domain);
  97     _is_shared = true;
  98   }
  99 
 100   // Lazy fields get filled in only upon request.
 101   _super  = NULL;
 102   _java_mirror = NULL;
 103 
 104   if (is_shared()) {
 105     if (k != SystemDictionary::Object_klass()) {
 106       super();
 107     }
 108     //compute_nonstatic_fields();  // done outside of constructor
 109   }
 110 
 111   _field_cache = NULL;
 112 }
 113 
 114 // Version for unloaded classes:
 115 ciInstanceKlass::ciInstanceKlass(ciSymbol* name,
 116                                  jobject loader, jobject protection_domain)
 117   : ciKlass(name, T_OBJECT)

 118 {
 119   assert(name->char_at(0) != '[', "not an instance klass");
 120   _init_state = (InstanceKlass::ClassState)0;
 121   _nonstatic_field_size = -1;
 122   _has_nonstatic_fields = false;
 123   _nonstatic_fields = NULL;
 124   _has_injected_fields = -1;

 125   _is_unsafe_anonymous = false;
 126   _loader = loader;
 127   _protection_domain = protection_domain;
 128   _is_shared = false;
 129   _super = NULL;
 130   _java_mirror = NULL;
 131   _field_cache = NULL;
 132 }
 133 
 134 
 135 
 136 // ------------------------------------------------------------------
 137 // ciInstanceKlass::compute_shared_is_initialized
 138 void ciInstanceKlass::compute_shared_init_state() {
 139   GUARDED_VM_ENTRY(
 140     InstanceKlass* ik = get_instanceKlass();
 141     _init_state = ik->init_state();
 142   )
 143 }
 144 


 399       ciField* field = _nonstatic_fields->at(i);
 400       int  field_off = field->offset_in_bytes();
 401       if (field_off == field_offset)
 402         return field;
 403       if (field_off > field_offset)
 404         break;
 405       // could do binary search or check bins, but probably not worth it
 406     }
 407     return NULL;
 408   }
 409   VM_ENTRY_MARK;
 410   InstanceKlass* k = get_instanceKlass();
 411   fieldDescriptor fd;
 412   if (!k->find_field_from_offset(field_offset, is_static, &fd)) {
 413     return NULL;
 414   }
 415   ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
 416   return field;
 417 }
 418 























 419 // ------------------------------------------------------------------
 420 // ciInstanceKlass::get_field_by_name
 421 ciField* ciInstanceKlass::get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static) {
 422   VM_ENTRY_MARK;
 423   InstanceKlass* k = get_instanceKlass();
 424   fieldDescriptor fd;
 425   Klass* def = k->find_field(name->get_symbol(), signature->get_symbol(), is_static, &fd);
 426   if (def == NULL) {
 427     return NULL;
 428   }
 429   ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
 430   return field;
 431 }
 432 
 433 
 434 static int sort_field_by_offset(ciField** a, ciField** b) {
 435   return (*a)->offset_in_bytes() - (*b)->offset_in_bytes();
 436   // (no worries about 32-bit overflow...)
 437 }
 438 


 466       _nonstatic_fields = super_fields;
 467       return super_fields->length();
 468     }
 469   }
 470 
 471   GrowableArray<ciField*>* fields = NULL;
 472   GUARDED_VM_ENTRY({
 473       fields = compute_nonstatic_fields_impl(super_fields);
 474     });
 475 
 476   if (fields == NULL) {
 477     // This can happen if this class (java.lang.Class) has invisible fields.
 478     if (super_fields != NULL) {
 479       _nonstatic_fields = super_fields;
 480       return super_fields->length();
 481     } else {
 482       return 0;
 483     }
 484   }
 485 
 486   int flen = fields->length();
 487 
 488   // Now sort them by offset, ascending.
 489   // (In principle, they could mix with superclass fields.)
 490   fields->sort(sort_field_by_offset);
 491   _nonstatic_fields = fields;
 492   return flen;
 493 }
 494 
 495 GrowableArray<ciField*>*
 496 ciInstanceKlass::compute_nonstatic_fields_impl(GrowableArray<ciField*>*
 497                                                super_fields) {
 498   ASSERT_IN_VM;
 499   Arena* arena = CURRENT_ENV->arena();
 500   int flen = 0;
 501   GrowableArray<ciField*>* fields = NULL;
 502   InstanceKlass* k = get_instanceKlass();
 503   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
 504     if (fs.access_flags().is_static())  continue;
 505     flen += 1;
 506   }
 507 
 508   // allocate the array:
 509   if (flen == 0) {
 510     return NULL;  // return nothing if none are locally declared
 511   }
 512   if (super_fields != NULL) {
 513     flen += super_fields->length();
 514   }

 515   fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, NULL);
 516   if (super_fields != NULL) {
 517     fields->appendAll(super_fields);
 518   }
 519 
 520   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
 521     if (fs.access_flags().is_static())  continue;
 522     fieldDescriptor& fd = fs.field_descriptor();



















 523     ciField* field = new (arena) ciField(&fd);
 524     fields->append(field);
 525   }

 526   assert(fields->length() == flen, "sanity");



 527   return fields;
 528 }
 529 
 530 bool ciInstanceKlass::compute_injected_fields_helper() {
 531   ASSERT_IN_VM;
 532   InstanceKlass* k = get_instanceKlass();
 533 
 534   for (InternalFieldStream fs(k); !fs.done(); fs.next()) {
 535     if (fs.access_flags().is_static())  continue;
 536     return true;
 537   }
 538   return false;
 539 }
 540 
 541 void ciInstanceKlass::compute_injected_fields() {
 542   assert(is_loaded(), "must be loaded");
 543 
 544   int has_injected_fields = 0;
 545   if (super() != NULL && super()->has_injected_fields()) {
 546     has_injected_fields = 1;


 614       }
 615     }
 616     // Memoize this result.
 617     if (!is_shared()) {
 618       _implementor = impl;
 619     }
 620   }
 621   return impl;
 622 }
 623 
 624 ciInstanceKlass* ciInstanceKlass::unsafe_anonymous_host() {
 625   assert(is_loaded(), "must be loaded");
 626   if (is_unsafe_anonymous()) {
 627     VM_ENTRY_MARK
 628     Klass* unsafe_anonymous_host = get_instanceKlass()->unsafe_anonymous_host();
 629     return CURRENT_ENV->get_instance_klass(unsafe_anonymous_host);
 630   }
 631   return NULL;
 632 }
 633 




 634 // Utility class for printing of the contents of the static fields for
 635 // use by compilation replay.  It only prints out the information that
 636 // could be consumed by the compiler, so for primitive types it prints
 637 // out the actual value.  For Strings it's the actual string value.
 638 // For array types it it's first level array size since that's the
 639 // only value which statically unchangeable.  For all other reference
 640 // types it simply prints out the dynamic type.
 641 
 642 class StaticFinalFieldPrinter : public FieldClosure {

 643   outputStream* _out;








 644   const char*   _holder;
 645  public:
 646   StaticFinalFieldPrinter(outputStream* out, const char* holder) :
 647     _out(out),
 648     _holder(holder) {
 649   }
 650   void do_field(fieldDescriptor* fd) {
 651     if (fd->is_final() && !fd->has_initial_value()) {
 652       ResourceMark rm;
 653       oop mirror = fd->field_holder()->java_mirror();
 654       _out->print("staticfield %s %s %s ", _holder, fd->name()->as_quoted_ascii(), fd->signature()->as_quoted_ascii());
 655       switch (fd->field_type()) {
 656         case T_BYTE:    _out->print_cr("%d", mirror->byte_field(fd->offset()));   break;
 657         case T_BOOLEAN: _out->print_cr("%d", mirror->bool_field(fd->offset()));   break;
 658         case T_SHORT:   _out->print_cr("%d", mirror->short_field(fd->offset()));  break;
 659         case T_CHAR:    _out->print_cr("%d", mirror->char_field(fd->offset()));   break;
 660         case T_INT:     _out->print_cr("%d", mirror->int_field(fd->offset()));    break;
 661         case T_LONG:    _out->print_cr(INT64_FORMAT, (int64_t)(mirror->long_field(fd->offset())));   break;

























 662         case T_FLOAT: {
 663           float f = mirror->float_field(fd->offset());
 664           _out->print_cr("%d", *(int*)&f);
 665           break;
 666         }
 667         case T_DOUBLE: {
 668           double d = mirror->double_field(fd->offset());
 669           _out->print_cr(INT64_FORMAT, *(int64_t*)&d);
 670           break;
 671         }
 672         case T_ARRAY:  // fall-through
 673         case T_OBJECT: {
 674           oop value =  mirror->obj_field_acquire(fd->offset());
 675           if (value == NULL) {
 676             _out->print_cr("null");
 677           } else if (value->is_instance()) {
 678             assert(fd->field_type() == T_OBJECT, "");
 679             if (value->is_a(SystemDictionary::String_klass())) {
 680               const char* ascii_value = java_lang_String::as_quoted_ascii(value);
 681               _out->print("\"%s\"", (ascii_value != NULL) ? ascii_value : "");
 682             } else {
 683               const char* klass_name  = value->klass()->name()->as_quoted_ascii();
 684               _out->print_cr("%s", klass_name);
 685             }
 686           } else if (value->is_array()) {
 687             typeArrayOop ta = (typeArrayOop)value;
 688             _out->print("%d", ta->length());
 689             if (value->is_objArray()) {
 690               objArrayOop oa = (objArrayOop)value;
 691               const char* klass_name  = value->klass()->name()->as_quoted_ascii();
 692               _out->print(" %s", klass_name);
 693             }
 694             _out->cr();
 695           } else {
 696             ShouldNotReachHere();
 697           }
 698           break;
 699         }
 700         default:
 701           ShouldNotReachHere();















 702         }



 703     }


 704   }
 705 };
 706 
 707 
 708 void ciInstanceKlass::dump_replay_data(outputStream* out) {
 709   ResourceMark rm;
 710 
 711   InstanceKlass* ik = get_instanceKlass();
 712   ConstantPool*  cp = ik->constants();
 713 
 714   // Try to record related loaded classes
 715   Klass* sub = ik->subklass();
 716   while (sub != NULL) {
 717     if (sub->is_instance_klass()) {
 718       out->print_cr("instanceKlass %s", sub->name()->as_quoted_ascii());
 719     }
 720     sub = sub->next_sibling();
 721   }
 722 
 723   // Dump out the state of the constant pool tags.  During replay the
 724   // tags will be validated for things which shouldn't change and
 725   // classes will be resolved if the tags indicate that they were




  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.inline.hpp"
  30 #include "ci/ciValueKlass.hpp"
  31 #include "classfile/systemDictionary.hpp"
  32 #include "memory/allocation.hpp"
  33 #include "memory/allocation.inline.hpp"
  34 #include "memory/resourceArea.hpp"
  35 #include "oops/oop.inline.hpp"
  36 #include "oops/fieldStreams.hpp"
  37 #include "oops/valueKlass.hpp"
  38 #include "runtime/fieldDescriptor.inline.hpp"
  39 #include "runtime/handles.inline.hpp"
  40 #include "runtime/jniHandles.inline.hpp"
  41 
  42 // ciInstanceKlass
  43 //
  44 // This class represents a Klass* in the HotSpot virtual machine
  45 // whose Klass part in an InstanceKlass.
  46 
  47 
  48 // ------------------------------------------------------------------
  49 // ciInstanceKlass::ciInstanceKlass
  50 //
  51 // Loaded instance klass.
  52 ciInstanceKlass::ciInstanceKlass(Klass* k) :
  53   ciKlass(k)
  54 {
  55   assert(get_Klass()->is_instance_klass(), "wrong type");
  56   assert(get_instanceKlass()->is_loaded(), "must be at least loaded");
  57   InstanceKlass* ik = get_instanceKlass();
  58 
  59   AccessFlags access_flags = ik->access_flags();
  60   _flags = ciFlags(access_flags);
  61   _has_finalizer = access_flags.has_finalizer();
  62   _has_subklass = flags().is_final() ? subklass_false : subklass_unknown;
  63   _init_state = ik->init_state();
  64   _nonstatic_field_size = ik->nonstatic_field_size();
  65   _has_nonstatic_fields = ik->has_nonstatic_fields();
  66   _has_nonstatic_concrete_methods = ik->has_nonstatic_concrete_methods();
  67   _is_unsafe_anonymous = ik->is_unsafe_anonymous();
  68   _nonstatic_fields = NULL;            // initialized lazily by compute_nonstatic_fields
  69   _has_injected_fields = -1;
  70   _vcc_klass = NULL;
  71   _implementor = NULL; // we will fill these lazily
  72 
  73   // Ensure that the metadata wrapped by the ciMetadata is kept alive by GC.
  74   // This is primarily useful for metadata which is considered as weak roots
  75   // by the GC but need to be strong roots if reachable from a current compilation.
  76   // InstanceKlass are created for both weak and strong metadata.  Ensuring this metadata
  77   // alive covers the cases where there are weak roots without performance cost.
  78   oop holder = ik->klass_holder();
  79   if (ik->is_unsafe_anonymous()) {
  80     // Though ciInstanceKlass records class loader oop, it's not enough to keep
  81     // VM unsafe anonymous classes alive (loader == NULL). Klass holder should
  82     // be used instead. It is enough to record a ciObject, since cached elements are never removed
  83     // during ciObjectFactory lifetime. ciObjectFactory itself is created for
  84     // every compilation and lives for the whole duration of the compilation.
  85     assert(holder != NULL, "holder of unsafe anonymous class is the mirror which is never null");
  86     (void)CURRENT_ENV->get_object(holder);
  87   }
  88 
  89   Thread *thread = Thread::current();
  90   if (ciObjectFactory::is_initialized()) {


  99     _protection_domain = JNIHandles::make_global(h_protection_domain);
 100     _is_shared = true;
 101   }
 102 
 103   // Lazy fields get filled in only upon request.
 104   _super  = NULL;
 105   _java_mirror = NULL;
 106 
 107   if (is_shared()) {
 108     if (k != SystemDictionary::Object_klass()) {
 109       super();
 110     }
 111     //compute_nonstatic_fields();  // done outside of constructor
 112   }
 113 
 114   _field_cache = NULL;
 115 }
 116 
 117 // Version for unloaded classes:
 118 ciInstanceKlass::ciInstanceKlass(ciSymbol* name,
 119                                  jobject loader, jobject protection_domain,
 120                                  BasicType bt)
 121   : ciKlass(name, bt)
 122 {
 123   assert(name->char_at(0) != '[', "not an instance klass");
 124   _init_state = (InstanceKlass::ClassState)0;
 125   _nonstatic_field_size = -1;
 126   _has_nonstatic_fields = false;
 127   _nonstatic_fields = NULL;            // initialized lazily by compute_nonstatic_fields
 128   _has_injected_fields = -1;
 129   _vcc_klass = NULL;
 130   _is_unsafe_anonymous = false;
 131   _loader = loader;
 132   _protection_domain = protection_domain;
 133   _is_shared = false;
 134   _super = NULL;
 135   _java_mirror = NULL;
 136   _field_cache = NULL;
 137 }
 138 
 139 
 140 
 141 // ------------------------------------------------------------------
 142 // ciInstanceKlass::compute_shared_is_initialized
 143 void ciInstanceKlass::compute_shared_init_state() {
 144   GUARDED_VM_ENTRY(
 145     InstanceKlass* ik = get_instanceKlass();
 146     _init_state = ik->init_state();
 147   )
 148 }
 149 


 404       ciField* field = _nonstatic_fields->at(i);
 405       int  field_off = field->offset_in_bytes();
 406       if (field_off == field_offset)
 407         return field;
 408       if (field_off > field_offset)
 409         break;
 410       // could do binary search or check bins, but probably not worth it
 411     }
 412     return NULL;
 413   }
 414   VM_ENTRY_MARK;
 415   InstanceKlass* k = get_instanceKlass();
 416   fieldDescriptor fd;
 417   if (!k->find_field_from_offset(field_offset, is_static, &fd)) {
 418     return NULL;
 419   }
 420   ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
 421   return field;
 422 }
 423 
 424 ciField* ciInstanceKlass::get_non_flattened_field_by_offset(int field_offset) {
 425   if (super() != NULL && super()->has_nonstatic_fields()) {
 426     ciField* f = super()->get_non_flattened_field_by_offset(field_offset);
 427     if (f != NULL) {
 428       return f;
 429     }
 430   }
 431 
 432   VM_ENTRY_MARK;
 433   InstanceKlass* k = get_instanceKlass();
 434   Arena* arena = CURRENT_ENV->arena();
 435   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
 436     if (fs.access_flags().is_static())  continue;
 437     fieldDescriptor& fd = fs.field_descriptor();
 438     if (fd.offset() == field_offset) {
 439       ciField* f = new (arena) ciField(&fd);
 440       return f;
 441     }
 442   }
 443 
 444   return NULL;
 445 }
 446 
 447 // ------------------------------------------------------------------
 448 // ciInstanceKlass::get_field_by_name
 449 ciField* ciInstanceKlass::get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static) {
 450   VM_ENTRY_MARK;
 451   InstanceKlass* k = get_instanceKlass();
 452   fieldDescriptor fd;
 453   Klass* def = k->find_field(name->get_symbol(), signature->get_symbol(), is_static, &fd);
 454   if (def == NULL) {
 455     return NULL;
 456   }
 457   ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
 458   return field;
 459 }
 460 
 461 
 462 static int sort_field_by_offset(ciField** a, ciField** b) {
 463   return (*a)->offset_in_bytes() - (*b)->offset_in_bytes();
 464   // (no worries about 32-bit overflow...)
 465 }
 466 


 494       _nonstatic_fields = super_fields;
 495       return super_fields->length();
 496     }
 497   }
 498 
 499   GrowableArray<ciField*>* fields = NULL;
 500   GUARDED_VM_ENTRY({
 501       fields = compute_nonstatic_fields_impl(super_fields);
 502     });
 503 
 504   if (fields == NULL) {
 505     // This can happen if this class (java.lang.Class) has invisible fields.
 506     if (super_fields != NULL) {
 507       _nonstatic_fields = super_fields;
 508       return super_fields->length();
 509     } else {
 510       return 0;
 511     }
 512   }
 513 





 514   _nonstatic_fields = fields;
 515   return fields->length();
 516 }
 517 
 518 GrowableArray<ciField*>* ciInstanceKlass::compute_nonstatic_fields_impl(GrowableArray<ciField*>* super_fields, bool flatten) {


 519   ASSERT_IN_VM;
 520   Arena* arena = CURRENT_ENV->arena();
 521   int flen = 0;
 522   GrowableArray<ciField*>* fields = NULL;
 523   InstanceKlass* k = get_instanceKlass();
 524   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
 525     if (fs.access_flags().is_static())  continue;
 526     flen += 1;
 527   }
 528 
 529   // allocate the array:
 530   if (flen == 0) {
 531     return NULL;  // return nothing if none are locally declared
 532   }
 533   if (super_fields != NULL) {
 534     flen += super_fields->length();
 535   }
 536 
 537   fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, NULL);
 538   if (super_fields != NULL) {
 539     fields->appendAll(super_fields);
 540   }
 541 
 542   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
 543     if (fs.access_flags().is_static())  continue;
 544     fieldDescriptor& fd = fs.field_descriptor();
 545     if (fd.is_flattened() && flatten) {
 546       // Value type fields are embedded
 547       int field_offset = fd.offset();
 548       // Get ValueKlass and adjust number of fields
 549       Klass* k = get_instanceKlass()->get_value_field_klass(fd.index());
 550       ciValueKlass* vk = CURRENT_ENV->get_klass(k)->as_value_klass();
 551       flen += vk->nof_nonstatic_fields() - 1;
 552       // Iterate over fields of the flattened value type and copy them to 'this'
 553       for (int i = 0; i < vk->nof_nonstatic_fields(); ++i) {
 554         ciField* flattened_field = vk->nonstatic_field_at(i);
 555         // Adjust offset to account for missing oop header
 556         int offset = field_offset + (flattened_field->offset() - vk->first_field_offset());
 557         // A flattened field can be treated as final if the non-flattened
 558         // field is declared final or the holder klass is a value type itself.
 559         bool is_final = fd.is_final() || is_valuetype();
 560         ciField* field = new (arena) ciField(flattened_field, this, offset, is_final);
 561         fields->append(field);
 562       }
 563     } else {
 564       ciField* field = new (arena) ciField(&fd);
 565       fields->append(field);
 566     }
 567   }
 568   assert(fields->length() == flen, "sanity");
 569   // Now sort them by offset, ascending.
 570   // (In principle, they could mix with superclass fields.)
 571   fields->sort(sort_field_by_offset);
 572   return fields;
 573 }
 574 
 575 bool ciInstanceKlass::compute_injected_fields_helper() {
 576   ASSERT_IN_VM;
 577   InstanceKlass* k = get_instanceKlass();
 578 
 579   for (InternalFieldStream fs(k); !fs.done(); fs.next()) {
 580     if (fs.access_flags().is_static())  continue;
 581     return true;
 582   }
 583   return false;
 584 }
 585 
 586 void ciInstanceKlass::compute_injected_fields() {
 587   assert(is_loaded(), "must be loaded");
 588 
 589   int has_injected_fields = 0;
 590   if (super() != NULL && super()->has_injected_fields()) {
 591     has_injected_fields = 1;


 659       }
 660     }
 661     // Memoize this result.
 662     if (!is_shared()) {
 663       _implementor = impl;
 664     }
 665   }
 666   return impl;
 667 }
 668 
 669 ciInstanceKlass* ciInstanceKlass::unsafe_anonymous_host() {
 670   assert(is_loaded(), "must be loaded");
 671   if (is_unsafe_anonymous()) {
 672     VM_ENTRY_MARK
 673     Klass* unsafe_anonymous_host = get_instanceKlass()->unsafe_anonymous_host();
 674     return CURRENT_ENV->get_instance_klass(unsafe_anonymous_host);
 675   }
 676   return NULL;
 677 }
 678 
 679 ciInstanceKlass* ciInstanceKlass::vcc_klass() {
 680   return NULL;
 681 }
 682 
 683 // Utility class for printing of the contents of the static fields for
 684 // use by compilation replay.  It only prints out the information that
 685 // could be consumed by the compiler, so for primitive types it prints
 686 // out the actual value.  For Strings it's the actual string value.
 687 // For array types it it's first level array size since that's the
 688 // only value which statically unchangeable.  For all other reference
 689 // types it simply prints out the dynamic type.
 690 
 691 class StaticFieldPrinter : public FieldClosure {
 692 protected:
 693   outputStream* _out;
 694 public:
 695   StaticFieldPrinter(outputStream* out) :
 696     _out(out) {
 697   }
 698   void do_field_helper(fieldDescriptor* fd, oop obj, bool flattened);
 699 };
 700 
 701 class StaticFinalFieldPrinter : public StaticFieldPrinter {
 702   const char*   _holder;
 703  public:
 704   StaticFinalFieldPrinter(outputStream* out, const char* holder) :
 705     StaticFieldPrinter(out), _holder(holder) {

 706   }
 707   void do_field(fieldDescriptor* fd) {
 708     if (fd->is_final() && !fd->has_initial_value()) {
 709       ResourceMark rm;
 710       InstanceKlass* holder = fd->field_holder();
 711       oop mirror = holder->java_mirror();
 712       _out->print("staticfield %s %s ", _holder, fd->name()->as_quoted_ascii());
 713       BasicType bt = fd->field_type();
 714       if (bt != T_OBJECT && bt != T_ARRAY) {
 715         _out->print("%s ", fd->signature()->as_quoted_ascii());
 716       }
 717       do_field_helper(fd, mirror, false);
 718       _out->cr();
 719     }
 720   }
 721 };
 722 
 723 class ValueTypeFieldPrinter : public StaticFieldPrinter {
 724   oop _obj;
 725 public:
 726   ValueTypeFieldPrinter(outputStream* out, oop obj) :
 727     StaticFieldPrinter(out), _obj(obj) {
 728   }
 729   void do_field(fieldDescriptor* fd) {
 730     do_field_helper(fd, _obj, true);
 731     _out->print(" ");
 732   }
 733 };
 734 
 735 void StaticFieldPrinter::do_field_helper(fieldDescriptor* fd, oop mirror, bool flattened) {
 736   BasicType bt = fd->field_type();
 737   switch (bt) {
 738     case T_BYTE:    _out->print("%d", mirror->byte_field(fd->offset()));   break;
 739     case T_BOOLEAN: _out->print("%d", mirror->bool_field(fd->offset()));   break;
 740     case T_SHORT:   _out->print("%d", mirror->short_field(fd->offset()));  break;
 741     case T_CHAR:    _out->print("%d", mirror->char_field(fd->offset()));   break;
 742     case T_INT:     _out->print("%d", mirror->int_field(fd->offset()));    break;
 743     case T_LONG:    _out->print(INT64_FORMAT, (int64_t)(mirror->long_field(fd->offset())));   break;
 744     case T_FLOAT: {
 745       float f = mirror->float_field(fd->offset());
 746       _out->print("%d", *(int*)&f);
 747       break;
 748     }
 749     case T_DOUBLE: {
 750       double d = mirror->double_field(fd->offset());
 751       _out->print(INT64_FORMAT, *(int64_t*)&d);
 752       break;
 753     }
 754     case T_ARRAY:  // fall-through
 755     case T_OBJECT: {
 756       oop value =  mirror->obj_field_acquire(fd->offset());
 757       if (value == NULL) {
 758         _out->print_cr("null");
 759       } else if (value->is_instance()) {
 760         assert(fd->field_type() == T_OBJECT, "");
 761         if (value->is_a(SystemDictionary::String_klass())) {
 762           const char* ascii_value = java_lang_String::as_quoted_ascii(value);
 763           _out->print("\"%s\"", (ascii_value != NULL) ? ascii_value : "");
 764          } else {
 765           const char* klass_name  = value->klass()->name()->as_quoted_ascii();
 766           _out->print_cr("%s", klass_name);
 767         }
 768       } else if (value->is_array()) {
 769         typeArrayOop ta = (typeArrayOop)value;
 770         _out->print("%d", ta->length());
 771         if (value->is_objArray() || value->is_valueArray()) {
 772           objArrayOop oa = (objArrayOop)value;
 773           const char* klass_name  = value->klass()->name()->as_quoted_ascii();
 774           _out->print(" %s", klass_name);
 775         }
 776         _out->cr();
 777       } else {
 778         ShouldNotReachHere();
 779       }
 780       break;
 781     }
 782     case T_VALUETYPE: {
 783       ResetNoHandleMark rnhm;
 784       Thread* THREAD = Thread::current();
 785       SignatureStream ss(fd->signature(), false);
 786       Symbol* name = ss.as_symbol(THREAD);
 787       assert(!HAS_PENDING_EXCEPTION, "can resolve klass?");
 788       InstanceKlass* holder = fd->field_holder();
 789       Klass* k = SystemDictionary::find(name, Handle(THREAD, holder->class_loader()),
 790                                         Handle(THREAD, holder->protection_domain()), THREAD);
 791       assert(k != NULL && !HAS_PENDING_EXCEPTION, "can resolve klass?");
 792       ValueKlass* vk = ValueKlass::cast(k);
 793       oop obj;
 794       if (flattened) {
 795         int field_offset = fd->offset() - vk->first_field_offset();
 796         obj = (oop)((address)mirror + field_offset);
 797       } else {
 798         obj =  mirror->obj_field_acquire(fd->offset());
 799       }
 800       ValueTypeFieldPrinter print_field(_out, obj);
 801       vk->do_nonstatic_fields(&print_field);
 802       break;
 803     }
 804     default:
 805       ShouldNotReachHere();
 806   }
 807 }
 808 
 809 
 810 void ciInstanceKlass::dump_replay_data(outputStream* out) {
 811   ResourceMark rm;
 812 
 813   InstanceKlass* ik = get_instanceKlass();
 814   ConstantPool*  cp = ik->constants();
 815 
 816   // Try to record related loaded classes
 817   Klass* sub = ik->subklass();
 818   while (sub != NULL) {
 819     if (sub->is_instance_klass()) {
 820       out->print_cr("instanceKlass %s", sub->name()->as_quoted_ascii());
 821     }
 822     sub = sub->next_sibling();
 823   }
 824 
 825   // Dump out the state of the constant pool tags.  During replay the
 826   // tags will be validated for things which shouldn't change and
 827   // classes will be resolved if the tags indicate that they were


< prev index next >