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