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