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