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