1 /*
   2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_CLASSFILE_JAVACLASSES_HPP
  26 #define SHARE_VM_CLASSFILE_JAVACLASSES_HPP
  27 
  28 #include "classfile/systemDictionary.hpp"
  29 #include "jvmtifiles/jvmti.h"
  30 #include "oops/oop.hpp"
  31 #include "runtime/os.hpp"
  32 #include "utilities/utf8.hpp"
  33 
  34 // Interface for manipulating the basic Java classes.
  35 //
  36 // All dependencies on layout of actual Java classes should be kept here.
  37 // If the layout of any of the classes above changes the offsets must be adjusted.
  38 //
  39 // For most classes we hardwire the offsets for performance reasons. In certain
  40 // cases (e.g. java.security.AccessControlContext) we compute the offsets at
  41 // startup since the layout here differs between JDK1.2 and JDK1.3.
  42 //
  43 // Note that fields (static and non-static) are arranged with oops before non-oops
  44 // on a per class basis. The offsets below have to reflect this ordering.
  45 //
  46 // When editing the layouts please update the check_offset verification code
  47 // correspondingly. The names in the enums must be identical to the actual field
  48 // names in order for the verification code to work.
  49 
  50 
  51 // Interface to java.lang.String objects
  52 
  53 class java_lang_String : AllStatic {
  54  private:
  55   static int value_offset;
  56   static int hash_offset;
  57   static int coder_offset;
  58 
  59   static bool initialized;
  60 
  61   static Handle basic_create(int length, bool byte_arr, TRAPS);
  62 
  63   static inline void set_coder(oop string, jbyte coder);
  64 
  65  public:
  66 
  67   // Coders
  68   enum Coder {
  69     CODER_LATIN1 =  0,
  70     CODER_UTF16  =  1
  71   };
  72 
  73   static void compute_offsets();
  74 
  75   // Instance creation
  76   static Handle create_from_unicode(jchar* unicode, int len, TRAPS);
  77   static oop    create_oop_from_unicode(jchar* unicode, int len, TRAPS);
  78   static Handle create_from_str(const char* utf8_str, TRAPS);
  79   static oop    create_oop_from_str(const char* utf8_str, TRAPS);
  80   static Handle create_from_symbol(Symbol* symbol, TRAPS);
  81   static Handle create_from_platform_dependent_str(const char* str, TRAPS);
  82   static Handle char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS);
  83 
  84   static bool has_hash_field()  {
  85     assert(initialized, "Must be initialized");
  86     return (hash_offset > 0);
  87   }
  88   static bool has_coder_field()  {
  89     assert(initialized, "Must be initialized");
  90     return (coder_offset > 0);
  91   }
  92 
  93   static void set_compact_strings(bool value);
  94 
  95   static int value_offset_in_bytes()  {
  96     assert(initialized && (value_offset > 0), "Must be initialized");
  97     return value_offset;
  98   }
  99   static int hash_offset_in_bytes()   {
 100     assert(initialized && (hash_offset > 0), "Must be initialized");
 101     return hash_offset;
 102   }
 103   static int coder_offset_in_bytes()   {
 104     assert(initialized && (coder_offset > 0), "Must be initialized");
 105     return coder_offset;
 106   }
 107 
 108   static inline void set_value_raw(oop string, typeArrayOop buffer);
 109   static inline void set_value(oop string, typeArrayOop buffer);
 110   static inline void set_hash(oop string, unsigned int hash);
 111 
 112   // Accessors
 113   static inline typeArrayOop value(oop java_string);
 114   static inline unsigned int hash(oop java_string);
 115   static inline bool is_latin1(oop java_string);
 116   static inline int length(oop java_string);
 117   static int utf8_length(oop java_string);
 118 
 119   // String converters
 120   static char*  as_utf8_string(oop java_string);
 121   static char*  as_utf8_string(oop java_string, char* buf, int buflen);
 122   static char*  as_utf8_string(oop java_string, int start, int len);
 123   static char*  as_utf8_string(oop java_string, int start, int len, char* buf, int buflen);
 124   static char*  as_platform_dependent_str(Handle java_string, TRAPS);
 125   static jchar* as_unicode_string(oop java_string, int& length, TRAPS);
 126   // produce an ascii string with all other values quoted using \u####
 127   static char*  as_quoted_ascii(oop java_string);
 128 
 129   // Compute the hash value for a java.lang.String object which would
 130   // contain the characters passed in.
 131   //
 132   // As the hash value used by the String object itself, in
 133   // String.hashCode().  This value is normally calculated in Java code
 134   // in the String.hashCode method(), but is precomputed for String
 135   // objects in the shared archive file.
 136   // hash P(31) from Kernighan & Ritchie
 137   //
 138   // For this reason, THIS ALGORITHM MUST MATCH String.hashCode().
 139   static unsigned int hash_code(const jchar* s, int len) {
 140     unsigned int h = 0;
 141     while (len-- > 0) {
 142       h = 31*h + (unsigned int) *s;
 143       s++;
 144     }
 145     return h;
 146   }
 147 
 148   static unsigned int hash_code(const jbyte* s, int len) {
 149     unsigned int h = 0;
 150     while (len-- > 0) {
 151       h = 31*h + (((unsigned int) *s) & 0xFF);
 152       s++;
 153     }
 154     return h;
 155   }
 156 
 157   static unsigned int hash_code(oop java_string);
 158   static unsigned int latin1_hash_code(typeArrayOop value, int len);
 159 
 160   // This is the string hash code used by the StringTable, which may be
 161   // the same as String.hashCode or an alternate hash code.
 162   static unsigned int hash_string(oop java_string);
 163 
 164   static bool equals(oop java_string, jchar* chars, int len);
 165   static bool equals(oop str1, oop str2);
 166 
 167   // Conversion between '.' and '/' formats
 168   static Handle externalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '/', '.', THREAD); }
 169   static Handle internalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '.', '/', THREAD); }
 170 
 171   // Conversion
 172   static Symbol* as_symbol(Handle java_string, TRAPS);
 173   static Symbol* as_symbol_or_null(oop java_string);
 174 
 175   // Testers
 176   static bool is_instance(oop obj);
 177   static inline bool is_instance_inlined(oop obj);
 178 
 179   // Debugging
 180   static void print(oop java_string, outputStream* st);
 181   friend class JavaClasses;
 182   friend class StringTable;
 183 };
 184 
 185 
 186 // Interface to java.lang.Class objects
 187 
 188 #define CLASS_INJECTED_FIELDS(macro)                                       \
 189   macro(java_lang_Class, klass,                  intptr_signature,  false) \
 190   macro(java_lang_Class, array_klass,            intptr_signature,  false) \
 191   macro(java_lang_Class, oop_size,               int_signature,     false) \
 192   macro(java_lang_Class, static_oop_field_count, int_signature,     false) \
 193   macro(java_lang_Class, protection_domain,      object_signature,  false) \
 194   macro(java_lang_Class, signers,                object_signature,  false)
 195 
 196 class java_lang_Class : AllStatic {
 197   friend class VMStructs;
 198   friend class JVMCIVMStructs;
 199 
 200  private:
 201   // The fake offsets are added by the class loader when java.lang.Class is loaded
 202 
 203   static int _klass_offset;
 204   static int _array_klass_offset;
 205 
 206   static int _oop_size_offset;
 207   static int _static_oop_field_count_offset;
 208 
 209   static int _protection_domain_offset;
 210   static int _init_lock_offset;
 211   static int _signers_offset;
 212   static int _class_loader_offset;
 213   static int _component_mirror_offset;
 214 
 215   static bool offsets_computed;
 216   static int classRedefinedCount_offset;
 217 
 218   static GrowableArray<Klass*>* _fixup_mirror_list;
 219 
 220   static void set_init_lock(oop java_class, oop init_lock);
 221   static void set_protection_domain(oop java_class, oop protection_domain);
 222   static void set_class_loader(oop java_class, oop class_loader);
 223   static void set_component_mirror(oop java_class, oop comp_mirror);
 224   static void initialize_mirror_fields(KlassHandle k, Handle mirror, Handle protection_domain, TRAPS);
 225  public:
 226   static void compute_offsets();
 227 
 228   // Instance creation
 229   static void create_mirror(KlassHandle k, Handle class_loader,
 230                             Handle protection_domain, TRAPS);
 231   static void fixup_mirror(KlassHandle k, TRAPS);
 232   static oop  create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS);
 233   // Conversion
 234   static Klass* as_Klass(oop java_class);
 235   static void set_klass(oop java_class, Klass* klass);
 236   static BasicType as_BasicType(oop java_class, Klass** reference_klass = NULL);
 237   static BasicType as_BasicType(oop java_class, KlassHandle* reference_klass) {
 238     Klass* refk_oop = NULL;
 239     BasicType result = as_BasicType(java_class, &refk_oop);
 240     (*reference_klass) = KlassHandle(refk_oop);
 241     return result;
 242   }
 243   static Symbol* as_signature(oop java_class, bool intern_if_not_found, TRAPS);
 244   static void print_signature(oop java_class, outputStream *st);
 245   static const char* as_external_name(oop java_class);
 246   // Testing
 247   static bool is_instance(oop obj);
 248 
 249   static bool is_primitive(oop java_class);
 250   static BasicType primitive_type(oop java_class);
 251   static oop primitive_mirror(BasicType t);
 252   // JVM_NewArray support
 253   static Klass* array_klass(oop java_class);
 254   static void set_array_klass(oop java_class, Klass* klass);
 255   // compiler support for class operations
 256   static int klass_offset_in_bytes()                { return _klass_offset; }
 257   static int array_klass_offset_in_bytes()          { return _array_klass_offset; }
 258   // Support for classRedefinedCount field
 259   static int classRedefinedCount(oop the_class_mirror);
 260   static void set_classRedefinedCount(oop the_class_mirror, int value);
 261 
 262   // Support for embedded per-class oops
 263   static oop  protection_domain(oop java_class);
 264   static oop  init_lock(oop java_class);
 265   static oop  component_mirror(oop java_class);
 266   static objArrayOop  signers(oop java_class);
 267   static void set_signers(oop java_class, objArrayOop signers);
 268 
 269   static oop class_loader(oop java_class);
 270 
 271   static int oop_size(oop java_class);
 272   static void set_oop_size(oop java_class, int size);
 273   static int static_oop_field_count(oop java_class);
 274   static void set_static_oop_field_count(oop java_class, int size);
 275 
 276   static GrowableArray<Klass*>* fixup_mirror_list() {
 277     return _fixup_mirror_list;
 278   }
 279   static void set_fixup_mirror_list(GrowableArray<Klass*>* v) {
 280     _fixup_mirror_list = v;
 281   }
 282   // Debugging
 283   friend class JavaClasses;
 284   friend class InstanceKlass;   // verification code accesses offsets
 285   friend class ClassFileParser; // access to number_of_fake_fields
 286 };
 287 
 288 // Interface to java.lang.Thread objects
 289 
 290 class java_lang_Thread : AllStatic {
 291  private:
 292   // Note that for this class the layout changed between JDK1.2 and JDK1.3,
 293   // so we compute the offsets at startup rather than hard-wiring them.
 294   static int _name_offset;
 295   static int _group_offset;
 296   static int _contextClassLoader_offset;
 297   static int _inheritedAccessControlContext_offset;
 298   static int _priority_offset;
 299   static int _eetop_offset;
 300   static int _daemon_offset;
 301   static int _stillborn_offset;
 302   static int _stackSize_offset;
 303   static int _tid_offset;
 304   static int _thread_status_offset;
 305   static int _park_blocker_offset;
 306   static int _park_event_offset ;
 307 
 308   static void compute_offsets();
 309 
 310  public:
 311   // Instance creation
 312   static oop create();
 313   // Returns the JavaThread associated with the thread obj
 314   static JavaThread* thread(oop java_thread);
 315   // Set JavaThread for instance
 316   static void set_thread(oop java_thread, JavaThread* thread);
 317   // Name
 318   static oop name(oop java_thread);
 319   static void set_name(oop java_thread, oop name);
 320   // Priority
 321   static ThreadPriority priority(oop java_thread);
 322   static void set_priority(oop java_thread, ThreadPriority priority);
 323   // Thread group
 324   static oop  threadGroup(oop java_thread);
 325   // Stillborn
 326   static bool is_stillborn(oop java_thread);
 327   static void set_stillborn(oop java_thread);
 328   // Alive (NOTE: this is not really a field, but provides the correct
 329   // definition without doing a Java call)
 330   static bool is_alive(oop java_thread);
 331   // Daemon
 332   static bool is_daemon(oop java_thread);
 333   static void set_daemon(oop java_thread);
 334   // Context ClassLoader
 335   static oop context_class_loader(oop java_thread);
 336   // Control context
 337   static oop inherited_access_control_context(oop java_thread);
 338   // Stack size hint
 339   static jlong stackSize(oop java_thread);
 340   // Thread ID
 341   static jlong thread_id(oop java_thread);
 342 
 343   // Blocker object responsible for thread parking
 344   static oop park_blocker(oop java_thread);
 345 
 346   // Pointer to type-stable park handler, encoded as jlong.
 347   // Should be set when apparently null
 348   // For details, see unsafe.cpp Unsafe_Unpark
 349   static jlong park_event(oop java_thread);
 350   static bool set_park_event(oop java_thread, jlong ptr);
 351 
 352   // Java Thread Status for JVMTI and M&M use.
 353   // This thread status info is saved in threadStatus field of
 354   // java.lang.Thread java class.
 355   enum ThreadStatus {
 356     NEW                      = 0,
 357     RUNNABLE                 = JVMTI_THREAD_STATE_ALIVE +          // runnable / running
 358                                JVMTI_THREAD_STATE_RUNNABLE,
 359     SLEEPING                 = JVMTI_THREAD_STATE_ALIVE +          // Thread.sleep()
 360                                JVMTI_THREAD_STATE_WAITING +
 361                                JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
 362                                JVMTI_THREAD_STATE_SLEEPING,
 363     IN_OBJECT_WAIT           = JVMTI_THREAD_STATE_ALIVE +          // Object.wait()
 364                                JVMTI_THREAD_STATE_WAITING +
 365                                JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
 366                                JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
 367     IN_OBJECT_WAIT_TIMED     = JVMTI_THREAD_STATE_ALIVE +          // Object.wait(long)
 368                                JVMTI_THREAD_STATE_WAITING +
 369                                JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
 370                                JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
 371     PARKED                   = JVMTI_THREAD_STATE_ALIVE +          // LockSupport.park()
 372                                JVMTI_THREAD_STATE_WAITING +
 373                                JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
 374                                JVMTI_THREAD_STATE_PARKED,
 375     PARKED_TIMED             = JVMTI_THREAD_STATE_ALIVE +          // LockSupport.park(long)
 376                                JVMTI_THREAD_STATE_WAITING +
 377                                JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
 378                                JVMTI_THREAD_STATE_PARKED,
 379     BLOCKED_ON_MONITOR_ENTER = JVMTI_THREAD_STATE_ALIVE +          // (re-)entering a synchronization block
 380                                JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER,
 381     TERMINATED               = JVMTI_THREAD_STATE_TERMINATED
 382   };
 383   // Write thread status info to threadStatus field of java.lang.Thread.
 384   static void set_thread_status(oop java_thread_oop, ThreadStatus status);
 385   // Read thread status info from threadStatus field of java.lang.Thread.
 386   static ThreadStatus get_thread_status(oop java_thread_oop);
 387 
 388   static const char*  thread_status_name(oop java_thread_oop);
 389 
 390   // Debugging
 391   friend class JavaClasses;
 392 };
 393 
 394 // Interface to java.lang.ThreadGroup objects
 395 
 396 class java_lang_ThreadGroup : AllStatic {
 397  private:
 398   static int _parent_offset;
 399   static int _name_offset;
 400   static int _threads_offset;
 401   static int _groups_offset;
 402   static int _maxPriority_offset;
 403   static int _destroyed_offset;
 404   static int _daemon_offset;
 405   static int _vmAllowSuspension_offset;
 406   static int _nthreads_offset;
 407   static int _ngroups_offset;
 408 
 409   static void compute_offsets();
 410 
 411  public:
 412   // parent ThreadGroup
 413   static oop  parent(oop java_thread_group);
 414   // name
 415   static const char* name(oop java_thread_group);
 416   // ("name as oop" accessor is not necessary)
 417   // Number of threads in group
 418   static int nthreads(oop java_thread_group);
 419   // threads
 420   static objArrayOop threads(oop java_thread_group);
 421   // Number of threads in group
 422   static int ngroups(oop java_thread_group);
 423   // groups
 424   static objArrayOop groups(oop java_thread_group);
 425   // maxPriority in group
 426   static ThreadPriority maxPriority(oop java_thread_group);
 427   // Destroyed
 428   static bool is_destroyed(oop java_thread_group);
 429   // Daemon
 430   static bool is_daemon(oop java_thread_group);
 431   // vmAllowSuspension
 432   static bool is_vmAllowSuspension(oop java_thread_group);
 433   // Debugging
 434   friend class JavaClasses;
 435 };
 436 
 437 
 438 
 439 // Interface to java.lang.Throwable objects
 440 
 441 class java_lang_Throwable: AllStatic {
 442   friend class BacktraceBuilder;
 443   friend class BacktraceIterator;
 444 
 445  private:
 446   // Offsets
 447   enum {
 448     hc_backtrace_offset     =  0,
 449     hc_detailMessage_offset =  1,
 450     hc_cause_offset         =  2,  // New since 1.4
 451     hc_stackTrace_offset    =  3   // New since 1.4
 452   };
 453   enum {
 454       hc_static_unassigned_stacktrace_offset = 0  // New since 1.7
 455   };
 456   // Trace constants
 457   enum {
 458     trace_methods_offset = 0,
 459     trace_bcis_offset    = 1,
 460     trace_mirrors_offset = 2,
 461     trace_cprefs_offset  = 3,
 462     trace_next_offset    = 4,
 463     trace_size           = 5,
 464     trace_chunk_size     = 32
 465   };
 466 
 467   static int backtrace_offset;
 468   static int detailMessage_offset;
 469   static int stackTrace_offset;
 470   static int depth_offset;
 471   static int static_unassigned_stacktrace_offset;
 472 
 473   // StackTrace (programmatic access, new since 1.4)
 474   static void clear_stacktrace(oop throwable);
 475   // Stacktrace (post JDK 1.7.0 to allow immutability protocol to be followed)
 476   static void set_stacktrace(oop throwable, oop st_element_array);
 477   static oop unassigned_stacktrace();
 478 
 479  public:
 480   // Backtrace
 481   static oop backtrace(oop throwable);
 482   static void set_backtrace(oop throwable, oop value);
 483   static 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 // Interface to sun.reflect.ConstantPool objects
 759 class sun_reflect_ConstantPool {
 760  private:
 761   // Note that to reduce dependencies on the JDK we compute these
 762   // offsets at run-time.
 763   static int _oop_offset;
 764 
 765   static void compute_offsets();
 766 
 767  public:
 768   // Allocation
 769   static Handle create(TRAPS);
 770 
 771   // Accessors
 772   static void set_cp(oop reflect, ConstantPool* value);
 773   static int oop_offset() {
 774     return _oop_offset;
 775   }
 776 
 777   static ConstantPool* get_cp(oop reflect);
 778 
 779   // Debugging
 780   friend class JavaClasses;
 781 };
 782 
 783 // Interface to sun.reflect.UnsafeStaticFieldAccessorImpl objects
 784 class sun_reflect_UnsafeStaticFieldAccessorImpl {
 785  private:
 786   static int _base_offset;
 787   static void compute_offsets();
 788 
 789  public:
 790   static int base_offset() {
 791     return _base_offset;
 792   }
 793 
 794   // Debugging
 795   friend class JavaClasses;
 796 };
 797 
 798 // Interface to java.lang primitive type boxing objects:
 799 //  - java.lang.Boolean
 800 //  - java.lang.Character
 801 //  - java.lang.Float
 802 //  - java.lang.Double
 803 //  - java.lang.Byte
 804 //  - java.lang.Short
 805 //  - java.lang.Integer
 806 //  - java.lang.Long
 807 
 808 // This could be separated out into 8 individual classes.
 809 
 810 class java_lang_boxing_object: AllStatic {
 811  private:
 812   enum {
 813    hc_value_offset = 0
 814   };
 815   static int value_offset;
 816   static int long_value_offset;
 817 
 818   static oop initialize_and_allocate(BasicType type, TRAPS);
 819  public:
 820   // Allocation. Returns a boxed value, or NULL for invalid type.
 821   static oop create(BasicType type, jvalue* value, TRAPS);
 822   // Accessors. Returns the basic type being boxed, or T_ILLEGAL for invalid oop.
 823   static BasicType get_value(oop box, jvalue* value);
 824   static BasicType set_value(oop box, jvalue* value);
 825   static BasicType basic_type(oop box);
 826   static bool is_instance(oop box)                 { return basic_type(box) != T_ILLEGAL; }
 827   static bool is_instance(oop box, BasicType type) { return basic_type(box) == type; }
 828   static void print(oop box, outputStream* st)     { jvalue value;  print(get_value(box, &value), &value, st); }
 829   static void print(BasicType type, jvalue* value, outputStream* st);
 830 
 831   static int value_offset_in_bytes(BasicType type) {
 832     return ( type == T_LONG || type == T_DOUBLE ) ? long_value_offset :
 833                                                     value_offset;
 834   }
 835 
 836   // Debugging
 837   friend class JavaClasses;
 838 };
 839 
 840 
 841 
 842 // Interface to java.lang.ref.Reference objects
 843 
 844 class java_lang_ref_Reference: AllStatic {
 845  public:
 846   enum {
 847    hc_referent_offset   = 0,
 848    hc_queue_offset      = 1,
 849    hc_next_offset       = 2,
 850    hc_discovered_offset = 3  // Is not last, see SoftRefs.
 851   };
 852 
 853   static int referent_offset;
 854   static int queue_offset;
 855   static int next_offset;
 856   static int discovered_offset;
 857   static int number_of_fake_oop_fields;
 858 
 859   // Accessors
 860   static inline oop referent(oop ref);
 861   static inline void set_referent(oop ref, oop value);
 862   static inline void set_referent_raw(oop ref, oop value);
 863   static inline HeapWord* referent_addr(oop ref);
 864   static inline oop next(oop ref);
 865   static inline void set_next(oop ref, oop value);
 866   static inline void set_next_raw(oop ref, oop value);
 867   static inline HeapWord* next_addr(oop ref);
 868   static inline oop discovered(oop ref);
 869   static inline void set_discovered(oop ref, oop value);
 870   static inline void set_discovered_raw(oop ref, oop value);
 871   static inline HeapWord* discovered_addr(oop ref);
 872 };
 873 
 874 
 875 // Interface to java.lang.ref.SoftReference objects
 876 
 877 class java_lang_ref_SoftReference: public java_lang_ref_Reference {
 878  public:
 879   enum {
 880    // The timestamp is a long field and may need to be adjusted for alignment.
 881    hc_timestamp_offset  = hc_discovered_offset + 1
 882   };
 883   enum {
 884    hc_static_clock_offset = 0
 885   };
 886 
 887   static int timestamp_offset;
 888   static int static_clock_offset;
 889 
 890   // Accessors
 891   static jlong timestamp(oop ref);
 892 
 893   // Accessors for statics
 894   static jlong clock();
 895   static void set_clock(jlong value);
 896 };
 897 
 898 // Interface to java.lang.invoke.MethodHandle objects
 899 
 900 class MethodHandleEntry;
 901 
 902 class java_lang_invoke_MethodHandle: AllStatic {
 903   friend class JavaClasses;
 904 
 905  private:
 906   static int _type_offset;               // the MethodType of this MH
 907   static int _form_offset;               // the LambdaForm of this MH
 908 
 909   static void compute_offsets();
 910 
 911  public:
 912   // Accessors
 913   static oop            type(oop mh);
 914   static void       set_type(oop mh, oop mtype);
 915 
 916   static oop            form(oop mh);
 917   static void       set_form(oop mh, oop lform);
 918 
 919   // Testers
 920   static bool is_subclass(Klass* klass) {
 921     return klass->is_subclass_of(SystemDictionary::MethodHandle_klass());
 922   }
 923   static bool is_instance(oop obj);
 924 
 925   // Accessors for code generation:
 926   static int type_offset_in_bytes()             { return _type_offset; }
 927   static int form_offset_in_bytes()             { return _form_offset; }
 928 };
 929 
 930 // Interface to java.lang.invoke.DirectMethodHandle objects
 931 
 932 class java_lang_invoke_DirectMethodHandle: AllStatic {
 933   friend class JavaClasses;
 934 
 935  private:
 936   static int _member_offset;               // the MemberName of this DMH
 937 
 938   static void compute_offsets();
 939 
 940  public:
 941   // Accessors
 942   static oop  member(oop mh);
 943 
 944   // Testers
 945   static bool is_subclass(Klass* klass) {
 946     return klass->is_subclass_of(SystemDictionary::DirectMethodHandle_klass());
 947   }
 948   static bool is_instance(oop obj);
 949 
 950   // Accessors for code generation:
 951   static int member_offset_in_bytes()           { return _member_offset; }
 952 };
 953 
 954 // Interface to java.lang.invoke.LambdaForm objects
 955 // (These are a private interface for managing adapter code generation.)
 956 
 957 class java_lang_invoke_LambdaForm: AllStatic {
 958   friend class JavaClasses;
 959 
 960  private:
 961   static int _vmentry_offset;  // type is MemberName
 962 
 963   static void compute_offsets();
 964 
 965  public:
 966   // Accessors
 967   static oop            vmentry(oop lform);
 968   static void       set_vmentry(oop lform, oop invoker);
 969 
 970   // Testers
 971   static bool is_subclass(Klass* klass) {
 972     return SystemDictionary::LambdaForm_klass() != NULL &&
 973       klass->is_subclass_of(SystemDictionary::LambdaForm_klass());
 974   }
 975   static bool is_instance(oop obj);
 976 
 977   // Accessors for code generation:
 978   static int vmentry_offset_in_bytes()          { return _vmentry_offset; }
 979 };
 980 
 981 
 982 // Interface to java.lang.invoke.MemberName objects
 983 // (These are a private interface for Java code to query the class hierarchy.)
 984 
 985 #define MEMBERNAME_INJECTED_FIELDS(macro)                               \
 986   macro(java_lang_invoke_MemberName, vmloader, object_signature, false) \
 987   macro(java_lang_invoke_MemberName, vmindex,  intptr_signature, false) \
 988   macro(java_lang_invoke_MemberName, vmtarget, intptr_signature, false)
 989 
 990 class java_lang_invoke_MemberName: AllStatic {
 991   friend class JavaClasses;
 992 
 993  private:
 994   // From java.lang.invoke.MemberName:
 995   //    private Class<?>   clazz;       // class in which the method is defined
 996   //    private String     name;        // may be null if not yet materialized
 997   //    private Object     type;        // may be null if not yet materialized
 998   //    private int        flags;       // modifier bits; see reflect.Modifier
 999   //    private intptr     vmtarget;    // VM-specific target value
1000   //    private intptr_t   vmindex;     // member index within class or interface
1001   static int _clazz_offset;
1002   static int _name_offset;
1003   static int _type_offset;
1004   static int _flags_offset;
1005   static int _vmtarget_offset;
1006   static int _vmloader_offset;
1007   static int _vmindex_offset;
1008 
1009   static void compute_offsets();
1010 
1011  public:
1012   // Accessors
1013   static oop            clazz(oop mname);
1014   static void       set_clazz(oop mname, oop clazz);
1015 
1016   static oop            type(oop mname);
1017   static void       set_type(oop mname, oop type);
1018 
1019   static oop            name(oop mname);
1020   static void       set_name(oop mname, oop name);
1021 
1022   static int            flags(oop mname);
1023   static void       set_flags(oop mname, int flags);
1024 
1025   static Metadata*      vmtarget(oop mname);
1026   static void       set_vmtarget(oop mname, Metadata* target);
1027 
1028   static intptr_t       vmindex(oop mname);
1029   static void       set_vmindex(oop mname, intptr_t index);
1030 
1031   // Testers
1032   static bool is_subclass(Klass* klass) {
1033     return klass->is_subclass_of(SystemDictionary::MemberName_klass());
1034   }
1035   static bool is_instance(oop obj);
1036 
1037   static bool is_method(oop obj);
1038 
1039   // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):
1040   enum {
1041     MN_IS_METHOD            = 0x00010000, // method (not constructor)
1042     MN_IS_CONSTRUCTOR       = 0x00020000, // constructor
1043     MN_IS_FIELD             = 0x00040000, // field
1044     MN_IS_TYPE              = 0x00080000, // nested type
1045     MN_CALLER_SENSITIVE     = 0x00100000, // @CallerSensitive annotation detected
1046     MN_REFERENCE_KIND_SHIFT = 24, // refKind
1047     MN_REFERENCE_KIND_MASK  = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT,
1048     // The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers:
1049     MN_SEARCH_SUPERCLASSES  = 0x00100000, // walk super classes
1050     MN_SEARCH_INTERFACES    = 0x00200000  // walk implemented interfaces
1051   };
1052 
1053   // Accessors for code generation:
1054   static int clazz_offset_in_bytes()            { return _clazz_offset; }
1055   static int type_offset_in_bytes()             { return _type_offset; }
1056   static int name_offset_in_bytes()             { return _name_offset; }
1057   static int flags_offset_in_bytes()            { return _flags_offset; }
1058   static int vmtarget_offset_in_bytes()         { return _vmtarget_offset; }
1059   static int vmindex_offset_in_bytes()          { return _vmindex_offset; }
1060 };
1061 
1062 
1063 // Interface to java.lang.invoke.MethodType objects
1064 
1065 class java_lang_invoke_MethodType: AllStatic {
1066   friend class JavaClasses;
1067 
1068  private:
1069   static int _rtype_offset;
1070   static int _ptypes_offset;
1071 
1072   static void compute_offsets();
1073 
1074  public:
1075   // Accessors
1076   static oop            rtype(oop mt);
1077   static objArrayOop    ptypes(oop mt);
1078 
1079   static oop            ptype(oop mt, int index);
1080   static int            ptype_count(oop mt);
1081 
1082   static int            ptype_slot_count(oop mt);  // extra counts for long/double
1083   static int            rtype_slot_count(oop mt);  // extra counts for long/double
1084 
1085   static Symbol*        as_signature(oop mt, bool intern_if_not_found, TRAPS);
1086   static void           print_signature(oop mt, outputStream* st);
1087 
1088   static bool is_instance(oop obj);
1089 
1090   static bool equals(oop mt1, oop mt2);
1091 
1092   // Accessors for code generation:
1093   static int rtype_offset_in_bytes()            { return _rtype_offset; }
1094   static int ptypes_offset_in_bytes()           { return _ptypes_offset; }
1095 };
1096 
1097 
1098 // Interface to java.lang.invoke.CallSite objects
1099 
1100 class java_lang_invoke_CallSite: AllStatic {
1101   friend class JavaClasses;
1102 
1103 private:
1104   static int _target_offset;
1105   static int _context_offset;
1106 
1107   static void compute_offsets();
1108 
1109 public:
1110   // Accessors
1111   static oop              target(          oop site);
1112   static void         set_target(          oop site, oop target);
1113   static void         set_target_volatile( oop site, oop target);
1114 
1115   static oop              context(oop site);
1116 
1117   // Testers
1118   static bool is_subclass(Klass* klass) {
1119     return klass->is_subclass_of(SystemDictionary::CallSite_klass());
1120   }
1121   static bool is_instance(oop obj);
1122 
1123   // Accessors for code generation:
1124   static int target_offset_in_bytes()           { return _target_offset; }
1125 };
1126 
1127 // Interface to java.lang.invoke.MethodHandleNatives$CallSiteContext objects
1128 
1129 #define CALLSITECONTEXT_INJECTED_FIELDS(macro) \
1130   macro(java_lang_invoke_MethodHandleNatives_CallSiteContext, vmdependencies, intptr_signature, false)
1131 
1132 class DependencyContext;
1133 
1134 class java_lang_invoke_MethodHandleNatives_CallSiteContext : AllStatic {
1135   friend class JavaClasses;
1136 
1137 private:
1138   static int _vmdependencies_offset;
1139 
1140   static void compute_offsets();
1141 
1142 public:
1143   // Accessors
1144   static DependencyContext vmdependencies(oop context);
1145 
1146   // Testers
1147   static bool is_subclass(Klass* klass) {
1148     return klass->is_subclass_of(SystemDictionary::Context_klass());
1149   }
1150   static bool is_instance(oop obj);
1151 };
1152 
1153 // Interface to java.security.AccessControlContext objects
1154 
1155 class java_security_AccessControlContext: AllStatic {
1156  private:
1157   // Note that for this class the layout changed between JDK1.2 and JDK1.3,
1158   // so we compute the offsets at startup rather than hard-wiring them.
1159   static int _context_offset;
1160   static int _privilegedContext_offset;
1161   static int _isPrivileged_offset;
1162   static int _isAuthorized_offset;
1163 
1164   static void compute_offsets();
1165  public:
1166   static oop create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS);
1167 
1168   static bool is_authorized(Handle context);
1169 
1170   // Debugging/initialization
1171   friend class JavaClasses;
1172 };
1173 
1174 
1175 // Interface to java.lang.ClassLoader objects
1176 
1177 #define CLASSLOADER_INJECTED_FIELDS(macro)                            \
1178   macro(java_lang_ClassLoader, loader_data,  intptr_signature, false)
1179 
1180 class java_lang_ClassLoader : AllStatic {
1181  private:
1182   // The fake offsets are added by the class loader when java.lang.Class is loaded
1183   enum {
1184    hc_parent_offset = 0
1185   };
1186   static int _loader_data_offset;
1187   static bool offsets_computed;
1188   static int parent_offset;
1189   static int parallelCapable_offset;
1190 
1191  public:
1192   static void compute_offsets();
1193 
1194   static ClassLoaderData** loader_data_addr(oop loader);
1195   static ClassLoaderData* loader_data(oop loader);
1196 
1197   static oop parent(oop loader);
1198   static bool isAncestor(oop loader, oop cl);
1199 
1200   // Support for parallelCapable field
1201   static bool parallelCapable(oop the_class_mirror);
1202 
1203   static bool is_trusted_loader(oop loader);
1204 
1205   // Fix for 4474172
1206   static oop  non_reflection_class_loader(oop loader);
1207 
1208   // Testers
1209   static bool is_subclass(Klass* klass) {
1210     return klass->is_subclass_of(SystemDictionary::ClassLoader_klass());
1211   }
1212   static bool is_instance(oop obj);
1213 
1214   // Debugging
1215   friend class JavaClasses;
1216   friend class ClassFileParser; // access to number_of_fake_fields
1217 };
1218 
1219 
1220 // Interface to java.lang.System objects
1221 
1222 class java_lang_System : AllStatic {
1223  private:
1224   enum {
1225    hc_static_in_offset  = 0,
1226    hc_static_out_offset = 1,
1227    hc_static_err_offset = 2,
1228    hc_static_security_offset = 3
1229   };
1230 
1231   static int  static_in_offset;
1232   static int static_out_offset;
1233   static int static_err_offset;
1234   static int static_security_offset;
1235 
1236  public:
1237   static int  in_offset_in_bytes();
1238   static int out_offset_in_bytes();
1239   static int err_offset_in_bytes();
1240 
1241   static bool has_security_manager();
1242 
1243   // Debugging
1244   friend class JavaClasses;
1245 };
1246 
1247 
1248 // Interface to java.lang.StackTraceElement objects
1249 
1250 class java_lang_StackTraceElement: AllStatic {
1251  private:
1252   enum {
1253     hc_declaringClass_offset  = 0,
1254     hc_methodName_offset = 1,
1255     hc_fileName_offset   = 2,
1256     hc_lineNumber_offset = 3
1257   };
1258 
1259   static int declaringClass_offset;
1260   static int methodName_offset;
1261   static int fileName_offset;
1262   static int lineNumber_offset;
1263 
1264   // Setters
1265   static void set_declaringClass(oop element, oop value);
1266   static void set_methodName(oop element, oop value);
1267   static void set_fileName(oop element, oop value);
1268   static void set_lineNumber(oop element, int value);
1269 
1270  public:
1271   // Create an instance of StackTraceElement
1272   static oop create(const methodHandle& method, int bci, TRAPS);
1273 
1274   static void fill_in(Handle element, InstanceKlass* holder, const methodHandle& method,
1275                       int version, int bci, int cpref, TRAPS);
1276 
1277   // Debugging
1278   friend class JavaClasses;
1279 };
1280 
1281 
1282 class Backtrace: AllStatic {
1283  public:
1284   // Helper backtrace functions to store bci|version together.
1285   static int merge_bci_and_version(int bci, int version);
1286   static int merge_mid_and_cpref(int mid, int cpref);
1287   static int bci_at(unsigned int merged);
1288   static int version_at(unsigned int merged);
1289   static int mid_at(unsigned int merged);
1290   static int cpref_at(unsigned int merged);
1291   static int get_line_number(const methodHandle& method, int bci);
1292   static Symbol* get_source_file_name(InstanceKlass* holder, int version);
1293 
1294   // Debugging
1295   friend class JavaClasses;
1296 };
1297 
1298 // Interface to java.lang.StackFrameInfo objects
1299 
1300 #define STACKFRAMEINFO_INJECTED_FIELDS(macro)                      \
1301   macro(java_lang_StackFrameInfo, mid,     short_signature, false) \
1302   macro(java_lang_StackFrameInfo, version, short_signature, false) \
1303   macro(java_lang_StackFrameInfo, cpref,   short_signature, false)
1304 
1305 class java_lang_StackFrameInfo: AllStatic {
1306 private:
1307   static int _declaringClass_offset;
1308   static int _memberName_offset;
1309   static int _bci_offset;
1310   static int _methodName_offset;
1311   static int _fileName_offset;
1312   static int _lineNumber_offset;
1313 
1314   static int _mid_offset;
1315   static int _version_offset;
1316   static int _cpref_offset;
1317 
1318   static Method* get_method(Handle stackFrame, InstanceKlass* holder, TRAPS);
1319   static Symbol* get_file_name(Handle stackFrame, InstanceKlass* holder);
1320 
1321 public:
1322   // Setters
1323   static void set_declaringClass(oop info, oop value);
1324   static void set_method_and_bci(Handle stackFrame, const methodHandle& method, int bci);
1325   static void set_bci(oop info, int value);
1326 
1327   // set method info in an instance of StackFrameInfo
1328   static void fill_methodInfo(Handle info, TRAPS);
1329   static void set_methodName(oop info, oop value);
1330   static void set_fileName(oop info, oop value);
1331   static void set_lineNumber(oop info, int value);
1332 
1333   // these injected fields are only used if -XX:-MemberNameInStackFrame set
1334   static void set_mid(oop info, short value);
1335   static void set_version(oop info, short value);
1336   static void set_cpref(oop info, short value);
1337 
1338   static void compute_offsets();
1339 
1340   // Debugging
1341   friend class JavaClasses;
1342 };
1343 
1344 class java_lang_LiveStackFrameInfo: AllStatic {
1345  private:
1346   static int _monitors_offset;
1347   static int _locals_offset;
1348   static int _operands_offset;
1349 
1350  public:
1351   static void set_monitors(oop info, oop value);
1352   static void set_locals(oop info, oop value);
1353   static void set_operands(oop info, oop value);
1354 
1355   static void compute_offsets();
1356 
1357   // Debugging
1358   friend class JavaClasses;
1359 };
1360 
1361 // Interface to java.lang.AssertionStatusDirectives objects
1362 
1363 class java_lang_AssertionStatusDirectives: AllStatic {
1364  private:
1365   enum {
1366     hc_classes_offset,
1367     hc_classEnabled_offset,
1368     hc_packages_offset,
1369     hc_packageEnabled_offset,
1370     hc_deflt_offset
1371   };
1372 
1373   static int classes_offset;
1374   static int classEnabled_offset;
1375   static int packages_offset;
1376   static int packageEnabled_offset;
1377   static int deflt_offset;
1378 
1379  public:
1380   // Setters
1381   static void set_classes(oop obj, oop val);
1382   static void set_classEnabled(oop obj, oop val);
1383   static void set_packages(oop obj, oop val);
1384   static void set_packageEnabled(oop obj, oop val);
1385   static void set_deflt(oop obj, bool val);
1386   // Debugging
1387   friend class JavaClasses;
1388 };
1389 
1390 
1391 class java_nio_Buffer: AllStatic {
1392  private:
1393   static int _limit_offset;
1394 
1395  public:
1396   static int  limit_offset();
1397   static void compute_offsets();
1398 };
1399 
1400 class java_util_concurrent_locks_AbstractOwnableSynchronizer : AllStatic {
1401  private:
1402   static int  _owner_offset;
1403  public:
1404   static void initialize(TRAPS);
1405   static oop  get_owner_threadObj(oop obj);
1406 };
1407 
1408 // Use to declare fields that need to be injected into Java classes
1409 // for the JVM to use.  The name_index and signature_index are
1410 // declared in vmSymbols.  The may_be_java flag is used to declare
1411 // fields that might already exist in Java but should be injected if
1412 // they don't.  Otherwise the field is unconditionally injected and
1413 // the JVM uses the injected one.  This is to ensure that name
1414 // collisions don't occur.  In general may_be_java should be false
1415 // unless there's a good reason.
1416 
1417 class InjectedField {
1418  public:
1419   const SystemDictionary::WKID klass_id;
1420   const vmSymbols::SID name_index;
1421   const vmSymbols::SID signature_index;
1422   const bool           may_be_java;
1423 
1424 
1425   Klass* klass() const    { return SystemDictionary::well_known_klass(klass_id); }
1426   Symbol* name() const      { return lookup_symbol(name_index); }
1427   Symbol* signature() const { return lookup_symbol(signature_index); }
1428 
1429   int compute_offset();
1430 
1431   // Find the Symbol for this index
1432   static Symbol* lookup_symbol(int symbol_index) {
1433     return vmSymbols::symbol_at((vmSymbols::SID)symbol_index);
1434   }
1435 };
1436 
1437 #define DECLARE_INJECTED_FIELD_ENUM(klass, name, signature, may_be_java) \
1438   klass##_##name##_enum,
1439 
1440 #define ALL_INJECTED_FIELDS(macro)          \
1441   CLASS_INJECTED_FIELDS(macro)              \
1442   CLASSLOADER_INJECTED_FIELDS(macro)        \
1443   MEMBERNAME_INJECTED_FIELDS(macro)         \
1444   CALLSITECONTEXT_INJECTED_FIELDS(macro)    \
1445   STACKFRAMEINFO_INJECTED_FIELDS(macro)
1446 
1447 
1448 // Interface to hard-coded offset checking
1449 
1450 class JavaClasses : AllStatic {
1451  private:
1452 
1453   static InjectedField _injected_fields[];
1454 
1455   static bool check_offset(const char *klass_name, int offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1456   static bool check_static_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1457   static bool check_constant(const char *klass_name, int constant, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1458 
1459  public:
1460   enum InjectedFieldID {
1461     ALL_INJECTED_FIELDS(DECLARE_INJECTED_FIELD_ENUM)
1462     MAX_enum
1463   };
1464 
1465   static int compute_injected_offset(InjectedFieldID id);
1466 
1467   static void compute_hard_coded_offsets();
1468   static void compute_offsets();
1469   static void check_offsets() PRODUCT_RETURN;
1470 
1471   static InjectedField* get_injected(Symbol* class_name, int* field_count);
1472 };
1473 
1474 #undef DECLARE_INJECTED_FIELD_ENUM
1475 
1476 #endif // SHARE_VM_CLASSFILE_JAVACLASSES_HPP