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