234 class java_lang_Class : AllStatic {
235 friend class VMStructs;
236 friend class JVMCIVMStructs;
237
238 private:
239
240 // The fake offsets are added by the class loader when java.lang.Class is loaded
241
242 static int _klass_offset;
243 static int _array_klass_offset;
244
245 static int _oop_size_offset;
246 static int _static_oop_field_count_offset;
247
248 static int _protection_domain_offset;
249 static int _init_lock_offset;
250 static int _signers_offset;
251 static int _class_loader_offset;
252 static int _module_offset;
253 static int _component_mirror_offset;
254 static int _name_offset;
255 static int _source_file_offset;
256 static int _classData_offset;
257 static int _classRedefinedCount_offset;
258 static int _reflectionData_offset;
259 static int _modifiers_offset;
260 static int _is_primitive_offset;
261
262 static bool _offsets_computed;
263
264 static GrowableArray<Klass*>* _fixup_mirror_list;
265 static GrowableArray<Klass*>* _fixup_module_field_list;
266
267 static void set_init_lock(oop java_class, oop init_lock);
268 static void set_protection_domain(oop java_class, oop protection_domain);
269 static void set_class_loader(oop java_class, oop class_loader);
270 static void set_component_mirror(oop java_class, oop comp_mirror);
271 static void initialize_mirror_fields(Klass* k, Handle mirror, Handle protection_domain,
272 Handle classData, TRAPS);
273 static void set_mirror_module_field(JavaThread* current, Klass* K, Handle mirror, Handle module);
274 public:
275 static void allocate_fixup_lists();
276 static void compute_offsets();
277
278 // Instance creation
279 static void allocate_mirror(Klass* k, bool is_scratch, Handle protection_domain, Handle classData,
280 Handle& mirror, Handle& comp_mirror, TRAPS); // returns mirror and comp_mirror
281 static void create_mirror(Klass* k, Handle class_loader, Handle module,
282 Handle protection_domain, Handle classData, TRAPS);
283 static void fixup_mirror(Klass* k, TRAPS);
284 static oop create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS);
285
286 // Archiving
287 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
288 static void create_scratch_mirror(Klass* k, TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
289 static bool restore_archived_mirror(Klass *k, Handle class_loader, Handle module,
290 Handle protection_domain,
295 // Conversion
296 static Klass* as_Klass(oop java_class);
297 static void set_klass(oop java_class, Klass* klass);
298 static BasicType as_BasicType(oop java_class, Klass** reference_klass = nullptr);
299 static Symbol* as_signature(oop java_class, bool intern_if_not_found);
300 static void print_signature(oop java_class, outputStream *st);
301 static const char* as_external_name(oop java_class);
302 // Testing
303 static bool is_instance(oop obj);
304
305 static bool is_primitive(oop java_class);
306 static void set_is_primitive(oop java_class);
307 static BasicType primitive_type(oop java_class);
308 static oop primitive_mirror(BasicType t);
309 // JVM_NewArray support
310 static Klass* array_klass_acquire(oop java_class);
311 static void release_set_array_klass(oop java_class, Klass* klass);
312 // compiler support for class operations
313 static int klass_offset() { CHECK_INIT(_klass_offset); }
314 static int array_klass_offset() { CHECK_INIT(_array_klass_offset); }
315 // Support for classRedefinedCount field
316 static int classRedefinedCount(oop the_class_mirror);
317 static void set_classRedefinedCount(oop the_class_mirror, int value);
318
319 // Support for embedded per-class oops
320 static oop protection_domain(oop java_class);
321 static oop init_lock(oop java_class);
322 static void clear_init_lock(oop java_class) {
323 set_init_lock(java_class, nullptr);
324 }
325 static oop component_mirror(oop java_class);
326 static int component_mirror_offset() { return _component_mirror_offset; }
327 static objArrayOop signers(oop java_class);
328 static oop class_data(oop java_class);
329 static void set_class_data(oop java_class, oop classData);
330 static void set_reflection_data(oop java_class, oop reflection_data);
331 static int reflection_data_offset() { return _reflectionData_offset; }
332
333 static oop class_loader(oop java_class);
334 static void set_module(oop java_class, oop module);
806 static void set_signature(oop constructor, oop value);
807 static void set_annotations(oop constructor, oop value);
808 static void set_parameter_annotations(oop method, oop value);
809
810 // Debugging
811 friend class JavaClasses;
812 };
813
814
815 // Interface to java.lang.reflect.Field objects
816
817 class java_lang_reflect_Field : public java_lang_reflect_AccessibleObject {
818 private:
819 // Note that to reduce dependencies on the JDK we compute these
820 // offsets at run-time.
821 static int _clazz_offset;
822 static int _name_offset;
823 static int _type_offset;
824 static int _slot_offset;
825 static int _modifiers_offset;
826 static int _trusted_final_offset;
827 static int _signature_offset;
828 static int _annotations_offset;
829
830 static void compute_offsets();
831
832 public:
833 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
834
835 // Allocation
836 static Handle create(TRAPS);
837
838 // Accessors
839 static oop clazz(oop reflect);
840 static void set_clazz(oop reflect, oop value);
841
842 static oop name(oop field);
843 static void set_name(oop field, oop value);
844
845 static oop type(oop field);
846 static void set_type(oop field, oop value);
847
848 static int slot(oop reflect);
849 static void set_slot(oop reflect, int value);
850
851 static int modifiers(oop field);
852 static void set_modifiers(oop field, int value);
853
854 static void set_trusted_final(oop field);
855
856 static void set_signature(oop constructor, oop value);
857 static void set_annotations(oop constructor, oop value);
858
859 // Debugging
860 friend class JavaClasses;
861 };
862
863 class java_lang_reflect_Parameter {
864 private:
865 // Note that to reduce dependencies on the JDK we compute these
866 // offsets at run-time.
867 static int _name_offset;
868 static int _modifiers_offset;
869 static int _index_offset;
870 static int _executable_offset;
871
872 static void compute_offsets();
873
874 public:
953
954 // Debugging
955 friend class JavaClasses;
956 };
957
958
959 // Interface to java.lang primitive type boxing objects:
960 // - java.lang.Boolean
961 // - java.lang.Character
962 // - java.lang.Float
963 // - java.lang.Double
964 // - java.lang.Byte
965 // - java.lang.Short
966 // - java.lang.Integer
967 // - java.lang.Long
968
969 // This could be separated out into 8 individual classes.
970
971 class java_lang_boxing_object: AllStatic {
972 private:
973 static int _value_offset;
974 static int _long_value_offset;
975
976 static void compute_offsets();
977 static oop initialize_and_allocate(BasicType type, TRAPS);
978 public:
979 // Allocation. Returns a boxed value, or null for invalid type.
980 static oop create(BasicType type, jvalue* value, TRAPS);
981 // Accessors. Returns the basic type being boxed, or T_ILLEGAL for invalid oop.
982 static BasicType get_value(oop box, jvalue* value);
983 static BasicType set_value(oop box, jvalue* value);
984 static BasicType basic_type(oop box);
985 static bool is_instance(oop box) { return basic_type(box) != T_ILLEGAL; }
986 static bool is_instance(oop box, BasicType type) { return basic_type(box) == type; }
987 static void print(oop box, outputStream* st) { jvalue value; print(get_value(box, &value), &value, st); }
988 static void print(BasicType type, jvalue* value, outputStream* st);
989
990 static int value_offset(BasicType type) {
991 return is_double_word_type(type) ? _long_value_offset : _value_offset;
992 }
993
994 static void serialize_offsets(SerializeClosure* f);
995
996 // Debugging
997 friend class JavaClasses;
998 };
999
1000
1001
1002 // Interface to java.lang.ref.Reference objects
1003
1004 class java_lang_ref_Reference: AllStatic {
1005 static int _referent_offset;
1006 static int _queue_offset;
1007 static int _next_offset;
1008 static int _discovered_offset;
1009
1010 static bool _offsets_initialized;
1011
1333 static void set_flags(oop mname, int flags);
1334
1335 // Link through ResolvedMethodName field to get Method*
1336 static Method* vmtarget(oop mname);
1337 static void set_method(oop mname, oop method);
1338
1339 static intptr_t vmindex(oop mname);
1340 static void set_vmindex(oop mname, intptr_t index);
1341
1342 // Testers
1343 static bool is_subclass(Klass* klass) {
1344 return klass->is_subclass_of(vmClasses::MemberName_klass());
1345 }
1346 static bool is_instance(oop obj);
1347
1348 static bool is_method(oop obj);
1349
1350 // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):
1351 enum {
1352 MN_IS_METHOD = 0x00010000, // method (not constructor)
1353 MN_IS_CONSTRUCTOR = 0x00020000, // constructor
1354 MN_IS_FIELD = 0x00040000, // field
1355 MN_IS_TYPE = 0x00080000, // nested type
1356 MN_CALLER_SENSITIVE = 0x00100000, // @CallerSensitive annotation detected
1357 MN_TRUSTED_FINAL = 0x00200000, // trusted final field
1358 MN_HIDDEN_MEMBER = 0x00400000, // @Hidden annotation detected
1359 MN_REFERENCE_KIND_SHIFT = 24, // refKind
1360 MN_REFERENCE_KIND_MASK = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT,
1361 MN_NESTMATE_CLASS = 0x00000001,
1362 MN_HIDDEN_CLASS = 0x00000002,
1363 MN_STRONG_LOADER_LINK = 0x00000004,
1364 MN_ACCESS_VM_ANNOTATIONS = 0x00000008,
1365 // Lookup modes
1366 MN_MODULE_MODE = 0x00000010,
1367 MN_UNCONDITIONAL_MODE = 0x00000020,
1368 MN_TRUSTED_MODE = -1
1369 };
1370
1371 // Accessors for code generation:
1372 static int clazz_offset() { CHECK_INIT(_clazz_offset); }
1373 static int type_offset() { CHECK_INIT(_type_offset); }
1374 static int flags_offset() { CHECK_INIT(_flags_offset); }
1375 static int method_offset() { CHECK_INIT(_method_offset); }
1376 static int vmindex_offset() { CHECK_INIT(_vmindex_offset); }
1377 };
1378
1379
1380 // Interface to java.lang.invoke.MethodType objects
1844 class java_lang_Short_ShortCache : AllStatic {
1845 private:
1846 static int _static_cache_offset;
1847 public:
1848 static Symbol* symbol();
1849 static void compute_offsets(InstanceKlass* k);
1850 static objArrayOop cache(InstanceKlass *k);
1851 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1852 };
1853
1854 class java_lang_Byte_ByteCache : AllStatic {
1855 private:
1856 static int _static_cache_offset;
1857 public:
1858 static Symbol* symbol();
1859 static void compute_offsets(InstanceKlass* k);
1860 static objArrayOop cache(InstanceKlass *k);
1861 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1862 };
1863
1864
1865 // Interface to java.lang.InternalError objects
1866
1867 #define INTERNALERROR_INJECTED_FIELDS(macro) \
1868 macro(java_lang_InternalError, during_unsafe_access, bool_signature, false)
1869
1870 class java_lang_InternalError : AllStatic {
1871 private:
1872 static int _during_unsafe_access_offset;
1873 public:
1874 static jboolean during_unsafe_access(oop internal_error);
1875 static void set_during_unsafe_access(oop internal_error);
1876 static void compute_offsets();
1877 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1878 };
1879
1880 // Use to declare fields that need to be injected into Java classes
1881 // for the JVM to use. The name_index and signature_index are
1882 // declared in vmSymbols. The may_be_java flag is used to declare
1883 // fields that might already exist in Java but should be injected if
1884 // they don't. Otherwise the field is unconditionally injected and
|
234 class java_lang_Class : AllStatic {
235 friend class VMStructs;
236 friend class JVMCIVMStructs;
237
238 private:
239
240 // The fake offsets are added by the class loader when java.lang.Class is loaded
241
242 static int _klass_offset;
243 static int _array_klass_offset;
244
245 static int _oop_size_offset;
246 static int _static_oop_field_count_offset;
247
248 static int _protection_domain_offset;
249 static int _init_lock_offset;
250 static int _signers_offset;
251 static int _class_loader_offset;
252 static int _module_offset;
253 static int _component_mirror_offset;
254
255 static int _name_offset;
256 static int _source_file_offset;
257 static int _classData_offset;
258 static int _classRedefinedCount_offset;
259 static int _reflectionData_offset;
260 static int _modifiers_offset;
261 static int _is_primitive_offset;
262
263 static bool _offsets_computed;
264
265 static GrowableArray<Klass*>* _fixup_mirror_list;
266 static GrowableArray<Klass*>* _fixup_module_field_list;
267
268 static void set_init_lock(oop java_class, oop init_lock);
269 static void set_protection_domain(oop java_class, oop protection_domain);
270 static void set_class_loader(oop java_class, oop class_loader);
271 static void set_component_mirror(oop java_class, oop comp_mirror);
272
273 static void initialize_mirror_fields(Klass* k, Handle mirror, Handle protection_domain,
274 Handle classData, TRAPS);
275 static void set_mirror_module_field(JavaThread* current, Klass* K, Handle mirror, Handle module);
276 public:
277 static void allocate_fixup_lists();
278 static void compute_offsets();
279
280 // Instance creation
281 static void allocate_mirror(Klass* k, bool is_scratch, Handle protection_domain, Handle classData,
282 Handle& mirror, Handle& comp_mirror, TRAPS); // returns mirror and comp_mirror
283 static void create_mirror(Klass* k, Handle class_loader, Handle module,
284 Handle protection_domain, Handle classData, TRAPS);
285 static void fixup_mirror(Klass* k, TRAPS);
286 static oop create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS);
287
288 // Archiving
289 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
290 static void create_scratch_mirror(Klass* k, TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
291 static bool restore_archived_mirror(Klass *k, Handle class_loader, Handle module,
292 Handle protection_domain,
297 // Conversion
298 static Klass* as_Klass(oop java_class);
299 static void set_klass(oop java_class, Klass* klass);
300 static BasicType as_BasicType(oop java_class, Klass** reference_klass = nullptr);
301 static Symbol* as_signature(oop java_class, bool intern_if_not_found);
302 static void print_signature(oop java_class, outputStream *st);
303 static const char* as_external_name(oop java_class);
304 // Testing
305 static bool is_instance(oop obj);
306
307 static bool is_primitive(oop java_class);
308 static void set_is_primitive(oop java_class);
309 static BasicType primitive_type(oop java_class);
310 static oop primitive_mirror(BasicType t);
311 // JVM_NewArray support
312 static Klass* array_klass_acquire(oop java_class);
313 static void release_set_array_klass(oop java_class, Klass* klass);
314 // compiler support for class operations
315 static int klass_offset() { CHECK_INIT(_klass_offset); }
316 static int array_klass_offset() { CHECK_INIT(_array_klass_offset); }
317
318 // Support for classRedefinedCount field
319 static int classRedefinedCount(oop the_class_mirror);
320 static void set_classRedefinedCount(oop the_class_mirror, int value);
321
322 // Support for embedded per-class oops
323 static oop protection_domain(oop java_class);
324 static oop init_lock(oop java_class);
325 static void clear_init_lock(oop java_class) {
326 set_init_lock(java_class, nullptr);
327 }
328 static oop component_mirror(oop java_class);
329 static int component_mirror_offset() { return _component_mirror_offset; }
330 static objArrayOop signers(oop java_class);
331 static oop class_data(oop java_class);
332 static void set_class_data(oop java_class, oop classData);
333 static void set_reflection_data(oop java_class, oop reflection_data);
334 static int reflection_data_offset() { return _reflectionData_offset; }
335
336 static oop class_loader(oop java_class);
337 static void set_module(oop java_class, oop module);
809 static void set_signature(oop constructor, oop value);
810 static void set_annotations(oop constructor, oop value);
811 static void set_parameter_annotations(oop method, oop value);
812
813 // Debugging
814 friend class JavaClasses;
815 };
816
817
818 // Interface to java.lang.reflect.Field objects
819
820 class java_lang_reflect_Field : public java_lang_reflect_AccessibleObject {
821 private:
822 // Note that to reduce dependencies on the JDK we compute these
823 // offsets at run-time.
824 static int _clazz_offset;
825 static int _name_offset;
826 static int _type_offset;
827 static int _slot_offset;
828 static int _modifiers_offset;
829 static int _flags_offset;
830 static int _signature_offset;
831 static int _annotations_offset;
832
833 static void compute_offsets();
834
835 public:
836 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
837
838 // Allocation
839 static Handle create(TRAPS);
840
841 // Accessors
842 static oop clazz(oop reflect);
843 static void set_clazz(oop reflect, oop value);
844
845 static oop name(oop field);
846 static void set_name(oop field, oop value);
847
848 static oop type(oop field);
849 static void set_type(oop field, oop value);
850
851 static int slot(oop reflect);
852 static void set_slot(oop reflect, int value);
853
854 static int modifiers(oop field);
855 static void set_modifiers(oop field, int value);
856
857 static void set_flags(oop field, int value);
858
859 static void set_signature(oop constructor, oop value);
860 static void set_annotations(oop constructor, oop value);
861
862 // Debugging
863 friend class JavaClasses;
864 };
865
866 class java_lang_reflect_Parameter {
867 private:
868 // Note that to reduce dependencies on the JDK we compute these
869 // offsets at run-time.
870 static int _name_offset;
871 static int _modifiers_offset;
872 static int _index_offset;
873 static int _executable_offset;
874
875 static void compute_offsets();
876
877 public:
956
957 // Debugging
958 friend class JavaClasses;
959 };
960
961
962 // Interface to java.lang primitive type boxing objects:
963 // - java.lang.Boolean
964 // - java.lang.Character
965 // - java.lang.Float
966 // - java.lang.Double
967 // - java.lang.Byte
968 // - java.lang.Short
969 // - java.lang.Integer
970 // - java.lang.Long
971
972 // This could be separated out into 8 individual classes.
973
974 class java_lang_boxing_object: AllStatic {
975 private:
976 static int* _offsets;
977
978 static void compute_offsets();
979 static oop initialize_and_allocate(BasicType type, TRAPS);
980 public:
981 // Allocation. Returns a boxed value, or null for invalid type.
982 static oop create(BasicType type, jvalue* value, TRAPS);
983 // Accessors. Returns the basic type being boxed, or T_ILLEGAL for invalid oop.
984 static BasicType get_value(oop box, jvalue* value);
985 static BasicType set_value(oop box, jvalue* value);
986 static BasicType basic_type(oop box);
987 static bool is_instance(oop box) { return basic_type(box) != T_ILLEGAL; }
988 static bool is_instance(oop box, BasicType type) { return basic_type(box) == type; }
989 static void print(oop box, outputStream* st) { jvalue value; print(get_value(box, &value), &value, st); }
990 static void print(BasicType type, jvalue* value, outputStream* st);
991
992 static int value_offset(BasicType type) {
993 assert(type >= T_BOOLEAN && type <= T_LONG, "BasicType out of range");
994 assert(_offsets != nullptr, "Uninitialized offsets");
995 return _offsets[type - T_BOOLEAN];
996 }
997
998 static void serialize_offsets(SerializeClosure* f);
999
1000 // Debugging
1001 friend class JavaClasses;
1002 };
1003
1004
1005
1006 // Interface to java.lang.ref.Reference objects
1007
1008 class java_lang_ref_Reference: AllStatic {
1009 static int _referent_offset;
1010 static int _queue_offset;
1011 static int _next_offset;
1012 static int _discovered_offset;
1013
1014 static bool _offsets_initialized;
1015
1337 static void set_flags(oop mname, int flags);
1338
1339 // Link through ResolvedMethodName field to get Method*
1340 static Method* vmtarget(oop mname);
1341 static void set_method(oop mname, oop method);
1342
1343 static intptr_t vmindex(oop mname);
1344 static void set_vmindex(oop mname, intptr_t index);
1345
1346 // Testers
1347 static bool is_subclass(Klass* klass) {
1348 return klass->is_subclass_of(vmClasses::MemberName_klass());
1349 }
1350 static bool is_instance(oop obj);
1351
1352 static bool is_method(oop obj);
1353
1354 // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):
1355 enum {
1356 MN_IS_METHOD = 0x00010000, // method (not constructor)
1357 MN_IS_OBJECT_CONSTRUCTOR = 0x00020000, // constructor
1358 MN_IS_FIELD = 0x00040000, // field
1359 MN_IS_TYPE = 0x00080000, // nested type
1360 MN_CALLER_SENSITIVE = 0x00100000, // @CallerSensitive annotation detected
1361 MN_TRUSTED_FINAL = 0x00200000, // trusted final field
1362 MN_HIDDEN_MEMBER = 0x00400000, // @Hidden annotation detected
1363 MN_NULL_RESTRICTED_FIELD = 0x00800000, // null-restricted field
1364 MN_REFERENCE_KIND_SHIFT = 24, // refKind
1365 MN_REFERENCE_KIND_MASK = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT, // 4 bits
1366 MN_LAYOUT_SHIFT = 28, // field layout
1367 MN_LAYOUT_MASK = 0x70000000 >> MN_LAYOUT_SHIFT, // 3 bits
1368 MN_NESTMATE_CLASS = 0x00000001,
1369 MN_HIDDEN_CLASS = 0x00000002,
1370 MN_STRONG_LOADER_LINK = 0x00000004,
1371 MN_ACCESS_VM_ANNOTATIONS = 0x00000008,
1372 // Lookup modes
1373 MN_MODULE_MODE = 0x00000010,
1374 MN_UNCONDITIONAL_MODE = 0x00000020,
1375 MN_TRUSTED_MODE = -1
1376 };
1377
1378 // Accessors for code generation:
1379 static int clazz_offset() { CHECK_INIT(_clazz_offset); }
1380 static int type_offset() { CHECK_INIT(_type_offset); }
1381 static int flags_offset() { CHECK_INIT(_flags_offset); }
1382 static int method_offset() { CHECK_INIT(_method_offset); }
1383 static int vmindex_offset() { CHECK_INIT(_vmindex_offset); }
1384 };
1385
1386
1387 // Interface to java.lang.invoke.MethodType objects
1851 class java_lang_Short_ShortCache : AllStatic {
1852 private:
1853 static int _static_cache_offset;
1854 public:
1855 static Symbol* symbol();
1856 static void compute_offsets(InstanceKlass* k);
1857 static objArrayOop cache(InstanceKlass *k);
1858 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1859 };
1860
1861 class java_lang_Byte_ByteCache : AllStatic {
1862 private:
1863 static int _static_cache_offset;
1864 public:
1865 static Symbol* symbol();
1866 static void compute_offsets(InstanceKlass* k);
1867 static objArrayOop cache(InstanceKlass *k);
1868 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1869 };
1870
1871 // Interface to java.lang.InternalError objects
1872
1873 #define INTERNALERROR_INJECTED_FIELDS(macro) \
1874 macro(java_lang_InternalError, during_unsafe_access, bool_signature, false)
1875
1876 class java_lang_InternalError : AllStatic {
1877 private:
1878 static int _during_unsafe_access_offset;
1879 public:
1880 static jboolean during_unsafe_access(oop internal_error);
1881 static void set_during_unsafe_access(oop internal_error);
1882 static void compute_offsets();
1883 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1884 };
1885
1886 // Use to declare fields that need to be injected into Java classes
1887 // for the JVM to use. The name_index and signature_index are
1888 // declared in vmSymbols. The may_be_java flag is used to declare
1889 // fields that might already exist in Java but should be injected if
1890 // they don't. Otherwise the field is unconditionally injected and
|