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