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