< prev index next >

src/hotspot/share/classfile/javaClasses.cpp

Print this page

  36 #include "classfile/moduleEntry.hpp"
  37 #include "classfile/stringTable.hpp"
  38 #include "classfile/symbolTable.hpp"
  39 #include "classfile/systemDictionary.hpp"
  40 #include "classfile/vmClasses.hpp"
  41 #include "classfile/vmSymbols.hpp"
  42 #include "code/debugInfo.hpp"
  43 #include "code/dependencyContext.hpp"
  44 #include "code/pcDesc.hpp"
  45 #include "gc/shared/collectedHeap.inline.hpp"
  46 #include "interpreter/interpreter.hpp"
  47 #include "interpreter/linkResolver.hpp"
  48 #include "jvm.h"
  49 #include "logging/log.hpp"
  50 #include "logging/logStream.hpp"
  51 #include "memory/oopFactory.hpp"
  52 #include "memory/resourceArea.hpp"
  53 #include "memory/universe.hpp"
  54 #include "oops/fieldInfo.hpp"
  55 #include "oops/fieldStreams.inline.hpp"


  56 #include "oops/instanceKlass.inline.hpp"
  57 #include "oops/instanceMirrorKlass.hpp"
  58 #include "oops/klass.hpp"
  59 #include "oops/klass.inline.hpp"
  60 #include "oops/method.inline.hpp"
  61 #include "oops/objArrayKlass.hpp"
  62 #include "oops/objArrayOop.inline.hpp"
  63 #include "oops/oopCast.inline.hpp"
  64 #include "oops/oop.inline.hpp"
  65 #include "oops/symbol.hpp"
  66 #include "oops/recordComponent.hpp"
  67 #include "oops/typeArrayOop.inline.hpp"
  68 #include "prims/jvmtiExport.hpp"
  69 #include "prims/methodHandles.hpp"
  70 #include "prims/resolvedMethodTable.hpp"
  71 #include "runtime/continuationEntry.inline.hpp"
  72 #include "runtime/continuationJavaClasses.inline.hpp"
  73 #include "runtime/fieldDescriptor.inline.hpp"
  74 #include "runtime/frame.inline.hpp"
  75 #include "runtime/handles.inline.hpp"
  76 #include "runtime/handshake.hpp"
  77 #include "runtime/init.hpp"

1064 void java_lang_Class::allocate_mirror(Klass* k, bool is_scratch, Handle protection_domain, Handle classData,
1065                                       Handle& mirror, Handle& comp_mirror, TRAPS) {
1066   // Allocate mirror (java.lang.Class instance)
1067   oop mirror_oop = InstanceMirrorKlass::cast(vmClasses::Class_klass())->allocate_instance(k, CHECK);
1068   mirror = Handle(THREAD, mirror_oop);
1069 
1070   // Setup indirection from mirror->klass
1071   set_klass(mirror(), k);
1072 
1073   // Set the modifiers flag.
1074   u2 computed_modifiers = k->compute_modifier_flags();
1075   set_modifiers(mirror(), computed_modifiers);
1076 
1077   InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
1078   assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
1079 
1080   set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
1081 
1082   // It might also have a component mirror.  This mirror must already exist.
1083   if (k->is_array_klass()) {
1084     if (k->is_typeArray_klass()) {








1085       BasicType type = TypeArrayKlass::cast(k)->element_type();
1086       if (is_scratch) {
1087         comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(type));
1088       } else {
1089         comp_mirror = Handle(THREAD, Universe::java_mirror(type));
1090       }
1091     } else {
1092       assert(k->is_objArray_klass(), "Must be");

1093       Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
1094       assert(element_klass != nullptr, "Must have an element klass");

1095       if (is_scratch) {
1096         comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(element_klass));
1097       } else {
1098         comp_mirror = Handle(THREAD, element_klass->java_mirror());
1099       }
1100     }
1101     assert(comp_mirror() != nullptr, "must have a mirror");
1102 
1103     // Two-way link between the array klass and its component mirror:
1104     // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
1105     set_component_mirror(mirror(), comp_mirror());
1106     // See below for ordering dependencies between field array_klass in component mirror
1107     // and java_mirror in this klass.
1108   } else {
1109     assert(k->is_instance_klass(), "Must be");
1110 
1111     initialize_mirror_fields(k, mirror, protection_domain, classData, THREAD);
1112     if (HAS_PENDING_EXCEPTION) {
1113       // If any of the fields throws an exception like OOM remove the klass field
1114       // from the mirror so GC doesn't follow it after the klass has been deallocated.
1115       // This mirror looks like a primitive type, which logically it is because it
1116       // it represents no class.
1117       set_klass(mirror(), nullptr);
1118       return;
1119     }
1120   }
1121 }
1122 
1123 void java_lang_Class::create_mirror(Klass* k, Handle class_loader,
1124                                     Handle module, Handle protection_domain,
1125                                     Handle classData, TRAPS) {
1126   assert(k != nullptr, "Use create_basic_type_mirror for primitive types");
1127   assert(k->java_mirror() == nullptr, "should only assign mirror once");
1128 
1129   // Class_klass has to be loaded because it is used to allocate
1130   // the mirror.
1131   if (vmClasses::Class_klass_loaded()) {









1132     Handle mirror;
1133     Handle comp_mirror;
1134 
1135     allocate_mirror(k, /*is_scratch=*/false, protection_domain, classData, mirror, comp_mirror, CHECK);
1136 
1137     // set the classLoader field in the java_lang_Class instance
1138     assert(class_loader() == k->class_loader(), "should be same");
1139     set_class_loader(mirror(), class_loader());
1140 
1141     // Setup indirection from klass->mirror
1142     // after any exceptions can happen during allocations.
1143     k->set_java_mirror(mirror);
1144 
1145     // Set the module field in the java_lang_Class instance.  This must be done
1146     // after the mirror is set.
1147     set_mirror_module_field(THREAD, k, mirror, module);
1148 
1149     if (comp_mirror() != nullptr) {
1150       // Set after k->java_mirror() is published, because compiled code running
1151       // concurrently doesn't expect a k to have a null java_mirror.
1152       release_set_array_klass(comp_mirror(), k);
1153     }

1154     if (CDSConfig::is_dumping_heap()) {
1155       create_scratch_mirror(k, CHECK);
1156     }
1157   } else {
1158     assert(fixup_mirror_list() != nullptr, "fixup_mirror_list not initialized");
1159     fixup_mirror_list()->push(k);
1160   }
1161 }
1162 
1163 #if INCLUDE_CDS_JAVA_HEAP
1164 // The "scratch mirror" stores the states of the mirror object that can be
1165 // decided at dump time (such as the initial values of the static fields, the
1166 // component mirror, etc). At runtime, more information is added to it by
1167 // java_lang_Class::restore_archived_mirror().
1168 //
1169 // Essentially, /*dumptime*/create_scratch_mirror() + /*runtime*/restore_archived_mirror()
1170 // produces the same result as /*runtime*/create_mirror().
1171 //
1172 // Note: we archive the "scratch mirror" instead of k->java_mirror(), because the
1173 // latter may contain dumptime-specific information that cannot be archived
1174 // (e.g., ClassLoaderData*, or static fields that are modified by Java code execution).
1175 void java_lang_Class::create_scratch_mirror(Klass* k, TRAPS) {
1176   if (k->class_loader() != nullptr &&
1177       k->class_loader() != SystemDictionary::java_platform_loader() &&
1178       k->class_loader() != SystemDictionary::java_system_loader()) {
1179     // We only archive the mirrors of classes loaded by the built-in loaders
1180     return;
1181   }
1182 
1183   Handle protection_domain, classData; // set to null. Will be reinitialized at runtime
1184   Handle mirror;
1185   Handle comp_mirror;
1186   allocate_mirror(k, /*is_scratch=*/true, protection_domain, classData, mirror, comp_mirror, CHECK);
1187 
1188   if (comp_mirror() != nullptr) {
1189     release_set_array_klass(comp_mirror(), k);
1190   }
1191 
1192   HeapShared::set_scratch_java_mirror(k, mirror());
1193 }
1194 
1195 // Returns true if the mirror is updated, false if no archived mirror
1196 // data is present. After the archived mirror object is restored, the
1197 // shared klass' _has_raw_archived_mirror flag is cleared.
1198 bool java_lang_Class::restore_archived_mirror(Klass *k,
1199                                               Handle class_loader, Handle module,
1200                                               Handle protection_domain, TRAPS) {
1201   // Postpone restoring archived mirror until java.lang.Class is loaded. Please
1202   // see more details in vmClasses::resolve_all().
1203   if (!vmClasses::Class_klass_loaded()) {
1204     assert(fixup_mirror_list() != nullptr, "fixup_mirror_list not initialized");
1205     fixup_mirror_list()->push(k);
1206     return true;
1207   }
1208 
1209   oop m = k->archived_java_mirror();
1210   assert(m != nullptr, "must have stored non-null archived mirror");
1211 
1212   // Sanity: clear it now to prevent re-initialization if any of the following fails
1213   k->clear_archived_mirror_index();
1214 
1215   // mirror is archived, restore
1216   log_debug(aot, mirror)("Archived mirror is: " PTR_FORMAT, p2i(m));
1217   assert(as_Klass(m) == k, "must be");
1218   Handle mirror(THREAD, m);
1219 
1220   if (!k->is_array_klass()) {

1221     // - local static final fields with initial values were initialized at dump time
1222 
1223     // create the init_lock
1224     typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK_(false));
1225     set_init_lock(mirror(), r);
1226 
1227     if (protection_domain.not_null()) {
1228       set_protection_domain(mirror(), protection_domain());
1229     }




1230   }
1231 
1232   assert(class_loader() == k->class_loader(), "should be same");
1233   if (class_loader.not_null()) {
1234     set_class_loader(mirror(), class_loader());
1235   }
1236 
1237   k->set_java_mirror(mirror);
1238 
1239   set_mirror_module_field(THREAD, k, mirror, module);
1240 
1241   if (log_is_enabled(Trace, aot, heap, mirror)) {
1242     ResourceMark rm(THREAD);
1243     log_trace(aot, heap, mirror)(
1244         "Restored %s archived mirror " PTR_FORMAT, k->external_name(), p2i(mirror()));
1245   }
1246 
1247   return true;
1248 }
1249 #endif // INCLUDE_CDS_JAVA_HEAP

1386   assert(is_instance(java_class), "must be a Class object");
1387   java_class->metadata_field_put(_klass_offset, klass);
1388 }
1389 
1390 
1391 void java_lang_Class::print_signature(oop java_class, outputStream* st) {
1392   assert(is_instance(java_class), "must be a Class object");
1393   Symbol* name = nullptr;
1394   bool is_instance = false;
1395   if (is_primitive(java_class)) {
1396     name = vmSymbols::type_signature(primitive_type(java_class));
1397   } else {
1398     Klass* k = as_Klass(java_class);
1399     is_instance = k->is_instance_klass();
1400     name = k->name();
1401   }
1402   if (name == nullptr) {
1403     st->print("<null>");
1404     return;
1405   }
1406   if (is_instance)  st->print("L");


1407   st->write((char*) name->base(), (int) name->utf8_length());
1408   if (is_instance)  st->print(";");
1409 }
1410 
1411 Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found) {
1412   assert(is_instance(java_class), "must be a Class object");
1413   Symbol* name;
1414   if (is_primitive(java_class)) {
1415     name = vmSymbols::type_signature(primitive_type(java_class));
1416     // Because this can create a new symbol, the caller has to decrement
1417     // the refcount, so make adjustment here and below for symbols returned
1418     // that are not created or incremented due to a successful lookup.
1419     name->increment_refcount();
1420   } else {
1421     Klass* k = as_Klass(java_class);
1422     if (!k->is_instance_klass()) {
1423       name = k->name();
1424       name->increment_refcount();
1425     } else {
1426       ResourceMark rm;

1445   if (is_primitive(java_class)) {
1446     name = type2name(primitive_type(java_class));
1447   } else {
1448     name = as_Klass(java_class)->external_name();
1449   }
1450   if (name == nullptr) {
1451     name = "<null>";
1452   }
1453   return name;
1454 }
1455 
1456 Klass* java_lang_Class::array_klass_acquire(oop java_class) {
1457   Klass* k = ((Klass*)java_class->metadata_field_acquire(_array_klass_offset));
1458   assert(k == nullptr || (k->is_klass() && k->is_array_klass()), "should be array klass");
1459   return k;
1460 }
1461 
1462 
1463 void java_lang_Class::release_set_array_klass(oop java_class, Klass* klass) {
1464   assert(klass->is_klass() && klass->is_array_klass(), "should be array klass");

1465   java_class->release_metadata_field_put(_array_klass_offset, klass);
1466 }
1467 
1468 
1469 BasicType java_lang_Class::primitive_type(oop java_class) {
1470   assert(is_primitive(java_class), "just checking");
1471   Klass* ak = ((Klass*)java_class->metadata_field(_array_klass_offset));
1472   BasicType type = T_VOID;
1473   if (ak != nullptr) {
1474     // Note: create_basic_type_mirror above initializes ak to a non-null value.
1475     type = ArrayKlass::cast(ak)->element_type();
1476   } else {
1477     assert(java_class == Universe::void_mirror(), "only valid non-array primitive");
1478   }
1479 #ifdef ASSERT
1480   if (CDSConfig::is_dumping_heap()) {
1481     oop mirror = Universe::java_mirror(type);
1482     oop scratch_mirror = HeapShared::scratch_java_mirror(type);
1483     assert(java_class == mirror || java_class == scratch_mirror, "must be consistent");
1484   } else {

2830 
2831     // the format of the stacktrace will be:
2832     // - 1 or more fillInStackTrace frames for the exception class (skipped)
2833     // - 0 or more <init> methods for the exception class (skipped)
2834     // - rest of the stack
2835 
2836     if (!skip_fillInStackTrace_check) {
2837       if (method->name() == vmSymbols::fillInStackTrace_name() &&
2838           throwable->is_a(method->method_holder())) {
2839         continue;
2840       }
2841       else {
2842         skip_fillInStackTrace_check = true; // gone past them all
2843       }
2844     }
2845     if (!skip_throwableInit_check) {
2846       assert(skip_fillInStackTrace_check, "logic error in backtrace filtering");
2847 
2848       // skip <init> methods of the exception class and superclasses
2849       // This is similar to classic VM.
2850       if (method->name() == vmSymbols::object_initializer_name() &&
2851           throwable->is_a(method->method_holder())) {
2852         continue;
2853       } else {
2854         // there are none or we've seen them all - either way stop checking
2855         skip_throwableInit_check = true;
2856       }
2857     }
2858     if (method->is_hidden() || method->is_continuation_enter_intrinsic()) {
2859       if (skip_hidden) {
2860         if (total_count == 0) {
2861           // The top frame will be hidden from the stack trace.
2862           bt.set_has_hidden_top_frame();
2863         }
2864         continue;
2865       }
2866     }
2867 
2868     bt.push(method, bci, CHECK);
2869     total_count++;
2870   }

3189 int java_lang_ClassFrameInfo::_classOrMemberName_offset;
3190 int java_lang_ClassFrameInfo::_flags_offset;
3191 
3192 #define CLASSFRAMEINFO_FIELDS_DO(macro) \
3193   macro(_classOrMemberName_offset, k, "classOrMemberName", object_signature,  false); \
3194   macro(_flags_offset,             k, vmSymbols::flags_name(), int_signature, false)
3195 
3196 void java_lang_ClassFrameInfo::compute_offsets() {
3197   InstanceKlass* k = vmClasses::ClassFrameInfo_klass();
3198   CLASSFRAMEINFO_FIELDS_DO(FIELD_COMPUTE_OFFSET);
3199 }
3200 
3201 #if INCLUDE_CDS
3202 void java_lang_ClassFrameInfo::serialize_offsets(SerializeClosure* f) {
3203   CLASSFRAMEINFO_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
3204 }
3205 #endif
3206 
3207 static int get_flags(const methodHandle& m) {
3208   int flags = m->access_flags().as_method_flags();
3209   if (m->is_object_initializer()) {
3210     flags |= java_lang_invoke_MemberName::MN_IS_CONSTRUCTOR;
3211   } else {
3212     // Note: Static initializers can be here. Record them as plain methods.
3213     flags |= java_lang_invoke_MemberName::MN_IS_METHOD;
3214   }
3215   if (m->caller_sensitive()) {
3216     flags |= java_lang_invoke_MemberName::MN_CALLER_SENSITIVE;
3217   }
3218   if (m->is_hidden()) {
3219     flags |= java_lang_invoke_MemberName::MN_HIDDEN_MEMBER;
3220   }
3221   assert((flags & 0xFF000000) == 0, "unexpected flags");
3222   return flags;
3223 }
3224 
3225 oop java_lang_ClassFrameInfo::classOrMemberName(oop obj) {
3226   return obj->obj_field(_classOrMemberName_offset);
3227 }
3228 
3229 int java_lang_ClassFrameInfo::flags(oop obj) {
3230   return obj->int_field(_flags_offset);

3581   constructor->int_field_put(_modifiers_offset, value);
3582 }
3583 
3584 void java_lang_reflect_Constructor::set_signature(oop constructor, oop value) {
3585   constructor->obj_field_put(_signature_offset, value);
3586 }
3587 
3588 void java_lang_reflect_Constructor::set_annotations(oop constructor, oop value) {
3589   constructor->obj_field_put(_annotations_offset, value);
3590 }
3591 
3592 void java_lang_reflect_Constructor::set_parameter_annotations(oop method, oop value) {
3593   method->obj_field_put(_parameter_annotations_offset, value);
3594 }
3595 
3596 int java_lang_reflect_Field::_clazz_offset;
3597 int java_lang_reflect_Field::_name_offset;
3598 int java_lang_reflect_Field::_type_offset;
3599 int java_lang_reflect_Field::_slot_offset;
3600 int java_lang_reflect_Field::_modifiers_offset;
3601 int java_lang_reflect_Field::_trusted_final_offset;
3602 int java_lang_reflect_Field::_signature_offset;
3603 int java_lang_reflect_Field::_annotations_offset;
3604 
3605 #define FIELD_FIELDS_DO(macro) \
3606   macro(_clazz_offset,     k, vmSymbols::clazz_name(),     class_signature,  false); \
3607   macro(_name_offset,      k, vmSymbols::name_name(),      string_signature, false); \
3608   macro(_type_offset,      k, vmSymbols::type_name(),      class_signature,  false); \
3609   macro(_slot_offset,      k, vmSymbols::slot_name(),      int_signature,    false); \
3610   macro(_modifiers_offset, k, vmSymbols::modifiers_name(), int_signature,    false); \
3611   macro(_trusted_final_offset,    k, vmSymbols::trusted_final_name(),    bool_signature,       false); \
3612   macro(_signature_offset,        k, vmSymbols::signature_name(),        string_signature,     false); \
3613   macro(_annotations_offset,      k, vmSymbols::annotations_name(),      byte_array_signature, false);
3614 
3615 void java_lang_reflect_Field::compute_offsets() {
3616   InstanceKlass* k = vmClasses::reflect_Field_klass();
3617   FIELD_FIELDS_DO(FIELD_COMPUTE_OFFSET);
3618 }
3619 
3620 #if INCLUDE_CDS
3621 void java_lang_reflect_Field::serialize_offsets(SerializeClosure* f) {
3622   FIELD_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
3623 }
3624 #endif
3625 
3626 Handle java_lang_reflect_Field::create(TRAPS) {
3627   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
3628   Symbol* name = vmSymbols::java_lang_reflect_Field();
3629   Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH);
3630   InstanceKlass* ik = InstanceKlass::cast(k);
3631   // Ensure it is initialized

3656 void java_lang_reflect_Field::set_type(oop field, oop value) {
3657   field->obj_field_put(_type_offset, value);
3658 }
3659 
3660 int java_lang_reflect_Field::slot(oop reflect) {
3661   return reflect->int_field(_slot_offset);
3662 }
3663 
3664 void java_lang_reflect_Field::set_slot(oop reflect, int value) {
3665   reflect->int_field_put(_slot_offset, value);
3666 }
3667 
3668 int java_lang_reflect_Field::modifiers(oop field) {
3669   return field->int_field(_modifiers_offset);
3670 }
3671 
3672 void java_lang_reflect_Field::set_modifiers(oop field, int value) {
3673   field->int_field_put(_modifiers_offset, value);
3674 }
3675 
3676 void java_lang_reflect_Field::set_trusted_final(oop field) {
3677   field->bool_field_put(_trusted_final_offset, true);
3678 }
3679 
3680 void java_lang_reflect_Field::set_signature(oop field, oop value) {
3681   field->obj_field_put(_signature_offset, value);
3682 }
3683 
3684 void java_lang_reflect_Field::set_annotations(oop field, oop value) {
3685   field->obj_field_put(_annotations_offset, value);
3686 }
3687 
3688 oop java_lang_reflect_RecordComponent::create(InstanceKlass* holder, RecordComponent* component, TRAPS) {
3689   // Allocate java.lang.reflect.RecordComponent instance
3690   HandleMark hm(THREAD);
3691   InstanceKlass* ik = vmClasses::RecordComponent_klass();
3692   assert(ik != nullptr, "must be loaded");
3693   ik->initialize(CHECK_NULL);
3694 
3695   Handle element = ik->allocate_instance_handle(CHECK_NULL);
3696 
3697   Handle decl_class(THREAD, holder->java_mirror());

3960 }
3961 #endif
3962 
3963 bool java_lang_ref_Reference::is_referent_field(oop obj, ptrdiff_t offset) {
3964   assert(obj != nullptr, "sanity");
3965   if (offset != _referent_offset) {
3966     return false;
3967   }
3968 
3969   Klass* k = obj->klass();
3970   if (!k->is_instance_klass()) {
3971     return false;
3972   }
3973 
3974   InstanceKlass* ik = InstanceKlass::cast(obj->klass());
3975   bool is_reference = ik->reference_type() != REF_NONE;
3976   assert(!is_reference || ik->is_subclass_of(vmClasses::Reference_klass()), "sanity");
3977   return is_reference;
3978 }
3979 
3980 int java_lang_boxing_object::_value_offset;
3981 int java_lang_boxing_object::_long_value_offset;
3982 
3983 #define BOXING_FIELDS_DO(macro) \
3984   macro(_value_offset,      integerKlass, "value", int_signature, false); \
3985   macro(_long_value_offset, longKlass, "value", long_signature, false);






3986 
3987 void java_lang_boxing_object::compute_offsets() {
3988   InstanceKlass* integerKlass = vmClasses::Integer_klass();
3989   InstanceKlass* longKlass = vmClasses::Long_klass();
3990   BOXING_FIELDS_DO(FIELD_COMPUTE_OFFSET);
3991 }
3992 
3993 #if INCLUDE_CDS
3994 void java_lang_boxing_object::serialize_offsets(SerializeClosure* f) {




3995   BOXING_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
3996 }
3997 #endif
3998 
3999 oop java_lang_boxing_object::initialize_and_allocate(BasicType type, TRAPS) {
4000   Klass* k = vmClasses::box_klass(type);
4001   if (k == nullptr)  return nullptr;
4002   InstanceKlass* ik = InstanceKlass::cast(k);
4003   if (!ik->is_initialized()) {
4004     ik->initialize(CHECK_NULL);
4005   }
4006   return ik->allocate_instance(THREAD);
4007 }
4008 
4009 
4010 oop java_lang_boxing_object::create(BasicType type, jvalue* value, TRAPS) {
4011   oop box = initialize_and_allocate(type, CHECK_NULL);
4012   if (box == nullptr)  return nullptr;
4013   switch (type) {
4014     case T_BOOLEAN:
4015       box->bool_field_put(_value_offset, value->z);
4016       break;
4017     case T_CHAR:
4018       box->char_field_put(_value_offset, value->c);
4019       break;
4020     case T_FLOAT:
4021       box->float_field_put(_value_offset, value->f);
4022       break;
4023     case T_DOUBLE:
4024       box->double_field_put(_long_value_offset, value->d);
4025       break;
4026     case T_BYTE:
4027       box->byte_field_put(_value_offset, value->b);
4028       break;
4029     case T_SHORT:
4030       box->short_field_put(_value_offset, value->s);
4031       break;
4032     case T_INT:
4033       box->int_field_put(_value_offset, value->i);
4034       break;
4035     case T_LONG:
4036       box->long_field_put(_long_value_offset, value->j);
4037       break;
4038     default:
4039       return nullptr;
4040   }
4041   return box;
4042 }
4043 
4044 
4045 BasicType java_lang_boxing_object::basic_type(oop box) {
4046   if (box == nullptr)  return T_ILLEGAL;
4047   BasicType type = vmClasses::box_klass_type(box->klass());
4048   if (type == T_OBJECT)         // 'unknown' value returned by SD::bkt
4049     return T_ILLEGAL;
4050   return type;
4051 }
4052 
4053 
4054 BasicType java_lang_boxing_object::get_value(oop box, jvalue* value) {
4055   BasicType type = vmClasses::box_klass_type(box->klass());
4056   switch (type) {
4057   case T_BOOLEAN:
4058     value->z = box->bool_field(_value_offset);
4059     break;
4060   case T_CHAR:
4061     value->c = box->char_field(_value_offset);
4062     break;
4063   case T_FLOAT:
4064     value->f = box->float_field(_value_offset);
4065     break;
4066   case T_DOUBLE:
4067     value->d = box->double_field(_long_value_offset);
4068     break;
4069   case T_BYTE:
4070     value->b = box->byte_field(_value_offset);
4071     break;
4072   case T_SHORT:
4073     value->s = box->short_field(_value_offset);
4074     break;
4075   case T_INT:
4076     value->i = box->int_field(_value_offset);
4077     break;
4078   case T_LONG:
4079     value->j = box->long_field(_long_value_offset);
4080     break;
4081   default:
4082     return T_ILLEGAL;
4083   } // end switch
4084   return type;
4085 }
4086 
4087 
4088 BasicType java_lang_boxing_object::set_value(oop box, jvalue* value) {
4089   BasicType type = vmClasses::box_klass_type(box->klass());
4090   switch (type) {
4091   case T_BOOLEAN:
4092     box->bool_field_put(_value_offset, value->z);
4093     break;
4094   case T_CHAR:
4095     box->char_field_put(_value_offset, value->c);
4096     break;
4097   case T_FLOAT:
4098     box->float_field_put(_value_offset, value->f);
4099     break;
4100   case T_DOUBLE:
4101     box->double_field_put(_long_value_offset, value->d);
4102     break;
4103   case T_BYTE:
4104     box->byte_field_put(_value_offset, value->b);
4105     break;
4106   case T_SHORT:
4107     box->short_field_put(_value_offset, value->s);
4108     break;
4109   case T_INT:
4110     box->int_field_put(_value_offset, value->i);
4111     break;
4112   case T_LONG:
4113     box->long_field_put(_long_value_offset, value->j);
4114     break;
4115   default:
4116     return T_ILLEGAL;
4117   } // end switch
4118   return type;
4119 }
4120 
4121 
4122 void java_lang_boxing_object::print(BasicType type, jvalue* value, outputStream* st) {
4123   switch (type) {
4124   case T_BOOLEAN:   st->print("%s", value->z ? "true" : "false");   break;
4125   case T_CHAR:      st->print("%d", value->c);                      break;
4126   case T_BYTE:      st->print("%d", value->b);                      break;
4127   case T_SHORT:     st->print("%d", value->s);                      break;
4128   case T_INT:       st->print("%d", value->i);                      break;
4129   case T_LONG:      st->print(JLONG_FORMAT, value->j);              break;
4130   case T_FLOAT:     st->print("%f", value->f);                      break;
4131   case T_DOUBLE:    st->print("%lf", value->d);                     break;
4132   default:          st->print("type %d?", type);                    break;
4133   }

4489 oop java_lang_invoke_MemberName::type(oop mname) {
4490   assert(is_instance(mname), "wrong type");
4491   return mname->obj_field(_type_offset);
4492 }
4493 
4494 void java_lang_invoke_MemberName::set_type(oop mname, oop type) {
4495   assert(is_instance(mname), "wrong type");
4496   mname->obj_field_put(_type_offset, type);
4497 }
4498 
4499 int java_lang_invoke_MemberName::flags(oop mname) {
4500   assert(is_instance(mname), "wrong type");
4501   return mname->int_field(_flags_offset);
4502 }
4503 
4504 void java_lang_invoke_MemberName::set_flags(oop mname, int flags) {
4505   assert(is_instance(mname), "wrong type");
4506   mname->int_field_put(_flags_offset, flags);
4507 }
4508 
4509 
4510 // Return vmtarget from ResolvedMethodName method field through indirection
4511 Method* java_lang_invoke_MemberName::vmtarget(oop mname) {
4512   assert(is_instance(mname), "wrong type");
4513   oop method = mname->obj_field(_method_offset);
4514   return method == nullptr ? nullptr : java_lang_invoke_ResolvedMethodName::vmtarget(method);
4515 }
4516 
4517 bool java_lang_invoke_MemberName::is_method(oop mname) {
4518   assert(is_instance(mname), "must be MemberName");
4519   return (flags(mname) & (MN_IS_METHOD | MN_IS_CONSTRUCTOR)) > 0;
4520 }
4521 
4522 void java_lang_invoke_MemberName::set_method(oop mname, oop resolved_method) {
4523   assert(is_instance(mname), "wrong type");
4524   mname->obj_field_put(_method_offset, resolved_method);
4525 }
4526 
4527 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) {
4528   assert(is_instance(mname), "wrong type");
4529   return (intptr_t) mname->address_field(_vmindex_offset);
4530 }
4531 
4532 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
4533   assert(is_instance(mname), "wrong type");
4534   mname->address_field_put(_vmindex_offset, (address) index);
4535 }
4536 
4537 
4538 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) {
4539   assert(is_instance(resolved_method), "wrong type");

5492   if (!ik->find_local_field(f_name, f_sig, &fd)) {
5493     tty->print_cr("Nonstatic field %s.%s not found", klass_name, field_name);
5494     return false;
5495   }
5496   if (fd.is_static()) {
5497     tty->print_cr("Nonstatic field %s.%s appears to be static", klass_name, field_name);
5498     return false;
5499   }
5500   if (fd.offset() == deserialized_offset ) {
5501     return true;
5502   } else {
5503     tty->print_cr("Offset of nonstatic field %s.%s is deserialized as %d but should really be %d.",
5504                   klass_name, field_name, deserialized_offset, fd.offset());
5505     return false;
5506   }
5507 }
5508 
5509 void JavaClasses::check_offsets() {
5510   bool valid = true;
5511 
5512 #define CHECK_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \
5513   valid &= check_offset(klass_name, cpp_klass_name :: _##field_name ## _offset, #field_name, field_sig)
5514 
5515 #define CHECK_LONG_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \
5516   valid &= check_offset(klass_name, cpp_klass_name :: _##long_ ## field_name ## _offset, #field_name, field_sig)
5517 
5518   // Boxed primitive objects (java_lang_boxing_object)
5519 
5520   CHECK_OFFSET("java/lang/Boolean",   java_lang_boxing_object, value, "Z");
5521   CHECK_OFFSET("java/lang/Character", java_lang_boxing_object, value, "C");
5522   CHECK_OFFSET("java/lang/Float",     java_lang_boxing_object, value, "F");
5523   CHECK_LONG_OFFSET("java/lang/Double", java_lang_boxing_object, value, "D");
5524   CHECK_OFFSET("java/lang/Byte",      java_lang_boxing_object, value, "B");
5525   CHECK_OFFSET("java/lang/Short",     java_lang_boxing_object, value, "S");
5526   CHECK_OFFSET("java/lang/Integer",   java_lang_boxing_object, value, "I");
5527   CHECK_LONG_OFFSET("java/lang/Long", java_lang_boxing_object, value, "J");
5528 
5529   if (!valid) vm_exit_during_initialization("Field offset verification failed");
5530 }
5531 
5532 #endif // PRODUCT
5533 
5534 int InjectedField::compute_offset() {
5535   InstanceKlass* ik = InstanceKlass::cast(klass());
5536   for (AllFieldStream fs(ik); !fs.done(); fs.next()) {
5537     if (!may_be_java && !fs.field_flags().is_injected()) {
5538       // Only look at injected fields
5539       continue;
5540     }
5541     if (fs.name() == name() && fs.signature() == signature()) {
5542       return fs.offset();
5543     }
5544   }
5545   ResourceMark rm;
5546   tty->print_cr("Invalid layout of %s at %s/%s%s", ik->external_name(), name()->as_C_string(), signature()->as_C_string(), may_be_java ? " (may_be_java)" : "");
5547 #ifndef PRODUCT

  36 #include "classfile/moduleEntry.hpp"
  37 #include "classfile/stringTable.hpp"
  38 #include "classfile/symbolTable.hpp"
  39 #include "classfile/systemDictionary.hpp"
  40 #include "classfile/vmClasses.hpp"
  41 #include "classfile/vmSymbols.hpp"
  42 #include "code/debugInfo.hpp"
  43 #include "code/dependencyContext.hpp"
  44 #include "code/pcDesc.hpp"
  45 #include "gc/shared/collectedHeap.inline.hpp"
  46 #include "interpreter/interpreter.hpp"
  47 #include "interpreter/linkResolver.hpp"
  48 #include "jvm.h"
  49 #include "logging/log.hpp"
  50 #include "logging/logStream.hpp"
  51 #include "memory/oopFactory.hpp"
  52 #include "memory/resourceArea.hpp"
  53 #include "memory/universe.hpp"
  54 #include "oops/fieldInfo.hpp"
  55 #include "oops/fieldStreams.inline.hpp"
  56 #include "oops/flatArrayKlass.hpp"
  57 #include "oops/inlineKlass.inline.hpp"
  58 #include "oops/instanceKlass.inline.hpp"
  59 #include "oops/instanceMirrorKlass.inline.hpp"
  60 #include "oops/klass.hpp"
  61 #include "oops/klass.inline.hpp"
  62 #include "oops/method.inline.hpp"
  63 #include "oops/objArrayKlass.hpp"
  64 #include "oops/objArrayOop.inline.hpp"
  65 #include "oops/oopCast.inline.hpp"
  66 #include "oops/oop.inline.hpp"
  67 #include "oops/symbol.hpp"
  68 #include "oops/recordComponent.hpp"
  69 #include "oops/typeArrayOop.inline.hpp"
  70 #include "prims/jvmtiExport.hpp"
  71 #include "prims/methodHandles.hpp"
  72 #include "prims/resolvedMethodTable.hpp"
  73 #include "runtime/continuationEntry.inline.hpp"
  74 #include "runtime/continuationJavaClasses.inline.hpp"
  75 #include "runtime/fieldDescriptor.inline.hpp"
  76 #include "runtime/frame.inline.hpp"
  77 #include "runtime/handles.inline.hpp"
  78 #include "runtime/handshake.hpp"
  79 #include "runtime/init.hpp"

1066 void java_lang_Class::allocate_mirror(Klass* k, bool is_scratch, Handle protection_domain, Handle classData,
1067                                       Handle& mirror, Handle& comp_mirror, TRAPS) {
1068   // Allocate mirror (java.lang.Class instance)
1069   oop mirror_oop = InstanceMirrorKlass::cast(vmClasses::Class_klass())->allocate_instance(k, CHECK);
1070   mirror = Handle(THREAD, mirror_oop);
1071 
1072   // Setup indirection from mirror->klass
1073   set_klass(mirror(), k);
1074 
1075   // Set the modifiers flag.
1076   u2 computed_modifiers = k->compute_modifier_flags();
1077   set_modifiers(mirror(), computed_modifiers);
1078 
1079   InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
1080   assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
1081 
1082   set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
1083 
1084   // It might also have a component mirror.  This mirror must already exist.
1085   if (k->is_array_klass()) {
1086     if (k->is_flatArray_klass()) {
1087       Klass* element_klass = (Klass*) FlatArrayKlass::cast(k)->element_klass();
1088       assert(element_klass->is_inline_klass(), "Must be inline type component");
1089       if (is_scratch) {
1090         comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(element_klass));
1091       } else {
1092         comp_mirror = Handle(THREAD, element_klass->java_mirror());
1093       }
1094     } else if (k->is_typeArray_klass()) {
1095       BasicType type = TypeArrayKlass::cast(k)->element_type();
1096       if (is_scratch) {
1097         comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(type));
1098       } else {
1099         comp_mirror = Handle(THREAD, Universe::java_mirror(type));
1100       }
1101     } else {
1102       assert(k->is_objArray_klass(), "Must be");
1103       assert(!k->is_refArray_klass() || !k->is_flatArray_klass(), "Must not have mirror");
1104       Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
1105       assert(element_klass != nullptr, "Must have an element klass");
1106       oop comp_oop = element_klass->java_mirror();
1107       if (is_scratch) {
1108         comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(element_klass));
1109       } else {
1110         comp_mirror = Handle(THREAD, comp_oop);
1111       }
1112     }
1113     assert(comp_mirror() != nullptr, "must have a mirror");
1114 
1115     // Two-way link between the array klass and its component mirror:
1116     // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
1117     set_component_mirror(mirror(), comp_mirror());
1118     // See below for ordering dependencies between field array_klass in component mirror
1119     // and java_mirror in this klass.
1120   } else {
1121     assert(k->is_instance_klass(), "Must be");
1122 
1123     initialize_mirror_fields(k, mirror, protection_domain, classData, THREAD);
1124     if (HAS_PENDING_EXCEPTION) {
1125       // If any of the fields throws an exception like OOM remove the klass field
1126       // from the mirror so GC doesn't follow it after the klass has been deallocated.
1127       // This mirror looks like a primitive type, which logically it is because it
1128       // it represents no class.
1129       set_klass(mirror(), nullptr);
1130       return;
1131     }
1132   }
1133 }
1134 
1135 void java_lang_Class::create_mirror(Klass* k, Handle class_loader,
1136                                     Handle module, Handle protection_domain,
1137                                     Handle classData, TRAPS) {
1138   assert(k != nullptr, "Use create_basic_type_mirror for primitive types");
1139   assert(k->java_mirror() == nullptr, "should only assign mirror once");

1140   // Class_klass has to be loaded because it is used to allocate
1141   // the mirror.
1142   if (vmClasses::Class_klass_loaded()) {
1143 
1144     if (k->is_refined_objArray_klass()) {
1145       Klass* super_klass = k->super();
1146       assert(super_klass != nullptr, "Must be");
1147       Handle mirror(THREAD, super_klass->java_mirror());
1148       k->set_java_mirror(mirror);
1149       return;
1150     }
1151 
1152     Handle mirror;
1153     Handle comp_mirror;
1154 
1155     allocate_mirror(k, /*is_scratch=*/false, protection_domain, classData, mirror, comp_mirror, CHECK);
1156 
1157     // set the classLoader field in the java_lang_Class instance
1158     assert(class_loader() == k->class_loader(), "should be same");
1159     set_class_loader(mirror(), class_loader());
1160 
1161     // Setup indirection from klass->mirror
1162     // after any exceptions can happen during allocations.
1163     k->set_java_mirror(mirror);
1164 
1165     // Set the module field in the java_lang_Class instance.  This must be done
1166     // after the mirror is set.
1167     set_mirror_module_field(THREAD, k, mirror, module);
1168 
1169     if (comp_mirror() != nullptr) {
1170       // Set after k->java_mirror() is published, because compiled code running
1171       // concurrently doesn't expect a k to have a null java_mirror.
1172       release_set_array_klass(comp_mirror(), k);
1173     }
1174 
1175     if (CDSConfig::is_dumping_heap()) {
1176       create_scratch_mirror(k, CHECK);
1177     }
1178   } else {
1179     assert(fixup_mirror_list() != nullptr, "fixup_mirror_list not initialized");
1180     fixup_mirror_list()->push(k);
1181   }
1182 }
1183 
1184 #if INCLUDE_CDS_JAVA_HEAP
1185 // The "scratch mirror" stores the states of the mirror object that can be
1186 // decided at dump time (such as the initial values of the static fields, the
1187 // component mirror, etc). At runtime, more information is added to it by
1188 // java_lang_Class::restore_archived_mirror().
1189 //
1190 // Essentially, /*dumptime*/create_scratch_mirror() + /*runtime*/restore_archived_mirror()
1191 // produces the same result as /*runtime*/create_mirror().
1192 //
1193 // Note: we archive the "scratch mirror" instead of k->java_mirror(), because the
1194 // latter may contain dumptime-specific information that cannot be archived
1195 // (e.g., ClassLoaderData*, or static fields that are modified by Java code execution).
1196 void java_lang_Class::create_scratch_mirror(Klass* k, TRAPS) {
1197   if ((k->class_loader() != nullptr &&
1198        k->class_loader() != SystemDictionary::java_platform_loader() &&
1199        k->class_loader() != SystemDictionary::java_system_loader())) {
1200     // We only archive the mirrors of classes loaded by the built-in loaders
1201     return;
1202   }
1203 
1204   Handle protection_domain, classData; // set to null. Will be reinitialized at runtime
1205   Handle mirror;
1206   Handle comp_mirror;
1207   allocate_mirror(k, /*is_scratch=*/true, protection_domain, classData, mirror, comp_mirror, CHECK);
1208 
1209   if (comp_mirror() != nullptr) {
1210     release_set_array_klass(comp_mirror(), k);
1211   }
1212 
1213   HeapShared::set_scratch_java_mirror(k, mirror());
1214 }
1215 
1216 // Returns true if the mirror is updated, false if no archived mirror
1217 // data is present. After the archived mirror object is restored, the
1218 // shared klass' _has_raw_archived_mirror flag is cleared.
1219 bool java_lang_Class::restore_archived_mirror(Klass *k,
1220                                               Handle class_loader, Handle module,
1221                                               Handle protection_domain, TRAPS) {
1222   // Postpone restoring archived mirror until java.lang.Class is loaded. Please
1223   // see more details in vmClasses::resolve_all().
1224   if (!vmClasses::Class_klass_loaded()) {
1225     assert(fixup_mirror_list() != nullptr, "fixup_mirror_list not initialized");
1226     fixup_mirror_list()->push(k);
1227     return true;
1228   }
1229 
1230   oop m = k->archived_java_mirror();
1231   assert(m != nullptr, "must have stored non-null archived mirror");
1232 
1233   // Sanity: clear it now to prevent re-initialization if any of the following fails
1234   k->clear_archived_mirror_index();
1235 
1236   // mirror is archived, restore
1237   log_debug(aot, mirror)("Archived mirror is: " PTR_FORMAT, p2i(m));

1238   Handle mirror(THREAD, m);
1239 
1240   if (!k->is_array_klass()) {
1241     assert(as_Klass(m) == k, "must be");
1242     // - local static final fields with initial values were initialized at dump time
1243 
1244     // create the init_lock
1245     typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK_(false));
1246     set_init_lock(mirror(), r);
1247 
1248     if (protection_domain.not_null()) {
1249       set_protection_domain(mirror(), protection_domain());
1250     }
1251   } else {
1252     ObjArrayKlass* objarray_k = (ObjArrayKlass*)as_Klass(m);
1253     // Mirror should be restored for an ObjArrayKlass or one of its refined array klasses
1254     assert(objarray_k == k || objarray_k->next_refined_array_klass() == k, "must be");
1255   }
1256 
1257   assert(class_loader() == k->class_loader(), "should be same");
1258   if (class_loader.not_null()) {
1259     set_class_loader(mirror(), class_loader());
1260   }
1261 
1262   k->set_java_mirror(mirror);
1263 
1264   set_mirror_module_field(THREAD, k, mirror, module);
1265 
1266   if (log_is_enabled(Trace, aot, heap, mirror)) {
1267     ResourceMark rm(THREAD);
1268     log_trace(aot, heap, mirror)(
1269         "Restored %s archived mirror " PTR_FORMAT, k->external_name(), p2i(mirror()));
1270   }
1271 
1272   return true;
1273 }
1274 #endif // INCLUDE_CDS_JAVA_HEAP

1411   assert(is_instance(java_class), "must be a Class object");
1412   java_class->metadata_field_put(_klass_offset, klass);
1413 }
1414 
1415 
1416 void java_lang_Class::print_signature(oop java_class, outputStream* st) {
1417   assert(is_instance(java_class), "must be a Class object");
1418   Symbol* name = nullptr;
1419   bool is_instance = false;
1420   if (is_primitive(java_class)) {
1421     name = vmSymbols::type_signature(primitive_type(java_class));
1422   } else {
1423     Klass* k = as_Klass(java_class);
1424     is_instance = k->is_instance_klass();
1425     name = k->name();
1426   }
1427   if (name == nullptr) {
1428     st->print("<null>");
1429     return;
1430   }
1431   if (is_instance)  {
1432     st->print("L");
1433   }
1434   st->write((char*) name->base(), (int) name->utf8_length());
1435   if (is_instance)  st->print(";");
1436 }
1437 
1438 Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found) {
1439   assert(is_instance(java_class), "must be a Class object");
1440   Symbol* name;
1441   if (is_primitive(java_class)) {
1442     name = vmSymbols::type_signature(primitive_type(java_class));
1443     // Because this can create a new symbol, the caller has to decrement
1444     // the refcount, so make adjustment here and below for symbols returned
1445     // that are not created or incremented due to a successful lookup.
1446     name->increment_refcount();
1447   } else {
1448     Klass* k = as_Klass(java_class);
1449     if (!k->is_instance_klass()) {
1450       name = k->name();
1451       name->increment_refcount();
1452     } else {
1453       ResourceMark rm;

1472   if (is_primitive(java_class)) {
1473     name = type2name(primitive_type(java_class));
1474   } else {
1475     name = as_Klass(java_class)->external_name();
1476   }
1477   if (name == nullptr) {
1478     name = "<null>";
1479   }
1480   return name;
1481 }
1482 
1483 Klass* java_lang_Class::array_klass_acquire(oop java_class) {
1484   Klass* k = ((Klass*)java_class->metadata_field_acquire(_array_klass_offset));
1485   assert(k == nullptr || (k->is_klass() && k->is_array_klass()), "should be array klass");
1486   return k;
1487 }
1488 
1489 
1490 void java_lang_Class::release_set_array_klass(oop java_class, Klass* klass) {
1491   assert(klass->is_klass() && klass->is_array_klass(), "should be array klass");
1492   assert(!klass->is_refined_objArray_klass(), "should not be ref or flat array klass");
1493   java_class->release_metadata_field_put(_array_klass_offset, klass);
1494 }
1495 
1496 
1497 BasicType java_lang_Class::primitive_type(oop java_class) {
1498   assert(is_primitive(java_class), "just checking");
1499   Klass* ak = ((Klass*)java_class->metadata_field(_array_klass_offset));
1500   BasicType type = T_VOID;
1501   if (ak != nullptr) {
1502     // Note: create_basic_type_mirror above initializes ak to a non-null value.
1503     type = ArrayKlass::cast(ak)->element_type();
1504   } else {
1505     assert(java_class == Universe::void_mirror(), "only valid non-array primitive");
1506   }
1507 #ifdef ASSERT
1508   if (CDSConfig::is_dumping_heap()) {
1509     oop mirror = Universe::java_mirror(type);
1510     oop scratch_mirror = HeapShared::scratch_java_mirror(type);
1511     assert(java_class == mirror || java_class == scratch_mirror, "must be consistent");
1512   } else {

2858 
2859     // the format of the stacktrace will be:
2860     // - 1 or more fillInStackTrace frames for the exception class (skipped)
2861     // - 0 or more <init> methods for the exception class (skipped)
2862     // - rest of the stack
2863 
2864     if (!skip_fillInStackTrace_check) {
2865       if (method->name() == vmSymbols::fillInStackTrace_name() &&
2866           throwable->is_a(method->method_holder())) {
2867         continue;
2868       }
2869       else {
2870         skip_fillInStackTrace_check = true; // gone past them all
2871       }
2872     }
2873     if (!skip_throwableInit_check) {
2874       assert(skip_fillInStackTrace_check, "logic error in backtrace filtering");
2875 
2876       // skip <init> methods of the exception class and superclasses
2877       // This is similar to classic VM.
2878       if (method->is_object_constructor() &&
2879           throwable->is_a(method->method_holder())) {
2880         continue;
2881       } else {
2882         // there are none or we've seen them all - either way stop checking
2883         skip_throwableInit_check = true;
2884       }
2885     }
2886     if (method->is_hidden() || method->is_continuation_enter_intrinsic()) {
2887       if (skip_hidden) {
2888         if (total_count == 0) {
2889           // The top frame will be hidden from the stack trace.
2890           bt.set_has_hidden_top_frame();
2891         }
2892         continue;
2893       }
2894     }
2895 
2896     bt.push(method, bci, CHECK);
2897     total_count++;
2898   }

3217 int java_lang_ClassFrameInfo::_classOrMemberName_offset;
3218 int java_lang_ClassFrameInfo::_flags_offset;
3219 
3220 #define CLASSFRAMEINFO_FIELDS_DO(macro) \
3221   macro(_classOrMemberName_offset, k, "classOrMemberName", object_signature,  false); \
3222   macro(_flags_offset,             k, vmSymbols::flags_name(), int_signature, false)
3223 
3224 void java_lang_ClassFrameInfo::compute_offsets() {
3225   InstanceKlass* k = vmClasses::ClassFrameInfo_klass();
3226   CLASSFRAMEINFO_FIELDS_DO(FIELD_COMPUTE_OFFSET);
3227 }
3228 
3229 #if INCLUDE_CDS
3230 void java_lang_ClassFrameInfo::serialize_offsets(SerializeClosure* f) {
3231   CLASSFRAMEINFO_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
3232 }
3233 #endif
3234 
3235 static int get_flags(const methodHandle& m) {
3236   int flags = m->access_flags().as_method_flags();
3237   if (m->is_object_constructor()) {
3238     flags |= java_lang_invoke_MemberName::MN_IS_OBJECT_CONSTRUCTOR;
3239   } else {
3240     // Note: Static initializers can be here. Record them as plain methods.
3241     flags |= java_lang_invoke_MemberName::MN_IS_METHOD;
3242   }
3243   if (m->caller_sensitive()) {
3244     flags |= java_lang_invoke_MemberName::MN_CALLER_SENSITIVE;
3245   }
3246   if (m->is_hidden()) {
3247     flags |= java_lang_invoke_MemberName::MN_HIDDEN_MEMBER;
3248   }
3249   assert((flags & 0xFF000000) == 0, "unexpected flags");
3250   return flags;
3251 }
3252 
3253 oop java_lang_ClassFrameInfo::classOrMemberName(oop obj) {
3254   return obj->obj_field(_classOrMemberName_offset);
3255 }
3256 
3257 int java_lang_ClassFrameInfo::flags(oop obj) {
3258   return obj->int_field(_flags_offset);

3609   constructor->int_field_put(_modifiers_offset, value);
3610 }
3611 
3612 void java_lang_reflect_Constructor::set_signature(oop constructor, oop value) {
3613   constructor->obj_field_put(_signature_offset, value);
3614 }
3615 
3616 void java_lang_reflect_Constructor::set_annotations(oop constructor, oop value) {
3617   constructor->obj_field_put(_annotations_offset, value);
3618 }
3619 
3620 void java_lang_reflect_Constructor::set_parameter_annotations(oop method, oop value) {
3621   method->obj_field_put(_parameter_annotations_offset, value);
3622 }
3623 
3624 int java_lang_reflect_Field::_clazz_offset;
3625 int java_lang_reflect_Field::_name_offset;
3626 int java_lang_reflect_Field::_type_offset;
3627 int java_lang_reflect_Field::_slot_offset;
3628 int java_lang_reflect_Field::_modifiers_offset;
3629 int java_lang_reflect_Field::_flags_offset;
3630 int java_lang_reflect_Field::_signature_offset;
3631 int java_lang_reflect_Field::_annotations_offset;
3632 
3633 #define FIELD_FIELDS_DO(macro) \
3634   macro(_clazz_offset,     k, vmSymbols::clazz_name(),     class_signature,  false); \
3635   macro(_name_offset,      k, vmSymbols::name_name(),      string_signature, false); \
3636   macro(_type_offset,      k, vmSymbols::type_name(),      class_signature,  false); \
3637   macro(_slot_offset,      k, vmSymbols::slot_name(),      int_signature,    false); \
3638   macro(_modifiers_offset, k, vmSymbols::modifiers_name(), int_signature,    false); \
3639   macro(_flags_offset,     k, vmSymbols::flags_name(),     int_signature,    false); \
3640   macro(_signature_offset,        k, vmSymbols::signature_name(),        string_signature,     false); \
3641   macro(_annotations_offset,      k, vmSymbols::annotations_name(),      byte_array_signature, false);
3642 
3643 void java_lang_reflect_Field::compute_offsets() {
3644   InstanceKlass* k = vmClasses::reflect_Field_klass();
3645   FIELD_FIELDS_DO(FIELD_COMPUTE_OFFSET);
3646 }
3647 
3648 #if INCLUDE_CDS
3649 void java_lang_reflect_Field::serialize_offsets(SerializeClosure* f) {
3650   FIELD_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
3651 }
3652 #endif
3653 
3654 Handle java_lang_reflect_Field::create(TRAPS) {
3655   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
3656   Symbol* name = vmSymbols::java_lang_reflect_Field();
3657   Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH);
3658   InstanceKlass* ik = InstanceKlass::cast(k);
3659   // Ensure it is initialized

3684 void java_lang_reflect_Field::set_type(oop field, oop value) {
3685   field->obj_field_put(_type_offset, value);
3686 }
3687 
3688 int java_lang_reflect_Field::slot(oop reflect) {
3689   return reflect->int_field(_slot_offset);
3690 }
3691 
3692 void java_lang_reflect_Field::set_slot(oop reflect, int value) {
3693   reflect->int_field_put(_slot_offset, value);
3694 }
3695 
3696 int java_lang_reflect_Field::modifiers(oop field) {
3697   return field->int_field(_modifiers_offset);
3698 }
3699 
3700 void java_lang_reflect_Field::set_modifiers(oop field, int value) {
3701   field->int_field_put(_modifiers_offset, value);
3702 }
3703 
3704 void java_lang_reflect_Field::set_flags(oop field, int value) {
3705   field->int_field_put(_flags_offset, value);
3706 }
3707 
3708 void java_lang_reflect_Field::set_signature(oop field, oop value) {
3709   field->obj_field_put(_signature_offset, value);
3710 }
3711 
3712 void java_lang_reflect_Field::set_annotations(oop field, oop value) {
3713   field->obj_field_put(_annotations_offset, value);
3714 }
3715 
3716 oop java_lang_reflect_RecordComponent::create(InstanceKlass* holder, RecordComponent* component, TRAPS) {
3717   // Allocate java.lang.reflect.RecordComponent instance
3718   HandleMark hm(THREAD);
3719   InstanceKlass* ik = vmClasses::RecordComponent_klass();
3720   assert(ik != nullptr, "must be loaded");
3721   ik->initialize(CHECK_NULL);
3722 
3723   Handle element = ik->allocate_instance_handle(CHECK_NULL);
3724 
3725   Handle decl_class(THREAD, holder->java_mirror());

3988 }
3989 #endif
3990 
3991 bool java_lang_ref_Reference::is_referent_field(oop obj, ptrdiff_t offset) {
3992   assert(obj != nullptr, "sanity");
3993   if (offset != _referent_offset) {
3994     return false;
3995   }
3996 
3997   Klass* k = obj->klass();
3998   if (!k->is_instance_klass()) {
3999     return false;
4000   }
4001 
4002   InstanceKlass* ik = InstanceKlass::cast(obj->klass());
4003   bool is_reference = ik->reference_type() != REF_NONE;
4004   assert(!is_reference || ik->is_subclass_of(vmClasses::Reference_klass()), "sanity");
4005   return is_reference;
4006 }
4007 
4008 int* java_lang_boxing_object::_offsets;

4009 
4010 #define BOXING_FIELDS_DO(macro)                                                                                                    \
4011   macro(java_lang_boxing_object::_offsets[T_BOOLEAN - T_BOOLEAN], vmClasses::Boolean_klass(),   "value", bool_signature,   false); \
4012   macro(java_lang_boxing_object::_offsets[T_CHAR - T_BOOLEAN],    vmClasses::Character_klass(), "value", char_signature,   false); \
4013   macro(java_lang_boxing_object::_offsets[T_FLOAT - T_BOOLEAN],   vmClasses::Float_klass(),     "value", float_signature,  false); \
4014   macro(java_lang_boxing_object::_offsets[T_DOUBLE - T_BOOLEAN],  vmClasses::Double_klass(),    "value", double_signature, false); \
4015   macro(java_lang_boxing_object::_offsets[T_BYTE - T_BOOLEAN],    vmClasses::Byte_klass(),      "value", byte_signature,   false); \
4016   macro(java_lang_boxing_object::_offsets[T_SHORT - T_BOOLEAN],   vmClasses::Short_klass(),     "value", short_signature,  false); \
4017   macro(java_lang_boxing_object::_offsets[T_INT - T_BOOLEAN],     vmClasses::Integer_klass(),   "value", int_signature,    false); \
4018   macro(java_lang_boxing_object::_offsets[T_LONG - T_BOOLEAN],    vmClasses::Long_klass(),      "value", long_signature,   false);
4019 
4020 void java_lang_boxing_object::compute_offsets() {
4021   assert(T_LONG - T_BOOLEAN == 7, "Sanity check");
4022   java_lang_boxing_object::_offsets = NEW_C_HEAP_ARRAY(int, 8, mtInternal);
4023   BOXING_FIELDS_DO(FIELD_COMPUTE_OFFSET);
4024 }
4025 
4026 #if INCLUDE_CDS
4027 void java_lang_boxing_object::serialize_offsets(SerializeClosure* f) {
4028   if (f->reading()) {
4029     assert(T_LONG - T_BOOLEAN == 7, "Sanity check");
4030     java_lang_boxing_object::_offsets = NEW_C_HEAP_ARRAY(int, 8, mtInternal);
4031   }
4032   BOXING_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
4033 }
4034 #endif
4035 
4036 oop java_lang_boxing_object::initialize_and_allocate(BasicType type, TRAPS) {
4037   Klass* k = vmClasses::box_klass(type);
4038   if (k == nullptr)  return nullptr;
4039   InstanceKlass* ik = InstanceKlass::cast(k);
4040   if (!ik->is_initialized()) {
4041     ik->initialize(CHECK_NULL);
4042   }
4043   return ik->allocate_instance(THREAD);
4044 }
4045 
4046 
4047 oop java_lang_boxing_object::create(BasicType type, jvalue* value, TRAPS) {
4048   oop box = initialize_and_allocate(type, CHECK_NULL);
4049   if (box == nullptr)  return nullptr;
4050   switch (type) {
4051     case T_BOOLEAN:
4052       box->bool_field_put(value_offset(type), value->z);
4053       break;
4054     case T_CHAR:
4055       box->char_field_put(value_offset(type), value->c);
4056       break;
4057     case T_FLOAT:
4058       box->float_field_put(value_offset(type), value->f);
4059       break;
4060     case T_DOUBLE:
4061       box->double_field_put(value_offset(type), value->d);
4062       break;
4063     case T_BYTE:
4064       box->byte_field_put(value_offset(type), value->b);
4065       break;
4066     case T_SHORT:
4067       box->short_field_put(value_offset(type), value->s);
4068       break;
4069     case T_INT:
4070       box->int_field_put(value_offset(type), value->i);
4071       break;
4072     case T_LONG:
4073       box->long_field_put(value_offset(type), value->j);
4074       break;
4075     default:
4076       return nullptr;
4077   }
4078   return box;
4079 }
4080 
4081 
4082 BasicType java_lang_boxing_object::basic_type(oop box) {
4083   if (box == nullptr)  return T_ILLEGAL;
4084   BasicType type = vmClasses::box_klass_type(box->klass());
4085   if (type == T_OBJECT)         // 'unknown' value returned by SD::bkt
4086     return T_ILLEGAL;
4087   return type;
4088 }
4089 
4090 
4091 BasicType java_lang_boxing_object::get_value(oop box, jvalue* value) {
4092   BasicType type = vmClasses::box_klass_type(box->klass());
4093   switch (type) {
4094   case T_BOOLEAN:
4095     value->z = box->bool_field(value_offset(type));
4096     break;
4097   case T_CHAR:
4098     value->c = box->char_field(value_offset(type));
4099     break;
4100   case T_FLOAT:
4101     value->f = box->float_field(value_offset(type));
4102     break;
4103   case T_DOUBLE:
4104     value->d = box->double_field(value_offset(type));
4105     break;
4106   case T_BYTE:
4107     value->b = box->byte_field(value_offset(type));
4108     break;
4109   case T_SHORT:
4110     value->s = box->short_field(value_offset(type));
4111     break;
4112   case T_INT:
4113     value->i = box->int_field(value_offset(type));
4114     break;
4115   case T_LONG:
4116     value->j = box->long_field(value_offset(type));
4117     break;
4118   default:
4119     return T_ILLEGAL;
4120   } // end switch
4121   return type;
4122 }
4123 
4124 
4125 BasicType java_lang_boxing_object::set_value(oop box, jvalue* value) {
4126   BasicType type = vmClasses::box_klass_type(box->klass());
4127   switch (type) {
4128   case T_BOOLEAN:
4129     box->bool_field_put(value_offset(type), value->z);
4130     break;
4131   case T_CHAR:
4132     box->char_field_put(value_offset(type), value->c);
4133     break;
4134   case T_FLOAT:
4135     box->float_field_put(value_offset(type), value->f);
4136     break;
4137   case T_DOUBLE:
4138     box->double_field_put(value_offset(type), value->d);
4139     break;
4140   case T_BYTE:
4141     box->byte_field_put(value_offset(type), value->b);
4142     break;
4143   case T_SHORT:
4144     box->short_field_put(value_offset(type), value->s);
4145     break;
4146   case T_INT:
4147     box->int_field_put(value_offset(type), value->i);
4148     break;
4149   case T_LONG:
4150     box->long_field_put(value_offset(type), value->j);
4151     break;
4152   default:
4153     return T_ILLEGAL;
4154   } // end switch
4155   return type;
4156 }
4157 
4158 
4159 void java_lang_boxing_object::print(BasicType type, jvalue* value, outputStream* st) {
4160   switch (type) {
4161   case T_BOOLEAN:   st->print("%s", value->z ? "true" : "false");   break;
4162   case T_CHAR:      st->print("%d", value->c);                      break;
4163   case T_BYTE:      st->print("%d", value->b);                      break;
4164   case T_SHORT:     st->print("%d", value->s);                      break;
4165   case T_INT:       st->print("%d", value->i);                      break;
4166   case T_LONG:      st->print(JLONG_FORMAT, value->j);              break;
4167   case T_FLOAT:     st->print("%f", value->f);                      break;
4168   case T_DOUBLE:    st->print("%lf", value->d);                     break;
4169   default:          st->print("type %d?", type);                    break;
4170   }

4526 oop java_lang_invoke_MemberName::type(oop mname) {
4527   assert(is_instance(mname), "wrong type");
4528   return mname->obj_field(_type_offset);
4529 }
4530 
4531 void java_lang_invoke_MemberName::set_type(oop mname, oop type) {
4532   assert(is_instance(mname), "wrong type");
4533   mname->obj_field_put(_type_offset, type);
4534 }
4535 
4536 int java_lang_invoke_MemberName::flags(oop mname) {
4537   assert(is_instance(mname), "wrong type");
4538   return mname->int_field(_flags_offset);
4539 }
4540 
4541 void java_lang_invoke_MemberName::set_flags(oop mname, int flags) {
4542   assert(is_instance(mname), "wrong type");
4543   mname->int_field_put(_flags_offset, flags);
4544 }
4545 

4546 // Return vmtarget from ResolvedMethodName method field through indirection
4547 Method* java_lang_invoke_MemberName::vmtarget(oop mname) {
4548   assert(is_instance(mname), "wrong type");
4549   oop method = mname->obj_field(_method_offset);
4550   return method == nullptr ? nullptr : java_lang_invoke_ResolvedMethodName::vmtarget(method);
4551 }
4552 
4553 bool java_lang_invoke_MemberName::is_method(oop mname) {
4554   assert(is_instance(mname), "must be MemberName");
4555   return (flags(mname) & (MN_IS_METHOD | MN_IS_OBJECT_CONSTRUCTOR)) > 0;
4556 }
4557 
4558 void java_lang_invoke_MemberName::set_method(oop mname, oop resolved_method) {
4559   assert(is_instance(mname), "wrong type");
4560   mname->obj_field_put(_method_offset, resolved_method);
4561 }
4562 
4563 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) {
4564   assert(is_instance(mname), "wrong type");
4565   return (intptr_t) mname->address_field(_vmindex_offset);
4566 }
4567 
4568 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
4569   assert(is_instance(mname), "wrong type");
4570   mname->address_field_put(_vmindex_offset, (address) index);
4571 }
4572 
4573 
4574 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) {
4575   assert(is_instance(resolved_method), "wrong type");

5528   if (!ik->find_local_field(f_name, f_sig, &fd)) {
5529     tty->print_cr("Nonstatic field %s.%s not found", klass_name, field_name);
5530     return false;
5531   }
5532   if (fd.is_static()) {
5533     tty->print_cr("Nonstatic field %s.%s appears to be static", klass_name, field_name);
5534     return false;
5535   }
5536   if (fd.offset() == deserialized_offset ) {
5537     return true;
5538   } else {
5539     tty->print_cr("Offset of nonstatic field %s.%s is deserialized as %d but should really be %d.",
5540                   klass_name, field_name, deserialized_offset, fd.offset());
5541     return false;
5542   }
5543 }
5544 
5545 void JavaClasses::check_offsets() {
5546   bool valid = true;
5547 
5548 #define CHECK_OFFSET(klass_name, type, field_sig) \
5549   valid &= check_offset(klass_name, java_lang_boxing_object::value_offset(type), "value", field_sig)
5550 
5551   CHECK_OFFSET("java/lang/Boolean",   T_BOOLEAN, "Z");
5552   CHECK_OFFSET("java/lang/Character", T_CHAR,    "C");
5553   CHECK_OFFSET("java/lang/Float",     T_FLOAT,   "F");
5554   CHECK_OFFSET("java/lang/Double",    T_DOUBLE,  "D");
5555   CHECK_OFFSET("java/lang/Byte",      T_BYTE,    "B");
5556   CHECK_OFFSET("java/lang/Short",     T_SHORT,   "S");
5557   CHECK_OFFSET("java/lang/Integer",   T_INT,     "I");
5558   CHECK_OFFSET("java/lang/Long",      T_LONG,    "J");





5559 
5560   if (!valid) vm_exit_during_initialization("Field offset verification failed");
5561 }
5562 
5563 #endif // PRODUCT
5564 
5565 int InjectedField::compute_offset() {
5566   InstanceKlass* ik = InstanceKlass::cast(klass());
5567   for (AllFieldStream fs(ik); !fs.done(); fs.next()) {
5568     if (!may_be_java && !fs.field_flags().is_injected()) {
5569       // Only look at injected fields
5570       continue;
5571     }
5572     if (fs.name() == name() && fs.signature() == signature()) {
5573       return fs.offset();
5574     }
5575   }
5576   ResourceMark rm;
5577   tty->print_cr("Invalid layout of %s at %s/%s%s", ik->external_name(), name()->as_C_string(), signature()->as_C_string(), may_be_java ? " (may_be_java)" : "");
5578 #ifndef PRODUCT
< prev index next >