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