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