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