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