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