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