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