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