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