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