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"
1025 new (mtModule) GrowableArray<Klass*>(500, mtModule);
1026 set_fixup_module_field_list(module_list);
1027 }
1028
1029 void java_lang_Class::allocate_mirror(Klass* k, bool is_scratch, Handle protection_domain, Handle classData,
1030 Handle& mirror, Handle& comp_mirror, TRAPS) {
1031 // Allocate mirror (java.lang.Class instance)
1032 oop mirror_oop = InstanceMirrorKlass::cast(vmClasses::Class_klass())->allocate_instance(k, CHECK);
1033 mirror = Handle(THREAD, mirror_oop);
1034
1035 // Setup indirection from mirror->klass
1036 set_klass(mirror(), k);
1037
1038 InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
1039 assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
1040
1041 set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
1042
1043 // It might also have a component mirror. This mirror must already exist.
1044 if (k->is_array_klass()) {
1045 if (k->is_typeArray_klass()) {
1046 BasicType type = TypeArrayKlass::cast(k)->element_type();
1047 if (is_scratch) {
1048 comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(type));
1049 } else {
1050 comp_mirror = Handle(THREAD, Universe::java_mirror(type));
1051 }
1052 } else {
1053 assert(k->is_objArray_klass(), "Must be");
1054 Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
1055 assert(element_klass != nullptr, "Must have an element klass");
1056 if (is_scratch) {
1057 comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(element_klass));
1058 } else {
1059 comp_mirror = Handle(THREAD, element_klass->java_mirror());
1060 }
1061 }
1062 assert(comp_mirror() != nullptr, "must have a mirror");
1063
1064 // Two-way link between the array klass and its component mirror:
1065 // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
1066 set_component_mirror(mirror(), comp_mirror());
1067 // See below for ordering dependencies between field array_klass in component mirror
1068 // and java_mirror in this klass.
1069 } else {
1070 assert(k->is_instance_klass(), "Must be");
1071
1072 initialize_mirror_fields(k, mirror, protection_domain, classData, THREAD);
1073 if (HAS_PENDING_EXCEPTION) {
1074 // If any of the fields throws an exception like OOM remove the klass field
1075 // from the mirror so GC doesn't follow it after the klass has been deallocated.
1076 // This mirror looks like a primitive type, which logically it is because it
1077 // it represents no class.
1078 set_klass(mirror(), nullptr);
1079 return;
1101
1102 allocate_mirror(k, /*is_scratch=*/false, protection_domain, classData, mirror, comp_mirror, CHECK);
1103
1104 // set the classLoader field in the java_lang_Class instance
1105 assert(class_loader() == k->class_loader(), "should be same");
1106 set_class_loader(mirror(), class_loader());
1107
1108 // Setup indirection from klass->mirror
1109 // after any exceptions can happen during allocations.
1110 k->set_java_mirror(mirror);
1111
1112 // Set the module field in the java_lang_Class instance. This must be done
1113 // after the mirror is set.
1114 set_mirror_module_field(THREAD, k, mirror, module);
1115
1116 if (comp_mirror() != nullptr) {
1117 // Set after k->java_mirror() is published, because compiled code running
1118 // concurrently doesn't expect a k to have a null java_mirror.
1119 release_set_array_klass(comp_mirror(), k);
1120 }
1121 if (CDSConfig::is_dumping_heap()) {
1122 create_scratch_mirror(k, CHECK);
1123 }
1124 } else {
1125 assert(fixup_mirror_list() != nullptr, "fixup_mirror_list not initialized");
1126 fixup_mirror_list()->push(k);
1127 }
1128 }
1129
1130 #if INCLUDE_CDS_JAVA_HEAP
1131 // The "scratch mirror" stores the states of the mirror object that can be
1132 // decided at dump time (such as the initial values of the static fields, the
1133 // component mirror, etc). At runtime, more information is added to it by
1134 // java_lang_Class::restore_archived_mirror().
1135 //
1136 // Essentially, /*dumptime*/create_scratch_mirror() + /*runtime*/restore_archived_mirror()
1137 // produces the same result as /*runtime*/create_mirror().
1138 //
1139 // Note: we archive the "scratch mirror" instead of k->java_mirror(), because the
1140 // latter may contain dumptime-specific information that cannot be archived
1141 // (e.g., ClassLoaderData*, or static fields that are modified by Java code execution).
1142 void java_lang_Class::create_scratch_mirror(Klass* k, TRAPS) {
1143 if (k->class_loader() != nullptr &&
1144 k->class_loader() != SystemDictionary::java_platform_loader() &&
1145 k->class_loader() != SystemDictionary::java_system_loader()) {
1146 // We only archive the mirrors of classes loaded by the built-in loaders
1147 return;
1148 }
1149
1150 Handle protection_domain, classData; // set to null. Will be reinitialized at runtime
1151 Handle mirror;
1152 Handle comp_mirror;
1153 allocate_mirror(k, /*is_scratch=*/true, protection_domain, classData, mirror, comp_mirror, CHECK);
1154
1155 if (comp_mirror() != nullptr) {
1156 release_set_array_klass(comp_mirror(), k);
1157 }
1158
1159 HeapShared::set_scratch_java_mirror(k, mirror());
1160 }
1161
1162 // Returns true if the mirror is updated, false if no archived mirror
1163 // data is present. After the archived mirror object is restored, the
1164 // shared klass' _has_raw_archived_mirror flag is cleared.
1165 bool java_lang_Class::restore_archived_mirror(Klass *k,
1338 assert(is_instance(java_class), "must be a Class object");
1339 java_class->metadata_field_put(_klass_offset, klass);
1340 }
1341
1342
1343 void java_lang_Class::print_signature(oop java_class, outputStream* st) {
1344 assert(is_instance(java_class), "must be a Class object");
1345 Symbol* name = nullptr;
1346 bool is_instance = false;
1347 if (is_primitive(java_class)) {
1348 name = vmSymbols::type_signature(primitive_type(java_class));
1349 } else {
1350 Klass* k = as_Klass(java_class);
1351 is_instance = k->is_instance_klass();
1352 name = k->name();
1353 }
1354 if (name == nullptr) {
1355 st->print("<null>");
1356 return;
1357 }
1358 if (is_instance) st->print("L");
1359 st->write((char*) name->base(), (int) name->utf8_length());
1360 if (is_instance) st->print(";");
1361 }
1362
1363 Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found) {
1364 assert(is_instance(java_class), "must be a Class object");
1365 Symbol* name;
1366 if (is_primitive(java_class)) {
1367 name = vmSymbols::type_signature(primitive_type(java_class));
1368 // Because this can create a new symbol, the caller has to decrement
1369 // the refcount, so make adjustment here and below for symbols returned
1370 // that are not created or incremented due to a successful lookup.
1371 name->increment_refcount();
1372 } else {
1373 Klass* k = as_Klass(java_class);
1374 if (!k->is_instance_klass()) {
1375 name = k->name();
1376 name->increment_refcount();
1377 } else {
1378 ResourceMark rm;
1397 if (is_primitive(java_class)) {
1398 name = type2name(primitive_type(java_class));
1399 } else {
1400 name = as_Klass(java_class)->external_name();
1401 }
1402 if (name == nullptr) {
1403 name = "<null>";
1404 }
1405 return name;
1406 }
1407
1408 Klass* java_lang_Class::array_klass_acquire(oop java_class) {
1409 Klass* k = ((Klass*)java_class->metadata_field_acquire(_array_klass_offset));
1410 assert(k == nullptr || (k->is_klass() && k->is_array_klass()), "should be array klass");
1411 return k;
1412 }
1413
1414
1415 void java_lang_Class::release_set_array_klass(oop java_class, Klass* klass) {
1416 assert(klass->is_klass() && klass->is_array_klass(), "should be array klass");
1417 java_class->release_metadata_field_put(_array_klass_offset, klass);
1418 }
1419
1420
1421 BasicType java_lang_Class::primitive_type(oop java_class) {
1422 assert(is_primitive(java_class), "just checking");
1423 Klass* ak = ((Klass*)java_class->metadata_field(_array_klass_offset));
1424 BasicType type = T_VOID;
1425 if (ak != nullptr) {
1426 // Note: create_basic_type_mirror above initializes ak to a non-null value.
1427 type = ArrayKlass::cast(ak)->element_type();
1428 } else {
1429 assert(java_class == Universe::void_mirror(), "only valid non-array primitive");
1430 }
1431 #ifdef ASSERT
1432 if (CDSConfig::is_dumping_heap()) {
1433 oop mirror = Universe::java_mirror(type);
1434 oop scratch_mirror = HeapShared::scratch_java_mirror(type);
1435 assert(java_class == mirror || java_class == scratch_mirror, "must be consistent");
1436 } else {
2676
2677 // the format of the stacktrace will be:
2678 // - 1 or more fillInStackTrace frames for the exception class (skipped)
2679 // - 0 or more <init> methods for the exception class (skipped)
2680 // - rest of the stack
2681
2682 if (!skip_fillInStackTrace_check) {
2683 if (method->name() == vmSymbols::fillInStackTrace_name() &&
2684 throwable->is_a(method->method_holder())) {
2685 continue;
2686 }
2687 else {
2688 skip_fillInStackTrace_check = true; // gone past them all
2689 }
2690 }
2691 if (!skip_throwableInit_check) {
2692 assert(skip_fillInStackTrace_check, "logic error in backtrace filtering");
2693
2694 // skip <init> methods of the exception class and superclasses
2695 // This is similar to classic VM.
2696 if (method->name() == vmSymbols::object_initializer_name() &&
2697 throwable->is_a(method->method_holder())) {
2698 continue;
2699 } else {
2700 // there are none or we've seen them all - either way stop checking
2701 skip_throwableInit_check = true;
2702 }
2703 }
2704 if (method->is_hidden() || method->is_continuation_enter_intrinsic()) {
2705 if (skip_hidden) {
2706 if (total_count == 0) {
2707 // The top frame will be hidden from the stack trace.
2708 bt.set_has_hidden_top_frame();
2709 }
2710 continue;
2711 }
2712 }
2713
2714 bt.push(method, bci, CHECK);
2715 total_count++;
2716 }
3035 int java_lang_ClassFrameInfo::_classOrMemberName_offset;
3036 int java_lang_ClassFrameInfo::_flags_offset;
3037
3038 #define CLASSFRAMEINFO_FIELDS_DO(macro) \
3039 macro(_classOrMemberName_offset, k, "classOrMemberName", object_signature, false); \
3040 macro(_flags_offset, k, vmSymbols::flags_name(), int_signature, false)
3041
3042 void java_lang_ClassFrameInfo::compute_offsets() {
3043 InstanceKlass* k = vmClasses::ClassFrameInfo_klass();
3044 CLASSFRAMEINFO_FIELDS_DO(FIELD_COMPUTE_OFFSET);
3045 }
3046
3047 #if INCLUDE_CDS
3048 void java_lang_ClassFrameInfo::serialize_offsets(SerializeClosure* f) {
3049 CLASSFRAMEINFO_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
3050 }
3051 #endif
3052
3053 static int get_flags(const methodHandle& m) {
3054 int flags = (jushort)( m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS );
3055 if (m->is_object_initializer()) {
3056 flags |= java_lang_invoke_MemberName::MN_IS_CONSTRUCTOR;
3057 } else {
3058 // Note: Static initializers can be here. Record them as plain methods.
3059 flags |= java_lang_invoke_MemberName::MN_IS_METHOD;
3060 }
3061 if (m->caller_sensitive()) {
3062 flags |= java_lang_invoke_MemberName::MN_CALLER_SENSITIVE;
3063 }
3064 if (m->is_hidden()) {
3065 flags |= java_lang_invoke_MemberName::MN_HIDDEN_MEMBER;
3066 }
3067 assert((flags & 0xFF000000) == 0, "unexpected flags");
3068 return flags;
3069 }
3070
3071 oop java_lang_ClassFrameInfo::classOrMemberName(oop obj) {
3072 return obj->obj_field(_classOrMemberName_offset);
3073 }
3074
3075 int java_lang_ClassFrameInfo::flags(oop obj) {
3076 return obj->int_field(_flags_offset);
3427 constructor->int_field_put(_modifiers_offset, value);
3428 }
3429
3430 void java_lang_reflect_Constructor::set_signature(oop constructor, oop value) {
3431 constructor->obj_field_put(_signature_offset, value);
3432 }
3433
3434 void java_lang_reflect_Constructor::set_annotations(oop constructor, oop value) {
3435 constructor->obj_field_put(_annotations_offset, value);
3436 }
3437
3438 void java_lang_reflect_Constructor::set_parameter_annotations(oop method, oop value) {
3439 method->obj_field_put(_parameter_annotations_offset, value);
3440 }
3441
3442 int java_lang_reflect_Field::_clazz_offset;
3443 int java_lang_reflect_Field::_name_offset;
3444 int java_lang_reflect_Field::_type_offset;
3445 int java_lang_reflect_Field::_slot_offset;
3446 int java_lang_reflect_Field::_modifiers_offset;
3447 int java_lang_reflect_Field::_trusted_final_offset;
3448 int java_lang_reflect_Field::_signature_offset;
3449 int java_lang_reflect_Field::_annotations_offset;
3450
3451 #define FIELD_FIELDS_DO(macro) \
3452 macro(_clazz_offset, k, vmSymbols::clazz_name(), class_signature, false); \
3453 macro(_name_offset, k, vmSymbols::name_name(), string_signature, false); \
3454 macro(_type_offset, k, vmSymbols::type_name(), class_signature, false); \
3455 macro(_slot_offset, k, vmSymbols::slot_name(), int_signature, false); \
3456 macro(_modifiers_offset, k, vmSymbols::modifiers_name(), int_signature, false); \
3457 macro(_trusted_final_offset, k, vmSymbols::trusted_final_name(), bool_signature, false); \
3458 macro(_signature_offset, k, vmSymbols::signature_name(), string_signature, false); \
3459 macro(_annotations_offset, k, vmSymbols::annotations_name(), byte_array_signature, false);
3460
3461 void java_lang_reflect_Field::compute_offsets() {
3462 InstanceKlass* k = vmClasses::reflect_Field_klass();
3463 FIELD_FIELDS_DO(FIELD_COMPUTE_OFFSET);
3464 }
3465
3466 #if INCLUDE_CDS
3467 void java_lang_reflect_Field::serialize_offsets(SerializeClosure* f) {
3468 FIELD_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
3469 }
3470 #endif
3471
3472 Handle java_lang_reflect_Field::create(TRAPS) {
3473 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
3474 Symbol* name = vmSymbols::java_lang_reflect_Field();
3475 Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH);
3476 InstanceKlass* ik = InstanceKlass::cast(k);
3477 // Ensure it is initialized
3502 void java_lang_reflect_Field::set_type(oop field, oop value) {
3503 field->obj_field_put(_type_offset, value);
3504 }
3505
3506 int java_lang_reflect_Field::slot(oop reflect) {
3507 return reflect->int_field(_slot_offset);
3508 }
3509
3510 void java_lang_reflect_Field::set_slot(oop reflect, int value) {
3511 reflect->int_field_put(_slot_offset, value);
3512 }
3513
3514 int java_lang_reflect_Field::modifiers(oop field) {
3515 return field->int_field(_modifiers_offset);
3516 }
3517
3518 void java_lang_reflect_Field::set_modifiers(oop field, int value) {
3519 field->int_field_put(_modifiers_offset, value);
3520 }
3521
3522 void java_lang_reflect_Field::set_trusted_final(oop field) {
3523 field->bool_field_put(_trusted_final_offset, true);
3524 }
3525
3526 void java_lang_reflect_Field::set_signature(oop field, oop value) {
3527 field->obj_field_put(_signature_offset, value);
3528 }
3529
3530 void java_lang_reflect_Field::set_annotations(oop field, oop value) {
3531 field->obj_field_put(_annotations_offset, value);
3532 }
3533
3534 oop java_lang_reflect_RecordComponent::create(InstanceKlass* holder, RecordComponent* component, TRAPS) {
3535 // Allocate java.lang.reflect.RecordComponent instance
3536 HandleMark hm(THREAD);
3537 InstanceKlass* ik = vmClasses::RecordComponent_klass();
3538 assert(ik != nullptr, "must be loaded");
3539 ik->initialize(CHECK_NULL);
3540
3541 Handle element = ik->allocate_instance_handle(CHECK_NULL);
3542
3543 Handle decl_class(THREAD, holder->java_mirror());
3810 assert(obj != nullptr, "sanity");
3811 if (offset != _referent_offset) {
3812 return false;
3813 }
3814
3815 Klass* k = obj->klass();
3816 if (!k->is_instance_klass()) {
3817 return false;
3818 }
3819
3820 InstanceKlass* ik = InstanceKlass::cast(obj->klass());
3821 bool is_reference = ik->reference_type() != REF_NONE;
3822 assert(!is_reference || ik->is_subclass_of(vmClasses::Reference_klass()), "sanity");
3823 return is_reference;
3824 }
3825
3826 int java_lang_boxing_object::_value_offset;
3827 int java_lang_boxing_object::_long_value_offset;
3828
3829 #define BOXING_FIELDS_DO(macro) \
3830 macro(_value_offset, integerKlass, "value", int_signature, false); \
3831 macro(_long_value_offset, longKlass, "value", long_signature, false);
3832
3833 void java_lang_boxing_object::compute_offsets() {
3834 InstanceKlass* integerKlass = vmClasses::Integer_klass();
3835 InstanceKlass* longKlass = vmClasses::Long_klass();
3836 BOXING_FIELDS_DO(FIELD_COMPUTE_OFFSET);
3837 }
3838
3839 #if INCLUDE_CDS
3840 void java_lang_boxing_object::serialize_offsets(SerializeClosure* f) {
3841 BOXING_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
3842 }
3843 #endif
3844
3845 oop java_lang_boxing_object::initialize_and_allocate(BasicType type, TRAPS) {
3846 Klass* k = vmClasses::box_klass(type);
3847 if (k == nullptr) return nullptr;
3848 InstanceKlass* ik = InstanceKlass::cast(k);
3849 if (!ik->is_initialized()) {
3850 ik->initialize(CHECK_NULL);
3851 }
3852 return ik->allocate_instance(THREAD);
3853 }
3854
4345 int java_lang_invoke_MemberName::flags(oop mname) {
4346 assert(is_instance(mname), "wrong type");
4347 return mname->int_field(_flags_offset);
4348 }
4349
4350 void java_lang_invoke_MemberName::set_flags(oop mname, int flags) {
4351 assert(is_instance(mname), "wrong type");
4352 mname->int_field_put(_flags_offset, flags);
4353 }
4354
4355
4356 // Return vmtarget from ResolvedMethodName method field through indirection
4357 Method* java_lang_invoke_MemberName::vmtarget(oop mname) {
4358 assert(is_instance(mname), "wrong type");
4359 oop method = mname->obj_field(_method_offset);
4360 return method == nullptr ? nullptr : java_lang_invoke_ResolvedMethodName::vmtarget(method);
4361 }
4362
4363 bool java_lang_invoke_MemberName::is_method(oop mname) {
4364 assert(is_instance(mname), "must be MemberName");
4365 return (flags(mname) & (MN_IS_METHOD | MN_IS_CONSTRUCTOR)) > 0;
4366 }
4367
4368 void java_lang_invoke_MemberName::set_method(oop mname, oop resolved_method) {
4369 assert(is_instance(mname), "wrong type");
4370 mname->obj_field_put(_method_offset, resolved_method);
4371 }
4372
4373 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) {
4374 assert(is_instance(mname), "wrong type");
4375 return (intptr_t) mname->address_field(_vmindex_offset);
4376 }
4377
4378 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
4379 assert(is_instance(mname), "wrong type");
4380 mname->address_field_put(_vmindex_offset, (address) index);
4381 }
4382
4383
4384 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) {
4385 assert(is_instance(resolved_method), "wrong type");
5443 } else {
5444 tty->print_cr("Offset of nonstatic field %s.%s is deserialized as %d but should really be %d.",
5445 klass_name, field_name, deserialized_offset, fd.offset());
5446 return false;
5447 }
5448 }
5449
5450 void JavaClasses::check_offsets() {
5451 bool valid = true;
5452
5453 #define CHECK_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \
5454 valid &= check_offset(klass_name, cpp_klass_name :: _##field_name ## _offset, #field_name, field_sig)
5455
5456 #define CHECK_LONG_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \
5457 valid &= check_offset(klass_name, cpp_klass_name :: _##long_ ## field_name ## _offset, #field_name, field_sig)
5458
5459 // Boxed primitive objects (java_lang_boxing_object)
5460
5461 CHECK_OFFSET("java/lang/Boolean", java_lang_boxing_object, value, "Z");
5462 CHECK_OFFSET("java/lang/Character", java_lang_boxing_object, value, "C");
5463 CHECK_OFFSET("java/lang/Float", java_lang_boxing_object, value, "F");
5464 CHECK_LONG_OFFSET("java/lang/Double", java_lang_boxing_object, value, "D");
5465 CHECK_OFFSET("java/lang/Byte", java_lang_boxing_object, value, "B");
5466 CHECK_OFFSET("java/lang/Short", java_lang_boxing_object, value, "S");
5467 CHECK_OFFSET("java/lang/Integer", java_lang_boxing_object, value, "I");
5468 CHECK_LONG_OFFSET("java/lang/Long", java_lang_boxing_object, value, "J");
5469
5470 if (!valid) vm_exit_during_initialization("Field offset verification failed");
5471 }
5472
5473 #endif // PRODUCT
5474
5475 int InjectedField::compute_offset() {
5476 InstanceKlass* ik = InstanceKlass::cast(klass());
5477 for (AllFieldStream fs(ik); !fs.done(); fs.next()) {
5478 if (!may_be_java && !fs.field_flags().is_injected()) {
5479 // Only look at injected fields
5480 continue;
5481 }
5482 if (fs.name() == name() && fs.signature() == signature()) {
5483 return fs.offset();
5484 }
5485 }
5486 ResourceMark rm;
5487 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)" : "");
|
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"
1027 new (mtModule) GrowableArray<Klass*>(500, mtModule);
1028 set_fixup_module_field_list(module_list);
1029 }
1030
1031 void java_lang_Class::allocate_mirror(Klass* k, bool is_scratch, Handle protection_domain, Handle classData,
1032 Handle& mirror, Handle& comp_mirror, TRAPS) {
1033 // Allocate mirror (java.lang.Class instance)
1034 oop mirror_oop = InstanceMirrorKlass::cast(vmClasses::Class_klass())->allocate_instance(k, CHECK);
1035 mirror = Handle(THREAD, mirror_oop);
1036
1037 // Setup indirection from mirror->klass
1038 set_klass(mirror(), k);
1039
1040 InstanceMirrorKlass* mk = InstanceMirrorKlass::cast(mirror->klass());
1041 assert(oop_size(mirror()) == mk->instance_size(k), "should have been set");
1042
1043 set_static_oop_field_count(mirror(), mk->compute_static_oop_field_count(mirror()));
1044
1045 // It might also have a component mirror. This mirror must already exist.
1046 if (k->is_array_klass()) {
1047 if (k->is_flatArray_klass()) {
1048 Klass* element_klass = (Klass*) FlatArrayKlass::cast(k)->element_klass();
1049 assert(element_klass->is_inline_klass(), "Must be inline type component");
1050 if (is_scratch) {
1051 comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(element_klass));
1052 } else {
1053 comp_mirror = Handle(THREAD, element_klass->java_mirror());
1054 }
1055 } else if (k->is_typeArray_klass()) {
1056 BasicType type = TypeArrayKlass::cast(k)->element_type();
1057 if (is_scratch) {
1058 comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(type));
1059 } else {
1060 comp_mirror = Handle(THREAD, Universe::java_mirror(type));
1061 }
1062 } else {
1063 assert(k->is_objArray_klass(), "Must be");
1064 Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
1065 assert(element_klass != nullptr, "Must have an element klass");
1066 oop comp_oop = element_klass->java_mirror();
1067 if (is_scratch) {
1068 comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(element_klass));
1069 } else {
1070 comp_mirror = Handle(THREAD, comp_oop);
1071 }
1072 }
1073 assert(comp_mirror() != nullptr, "must have a mirror");
1074
1075 // Two-way link between the array klass and its component mirror:
1076 // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
1077 set_component_mirror(mirror(), comp_mirror());
1078 // See below for ordering dependencies between field array_klass in component mirror
1079 // and java_mirror in this klass.
1080 } else {
1081 assert(k->is_instance_klass(), "Must be");
1082
1083 initialize_mirror_fields(k, mirror, protection_domain, classData, THREAD);
1084 if (HAS_PENDING_EXCEPTION) {
1085 // If any of the fields throws an exception like OOM remove the klass field
1086 // from the mirror so GC doesn't follow it after the klass has been deallocated.
1087 // This mirror looks like a primitive type, which logically it is because it
1088 // it represents no class.
1089 set_klass(mirror(), nullptr);
1090 return;
1112
1113 allocate_mirror(k, /*is_scratch=*/false, protection_domain, classData, mirror, comp_mirror, CHECK);
1114
1115 // set the classLoader field in the java_lang_Class instance
1116 assert(class_loader() == k->class_loader(), "should be same");
1117 set_class_loader(mirror(), class_loader());
1118
1119 // Setup indirection from klass->mirror
1120 // after any exceptions can happen during allocations.
1121 k->set_java_mirror(mirror);
1122
1123 // Set the module field in the java_lang_Class instance. This must be done
1124 // after the mirror is set.
1125 set_mirror_module_field(THREAD, k, mirror, module);
1126
1127 if (comp_mirror() != nullptr) {
1128 // Set after k->java_mirror() is published, because compiled code running
1129 // concurrently doesn't expect a k to have a null java_mirror.
1130 release_set_array_klass(comp_mirror(), k);
1131 }
1132
1133 if (CDSConfig::is_dumping_heap()) {
1134 create_scratch_mirror(k, CHECK);
1135 }
1136 } else {
1137 assert(fixup_mirror_list() != nullptr, "fixup_mirror_list not initialized");
1138 fixup_mirror_list()->push(k);
1139 }
1140 }
1141
1142 #if INCLUDE_CDS_JAVA_HEAP
1143 // The "scratch mirror" stores the states of the mirror object that can be
1144 // decided at dump time (such as the initial values of the static fields, the
1145 // component mirror, etc). At runtime, more information is added to it by
1146 // java_lang_Class::restore_archived_mirror().
1147 //
1148 // Essentially, /*dumptime*/create_scratch_mirror() + /*runtime*/restore_archived_mirror()
1149 // produces the same result as /*runtime*/create_mirror().
1150 //
1151 // Note: we archive the "scratch mirror" instead of k->java_mirror(), because the
1152 // latter may contain dumptime-specific information that cannot be archived
1153 // (e.g., ClassLoaderData*, or static fields that are modified by Java code execution).
1154 void java_lang_Class::create_scratch_mirror(Klass* k, TRAPS) {
1155 if ((k->class_loader() != nullptr &&
1156 k->class_loader() != SystemDictionary::java_platform_loader() &&
1157 k->class_loader() != SystemDictionary::java_system_loader())) {
1158 // We only archive the mirrors of classes loaded by the built-in loaders
1159 return;
1160 }
1161
1162 Handle protection_domain, classData; // set to null. Will be reinitialized at runtime
1163 Handle mirror;
1164 Handle comp_mirror;
1165 allocate_mirror(k, /*is_scratch=*/true, protection_domain, classData, mirror, comp_mirror, CHECK);
1166
1167 if (comp_mirror() != nullptr) {
1168 release_set_array_klass(comp_mirror(), k);
1169 }
1170
1171 HeapShared::set_scratch_java_mirror(k, mirror());
1172 }
1173
1174 // Returns true if the mirror is updated, false if no archived mirror
1175 // data is present. After the archived mirror object is restored, the
1176 // shared klass' _has_raw_archived_mirror flag is cleared.
1177 bool java_lang_Class::restore_archived_mirror(Klass *k,
1350 assert(is_instance(java_class), "must be a Class object");
1351 java_class->metadata_field_put(_klass_offset, klass);
1352 }
1353
1354
1355 void java_lang_Class::print_signature(oop java_class, outputStream* st) {
1356 assert(is_instance(java_class), "must be a Class object");
1357 Symbol* name = nullptr;
1358 bool is_instance = false;
1359 if (is_primitive(java_class)) {
1360 name = vmSymbols::type_signature(primitive_type(java_class));
1361 } else {
1362 Klass* k = as_Klass(java_class);
1363 is_instance = k->is_instance_klass();
1364 name = k->name();
1365 }
1366 if (name == nullptr) {
1367 st->print("<null>");
1368 return;
1369 }
1370 if (is_instance) {
1371 st->print("L");
1372 }
1373 st->write((char*) name->base(), (int) name->utf8_length());
1374 if (is_instance) st->print(";");
1375 }
1376
1377 Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found) {
1378 assert(is_instance(java_class), "must be a Class object");
1379 Symbol* name;
1380 if (is_primitive(java_class)) {
1381 name = vmSymbols::type_signature(primitive_type(java_class));
1382 // Because this can create a new symbol, the caller has to decrement
1383 // the refcount, so make adjustment here and below for symbols returned
1384 // that are not created or incremented due to a successful lookup.
1385 name->increment_refcount();
1386 } else {
1387 Klass* k = as_Klass(java_class);
1388 if (!k->is_instance_klass()) {
1389 name = k->name();
1390 name->increment_refcount();
1391 } else {
1392 ResourceMark rm;
1411 if (is_primitive(java_class)) {
1412 name = type2name(primitive_type(java_class));
1413 } else {
1414 name = as_Klass(java_class)->external_name();
1415 }
1416 if (name == nullptr) {
1417 name = "<null>";
1418 }
1419 return name;
1420 }
1421
1422 Klass* java_lang_Class::array_klass_acquire(oop java_class) {
1423 Klass* k = ((Klass*)java_class->metadata_field_acquire(_array_klass_offset));
1424 assert(k == nullptr || (k->is_klass() && k->is_array_klass()), "should be array klass");
1425 return k;
1426 }
1427
1428
1429 void java_lang_Class::release_set_array_klass(oop java_class, Klass* klass) {
1430 assert(klass->is_klass() && klass->is_array_klass(), "should be array klass");
1431 if (klass->is_flatArray_klass() || (klass->is_objArray_klass() && ObjArrayKlass::cast(klass)->is_null_free_array_klass())) {
1432 // TODO 8336006 Ignore flat / null-free arrays
1433 return;
1434 }
1435 java_class->release_metadata_field_put(_array_klass_offset, klass);
1436 }
1437
1438
1439 BasicType java_lang_Class::primitive_type(oop java_class) {
1440 assert(is_primitive(java_class), "just checking");
1441 Klass* ak = ((Klass*)java_class->metadata_field(_array_klass_offset));
1442 BasicType type = T_VOID;
1443 if (ak != nullptr) {
1444 // Note: create_basic_type_mirror above initializes ak to a non-null value.
1445 type = ArrayKlass::cast(ak)->element_type();
1446 } else {
1447 assert(java_class == Universe::void_mirror(), "only valid non-array primitive");
1448 }
1449 #ifdef ASSERT
1450 if (CDSConfig::is_dumping_heap()) {
1451 oop mirror = Universe::java_mirror(type);
1452 oop scratch_mirror = HeapShared::scratch_java_mirror(type);
1453 assert(java_class == mirror || java_class == scratch_mirror, "must be consistent");
1454 } else {
2694
2695 // the format of the stacktrace will be:
2696 // - 1 or more fillInStackTrace frames for the exception class (skipped)
2697 // - 0 or more <init> methods for the exception class (skipped)
2698 // - rest of the stack
2699
2700 if (!skip_fillInStackTrace_check) {
2701 if (method->name() == vmSymbols::fillInStackTrace_name() &&
2702 throwable->is_a(method->method_holder())) {
2703 continue;
2704 }
2705 else {
2706 skip_fillInStackTrace_check = true; // gone past them all
2707 }
2708 }
2709 if (!skip_throwableInit_check) {
2710 assert(skip_fillInStackTrace_check, "logic error in backtrace filtering");
2711
2712 // skip <init> methods of the exception class and superclasses
2713 // This is similar to classic VM.
2714 if (method->is_object_constructor() &&
2715 throwable->is_a(method->method_holder())) {
2716 continue;
2717 } else {
2718 // there are none or we've seen them all - either way stop checking
2719 skip_throwableInit_check = true;
2720 }
2721 }
2722 if (method->is_hidden() || method->is_continuation_enter_intrinsic()) {
2723 if (skip_hidden) {
2724 if (total_count == 0) {
2725 // The top frame will be hidden from the stack trace.
2726 bt.set_has_hidden_top_frame();
2727 }
2728 continue;
2729 }
2730 }
2731
2732 bt.push(method, bci, CHECK);
2733 total_count++;
2734 }
3053 int java_lang_ClassFrameInfo::_classOrMemberName_offset;
3054 int java_lang_ClassFrameInfo::_flags_offset;
3055
3056 #define CLASSFRAMEINFO_FIELDS_DO(macro) \
3057 macro(_classOrMemberName_offset, k, "classOrMemberName", object_signature, false); \
3058 macro(_flags_offset, k, vmSymbols::flags_name(), int_signature, false)
3059
3060 void java_lang_ClassFrameInfo::compute_offsets() {
3061 InstanceKlass* k = vmClasses::ClassFrameInfo_klass();
3062 CLASSFRAMEINFO_FIELDS_DO(FIELD_COMPUTE_OFFSET);
3063 }
3064
3065 #if INCLUDE_CDS
3066 void java_lang_ClassFrameInfo::serialize_offsets(SerializeClosure* f) {
3067 CLASSFRAMEINFO_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
3068 }
3069 #endif
3070
3071 static int get_flags(const methodHandle& m) {
3072 int flags = (jushort)( m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS );
3073 if (m->is_object_constructor()) {
3074 flags |= java_lang_invoke_MemberName::MN_IS_OBJECT_CONSTRUCTOR;
3075 } else {
3076 // Note: Static initializers can be here. Record them as plain methods.
3077 flags |= java_lang_invoke_MemberName::MN_IS_METHOD;
3078 }
3079 if (m->caller_sensitive()) {
3080 flags |= java_lang_invoke_MemberName::MN_CALLER_SENSITIVE;
3081 }
3082 if (m->is_hidden()) {
3083 flags |= java_lang_invoke_MemberName::MN_HIDDEN_MEMBER;
3084 }
3085 assert((flags & 0xFF000000) == 0, "unexpected flags");
3086 return flags;
3087 }
3088
3089 oop java_lang_ClassFrameInfo::classOrMemberName(oop obj) {
3090 return obj->obj_field(_classOrMemberName_offset);
3091 }
3092
3093 int java_lang_ClassFrameInfo::flags(oop obj) {
3094 return obj->int_field(_flags_offset);
3445 constructor->int_field_put(_modifiers_offset, value);
3446 }
3447
3448 void java_lang_reflect_Constructor::set_signature(oop constructor, oop value) {
3449 constructor->obj_field_put(_signature_offset, value);
3450 }
3451
3452 void java_lang_reflect_Constructor::set_annotations(oop constructor, oop value) {
3453 constructor->obj_field_put(_annotations_offset, value);
3454 }
3455
3456 void java_lang_reflect_Constructor::set_parameter_annotations(oop method, oop value) {
3457 method->obj_field_put(_parameter_annotations_offset, value);
3458 }
3459
3460 int java_lang_reflect_Field::_clazz_offset;
3461 int java_lang_reflect_Field::_name_offset;
3462 int java_lang_reflect_Field::_type_offset;
3463 int java_lang_reflect_Field::_slot_offset;
3464 int java_lang_reflect_Field::_modifiers_offset;
3465 int java_lang_reflect_Field::_flags_offset;
3466 int java_lang_reflect_Field::_signature_offset;
3467 int java_lang_reflect_Field::_annotations_offset;
3468
3469 #define FIELD_FIELDS_DO(macro) \
3470 macro(_clazz_offset, k, vmSymbols::clazz_name(), class_signature, false); \
3471 macro(_name_offset, k, vmSymbols::name_name(), string_signature, false); \
3472 macro(_type_offset, k, vmSymbols::type_name(), class_signature, false); \
3473 macro(_slot_offset, k, vmSymbols::slot_name(), int_signature, false); \
3474 macro(_modifiers_offset, k, vmSymbols::modifiers_name(), int_signature, false); \
3475 macro(_flags_offset, k, vmSymbols::flags_name(), int_signature, false); \
3476 macro(_signature_offset, k, vmSymbols::signature_name(), string_signature, false); \
3477 macro(_annotations_offset, k, vmSymbols::annotations_name(), byte_array_signature, false);
3478
3479 void java_lang_reflect_Field::compute_offsets() {
3480 InstanceKlass* k = vmClasses::reflect_Field_klass();
3481 FIELD_FIELDS_DO(FIELD_COMPUTE_OFFSET);
3482 }
3483
3484 #if INCLUDE_CDS
3485 void java_lang_reflect_Field::serialize_offsets(SerializeClosure* f) {
3486 FIELD_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
3487 }
3488 #endif
3489
3490 Handle java_lang_reflect_Field::create(TRAPS) {
3491 assert(Universe::is_fully_initialized(), "Need to find another solution to the reflection problem");
3492 Symbol* name = vmSymbols::java_lang_reflect_Field();
3493 Klass* k = SystemDictionary::resolve_or_fail(name, true, CHECK_NH);
3494 InstanceKlass* ik = InstanceKlass::cast(k);
3495 // Ensure it is initialized
3520 void java_lang_reflect_Field::set_type(oop field, oop value) {
3521 field->obj_field_put(_type_offset, value);
3522 }
3523
3524 int java_lang_reflect_Field::slot(oop reflect) {
3525 return reflect->int_field(_slot_offset);
3526 }
3527
3528 void java_lang_reflect_Field::set_slot(oop reflect, int value) {
3529 reflect->int_field_put(_slot_offset, value);
3530 }
3531
3532 int java_lang_reflect_Field::modifiers(oop field) {
3533 return field->int_field(_modifiers_offset);
3534 }
3535
3536 void java_lang_reflect_Field::set_modifiers(oop field, int value) {
3537 field->int_field_put(_modifiers_offset, value);
3538 }
3539
3540 void java_lang_reflect_Field::set_flags(oop field, int value) {
3541 field->int_field_put(_flags_offset, value);
3542 }
3543
3544 void java_lang_reflect_Field::set_signature(oop field, oop value) {
3545 field->obj_field_put(_signature_offset, value);
3546 }
3547
3548 void java_lang_reflect_Field::set_annotations(oop field, oop value) {
3549 field->obj_field_put(_annotations_offset, value);
3550 }
3551
3552 oop java_lang_reflect_RecordComponent::create(InstanceKlass* holder, RecordComponent* component, TRAPS) {
3553 // Allocate java.lang.reflect.RecordComponent instance
3554 HandleMark hm(THREAD);
3555 InstanceKlass* ik = vmClasses::RecordComponent_klass();
3556 assert(ik != nullptr, "must be loaded");
3557 ik->initialize(CHECK_NULL);
3558
3559 Handle element = ik->allocate_instance_handle(CHECK_NULL);
3560
3561 Handle decl_class(THREAD, holder->java_mirror());
3828 assert(obj != nullptr, "sanity");
3829 if (offset != _referent_offset) {
3830 return false;
3831 }
3832
3833 Klass* k = obj->klass();
3834 if (!k->is_instance_klass()) {
3835 return false;
3836 }
3837
3838 InstanceKlass* ik = InstanceKlass::cast(obj->klass());
3839 bool is_reference = ik->reference_type() != REF_NONE;
3840 assert(!is_reference || ik->is_subclass_of(vmClasses::Reference_klass()), "sanity");
3841 return is_reference;
3842 }
3843
3844 int java_lang_boxing_object::_value_offset;
3845 int java_lang_boxing_object::_long_value_offset;
3846
3847 #define BOXING_FIELDS_DO(macro) \
3848 macro(_value_offset, byteKlass, "value", byte_signature, false); \
3849 macro(_long_value_offset, longKlass, "value", long_signature, false);
3850
3851 void java_lang_boxing_object::compute_offsets() {
3852 InstanceKlass* byteKlass = vmClasses::Byte_klass();
3853 InstanceKlass* longKlass = vmClasses::Long_klass();
3854 BOXING_FIELDS_DO(FIELD_COMPUTE_OFFSET);
3855 }
3856
3857 #if INCLUDE_CDS
3858 void java_lang_boxing_object::serialize_offsets(SerializeClosure* f) {
3859 BOXING_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
3860 }
3861 #endif
3862
3863 oop java_lang_boxing_object::initialize_and_allocate(BasicType type, TRAPS) {
3864 Klass* k = vmClasses::box_klass(type);
3865 if (k == nullptr) return nullptr;
3866 InstanceKlass* ik = InstanceKlass::cast(k);
3867 if (!ik->is_initialized()) {
3868 ik->initialize(CHECK_NULL);
3869 }
3870 return ik->allocate_instance(THREAD);
3871 }
3872
4363 int java_lang_invoke_MemberName::flags(oop mname) {
4364 assert(is_instance(mname), "wrong type");
4365 return mname->int_field(_flags_offset);
4366 }
4367
4368 void java_lang_invoke_MemberName::set_flags(oop mname, int flags) {
4369 assert(is_instance(mname), "wrong type");
4370 mname->int_field_put(_flags_offset, flags);
4371 }
4372
4373
4374 // Return vmtarget from ResolvedMethodName method field through indirection
4375 Method* java_lang_invoke_MemberName::vmtarget(oop mname) {
4376 assert(is_instance(mname), "wrong type");
4377 oop method = mname->obj_field(_method_offset);
4378 return method == nullptr ? nullptr : java_lang_invoke_ResolvedMethodName::vmtarget(method);
4379 }
4380
4381 bool java_lang_invoke_MemberName::is_method(oop mname) {
4382 assert(is_instance(mname), "must be MemberName");
4383 return (flags(mname) & (MN_IS_METHOD | MN_IS_OBJECT_CONSTRUCTOR)) > 0;
4384 }
4385
4386 void java_lang_invoke_MemberName::set_method(oop mname, oop resolved_method) {
4387 assert(is_instance(mname), "wrong type");
4388 mname->obj_field_put(_method_offset, resolved_method);
4389 }
4390
4391 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) {
4392 assert(is_instance(mname), "wrong type");
4393 return (intptr_t) mname->address_field(_vmindex_offset);
4394 }
4395
4396 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
4397 assert(is_instance(mname), "wrong type");
4398 mname->address_field_put(_vmindex_offset, (address) index);
4399 }
4400
4401
4402 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) {
4403 assert(is_instance(resolved_method), "wrong type");
5461 } else {
5462 tty->print_cr("Offset of nonstatic field %s.%s is deserialized as %d but should really be %d.",
5463 klass_name, field_name, deserialized_offset, fd.offset());
5464 return false;
5465 }
5466 }
5467
5468 void JavaClasses::check_offsets() {
5469 bool valid = true;
5470
5471 #define CHECK_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \
5472 valid &= check_offset(klass_name, cpp_klass_name :: _##field_name ## _offset, #field_name, field_sig)
5473
5474 #define CHECK_LONG_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \
5475 valid &= check_offset(klass_name, cpp_klass_name :: _##long_ ## field_name ## _offset, #field_name, field_sig)
5476
5477 // Boxed primitive objects (java_lang_boxing_object)
5478
5479 CHECK_OFFSET("java/lang/Boolean", java_lang_boxing_object, value, "Z");
5480 CHECK_OFFSET("java/lang/Character", java_lang_boxing_object, value, "C");
5481 if (Arguments::enable_preview() && NullableFieldFlattening && (InlineFieldMaxFlatSize >= 64 || InlineFieldMaxFlatSize < 0)) {
5482 CHECK_LONG_OFFSET("java/lang/Float", java_lang_boxing_object, value, "F");
5483 } else {
5484 CHECK_OFFSET("java/lang/Float", java_lang_boxing_object, value, "F");
5485 }
5486 CHECK_LONG_OFFSET("java/lang/Double", java_lang_boxing_object, value, "D");
5487 CHECK_OFFSET("java/lang/Byte", java_lang_boxing_object, value, "B");
5488 CHECK_OFFSET("java/lang/Short", java_lang_boxing_object, value, "S");
5489 if (Arguments::enable_preview() && NullableFieldFlattening && (InlineFieldMaxFlatSize >= 64 || InlineFieldMaxFlatSize < 0)) {
5490 CHECK_LONG_OFFSET("java/lang/Integer", java_lang_boxing_object, value, "I");
5491 } else {
5492 CHECK_OFFSET("java/lang/Integer", java_lang_boxing_object, value, "I");
5493 }
5494 CHECK_LONG_OFFSET("java/lang/Long", java_lang_boxing_object, value, "J");
5495
5496 if (!valid) vm_exit_during_initialization("Field offset verification failed");
5497 }
5498
5499 #endif // PRODUCT
5500
5501 int InjectedField::compute_offset() {
5502 InstanceKlass* ik = InstanceKlass::cast(klass());
5503 for (AllFieldStream fs(ik); !fs.done(); fs.next()) {
5504 if (!may_be_java && !fs.field_flags().is_injected()) {
5505 // Only look at injected fields
5506 continue;
5507 }
5508 if (fs.name() == name() && fs.signature() == signature()) {
5509 return fs.offset();
5510 }
5511 }
5512 ResourceMark rm;
5513 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)" : "");
|