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