< prev index next >

src/hotspot/share/ci/ciInstanceKlass.cpp

Print this page

  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.inline.hpp"
 30 #include "classfile/javaClasses.hpp"

 31 #include "classfile/vmClasses.hpp"
 32 #include "memory/allocation.hpp"
 33 #include "memory/allocation.inline.hpp"
 34 #include "memory/resourceArea.hpp"
 35 #include "oops/instanceKlass.inline.hpp"
 36 #include "oops/klass.inline.hpp"
 37 #include "oops/oop.inline.hpp"
 38 #include "oops/fieldStreams.inline.hpp"

 39 #include "runtime/fieldDescriptor.inline.hpp"
 40 #include "runtime/handles.inline.hpp"
 41 #include "runtime/jniHandles.inline.hpp"
 42 
 43 // ciInstanceKlass
 44 //
 45 // This class represents a Klass* in the HotSpot virtual machine
 46 // whose Klass part in an InstanceKlass.
 47 
 48 
 49 // ------------------------------------------------------------------
 50 // ciInstanceKlass::ciInstanceKlass
 51 //
 52 // Loaded instance klass.
 53 ciInstanceKlass::ciInstanceKlass(Klass* k) :
 54   ciKlass(k)
 55 {
 56   assert(get_Klass()->is_instance_klass(), "wrong type");
 57   assert(get_instanceKlass()->is_loaded(), "must be at least loaded");
 58   InstanceKlass* ik = get_instanceKlass();

101   }
102 
103   _has_trusted_loader = compute_has_trusted_loader();
104 
105   // Lazy fields get filled in only upon request.
106   _super  = NULL;
107   _java_mirror = NULL;
108 
109   if (is_shared()) {
110     if (k != vmClasses::Object_klass()) {
111       super();
112     }
113     //compute_nonstatic_fields();  // done outside of constructor
114   }
115 
116   _field_cache = NULL;
117 }
118 
119 // Version for unloaded classes:
120 ciInstanceKlass::ciInstanceKlass(ciSymbol* name,
121                                  jobject loader, jobject protection_domain)
122   : ciKlass(name, T_OBJECT)

123 {
124   assert(name->char_at(0) != JVM_SIGNATURE_ARRAY, "not an instance klass");
125   _init_state = (InstanceKlass::ClassState)0;
126   _has_nonstatic_fields = false;
127   _nonstatic_fields = NULL;
128   _has_injected_fields = -1;
129   _is_hidden = false;
130   _is_record = 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   _has_trusted_loader = compute_has_trusted_loader();
138 }
139 
140 
141 
142 // ------------------------------------------------------------------
143 // ciInstanceKlass::compute_shared_is_initialized
144 void ciInstanceKlass::compute_shared_init_state() {
145   GUARDED_VM_ENTRY(
146     InstanceKlass* ik = get_instanceKlass();
147     _init_state = ik->init_state();

319   if (name()->index_of_at(len+1, "/", 1) >= 0)
320     return false;
321 
322   return true;
323 }
324 
325 // ------------------------------------------------------------------
326 // ciInstanceKlass::print_impl
327 //
328 // Implementation of the print method.
329 void ciInstanceKlass::print_impl(outputStream* st) {
330   ciKlass::print_impl(st);
331   GUARDED_VM_ENTRY(st->print(" loader=" INTPTR_FORMAT, p2i(loader()));)
332   if (is_loaded()) {
333     st->print(" initialized=%s finalized=%s subklass=%s size=%d flags=",
334               bool_to_str(is_initialized()),
335               bool_to_str(has_finalizer()),
336               bool_to_str(has_subklass()),
337               layout_helper());
338 
339     _flags.print_klass_flags();
340 
341     if (_super) {
342       st->print(" super=");
343       _super->print_name();
344     }
345     if (_java_mirror) {
346       st->print(" mirror=PRESENT");
347     }
348   }
349 }
350 
351 // ------------------------------------------------------------------
352 // ciInstanceKlass::super
353 //
354 // Get the superklass of this klass.
355 ciInstanceKlass* ciInstanceKlass::super() {
356   assert(is_loaded(), "must be loaded");
357   if (_super == NULL && !is_java_lang_Object()) {
358     GUARDED_VM_ENTRY(
359       Klass* super_klass = get_instanceKlass()->super();
360       _super = CURRENT_ENV->get_instance_klass(super_klass);
361     )
362   }
363   return _super;

417       ciField* field = _nonstatic_fields->at(i);
418       int  field_off = field->offset_in_bytes();
419       if (field_off == field_offset)
420         return field;
421       if (field_off > field_offset)
422         break;
423       // could do binary search or check bins, but probably not worth it
424     }
425     return NULL;
426   }
427   VM_ENTRY_MARK;
428   InstanceKlass* k = get_instanceKlass();
429   fieldDescriptor fd;
430   if (!k->find_field_from_offset(field_offset, is_static, &fd)) {
431     return NULL;
432   }
433   ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
434   return field;
435 }
436 























437 // ------------------------------------------------------------------
438 // ciInstanceKlass::get_field_by_name
439 ciField* ciInstanceKlass::get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static) {
440   VM_ENTRY_MARK;
441   InstanceKlass* k = get_instanceKlass();
442   fieldDescriptor fd;
443   Klass* def = k->find_field(name->get_symbol(), signature->get_symbol(), is_static, &fd);
444   if (def == NULL) {
445     return NULL;
446   }
447   ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
448   return field;
449 }
450 
451 
452 static int sort_field_by_offset(ciField** a, ciField** b) {
453   return (*a)->offset_in_bytes() - (*b)->offset_in_bytes();
454   // (no worries about 32-bit overflow...)
455 }
456 

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

524   fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, NULL);
525   if (super_fields != NULL) {
526     fields->appendAll(super_fields);
527   }
528 
529   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
530     if (fs.access_flags().is_static())  continue;
531     fieldDescriptor& fd = fs.field_descriptor();
532     ciField* field = new (arena) ciField(&fd);
533     fields->append(field);




















534   }
535   assert(fields->length() == flen, "sanity");



536   return fields;
537 }
538 
539 bool ciInstanceKlass::compute_injected_fields_helper() {
540   ASSERT_IN_VM;
541   InstanceKlass* k = get_instanceKlass();
542 
543   for (InternalFieldStream fs(k); !fs.done(); fs.next()) {
544     if (fs.access_flags().is_static())  continue;
545     return true;
546   }
547   return false;
548 }
549 
550 void ciInstanceKlass::compute_injected_fields() {
551   assert(is_loaded(), "must be loaded");
552 
553   int has_injected_fields = 0;
554   if (super() != NULL && super()->has_injected_fields()) {
555     has_injected_fields = 1;

622     } else {
623       // Go into the VM to fetch the implementor.
624       VM_ENTRY_MARK;
625       MutexLocker ml(Compile_lock);
626       Klass* k = get_instanceKlass()->implementor();
627       if (k != NULL) {
628         if (k == get_instanceKlass()) {
629           // More than one implementors. Use 'this' in this case.
630           impl = this;
631         } else {
632           impl = CURRENT_THREAD_ENV->get_instance_klass(k);
633         }
634       }
635     }
636     // Memoize this result.
637     _implementor = impl;
638   }
639   return impl;
640 }
641 
















642 // Utility class for printing of the contents of the static fields for
643 // use by compilation replay.  It only prints out the information that
644 // could be consumed by the compiler, so for primitive types it prints
645 // out the actual value.  For Strings it's the actual string value.
646 // For array types it it's first level array size since that's the
647 // only value which statically unchangeable.  For all other reference
648 // types it simply prints out the dynamic type.
649 
650 class StaticFinalFieldPrinter : public FieldClosure {

651   outputStream* _out;








652   const char*   _holder;
653  public:
654   StaticFinalFieldPrinter(outputStream* out, const char* holder) :
655     _out(out),
656     _holder(holder) {
657   }
658   void do_field(fieldDescriptor* fd) {
659     if (fd->is_final() && !fd->has_initial_value()) {
660       ResourceMark rm;
661       oop mirror = fd->field_holder()->java_mirror();
662       _out->print("staticfield %s %s %s ", _holder, fd->name()->as_quoted_ascii(), fd->signature()->as_quoted_ascii());
663       switch (fd->field_type()) {
664         case T_BYTE:    _out->print_cr("%d", mirror->byte_field(fd->offset()));   break;
665         case T_BOOLEAN: _out->print_cr("%d", mirror->bool_field(fd->offset()));   break;
666         case T_SHORT:   _out->print_cr("%d", mirror->short_field(fd->offset()));  break;
667         case T_CHAR:    _out->print_cr("%d", mirror->char_field(fd->offset()));   break;
668         case T_INT:     _out->print_cr("%d", mirror->int_field(fd->offset()));    break;
669         case T_LONG:    _out->print_cr(INT64_FORMAT, (int64_t)(mirror->long_field(fd->offset())));   break;
670         case T_FLOAT: {
671           float f = mirror->float_field(fd->offset());
672           _out->print_cr("%d", *(int*)&f);
673           break;
674         }
675         case T_DOUBLE: {
676           double d = mirror->double_field(fd->offset());
677           _out->print_cr(INT64_FORMAT, *(int64_t*)&d);
678           break;
679         }
680         case T_ARRAY:  // fall-through
681         case T_OBJECT: {
682           oop value =  mirror->obj_field_acquire(fd->offset());
683           if (value == NULL) {
684             _out->print_cr("null");
685           } else if (value->is_instance()) {
686             assert(fd->field_type() == T_OBJECT, "");
687             if (value->is_a(vmClasses::String_klass())) {
688               const char* ascii_value = java_lang_String::as_quoted_ascii(value);
689               _out->print_cr("\"%s\"", (ascii_value != NULL) ? ascii_value : "");
690             } else {
691               const char* klass_name  = value->klass()->name()->as_quoted_ascii();
692               _out->print_cr("%s", klass_name);
693             }
694           } else if (value->is_array()) {
695             typeArrayOop ta = (typeArrayOop)value;
696             _out->print("%d", ta->length());
697             if (value->is_objArray()) {
698               objArrayOop oa = (objArrayOop)value;
699               const char* klass_name  = value->klass()->name()->as_quoted_ascii();
700               _out->print(" %s", klass_name);
701             }
702             _out->cr();
703           } else {
704             ShouldNotReachHere();
705           }
706           break;












707         }
708         default:
709           ShouldNotReachHere();





710         }




711     }

























712   }
713 };
714 
715 const char *ciInstanceKlass::replay_name() const {
716   return CURRENT_ENV->replay_name(get_instanceKlass());
717 }
718 
719 void ciInstanceKlass::dump_replay_instanceKlass(outputStream* out, InstanceKlass* ik) {
720   if (ik->is_hidden()) {
721     const char *name = CURRENT_ENV->dyno_name(ik);
722     if (name != NULL) {
723       out->print_cr("instanceKlass %s # %s", name, ik->name()->as_quoted_ascii());
724     } else {
725       out->print_cr("# instanceKlass %s", ik->name()->as_quoted_ascii());
726     }
727   } else {
728     out->print_cr("instanceKlass %s", ik->name()->as_quoted_ascii());
729   }
730 }
731 
732 void ciInstanceKlass::dump_replay_data(outputStream* out) {
733   ResourceMark rm;

  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/ciInlineKlass.hpp"
 28 #include "ci/ciInstance.hpp"
 29 #include "ci/ciInstanceKlass.hpp"
 30 #include "ci/ciUtilities.inline.hpp"
 31 #include "classfile/javaClasses.hpp"
 32 #include "classfile/systemDictionary.hpp"
 33 #include "classfile/vmClasses.hpp"
 34 #include "memory/allocation.hpp"
 35 #include "memory/allocation.inline.hpp"
 36 #include "memory/resourceArea.hpp"
 37 #include "oops/instanceKlass.inline.hpp"
 38 #include "oops/klass.inline.hpp"
 39 #include "oops/oop.inline.hpp"
 40 #include "oops/fieldStreams.inline.hpp"
 41 #include "oops/inlineKlass.inline.hpp"
 42 #include "runtime/fieldDescriptor.inline.hpp"
 43 #include "runtime/handles.inline.hpp"
 44 #include "runtime/jniHandles.inline.hpp"
 45 
 46 // ciInstanceKlass
 47 //
 48 // This class represents a Klass* in the HotSpot virtual machine
 49 // whose Klass part in an InstanceKlass.
 50 
 51 
 52 // ------------------------------------------------------------------
 53 // ciInstanceKlass::ciInstanceKlass
 54 //
 55 // Loaded instance klass.
 56 ciInstanceKlass::ciInstanceKlass(Klass* k) :
 57   ciKlass(k)
 58 {
 59   assert(get_Klass()->is_instance_klass(), "wrong type");
 60   assert(get_instanceKlass()->is_loaded(), "must be at least loaded");
 61   InstanceKlass* ik = get_instanceKlass();

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

323   if (name()->index_of_at(len+1, "/", 1) >= 0)
324     return false;
325 
326   return true;
327 }
328 
329 // ------------------------------------------------------------------
330 // ciInstanceKlass::print_impl
331 //
332 // Implementation of the print method.
333 void ciInstanceKlass::print_impl(outputStream* st) {
334   ciKlass::print_impl(st);
335   GUARDED_VM_ENTRY(st->print(" loader=" INTPTR_FORMAT, p2i(loader()));)
336   if (is_loaded()) {
337     st->print(" initialized=%s finalized=%s subklass=%s size=%d flags=",
338               bool_to_str(is_initialized()),
339               bool_to_str(has_finalizer()),
340               bool_to_str(has_subklass()),
341               layout_helper());
342 
343     _flags.print_klass_flags(st);
344 
345     if (_super) {
346       st->print(" super=");
347       _super->print_name_on(st);
348     }
349     if (_java_mirror) {
350       st->print(" mirror=PRESENT");
351     }
352   }
353 }
354 
355 // ------------------------------------------------------------------
356 // ciInstanceKlass::super
357 //
358 // Get the superklass of this klass.
359 ciInstanceKlass* ciInstanceKlass::super() {
360   assert(is_loaded(), "must be loaded");
361   if (_super == NULL && !is_java_lang_Object()) {
362     GUARDED_VM_ENTRY(
363       Klass* super_klass = get_instanceKlass()->super();
364       _super = CURRENT_ENV->get_instance_klass(super_klass);
365     )
366   }
367   return _super;

421       ciField* field = _nonstatic_fields->at(i);
422       int  field_off = field->offset_in_bytes();
423       if (field_off == field_offset)
424         return field;
425       if (field_off > field_offset)
426         break;
427       // could do binary search or check bins, but probably not worth it
428     }
429     return NULL;
430   }
431   VM_ENTRY_MARK;
432   InstanceKlass* k = get_instanceKlass();
433   fieldDescriptor fd;
434   if (!k->find_field_from_offset(field_offset, is_static, &fd)) {
435     return NULL;
436   }
437   ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
438   return field;
439 }
440 
441 ciField* ciInstanceKlass::get_non_flattened_field_by_offset(int field_offset) {
442   if (super() != NULL && super()->has_nonstatic_fields()) {
443     ciField* f = super()->get_non_flattened_field_by_offset(field_offset);
444     if (f != NULL) {
445       return f;
446     }
447   }
448 
449   VM_ENTRY_MARK;
450   InstanceKlass* k = get_instanceKlass();
451   Arena* arena = CURRENT_ENV->arena();
452   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
453     if (fs.access_flags().is_static())  continue;
454     fieldDescriptor& fd = fs.field_descriptor();
455     if (fd.offset() == field_offset) {
456       ciField* f = new (arena) ciField(&fd);
457       return f;
458     }
459   }
460 
461   return NULL;
462 }
463 
464 // ------------------------------------------------------------------
465 // ciInstanceKlass::get_field_by_name
466 ciField* ciInstanceKlass::get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static) {
467   VM_ENTRY_MARK;
468   InstanceKlass* k = get_instanceKlass();
469   fieldDescriptor fd;
470   Klass* def = k->find_field(name->get_symbol(), signature->get_symbol(), is_static, &fd);
471   if (def == NULL) {
472     return NULL;
473   }
474   ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
475   return field;
476 }
477 
478 
479 static int sort_field_by_offset(ciField** a, ciField** b) {
480   return (*a)->offset_in_bytes() - (*b)->offset_in_bytes();
481   // (no worries about 32-bit overflow...)
482 }
483 

502     int super_flen   = super->nof_nonstatic_fields();
503     super_fields = super->_nonstatic_fields;
504     assert(super_flen == 0 || super_fields != NULL, "first get nof_fields");
505   }
506 
507   GrowableArray<ciField*>* fields = NULL;
508   GUARDED_VM_ENTRY({
509       fields = compute_nonstatic_fields_impl(super_fields);
510     });
511 
512   if (fields == NULL) {
513     // This can happen if this class (java.lang.Class) has invisible fields.
514     if (super_fields != NULL) {
515       _nonstatic_fields = super_fields;
516       return super_fields->length();
517     } else {
518       return 0;
519     }
520   }
521 





522   _nonstatic_fields = fields;
523   return fields->length();
524 }
525 
526 GrowableArray<ciField*>* ciInstanceKlass::compute_nonstatic_fields_impl(GrowableArray<ciField*>* super_fields, bool flatten) {


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

666     } else {
667       // Go into the VM to fetch the implementor.
668       VM_ENTRY_MARK;
669       MutexLocker ml(Compile_lock);
670       Klass* k = get_instanceKlass()->implementor();
671       if (k != NULL) {
672         if (k == get_instanceKlass()) {
673           // More than one implementors. Use 'this' in this case.
674           impl = this;
675         } else {
676           impl = CURRENT_THREAD_ENV->get_instance_klass(k);
677         }
678       }
679     }
680     // Memoize this result.
681     _implementor = impl;
682   }
683   return impl;
684 }
685 
686 bool ciInstanceKlass::can_be_inline_klass(bool is_exact) {
687   if (!EnableValhalla) {
688     return false;
689   }
690   if (!is_loaded() || is_inlinetype()) {
691     // Not loaded or known to be an inline klass
692     return true;
693   }
694   if (!is_exact) {
695     // Not exact, check if this is a valid super for an inline klass
696     VM_ENTRY_MARK;
697     return !get_instanceKlass()->carries_identity_modifier();
698   }
699   return false;
700 }
701 
702 // Utility class for printing of the contents of the static fields for
703 // use by compilation replay.  It only prints out the information that
704 // could be consumed by the compiler, so for primitive types it prints
705 // out the actual value.  For Strings it's the actual string value.
706 // For array types it it's first level array size since that's the
707 // only value which statically unchangeable.  For all other reference
708 // types it simply prints out the dynamic type.
709 
710 class StaticFieldPrinter : public FieldClosure {
711 protected:
712   outputStream* _out;
713 public:
714   StaticFieldPrinter(outputStream* out) :
715     _out(out) {
716   }
717   void do_field_helper(fieldDescriptor* fd, oop obj, bool flattened);
718 };
719 
720 class StaticFinalFieldPrinter : public StaticFieldPrinter {
721   const char*   _holder;
722  public:
723   StaticFinalFieldPrinter(outputStream* out, const char* holder) :
724     StaticFieldPrinter(out), _holder(holder) {

725   }
726   void do_field(fieldDescriptor* fd) {
727     if (fd->is_final() && !fd->has_initial_value()) {
728       ResourceMark rm;
729       InstanceKlass* holder = fd->field_holder();
730       oop mirror = holder->java_mirror();
731       _out->print("staticfield %s %s ", _holder, fd->name()->as_quoted_ascii());
732       BasicType bt = fd->field_type();
733       if (bt != T_OBJECT && bt != T_ARRAY) {
734         _out->print("%s ", fd->signature()->as_quoted_ascii());
735       }
736       do_field_helper(fd, mirror, false);
737       _out->cr();
738     }
739   }
740 };
741 
742 class InlineTypeFieldPrinter : public StaticFieldPrinter {
743   oop _obj;
744 public:
745   InlineTypeFieldPrinter(outputStream* out, oop obj) :
746     StaticFieldPrinter(out), _obj(obj) {
747   }
748   void do_field(fieldDescriptor* fd) {
749     do_field_helper(fd, _obj, true);
750     _out->print(" ");
751   }
752 };
753 
754 void StaticFieldPrinter::do_field_helper(fieldDescriptor* fd, oop mirror, bool flattened) {
755   BasicType bt = fd->field_type();
756   switch (bt) {
757     case T_BYTE:    _out->print("%d", mirror->byte_field(fd->offset()));   break;
758     case T_BOOLEAN: _out->print("%d", mirror->bool_field(fd->offset()));   break;
759     case T_SHORT:   _out->print("%d", mirror->short_field(fd->offset()));  break;
760     case T_CHAR:    _out->print("%d", mirror->char_field(fd->offset()));   break;
761     case T_INT:     _out->print("%d", mirror->int_field(fd->offset()));    break;
762     case T_LONG:    _out->print(INT64_FORMAT, (int64_t)(mirror->long_field(fd->offset())));   break;
763     case T_FLOAT: {
764       float f = mirror->float_field(fd->offset());
765       _out->print("%d", *(int*)&f);
766       break;
767     }
768     case T_DOUBLE: {
769       double d = mirror->double_field(fd->offset());
770       _out->print(INT64_FORMAT, *(int64_t*)&d);
771       break;
772     }
773     case T_ARRAY:  // fall-through
774     case T_OBJECT: {
775       _out->print("%s ", fd->signature()->as_quoted_ascii());
776       oop value =  mirror->obj_field_acquire(fd->offset());
777       if (value == NULL) {
778         _out->print_cr("null");
779       } else if (value->is_instance()) {
780         assert(fd->field_type() == T_OBJECT, "");
781         if (value->is_a(vmClasses::String_klass())) {
782           const char* ascii_value = java_lang_String::as_quoted_ascii(value);
783           _out->print("\"%s\"", (ascii_value != NULL) ? ascii_value : "");
784          } else {
785           const char* klass_name  = value->klass()->name()->as_quoted_ascii();
786           _out->print("%s", klass_name);
787         }
788       } else if (value->is_array()) {
789         typeArrayOop ta = (typeArrayOop)value;
790         _out->print("%d", ta->length());
791         if (value->is_objArray() || value->is_flatArray()) {
792           objArrayOop oa = (objArrayOop)value;
793           const char* klass_name  = value->klass()->name()->as_quoted_ascii();
794           _out->print(" %s", klass_name);
795         }
796       } else {
797         ShouldNotReachHere();
798       }
799       break;
800     }
801     case T_PRIMITIVE_OBJECT: {
802       ResetNoHandleMark rnhm;
803       Thread* THREAD = Thread::current();
804       SignatureStream ss(fd->signature(), false);
805       Symbol* name = ss.as_symbol();
806       assert(!HAS_PENDING_EXCEPTION, "can resolve klass?");
807       InstanceKlass* holder = fd->field_holder();
808       InstanceKlass* k = SystemDictionary::find_instance_klass(THREAD, name,
809                                                                Handle(THREAD, holder->class_loader()),
810                                                                Handle(THREAD, holder->protection_domain()));
811       assert(k != NULL && !HAS_PENDING_EXCEPTION, "can resolve klass?");
812       InlineKlass* vk = InlineKlass::cast(k);
813       oop obj;
814       if (flattened) {
815         int field_offset = fd->offset() - vk->first_field_offset();
816         obj = cast_to_oop(cast_from_oop<address>(mirror) + field_offset);
817       } else {
818         obj = mirror->obj_field_acquire(fd->offset());
819       }
820       InlineTypeFieldPrinter print_field(_out, obj);
821       vk->do_nonstatic_fields(&print_field);
822       break;
823     }
824     default:
825       ShouldNotReachHere();
826   }
827 }
828 
829 const char *ciInstanceKlass::replay_name() const {
830   return CURRENT_ENV->replay_name(get_instanceKlass());
831 }
832 
833 void ciInstanceKlass::dump_replay_instanceKlass(outputStream* out, InstanceKlass* ik) {
834   if (ik->is_hidden()) {
835     const char *name = CURRENT_ENV->dyno_name(ik);
836     if (name != NULL) {
837       out->print_cr("instanceKlass %s # %s", name, ik->name()->as_quoted_ascii());
838     } else {
839       out->print_cr("# instanceKlass %s", ik->name()->as_quoted_ascii());
840     }
841   } else {
842     out->print_cr("instanceKlass %s", ik->name()->as_quoted_ascii());
843   }
844 }
845 
846 void ciInstanceKlass::dump_replay_data(outputStream* out) {
847   ResourceMark rm;
< prev index next >