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