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