< prev index next >

src/hotspot/share/classfile/javaClasses.cpp

Print this page

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


  55 #include "oops/instanceKlass.inline.hpp"
  56 #include "oops/instanceMirrorKlass.hpp"
  57 #include "oops/klass.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/oopCast.inline.hpp"
  63 #include "oops/oop.inline.hpp"
  64 #include "oops/symbol.hpp"
  65 #include "oops/recordComponent.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"

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








1077       BasicType type = TypeArrayKlass::cast(k)->element_type();
1078       if (is_scratch) {
1079         comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(type));
1080       } else {
1081         comp_mirror = Handle(THREAD, Universe::java_mirror(type));
1082       }
1083     } else {
1084       assert(k->is_objArray_klass(), "Must be");
1085       Klass* element_klass = ObjArrayKlass::cast(k)->element_klass();
1086       assert(element_klass != nullptr, "Must have an element klass");

1087       if (is_scratch) {
1088         comp_mirror = Handle(THREAD, HeapShared::scratch_java_mirror(element_klass));
1089       } else {
1090         comp_mirror = Handle(THREAD, element_klass->java_mirror());
1091       }
1092     }
1093     assert(comp_mirror() != nullptr, "must have a mirror");
1094 
1095     // Two-way link between the array klass and its component mirror:
1096     // (array_klass) k -> mirror -> component_mirror -> array_klass -> k
1097     set_component_mirror(mirror(), comp_mirror());
1098     // See below for ordering dependencies between field array_klass in component mirror
1099     // and java_mirror in this klass.
1100   } else {
1101     assert(k->is_instance_klass(), "Must be");
1102 
1103     initialize_mirror_fields(k, mirror, protection_domain, classData, THREAD);
1104     if (HAS_PENDING_EXCEPTION) {
1105       // If any of the fields throws an exception like OOM remove the klass field
1106       // from the mirror so GC doesn't follow it after the klass has been deallocated.
1107       // This mirror looks like a primitive type, which logically it is because it
1108       // it represents no class.
1109       set_klass(mirror(), nullptr);
1110       return;

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

1146     if (CDSConfig::is_dumping_heap()) {
1147       create_scratch_mirror(k, CHECK);
1148     }
1149   } else {
1150     assert(fixup_mirror_list() != nullptr, "fixup_mirror_list not initialized");
1151     fixup_mirror_list()->push(k);
1152   }
1153 }
1154 
1155 #if INCLUDE_CDS_JAVA_HEAP
1156 // The "scratch mirror" stores the states of the mirror object that can be
1157 // decided at dump time (such as the initial values of the static fields, the
1158 // component mirror, etc). At runtime, more information is added to it by
1159 // java_lang_Class::restore_archived_mirror().
1160 //
1161 // Essentially, /*dumptime*/create_scratch_mirror() + /*runtime*/restore_archived_mirror()
1162 // produces the same result as /*runtime*/create_mirror().
1163 //
1164 // Note: we archive the "scratch mirror" instead of k->java_mirror(), because the
1165 // latter may contain dumptime-specific information that cannot be archived
1166 // (e.g., ClassLoaderData*, or static fields that are modified by Java code execution).
1167 void java_lang_Class::create_scratch_mirror(Klass* k, TRAPS) {
1168   if (k->class_loader() != nullptr &&
1169       k->class_loader() != SystemDictionary::java_platform_loader() &&
1170       k->class_loader() != SystemDictionary::java_system_loader()) {
1171     // We only archive the mirrors of classes loaded by the built-in loaders
1172     return;
1173   }
1174 
1175   Handle protection_domain, classData; // set to null. Will be reinitialized at runtime
1176   Handle mirror;
1177   Handle comp_mirror;
1178   allocate_mirror(k, /*is_scratch=*/true, protection_domain, classData, mirror, comp_mirror, CHECK);
1179 
1180   if (comp_mirror() != nullptr) {
1181     release_set_array_klass(comp_mirror(), k);
1182   }
1183 
1184   HeapShared::set_scratch_java_mirror(k, mirror());
1185 }
1186 
1187 // Returns true if the mirror is updated, false if no archived mirror
1188 // data is present. After the archived mirror object is restored, the
1189 // shared klass' _has_raw_archived_mirror flag is cleared.
1190 bool java_lang_Class::restore_archived_mirror(Klass *k,

1378   assert(is_instance(java_class), "must be a Class object");
1379   java_class->metadata_field_put(_klass_offset, klass);
1380 }
1381 
1382 
1383 void java_lang_Class::print_signature(oop java_class, outputStream* st) {
1384   assert(is_instance(java_class), "must be a Class object");
1385   Symbol* name = nullptr;
1386   bool is_instance = false;
1387   if (is_primitive(java_class)) {
1388     name = vmSymbols::type_signature(primitive_type(java_class));
1389   } else {
1390     Klass* k = as_Klass(java_class);
1391     is_instance = k->is_instance_klass();
1392     name = k->name();
1393   }
1394   if (name == nullptr) {
1395     st->print("<null>");
1396     return;
1397   }
1398   if (is_instance)  st->print("L");


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

1437   if (is_primitive(java_class)) {
1438     name = type2name(primitive_type(java_class));
1439   } else {
1440     name = as_Klass(java_class)->external_name();
1441   }
1442   if (name == nullptr) {
1443     name = "<null>";
1444   }
1445   return name;
1446 }
1447 
1448 Klass* java_lang_Class::array_klass_acquire(oop java_class) {
1449   Klass* k = ((Klass*)java_class->metadata_field_acquire(_array_klass_offset));
1450   assert(k == nullptr || (k->is_klass() && k->is_array_klass()), "should be array klass");
1451   return k;
1452 }
1453 
1454 
1455 void java_lang_Class::release_set_array_klass(oop java_class, Klass* klass) {
1456   assert(klass->is_klass() && klass->is_array_klass(), "should be array klass");




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

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

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

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

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

3952 }
3953 #endif
3954 
3955 bool java_lang_ref_Reference::is_referent_field(oop obj, ptrdiff_t offset) {
3956   assert(obj != nullptr, "sanity");
3957   if (offset != _referent_offset) {
3958     return false;
3959   }
3960 
3961   Klass* k = obj->klass();
3962   if (!k->is_instance_klass()) {
3963     return false;
3964   }
3965 
3966   InstanceKlass* ik = InstanceKlass::cast(obj->klass());
3967   bool is_reference = ik->reference_type() != REF_NONE;
3968   assert(!is_reference || ik->is_subclass_of(vmClasses::Reference_klass()), "sanity");
3969   return is_reference;
3970 }
3971 
3972 int java_lang_boxing_object::_value_offset;
3973 int java_lang_boxing_object::_long_value_offset;

3974 
3975 #define BOXING_FIELDS_DO(macro) \
3976   macro(_value_offset,      integerKlass, "value", int_signature, false); \
3977   macro(_long_value_offset, longKlass, "value", long_signature, false);

3978 
3979 void java_lang_boxing_object::compute_offsets() {
3980   InstanceKlass* integerKlass = vmClasses::Integer_klass();

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

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

5486   if (!ik->find_local_field(f_name, f_sig, &fd)) {
5487     tty->print_cr("Nonstatic field %s.%s not found", klass_name, field_name);
5488     return false;
5489   }
5490   if (fd.is_static()) {
5491     tty->print_cr("Nonstatic field %s.%s appears to be static", klass_name, field_name);
5492     return false;
5493   }
5494   if (fd.offset() == deserialized_offset ) {
5495     return true;
5496   } else {
5497     tty->print_cr("Offset of nonstatic field %s.%s is deserialized as %d but should really be %d.",
5498                   klass_name, field_name, deserialized_offset, fd.offset());
5499     return false;
5500   }
5501 }
5502 
5503 void JavaClasses::check_offsets() {
5504   bool valid = true;
5505 
5506 #define CHECK_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \
5507   valid &= check_offset(klass_name, cpp_klass_name :: _##field_name ## _offset, #field_name, field_sig)






5508 
5509 #define CHECK_LONG_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \
5510   valid &= check_offset(klass_name, cpp_klass_name :: _##long_ ## field_name ## _offset, #field_name, field_sig)
5511 
5512   // Boxed primitive objects (java_lang_boxing_object)
5513 
5514   CHECK_OFFSET("java/lang/Boolean",   java_lang_boxing_object, value, "Z");
5515   CHECK_OFFSET("java/lang/Character", java_lang_boxing_object, value, "C");
5516   CHECK_OFFSET("java/lang/Float",     java_lang_boxing_object, value, "F");
5517   CHECK_LONG_OFFSET("java/lang/Double", java_lang_boxing_object, value, "D");
5518   CHECK_OFFSET("java/lang/Byte",      java_lang_boxing_object, value, "B");
5519   CHECK_OFFSET("java/lang/Short",     java_lang_boxing_object, value, "S");
5520   CHECK_OFFSET("java/lang/Integer",   java_lang_boxing_object, value, "I");
5521   CHECK_LONG_OFFSET("java/lang/Long", java_lang_boxing_object, value, "J");
5522 
5523   if (!valid) vm_exit_during_initialization("Field offset verification failed");
5524 }
5525 
5526 #endif // PRODUCT
5527 
5528 int InjectedField::compute_offset() {
5529   InstanceKlass* ik = InstanceKlass::cast(klass());
5530   for (AllFieldStream fs(ik); !fs.done(); fs.next()) {
5531     if (!may_be_java && !fs.field_flags().is_injected()) {
5532       // Only look at injected fields
5533       continue;
5534     }
5535     if (fs.name() == name() && fs.signature() == signature()) {
5536       return fs.offset();
5537     }
5538   }
5539   ResourceMark rm;
5540   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)" : "");
5541 #ifndef PRODUCT

  35 #include "classfile/moduleEntry.hpp"
  36 #include "classfile/stringTable.hpp"
  37 #include "classfile/symbolTable.hpp"
  38 #include "classfile/systemDictionary.hpp"
  39 #include "classfile/vmClasses.hpp"
  40 #include "classfile/vmSymbols.hpp"
  41 #include "code/debugInfo.hpp"
  42 #include "code/dependencyContext.hpp"
  43 #include "code/pcDesc.hpp"
  44 #include "gc/shared/collectedHeap.inline.hpp"
  45 #include "interpreter/interpreter.hpp"
  46 #include "interpreter/linkResolver.hpp"
  47 #include "jvm.h"
  48 #include "logging/log.hpp"
  49 #include "logging/logStream.hpp"
  50 #include "memory/oopFactory.hpp"
  51 #include "memory/resourceArea.hpp"
  52 #include "memory/universe.hpp"
  53 #include "oops/fieldInfo.hpp"
  54 #include "oops/fieldStreams.inline.hpp"
  55 #include "oops/flatArrayKlass.hpp"
  56 #include "oops/inlineKlass.inline.hpp"
  57 #include "oops/instanceKlass.inline.hpp"
  58 #include "oops/instanceMirrorKlass.inline.hpp"
  59 #include "oops/klass.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/oopCast.inline.hpp"
  65 #include "oops/oop.inline.hpp"
  66 #include "oops/symbol.hpp"
  67 #include "oops/recordComponent.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"

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

1137 
1138     allocate_mirror(k, /*is_scratch=*/false, protection_domain, classData, mirror, comp_mirror, CHECK);
1139 
1140     // set the classLoader field in the java_lang_Class instance
1141     assert(class_loader() == k->class_loader(), "should be same");
1142     set_class_loader(mirror(), class_loader());
1143 
1144     // Setup indirection from klass->mirror
1145     // after any exceptions can happen during allocations.
1146     k->set_java_mirror(mirror);
1147 
1148     // Set the module field in the java_lang_Class instance.  This must be done
1149     // after the mirror is set.
1150     set_mirror_module_field(THREAD, k, mirror, module);
1151 
1152     if (comp_mirror() != nullptr) {
1153       // Set after k->java_mirror() is published, because compiled code running
1154       // concurrently doesn't expect a k to have a null java_mirror.
1155       release_set_array_klass(comp_mirror(), k);
1156     }
1157 
1158     if (CDSConfig::is_dumping_heap()) {
1159       create_scratch_mirror(k, CHECK);
1160     }
1161   } else {
1162     assert(fixup_mirror_list() != nullptr, "fixup_mirror_list not initialized");
1163     fixup_mirror_list()->push(k);
1164   }
1165 }
1166 
1167 #if INCLUDE_CDS_JAVA_HEAP
1168 // The "scratch mirror" stores the states of the mirror object that can be
1169 // decided at dump time (such as the initial values of the static fields, the
1170 // component mirror, etc). At runtime, more information is added to it by
1171 // java_lang_Class::restore_archived_mirror().
1172 //
1173 // Essentially, /*dumptime*/create_scratch_mirror() + /*runtime*/restore_archived_mirror()
1174 // produces the same result as /*runtime*/create_mirror().
1175 //
1176 // Note: we archive the "scratch mirror" instead of k->java_mirror(), because the
1177 // latter may contain dumptime-specific information that cannot be archived
1178 // (e.g., ClassLoaderData*, or static fields that are modified by Java code execution).
1179 void java_lang_Class::create_scratch_mirror(Klass* k, TRAPS) {
1180   if ((k->class_loader() != nullptr &&
1181        k->class_loader() != SystemDictionary::java_platform_loader() &&
1182        k->class_loader() != SystemDictionary::java_system_loader())) {
1183     // We only archive the mirrors of classes loaded by the built-in loaders
1184     return;
1185   }
1186 
1187   Handle protection_domain, classData; // set to null. Will be reinitialized at runtime
1188   Handle mirror;
1189   Handle comp_mirror;
1190   allocate_mirror(k, /*is_scratch=*/true, protection_domain, classData, mirror, comp_mirror, CHECK);
1191 
1192   if (comp_mirror() != nullptr) {
1193     release_set_array_klass(comp_mirror(), k);
1194   }
1195 
1196   HeapShared::set_scratch_java_mirror(k, mirror());
1197 }
1198 
1199 // Returns true if the mirror is updated, false if no archived mirror
1200 // data is present. After the archived mirror object is restored, the
1201 // shared klass' _has_raw_archived_mirror flag is cleared.
1202 bool java_lang_Class::restore_archived_mirror(Klass *k,

1390   assert(is_instance(java_class), "must be a Class object");
1391   java_class->metadata_field_put(_klass_offset, klass);
1392 }
1393 
1394 
1395 void java_lang_Class::print_signature(oop java_class, outputStream* st) {
1396   assert(is_instance(java_class), "must be a Class object");
1397   Symbol* name = nullptr;
1398   bool is_instance = false;
1399   if (is_primitive(java_class)) {
1400     name = vmSymbols::type_signature(primitive_type(java_class));
1401   } else {
1402     Klass* k = as_Klass(java_class);
1403     is_instance = k->is_instance_klass();
1404     name = k->name();
1405   }
1406   if (name == nullptr) {
1407     st->print("<null>");
1408     return;
1409   }
1410   if (is_instance)  {
1411     st->print("L");
1412   }
1413   st->write((char*) name->base(), (int) name->utf8_length());
1414   if (is_instance)  st->print(";");
1415 }
1416 
1417 Symbol* java_lang_Class::as_signature(oop java_class, bool intern_if_not_found) {
1418   assert(is_instance(java_class), "must be a Class object");
1419   Symbol* name;
1420   if (is_primitive(java_class)) {
1421     name = vmSymbols::type_signature(primitive_type(java_class));
1422     // Because this can create a new symbol, the caller has to decrement
1423     // the refcount, so make adjustment here and below for symbols returned
1424     // that are not created or incremented due to a successful lookup.
1425     name->increment_refcount();
1426   } else {
1427     Klass* k = as_Klass(java_class);
1428     if (!k->is_instance_klass()) {
1429       name = k->name();
1430       name->increment_refcount();
1431     } else {
1432       ResourceMark rm;

1451   if (is_primitive(java_class)) {
1452     name = type2name(primitive_type(java_class));
1453   } else {
1454     name = as_Klass(java_class)->external_name();
1455   }
1456   if (name == nullptr) {
1457     name = "<null>";
1458   }
1459   return name;
1460 }
1461 
1462 Klass* java_lang_Class::array_klass_acquire(oop java_class) {
1463   Klass* k = ((Klass*)java_class->metadata_field_acquire(_array_klass_offset));
1464   assert(k == nullptr || (k->is_klass() && k->is_array_klass()), "should be array klass");
1465   return k;
1466 }
1467 
1468 
1469 void java_lang_Class::release_set_array_klass(oop java_class, Klass* klass) {
1470   assert(klass->is_klass() && klass->is_array_klass(), "should be array klass");
1471   if (klass->is_flatArray_klass() || (klass->is_objArray_klass() && ObjArrayKlass::cast(klass)->is_null_free_array_klass())) {
1472     // TODO 8336006 Ignore flat / null-free arrays
1473     return;
1474   }
1475   java_class->release_metadata_field_put(_array_klass_offset, klass);
1476 }
1477 
1478 
1479 BasicType java_lang_Class::primitive_type(oop java_class) {
1480   assert(is_primitive(java_class), "just checking");
1481   Klass* ak = ((Klass*)java_class->metadata_field(_array_klass_offset));
1482   BasicType type = T_VOID;
1483   if (ak != nullptr) {
1484     // Note: create_basic_type_mirror above initializes ak to a non-null value.
1485     type = ArrayKlass::cast(ak)->element_type();
1486   } else {
1487     assert(java_class == Universe::void_mirror(), "only valid non-array primitive");
1488   }
1489 #ifdef ASSERT
1490   if (CDSConfig::is_dumping_heap()) {
1491     oop mirror = Universe::java_mirror(type);
1492     oop scratch_mirror = HeapShared::scratch_java_mirror(type);
1493     assert(java_class == mirror || java_class == scratch_mirror, "must be consistent");
1494   } else {

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

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

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

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

3970 }
3971 #endif
3972 
3973 bool java_lang_ref_Reference::is_referent_field(oop obj, ptrdiff_t offset) {
3974   assert(obj != nullptr, "sanity");
3975   if (offset != _referent_offset) {
3976     return false;
3977   }
3978 
3979   Klass* k = obj->klass();
3980   if (!k->is_instance_klass()) {
3981     return false;
3982   }
3983 
3984   InstanceKlass* ik = InstanceKlass::cast(obj->klass());
3985   bool is_reference = ik->reference_type() != REF_NONE;
3986   assert(!is_reference || ik->is_subclass_of(vmClasses::Reference_klass()), "sanity");
3987   return is_reference;
3988 }
3989 
3990 int java_lang_boxing_object::_sub32bits_value_offset;
3991 int java_lang_boxing_object::_32bits_value_offset;
3992 int java_lang_boxing_object::_64bits_value_offset;
3993 
3994 #define BOXING_FIELDS_DO(macro) \
3995   macro(_sub32bits_value_offset, byteKlass, "value", byte_signature, false); \
3996   macro(_32bits_value_offset,    intKlass,  "value", int_signature,  false); \
3997   macro(_64bits_value_offset,    longKlass, "value", long_signature, false);
3998 
3999 void java_lang_boxing_object::compute_offsets() {
4000   InstanceKlass* byteKlass = vmClasses::Byte_klass();
4001   InstanceKlass* intKlass = vmClasses::Integer_klass();
4002   InstanceKlass* longKlass = vmClasses::Long_klass();
4003   BOXING_FIELDS_DO(FIELD_COMPUTE_OFFSET);
4004 }
4005 
4006 #if INCLUDE_CDS
4007 void java_lang_boxing_object::serialize_offsets(SerializeClosure* f) {
4008   BOXING_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
4009 }
4010 #endif
4011 
4012 oop java_lang_boxing_object::initialize_and_allocate(BasicType type, TRAPS) {
4013   Klass* k = vmClasses::box_klass(type);
4014   if (k == nullptr)  return nullptr;
4015   InstanceKlass* ik = InstanceKlass::cast(k);
4016   if (!ik->is_initialized()) {
4017     ik->initialize(CHECK_NULL);
4018   }
4019   return ik->allocate_instance(THREAD);
4020 }
4021 
4022 
4023 oop java_lang_boxing_object::create(BasicType type, jvalue* value, TRAPS) {
4024   oop box = initialize_and_allocate(type, CHECK_NULL);
4025   if (box == nullptr)  return nullptr;
4026   switch (type) {
4027     case T_BOOLEAN:
4028       box->bool_field_put(_sub32bits_value_offset, value->z);
4029       break;
4030     case T_CHAR:
4031       box->char_field_put(_sub32bits_value_offset, value->c);
4032       break;
4033     case T_FLOAT:
4034       box->float_field_put(_32bits_value_offset, value->f);
4035       break;
4036     case T_DOUBLE:
4037       box->double_field_put(_64bits_value_offset, value->d);
4038       break;
4039     case T_BYTE:
4040       box->byte_field_put(_sub32bits_value_offset, value->b);
4041       break;
4042     case T_SHORT:
4043       box->short_field_put(_sub32bits_value_offset, value->s);
4044       break;
4045     case T_INT:
4046       box->int_field_put(_32bits_value_offset, value->i);
4047       break;
4048     case T_LONG:
4049       box->long_field_put(_64bits_value_offset, value->j);
4050       break;
4051     default:
4052       return nullptr;
4053   }
4054   return box;
4055 }
4056 
4057 
4058 BasicType java_lang_boxing_object::basic_type(oop box) {
4059   if (box == nullptr)  return T_ILLEGAL;
4060   BasicType type = vmClasses::box_klass_type(box->klass());
4061   if (type == T_OBJECT)         // 'unknown' value returned by SD::bkt
4062     return T_ILLEGAL;
4063   return type;
4064 }
4065 
4066 
4067 BasicType java_lang_boxing_object::get_value(oop box, jvalue* value) {
4068   BasicType type = vmClasses::box_klass_type(box->klass());
4069   switch (type) {
4070   case T_BOOLEAN:
4071     value->z = box->bool_field(_sub32bits_value_offset);
4072     break;
4073   case T_CHAR:
4074     value->c = box->char_field(_sub32bits_value_offset);
4075     break;
4076   case T_FLOAT:
4077       value->f = box->float_field(_32bits_value_offset);
4078     break;
4079   case T_DOUBLE:
4080     value->d = box->double_field(_64bits_value_offset);
4081     break;
4082   case T_BYTE:
4083     value->b = box->byte_field(_sub32bits_value_offset);
4084     break;
4085   case T_SHORT:
4086     value->s = box->short_field(_sub32bits_value_offset);
4087     break;
4088   case T_INT:
4089       value->i = box->int_field(_32bits_value_offset);
4090     break;
4091   case T_LONG:
4092     value->j = box->long_field(_64bits_value_offset);
4093     break;
4094   default:
4095     return T_ILLEGAL;
4096   } // end switch
4097   return type;
4098 }
4099 
4100 
4101 BasicType java_lang_boxing_object::set_value(oop box, jvalue* value) {
4102   BasicType type = vmClasses::box_klass_type(box->klass());
4103   switch (type) {
4104   case T_BOOLEAN:
4105     box->bool_field_put(_sub32bits_value_offset, value->z);
4106     break;
4107   case T_CHAR:
4108     box->char_field_put(_sub32bits_value_offset, value->c);
4109     break;
4110   case T_FLOAT:
4111     box->float_field_put(_32bits_value_offset, value->f);
4112     break;
4113   case T_DOUBLE:
4114     box->double_field_put(_64bits_value_offset, value->d);
4115     break;
4116   case T_BYTE:
4117     box->byte_field_put(_sub32bits_value_offset, value->b);
4118     break;
4119   case T_SHORT:
4120     box->short_field_put(_sub32bits_value_offset, value->s);
4121     break;
4122   case T_INT:
4123     box->int_field_put(_32bits_value_offset, value->i);
4124     break;
4125   case T_LONG:
4126     box->long_field_put(_64bits_value_offset, value->j);
4127     break;
4128   default:
4129     return T_ILLEGAL;
4130   } // end switch
4131   return type;
4132 }
4133 
4134 
4135 void java_lang_boxing_object::print(BasicType type, jvalue* value, outputStream* st) {
4136   switch (type) {
4137   case T_BOOLEAN:   st->print("%s", value->z ? "true" : "false");   break;
4138   case T_CHAR:      st->print("%d", value->c);                      break;
4139   case T_BYTE:      st->print("%d", value->b);                      break;
4140   case T_SHORT:     st->print("%d", value->s);                      break;
4141   case T_INT:       st->print("%d", value->i);                      break;
4142   case T_LONG:      st->print(JLONG_FORMAT, value->j);              break;
4143   case T_FLOAT:     st->print("%f", value->f);                      break;
4144   case T_DOUBLE:    st->print("%lf", value->d);                     break;
4145   default:          st->print("type %d?", type);                    break;
4146   }

4502 oop java_lang_invoke_MemberName::type(oop mname) {
4503   assert(is_instance(mname), "wrong type");
4504   return mname->obj_field(_type_offset);
4505 }
4506 
4507 void java_lang_invoke_MemberName::set_type(oop mname, oop type) {
4508   assert(is_instance(mname), "wrong type");
4509   mname->obj_field_put(_type_offset, type);
4510 }
4511 
4512 int java_lang_invoke_MemberName::flags(oop mname) {
4513   assert(is_instance(mname), "wrong type");
4514   return mname->int_field(_flags_offset);
4515 }
4516 
4517 void java_lang_invoke_MemberName::set_flags(oop mname, int flags) {
4518   assert(is_instance(mname), "wrong type");
4519   mname->int_field_put(_flags_offset, flags);
4520 }
4521 

4522 // Return vmtarget from ResolvedMethodName method field through indirection
4523 Method* java_lang_invoke_MemberName::vmtarget(oop mname) {
4524   assert(is_instance(mname), "wrong type");
4525   oop method = mname->obj_field(_method_offset);
4526   return method == nullptr ? nullptr : java_lang_invoke_ResolvedMethodName::vmtarget(method);
4527 }
4528 
4529 bool java_lang_invoke_MemberName::is_method(oop mname) {
4530   assert(is_instance(mname), "must be MemberName");
4531   return (flags(mname) & (MN_IS_METHOD | MN_IS_OBJECT_CONSTRUCTOR)) > 0;
4532 }
4533 
4534 void java_lang_invoke_MemberName::set_method(oop mname, oop resolved_method) {
4535   assert(is_instance(mname), "wrong type");
4536   mname->obj_field_put(_method_offset, resolved_method);
4537 }
4538 
4539 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) {
4540   assert(is_instance(mname), "wrong type");
4541   return (intptr_t) mname->address_field(_vmindex_offset);
4542 }
4543 
4544 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
4545   assert(is_instance(mname), "wrong type");
4546   mname->address_field_put(_vmindex_offset, (address) index);
4547 }
4548 
4549 
4550 Method* java_lang_invoke_ResolvedMethodName::vmtarget(oop resolved_method) {
4551   assert(is_instance(resolved_method), "wrong type");

5506   if (!ik->find_local_field(f_name, f_sig, &fd)) {
5507     tty->print_cr("Nonstatic field %s.%s not found", klass_name, field_name);
5508     return false;
5509   }
5510   if (fd.is_static()) {
5511     tty->print_cr("Nonstatic field %s.%s appears to be static", klass_name, field_name);
5512     return false;
5513   }
5514   if (fd.offset() == deserialized_offset ) {
5515     return true;
5516   } else {
5517     tty->print_cr("Offset of nonstatic field %s.%s is deserialized as %d but should really be %d.",
5518                   klass_name, field_name, deserialized_offset, fd.offset());
5519     return false;
5520   }
5521 }
5522 
5523 void JavaClasses::check_offsets() {
5524   bool valid = true;
5525 
5526 #define CHECK_SUB32BITS_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \
5527   valid &= check_offset(klass_name, cpp_klass_name :: _ ##sub32bits_ ## field_name ## _offset, #field_name, field_sig)
5528 
5529 #define CHECK_32BITS_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \
5530   valid &= check_offset(klass_name, cpp_klass_name :: _##32bits_ ## field_name ## _offset, #field_name, field_sig)
5531 
5532 #define CHECK_64BITS_OFFSET(klass_name, cpp_klass_name, field_name, field_sig) \
5533   valid &= check_offset(klass_name, cpp_klass_name :: _##64bits_ ## field_name ## _offset, #field_name, field_sig)
5534 


5535 
5536   // Boxed primitive objects (java_lang_boxing_object)
5537 
5538   CHECK_SUB32BITS_OFFSET("java/lang/Boolean",   java_lang_boxing_object, value, "Z");
5539   CHECK_SUB32BITS_OFFSET("java/lang/Character", java_lang_boxing_object, value, "C");
5540   CHECK_32BITS_OFFSET("java/lang/Float",     java_lang_boxing_object, value, "F");
5541   CHECK_64BITS_OFFSET("java/lang/Double", java_lang_boxing_object, value, "D");
5542   CHECK_SUB32BITS_OFFSET("java/lang/Byte",      java_lang_boxing_object, value, "B");
5543   CHECK_SUB32BITS_OFFSET("java/lang/Short",     java_lang_boxing_object, value, "S");
5544   CHECK_32BITS_OFFSET("java/lang/Integer",   java_lang_boxing_object, value, "I");
5545   CHECK_64BITS_OFFSET("java/lang/Long", java_lang_boxing_object, value, "J");
5546 
5547   if (!valid) vm_exit_during_initialization("Field offset verification failed");
5548 }
5549 
5550 #endif // PRODUCT
5551 
5552 int InjectedField::compute_offset() {
5553   InstanceKlass* ik = InstanceKlass::cast(klass());
5554   for (AllFieldStream fs(ik); !fs.done(); fs.next()) {
5555     if (!may_be_java && !fs.field_flags().is_injected()) {
5556       // Only look at injected fields
5557       continue;
5558     }
5559     if (fs.name() == name() && fs.signature() == signature()) {
5560       return fs.offset();
5561     }
5562   }
5563   ResourceMark rm;
5564   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)" : "");
5565 #ifndef PRODUCT
< prev index next >