1 /* 2 * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_CLASSFILE_JAVACLASSES_HPP 26 #define SHARE_CLASSFILE_JAVACLASSES_HPP 27 28 #include "classfile/vmClasses.hpp" 29 #include "oops/oop.hpp" 30 #include "oops/instanceKlass.hpp" 31 #include "oops/symbol.hpp" 32 #include "runtime/os.hpp" 33 #include "utilities/vmEnums.hpp" 34 35 class RecordComponent; 36 37 // Interface for manipulating the basic Java classes. 38 39 #define BASIC_JAVA_CLASSES_DO_PART1(f) \ 40 f(java_lang_Class) \ 41 f(java_lang_String) \ 42 f(java_lang_ref_Reference) \ 43 //end 44 45 #define BASIC_JAVA_CLASSES_DO_PART2(f) \ 46 f(java_lang_System) \ 47 f(java_lang_ClassLoader) \ 48 f(java_lang_Throwable) \ 49 f(java_lang_Thread) \ 50 f(java_lang_ThreadGroup) \ 51 f(java_lang_InternalError) \ 52 f(java_lang_AssertionStatusDirectives) \ 53 f(java_lang_ref_SoftReference) \ 54 f(java_lang_invoke_MethodHandle) \ 55 f(java_lang_invoke_DirectMethodHandle) \ 56 f(java_lang_invoke_MemberName) \ 57 f(java_lang_invoke_ResolvedMethodName) \ 58 f(java_lang_invoke_LambdaForm) \ 59 f(java_lang_invoke_MethodType) \ 60 f(java_lang_invoke_CallSite) \ 61 f(java_lang_invoke_ConstantCallSite) \ 62 f(java_lang_invoke_MethodHandleNatives_CallSiteContext) \ 63 f(java_security_AccessControlContext) \ 64 f(java_lang_reflect_AccessibleObject) \ 65 f(java_lang_reflect_Method) \ 66 f(java_lang_reflect_Constructor) \ 67 f(java_lang_reflect_Field) \ 68 f(java_lang_reflect_RecordComponent) \ 69 f(reflect_ConstantPool) \ 70 f(reflect_UnsafeStaticFieldAccessorImpl) \ 71 f(java_lang_reflect_Parameter) \ 72 f(java_lang_Module) \ 73 f(java_lang_StackTraceElement) \ 74 f(java_lang_StackFrameInfo) \ 75 f(java_lang_LiveStackFrameInfo) \ 76 f(java_util_concurrent_locks_AbstractOwnableSynchronizer) \ 77 f(jdk_internal_invoke_NativeEntryPoint) \ 78 f(jdk_internal_misc_UnsafeConstants) \ 79 f(java_lang_boxing_object) \ 80 f(vector_VectorPayload) \ 81 //end 82 83 #define BASIC_JAVA_CLASSES_DO(f) \ 84 BASIC_JAVA_CLASSES_DO_PART1(f) \ 85 BASIC_JAVA_CLASSES_DO_PART2(f) 86 87 #define CHECK_INIT(offset) assert(offset != 0, "should be initialized"); return offset; 88 89 // Interface to java.lang.Object objects 90 91 class java_lang_Object : AllStatic { 92 public: 93 static void register_natives(TRAPS); 94 }; 95 96 // Interface to java.lang.String objects 97 98 // The flags field is a collection of bits representing boolean values used 99 // internally by the VM. 100 #define STRING_INJECTED_FIELDS(macro) \ 101 macro(java_lang_String, flags, byte_signature, false) 102 103 class java_lang_String : AllStatic { 104 private: 105 static int _value_offset; 106 static int _hash_offset; 107 static int _hashIsZero_offset; 108 static int _coder_offset; 109 static int _flags_offset; 110 111 static bool _initialized; 112 113 static Handle basic_create(int length, bool byte_arr, TRAPS); 114 115 static inline void set_coder(oop string, jbyte coder); 116 117 // Bitmasks for values in the injected flags field. 118 static const uint8_t _deduplication_forbidden_mask = 1 << 0; 119 static const uint8_t _deduplication_requested_mask = 1 << 1; 120 121 static int flags_offset() { CHECK_INIT(_flags_offset); } 122 // Return the address of the injected flags field. 123 static inline uint8_t* flags_addr(oop java_string); 124 // Test whether the designated bit of the injected flags field is set. 125 static inline bool is_flag_set(oop java_string, uint8_t flag_mask); 126 // Atomically test and set the designated bit of the injected flags field, 127 // returning true if the bit was already set. 128 static bool test_and_set_flag(oop java_string, uint8_t flag_mask); 129 130 static inline unsigned int hash_code_impl(oop java_string, bool update); 131 132 public: 133 134 // Coders 135 enum Coder { 136 CODER_LATIN1 = 0, 137 CODER_UTF16 = 1 138 }; 139 140 static void compute_offsets(); 141 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 142 143 // Instance creation 144 static Handle create_from_unicode(const jchar* unicode, int len, TRAPS); 145 static oop create_oop_from_unicode(const jchar* unicode, int len, TRAPS); 146 static Handle create_from_str(const char* utf8_str, TRAPS); 147 static oop create_oop_from_str(const char* utf8_str, TRAPS); 148 static Handle create_from_symbol(Symbol* symbol, TRAPS); 149 static Handle create_from_platform_dependent_str(const char* str, TRAPS); 150 151 static void set_compact_strings(bool value); 152 153 static int value_offset() { CHECK_INIT(_value_offset); } 154 static int coder_offset() { CHECK_INIT(_coder_offset); } 155 156 static inline void set_value_raw(oop string, typeArrayOop buffer); 157 static inline void set_value(oop string, typeArrayOop buffer); 158 159 // Set the deduplication_forbidden flag true. This flag is sticky; once 160 // set it never gets cleared. This is set when a String is interned in 161 // the StringTable, to prevent string deduplication from changing the 162 // String's value array. 163 static inline void set_deduplication_forbidden(oop java_string); 164 165 // Test and set the deduplication_requested flag. Returns the old value 166 // of the flag. This flag is sticky; once set it never gets cleared. 167 // Some GCs may use this flag when deciding whether to request 168 // deduplication of a String, to avoid multiple requests for the same 169 // object. 170 static inline bool test_and_set_deduplication_requested(oop java_string); 171 172 // Accessors 173 static inline typeArrayOop value(oop java_string); 174 static inline typeArrayOop value_no_keepalive(oop java_string); 175 static inline bool hash_is_set(oop string); 176 static inline bool is_latin1(oop java_string); 177 static inline bool deduplication_forbidden(oop java_string); 178 static inline bool deduplication_requested(oop java_string); 179 static inline int length(oop java_string); 180 static inline int length(oop java_string, typeArrayOop string_value); 181 static int utf8_length(oop java_string); 182 static int utf8_length(oop java_string, typeArrayOop string_value); 183 184 // String converters 185 static char* as_utf8_string(oop java_string); 186 static char* as_utf8_string(oop java_string, int& length); 187 static char* as_utf8_string_full(oop java_string, char* buf, int buflen, int& length); 188 static char* as_utf8_string(oop java_string, char* buf, int buflen); 189 static char* as_utf8_string(oop java_string, int start, int len); 190 static char* as_utf8_string(oop java_string, typeArrayOop value, char* buf, int buflen); 191 static char* as_utf8_string(oop java_string, typeArrayOop value, int start, int len, char* buf, int buflen); 192 static char* as_platform_dependent_str(Handle java_string, TRAPS); 193 static jchar* as_unicode_string(oop java_string, int& length, TRAPS); 194 static jchar* as_unicode_string_or_null(oop java_string, int& length); 195 // produce an ascii string with all other values quoted using \u#### 196 static char* as_quoted_ascii(oop java_string); 197 198 // Compute the hash value for a java.lang.String object which would 199 // contain the characters passed in. 200 // 201 // As the hash value used by the String object itself, in 202 // String.hashCode(). This value is normally calculated in Java code 203 // in the String.hashCode method(), but is precomputed for String 204 // objects in the shared archive file. 205 // hash P(31) from Kernighan & Ritchie 206 // 207 // For this reason, THIS ALGORITHM MUST MATCH String.hashCode(). 208 static unsigned int hash_code(const jchar* s, int len) { 209 unsigned int h = 0; 210 while (len-- > 0) { 211 h = 31*h + (unsigned int) *s; 212 s++; 213 } 214 return h; 215 } 216 217 static unsigned int hash_code(const jbyte* s, int len) { 218 unsigned int h = 0; 219 while (len-- > 0) { 220 h = 31*h + (((unsigned int) *s) & 0xFF); 221 s++; 222 } 223 return h; 224 } 225 226 static unsigned int hash_code(oop java_string); 227 static unsigned int hash_code_noupdate(oop java_string); 228 229 static bool equals(oop java_string, const jchar* chars, int len); 230 static bool equals(oop str1, oop str2); 231 static inline bool value_equals(typeArrayOop str_value1, typeArrayOop str_value2); 232 233 // Conversion between '.' and '/' formats, and allocate a String from the result. 234 static Handle externalize_classname(Symbol* java_name, TRAPS); 235 236 // Conversion 237 static Symbol* as_symbol(oop java_string); 238 static Symbol* as_symbol_or_null(oop java_string); 239 240 // Tester 241 static inline bool is_instance(oop obj); 242 243 // Debugging 244 static void print(oop java_string, outputStream* st); 245 friend class JavaClasses; 246 friend class StringTable; 247 }; 248 249 250 // Interface to java.lang.Class objects 251 252 #define CLASS_INJECTED_FIELDS(macro) \ 253 macro(java_lang_Class, klass, intptr_signature, false) \ 254 macro(java_lang_Class, array_klass, intptr_signature, false) \ 255 macro(java_lang_Class, oop_size, int_signature, false) \ 256 macro(java_lang_Class, static_oop_field_count, int_signature, false) \ 257 macro(java_lang_Class, protection_domain, object_signature, false) \ 258 macro(java_lang_Class, signers, object_signature, false) \ 259 macro(java_lang_Class, source_file, object_signature, false) \ 260 261 class java_lang_Class : AllStatic { 262 friend class VMStructs; 263 friend class JVMCIVMStructs; 264 265 private: 266 267 // The fake offsets are added by the class loader when java.lang.Class is loaded 268 269 static int _klass_offset; 270 static int _array_klass_offset; 271 272 static int _oop_size_offset; 273 static int _static_oop_field_count_offset; 274 275 static int _protection_domain_offset; 276 static int _init_lock_offset; 277 static int _signers_offset; 278 static int _class_loader_offset; 279 static int _module_offset; 280 static int _component_mirror_offset; 281 static int _name_offset; 282 static int _source_file_offset; 283 static int _classData_offset; 284 static int _classRedefinedCount_offset; 285 286 static bool _offsets_computed; 287 288 static GrowableArray<Klass*>* _fixup_mirror_list; 289 static GrowableArray<Klass*>* _fixup_module_field_list; 290 291 static void set_init_lock(oop java_class, oop init_lock); 292 static void set_protection_domain(oop java_class, oop protection_domain); 293 static void set_class_loader(oop java_class, oop class_loader); 294 static void set_component_mirror(oop java_class, oop comp_mirror); 295 static void initialize_mirror_fields(Klass* k, Handle mirror, Handle protection_domain, 296 Handle classData, TRAPS); 297 static void set_mirror_module_field(JavaThread* current, Klass* K, Handle mirror, Handle module); 298 public: 299 static void allocate_fixup_lists(); 300 static void compute_offsets(); 301 302 // Instance creation 303 static void create_mirror(Klass* k, Handle class_loader, Handle module, 304 Handle protection_domain, Handle classData, TRAPS); 305 static void fixup_mirror(Klass* k, TRAPS); 306 static oop create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS); 307 static void update_archived_primitive_mirror_native_pointers(oop archived_mirror) NOT_CDS_JAVA_HEAP_RETURN; 308 static void update_archived_mirror_native_pointers(oop archived_mirror) NOT_CDS_JAVA_HEAP_RETURN; 309 310 // Archiving 311 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 312 static void archive_basic_type_mirrors() NOT_CDS_JAVA_HEAP_RETURN; 313 static oop archive_mirror(Klass* k) NOT_CDS_JAVA_HEAP_RETURN_(NULL); 314 static oop process_archived_mirror(Klass* k, oop mirror, oop archived_mirror) 315 NOT_CDS_JAVA_HEAP_RETURN_(NULL); 316 static bool restore_archived_mirror(Klass *k, Handle class_loader, Handle module, 317 Handle protection_domain, 318 TRAPS) NOT_CDS_JAVA_HEAP_RETURN_(false); 319 320 static void fixup_module_field(Klass* k, Handle module); 321 322 // Conversion 323 static Klass* as_Klass(oop java_class); 324 static void set_klass(oop java_class, Klass* klass); 325 static BasicType as_BasicType(oop java_class, Klass** reference_klass = NULL); 326 static Symbol* as_signature(oop java_class, bool intern_if_not_found); 327 static void print_signature(oop java_class, outputStream *st); 328 static const char* as_external_name(oop java_class); 329 // Testing 330 static bool is_instance(oop obj); 331 332 static bool is_primitive(oop java_class); 333 static BasicType primitive_type(oop java_class); 334 static oop primitive_mirror(BasicType t); 335 // JVM_NewArray support 336 static Klass* array_klass_acquire(oop java_class); 337 static void release_set_array_klass(oop java_class, Klass* klass); 338 // compiler support for class operations 339 static int klass_offset() { CHECK_INIT(_klass_offset); } 340 static int array_klass_offset() { CHECK_INIT(_array_klass_offset); } 341 // Support for classRedefinedCount field 342 static int classRedefinedCount(oop the_class_mirror); 343 static void set_classRedefinedCount(oop the_class_mirror, int value); 344 345 // Support for embedded per-class oops 346 static oop protection_domain(oop java_class); 347 static oop init_lock(oop java_class); 348 static void clear_init_lock(oop java_class) { 349 set_init_lock(java_class, NULL); 350 } 351 static oop component_mirror(oop java_class); 352 static objArrayOop signers(oop java_class); 353 static void set_signers(oop java_class, objArrayOop signers); 354 static oop class_data(oop java_class); 355 static void set_class_data(oop java_class, oop classData); 356 357 static int component_mirror_offset() { return _component_mirror_offset; } 358 359 static oop class_loader(oop java_class); 360 static void set_module(oop java_class, oop module); 361 static oop module(oop java_class); 362 363 static oop name(Handle java_class, TRAPS); 364 365 static oop source_file(oop java_class); 366 static void set_source_file(oop java_class, oop source_file); 367 368 static size_t oop_size(oop java_class); 369 static void set_oop_size(HeapWord* java_class, size_t size); 370 static int static_oop_field_count(oop java_class); 371 static void set_static_oop_field_count(oop java_class, int size); 372 373 static GrowableArray<Klass*>* fixup_mirror_list() { 374 return _fixup_mirror_list; 375 } 376 static void set_fixup_mirror_list(GrowableArray<Klass*>* v) { 377 _fixup_mirror_list = v; 378 } 379 380 static GrowableArray<Klass*>* fixup_module_field_list() { 381 return _fixup_module_field_list; 382 } 383 static void set_fixup_module_field_list(GrowableArray<Klass*>* v) { 384 _fixup_module_field_list = v; 385 } 386 387 // Debugging 388 friend class JavaClasses; 389 }; 390 391 // Interface to java.lang.Thread objects 392 393 class java_lang_Thread : AllStatic { 394 private: 395 // Note that for this class the layout changed between JDK1.2 and JDK1.3, 396 // so we compute the offsets at startup rather than hard-wiring them. 397 static int _name_offset; 398 static int _group_offset; 399 static int _contextClassLoader_offset; 400 static int _inheritedAccessControlContext_offset; 401 static int _priority_offset; 402 static int _eetop_offset; 403 static int _interrupted_offset; 404 static int _daemon_offset; 405 static int _stillborn_offset; 406 static int _stackSize_offset; 407 static int _tid_offset; 408 static int _thread_status_offset; 409 static int _park_blocker_offset; 410 411 static void compute_offsets(); 412 413 public: 414 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 415 416 // Returns the JavaThread associated with the thread obj 417 static JavaThread* thread(oop java_thread); 418 // Set JavaThread for instance 419 static void set_thread(oop java_thread, JavaThread* thread); 420 // Interrupted status 421 static bool interrupted(oop java_thread); 422 static void set_interrupted(oop java_thread, bool val); 423 // Name 424 static oop name(oop java_thread); 425 static void set_name(oop java_thread, oop name); 426 // Priority 427 static ThreadPriority priority(oop java_thread); 428 static void set_priority(oop java_thread, ThreadPriority priority); 429 // Thread group 430 static oop threadGroup(oop java_thread); 431 // Stillborn 432 static bool is_stillborn(oop java_thread); 433 static void set_stillborn(oop java_thread); 434 // Alive (NOTE: this is not really a field, but provides the correct 435 // definition without doing a Java call) 436 static bool is_alive(oop java_thread); 437 // Daemon 438 static bool is_daemon(oop java_thread); 439 static void set_daemon(oop java_thread); 440 // Context ClassLoader 441 static oop context_class_loader(oop java_thread); 442 // Control context 443 static oop inherited_access_control_context(oop java_thread); 444 // Stack size hint 445 static jlong stackSize(oop java_thread); 446 // Thread ID 447 static jlong thread_id(oop java_thread); 448 449 // Blocker object responsible for thread parking 450 static oop park_blocker(oop java_thread); 451 452 // Write thread status info to threadStatus field of java.lang.Thread. 453 static void set_thread_status(oop java_thread_oop, JavaThreadStatus status); 454 // Read thread status info from threadStatus field of java.lang.Thread. 455 static JavaThreadStatus get_thread_status(oop java_thread_oop); 456 457 static const char* thread_status_name(oop java_thread_oop); 458 459 // Debugging 460 friend class JavaClasses; 461 }; 462 463 // Interface to java.lang.ThreadGroup objects 464 465 class java_lang_ThreadGroup : AllStatic { 466 private: 467 static int _parent_offset; 468 static int _name_offset; 469 static int _threads_offset; 470 static int _groups_offset; 471 static int _maxPriority_offset; 472 static int _destroyed_offset; 473 static int _daemon_offset; 474 static int _nthreads_offset; 475 static int _ngroups_offset; 476 477 static void compute_offsets(); 478 479 public: 480 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 481 482 // parent ThreadGroup 483 static oop parent(oop java_thread_group); 484 // name 485 static const char* name(oop java_thread_group); 486 // ("name as oop" accessor is not necessary) 487 // Number of threads in group 488 static int nthreads(oop java_thread_group); 489 // threads 490 static objArrayOop threads(oop java_thread_group); 491 // Number of threads in group 492 static int ngroups(oop java_thread_group); 493 // groups 494 static objArrayOop groups(oop java_thread_group); 495 // maxPriority in group 496 static ThreadPriority maxPriority(oop java_thread_group); 497 // Destroyed 498 static bool is_destroyed(oop java_thread_group); 499 // Daemon 500 static bool is_daemon(oop java_thread_group); 501 // Debugging 502 friend class JavaClasses; 503 }; 504 505 506 507 // Interface to java.lang.Throwable objects 508 509 class java_lang_Throwable: AllStatic { 510 friend class BacktraceBuilder; 511 friend class BacktraceIterator; 512 513 private: 514 // Trace constants 515 enum { 516 trace_methods_offset = 0, 517 trace_bcis_offset = 1, 518 trace_mirrors_offset = 2, 519 trace_names_offset = 3, 520 trace_next_offset = 4, 521 trace_hidden_offset = 5, 522 trace_size = 6, 523 trace_chunk_size = 32 524 }; 525 526 static int _backtrace_offset; 527 static int _detailMessage_offset; 528 static int _stackTrace_offset; 529 static int _depth_offset; 530 static int _cause_offset; 531 static int _static_unassigned_stacktrace_offset; 532 533 // StackTrace (programmatic access, new since 1.4) 534 static void clear_stacktrace(oop throwable); 535 // Stacktrace (post JDK 1.7.0 to allow immutability protocol to be followed) 536 static void set_stacktrace(oop throwable, oop st_element_array); 537 static oop unassigned_stacktrace(); 538 539 public: 540 // Backtrace 541 static oop backtrace(oop throwable); 542 static void set_backtrace(oop throwable, oop value); 543 static int depth(oop throwable); 544 static void set_depth(oop throwable, int value); 545 static int get_detailMessage_offset() { CHECK_INIT(_detailMessage_offset); } 546 // Message 547 static oop message(oop throwable); 548 static oop cause(oop throwable); 549 static void set_message(oop throwable, oop value); 550 static Symbol* detail_message(oop throwable); 551 static void print_stack_element(outputStream *st, Method* method, int bci); 552 553 static void compute_offsets(); 554 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 555 556 // Allocate space for backtrace (created but stack trace not filled in) 557 static void allocate_backtrace(Handle throwable, TRAPS); 558 // Fill in current stack trace for throwable with preallocated backtrace (no GC) 559 static void fill_in_stack_trace_of_preallocated_backtrace(Handle throwable); 560 // Fill in current stack trace, can cause GC 561 static void fill_in_stack_trace(Handle throwable, const methodHandle& method, TRAPS); 562 static void fill_in_stack_trace(Handle throwable, const methodHandle& method = methodHandle()); 563 // Programmatic access to stack trace 564 static void get_stack_trace_elements(Handle throwable, objArrayHandle stack_trace, TRAPS); 565 566 // For recreating class initialization error exceptions. 567 static Handle get_cause_with_stack_trace(Handle throwable, TRAPS); 568 569 // Printing 570 static void print(oop throwable, outputStream* st); 571 static void print_stack_trace(Handle throwable, outputStream* st); 572 static void java_printStackTrace(Handle throwable, TRAPS); 573 // Debugging 574 friend class JavaClasses; 575 // Gets the method and bci of the top frame (TOS). Returns false if this failed. 576 static bool get_top_method_and_bci(oop throwable, Method** method, int* bci); 577 }; 578 579 580 // Interface to java.lang.reflect.AccessibleObject objects 581 582 class java_lang_reflect_AccessibleObject: AllStatic { 583 private: 584 // Note that to reduce dependencies on the JDK we compute these 585 // offsets at run-time. 586 static int _override_offset; 587 588 static void compute_offsets(); 589 590 public: 591 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 592 593 // Accessors 594 static jboolean override(oop reflect); 595 static void set_override(oop reflect, jboolean value); 596 597 // Debugging 598 friend class JavaClasses; 599 }; 600 601 602 // Interface to java.lang.reflect.Method objects 603 604 class java_lang_reflect_Method : public java_lang_reflect_AccessibleObject { 605 private: 606 // Note that to reduce dependencies on the JDK we compute these 607 // offsets at run-time. 608 static int _clazz_offset; 609 static int _name_offset; 610 static int _returnType_offset; 611 static int _parameterTypes_offset; 612 static int _exceptionTypes_offset; 613 static int _slot_offset; 614 static int _modifiers_offset; 615 static int _signature_offset; 616 static int _annotations_offset; 617 static int _parameter_annotations_offset; 618 static int _annotation_default_offset; 619 620 static void compute_offsets(); 621 public: 622 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 623 624 // Allocation 625 static Handle create(TRAPS); 626 627 // Accessors 628 static oop clazz(oop reflect); 629 static void set_clazz(oop reflect, oop value); 630 631 static void set_name(oop method, oop value); 632 633 static oop return_type(oop method); 634 static void set_return_type(oop method, oop value); 635 636 static oop parameter_types(oop method); 637 static void set_parameter_types(oop method, oop value); 638 639 static int slot(oop reflect); 640 static void set_slot(oop reflect, int value); 641 642 static void set_exception_types(oop method, oop value); 643 static void set_modifiers(oop method, int value); 644 static void set_signature(oop method, oop value); 645 static void set_annotations(oop method, oop value); 646 static void set_parameter_annotations(oop method, oop value); 647 static void set_annotation_default(oop method, oop value); 648 649 // Debugging 650 friend class JavaClasses; 651 }; 652 653 654 // Interface to java.lang.reflect.Constructor objects 655 656 class java_lang_reflect_Constructor : public java_lang_reflect_AccessibleObject { 657 private: 658 // Note that to reduce dependencies on the JDK we compute these 659 // offsets at run-time. 660 static int _clazz_offset; 661 static int _parameterTypes_offset; 662 static int _exceptionTypes_offset; 663 static int _slot_offset; 664 static int _modifiers_offset; 665 static int _signature_offset; 666 static int _annotations_offset; 667 static int _parameter_annotations_offset; 668 669 static void compute_offsets(); 670 public: 671 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 672 673 // Allocation 674 static Handle create(TRAPS); 675 676 // Accessors 677 static oop clazz(oop reflect); 678 static void set_clazz(oop reflect, oop value); 679 680 static oop parameter_types(oop constructor); 681 static void set_parameter_types(oop constructor, oop value); 682 683 static int slot(oop reflect); 684 static void set_slot(oop reflect, int value); 685 686 static void set_exception_types(oop constructor, oop value); 687 static void set_modifiers(oop constructor, int value); 688 static void set_signature(oop constructor, oop value); 689 static void set_annotations(oop constructor, oop value); 690 static void set_parameter_annotations(oop method, oop value); 691 692 // Debugging 693 friend class JavaClasses; 694 }; 695 696 697 // Interface to java.lang.reflect.Field objects 698 699 class java_lang_reflect_Field : public java_lang_reflect_AccessibleObject { 700 private: 701 // Note that to reduce dependencies on the JDK we compute these 702 // offsets at run-time. 703 static int _clazz_offset; 704 static int _name_offset; 705 static int _type_offset; 706 static int _slot_offset; 707 static int _modifiers_offset; 708 static int _trusted_final_offset; 709 static int _signature_offset; 710 static int _annotations_offset; 711 712 static void compute_offsets(); 713 714 public: 715 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 716 717 // Allocation 718 static Handle create(TRAPS); 719 720 // Accessors 721 static oop clazz(oop reflect); 722 static void set_clazz(oop reflect, oop value); 723 724 static oop name(oop field); 725 static void set_name(oop field, oop value); 726 727 static oop type(oop field); 728 static void set_type(oop field, oop value); 729 730 static int slot(oop reflect); 731 static void set_slot(oop reflect, int value); 732 733 static int modifiers(oop field); 734 static void set_modifiers(oop field, int value); 735 736 static void set_trusted_final(oop field); 737 738 static void set_signature(oop constructor, oop value); 739 static void set_annotations(oop constructor, oop value); 740 741 // Debugging 742 friend class JavaClasses; 743 }; 744 745 class java_lang_reflect_Parameter { 746 private: 747 // Note that to reduce dependencies on the JDK we compute these 748 // offsets at run-time. 749 static int _name_offset; 750 static int _modifiers_offset; 751 static int _index_offset; 752 static int _executable_offset; 753 754 static void compute_offsets(); 755 756 public: 757 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 758 759 // Allocation 760 static Handle create(TRAPS); 761 762 // Accessors 763 static oop name(oop field); 764 static void set_name(oop field, oop value); 765 766 static int index(oop reflect); 767 static void set_index(oop reflect, int value); 768 769 static int modifiers(oop reflect); 770 static void set_modifiers(oop reflect, int value); 771 772 static oop executable(oop constructor); 773 static void set_executable(oop constructor, oop value); 774 775 friend class JavaClasses; 776 }; 777 778 #define MODULE_INJECTED_FIELDS(macro) \ 779 macro(java_lang_Module, module_entry, intptr_signature, false) 780 781 class java_lang_Module { 782 private: 783 static int _loader_offset; 784 static int _name_offset; 785 static int _module_entry_offset; 786 787 static void compute_offsets(); 788 789 public: 790 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 791 792 // Allocation 793 static Handle create(Handle loader, Handle module_name, TRAPS); 794 795 // Testers 796 static bool is_instance(oop obj); 797 798 // Accessors 799 static oop loader(oop module); 800 static void set_loader(oop module, oop value); 801 802 static oop name(oop module); 803 static void set_name(oop module, oop value); 804 805 static ModuleEntry* module_entry(oop module); 806 static ModuleEntry* module_entry_raw(oop module); 807 static void set_module_entry(oop module, ModuleEntry* module_entry); 808 809 friend class JavaClasses; 810 }; 811 812 // Interface to jdk.internal.reflect.ConstantPool objects 813 class reflect_ConstantPool { 814 private: 815 // Note that to reduce dependencies on the JDK we compute these 816 // offsets at run-time. 817 static int _oop_offset; 818 819 static void compute_offsets(); 820 821 public: 822 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 823 824 // Allocation 825 static Handle create(TRAPS); 826 827 // Accessors 828 static void set_cp(oop reflect, ConstantPool* value); 829 static int oop_offset() { CHECK_INIT(_oop_offset); } 830 831 static ConstantPool* get_cp(oop reflect); 832 833 // Debugging 834 friend class JavaClasses; 835 }; 836 837 // Interface to jdk.internal.reflect.UnsafeStaticFieldAccessorImpl objects 838 class reflect_UnsafeStaticFieldAccessorImpl { 839 private: 840 static int _base_offset; 841 static void compute_offsets(); 842 843 public: 844 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 845 846 static int base_offset() { CHECK_INIT(_base_offset); } 847 848 // Debugging 849 friend class JavaClasses; 850 }; 851 852 // Interface to java.lang primitive type boxing objects: 853 // - java.lang.Boolean 854 // - java.lang.Character 855 // - java.lang.Float 856 // - java.lang.Double 857 // - java.lang.Byte 858 // - java.lang.Short 859 // - java.lang.Integer 860 // - java.lang.Long 861 862 // This could be separated out into 8 individual classes. 863 864 class java_lang_boxing_object: AllStatic { 865 private: 866 static int _value_offset; 867 static int _long_value_offset; 868 869 static void compute_offsets(); 870 static oop initialize_and_allocate(BasicType type, TRAPS); 871 public: 872 // Allocation. Returns a boxed value, or NULL for invalid type. 873 static oop create(BasicType type, jvalue* value, TRAPS); 874 // Accessors. Returns the basic type being boxed, or T_ILLEGAL for invalid oop. 875 static BasicType get_value(oop box, jvalue* value); 876 static BasicType set_value(oop box, jvalue* value); 877 static BasicType basic_type(oop box); 878 static bool is_instance(oop box) { return basic_type(box) != T_ILLEGAL; } 879 static bool is_instance(oop box, BasicType type) { return basic_type(box) == type; } 880 static void print(oop box, outputStream* st) { jvalue value; print(get_value(box, &value), &value, st); } 881 static void print(BasicType type, jvalue* value, outputStream* st); 882 883 static int value_offset(BasicType type) { 884 return is_double_word_type(type) ? _long_value_offset : _value_offset; 885 } 886 887 static void serialize_offsets(SerializeClosure* f); 888 889 // Debugging 890 friend class JavaClasses; 891 }; 892 893 894 895 // Interface to java.lang.ref.Reference objects 896 897 class java_lang_ref_Reference: AllStatic { 898 static int _referent_offset; 899 static int _queue_offset; 900 static int _next_offset; 901 static int _discovered_offset; 902 903 static bool _offsets_initialized; 904 905 public: 906 // Accessors 907 static inline oop weak_referent_no_keepalive(oop ref); 908 static inline oop phantom_referent_no_keepalive(oop ref); 909 static inline oop unknown_referent_no_keepalive(oop ref); 910 static inline void clear_referent(oop ref); 911 static inline HeapWord* referent_addr_raw(oop ref); 912 static inline oop next(oop ref); 913 static inline void set_next(oop ref, oop value); 914 static inline void set_next_raw(oop ref, oop value); 915 static inline HeapWord* next_addr_raw(oop ref); 916 static inline oop discovered(oop ref); 917 static inline void set_discovered(oop ref, oop value); 918 static inline void set_discovered_raw(oop ref, oop value); 919 static inline HeapWord* discovered_addr_raw(oop ref); 920 static bool is_referent_field(oop obj, ptrdiff_t offset); 921 static inline bool is_final(oop ref); 922 static inline bool is_phantom(oop ref); 923 924 static int referent_offset() { CHECK_INIT(_referent_offset); } 925 static int queue_offset() { CHECK_INIT(_queue_offset); } 926 static int next_offset() { CHECK_INIT(_next_offset); } 927 static int discovered_offset() { CHECK_INIT(_discovered_offset); } 928 929 static void compute_offsets(); 930 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 931 }; 932 933 934 // Interface to java.lang.ref.SoftReference objects 935 936 class java_lang_ref_SoftReference: public java_lang_ref_Reference { 937 static int _timestamp_offset; 938 static int _static_clock_offset; 939 940 public: 941 // Accessors 942 static jlong timestamp(oop ref); 943 944 // Accessors for statics 945 static jlong clock(); 946 static void set_clock(jlong value); 947 948 static void compute_offsets(); 949 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 950 }; 951 952 // Interface to java.lang.invoke.MethodHandle objects 953 954 class java_lang_invoke_MethodHandle: AllStatic { 955 friend class JavaClasses; 956 957 private: 958 static int _type_offset; // the MethodType of this MH 959 static int _form_offset; // the LambdaForm of this MH 960 961 static void compute_offsets(); 962 963 public: 964 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 965 966 // Accessors 967 static oop type(oop mh); 968 static void set_type(oop mh, oop mtype); 969 970 static oop form(oop mh); 971 static void set_form(oop mh, oop lform); 972 973 // Testers 974 static bool is_subclass(Klass* klass) { 975 return klass->is_subclass_of(vmClasses::MethodHandle_klass()); 976 } 977 static bool is_instance(oop obj); 978 979 // Accessors for code generation: 980 static int type_offset() { CHECK_INIT(_type_offset); } 981 static int form_offset() { CHECK_INIT(_form_offset); } 982 }; 983 984 // Interface to java.lang.invoke.DirectMethodHandle objects 985 986 class java_lang_invoke_DirectMethodHandle: AllStatic { 987 friend class JavaClasses; 988 989 private: 990 static int _member_offset; // the MemberName of this DMH 991 992 static void compute_offsets(); 993 994 public: 995 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 996 997 // Accessors 998 static oop member(oop mh); 999 1000 // Testers 1001 static bool is_subclass(Klass* klass) { 1002 return klass->is_subclass_of(vmClasses::DirectMethodHandle_klass()); 1003 } 1004 static bool is_instance(oop obj); 1005 1006 // Accessors for code generation: 1007 static int member_offset() { CHECK_INIT(_member_offset); } 1008 }; 1009 1010 // Interface to java.lang.invoke.LambdaForm objects 1011 // (These are a private interface for managing adapter code generation.) 1012 1013 class java_lang_invoke_LambdaForm: AllStatic { 1014 friend class JavaClasses; 1015 1016 private: 1017 static int _vmentry_offset; // type is MemberName 1018 1019 static void compute_offsets(); 1020 1021 public: 1022 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1023 1024 // Accessors 1025 static oop vmentry(oop lform); 1026 1027 // Testers 1028 static bool is_subclass(Klass* klass) { 1029 return vmClasses::LambdaForm_klass() != NULL && 1030 klass->is_subclass_of(vmClasses::LambdaForm_klass()); 1031 } 1032 static bool is_instance(oop obj); 1033 1034 // Accessors for code generation: 1035 static int vmentry_offset() { CHECK_INIT(_vmentry_offset); } 1036 }; 1037 1038 // Interface to java.lang.invoke.NativeEntryPoint objects 1039 // (These are a private interface for managing adapter code generation.) 1040 1041 class jdk_internal_invoke_NativeEntryPoint: AllStatic { 1042 friend class JavaClasses; 1043 1044 private: 1045 static int _shadow_space_offset; 1046 static int _argMoves_offset; 1047 static int _returnMoves_offset; 1048 static int _need_transition_offset; 1049 static int _method_type_offset; 1050 static int _name_offset; 1051 1052 static void compute_offsets(); 1053 1054 public: 1055 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1056 1057 // Accessors 1058 static jint shadow_space(oop entry); 1059 static oop argMoves(oop entry); 1060 static oop returnMoves(oop entry); 1061 static jboolean need_transition(oop entry); 1062 static oop method_type(oop entry); 1063 static oop name(oop entry); 1064 1065 // Testers 1066 static bool is_subclass(Klass* klass) { 1067 return vmClasses::NativeEntryPoint_klass() != NULL && 1068 klass->is_subclass_of(vmClasses::NativeEntryPoint_klass()); 1069 } 1070 static bool is_instance(oop obj); 1071 1072 // Accessors for code generation: 1073 static int shadow_space_offset_in_bytes() { return _shadow_space_offset; } 1074 static int argMoves_offset_in_bytes() { return _argMoves_offset; } 1075 static int returnMoves_offset_in_bytes() { return _returnMoves_offset; } 1076 static int need_transition_offset_in_bytes() { return _need_transition_offset; } 1077 static int method_type_offset_in_bytes() { return _method_type_offset; } 1078 static int name_offset_in_bytes() { return _name_offset; } 1079 }; 1080 1081 // Interface to java.lang.invoke.MemberName objects 1082 // (These are a private interface for Java code to query the class hierarchy.) 1083 1084 #define RESOLVEDMETHOD_INJECTED_FIELDS(macro) \ 1085 macro(java_lang_invoke_ResolvedMethodName, vmholder, object_signature, false) \ 1086 macro(java_lang_invoke_ResolvedMethodName, vmtarget, intptr_signature, false) 1087 1088 class java_lang_invoke_ResolvedMethodName : AllStatic { 1089 friend class JavaClasses; 1090 1091 static int _vmtarget_offset; 1092 static int _vmholder_offset; 1093 1094 static void compute_offsets(); 1095 public: 1096 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1097 1098 static int vmtarget_offset() { CHECK_INIT(_vmtarget_offset); } 1099 1100 static Method* vmtarget(oop resolved_method); 1101 static void set_vmtarget(oop resolved_method, Method* method); 1102 1103 static void set_vmholder(oop resolved_method, oop holder); 1104 1105 // find or create resolved member name 1106 static oop find_resolved_method(const methodHandle& m, TRAPS); 1107 1108 static bool is_instance(oop resolved_method); 1109 }; 1110 1111 1112 #define MEMBERNAME_INJECTED_FIELDS(macro) \ 1113 macro(java_lang_invoke_MemberName, vmindex, intptr_signature, false) 1114 1115 1116 class java_lang_invoke_MemberName: AllStatic { 1117 friend class JavaClasses; 1118 1119 private: 1120 // From java.lang.invoke.MemberName: 1121 // private Class<?> clazz; // class in which the method is defined 1122 // private String name; // may be null if not yet materialized 1123 // private Object type; // may be null if not yet materialized 1124 // private int flags; // modifier bits; see reflect.Modifier 1125 // private ResolvedMethodName method; // holds VM-specific target value 1126 // private intptr_t vmindex; // member index within class or interface 1127 static int _clazz_offset; 1128 static int _name_offset; 1129 static int _type_offset; 1130 static int _flags_offset; 1131 static int _method_offset; 1132 static int _vmindex_offset; 1133 1134 static void compute_offsets(); 1135 1136 public: 1137 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1138 // Accessors 1139 static oop clazz(oop mname); 1140 static void set_clazz(oop mname, oop clazz); 1141 1142 static oop type(oop mname); 1143 static void set_type(oop mname, oop type); 1144 1145 static oop name(oop mname); 1146 static void set_name(oop mname, oop name); 1147 1148 static int flags(oop mname); 1149 static void set_flags(oop mname, int flags); 1150 1151 // Link through ResolvedMethodName field to get Method* 1152 static Method* vmtarget(oop mname); 1153 static void set_method(oop mname, oop method); 1154 1155 static intptr_t vmindex(oop mname); 1156 static void set_vmindex(oop mname, intptr_t index); 1157 1158 // Testers 1159 static bool is_subclass(Klass* klass) { 1160 return klass->is_subclass_of(vmClasses::MemberName_klass()); 1161 } 1162 static bool is_instance(oop obj); 1163 1164 static bool is_method(oop obj); 1165 1166 // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants): 1167 enum { 1168 MN_IS_METHOD = 0x00010000, // method (not constructor) 1169 MN_IS_CONSTRUCTOR = 0x00020000, // constructor 1170 MN_IS_FIELD = 0x00040000, // field 1171 MN_IS_TYPE = 0x00080000, // nested type 1172 MN_CALLER_SENSITIVE = 0x00100000, // @CallerSensitive annotation detected 1173 MN_TRUSTED_FINAL = 0x00200000, // trusted final field 1174 MN_REFERENCE_KIND_SHIFT = 24, // refKind 1175 MN_REFERENCE_KIND_MASK = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT, 1176 // The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers: 1177 MN_SEARCH_SUPERCLASSES = 0x00100000, // walk super classes 1178 MN_SEARCH_INTERFACES = 0x00200000, // walk implemented interfaces 1179 MN_NESTMATE_CLASS = 0x00000001, 1180 MN_HIDDEN_CLASS = 0x00000002, 1181 MN_STRONG_LOADER_LINK = 0x00000004, 1182 MN_ACCESS_VM_ANNOTATIONS = 0x00000008, 1183 // Lookup modes 1184 MN_MODULE_MODE = 0x00000010, 1185 MN_UNCONDITIONAL_MODE = 0x00000020, 1186 MN_TRUSTED_MODE = -1 1187 }; 1188 1189 // Accessors for code generation: 1190 static int clazz_offset() { CHECK_INIT(_clazz_offset); } 1191 static int type_offset() { CHECK_INIT(_type_offset); } 1192 static int flags_offset() { CHECK_INIT(_flags_offset); } 1193 static int method_offset() { CHECK_INIT(_method_offset); } 1194 static int vmindex_offset() { CHECK_INIT(_vmindex_offset); } 1195 }; 1196 1197 1198 // Interface to java.lang.invoke.MethodType objects 1199 1200 class java_lang_invoke_MethodType: AllStatic { 1201 friend class JavaClasses; 1202 1203 private: 1204 static int _rtype_offset; 1205 static int _ptypes_offset; 1206 1207 static void compute_offsets(); 1208 1209 public: 1210 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1211 // Accessors 1212 static oop rtype(oop mt); 1213 static objArrayOop ptypes(oop mt); 1214 1215 static oop ptype(oop mt, int index); 1216 static int ptype_count(oop mt); 1217 1218 static int ptype_slot_count(oop mt); // extra counts for long/double 1219 static int rtype_slot_count(oop mt); // extra counts for long/double 1220 1221 static Symbol* as_signature(oop mt, bool intern_if_not_found); 1222 static void print_signature(oop mt, outputStream* st); 1223 1224 static bool is_instance(oop obj); 1225 1226 static bool equals(oop mt1, oop mt2); 1227 1228 // Accessors for code generation: 1229 static int rtype_offset() { CHECK_INIT(_rtype_offset); } 1230 static int ptypes_offset() { CHECK_INIT(_ptypes_offset); } 1231 }; 1232 1233 1234 // Interface to java.lang.invoke.CallSite objects 1235 1236 class java_lang_invoke_CallSite: AllStatic { 1237 friend class JavaClasses; 1238 1239 private: 1240 static int _target_offset; 1241 static int _context_offset; 1242 1243 static void compute_offsets(); 1244 1245 public: 1246 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1247 // Accessors 1248 static oop target( oop site); 1249 static void set_target( oop site, oop target); 1250 static void set_target_volatile( oop site, oop target); 1251 1252 static oop context_no_keepalive(oop site); 1253 1254 // Testers 1255 static bool is_subclass(Klass* klass) { 1256 return klass->is_subclass_of(vmClasses::CallSite_klass()); 1257 } 1258 static bool is_instance(oop obj); 1259 1260 // Accessors for code generation: 1261 static int target_offset() { CHECK_INIT(_target_offset); } 1262 static int context_offset() { CHECK_INIT(_context_offset); } 1263 }; 1264 1265 // Interface to java.lang.invoke.ConstantCallSite objects 1266 1267 class java_lang_invoke_ConstantCallSite: AllStatic { 1268 friend class JavaClasses; 1269 1270 private: 1271 static int _is_frozen_offset; 1272 1273 static void compute_offsets(); 1274 1275 public: 1276 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1277 // Accessors 1278 static jboolean is_frozen(oop site); 1279 1280 // Testers 1281 static bool is_subclass(Klass* klass) { 1282 return klass->is_subclass_of(vmClasses::ConstantCallSite_klass()); 1283 } 1284 static bool is_instance(oop obj); 1285 }; 1286 1287 // Interface to java.lang.invoke.MethodHandleNatives$CallSiteContext objects 1288 1289 #define CALLSITECONTEXT_INJECTED_FIELDS(macro) \ 1290 macro(java_lang_invoke_MethodHandleNatives_CallSiteContext, vmdependencies, intptr_signature, false) \ 1291 macro(java_lang_invoke_MethodHandleNatives_CallSiteContext, last_cleanup, long_signature, false) 1292 1293 class DependencyContext; 1294 1295 class java_lang_invoke_MethodHandleNatives_CallSiteContext : AllStatic { 1296 friend class JavaClasses; 1297 1298 private: 1299 static int _vmdependencies_offset; 1300 static int _last_cleanup_offset; 1301 1302 static void compute_offsets(); 1303 1304 public: 1305 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1306 // Accessors 1307 static DependencyContext vmdependencies(oop context); 1308 1309 // Testers 1310 static bool is_subclass(Klass* klass) { 1311 return klass->is_subclass_of(vmClasses::Context_klass()); 1312 } 1313 static bool is_instance(oop obj); 1314 }; 1315 1316 // Interface to java.security.AccessControlContext objects 1317 1318 class java_security_AccessControlContext: AllStatic { 1319 private: 1320 // Note that for this class the layout changed between JDK1.2 and JDK1.3, 1321 // so we compute the offsets at startup rather than hard-wiring them. 1322 static int _context_offset; 1323 static int _privilegedContext_offset; 1324 static int _isPrivileged_offset; 1325 static int _isAuthorized_offset; 1326 1327 static void compute_offsets(); 1328 public: 1329 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1330 static oop create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS); 1331 1332 // Debugging/initialization 1333 friend class JavaClasses; 1334 }; 1335 1336 1337 // Interface to java.lang.ClassLoader objects 1338 1339 #define CLASSLOADER_INJECTED_FIELDS(macro) \ 1340 macro(java_lang_ClassLoader, loader_data, intptr_signature, false) 1341 1342 class java_lang_ClassLoader : AllStatic { 1343 private: 1344 static int _loader_data_offset; 1345 static int _parent_offset; 1346 static int _parallelCapable_offset; 1347 static int _name_offset; 1348 static int _nameAndId_offset; 1349 static int _unnamedModule_offset; 1350 1351 static void compute_offsets(); 1352 1353 public: 1354 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1355 1356 static ClassLoaderData* loader_data_acquire(oop loader); 1357 static ClassLoaderData* loader_data(oop loader); 1358 static void release_set_loader_data(oop loader, ClassLoaderData* new_data); 1359 1360 static oop parent(oop loader); 1361 static oop name(oop loader); 1362 static oop nameAndId(oop loader); 1363 static bool isAncestor(oop loader, oop cl); 1364 1365 // Support for parallelCapable field 1366 static bool parallelCapable(oop the_class_mirror); 1367 1368 static bool is_trusted_loader(oop loader); 1369 1370 // Return true if this is one of the class loaders associated with 1371 // the generated bytecodes for reflection. 1372 static bool is_reflection_class_loader(oop loader); 1373 1374 // Fix for 4474172 1375 static oop non_reflection_class_loader(oop loader); 1376 1377 // Testers 1378 static bool is_subclass(Klass* klass) { 1379 return klass->is_subclass_of(vmClasses::ClassLoader_klass()); 1380 } 1381 static bool is_instance(oop obj); 1382 1383 static oop unnamedModule(oop loader); 1384 1385 // Debugging 1386 friend class JavaClasses; 1387 }; 1388 1389 1390 // Interface to java.lang.System objects 1391 1392 class java_lang_System : AllStatic { 1393 private: 1394 static int _static_in_offset; 1395 static int _static_out_offset; 1396 static int _static_err_offset; 1397 static int _static_security_offset; 1398 static int _static_allow_security_offset; 1399 static int _static_never_offset; 1400 1401 public: 1402 static int in_offset() { CHECK_INIT(_static_in_offset); } 1403 static int out_offset() { CHECK_INIT(_static_out_offset); } 1404 static int err_offset() { CHECK_INIT(_static_err_offset); } 1405 static bool allow_security_manager(); 1406 static bool has_security_manager(); 1407 1408 static void compute_offsets(); 1409 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1410 1411 // Debugging 1412 friend class JavaClasses; 1413 }; 1414 1415 1416 // Interface to java.lang.StackTraceElement objects 1417 1418 class java_lang_StackTraceElement: AllStatic { 1419 private: 1420 static int _declaringClassObject_offset; 1421 static int _classLoaderName_offset; 1422 static int _moduleName_offset; 1423 static int _moduleVersion_offset; 1424 static int _declaringClass_offset; 1425 static int _methodName_offset; 1426 static int _fileName_offset; 1427 static int _lineNumber_offset; 1428 1429 // Setters 1430 static void set_classLoaderName(oop element, oop value); 1431 static void set_moduleName(oop element, oop value); 1432 static void set_moduleVersion(oop element, oop value); 1433 static void set_declaringClass(oop element, oop value); 1434 static void set_methodName(oop element, oop value); 1435 static void set_fileName(oop element, oop value); 1436 static void set_lineNumber(oop element, int value); 1437 static void set_declaringClassObject(oop element, oop value); 1438 1439 static void decode_file_and_line(Handle java_mirror, InstanceKlass* holder, int version, 1440 const methodHandle& method, int bci, 1441 Symbol*& source, oop& source_file, int& line_number, TRAPS); 1442 1443 public: 1444 // Create an instance of StackTraceElement 1445 static oop create(const methodHandle& method, int bci, TRAPS); 1446 1447 static void fill_in(Handle element, InstanceKlass* holder, const methodHandle& method, 1448 int version, int bci, Symbol* name, TRAPS); 1449 1450 static void compute_offsets(); 1451 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1452 1453 #if INCLUDE_JVMCI 1454 static void decode(const methodHandle& method, int bci, Symbol*& fileName, int& lineNumber, TRAPS); 1455 #endif 1456 1457 // Debugging 1458 friend class JavaClasses; 1459 }; 1460 1461 1462 class Backtrace: AllStatic { 1463 public: 1464 // Helper backtrace functions to store bci|version together. 1465 static int merge_bci_and_version(int bci, int version); 1466 static int merge_mid_and_cpref(int mid, int cpref); 1467 static int bci_at(unsigned int merged); 1468 static int version_at(unsigned int merged); 1469 static int mid_at(unsigned int merged); 1470 static int cpref_at(unsigned int merged); 1471 static int get_line_number(Method* method, int bci); 1472 static Symbol* get_source_file_name(InstanceKlass* holder, int version); 1473 1474 // Debugging 1475 friend class JavaClasses; 1476 }; 1477 1478 // Interface to java.lang.StackFrameInfo objects 1479 1480 #define STACKFRAMEINFO_INJECTED_FIELDS(macro) \ 1481 macro(java_lang_StackFrameInfo, version, short_signature, false) 1482 1483 class java_lang_StackFrameInfo: AllStatic { 1484 private: 1485 static int _memberName_offset; 1486 static int _bci_offset; 1487 static int _version_offset; 1488 1489 static Method* get_method(Handle stackFrame, InstanceKlass* holder, TRAPS); 1490 1491 public: 1492 // Setters 1493 static void set_method_and_bci(Handle stackFrame, const methodHandle& method, int bci, TRAPS); 1494 static void set_bci(oop info, int value); 1495 1496 static void set_version(oop info, short value); 1497 1498 static void compute_offsets(); 1499 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1500 1501 static void to_stack_trace_element(Handle stackFrame, Handle stack_trace_element, TRAPS); 1502 1503 // Debugging 1504 friend class JavaClasses; 1505 }; 1506 1507 class java_lang_LiveStackFrameInfo: AllStatic { 1508 private: 1509 static int _monitors_offset; 1510 static int _locals_offset; 1511 static int _operands_offset; 1512 static int _mode_offset; 1513 1514 public: 1515 static void set_monitors(oop info, oop value); 1516 static void set_locals(oop info, oop value); 1517 static void set_operands(oop info, oop value); 1518 static void set_mode(oop info, int value); 1519 1520 static void compute_offsets(); 1521 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1522 1523 // Debugging 1524 friend class JavaClasses; 1525 }; 1526 1527 // Interface to java.lang.reflect.RecordComponent objects 1528 1529 class java_lang_reflect_RecordComponent: AllStatic { 1530 private: 1531 static int _clazz_offset; 1532 static int _name_offset; 1533 static int _type_offset; 1534 static int _accessor_offset; 1535 static int _signature_offset; 1536 static int _annotations_offset; 1537 static int _typeAnnotations_offset; 1538 1539 // Setters 1540 static void set_clazz(oop element, oop value); 1541 static void set_name(oop element, oop value); 1542 static void set_type(oop element, oop value); 1543 static void set_accessor(oop element, oop value); 1544 static void set_signature(oop element, oop value); 1545 static void set_annotations(oop element, oop value); 1546 static void set_typeAnnotations(oop element, oop value); 1547 1548 public: 1549 // Create an instance of RecordComponent 1550 static oop create(InstanceKlass* holder, RecordComponent* component, TRAPS); 1551 1552 static void compute_offsets(); 1553 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1554 1555 // Debugging 1556 friend class JavaClasses; 1557 }; 1558 1559 1560 // Interface to java.lang.AssertionStatusDirectives objects 1561 1562 class java_lang_AssertionStatusDirectives: AllStatic { 1563 private: 1564 static int _classes_offset; 1565 static int _classEnabled_offset; 1566 static int _packages_offset; 1567 static int _packageEnabled_offset; 1568 static int _deflt_offset; 1569 1570 public: 1571 // Setters 1572 static void set_classes(oop obj, oop val); 1573 static void set_classEnabled(oop obj, oop val); 1574 static void set_packages(oop obj, oop val); 1575 static void set_packageEnabled(oop obj, oop val); 1576 static void set_deflt(oop obj, bool val); 1577 1578 static void compute_offsets(); 1579 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1580 1581 // Debugging 1582 friend class JavaClasses; 1583 }; 1584 1585 1586 class java_util_concurrent_locks_AbstractOwnableSynchronizer : AllStatic { 1587 private: 1588 static int _owner_offset; 1589 public: 1590 static void compute_offsets(); 1591 static oop get_owner_threadObj(oop obj); 1592 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1593 }; 1594 1595 // Interface to jdk.internal.misc.UnsafeConsants 1596 1597 class jdk_internal_misc_UnsafeConstants : AllStatic { 1598 public: 1599 static void set_unsafe_constants(); 1600 static void compute_offsets() { } 1601 static void serialize_offsets(SerializeClosure* f) { } 1602 }; 1603 1604 // Interface to jdk.internal.vm.vector.VectorSupport.VectorPayload objects 1605 1606 class vector_VectorPayload : AllStatic { 1607 private: 1608 static int _payload_offset; 1609 public: 1610 static void set_payload(oop o, oop val); 1611 1612 static void compute_offsets(); 1613 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1614 1615 // Testers 1616 static bool is_subclass(Klass* klass) { 1617 return klass->is_subclass_of(vmClasses::vector_VectorPayload_klass()); 1618 } 1619 static bool is_instance(oop obj); 1620 }; 1621 1622 class java_lang_Integer : AllStatic { 1623 public: 1624 static jint value(oop obj); 1625 }; 1626 1627 class java_lang_Long : AllStatic { 1628 public: 1629 static jlong value(oop obj); 1630 }; 1631 1632 class java_lang_Character : AllStatic { 1633 public: 1634 static jchar value(oop obj); 1635 }; 1636 1637 class java_lang_Short : AllStatic { 1638 public: 1639 static jshort value(oop obj); 1640 }; 1641 1642 class java_lang_Byte : AllStatic { 1643 public: 1644 static jbyte value(oop obj); 1645 }; 1646 1647 class java_lang_Boolean : AllStatic { 1648 private: 1649 static int _static_TRUE_offset; 1650 static int _static_FALSE_offset; 1651 public: 1652 static Symbol* symbol(); 1653 static void compute_offsets(InstanceKlass* k); 1654 static oop get_TRUE(InstanceKlass *k); 1655 static oop get_FALSE(InstanceKlass *k); 1656 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1657 static jboolean value(oop obj); 1658 }; 1659 1660 class java_lang_Integer_IntegerCache : AllStatic { 1661 private: 1662 static int _static_cache_offset; 1663 public: 1664 static Symbol* symbol(); 1665 static void compute_offsets(InstanceKlass* k); 1666 static objArrayOop cache(InstanceKlass *k); 1667 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1668 }; 1669 1670 class java_lang_Long_LongCache : AllStatic { 1671 private: 1672 static int _static_cache_offset; 1673 public: 1674 static Symbol* symbol(); 1675 static void compute_offsets(InstanceKlass* k); 1676 static objArrayOop cache(InstanceKlass *k); 1677 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1678 }; 1679 1680 class java_lang_Character_CharacterCache : AllStatic { 1681 private: 1682 static int _static_cache_offset; 1683 public: 1684 static Symbol* symbol(); 1685 static void compute_offsets(InstanceKlass* k); 1686 static objArrayOop cache(InstanceKlass *k); 1687 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1688 }; 1689 1690 class java_lang_Short_ShortCache : AllStatic { 1691 private: 1692 static int _static_cache_offset; 1693 public: 1694 static Symbol* symbol(); 1695 static void compute_offsets(InstanceKlass* k); 1696 static objArrayOop cache(InstanceKlass *k); 1697 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1698 }; 1699 1700 class java_lang_Byte_ByteCache : AllStatic { 1701 private: 1702 static int _static_cache_offset; 1703 public: 1704 static Symbol* symbol(); 1705 static void compute_offsets(InstanceKlass* k); 1706 static objArrayOop cache(InstanceKlass *k); 1707 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1708 }; 1709 1710 1711 // Interface to java.lang.InternalError objects 1712 1713 #define INTERNALERROR_INJECTED_FIELDS(macro) \ 1714 macro(java_lang_InternalError, during_unsafe_access, bool_signature, false) 1715 1716 class java_lang_InternalError : AllStatic { 1717 private: 1718 static int _during_unsafe_access_offset; 1719 public: 1720 static jboolean during_unsafe_access(oop internal_error); 1721 static void set_during_unsafe_access(oop internal_error); 1722 static void compute_offsets(); 1723 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1724 }; 1725 1726 // Use to declare fields that need to be injected into Java classes 1727 // for the JVM to use. The name_index and signature_index are 1728 // declared in vmSymbols. The may_be_java flag is used to declare 1729 // fields that might already exist in Java but should be injected if 1730 // they don't. Otherwise the field is unconditionally injected and 1731 // the JVM uses the injected one. This is to ensure that name 1732 // collisions don't occur. In general may_be_java should be false 1733 // unless there's a good reason. 1734 1735 class InjectedField { 1736 public: 1737 const vmClassID klass_id; 1738 const vmSymbolID name_index; 1739 const vmSymbolID signature_index; 1740 const bool may_be_java; 1741 1742 1743 Klass* klass() const { return vmClasses::klass_at(klass_id); } 1744 Symbol* name() const { return lookup_symbol(name_index); } 1745 Symbol* signature() const { return lookup_symbol(signature_index); } 1746 1747 int compute_offset(); 1748 1749 // Find the Symbol for this index 1750 static Symbol* lookup_symbol(vmSymbolID symbol_index) { 1751 return Symbol::vm_symbol_at(symbol_index); 1752 } 1753 }; 1754 1755 #define DECLARE_INJECTED_FIELD_ENUM(klass, name, signature, may_be_java) \ 1756 klass##_##name##_enum, 1757 1758 #define ALL_INJECTED_FIELDS(macro) \ 1759 STRING_INJECTED_FIELDS(macro) \ 1760 CLASS_INJECTED_FIELDS(macro) \ 1761 CLASSLOADER_INJECTED_FIELDS(macro) \ 1762 RESOLVEDMETHOD_INJECTED_FIELDS(macro) \ 1763 MEMBERNAME_INJECTED_FIELDS(macro) \ 1764 CALLSITECONTEXT_INJECTED_FIELDS(macro) \ 1765 STACKFRAMEINFO_INJECTED_FIELDS(macro) \ 1766 MODULE_INJECTED_FIELDS(macro) \ 1767 INTERNALERROR_INJECTED_FIELDS(macro) 1768 1769 1770 // Interface to hard-coded offset checking 1771 1772 class JavaClasses : AllStatic { 1773 private: 1774 1775 static InjectedField _injected_fields[]; 1776 1777 static bool check_offset(const char *klass_name, int offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0; 1778 public: 1779 enum InjectedFieldID { 1780 ALL_INJECTED_FIELDS(DECLARE_INJECTED_FIELD_ENUM) 1781 MAX_enum 1782 }; 1783 1784 static int compute_injected_offset(InjectedFieldID id); 1785 1786 static void compute_offsets(); 1787 static void check_offsets() PRODUCT_RETURN; 1788 static void serialize_offsets(SerializeClosure* soc) NOT_CDS_RETURN; 1789 static InjectedField* get_injected(Symbol* class_name, int* field_count); 1790 static bool is_supported_for_archiving(oop obj) NOT_CDS_JAVA_HEAP_RETURN_(false); 1791 }; 1792 1793 #undef DECLARE_INJECTED_FIELD_ENUM 1794 1795 #undef CHECK_INIT 1796 #endif // SHARE_CLASSFILE_JAVACLASSES_HPP