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