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