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