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