< 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.inline.hpp"
  59 #include "oops/method.inline.hpp"
  60 #include "oops/objArrayKlass.hpp"
  61 #include "oops/objArrayOop.inline.hpp"
  62 #include "oops/oop.inline.hpp"
  63 #include "oops/oopCast.inline.hpp"
  64 #include "oops/recordComponent.hpp"
  65 #include "oops/symbol.hpp"
  66 #include "oops/typeArrayOop.inline.hpp"
  67 #include "prims/jvmtiExport.hpp"
  68 #include "prims/methodHandles.hpp"
  69 #include "prims/resolvedMethodTable.hpp"
  70 #include "runtime/continuationEntry.inline.hpp"
  71 #include "runtime/continuationJavaClasses.inline.hpp"
  72 #include "runtime/fieldDescriptor.inline.hpp"
  73 #include "runtime/frame.inline.hpp"
  74 #include "runtime/handles.inline.hpp"
  75 #include "runtime/handshake.hpp"
  76 #include "runtime/init.hpp"
  77 #include "runtime/interfaceSupport.inline.hpp"

1087   mirror = Handle(THREAD, mirror_oop);
1088 
1089   // Setup indirection from mirror->klass
1090   set_klass(mirror(), k);
1091 
1092   // Set the modifiers flag.
1093   u2 computed_modifiers = k->compute_modifier_flags();
1094   set_modifiers(mirror(), computed_modifiers);
1095   // Set the raw access_flags, this is used by reflection instead of modifier flags.
1096   // The Java code for array classes gets the access flags from the element type.
1097   assert(!k->is_array_klass() || k->access_flags().as_unsigned_short() == 0, "access flags are not set for arrays");
1098   set_raw_access_flags(mirror(), k->access_flags().as_unsigned_short());
1099 
1100   InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
1101   assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
1102 
1103   set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
1104 
1105   // It might also have a component mirror.  This mirror must already exist.
1106   if (k->is_array_klass()) {
1107     if (k->is_typeArray_klass()) {








1108       BasicType type = TypeArrayKlass::cast(k)->element_type();
1109       if (is_scratch) {
1110         comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(type));
1111       } else {
1112         comp_mirror = Handle(THREAD, Universe::java_mirror(type));
1113       }
1114     } else {
1115       assert(k->is_objArray_klass(), "Must be");

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

1118       if (is_scratch) {
1119         comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(element_klass));
1120       } else {
1121         comp_mirror = Handle(THREAD, element_klass->java_mirror());
1122       }
1123     }
1124     assert(comp_mirror() != nullptr, "must have a mirror");
1125 
1126     // Two-way link between the array klass and its component mirror:
1127     // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
1128     set_component_mirror(mirror(), comp_mirror());
1129     // See below for ordering dependencies between field array_klass in component mirror
1130     // and java_mirror in this klass.
1131   } else {
1132     assert(k->is_instance_klass(), "Must be");
1133     initialize_mirror_fields(InstanceKlass::cast(k), mirror, protection_domain, classData, THREAD);
1134     if (HAS_PENDING_EXCEPTION) {
1135       // If any of the fields throws an exception like OOM remove the klass field
1136       // from the mirror so GC doesn't follow it after the klass has been deallocated.
1137       // This mirror looks like a primitive type, which logically it is because it
1138       // it represents no class.
1139       set_klass(mirror(), nullptr);
1140       return;
1141     }
1142   }
1143 }
1144 
1145 void java_lang_Class::create_mirror(Klass* k, Handle class_loader,
1146                                     Handle module, Handle protection_domain,
1147                                     Handle classData, TRAPS) {
1148   assert(k != nullptr, "Use create_basic_type_mirror for primitive types");
1149   assert(k->java_mirror() == nullptr, "should only assign mirror once");
1150 
1151   // Class_klass has to be loaded because it is used to allocate
1152   // the mirror.
1153   if (vmClasses::Class_klass_is_loaded()) {









1154     Handle mirror;
1155     Handle comp_mirror;
1156 
1157     allocate_mirror(k, /*is_scratch=*/false, protection_domain, classData, mirror, comp_mirror, CHECK);
1158 
1159     // set the classLoader field in the java_lang_Class instance
1160     assert(class_loader() == k->class_loader(), "should be same");
1161     set_class_loader(mirror(), class_loader());
1162 
1163     // Setup indirection from klass->mirror
1164     // after any exceptions can happen during allocations.
1165     k->set_java_mirror(mirror);
1166 
1167     // Set the module field in the java_lang_Class instance.  This must be done
1168     // after the mirror is set.
1169     set_mirror_module_field(THREAD, k, mirror, module);
1170 
1171     if (comp_mirror() != nullptr) {
1172       // Set after k->java_mirror() is published, because compiled code running
1173       // concurrently doesn't expect a k to have a null java_mirror.
1174       release_set_array_klass(comp_mirror(), k);
1175     }

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

1244     // - local static final fields with initial values were initialized at dump time
1245 
1246     // create the init_lock
1247     typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK_(false));
1248     set_init_lock(mirror(), r);
1249 
1250     if (protection_domain.not_null()) {
1251       set_protection_domain(mirror(), protection_domain());
1252     }




1253   }
1254 
1255   assert(class_loader() == k->class_loader(), "should be same");
1256   if (class_loader.not_null()) {
1257     set_class_loader(mirror(), class_loader());
1258   }
1259 
1260   k->set_java_mirror(mirror);
1261 
1262   set_mirror_module_field(THREAD, k, mirror, module);
1263 
1264   if (log_is_enabled(Trace, aot, heap, mirror)) {
1265     ResourceMark rm(THREAD);
1266     log_trace(aot, heap, mirror)(
1267         "Restored %s archived mirror " PTR_FORMAT, k->external_name(), p2i(mirror()));
1268   }
1269 
1270   return true;
1271 }
1272 #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)  st->print("L");


1432   st->write((char*) name->base(), (int) name->utf8_length());
1433   if (is_instance)  st->print(";");
1434 }
1435 
1436 Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found) {
1437   assert(is_instance(java_class), "must be a Class object");
1438   Symbol* name;
1439   if (is_primitive(java_class)) {
1440     name = vmSymbols::type_signature(primitive_type(java_class));
1441     // Because this can create a new symbol, the caller has to decrement
1442     // the refcount, so make adjustment here and below for symbols returned
1443     // that are not created or incremented due to a successful lookup.
1444     name->increment_refcount();
1445   } else {
1446     Klass* k = as_Klass(java_class);
1447     if (!k->is_instance_klass()) {
1448       name = k->name();
1449       name->increment_refcount();
1450     } else {
1451       ResourceMark rm;

1470   if (is_primitive(java_class)) {
1471     name = type2name(primitive_type(java_class));
1472   } else {
1473     name = as_Klass(java_class)->external_name();
1474   }
1475   if (name == nullptr) {
1476     name = "<null>";
1477   }
1478   return name;
1479 }
1480 
1481 Klass* java_lang_Class::array_klass_acquire(oop java_class) {
1482   Klass* k = ((Klass*)java_class->metadata_field_acquire(_array_klass_offset));
1483   assert(k == nullptr || (k->is_klass() && k->is_array_klass()), "should be array klass");
1484   return k;
1485 }
1486 
1487 
1488 void java_lang_Class::release_set_array_klass(oop java_class, Klass* klass) {
1489   assert(klass->is_klass() && klass->is_array_klass(), "should be array klass");

1490   java_class->release_metadata_field_put(_array_klass_offset, klass);
1491 }
1492 
1493 
1494 BasicType java_lang_Class::primitive_type(oop java_class) {
1495   assert(is_primitive(java_class), "just checking");
1496   Klass* ak = ((Klass*)java_class->metadata_field(_array_klass_offset));
1497   BasicType type = T_VOID;
1498   if (ak != nullptr) {
1499     // Note: create_basic_type_mirror above initializes ak to a non-null value.
1500     type = ArrayKlass::cast(ak)->element_type();
1501   } else {
1502     assert(java_class == Universe::void_mirror(), "only valid non-array primitive");
1503   }
1504 #ifdef ASSERT
1505   if (CDSConfig::is_dumping_heap()) {
1506     oop mirror = Universe::java_mirror(type);
1507     oop scratch_mirror = HeapShared::scratch_java_mirror(type);
1508     assert(java_class == mirror || java_class == scratch_mirror, "must be consistent");
1509   } else {

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

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

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

3674 void java_lang_reflect_Field::set_type(oop field, oop value) {
3675   field->obj_field_put(_type_offset, value);
3676 }
3677 
3678 int java_lang_reflect_Field::slot(oop reflect) {
3679   return reflect->int_field(_slot_offset);
3680 }
3681 
3682 void java_lang_reflect_Field::set_slot(oop reflect, int value) {
3683   reflect->int_field_put(_slot_offset, value);
3684 }
3685 
3686 int java_lang_reflect_Field::modifiers(oop field) {
3687   return field->int_field(_modifiers_offset);
3688 }
3689 
3690 void java_lang_reflect_Field::set_modifiers(oop field, int value) {
3691   field->int_field_put(_modifiers_offset, value);
3692 }
3693 
3694 void java_lang_reflect_Field::set_trusted_final(oop field) {
3695   field->bool_field_put(_trusted_final_offset, true);
3696 }
3697 
3698 void java_lang_reflect_Field::set_signature(oop field, oop value) {
3699   field->obj_field_put(_signature_offset, value);
3700 }
3701 
3702 void java_lang_reflect_Field::set_annotations(oop field, oop value) {
3703   field->obj_field_put(_annotations_offset, value);
3704 }
3705 
3706 oop java_lang_reflect_RecordComponent::create(InstanceKlass* holder, RecordComponent* component, TRAPS) {
3707   // Allocate java.lang.reflect.RecordComponent instance
3708   HandleMark hm(THREAD);
3709   InstanceKlass* ik = vmClasses::RecordComponent_klass();
3710   assert(ik != nullptr, "must be loaded");
3711   ik->initialize(CHECK_NULL);
3712 
3713   Handle element = ik->allocate_instance_handle(CHECK_NULL);
3714 
3715   Handle decl_class(THREAD, holder->java_mirror());

3975 }
3976 #endif
3977 
3978 bool java_lang_ref_Reference::is_referent_field(oop obj, ptrdiff_t offset) {
3979   assert(obj != nullptr, "sanity");
3980   if (offset != _referent_offset) {
3981     return false;
3982   }
3983 
3984   Klass* k = obj->klass();
3985   if (!k->is_instance_klass()) {
3986     return false;
3987   }
3988 
3989   InstanceKlass* ik = InstanceKlass::cast(obj->klass());
3990   bool is_reference = ik->reference_type() != REF_NONE;
3991   assert(!is_reference || ik->is_subclass_of(vmClasses::Reference_klass()), "sanity");
3992   return is_reference;
3993 }
3994 
3995 int java_lang_boxing_object::_value_offset;
3996 int java_lang_boxing_object::_long_value_offset;
3997 
3998 #define BOXING_FIELDS_DO(macro) \
3999   macro(_value_offset,      integerKlass, "value", int_signature, false); \
4000   macro(_long_value_offset, longKlass, "value", long_signature, false);






4001 
4002 void java_lang_boxing_object::compute_offsets() {
4003   InstanceKlass* integerKlass = vmClasses::Integer_klass();
4004   InstanceKlass* longKlass = vmClasses::Long_klass();
4005   BOXING_FIELDS_DO(FIELD_COMPUTE_OFFSET);
4006 }
4007 
4008 #if INCLUDE_CDS
4009 void java_lang_boxing_object::serialize_offsets(SerializeClosure* f) {




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

4504 oop java_lang_invoke_MemberName::type(oop mname) {
4505   assert(is_instance(mname), "wrong type");
4506   return mname->obj_field(_type_offset);
4507 }
4508 
4509 void java_lang_invoke_MemberName::set_type(oop mname, oop type) {
4510   assert(is_instance(mname), "wrong type");
4511   mname->obj_field_put(_type_offset, type);
4512 }
4513 
4514 int java_lang_invoke_MemberName::flags(oop mname) {
4515   assert(is_instance(mname), "wrong type");
4516   return mname->int_field(_flags_offset);
4517 }
4518 
4519 void java_lang_invoke_MemberName::set_flags(oop mname, int flags) {
4520   assert(is_instance(mname), "wrong type");
4521   mname->int_field_put(_flags_offset, flags);
4522 }
4523 
4524 
4525 // Return vmtarget from ResolvedMethodName method field through indirection
4526 Method* java_lang_invoke_MemberName::vmtarget(oop mname) {
4527   assert(is_instance(mname), "wrong type");
4528   oop method = mname->obj_field(_method_offset);
4529   return method == nullptr ? nullptr : java_lang_invoke_ResolvedMethodName::vmtarget(method);
4530 }
4531 
4532 bool java_lang_invoke_MemberName::is_method(oop mname) {
4533   assert(is_instance(mname), "must be MemberName");
4534   return (flags(mname) & (MN_IS_METHOD | MN_IS_CONSTRUCTOR)) > 0;
4535 }
4536 
4537 void java_lang_invoke_MemberName::set_method(oop mname, oop resolved_method) {
4538   assert(is_instance(mname), "wrong type");
4539   mname->obj_field_put(_method_offset, resolved_method);
4540 }
4541 
4542 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) {
4543   assert(is_instance(mname), "wrong type");
4544   return (intptr_t) mname->address_field(_vmindex_offset);
4545 }
4546 
4547 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
4548   assert(is_instance(mname), "wrong type");
4549   mname->address_field_put(_vmindex_offset, (address) index);
4550 }
4551 
4552 
4553 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) {
4554   assert(is_instance(resolved_method), "wrong type");

5507   if (!ik->find_local_field(f_name, f_sig, &fd)) {
5508     tty->print_cr("Nonstatic field %s.%s not found", klass_name, field_name);
5509     return false;
5510   }
5511   if (fd.is_static()) {
5512     tty->print_cr("Nonstatic field %s.%s appears to be static", klass_name, field_name);
5513     return false;
5514   }
5515   if (fd.offset() == deserialized_offset ) {
5516     return true;
5517   } else {
5518     tty->print_cr("Offset of nonstatic field %s.%s is deserialized as %d but should really be %d.",
5519                   klass_name, field_name, deserialized_offset, fd.offset());
5520     return false;
5521   }
5522 }
5523 
5524 void JavaClasses::check_offsets() {
5525   bool valid = true;
5526 
5527 #define CHECK_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \
5528   valid &= check_offset(klass_name, cpp_klass_name :: _##field_name ## _offset, #field_name, field_sig)
5529 
5530 #define CHECK_LONG_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \
5531   valid &= check_offset(klass_name, cpp_klass_name :: _##long_ ## field_name ## _offset, #field_name, field_sig)
5532 
5533   // Boxed primitive objects (java_lang_boxing_object)
5534 
5535   CHECK_OFFSET("java/lang/Boolean",   java_lang_boxing_object, value, "Z");
5536   CHECK_OFFSET("java/lang/Character", java_lang_boxing_object, value, "C");
5537   CHECK_OFFSET("java/lang/Float",     java_lang_boxing_object, value, "F");
5538   CHECK_LONG_OFFSET("java/lang/Double", java_lang_boxing_object, value, "D");
5539   CHECK_OFFSET("java/lang/Byte",      java_lang_boxing_object, value, "B");
5540   CHECK_OFFSET("java/lang/Short",     java_lang_boxing_object, value, "S");
5541   CHECK_OFFSET("java/lang/Integer",   java_lang_boxing_object, value, "I");
5542   CHECK_LONG_OFFSET("java/lang/Long", java_lang_boxing_object, value, "J");
5543 
5544   if (!valid) vm_exit_during_initialization("Field offset verification failed");
5545 }
5546 
5547 #endif // PRODUCT
5548 
5549 int InjectedField::compute_offset() {
5550   InstanceKlass* ik = klass();
5551   for (AllFieldStream fs(ik); !fs.done(); fs.next()) {
5552     if (!may_be_java && !fs.field_flags().is_injected()) {
5553       // Only look at injected fields
5554       continue;
5555     }
5556     if (fs.name() == name() && fs.signature() == signature()) {
5557       return fs.offset();
5558     }
5559   }
5560   ResourceMark rm;
5561   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)" : "");
5562 #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.inline.hpp"
  61 #include "oops/method.inline.hpp"
  62 #include "oops/objArrayKlass.hpp"
  63 #include "oops/objArrayOop.inline.hpp"
  64 #include "oops/oop.inline.hpp"
  65 #include "oops/oopCast.inline.hpp"
  66 #include "oops/recordComponent.hpp"
  67 #include "oops/symbol.hpp"
  68 #include "oops/typeArrayOop.inline.hpp"
  69 #include "prims/jvmtiExport.hpp"
  70 #include "prims/methodHandles.hpp"
  71 #include "prims/resolvedMethodTable.hpp"
  72 #include "runtime/continuationEntry.inline.hpp"
  73 #include "runtime/continuationJavaClasses.inline.hpp"
  74 #include "runtime/fieldDescriptor.inline.hpp"
  75 #include "runtime/frame.inline.hpp"
  76 #include "runtime/handles.inline.hpp"
  77 #include "runtime/handshake.hpp"
  78 #include "runtime/init.hpp"
  79 #include "runtime/interfaceSupport.inline.hpp"

1089   mirror = Handle(THREAD, mirror_oop);
1090 
1091   // Setup indirection from mirror->klass
1092   set_klass(mirror(), k);
1093 
1094   // Set the modifiers flag.
1095   u2 computed_modifiers = k->compute_modifier_flags();
1096   set_modifiers(mirror(), computed_modifiers);
1097   // Set the raw access_flags, this is used by reflection instead of modifier flags.
1098   // The Java code for array classes gets the access flags from the element type.
1099   assert(!k->is_array_klass() || k->access_flags().as_unsigned_short() == 0, "access flags are not set for arrays");
1100   set_raw_access_flags(mirror(), k->access_flags().as_unsigned_short());
1101 
1102   InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
1103   assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
1104 
1105   set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
1106 
1107   // It might also have a component mirror.  This mirror must already exist.
1108   if (k->is_array_klass()) {
1109     if (k->is_flatArray_klass()) {
1110       Klass* element_klass = (Klass*) FlatArrayKlass::cast(k)->element_klass();
1111       assert(element_klass->is_inline_klass(), "Must be inline type component");
1112       if (is_scratch) {
1113         comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(element_klass));
1114       } else {
1115         comp_mirror = Handle(THREAD, element_klass->java_mirror());
1116       }
1117     } else if (k->is_typeArray_klass()) {
1118       BasicType type = TypeArrayKlass::cast(k)->element_type();
1119       if (is_scratch) {
1120         comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(type));
1121       } else {
1122         comp_mirror = Handle(THREAD, Universe::java_mirror(type));
1123       }
1124     } else {
1125       assert(k->is_objArray_klass(), "Must be");
1126       assert(!k->is_refArray_klass() || !k->is_flatArray_klass(), "Must not have mirror");
1127       Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
1128       assert(element_klass != nullptr, "Must have an element klass");
1129       oop comp_oop = element_klass->java_mirror();
1130       if (is_scratch) {
1131         comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(element_klass));
1132       } else {
1133         comp_mirror = Handle(THREAD, comp_oop);
1134       }
1135     }
1136     assert(comp_mirror() != nullptr, "must have a mirror");
1137 
1138     // Two-way link between the array klass and its component mirror:
1139     // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
1140     set_component_mirror(mirror(), comp_mirror());
1141     // See below for ordering dependencies between field array_klass in component mirror
1142     // and java_mirror in this klass.
1143   } else {
1144     assert(k->is_instance_klass(), "Must be");
1145     initialize_mirror_fields(InstanceKlass::cast(k), mirror, protection_domain, classData, THREAD);
1146     if (HAS_PENDING_EXCEPTION) {
1147       // If any of the fields throws an exception like OOM remove the klass field
1148       // from the mirror so GC doesn't follow it after the klass has been deallocated.
1149       // This mirror looks like a primitive type, which logically it is because it
1150       // it represents no class.
1151       set_klass(mirror(), nullptr);
1152       return;
1153     }
1154   }
1155 }
1156 
1157 void java_lang_Class::create_mirror(Klass* k, Handle class_loader,
1158                                     Handle module, Handle protection_domain,
1159                                     Handle classData, TRAPS) {
1160   assert(k != nullptr, "Use create_basic_type_mirror for primitive types");
1161   assert(k->java_mirror() == nullptr, "should only assign mirror once");

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

1261   Handle mirror(THREAD, m);
1262 
1263   if (!k->is_array_klass()) {
1264     assert(as_Klass(m) == k, "must be");
1265     // - local static final fields with initial values were initialized at dump time
1266 
1267     // create the init_lock
1268     typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK_(false));
1269     set_init_lock(mirror(), r);
1270 
1271     if (protection_domain.not_null()) {
1272       set_protection_domain(mirror(), protection_domain());
1273     }
1274   } else {
1275     ObjArrayKlass* objarray_k = (ObjArrayKlass*)as_Klass(m);
1276     // Mirror should be restored for an ObjArrayKlass or one of its refined array klasses
1277     assert(objarray_k == k || objarray_k->next_refined_array_klass() == k, "must be");
1278   }
1279 
1280   assert(class_loader() == k->class_loader(), "should be same");
1281   if (class_loader.not_null()) {
1282     set_class_loader(mirror(), class_loader());
1283   }
1284 
1285   k->set_java_mirror(mirror);
1286 
1287   set_mirror_module_field(THREAD, k, mirror, module);
1288 
1289   if (log_is_enabled(Trace, aot, heap, mirror)) {
1290     ResourceMark rm(THREAD);
1291     log_trace(aot, heap, mirror)(
1292         "Restored %s archived mirror " PTR_FORMAT, k->external_name(), p2i(mirror()));
1293   }
1294 
1295   return true;
1296 }
1297 #endif // INCLUDE_CDS_JAVA_HEAP

1436   assert(is_instance(java_class), "must be a Class object");
1437   java_class->metadata_field_put(_klass_offset, klass);
1438 }
1439 
1440 
1441 void java_lang_Class::print_signature(oop java_class, outputStream* st) {
1442   assert(is_instance(java_class), "must be a Class object");
1443   Symbol* name = nullptr;
1444   bool is_instance = false;
1445   if (is_primitive(java_class)) {
1446     name = vmSymbols::type_signature(primitive_type(java_class));
1447   } else {
1448     Klass* k = as_Klass(java_class);
1449     is_instance = k->is_instance_klass();
1450     name = k->name();
1451   }
1452   if (name == nullptr) {
1453     st->print("<null>");
1454     return;
1455   }
1456   if (is_instance)  {
1457     st->print("L");
1458   }
1459   st->write((char*) name->base(), (int) name->utf8_length());
1460   if (is_instance)  st->print(";");
1461 }
1462 
1463 Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found) {
1464   assert(is_instance(java_class), "must be a Class object");
1465   Symbol* name;
1466   if (is_primitive(java_class)) {
1467     name = vmSymbols::type_signature(primitive_type(java_class));
1468     // Because this can create a new symbol, the caller has to decrement
1469     // the refcount, so make adjustment here and below for symbols returned
1470     // that are not created or incremented due to a successful lookup.
1471     name->increment_refcount();
1472   } else {
1473     Klass* k = as_Klass(java_class);
1474     if (!k->is_instance_klass()) {
1475       name = k->name();
1476       name->increment_refcount();
1477     } else {
1478       ResourceMark rm;

1497   if (is_primitive(java_class)) {
1498     name = type2name(primitive_type(java_class));
1499   } else {
1500     name = as_Klass(java_class)->external_name();
1501   }
1502   if (name == nullptr) {
1503     name = "<null>";
1504   }
1505   return name;
1506 }
1507 
1508 Klass* java_lang_Class::array_klass_acquire(oop java_class) {
1509   Klass* k = ((Klass*)java_class->metadata_field_acquire(_array_klass_offset));
1510   assert(k == nullptr || (k->is_klass() && k->is_array_klass()), "should be array klass");
1511   return k;
1512 }
1513 
1514 
1515 void java_lang_Class::release_set_array_klass(oop java_class, Klass* klass) {
1516   assert(klass->is_klass() && klass->is_array_klass(), "should be array klass");
1517   assert(!klass->is_refined_objArray_klass(), "should not be ref or flat array klass");
1518   java_class->release_metadata_field_put(_array_klass_offset, klass);
1519 }
1520 
1521 
1522 BasicType java_lang_Class::primitive_type(oop java_class) {
1523   assert(is_primitive(java_class), "just checking");
1524   Klass* ak = ((Klass*)java_class->metadata_field(_array_klass_offset));
1525   BasicType type = T_VOID;
1526   if (ak != nullptr) {
1527     // Note: create_basic_type_mirror above initializes ak to a non-null value.
1528     type = ArrayKlass::cast(ak)->element_type();
1529   } else {
1530     assert(java_class == Universe::void_mirror(), "only valid non-array primitive");
1531   }
1532 #ifdef ASSERT
1533   if (CDSConfig::is_dumping_heap()) {
1534     oop mirror = Universe::java_mirror(type);
1535     oop scratch_mirror = HeapShared::scratch_java_mirror(type);
1536     assert(java_class == mirror || java_class == scratch_mirror, "must be consistent");
1537   } else {

2876 
2877     // the format of the stacktrace will be:
2878     // - 1 or more fillInStackTrace frames for the exception class (skipped)
2879     // - 0 or more <init> methods for the exception class (skipped)
2880     // - rest of the stack
2881 
2882     if (!skip_fillInStackTrace_check) {
2883       if (method->name() == vmSymbols::fillInStackTrace_name() &&
2884           throwable->is_a(method->method_holder())) {
2885         continue;
2886       }
2887       else {
2888         skip_fillInStackTrace_check = true; // gone past them all
2889       }
2890     }
2891     if (!skip_throwableInit_check) {
2892       assert(skip_fillInStackTrace_check, "logic error in backtrace filtering");
2893 
2894       // skip <init> methods of the exception class and superclasses
2895       // This is similar to classic VM.
2896       if (method->is_object_constructor() &&
2897           throwable->is_a(method->method_holder())) {
2898         continue;
2899       } else {
2900         // there are none or we've seen them all - either way stop checking
2901         skip_throwableInit_check = true;
2902       }
2903     }
2904     if (method->is_hidden() || method->is_continuation_enter_intrinsic()) {
2905       if (skip_hidden) {
2906         if (total_count == 0) {
2907           // The top frame will be hidden from the stack trace.
2908           bt.set_has_hidden_top_frame();
2909         }
2910         continue;
2911       }
2912     }
2913 
2914     bt.push(method, bci, CHECK);
2915     total_count++;
2916   }

3235 int java_lang_ClassFrameInfo::_classOrMemberName_offset;
3236 int java_lang_ClassFrameInfo::_flags_offset;
3237 
3238 #define CLASSFRAMEINFO_FIELDS_DO(macro) \
3239   macro(_classOrMemberName_offset, k, "classOrMemberName", object_signature,  false); \
3240   macro(_flags_offset,             k, vmSymbols::flags_name(), int_signature, false)
3241 
3242 void java_lang_ClassFrameInfo::compute_offsets() {
3243   InstanceKlass* k = vmClasses::ClassFrameInfo_klass();
3244   CLASSFRAMEINFO_FIELDS_DO(FIELD_COMPUTE_OFFSET);
3245 }
3246 
3247 #if INCLUDE_CDS
3248 void java_lang_ClassFrameInfo::serialize_offsets(SerializeClosure* f) {
3249   CLASSFRAMEINFO_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
3250 }
3251 #endif
3252 
3253 static int get_flags(const methodHandle& m) {
3254   int flags = m->access_flags().as_method_flags();
3255   if (m->is_object_constructor()) {
3256     flags |= java_lang_invoke_MemberName::MN_IS_OBJECT_CONSTRUCTOR;
3257   } else {
3258     // Note: Static initializers can be here. Record them as plain methods.
3259     flags |= java_lang_invoke_MemberName::MN_IS_METHOD;
3260   }
3261   if (m->caller_sensitive()) {
3262     flags |= java_lang_invoke_MemberName::MN_CALLER_SENSITIVE;
3263   }
3264   if (m->is_hidden()) {
3265     flags |= java_lang_invoke_MemberName::MN_HIDDEN_MEMBER;
3266   }
3267   assert((flags & 0xFF000000) == 0, "unexpected flags");
3268   return flags;
3269 }
3270 
3271 oop java_lang_ClassFrameInfo::classOrMemberName(oop obj) {
3272   return obj->obj_field(_classOrMemberName_offset);
3273 }
3274 
3275 int java_lang_ClassFrameInfo::flags(oop obj) {
3276   return obj->int_field(_flags_offset);

3627   constructor->int_field_put(_modifiers_offset, value);
3628 }
3629 
3630 void java_lang_reflect_Constructor::set_signature(oop constructor, oop value) {
3631   constructor->obj_field_put(_signature_offset, value);
3632 }
3633 
3634 void java_lang_reflect_Constructor::set_annotations(oop constructor, oop value) {
3635   constructor->obj_field_put(_annotations_offset, value);
3636 }
3637 
3638 void java_lang_reflect_Constructor::set_parameter_annotations(oop method, oop value) {
3639   method->obj_field_put(_parameter_annotations_offset, value);
3640 }
3641 
3642 int java_lang_reflect_Field::_clazz_offset;
3643 int java_lang_reflect_Field::_name_offset;
3644 int java_lang_reflect_Field::_type_offset;
3645 int java_lang_reflect_Field::_slot_offset;
3646 int java_lang_reflect_Field::_modifiers_offset;
3647 int java_lang_reflect_Field::_flags_offset;
3648 int java_lang_reflect_Field::_signature_offset;
3649 int java_lang_reflect_Field::_annotations_offset;
3650 
3651 #define FIELD_FIELDS_DO(macro) \
3652   macro(_clazz_offset,     k, vmSymbols::clazz_name(),     class_signature,  false); \
3653   macro(_name_offset,      k, vmSymbols::name_name(),      string_signature, false); \
3654   macro(_type_offset,      k, vmSymbols::type_name(),      class_signature,  false); \
3655   macro(_slot_offset,      k, vmSymbols::slot_name(),      int_signature,    false); \
3656   macro(_modifiers_offset, k, vmSymbols::modifiers_name(), int_signature,    false); \
3657   macro(_flags_offset,     k, vmSymbols::flags_name(),     int_signature,    false); \
3658   macro(_signature_offset,        k, vmSymbols::signature_name(),        string_signature,     false); \
3659   macro(_annotations_offset,      k, vmSymbols::annotations_name(),      byte_array_signature, false);
3660 
3661 void java_lang_reflect_Field::compute_offsets() {
3662   InstanceKlass* k = vmClasses::reflect_Field_klass();
3663   FIELD_FIELDS_DO(FIELD_COMPUTE_OFFSET);
3664 }
3665 
3666 #if INCLUDE_CDS
3667 void java_lang_reflect_Field::serialize_offsets(SerializeClosure* f) {
3668   FIELD_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
3669 }
3670 #endif
3671 
3672 Handle java_lang_reflect_Field::create(TRAPS) {
3673   assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
3674   Symbol* name = vmSymbols::java_lang_reflect_Field();
3675   Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH);
3676   InstanceKlass* ik = InstanceKlass::cast(k);
3677   // Ensure it is initialized

3702 void java_lang_reflect_Field::set_type(oop field, oop value) {
3703   field->obj_field_put(_type_offset, value);
3704 }
3705 
3706 int java_lang_reflect_Field::slot(oop reflect) {
3707   return reflect->int_field(_slot_offset);
3708 }
3709 
3710 void java_lang_reflect_Field::set_slot(oop reflect, int value) {
3711   reflect->int_field_put(_slot_offset, value);
3712 }
3713 
3714 int java_lang_reflect_Field::modifiers(oop field) {
3715   return field->int_field(_modifiers_offset);
3716 }
3717 
3718 void java_lang_reflect_Field::set_modifiers(oop field, int value) {
3719   field->int_field_put(_modifiers_offset, value);
3720 }
3721 
3722 void java_lang_reflect_Field::set_flags(oop field, int value) {
3723   field->int_field_put(_flags_offset, value);
3724 }
3725 
3726 void java_lang_reflect_Field::set_signature(oop field, oop value) {
3727   field->obj_field_put(_signature_offset, value);
3728 }
3729 
3730 void java_lang_reflect_Field::set_annotations(oop field, oop value) {
3731   field->obj_field_put(_annotations_offset, value);
3732 }
3733 
3734 oop java_lang_reflect_RecordComponent::create(InstanceKlass* holder, RecordComponent* component, TRAPS) {
3735   // Allocate java.lang.reflect.RecordComponent instance
3736   HandleMark hm(THREAD);
3737   InstanceKlass* ik = vmClasses::RecordComponent_klass();
3738   assert(ik != nullptr, "must be loaded");
3739   ik->initialize(CHECK_NULL);
3740 
3741   Handle element = ik->allocate_instance_handle(CHECK_NULL);
3742 
3743   Handle decl_class(THREAD, holder->java_mirror());

4003 }
4004 #endif
4005 
4006 bool java_lang_ref_Reference::is_referent_field(oop obj, ptrdiff_t offset) {
4007   assert(obj != nullptr, "sanity");
4008   if (offset != _referent_offset) {
4009     return false;
4010   }
4011 
4012   Klass* k = obj->klass();
4013   if (!k->is_instance_klass()) {
4014     return false;
4015   }
4016 
4017   InstanceKlass* ik = InstanceKlass::cast(obj->klass());
4018   bool is_reference = ik->reference_type() != REF_NONE;
4019   assert(!is_reference || ik->is_subclass_of(vmClasses::Reference_klass()), "sanity");
4020   return is_reference;
4021 }
4022 
4023 int* java_lang_boxing_object::_offsets;

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

4541 oop java_lang_invoke_MemberName::type(oop mname) {
4542   assert(is_instance(mname), "wrong type");
4543   return mname->obj_field(_type_offset);
4544 }
4545 
4546 void java_lang_invoke_MemberName::set_type(oop mname, oop type) {
4547   assert(is_instance(mname), "wrong type");
4548   mname->obj_field_put(_type_offset, type);
4549 }
4550 
4551 int java_lang_invoke_MemberName::flags(oop mname) {
4552   assert(is_instance(mname), "wrong type");
4553   return mname->int_field(_flags_offset);
4554 }
4555 
4556 void java_lang_invoke_MemberName::set_flags(oop mname, int flags) {
4557   assert(is_instance(mname), "wrong type");
4558   mname->int_field_put(_flags_offset, flags);
4559 }
4560 

4561 // Return vmtarget from ResolvedMethodName method field through indirection
4562 Method* java_lang_invoke_MemberName::vmtarget(oop mname) {
4563   assert(is_instance(mname), "wrong type");
4564   oop method = mname->obj_field(_method_offset);
4565   return method == nullptr ? nullptr : java_lang_invoke_ResolvedMethodName::vmtarget(method);
4566 }
4567 
4568 bool java_lang_invoke_MemberName::is_method(oop mname) {
4569   assert(is_instance(mname), "must be MemberName");
4570   return (flags(mname) & (MN_IS_METHOD | MN_IS_OBJECT_CONSTRUCTOR)) > 0;
4571 }
4572 
4573 void java_lang_invoke_MemberName::set_method(oop mname, oop resolved_method) {
4574   assert(is_instance(mname), "wrong type");
4575   mname->obj_field_put(_method_offset, resolved_method);
4576 }
4577 
4578 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) {
4579   assert(is_instance(mname), "wrong type");
4580   return (intptr_t) mname->address_field(_vmindex_offset);
4581 }
4582 
4583 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
4584   assert(is_instance(mname), "wrong type");
4585   mname->address_field_put(_vmindex_offset, (address) index);
4586 }
4587 
4588 
4589 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) {
4590   assert(is_instance(resolved_method), "wrong type");

5543   if (!ik->find_local_field(f_name, f_sig, &fd)) {
5544     tty->print_cr("Nonstatic field %s.%s not found", klass_name, field_name);
5545     return false;
5546   }
5547   if (fd.is_static()) {
5548     tty->print_cr("Nonstatic field %s.%s appears to be static", klass_name, field_name);
5549     return false;
5550   }
5551   if (fd.offset() == deserialized_offset ) {
5552     return true;
5553   } else {
5554     tty->print_cr("Offset of nonstatic field %s.%s is deserialized as %d but should really be %d.",
5555                   klass_name, field_name, deserialized_offset, fd.offset());
5556     return false;
5557   }
5558 }
5559 
5560 void JavaClasses::check_offsets() {
5561   bool valid = true;
5562 
5563 #define CHECK_OFFSET(klass_name, type, field_sig) \
5564   valid &= check_offset(klass_name, java_lang_boxing_object::value_offset(type), "value", field_sig)
5565 
5566   CHECK_OFFSET("java/lang/Boolean",   T_BOOLEAN, "Z");
5567   CHECK_OFFSET("java/lang/Character", T_CHAR,    "C");
5568   CHECK_OFFSET("java/lang/Float",     T_FLOAT,   "F");
5569   CHECK_OFFSET("java/lang/Double",    T_DOUBLE,  "D");
5570   CHECK_OFFSET("java/lang/Byte",      T_BYTE,    "B");
5571   CHECK_OFFSET("java/lang/Short",     T_SHORT,   "S");
5572   CHECK_OFFSET("java/lang/Integer",   T_INT,     "I");
5573   CHECK_OFFSET("java/lang/Long",      T_LONG,    "J");





5574 
5575   if (!valid) vm_exit_during_initialization("Field offset verification failed");
5576 }
5577 
5578 #endif // PRODUCT
5579 
5580 int InjectedField::compute_offset() {
5581   InstanceKlass* ik = klass();
5582   for (AllFieldStream fs(ik); !fs.done(); fs.next()) {
5583     if (!may_be_java && !fs.field_flags().is_injected()) {
5584       // Only look at injected fields
5585       continue;
5586     }
5587     if (fs.name() == name() && fs.signature() == signature()) {
5588       return fs.offset();
5589     }
5590   }
5591   ResourceMark rm;
5592   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)" : "");
5593 #ifndef PRODUCT
< prev index next >