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