< prev index next >

src/hotspot/share/ci/ciInstanceKlass.cpp

Print this page

  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "ci/ciField.hpp"

 26 #include "ci/ciInstance.hpp"
 27 #include "ci/ciInstanceKlass.hpp"
 28 #include "ci/ciUtilities.inline.hpp"
 29 #include "classfile/javaClasses.hpp"

 30 #include "classfile/vmClasses.hpp"
 31 #include "memory/allocation.hpp"
 32 #include "memory/allocation.inline.hpp"
 33 #include "memory/resourceArea.hpp"
 34 #include "oops/instanceKlass.inline.hpp"
 35 #include "oops/klass.inline.hpp"
 36 #include "oops/oop.inline.hpp"
 37 #include "oops/fieldStreams.inline.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();

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

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

301   if (name()->index_of_at(len+1, "/", 1) >= 0)
302     return false;
303 
304   return true;
305 }
306 
307 // ------------------------------------------------------------------
308 // ciInstanceKlass::print_impl
309 //
310 // Implementation of the print method.
311 void ciInstanceKlass::print_impl(outputStream* st) {
312   ciKlass::print_impl(st);
313   GUARDED_VM_ENTRY(st->print(" loader=" INTPTR_FORMAT, p2i(loader()));)
314   if (is_loaded()) {
315     st->print(" initialized=%s finalized=%s subklass=%s size=%d flags=",
316               bool_to_str(is_initialized()),
317               bool_to_str(has_finalizer()),
318               bool_to_str(has_subklass()),
319               layout_helper());
320 
321     _flags.print_klass_flags();
322 
323     if (_super) {
324       st->print(" super=");
325       _super->print_name();
326     }
327     if (_java_mirror) {
328       st->print(" mirror=PRESENT");
329     }
330   }
331 }
332 
333 // ------------------------------------------------------------------
334 // ciInstanceKlass::super
335 //
336 // Get the superklass of this klass.
337 ciInstanceKlass* ciInstanceKlass::super() {
338   assert(is_loaded(), "must be loaded");
339   if (_super == nullptr && !is_java_lang_Object()) {
340     GUARDED_VM_ENTRY(
341       Klass* super_klass = get_instanceKlass()->super();
342       _super = CURRENT_ENV->get_instance_klass(super_klass);
343     )
344   }
345   return _super;

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 nullptr;
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 nullptr;
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 == nullptr) {
427     return nullptr;
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 

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




















516   }
517   assert(fields->length() == flen, "sanity");



518   return fields;
519 }
520 
521 bool ciInstanceKlass::compute_injected_fields_helper() {
522   ASSERT_IN_VM;
523   InstanceKlass* k = get_instanceKlass();
524 
525   for (InternalFieldStream fs(k); !fs.done(); fs.next()) {
526     if (fs.access_flags().is_static())  continue;
527     return true;
528   }
529   return false;
530 }
531 
532 void ciInstanceKlass::compute_injected_fields() {
533   assert(is_loaded(), "must be loaded");
534 
535   int has_injected_fields = 0;
536   if (super() != nullptr && super()->has_injected_fields()) {
537     has_injected_fields = 1;

604     } else {
605       // Go into the VM to fetch the implementor.
606       VM_ENTRY_MARK;
607       InstanceKlass* ik = get_instanceKlass();
608       Klass* implk = ik->implementor();
609       if (implk != nullptr) {
610         if (implk == ik) {
611           // More than one implementors. Use 'this' in this case.
612           impl = this;
613         } else {
614           impl = CURRENT_THREAD_ENV->get_instance_klass(implk);
615         }
616       }
617     }
618     // Memoize this result.
619     _implementor = impl;
620   }
621   return impl;
622 }
623 
















624 // Utility class for printing of the contents of the static fields for
625 // use by compilation replay.  It only prints out the information that
626 // could be consumed by the compiler, so for primitive types it prints
627 // out the actual value.  For Strings it's the actual string value.
628 // For array types it it's first level array size since that's the
629 // only value which statically unchangeable.  For all other reference
630 // types it simply prints out the dynamic type.
631 
632 class StaticFinalFieldPrinter : public FieldClosure {

633   outputStream* _out;








634   const char*   _holder;
635  public:
636   StaticFinalFieldPrinter(outputStream* out, const char* holder) :
637     _out(out),
638     _holder(holder) {
639   }
640   void do_field(fieldDescriptor* fd) {
641     if (fd->is_final() && !fd->has_initial_value()) {
642       ResourceMark rm;
643       oop mirror = fd->field_holder()->java_mirror();
644       _out->print("staticfield %s %s %s ", _holder, fd->name()->as_quoted_ascii(), fd->signature()->as_quoted_ascii());
645       BasicType field_type = fd->field_type();
646       switch (field_type) {
647         case T_BYTE:    _out->print_cr("%d", mirror->byte_field(fd->offset()));   break;
648         case T_BOOLEAN: _out->print_cr("%d", mirror->bool_field(fd->offset()));   break;
649         case T_SHORT:   _out->print_cr("%d", mirror->short_field(fd->offset()));  break;
650         case T_CHAR:    _out->print_cr("%d", mirror->char_field(fd->offset()));   break;
651         case T_INT:     _out->print_cr("%d", mirror->int_field(fd->offset()));    break;
652         case T_LONG:    _out->print_cr(INT64_FORMAT, (int64_t)(mirror->long_field(fd->offset())));   break;
653         case T_FLOAT: {
654           float f = mirror->float_field(fd->offset());
655           _out->print_cr("%d", *(int*)&f);
656           break;
657         }
658         case T_DOUBLE: {
659           double d = mirror->double_field(fd->offset());
660           _out->print_cr(INT64_FORMAT, *(int64_t*)&d);
661           break;
662         }
663         case T_ARRAY:  // fall-through
664         case T_OBJECT: {
665           oop value =  mirror->obj_field_acquire(fd->offset());
666           if (value == nullptr) {
667             if (field_type == T_ARRAY) {
668               _out->print("%d", -1);
669             }
670             _out->cr();
671           } else if (value->is_instance()) {
672             assert(field_type == T_OBJECT, "");
673             if (value->is_a(vmClasses::String_klass())) {
674               const char* ascii_value = java_lang_String::as_quoted_ascii(value);
675               _out->print_cr("\"%s\"", (ascii_value != nullptr) ? ascii_value : "");
676             } else {
677               const char* klass_name  = value->klass()->name()->as_quoted_ascii();
678               _out->print_cr("%s", klass_name);
679             }
680           } else if (value->is_array()) {
681             typeArrayOop ta = (typeArrayOop)value;
682             _out->print("%d", ta->length());
683             if (value->is_objArray()) {
684               objArrayOop oa = (objArrayOop)value;
685               const char* klass_name  = value->klass()->name()->as_quoted_ascii();
686               _out->print(" %s", klass_name);
687             }
688             _out->cr();













689           } else {
690             ShouldNotReachHere();

691           }
692           break;
693         }
694         default:






695           ShouldNotReachHere();
696         }
697     }

























698   }
699 };
700 
701 const char *ciInstanceKlass::replay_name() const {
702   return CURRENT_ENV->replay_name(get_instanceKlass());
703 }
704 
705 void ciInstanceKlass::dump_replay_instanceKlass(outputStream* out, InstanceKlass* ik) {
706   if (ik->is_hidden()) {
707     const char *name = CURRENT_ENV->dyno_name(ik);
708     if (name != nullptr) {
709       out->print_cr("instanceKlass %s # %s", name, ik->name()->as_quoted_ascii());
710     } else {
711       out->print_cr("# instanceKlass %s", ik->name()->as_quoted_ascii());
712     }
713   } else {
714     out->print_cr("instanceKlass %s", ik->name()->as_quoted_ascii());
715   }
716 }
717 
718 GrowableArray<ciInstanceKlass*>* ciInstanceKlass::transitive_interfaces() const{
719   if (_transitive_interfaces == nullptr) {

  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "ci/ciField.hpp"
 26 #include "ci/ciInlineKlass.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/systemDictionary.hpp"
 32 #include "classfile/vmClasses.hpp"
 33 #include "memory/allocation.hpp"
 34 #include "memory/allocation.inline.hpp"
 35 #include "memory/resourceArea.hpp"
 36 #include "oops/instanceKlass.inline.hpp"
 37 #include "oops/klass.inline.hpp"
 38 #include "oops/oop.inline.hpp"
 39 #include "oops/fieldStreams.inline.hpp"
 40 #include "oops/inlineKlass.inline.hpp"
 41 #include "runtime/fieldDescriptor.inline.hpp"
 42 #include "runtime/handles.inline.hpp"
 43 #include "runtime/jniHandles.inline.hpp"
 44 
 45 // ciInstanceKlass
 46 //
 47 // This class represents a Klass* in the HotSpot virtual machine
 48 // whose Klass part in an InstanceKlass.
 49 
 50 
 51 // ------------------------------------------------------------------
 52 // ciInstanceKlass::ciInstanceKlass
 53 //
 54 // Loaded instance klass.
 55 ciInstanceKlass::ciInstanceKlass(Klass* k) :
 56   ciKlass(k)
 57 {
 58   assert(get_Klass()->is_instance_klass(), "wrong type");
 59   assert(get_instanceKlass()->is_loaded(), "must be at least loaded");
 60   InstanceKlass* ik = get_instanceKlass();

100   }
101 
102   _has_trusted_loader = compute_has_trusted_loader();
103 
104   // Lazy fields get filled in only upon request.
105   _super  = nullptr;
106   _java_mirror = nullptr;
107 
108   if (is_shared()) {
109     if (k != vmClasses::Object_klass()) {
110       super();
111     }
112     //compute_nonstatic_fields();  // done outside of constructor
113   }
114 
115   _field_cache = nullptr;
116 }
117 
118 // Version for unloaded classes:
119 ciInstanceKlass::ciInstanceKlass(ciSymbol* name,
120                                  jobject loader,
121                                  BasicType bt)
122   : ciKlass(name, bt)
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 = nullptr;         // initialized lazily by compute_nonstatic_fields
128   _has_injected_fields = -1;
129   _is_hidden = false;
130   _is_record = false;
131   _loader = loader;
132   _is_shared = false;
133   _super = nullptr;
134   _java_mirror = nullptr;
135   _field_cache = nullptr;
136   _has_trusted_loader = compute_has_trusted_loader();
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   )

305   if (name()->index_of_at(len+1, "/", 1) >= 0)
306     return false;
307 
308   return true;
309 }
310 
311 // ------------------------------------------------------------------
312 // ciInstanceKlass::print_impl
313 //
314 // Implementation of the print method.
315 void ciInstanceKlass::print_impl(outputStream* st) {
316   ciKlass::print_impl(st);
317   GUARDED_VM_ENTRY(st->print(" loader=" INTPTR_FORMAT, p2i(loader()));)
318   if (is_loaded()) {
319     st->print(" initialized=%s finalized=%s subklass=%s size=%d flags=",
320               bool_to_str(is_initialized()),
321               bool_to_str(has_finalizer()),
322               bool_to_str(has_subklass()),
323               layout_helper());
324 
325     _flags.print_klass_flags(st);
326 
327     if (_super) {
328       st->print(" super=");
329       _super->print_name_on(st);
330     }
331     if (_java_mirror) {
332       st->print(" mirror=PRESENT");
333     }
334   }
335 }
336 
337 // ------------------------------------------------------------------
338 // ciInstanceKlass::super
339 //
340 // Get the superklass of this klass.
341 ciInstanceKlass* ciInstanceKlass::super() {
342   assert(is_loaded(), "must be loaded");
343   if (_super == nullptr && !is_java_lang_Object()) {
344     GUARDED_VM_ENTRY(
345       Klass* super_klass = get_instanceKlass()->super();
346       _super = CURRENT_ENV->get_instance_klass(super_klass);
347     )
348   }
349   return _super;

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

484     int super_flen   = super->nof_nonstatic_fields();
485     super_fields = super->_nonstatic_fields;
486     assert(super_flen == 0 || super_fields != nullptr, "first get nof_fields");
487   }
488 
489   GrowableArray<ciField*>* fields = nullptr;
490   GUARDED_VM_ENTRY({
491       fields = compute_nonstatic_fields_impl(super_fields);
492     });
493 
494   if (fields == nullptr) {
495     // This can happen if this class (java.lang.Class) has invisible fields.
496     if (super_fields != nullptr) {
497       _nonstatic_fields = super_fields;
498       return super_fields->length();
499     } else {
500       return 0;
501     }
502   }
503 





504   _nonstatic_fields = fields;
505   return fields->length();
506 }
507 
508 GrowableArray<ciField*>* ciInstanceKlass::compute_nonstatic_fields_impl(GrowableArray<ciField*>* super_fields, bool is_flat) {


509   ASSERT_IN_VM;
510   Arena* arena = CURRENT_ENV->arena();
511   int flen = 0;
512   GrowableArray<ciField*>* fields = nullptr;
513   InstanceKlass* k = get_instanceKlass();
514   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
515     if (fs.access_flags().is_static())  continue;
516     flen += 1;
517   }
518 
519   // allocate the array:
520   if (flen == 0 && !is_inlinetype()) {
521     return nullptr;  // return nothing if none are locally declared
522   }
523   if (super_fields != nullptr) {
524     flen += super_fields->length();
525   }
526   fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, nullptr);
527   if (super_fields != nullptr) {
528     fields->appendAll(super_fields);
529   }
530 
531   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
532     if (fs.access_flags().is_static())  continue;
533     fieldDescriptor& fd = fs.field_descriptor();
534     if (fd.is_flat() && is_flat) {
535       // Inline type fields are embedded
536       int field_offset = fd.offset();
537       // Get InlineKlass and adjust number of fields
538       Klass* k = get_instanceKlass()->get_inline_type_field_klass(fd.index());
539       ciInlineKlass* vk = CURRENT_ENV->get_klass(k)->as_inline_klass();
540       flen += vk->nof_nonstatic_fields() - 1;
541       // Iterate over fields of the flat inline type and copy them to 'this'
542       for (int i = 0; i < vk->nof_nonstatic_fields(); ++i) {
543         ciField* flat_field = vk->nonstatic_field_at(i);
544         // Adjust offset to account for missing oop header
545         int offset = field_offset + (flat_field->offset_in_bytes() - vk->payload_offset());
546         // A flat field can be treated as final if the non-flat
547         // field is declared final or the holder klass is an inline type itself.
548         bool is_final = fd.is_final() || is_inlinetype();
549         ciField* field = new (arena) ciField(flat_field, this, offset, is_final);
550         fields->append(field);
551       }
552     } else {
553       ciField* field = new (arena) ciField(&fd);
554       fields->append(field);
555     }
556   }
557   assert(fields->length() == flen, "sanity");
558   // Now sort them by offset, ascending.
559   // (In principle, they could mix with superclass fields.)
560   fields->sort(sort_field_by_offset);
561   return fields;
562 }
563 
564 bool ciInstanceKlass::compute_injected_fields_helper() {
565   ASSERT_IN_VM;
566   InstanceKlass* k = get_instanceKlass();
567 
568   for (InternalFieldStream fs(k); !fs.done(); fs.next()) {
569     if (fs.access_flags().is_static())  continue;
570     return true;
571   }
572   return false;
573 }
574 
575 void ciInstanceKlass::compute_injected_fields() {
576   assert(is_loaded(), "must be loaded");
577 
578   int has_injected_fields = 0;
579   if (super() != nullptr && super()->has_injected_fields()) {
580     has_injected_fields = 1;

647     } else {
648       // Go into the VM to fetch the implementor.
649       VM_ENTRY_MARK;
650       InstanceKlass* ik = get_instanceKlass();
651       Klass* implk = ik->implementor();
652       if (implk != nullptr) {
653         if (implk == ik) {
654           // More than one implementors. Use 'this' in this case.
655           impl = this;
656         } else {
657           impl = CURRENT_THREAD_ENV->get_instance_klass(implk);
658         }
659       }
660     }
661     // Memoize this result.
662     _implementor = impl;
663   }
664   return impl;
665 }
666 
667 bool ciInstanceKlass::can_be_inline_klass(bool is_exact) {
668   if (!EnableValhalla) {
669     return false;
670   }
671   if (!is_loaded() || is_inlinetype()) {
672     // Not loaded or known to be an inline klass
673     return true;
674   }
675   if (!is_exact) {
676     // Not exact, check if this is a valid super for an inline klass
677     VM_ENTRY_MARK;
678     return !get_instanceKlass()->access_flags().is_identity_class() || is_java_lang_Object() ;
679   }
680   return false;
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 is_flat);
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 InlineTypeFieldPrinter : public StaticFieldPrinter {
724   oop _obj;
725 public:
726   InlineTypeFieldPrinter(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 is_flat) {
736   BasicType field_type = fd->field_type();
737   switch (field_type) {
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       if (!fd->is_null_free_inline_type()) {
757         _out->print("%s ", fd->signature()->as_quoted_ascii());
758         oop value =  mirror->obj_field_acquire(fd->offset());
759         if (value == nullptr) {
760           if (field_type == T_ARRAY) {
761             _out->print("%d", -1);
762           }
763           _out->cr();
764         } else if (value->is_instance()) {
765           assert(field_type == T_OBJECT, "");
766           if (value->is_a(vmClasses::String_klass())) {
767             const char* ascii_value = java_lang_String::as_quoted_ascii(value);
768             _out->print("\"%s\"", (ascii_value != nullptr) ? ascii_value : "");
769           } else {
770             const char* klass_name  = value->klass()->name()->as_quoted_ascii();
771             _out->print("%s", klass_name);
772           }
773         } else if (value->is_array()) {
774           typeArrayOop ta = (typeArrayOop)value;
775           _out->print("%d", ta->length());
776           if (value->is_objArray() || value->is_flatArray()) {
777             objArrayOop oa = (objArrayOop)value;
778             const char* klass_name  = value->klass()->name()->as_quoted_ascii();
779             _out->print(" %s", klass_name);
780           }
781         } else {
782           ShouldNotReachHere();
783         }
784         break;
785       } else {
786         // handling of null free inline type
787         ResetNoHandleMark rnhm;
788         Thread* THREAD = Thread::current();
789         SignatureStream ss(fd->signature(), false);
790         Symbol* name = ss.as_symbol();
791         assert(!HAS_PENDING_EXCEPTION, "can resolve klass?");
792         InstanceKlass* holder = fd->field_holder();
793         InstanceKlass* k = SystemDictionary::find_instance_klass(THREAD, name,
794                                                                  Handle(THREAD, holder->class_loader()));
795         assert(k != nullptr && !HAS_PENDING_EXCEPTION, "can resolve klass?");
796         InlineKlass* vk = InlineKlass::cast(k);
797         oop obj;
798         if (is_flat) {
799           int field_offset = fd->offset() - vk->payload_offset();
800           obj = cast_to_oop(cast_from_oop<address>(mirror) + field_offset);
801         } else {
802           obj = mirror->obj_field_acquire(fd->offset());
803         }
804         InlineTypeFieldPrinter print_field(_out, obj);
805         vk->do_nonstatic_fields(&print_field);
806         break;
807       }
808     default:
809       ShouldNotReachHere();
810   }
811 }
812 
813 const char *ciInstanceKlass::replay_name() const {
814   return CURRENT_ENV->replay_name(get_instanceKlass());
815 }
816 
817 void ciInstanceKlass::dump_replay_instanceKlass(outputStream* out, InstanceKlass* ik) {
818   if (ik->is_hidden()) {
819     const char *name = CURRENT_ENV->dyno_name(ik);
820     if (name != nullptr) {
821       out->print_cr("instanceKlass %s # %s", name, ik->name()->as_quoted_ascii());
822     } else {
823       out->print_cr("# instanceKlass %s", ik->name()->as_quoted_ascii());
824     }
825   } else {
826     out->print_cr("instanceKlass %s", ik->name()->as_quoted_ascii());
827   }
828 }
829 
830 GrowableArray<ciInstanceKlass*>* ciInstanceKlass::transitive_interfaces() const{
831   if (_transitive_interfaces == nullptr) {
< prev index next >