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