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

101     _protection_domain = JNIHandles::make_global(h_protection_domain);
102     _is_shared = true;
103   }
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   _nonstatic_field_size = -1;
127   _has_nonstatic_fields = false;
128   _nonstatic_fields = NULL;
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 = NULL;
136   _java_mirror = NULL;
137   _field_cache = NULL;
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();
148   )

344   if (name()->index_of_at(len+1, "/", 1) >= 0)
345     return false;
346 
347   return true;
348 }
349 
350 // ------------------------------------------------------------------
351 // ciInstanceKlass::print_impl
352 //
353 // Implementation of the print method.
354 void ciInstanceKlass::print_impl(outputStream* st) {
355   ciKlass::print_impl(st);
356   GUARDED_VM_ENTRY(st->print(" loader=" INTPTR_FORMAT, p2i(loader()));)
357   if (is_loaded()) {
358     st->print(" loaded=true initialized=%s finalized=%s subklass=%s size=%d flags=",
359               bool_to_str(is_initialized()),
360               bool_to_str(has_finalizer()),
361               bool_to_str(has_subklass()),
362               layout_helper());
363 
364     _flags.print_klass_flags();
365 
366     if (_super) {
367       st->print(" super=");
368       _super->print_name();
369     }
370     if (_java_mirror) {
371       st->print(" mirror=PRESENT");
372     }
373   } else {
374     st->print(" loaded=false");
375   }
376 }
377 
378 // ------------------------------------------------------------------
379 // ciInstanceKlass::super
380 //
381 // Get the superklass of this klass.
382 ciInstanceKlass* ciInstanceKlass::super() {
383   assert(is_loaded(), "must be loaded");
384   if (_super == NULL && !is_java_lang_Object()) {
385     GUARDED_VM_ENTRY(
386       Klass* super_klass = get_instanceKlass()->super();
387       _super = CURRENT_ENV->get_instance_klass(super_klass);
388     )

444       ciField* field = _nonstatic_fields->at(i);
445       int  field_off = field->offset_in_bytes();
446       if (field_off == field_offset)
447         return field;
448       if (field_off > field_offset)
449         break;
450       // could do binary search or check bins, but probably not worth it
451     }
452     return NULL;
453   }
454   VM_ENTRY_MARK;
455   InstanceKlass* k = get_instanceKlass();
456   fieldDescriptor fd;
457   if (!k->find_field_from_offset(field_offset, is_static, &fd)) {
458     return NULL;
459   }
460   ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
461   return field;
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 

505     int super_flen   = super->nof_nonstatic_fields();
506     super_fields = super->_nonstatic_fields;
507     assert(super_flen == 0 || super_fields != NULL, "first get nof_fields");
508   }
509 
510   GrowableArray<ciField*>* fields = NULL;
511   GUARDED_VM_ENTRY({
512       fields = compute_nonstatic_fields_impl(super_fields);
513     });
514 
515   if (fields == NULL) {
516     // This can happen if this class (java.lang.Class) has invisible fields.
517     if (super_fields != NULL) {
518       _nonstatic_fields = super_fields;
519       return super_fields->length();
520     } else {
521       return 0;
522     }
523   }
524 
525   int flen = fields->length();
526 
527   // Now sort them by offset, ascending.
528   // (In principle, they could mix with superclass fields.)
529   fields->sort(sort_field_by_offset);
530   _nonstatic_fields = fields;
531   return flen;
532 }
533 
534 GrowableArray<ciField*>*
535 ciInstanceKlass::compute_nonstatic_fields_impl(GrowableArray<ciField*>*
536                                                super_fields) {
537   ASSERT_IN_VM;
538   Arena* arena = CURRENT_ENV->arena();
539   int flen = 0;
540   GrowableArray<ciField*>* fields = NULL;
541   InstanceKlass* k = get_instanceKlass();
542   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
543     if (fs.access_flags().is_static())  continue;
544     flen += 1;
545   }
546 
547   // allocate the array:
548   if (flen == 0) {
549     return NULL;  // return nothing if none are locally declared
550   }
551   if (super_fields != NULL) {
552     flen += super_fields->length();
553   }

554   fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, NULL);
555   if (super_fields != NULL) {
556     fields->appendAll(super_fields);
557   }
558 
559   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
560     if (fs.access_flags().is_static())  continue;
561     fieldDescriptor& fd = fs.field_descriptor();
562     ciField* field = new (arena) ciField(&fd);
563     fields->append(field);




















564   }
565   assert(fields->length() == flen, "sanity");



566   return fields;
567 }
568 
569 bool ciInstanceKlass::compute_injected_fields_helper() {
570   ASSERT_IN_VM;
571   InstanceKlass* k = get_instanceKlass();
572 
573   for (InternalFieldStream fs(k); !fs.done(); fs.next()) {
574     if (fs.access_flags().is_static())  continue;
575     return true;
576   }
577   return false;
578 }
579 
580 void ciInstanceKlass::compute_injected_fields() {
581   assert(is_loaded(), "must be loaded");
582 
583   int has_injected_fields = 0;
584   if (super() != NULL && super()->has_injected_fields()) {
585     has_injected_fields = 1;

643       VM_ENTRY_MARK;
644       MutexLocker ml(Compile_lock);
645       Klass* k = get_instanceKlass()->implementor();
646       if (k != NULL) {
647         if (k == get_instanceKlass()) {
648           // More than one implementors. Use 'this' in this case.
649           impl = this;
650         } else {
651           impl = CURRENT_THREAD_ENV->get_instance_klass(k);
652         }
653       }
654     }
655     // Memoize this result.
656     if (!is_shared()) {
657       _implementor = impl;
658     }
659   }
660   return impl;
661 }
662 
















663 // Utility class for printing of the contents of the static fields for
664 // use by compilation replay.  It only prints out the information that
665 // could be consumed by the compiler, so for primitive types it prints
666 // out the actual value.  For Strings it's the actual string value.
667 // For array types it it's first level array size since that's the
668 // only value which statically unchangeable.  For all other reference
669 // types it simply prints out the dynamic type.
670 
671 class StaticFinalFieldPrinter : public FieldClosure {

672   outputStream* _out;








673   const char*   _holder;
674  public:
675   StaticFinalFieldPrinter(outputStream* out, const char* holder) :
676     _out(out),
677     _holder(holder) {
678   }
679   void do_field(fieldDescriptor* fd) {
680     if (fd->is_final() && !fd->has_initial_value()) {
681       ResourceMark rm;
682       oop mirror = fd->field_holder()->java_mirror();
683       _out->print("staticfield %s %s %s ", _holder, fd->name()->as_quoted_ascii(), fd->signature()->as_quoted_ascii());
684       switch (fd->field_type()) {
685         case T_BYTE:    _out->print_cr("%d", mirror->byte_field(fd->offset()));   break;
686         case T_BOOLEAN: _out->print_cr("%d", mirror->bool_field(fd->offset()));   break;
687         case T_SHORT:   _out->print_cr("%d", mirror->short_field(fd->offset()));  break;
688         case T_CHAR:    _out->print_cr("%d", mirror->char_field(fd->offset()));   break;
689         case T_INT:     _out->print_cr("%d", mirror->int_field(fd->offset()));    break;
690         case T_LONG:    _out->print_cr(INT64_FORMAT, (int64_t)(mirror->long_field(fd->offset())));   break;
691         case T_FLOAT: {
692           float f = mirror->float_field(fd->offset());
693           _out->print_cr("%d", *(int*)&f);
694           break;
695         }
696         case T_DOUBLE: {
697           double d = mirror->double_field(fd->offset());
698           _out->print_cr(INT64_FORMAT, *(int64_t*)&d);
699           break;
700         }
701         case T_ARRAY:  // fall-through
702         case T_OBJECT: {
703           oop value =  mirror->obj_field_acquire(fd->offset());
704           if (value == NULL) {
705             _out->print_cr("null");
706           } else if (value->is_instance()) {
707             assert(fd->field_type() == T_OBJECT, "");
708             if (value->is_a(vmClasses::String_klass())) {
709               const char* ascii_value = java_lang_String::as_quoted_ascii(value);
710               _out->print("\"%s\"", (ascii_value != NULL) ? ascii_value : "");
711             } else {
712               const char* klass_name  = value->klass()->name()->as_quoted_ascii();
713               _out->print_cr("%s", klass_name);
714             }
715           } else if (value->is_array()) {
716             typeArrayOop ta = (typeArrayOop)value;
717             _out->print("%d", ta->length());
718             if (value->is_objArray()) {
719               objArrayOop oa = (objArrayOop)value;
720               const char* klass_name  = value->klass()->name()->as_quoted_ascii();
721               _out->print(" %s", klass_name);
722             }
723             _out->cr();
724           } else {
725             ShouldNotReachHere();
726           }
727           break;












728         }
729         default:
730           ShouldNotReachHere();





731         }




732     }

























733   }
734 };
735 
736 const char *ciInstanceKlass::replay_name() const {
737   return CURRENT_ENV->replay_name(get_instanceKlass());
738 }
739 
740 void ciInstanceKlass::dump_replay_data(outputStream* out) {
741   ResourceMark rm;
742 
743   InstanceKlass* ik = get_instanceKlass();
744   ConstantPool*  cp = ik->constants();
745 
746   // Try to record related loaded classes
747   Klass* sub = ik->subklass();
748   while (sub != NULL) {
749     if (sub->is_instance_klass()) {
750       InstanceKlass *isub = InstanceKlass::cast(sub);
751       if (isub->is_hidden()) {
752         const char *name = CURRENT_ENV->dyno_name(isub);
753         if (name != NULL) {
754           out->print_cr("instanceKlass %s # %s", name, sub->name()->as_quoted_ascii());

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

103     _protection_domain = JNIHandles::make_global(h_protection_domain);
104     _is_shared = true;
105   }
106 
107   // Lazy fields get filled in only upon request.
108   _super  = NULL;
109   _java_mirror = NULL;
110 
111   if (is_shared()) {
112     if (k != vmClasses::Object_klass()) {
113       super();
114     }
115     //compute_nonstatic_fields();  // done outside of constructor
116   }
117 
118   _field_cache = NULL;
119 }
120 
121 // Version for unloaded classes:
122 ciInstanceKlass::ciInstanceKlass(ciSymbol* name,
123                                  jobject loader, jobject protection_domain,
124                                  BasicType bt)
125   : ciKlass(name, bt)
126 {
127   assert(name->char_at(0) != JVM_SIGNATURE_ARRAY, "not an instance klass");
128   _init_state = (InstanceKlass::ClassState)0;
129   _nonstatic_field_size = -1;
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 }
142 
143 
144 
145 // ------------------------------------------------------------------
146 // ciInstanceKlass::compute_shared_is_initialized
147 void ciInstanceKlass::compute_shared_init_state() {
148   GUARDED_VM_ENTRY(
149     InstanceKlass* ik = get_instanceKlass();
150     _init_state = ik->init_state();
151   )

347   if (name()->index_of_at(len+1, "/", 1) >= 0)
348     return false;
349 
350   return true;
351 }
352 
353 // ------------------------------------------------------------------
354 // ciInstanceKlass::print_impl
355 //
356 // Implementation of the print method.
357 void ciInstanceKlass::print_impl(outputStream* st) {
358   ciKlass::print_impl(st);
359   GUARDED_VM_ENTRY(st->print(" loader=" INTPTR_FORMAT, p2i(loader()));)
360   if (is_loaded()) {
361     st->print(" loaded=true initialized=%s finalized=%s subklass=%s size=%d flags=",
362               bool_to_str(is_initialized()),
363               bool_to_str(has_finalizer()),
364               bool_to_str(has_subklass()),
365               layout_helper());
366 
367     _flags.print_klass_flags(st);
368 
369     if (_super) {
370       st->print(" super=");
371       _super->print_name_on(st);
372     }
373     if (_java_mirror) {
374       st->print(" mirror=PRESENT");
375     }
376   } else {
377     st->print(" loaded=false");
378   }
379 }
380 
381 // ------------------------------------------------------------------
382 // ciInstanceKlass::super
383 //
384 // Get the superklass of this klass.
385 ciInstanceKlass* ciInstanceKlass::super() {
386   assert(is_loaded(), "must be loaded");
387   if (_super == NULL && !is_java_lang_Object()) {
388     GUARDED_VM_ENTRY(
389       Klass* super_klass = get_instanceKlass()->super();
390       _super = CURRENT_ENV->get_instance_klass(super_klass);
391     )

447       ciField* field = _nonstatic_fields->at(i);
448       int  field_off = field->offset_in_bytes();
449       if (field_off == field_offset)
450         return field;
451       if (field_off > field_offset)
452         break;
453       // could do binary search or check bins, but probably not worth it
454     }
455     return NULL;
456   }
457   VM_ENTRY_MARK;
458   InstanceKlass* k = get_instanceKlass();
459   fieldDescriptor fd;
460   if (!k->find_field_from_offset(field_offset, is_static, &fd)) {
461     return NULL;
462   }
463   ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
464   return field;
465 }
466 
467 ciField* ciInstanceKlass::get_non_flattened_field_by_offset(int field_offset) {
468   if (super() != NULL && super()->has_nonstatic_fields()) {
469     ciField* f = super()->get_non_flattened_field_by_offset(field_offset);
470     if (f != NULL) {
471       return f;
472     }
473   }
474 
475   VM_ENTRY_MARK;
476   InstanceKlass* k = get_instanceKlass();
477   Arena* arena = CURRENT_ENV->arena();
478   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
479     if (fs.access_flags().is_static())  continue;
480     fieldDescriptor& fd = fs.field_descriptor();
481     if (fd.offset() == field_offset) {
482       ciField* f = new (arena) ciField(&fd);
483       return f;
484     }
485   }
486 
487   return NULL;
488 }
489 
490 // ------------------------------------------------------------------
491 // ciInstanceKlass::get_field_by_name
492 ciField* ciInstanceKlass::get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static) {
493   VM_ENTRY_MARK;
494   InstanceKlass* k = get_instanceKlass();
495   fieldDescriptor fd;
496   Klass* def = k->find_field(name->get_symbol(), signature->get_symbol(), is_static, &fd);
497   if (def == NULL) {
498     return NULL;
499   }
500   ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
501   return field;
502 }
503 
504 
505 static int sort_field_by_offset(ciField** a, ciField** b) {
506   return (*a)->offset_in_bytes() - (*b)->offset_in_bytes();
507   // (no worries about 32-bit overflow...)
508 }
509 

531     int super_flen   = super->nof_nonstatic_fields();
532     super_fields = super->_nonstatic_fields;
533     assert(super_flen == 0 || super_fields != NULL, "first get nof_fields");
534   }
535 
536   GrowableArray<ciField*>* fields = NULL;
537   GUARDED_VM_ENTRY({
538       fields = compute_nonstatic_fields_impl(super_fields);
539     });
540 
541   if (fields == NULL) {
542     // This can happen if this class (java.lang.Class) has invisible fields.
543     if (super_fields != NULL) {
544       _nonstatic_fields = super_fields;
545       return super_fields->length();
546     } else {
547       return 0;
548     }
549   }
550 





551   _nonstatic_fields = fields;
552   return fields->length();
553 }
554 
555 GrowableArray<ciField*>* ciInstanceKlass::compute_nonstatic_fields_impl(GrowableArray<ciField*>* super_fields, bool flatten) {


556   ASSERT_IN_VM;
557   Arena* arena = CURRENT_ENV->arena();
558   int flen = 0;
559   GrowableArray<ciField*>* fields = NULL;
560   InstanceKlass* k = get_instanceKlass();
561   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
562     if (fs.access_flags().is_static())  continue;
563     flen += 1;
564   }
565 
566   // allocate the array:
567   if (flen == 0) {
568     return NULL;  // return nothing if none are locally declared
569   }
570   if (super_fields != NULL) {
571     flen += super_fields->length();
572   }
573 
574   fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, NULL);
575   if (super_fields != NULL) {
576     fields->appendAll(super_fields);
577   }
578 
579   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
580     if (fs.access_flags().is_static())  continue;
581     fieldDescriptor& fd = fs.field_descriptor();
582     if (fd.is_inlined() && flatten) {
583       // Inline type fields are embedded
584       int field_offset = fd.offset();
585       // Get InlineKlass and adjust number of fields
586       Klass* k = get_instanceKlass()->get_inline_type_field_klass(fd.index());
587       ciInlineKlass* vk = CURRENT_ENV->get_klass(k)->as_inline_klass();
588       flen += vk->nof_nonstatic_fields() - 1;
589       // Iterate over fields of the flattened inline type and copy them to 'this'
590       for (int i = 0; i < vk->nof_nonstatic_fields(); ++i) {
591         ciField* flattened_field = vk->nonstatic_field_at(i);
592         // Adjust offset to account for missing oop header
593         int offset = field_offset + (flattened_field->offset() - vk->first_field_offset());
594         // A flattened field can be treated as final if the non-flattened
595         // field is declared final or the holder klass is an inline type itself.
596         bool is_final = fd.is_final() || is_inlinetype();
597         ciField* field = new (arena) ciField(flattened_field, this, offset, is_final);
598         fields->append(field);
599       }
600     } else {
601       ciField* field = new (arena) ciField(&fd);
602       fields->append(field);
603     }
604   }
605   assert(fields->length() == flen, "sanity");
606   // Now sort them by offset, ascending.
607   // (In principle, they could mix with superclass fields.)
608   fields->sort(sort_field_by_offset);
609   return fields;
610 }
611 
612 bool ciInstanceKlass::compute_injected_fields_helper() {
613   ASSERT_IN_VM;
614   InstanceKlass* k = get_instanceKlass();
615 
616   for (InternalFieldStream fs(k); !fs.done(); fs.next()) {
617     if (fs.access_flags().is_static())  continue;
618     return true;
619   }
620   return false;
621 }
622 
623 void ciInstanceKlass::compute_injected_fields() {
624   assert(is_loaded(), "must be loaded");
625 
626   int has_injected_fields = 0;
627   if (super() != NULL && super()->has_injected_fields()) {
628     has_injected_fields = 1;

686       VM_ENTRY_MARK;
687       MutexLocker ml(Compile_lock);
688       Klass* k = get_instanceKlass()->implementor();
689       if (k != NULL) {
690         if (k == get_instanceKlass()) {
691           // More than one implementors. Use 'this' in this case.
692           impl = this;
693         } else {
694           impl = CURRENT_THREAD_ENV->get_instance_klass(k);
695         }
696       }
697     }
698     // Memoize this result.
699     if (!is_shared()) {
700       _implementor = impl;
701     }
702   }
703   return impl;
704 }
705 
706 bool ciInstanceKlass::can_be_inline_klass(bool is_exact) {
707   if (!EnableValhalla) {
708     return false;
709   }
710   if (!is_loaded() || is_inlinetype()) {
711     // Not loaded or known to be an inline klass
712     return true;
713   }
714   if (!is_exact) {
715     // Not exact, check if this is a valid super for an inline klass
716     VM_ENTRY_MARK;
717     return !get_instanceKlass()->invalid_inline_super();
718   }
719   return false;
720 }
721 
722 // Utility class for printing of the contents of the static fields for
723 // use by compilation replay.  It only prints out the information that
724 // could be consumed by the compiler, so for primitive types it prints
725 // out the actual value.  For Strings it's the actual string value.
726 // For array types it it's first level array size since that's the
727 // only value which statically unchangeable.  For all other reference
728 // types it simply prints out the dynamic type.
729 
730 class StaticFieldPrinter : public FieldClosure {
731 protected:
732   outputStream* _out;
733 public:
734   StaticFieldPrinter(outputStream* out) :
735     _out(out) {
736   }
737   void do_field_helper(fieldDescriptor* fd, oop obj, bool flattened);
738 };
739 
740 class StaticFinalFieldPrinter : public StaticFieldPrinter {
741   const char*   _holder;
742  public:
743   StaticFinalFieldPrinter(outputStream* out, const char* holder) :
744     StaticFieldPrinter(out), _holder(holder) {

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