< 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();

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

124 {
125   assert(name->char_at(0) != JVM_SIGNATURE_ARRAY, "not an instance klass");
126   _init_state = (InstanceKlass::ClassState)0;
127   _has_nonstatic_fields = false;
128   _nonstatic_fields = nullptr;
129   _has_injected_fields = -1;
130   _is_hidden = false;
131   _is_record = false;
132   _loader = loader;
133   _protection_domain = protection_domain;
134   _is_shared = false;
135   _super = nullptr;
136   _java_mirror = nullptr;
137   _field_cache = nullptr;
138   _has_trusted_loader = compute_has_trusted_loader();
139 }
140 
141 
142 
143 // ------------------------------------------------------------------
144 // ciInstanceKlass::compute_shared_is_initialized
145 void ciInstanceKlass::compute_shared_init_state() {
146   GUARDED_VM_ENTRY(
147     InstanceKlass* ik = get_instanceKlass();
148     _init_state = ik->init_state();

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

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























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

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




















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



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

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
















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

652   outputStream* _out;








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













708           } else {
709             ShouldNotReachHere();

710           }
711           break;
712         }
713         default:






714           ShouldNotReachHere();
715         }
716     }


























717   }
718 };
719 
720 const char *ciInstanceKlass::replay_name() const {
721   return CURRENT_ENV->replay_name(get_instanceKlass());
722 }
723 
724 void ciInstanceKlass::dump_replay_instanceKlass(outputStream* out, InstanceKlass* ik) {
725   if (ik->is_hidden()) {
726     const char *name = CURRENT_ENV->dyno_name(ik);
727     if (name != nullptr) {
728       out->print_cr("instanceKlass %s # %s", name, ik->name()->as_quoted_ascii());
729     } else {
730       out->print_cr("# instanceKlass %s", ik->name()->as_quoted_ascii());
731     }
732   } else {
733     out->print_cr("instanceKlass %s", ik->name()->as_quoted_ascii());
734   }
735 }
736 
737 GrowableArray<ciInstanceKlass*>* ciInstanceKlass::transitive_interfaces() const{
738   if (_transitive_interfaces == nullptr) {

  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();

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

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

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

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





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


528   ASSERT_IN_VM;
529   Arena* arena = CURRENT_ENV->arena();
530   int flen = 0;
531   GrowableArray<ciField*>* fields = nullptr;
532   InstanceKlass* k = get_instanceKlass();
533   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
534     if (fs.access_flags().is_static())  continue;
535     flen += 1;
536   }
537 
538   // allocate the array:
539   if (flen == 0) {
540     return nullptr;  // return nothing if none are locally declared
541   }
542   if (super_fields != nullptr) {
543     flen += super_fields->length();
544   }
545   fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, nullptr);
546   if (super_fields != nullptr) {
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_flat() && is_flat) {
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 flat inline type and copy them to 'this'
561       for (int i = 0; i < vk->nof_nonstatic_fields(); ++i) {
562         ciField* flat_field = vk->nonstatic_field_at(i);
563         // Adjust offset to account for missing oop header
564         int offset = field_offset + (flat_field->offset_in_bytes() - vk->first_field_offset());
565         // A flat field can be treated as final if the non-flat
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(flat_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() != nullptr && 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       InstanceKlass* ik = get_instanceKlass();
670       Klass* implk = ik->implementor();
671       if (implk != nullptr) {
672         if (implk == ik) {
673           // More than one implementors. Use 'this' in this case.
674           impl = this;
675         } else {
676           impl = CURRENT_THREAD_ENV->get_instance_klass(implk);
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()->access_flags().is_identity_class() || is_java_lang_Object() ;
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 is_flat);
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 is_flat) {
755   BasicType field_type = fd->field_type();
756   switch (field_type) {
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       if (!fd->is_null_free_inline_type()) {
776         _out->print("%s ", fd->signature()->as_quoted_ascii());
777         oop value =  mirror->obj_field_acquire(fd->offset());
778         if (value == nullptr) {
779           if (field_type == T_ARRAY) {
780             _out->print("%d", -1);
781           }
782           _out->cr();
783         } else if (value->is_instance()) {
784           assert(field_type == T_OBJECT, "");
785           if (value->is_a(vmClasses::String_klass())) {
786             const char* ascii_value = java_lang_String::as_quoted_ascii(value);
787             _out->print("\"%s\"", (ascii_value != nullptr) ? ascii_value : "");
788           } else {
789             const char* klass_name  = value->klass()->name()->as_quoted_ascii();
790             _out->print("%s", klass_name);
791           }
792         } else if (value->is_array()) {
793           typeArrayOop ta = (typeArrayOop)value;
794           _out->print("%d", ta->length());
795           if (value->is_objArray() || value->is_flatArray()) {
796             objArrayOop oa = (objArrayOop)value;
797             const char* klass_name  = value->klass()->name()->as_quoted_ascii();
798             _out->print(" %s", klass_name);
799           }
800         } else {
801           ShouldNotReachHere();
802         }
803         break;
804       } else {
805         // handling of null free inline type
806         ResetNoHandleMark rnhm;
807         Thread* THREAD = Thread::current();
808         SignatureStream ss(fd->signature(), false);
809         Symbol* name = ss.as_symbol();
810         assert(!HAS_PENDING_EXCEPTION, "can resolve klass?");
811         InstanceKlass* holder = fd->field_holder();
812         InstanceKlass* k = SystemDictionary::find_instance_klass(THREAD, name,
813                                                                  Handle(THREAD, holder->class_loader()),
814                                                                  Handle(THREAD, holder->protection_domain()));
815         assert(k != nullptr && !HAS_PENDING_EXCEPTION, "can resolve klass?");
816         InlineKlass* vk = InlineKlass::cast(k);
817         oop obj;
818         if (is_flat) {
819           int field_offset = fd->offset() - vk->first_field_offset();
820           obj = cast_to_oop(cast_from_oop<address>(mirror) + field_offset);
821         } else {
822           obj = mirror->obj_field_acquire(fd->offset());
823         }
824         InlineTypeFieldPrinter print_field(_out, obj);
825         vk->do_nonstatic_fields(&print_field);
826         break;
827       }
828     default:
829       ShouldNotReachHere();
830   }
831 }
832 
833 const char *ciInstanceKlass::replay_name() const {
834   return CURRENT_ENV->replay_name(get_instanceKlass());
835 }
836 
837 void ciInstanceKlass::dump_replay_instanceKlass(outputStream* out, InstanceKlass* ik) {
838   if (ik->is_hidden()) {
839     const char *name = CURRENT_ENV->dyno_name(ik);
840     if (name != nullptr) {
841       out->print_cr("instanceKlass %s # %s", name, ik->name()->as_quoted_ascii());
842     } else {
843       out->print_cr("# instanceKlass %s", ik->name()->as_quoted_ascii());
844     }
845   } else {
846     out->print_cr("instanceKlass %s", ik->name()->as_quoted_ascii());
847   }
848 }
849 
850 GrowableArray<ciInstanceKlass*>* ciInstanceKlass::transitive_interfaces() const{
851   if (_transitive_interfaces == nullptr) {
< prev index next >