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