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