1 /* 2 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_CLASSFILE_JAVACLASSES_HPP 26 #define SHARE_CLASSFILE_JAVACLASSES_HPP 27 28 #include "classfile/systemDictionary.hpp" 29 #include "jvmtifiles/jvmti.h" 30 #include "oops/oop.hpp" 31 #include "runtime/os.hpp" 32 33 // Interface for manipulating the basic Java classes. 34 // 35 // All dependencies on layout of actual Java classes should be kept here. 36 // If the layout of any of the classes above changes the offsets must be adjusted. 37 // 38 // For most classes we hardwire the offsets for performance reasons. In certain 39 // cases (e.g. java.security.AccessControlContext) we compute the offsets at 40 // startup since the layout here differs between JDK1.2 and JDK1.3. 41 // 42 // Note that fields (static and non-static) are arranged with oops before non-oops 43 // on a per class basis. The offsets below have to reflect this ordering. 44 // 45 // When editing the layouts please update the check_offset verification code 46 // correspondingly. The names in the enums must be identical to the actual field 47 // names in order for the verification code to work. 48 49 #define BASIC_JAVA_CLASSES_DO_PART1(f) \ 50 f(java_lang_Class) \ 51 f(java_lang_String) \ 52 //end 53 54 #define BASIC_JAVA_CLASSES_DO_PART2(f) \ 55 f(java_lang_System) \ 56 f(java_lang_ClassLoader) \ 57 f(java_lang_Throwable) \ 58 f(java_lang_Thread) \ 59 f(java_lang_ThreadGroup) \ 60 f(java_lang_AssertionStatusDirectives) \ 61 f(java_lang_ref_SoftReference) \ 62 f(java_lang_invoke_MethodHandle) \ 63 f(java_lang_invoke_DirectMethodHandle) \ 64 f(java_lang_invoke_MemberName) \ 65 f(java_lang_invoke_ResolvedMethodName) \ 66 f(java_lang_invoke_LambdaForm) \ 67 f(java_lang_invoke_MethodType) \ 68 f(java_lang_invoke_CallSite) \ 69 f(java_lang_invoke_MethodHandleNatives_CallSiteContext) \ 70 f(java_security_AccessControlContext) \ 71 f(java_lang_reflect_AccessibleObject) \ 72 f(java_lang_reflect_Method) \ 73 f(java_lang_reflect_Constructor) \ 74 f(java_lang_reflect_Field) \ 75 f(java_nio_Buffer) \ 76 f(reflect_ConstantPool) \ 77 f(reflect_UnsafeStaticFieldAccessorImpl) \ 78 f(java_lang_reflect_Parameter) \ 79 f(java_lang_Module) \ 80 f(java_lang_StackTraceElement) \ 81 f(java_lang_StackFrameInfo) \ 82 f(java_lang_LiveStackFrameInfo) \ 83 f(java_util_concurrent_locks_AbstractOwnableSynchronizer) \ 84 f(jdk_internal_misc_UnsafeConstants) \ 85 //end 86 87 #define BASIC_JAVA_CLASSES_DO(f) \ 88 BASIC_JAVA_CLASSES_DO_PART1(f) \ 89 BASIC_JAVA_CLASSES_DO_PART2(f) 90 91 // Interface to java.lang.String objects 92 93 class java_lang_String : AllStatic { 94 private: 95 static int value_offset; 96 static int hash_offset; 97 static int hashIsZero_offset; 98 static int coder_offset; 99 100 static bool initialized; 101 102 static Handle basic_create(int length, bool byte_arr, TRAPS); 103 104 static inline void set_coder(oop string, jbyte coder); 105 106 public: 107 108 // Coders 109 enum Coder { 110 CODER_LATIN1 = 0, 111 CODER_UTF16 = 1 112 }; 113 114 static void compute_offsets(); 115 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 116 117 // Instance creation 118 static Handle create_from_unicode(const jchar* unicode, int len, TRAPS); 119 static oop create_oop_from_unicode(const jchar* unicode, int len, TRAPS); 120 static Handle create_from_str(const char* utf8_str, TRAPS); 121 static oop create_oop_from_str(const char* utf8_str, TRAPS); 122 static Handle create_from_symbol(Symbol* symbol, TRAPS); 123 static Handle create_from_platform_dependent_str(const char* str, TRAPS); 124 static Handle char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS); 125 126 static void set_compact_strings(bool value); 127 128 static int value_offset_in_bytes() { 129 assert(initialized && (value_offset > 0), "Must be initialized"); 130 return value_offset; 131 } 132 static int hash_offset_in_bytes() { 133 assert(initialized && (hash_offset > 0), "Must be initialized"); 134 return hash_offset; 135 } 136 static int hashIsZero_offset_in_bytes() { 137 assert(initialized && (hashIsZero_offset > 0), "Must be initialized"); 138 return hashIsZero_offset; 139 } 140 static int coder_offset_in_bytes() { 141 assert(initialized && (coder_offset > 0), "Must be initialized"); 142 return coder_offset; 143 } 144 145 static inline void set_value_raw(oop string, typeArrayOop buffer); 146 static inline void set_value(oop string, typeArrayOop buffer); 147 148 // Accessors 149 static inline typeArrayOop value(oop java_string); 150 static inline typeArrayOop value_no_keepalive(oop java_string); 151 static inline bool hash_is_set(oop string); 152 static inline bool is_latin1(oop java_string); 153 static inline int length(oop java_string); 154 static inline int length(oop java_string, typeArrayOop string_value); 155 static int utf8_length(oop java_string); 156 static int utf8_length(oop java_string, typeArrayOop string_value); 157 158 // String converters 159 static char* as_utf8_string(oop java_string); 160 static char* as_utf8_string(oop java_string, char* buf, int buflen); 161 static char* as_utf8_string(oop java_string, int start, int len); 162 static char* as_utf8_string(oop java_string, typeArrayOop value, char* buf, int buflen); 163 static char* as_utf8_string(oop java_string, typeArrayOop value, int start, int len, char* buf, int buflen); 164 static char* as_platform_dependent_str(Handle java_string, TRAPS); 165 static jchar* as_unicode_string(oop java_string, int& length, TRAPS); 166 // produce an ascii string with all other values quoted using \u#### 167 static char* as_quoted_ascii(oop java_string); 168 169 // Compute the hash value for a java.lang.String object which would 170 // contain the characters passed in. 171 // 172 // As the hash value used by the String object itself, in 173 // String.hashCode(). This value is normally calculated in Java code 174 // in the String.hashCode method(), but is precomputed for String 175 // objects in the shared archive file. 176 // hash P(31) from Kernighan & Ritchie 177 // 178 // For this reason, THIS ALGORITHM MUST MATCH String.hashCode(). 179 static unsigned int hash_code(const jchar* s, int len) { 180 unsigned int h = 0; 181 while (len-- > 0) { 182 h = 31*h + (unsigned int) *s; 183 s++; 184 } 185 return h; 186 } 187 188 static unsigned int hash_code(const jbyte* s, int len) { 189 unsigned int h = 0; 190 while (len-- > 0) { 191 h = 31*h + (((unsigned int) *s) & 0xFF); 192 s++; 193 } 194 return h; 195 } 196 197 static unsigned int hash_code(oop java_string); 198 199 static bool equals(oop java_string, const jchar* chars, int len); 200 static bool equals(oop str1, oop str2); 201 static inline bool value_equals(typeArrayOop str_value1, typeArrayOop str_value2); 202 203 // Conversion between '.' and '/' formats 204 static Handle externalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '/', '.', THREAD); } 205 static Handle internalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '.', '/', THREAD); } 206 207 // Conversion 208 static Symbol* as_symbol(oop java_string, TRAPS); 209 static Symbol* as_symbol_or_null(oop java_string); 210 211 // Testers 212 static bool is_instance(oop obj); 213 static inline bool is_instance_inlined(oop obj); 214 215 // Debugging 216 static void print(oop java_string, outputStream* st); 217 friend class JavaClasses; 218 friend class StringTable; 219 }; 220 221 222 // Interface to java.lang.Class objects 223 224 #define CLASS_INJECTED_FIELDS(macro) \ 225 macro(java_lang_Class, klass, intptr_signature, false) \ 226 macro(java_lang_Class, array_klass, intptr_signature, false) \ 227 macro(java_lang_Class, oop_size, int_signature, false) \ 228 macro(java_lang_Class, static_oop_field_count, int_signature, false) \ 229 macro(java_lang_Class, protection_domain, object_signature, false) \ 230 macro(java_lang_Class, signers, object_signature, false) \ 231 macro(java_lang_Class, source_file, object_signature, false) \ 232 233 class java_lang_Class : AllStatic { 234 friend class VMStructs; 235 friend class JVMCIVMStructs; 236 237 private: 238 // The fake offsets are added by the class loader when java.lang.Class is loaded 239 240 static int _klass_offset; 241 static int _array_klass_offset; 242 243 static int _oop_size_offset; 244 static int _static_oop_field_count_offset; 245 246 static int _protection_domain_offset; 247 static int _init_lock_offset; 248 static int _signers_offset; 249 static int _class_loader_offset; 250 static int _module_offset; 251 static int _component_mirror_offset; 252 static int _name_offset; 253 static int _source_file_offset; 254 static int _inline_mirror_offset; 255 static int _nullable_mirror_offset; 256 257 static bool offsets_computed; 258 static int classRedefinedCount_offset; 259 260 static GrowableArray<Klass*>* _fixup_mirror_list; 261 static GrowableArray<Klass*>* _fixup_module_field_list; 262 263 static void set_init_lock(oop java_class, oop init_lock); 264 static void set_protection_domain(oop java_class, oop protection_domain); 265 static void set_class_loader(oop java_class, oop class_loader); 266 static void set_component_mirror(oop java_class, oop comp_mirror); 267 static void initialize_mirror_fields(Klass* k, Handle mirror, Handle protection_domain, TRAPS); 268 static void set_mirror_module_field(Klass* K, Handle mirror, Handle module, TRAPS); 269 public: 270 static void allocate_fixup_lists(); 271 static void compute_offsets(); 272 273 // Instance creation 274 static void create_mirror(Klass* k, Handle class_loader, Handle module, 275 Handle protection_domain, TRAPS); 276 static void fixup_mirror(Klass* k, TRAPS); 277 static oop create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS); 278 static oop create_nullable_inline_type_mirror(Klass* k, Handle mirror, TRAPS); 279 280 // Archiving 281 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 282 static void archive_basic_type_mirrors(TRAPS) NOT_CDS_JAVA_HEAP_RETURN; 283 static oop archive_mirror(Klass* k, TRAPS) NOT_CDS_JAVA_HEAP_RETURN_(NULL); 284 static oop process_archived_mirror(Klass* k, oop mirror, oop archived_mirror, Thread *THREAD) 285 NOT_CDS_JAVA_HEAP_RETURN_(NULL); 286 static bool restore_archived_mirror(Klass *k, Handle class_loader, Handle module, 287 Handle protection_domain, 288 TRAPS) NOT_CDS_JAVA_HEAP_RETURN_(false); 289 290 static void fixup_module_field(Klass* k, Handle module); 291 292 // Conversion 293 static Klass* as_Klass(oop java_class); 294 static Klass* as_Klass_raw(oop java_class); 295 static void set_klass(oop java_class, Klass* klass); 296 static BasicType as_BasicType(oop java_class, Klass** reference_klass = NULL); 297 static Symbol* as_signature(oop java_class, bool intern_if_not_found, TRAPS); 298 static void print_signature(oop java_class, outputStream *st); 299 static const char* as_external_name(oop java_class); 300 // Testing 301 static bool is_instance(oop obj); 302 303 static bool is_primitive(oop java_class); 304 static BasicType primitive_type(oop java_class); 305 static oop primitive_mirror(BasicType t); 306 // JVM_NewArray support 307 static Klass* array_klass_acquire(oop java_class); 308 static void release_set_array_klass(oop java_class, Klass* klass); 309 // compiler support for class operations 310 static int klass_offset_in_bytes() { return _klass_offset; } 311 static int array_klass_offset_in_bytes() { return _array_klass_offset; } 312 static int inline_mirror_offset_in_bytes() { return _inline_mirror_offset; } 313 static int component_mirror_offset_in_bytes() { return _component_mirror_offset; } 314 // Support for classRedefinedCount field 315 static int classRedefinedCount(oop the_class_mirror); 316 static void set_classRedefinedCount(oop the_class_mirror, int value); 317 318 // Support for embedded per-class oops 319 static oop protection_domain(oop java_class); 320 static oop init_lock(oop java_class); 321 static oop component_mirror(oop java_class); 322 static objArrayOop signers(oop java_class); 323 static void set_signers(oop java_class, objArrayOop signers); 324 325 static oop class_loader(oop java_class); 326 static void set_module(oop java_class, oop module); 327 static oop module(oop java_class); 328 329 static void set_nullable_type_mirror(oop java_class, oop mirror); 330 static oop nullable_type_mirror(oop java_class); 331 static bool is_nullable_type(oop java_class) { // Must match "Class.isNullableType()" 332 return nullable_type_mirror(java_class) == NULL || oopDesc::equals(nullable_type_mirror(java_class), java_class); 333 } 334 335 static void set_inline_type_mirror(oop java_class, oop mirror); 336 static oop inline_type_mirror(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 _daemon_offset; 383 static int _stillborn_offset; 384 static int _stackSize_offset; 385 static int _tid_offset; 386 static int _thread_status_offset; 387 static int _park_blocker_offset; 388 static int _park_event_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 // Name 402 static oop name(oop java_thread); 403 static void set_name(oop java_thread, oop name); 404 // Priority 405 static ThreadPriority priority(oop java_thread); 406 static void set_priority(oop java_thread, ThreadPriority priority); 407 // Thread group 408 static oop threadGroup(oop java_thread); 409 // Stillborn 410 static bool is_stillborn(oop java_thread); 411 static void set_stillborn(oop java_thread); 412 // Alive (NOTE: this is not really a field, but provides the correct 413 // definition without doing a Java call) 414 static bool is_alive(oop java_thread); 415 // Daemon 416 static bool is_daemon(oop java_thread); 417 static void set_daemon(oop java_thread); 418 // Context ClassLoader 419 static oop context_class_loader(oop java_thread); 420 // Control context 421 static oop inherited_access_control_context(oop java_thread); 422 // Stack size hint 423 static jlong stackSize(oop java_thread); 424 // Thread ID 425 static jlong thread_id(oop java_thread); 426 427 // Blocker object responsible for thread parking 428 static oop park_blocker(oop java_thread); 429 430 // Pointer to type-stable park handler, encoded as jlong. 431 // Should be set when apparently null 432 // For details, see unsafe.cpp Unsafe_Unpark 433 static jlong park_event(oop java_thread); 434 static bool set_park_event(oop java_thread, jlong ptr); 435 436 // Java Thread Status for JVMTI and M&M use. 437 // This thread status info is saved in threadStatus field of 438 // java.lang.Thread java class. 439 enum ThreadStatus { 440 NEW = 0, 441 RUNNABLE = JVMTI_THREAD_STATE_ALIVE + // runnable / running 442 JVMTI_THREAD_STATE_RUNNABLE, 443 SLEEPING = JVMTI_THREAD_STATE_ALIVE + // Thread.sleep() 444 JVMTI_THREAD_STATE_WAITING + 445 JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT + 446 JVMTI_THREAD_STATE_SLEEPING, 447 IN_OBJECT_WAIT = JVMTI_THREAD_STATE_ALIVE + // Object.wait() 448 JVMTI_THREAD_STATE_WAITING + 449 JVMTI_THREAD_STATE_WAITING_INDEFINITELY + 450 JVMTI_THREAD_STATE_IN_OBJECT_WAIT, 451 IN_OBJECT_WAIT_TIMED = JVMTI_THREAD_STATE_ALIVE + // Object.wait(long) 452 JVMTI_THREAD_STATE_WAITING + 453 JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT + 454 JVMTI_THREAD_STATE_IN_OBJECT_WAIT, 455 PARKED = JVMTI_THREAD_STATE_ALIVE + // LockSupport.park() 456 JVMTI_THREAD_STATE_WAITING + 457 JVMTI_THREAD_STATE_WAITING_INDEFINITELY + 458 JVMTI_THREAD_STATE_PARKED, 459 PARKED_TIMED = JVMTI_THREAD_STATE_ALIVE + // LockSupport.park(long) 460 JVMTI_THREAD_STATE_WAITING + 461 JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT + 462 JVMTI_THREAD_STATE_PARKED, 463 BLOCKED_ON_MONITOR_ENTER = JVMTI_THREAD_STATE_ALIVE + // (re-)entering a synchronization block 464 JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER, 465 TERMINATED = JVMTI_THREAD_STATE_TERMINATED 466 }; 467 // Write thread status info to threadStatus field of java.lang.Thread. 468 static void set_thread_status(oop java_thread_oop, ThreadStatus status); 469 // Read thread status info from threadStatus field of java.lang.Thread. 470 static ThreadStatus get_thread_status(oop java_thread_oop); 471 472 static const char* thread_status_name(oop java_thread_oop); 473 474 // Debugging 475 friend class JavaClasses; 476 }; 477 478 // Interface to java.lang.ThreadGroup objects 479 480 class java_lang_ThreadGroup : AllStatic { 481 private: 482 static int _parent_offset; 483 static int _name_offset; 484 static int _threads_offset; 485 static int _groups_offset; 486 static int _maxPriority_offset; 487 static int _destroyed_offset; 488 static int _daemon_offset; 489 static int _nthreads_offset; 490 static int _ngroups_offset; 491 492 static void compute_offsets(); 493 494 public: 495 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 496 497 // parent ThreadGroup 498 static oop parent(oop java_thread_group); 499 // name 500 static const char* name(oop java_thread_group); 501 // ("name as oop" accessor is not necessary) 502 // Number of threads in group 503 static int nthreads(oop java_thread_group); 504 // threads 505 static objArrayOop threads(oop java_thread_group); 506 // Number of threads in group 507 static int ngroups(oop java_thread_group); 508 // groups 509 static objArrayOop groups(oop java_thread_group); 510 // maxPriority in group 511 static ThreadPriority maxPriority(oop java_thread_group); 512 // Destroyed 513 static bool is_destroyed(oop java_thread_group); 514 // Daemon 515 static bool is_daemon(oop java_thread_group); 516 // Debugging 517 friend class JavaClasses; 518 }; 519 520 521 522 // Interface to java.lang.Throwable objects 523 524 class java_lang_Throwable: AllStatic { 525 friend class BacktraceBuilder; 526 friend class BacktraceIterator; 527 528 private: 529 // Offsets 530 enum { 531 hc_backtrace_offset = 0, 532 hc_detailMessage_offset = 1, 533 hc_cause_offset = 2, // New since 1.4 534 hc_stackTrace_offset = 3 // New since 1.4 535 }; 536 // Trace constants 537 enum { 538 trace_methods_offset = 0, 539 trace_bcis_offset = 1, 540 trace_mirrors_offset = 2, 541 trace_names_offset = 3, 542 trace_next_offset = 4, 543 trace_size = 5, 544 trace_chunk_size = 32 545 }; 546 547 static int backtrace_offset; 548 static int detailMessage_offset; 549 static int stackTrace_offset; 550 static int depth_offset; 551 static int static_unassigned_stacktrace_offset; 552 553 // StackTrace (programmatic access, new since 1.4) 554 static void clear_stacktrace(oop throwable); 555 // Stacktrace (post JDK 1.7.0 to allow immutability protocol to be followed) 556 static void set_stacktrace(oop throwable, oop st_element_array); 557 static oop unassigned_stacktrace(); 558 559 public: 560 // Backtrace 561 static oop backtrace(oop throwable); 562 static void set_backtrace(oop throwable, oop value); 563 static int depth(oop throwable); 564 static void set_depth(oop throwable, int value); 565 // Needed by JVMTI to filter out this internal field. 566 static int get_backtrace_offset() { return backtrace_offset;} 567 static int get_detailMessage_offset() { return detailMessage_offset;} 568 // Message 569 static oop message(oop throwable); 570 static void set_message(oop throwable, oop value); 571 static Symbol* detail_message(oop throwable); 572 static void print_stack_element(outputStream *st, const methodHandle& method, int bci); 573 static void print_stack_usage(Handle stream); 574 575 static void compute_offsets(); 576 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 577 578 // Allocate space for backtrace (created but stack trace not filled in) 579 static void allocate_backtrace(Handle throwable, TRAPS); 580 // Fill in current stack trace for throwable with preallocated backtrace (no GC) 581 static void fill_in_stack_trace_of_preallocated_backtrace(Handle throwable); 582 // Fill in current stack trace, can cause GC 583 static void fill_in_stack_trace(Handle throwable, const methodHandle& method, TRAPS); 584 static void fill_in_stack_trace(Handle throwable, const methodHandle& method = methodHandle()); 585 // Programmatic access to stack trace 586 static void get_stack_trace_elements(Handle throwable, objArrayHandle stack_trace, TRAPS); 587 // Printing 588 static void print(oop throwable, outputStream* st); 589 static void print_stack_trace(Handle throwable, outputStream* st); 590 static void java_printStackTrace(Handle throwable, TRAPS); 591 // Debugging 592 friend class JavaClasses; 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 // find or create resolved member name 1081 static oop find_resolved_method(const methodHandle& m, TRAPS); 1082 1083 static bool is_instance(oop resolved_method); 1084 }; 1085 1086 1087 #define MEMBERNAME_INJECTED_FIELDS(macro) \ 1088 macro(java_lang_invoke_MemberName, vmindex, intptr_signature, false) 1089 1090 1091 class java_lang_invoke_MemberName: AllStatic { 1092 friend class JavaClasses; 1093 1094 private: 1095 // From java.lang.invoke.MemberName: 1096 // private Class<?> clazz; // class in which the method is defined 1097 // private String name; // may be null if not yet materialized 1098 // private Object type; // may be null if not yet materialized 1099 // private int flags; // modifier bits; see reflect.Modifier 1100 // private ResolvedMethodName method; // holds VM-specific target value 1101 // private intptr_t vmindex; // member index within class or interface 1102 static int _clazz_offset; 1103 static int _name_offset; 1104 static int _type_offset; 1105 static int _flags_offset; 1106 static int _method_offset; 1107 static int _vmindex_offset; 1108 1109 static void compute_offsets(); 1110 1111 public: 1112 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1113 // Accessors 1114 static oop clazz(oop mname); 1115 static void set_clazz(oop mname, oop clazz); 1116 1117 static oop type(oop mname); 1118 static void set_type(oop mname, oop type); 1119 1120 static oop name(oop mname); 1121 static void set_name(oop mname, oop name); 1122 1123 static int flags(oop mname); 1124 static void set_flags(oop mname, int flags); 1125 1126 // Link through ResolvedMethodName field to get Method* 1127 static Method* vmtarget(oop mname); 1128 static void set_method(oop mname, oop method); 1129 1130 static intptr_t vmindex(oop mname); 1131 static void set_vmindex(oop mname, intptr_t index); 1132 1133 // Testers 1134 static bool is_subclass(Klass* klass) { 1135 return klass->is_subclass_of(SystemDictionary::MemberName_klass()); 1136 } 1137 static bool is_instance(oop obj); 1138 1139 static bool is_method(oop obj); 1140 1141 // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants): 1142 enum { 1143 MN_IS_METHOD = 0x00010000, // method (not constructor) 1144 MN_IS_CONSTRUCTOR = 0x00020000, // constructor 1145 MN_IS_FIELD = 0x00040000, // field 1146 MN_IS_TYPE = 0x00080000, // nested type 1147 MN_CALLER_SENSITIVE = 0x00100000, // @CallerSensitive annotation detected 1148 MN_REFERENCE_KIND_SHIFT = 24, // refKind 1149 MN_REFERENCE_KIND_MASK = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT, 1150 // The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers: 1151 MN_SEARCH_SUPERCLASSES = 0x00100000, // walk super classes 1152 MN_SEARCH_INTERFACES = 0x00200000 // walk implemented interfaces 1153 }; 1154 1155 // Accessors for code generation: 1156 static int clazz_offset_in_bytes() { return _clazz_offset; } 1157 static int type_offset_in_bytes() { return _type_offset; } 1158 static int name_offset_in_bytes() { return _name_offset; } 1159 static int flags_offset_in_bytes() { return _flags_offset; } 1160 static int method_offset_in_bytes() { return _method_offset; } 1161 static int vmindex_offset_in_bytes() { return _vmindex_offset; } 1162 }; 1163 1164 1165 // Interface to java.lang.invoke.MethodType objects 1166 1167 class java_lang_invoke_MethodType: AllStatic { 1168 friend class JavaClasses; 1169 1170 private: 1171 static int _rtype_offset; 1172 static int _ptypes_offset; 1173 1174 static void compute_offsets(); 1175 1176 public: 1177 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1178 // Accessors 1179 static oop rtype(oop mt); 1180 static objArrayOop ptypes(oop mt); 1181 1182 static oop ptype(oop mt, int index); 1183 static int ptype_count(oop mt); 1184 1185 static int ptype_slot_count(oop mt); // extra counts for long/double 1186 static int rtype_slot_count(oop mt); // extra counts for long/double 1187 1188 static Symbol* as_signature(oop mt, bool intern_if_not_found, TRAPS); 1189 static void print_signature(oop mt, outputStream* st); 1190 1191 static bool is_instance(oop obj); 1192 1193 static bool equals(oop mt1, oop mt2); 1194 1195 // Accessors for code generation: 1196 static int rtype_offset_in_bytes() { return _rtype_offset; } 1197 static int ptypes_offset_in_bytes() { return _ptypes_offset; } 1198 }; 1199 1200 1201 // Interface to java.lang.invoke.CallSite objects 1202 1203 class java_lang_invoke_CallSite: AllStatic { 1204 friend class JavaClasses; 1205 1206 private: 1207 static int _target_offset; 1208 static int _context_offset; 1209 1210 static void compute_offsets(); 1211 1212 public: 1213 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1214 // Accessors 1215 static oop target( oop site); 1216 static void set_target( oop site, oop target); 1217 static void set_target_volatile( oop site, oop target); 1218 1219 static oop context_no_keepalive(oop site); 1220 1221 // Testers 1222 static bool is_subclass(Klass* klass) { 1223 return klass->is_subclass_of(SystemDictionary::CallSite_klass()); 1224 } 1225 static bool is_instance(oop obj); 1226 1227 // Accessors for code generation: 1228 static int target_offset_in_bytes() { return _target_offset; } 1229 }; 1230 1231 // Interface to java.lang.invoke.MethodHandleNatives$CallSiteContext objects 1232 1233 #define CALLSITECONTEXT_INJECTED_FIELDS(macro) \ 1234 macro(java_lang_invoke_MethodHandleNatives_CallSiteContext, vmdependencies, intptr_signature, false) \ 1235 macro(java_lang_invoke_MethodHandleNatives_CallSiteContext, last_cleanup, long_signature, false) 1236 1237 class DependencyContext; 1238 1239 class java_lang_invoke_MethodHandleNatives_CallSiteContext : AllStatic { 1240 friend class JavaClasses; 1241 1242 private: 1243 static int _vmdependencies_offset; 1244 static int _last_cleanup_offset; 1245 1246 static void compute_offsets(); 1247 1248 public: 1249 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1250 // Accessors 1251 static DependencyContext vmdependencies(oop context); 1252 1253 // Testers 1254 static bool is_subclass(Klass* klass) { 1255 return klass->is_subclass_of(SystemDictionary::Context_klass()); 1256 } 1257 static bool is_instance(oop obj); 1258 }; 1259 1260 // Interface to java.security.AccessControlContext objects 1261 1262 class java_security_AccessControlContext: AllStatic { 1263 private: 1264 // Note that for this class the layout changed between JDK1.2 and JDK1.3, 1265 // so we compute the offsets at startup rather than hard-wiring them. 1266 static int _context_offset; 1267 static int _privilegedContext_offset; 1268 static int _isPrivileged_offset; 1269 static int _isAuthorized_offset; 1270 1271 static void compute_offsets(); 1272 public: 1273 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1274 static oop create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS); 1275 1276 // Debugging/initialization 1277 friend class JavaClasses; 1278 }; 1279 1280 1281 // Interface to java.lang.ClassLoader objects 1282 1283 #define CLASSLOADER_INJECTED_FIELDS(macro) \ 1284 macro(java_lang_ClassLoader, loader_data, intptr_signature, false) 1285 1286 class java_lang_ClassLoader : AllStatic { 1287 private: 1288 static int _loader_data_offset; 1289 static bool offsets_computed; 1290 static int parent_offset; 1291 static int parallelCapable_offset; 1292 static int name_offset; 1293 static int nameAndId_offset; 1294 static int unnamedModule_offset; 1295 1296 public: 1297 static void compute_offsets(); 1298 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1299 1300 static ClassLoaderData* loader_data_acquire(oop loader); 1301 static ClassLoaderData* loader_data_raw(oop loader); 1302 static void release_set_loader_data(oop loader, ClassLoaderData* new_data); 1303 1304 static oop parent(oop loader); 1305 static oop name(oop loader); 1306 static oop nameAndId(oop loader); 1307 static bool isAncestor(oop loader, oop cl); 1308 1309 // Support for parallelCapable field 1310 static bool parallelCapable(oop the_class_mirror); 1311 1312 static bool is_trusted_loader(oop loader); 1313 1314 // Return true if this is one of the class loaders associated with 1315 // the generated bytecodes for reflection. 1316 static bool is_reflection_class_loader(oop loader); 1317 1318 // Fix for 4474172 1319 static oop non_reflection_class_loader(oop loader); 1320 1321 // Testers 1322 static bool is_subclass(Klass* klass) { 1323 return klass->is_subclass_of(SystemDictionary::ClassLoader_klass()); 1324 } 1325 static bool is_instance(oop obj); 1326 1327 static oop unnamedModule(oop loader); 1328 1329 // Debugging 1330 friend class JavaClasses; 1331 friend class ClassFileParser; // access to number_of_fake_fields 1332 }; 1333 1334 1335 // Interface to java.lang.System objects 1336 1337 class java_lang_System : AllStatic { 1338 private: 1339 static int static_in_offset; 1340 static int static_out_offset; 1341 static int static_err_offset; 1342 static int static_security_offset; 1343 1344 public: 1345 static int in_offset_in_bytes(); 1346 static int out_offset_in_bytes(); 1347 static int err_offset_in_bytes(); 1348 1349 static void compute_offsets(); 1350 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1351 1352 // Debugging 1353 friend class JavaClasses; 1354 }; 1355 1356 1357 // Interface to java.lang.StackTraceElement objects 1358 1359 class java_lang_StackTraceElement: AllStatic { 1360 private: 1361 static int declaringClassObject_offset; 1362 static int classLoaderName_offset; 1363 static int moduleName_offset; 1364 static int moduleVersion_offset; 1365 static int declaringClass_offset; 1366 static int methodName_offset; 1367 static int fileName_offset; 1368 static int lineNumber_offset; 1369 1370 // Setters 1371 static void set_classLoaderName(oop element, oop value); 1372 static void set_moduleName(oop element, oop value); 1373 static void set_moduleVersion(oop element, oop value); 1374 static void set_declaringClass(oop element, oop value); 1375 static void set_methodName(oop element, oop value); 1376 static void set_fileName(oop element, oop value); 1377 static void set_lineNumber(oop element, int value); 1378 static void set_declaringClassObject(oop element, oop value); 1379 1380 public: 1381 // Create an instance of StackTraceElement 1382 static oop create(const methodHandle& method, int bci, TRAPS); 1383 1384 static void fill_in(Handle element, InstanceKlass* holder, const methodHandle& method, 1385 int version, int bci, Symbol* name, TRAPS); 1386 1387 static void compute_offsets(); 1388 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1389 1390 // Debugging 1391 friend class JavaClasses; 1392 }; 1393 1394 1395 class Backtrace: AllStatic { 1396 public: 1397 // Helper backtrace functions to store bci|version together. 1398 static int merge_bci_and_version(int bci, int version); 1399 static int merge_mid_and_cpref(int mid, int cpref); 1400 static int bci_at(unsigned int merged); 1401 static int version_at(unsigned int merged); 1402 static int mid_at(unsigned int merged); 1403 static int cpref_at(unsigned int merged); 1404 static int get_line_number(const methodHandle& method, int bci); 1405 static Symbol* get_source_file_name(InstanceKlass* holder, int version); 1406 1407 // Debugging 1408 friend class JavaClasses; 1409 }; 1410 1411 // Interface to java.lang.StackFrameInfo objects 1412 1413 #define STACKFRAMEINFO_INJECTED_FIELDS(macro) \ 1414 macro(java_lang_StackFrameInfo, version, short_signature, false) 1415 1416 class java_lang_StackFrameInfo: AllStatic { 1417 private: 1418 static int _memberName_offset; 1419 static int _bci_offset; 1420 static int _version_offset; 1421 1422 static Method* get_method(Handle stackFrame, InstanceKlass* holder, TRAPS); 1423 1424 public: 1425 // Setters 1426 static void set_method_and_bci(Handle stackFrame, const methodHandle& method, int bci, TRAPS); 1427 static void set_bci(oop info, int value); 1428 1429 static void set_version(oop info, short value); 1430 1431 static void compute_offsets(); 1432 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1433 1434 static void to_stack_trace_element(Handle stackFrame, Handle stack_trace_element, TRAPS); 1435 1436 // Debugging 1437 friend class JavaClasses; 1438 }; 1439 1440 class java_lang_LiveStackFrameInfo: AllStatic { 1441 private: 1442 static int _monitors_offset; 1443 static int _locals_offset; 1444 static int _operands_offset; 1445 static int _mode_offset; 1446 1447 public: 1448 static void set_monitors(oop info, oop value); 1449 static void set_locals(oop info, oop value); 1450 static void set_operands(oop info, oop value); 1451 static void set_mode(oop info, int value); 1452 1453 static void compute_offsets(); 1454 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1455 1456 // Debugging 1457 friend class JavaClasses; 1458 }; 1459 1460 // Interface to java.lang.AssertionStatusDirectives objects 1461 1462 class java_lang_AssertionStatusDirectives: AllStatic { 1463 private: 1464 static int classes_offset; 1465 static int classEnabled_offset; 1466 static int packages_offset; 1467 static int packageEnabled_offset; 1468 static int deflt_offset; 1469 1470 public: 1471 // Setters 1472 static void set_classes(oop obj, oop val); 1473 static void set_classEnabled(oop obj, oop val); 1474 static void set_packages(oop obj, oop val); 1475 static void set_packageEnabled(oop obj, oop val); 1476 static void set_deflt(oop obj, bool val); 1477 1478 static void compute_offsets(); 1479 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1480 1481 // Debugging 1482 friend class JavaClasses; 1483 }; 1484 1485 1486 class java_nio_Buffer: AllStatic { 1487 private: 1488 static int _limit_offset; 1489 1490 public: 1491 static int limit_offset(); 1492 static void compute_offsets(); 1493 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1494 }; 1495 1496 class java_util_concurrent_locks_AbstractOwnableSynchronizer : AllStatic { 1497 private: 1498 static int _owner_offset; 1499 public: 1500 static void compute_offsets(); 1501 static oop get_owner_threadObj(oop obj); 1502 static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; 1503 }; 1504 1505 // Interface to jdk.internal.misc.UnsafeConsants 1506 1507 class jdk_internal_misc_UnsafeConstants : AllStatic { 1508 public: 1509 static void set_unsafe_constants(); 1510 static void compute_offsets() { } 1511 static void serialize_offsets(SerializeClosure* f) { } 1512 }; 1513 1514 // Use to declare fields that need to be injected into Java classes 1515 // for the JVM to use. The name_index and signature_index are 1516 // declared in vmSymbols. The may_be_java flag is used to declare 1517 // fields that might already exist in Java but should be injected if 1518 // they don't. Otherwise the field is unconditionally injected and 1519 // the JVM uses the injected one. This is to ensure that name 1520 // collisions don't occur. In general may_be_java should be false 1521 // unless there's a good reason. 1522 1523 class InjectedField { 1524 public: 1525 const SystemDictionary::WKID klass_id; 1526 const vmSymbols::SID name_index; 1527 const vmSymbols::SID signature_index; 1528 const bool may_be_java; 1529 1530 1531 Klass* klass() const { return SystemDictionary::well_known_klass(klass_id); } 1532 Symbol* name() const { return lookup_symbol(name_index); } 1533 Symbol* signature() const { return lookup_symbol(signature_index); } 1534 1535 int compute_offset(); 1536 1537 // Find the Symbol for this index 1538 static Symbol* lookup_symbol(int symbol_index) { 1539 return vmSymbols::symbol_at((vmSymbols::SID)symbol_index); 1540 } 1541 }; 1542 1543 #define DECLARE_INJECTED_FIELD_ENUM(klass, name, signature, may_be_java) \ 1544 klass##_##name##_enum, 1545 1546 #define ALL_INJECTED_FIELDS(macro) \ 1547 CLASS_INJECTED_FIELDS(macro) \ 1548 CLASSLOADER_INJECTED_FIELDS(macro) \ 1549 RESOLVEDMETHOD_INJECTED_FIELDS(macro) \ 1550 MEMBERNAME_INJECTED_FIELDS(macro) \ 1551 CALLSITECONTEXT_INJECTED_FIELDS(macro) \ 1552 STACKFRAMEINFO_INJECTED_FIELDS(macro) \ 1553 MODULE_INJECTED_FIELDS(macro) 1554 1555 // Interface to hard-coded offset checking 1556 1557 class JavaClasses : AllStatic { 1558 private: 1559 1560 static InjectedField _injected_fields[]; 1561 1562 static bool check_offset(const char *klass_name, int offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0; 1563 public: 1564 enum InjectedFieldID { 1565 ALL_INJECTED_FIELDS(DECLARE_INJECTED_FIELD_ENUM) 1566 MAX_enum 1567 }; 1568 1569 static int compute_injected_offset(InjectedFieldID id); 1570 1571 static void compute_hard_coded_offsets(); 1572 static void compute_offsets(); 1573 static void check_offsets() PRODUCT_RETURN; 1574 static void serialize_offsets(SerializeClosure* soc) NOT_CDS_RETURN; 1575 static InjectedField* get_injected(Symbol* class_name, int* field_count); 1576 }; 1577 1578 #undef DECLARE_INJECTED_FIELD_ENUM 1579 1580 #endif // SHARE_CLASSFILE_JAVACLASSES_HPP