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