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, const 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, const methodHandle& method, TRAPS);
 549   static void fill_in_stack_trace(Handle throwable, const 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(Handle throwable, outputStream* st);
 555   static void print_stack_trace(Handle throwable, outputStream* st);
 556   // Debugging
 557   friend class JavaClasses;
 558 };
 559 
 560 
 561 // Interface to java.lang.reflect.AccessibleObject objects
 562 
 563 class java_lang_reflect_AccessibleObject: AllStatic {
 564  private:
 565   // Note that to reduce dependencies on the JDK we compute these
 566   // offsets at run-time.
 567   static int override_offset;
 568 
 569   static void compute_offsets();
 570 
 571  public:
 572   // Accessors
 573   static jboolean override(oop reflect);
 574   static void set_override(oop reflect, jboolean value);
 575 
 576   // Debugging
 577   friend class JavaClasses;
 578 };
 579 
 580 
 581 // Interface to java.lang.reflect.Method objects
 582 
 583 class java_lang_reflect_Method : public java_lang_reflect_AccessibleObject {
 584  private:
 585   // Note that to reduce dependencies on the JDK we compute these
 586   // offsets at run-time.
 587   static int clazz_offset;
 588   static int name_offset;
 589   static int returnType_offset;
 590   static int parameterTypes_offset;
 591   static int exceptionTypes_offset;
 592   static int slot_offset;
 593   static int modifiers_offset;
 594   static int signature_offset;
 595   static int annotations_offset;
 596   static int parameter_annotations_offset;
 597   static int annotation_default_offset;
 598   static int type_annotations_offset;
 599 
 600   static void compute_offsets();
 601 
 602  public:
 603   // Allocation
 604   static Handle create(TRAPS);
 605 
 606   // Accessors
 607   static oop clazz(oop reflect);
 608   static void set_clazz(oop reflect, oop value);
 609 
 610   static oop name(oop method);
 611   static void set_name(oop method, oop value);
 612 
 613   static oop return_type(oop method);
 614   static void set_return_type(oop method, oop value);
 615 
 616   static oop parameter_types(oop method);
 617   static void set_parameter_types(oop method, oop value);
 618 
 619   static oop exception_types(oop method);
 620   static void set_exception_types(oop method, oop value);
 621 
 622   static int slot(oop reflect);
 623   static void set_slot(oop reflect, int value);
 624 
 625   static int modifiers(oop method);
 626   static void set_modifiers(oop method, int value);
 627 
 628   static bool has_signature_field();
 629   static oop signature(oop method);
 630   static void set_signature(oop method, oop value);
 631 
 632   static bool has_annotations_field();
 633   static oop annotations(oop method);
 634   static void set_annotations(oop method, oop value);
 635 
 636   static bool has_parameter_annotations_field();
 637   static oop parameter_annotations(oop method);
 638   static void set_parameter_annotations(oop method, oop value);
 639 
 640   static bool has_annotation_default_field();
 641   static oop annotation_default(oop method);
 642   static void set_annotation_default(oop method, oop value);
 643 
 644   static bool has_type_annotations_field();
 645   static oop type_annotations(oop method);
 646   static void set_type_annotations(oop method, oop value);
 647 
 648   // Debugging
 649   friend class JavaClasses;
 650 };
 651 
 652 
 653 // Interface to java.lang.reflect.Constructor objects
 654 
 655 class java_lang_reflect_Constructor : public java_lang_reflect_AccessibleObject {
 656  private:
 657   // Note that to reduce dependencies on the JDK we compute these
 658   // offsets at run-time.
 659   static int clazz_offset;
 660   static int parameterTypes_offset;
 661   static int exceptionTypes_offset;
 662   static int slot_offset;
 663   static int modifiers_offset;
 664   static int signature_offset;
 665   static int annotations_offset;
 666   static int parameter_annotations_offset;
 667   static int type_annotations_offset;
 668 
 669   static void compute_offsets();
 670 
 671  public:
 672   // Allocation
 673   static Handle create(TRAPS);
 674 
 675   // Accessors
 676   static oop clazz(oop reflect);
 677   static void set_clazz(oop reflect, oop value);
 678 
 679   static oop parameter_types(oop constructor);
 680   static void set_parameter_types(oop constructor, oop value);
 681 
 682   static oop exception_types(oop constructor);
 683   static void set_exception_types(oop constructor, oop value);
 684 
 685   static int slot(oop reflect);
 686   static void set_slot(oop reflect, int value);
 687 
 688   static int modifiers(oop constructor);
 689   static void set_modifiers(oop constructor, int value);
 690 
 691   static bool has_signature_field();
 692   static oop signature(oop constructor);
 693   static void set_signature(oop constructor, oop value);
 694 
 695   static bool has_annotations_field();
 696   static oop annotations(oop constructor);
 697   static void set_annotations(oop constructor, oop value);
 698 
 699   static bool has_parameter_annotations_field();
 700   static oop parameter_annotations(oop method);
 701   static void set_parameter_annotations(oop method, oop value);
 702 
 703   static bool has_type_annotations_field();
 704   static oop type_annotations(oop constructor);
 705   static void set_type_annotations(oop constructor, oop value);
 706 
 707   // Debugging
 708   friend class JavaClasses;
 709 };
 710 
 711 
 712 // Interface to java.lang.reflect.Field objects
 713 
 714 class java_lang_reflect_Field : public java_lang_reflect_AccessibleObject {
 715  private:
 716   // Note that to reduce dependencies on the JDK we compute these
 717   // offsets at run-time.
 718   static int clazz_offset;
 719   static int name_offset;
 720   static int type_offset;
 721   static int slot_offset;
 722   static int modifiers_offset;
 723   static int signature_offset;
 724   static int annotations_offset;
 725   static int type_annotations_offset;
 726 
 727   static void compute_offsets();
 728 
 729  public:
 730   // Allocation
 731   static Handle create(TRAPS);
 732 
 733   // Accessors
 734   static oop clazz(oop reflect);
 735   static void set_clazz(oop reflect, oop value);
 736 
 737   static oop name(oop field);
 738   static void set_name(oop field, oop value);
 739 
 740   static oop type(oop field);
 741   static void set_type(oop field, oop value);
 742 
 743   static int slot(oop reflect);
 744   static void set_slot(oop reflect, int value);
 745 
 746   static int modifiers(oop field);
 747   static void set_modifiers(oop field, int value);
 748 
 749   static bool has_signature_field();
 750   static oop signature(oop constructor);
 751   static void set_signature(oop constructor, oop value);
 752 
 753   static bool has_annotations_field();
 754   static oop annotations(oop constructor);
 755   static void set_annotations(oop constructor, oop value);
 756 
 757   static bool has_parameter_annotations_field();
 758   static oop parameter_annotations(oop method);
 759   static void set_parameter_annotations(oop method, oop value);
 760 
 761   static bool has_annotation_default_field();
 762   static oop annotation_default(oop method);
 763   static void set_annotation_default(oop method, oop value);
 764 
 765   static bool has_type_annotations_field();
 766   static oop type_annotations(oop field);
 767   static void set_type_annotations(oop field, oop value);
 768 
 769   // Debugging
 770   friend class JavaClasses;
 771 };
 772 
 773 class java_lang_reflect_Parameter {
 774  private:
 775   // Note that to reduce dependencies on the JDK we compute these
 776   // offsets at run-time.
 777   static int name_offset;
 778   static int modifiers_offset;
 779   static int index_offset;
 780   static int executable_offset;
 781 
 782   static void compute_offsets();
 783 
 784  public:
 785   // Allocation
 786   static Handle create(TRAPS);
 787 
 788   // Accessors
 789   static oop name(oop field);
 790   static void set_name(oop field, oop value);
 791 
 792   static int index(oop reflect);
 793   static void set_index(oop reflect, int value);
 794 
 795   static int modifiers(oop reflect);
 796   static void set_modifiers(oop reflect, int value);
 797 
 798   static oop executable(oop constructor);
 799   static void set_executable(oop constructor, oop value);
 800 
 801   friend class JavaClasses;
 802 };
 803 
 804 // Interface to sun.reflect.ConstantPool objects
 805 class sun_reflect_ConstantPool {
 806  private:
 807   // Note that to reduce dependencies on the JDK we compute these
 808   // offsets at run-time.
 809   static int _oop_offset;
 810 
 811   static void compute_offsets();
 812 
 813  public:
 814   // Allocation
 815   static Handle create(TRAPS);
 816 
 817   // Accessors
 818   static void set_cp(oop reflect, ConstantPool* value);
 819   static int oop_offset() {
 820     return _oop_offset;
 821   }
 822 
 823   static ConstantPool* get_cp(oop reflect);
 824 
 825   // Debugging
 826   friend class JavaClasses;
 827 };
 828 
 829 // Interface to sun.reflect.UnsafeStaticFieldAccessorImpl objects
 830 class sun_reflect_UnsafeStaticFieldAccessorImpl {
 831  private:
 832   static int _base_offset;
 833   static void compute_offsets();
 834 
 835  public:
 836   static int base_offset() {
 837     return _base_offset;
 838   }
 839 
 840   // Debugging
 841   friend class JavaClasses;
 842 };
 843 
 844 // Interface to java.lang primitive type boxing objects:
 845 //  - java.lang.Boolean
 846 //  - java.lang.Character
 847 //  - java.lang.Float
 848 //  - java.lang.Double
 849 //  - java.lang.Byte
 850 //  - java.lang.Short
 851 //  - java.lang.Integer
 852 //  - java.lang.Long
 853 
 854 // This could be separated out into 8 individual classes.
 855 
 856 class java_lang_boxing_object: AllStatic {
 857  private:
 858   enum {
 859    hc_value_offset = 0
 860   };
 861   static int value_offset;
 862   static int long_value_offset;
 863 
 864   static oop initialize_and_allocate(BasicType type, TRAPS);
 865  public:
 866   // Allocation. Returns a boxed value, or NULL for invalid type.
 867   static oop create(BasicType type, jvalue* value, TRAPS);
 868   // Accessors. Returns the basic type being boxed, or T_ILLEGAL for invalid oop.
 869   static BasicType get_value(oop box, jvalue* value);
 870   static BasicType set_value(oop box, jvalue* value);
 871   static BasicType basic_type(oop box);
 872   static bool is_instance(oop box)                 { return basic_type(box) != T_ILLEGAL; }
 873   static bool is_instance(oop box, BasicType type) { return basic_type(box) == type; }
 874   static void print(oop box, outputStream* st)     { jvalue value;  print(get_value(box, &value), &value, st); }
 875   static void print(BasicType type, jvalue* value, outputStream* st);
 876 
 877   static int value_offset_in_bytes(BasicType type) {
 878     return ( type == T_LONG || type == T_DOUBLE ) ? long_value_offset :
 879                                                     value_offset;
 880   }
 881 
 882   // Debugging
 883   friend class JavaClasses;
 884 };
 885 
 886 
 887 
 888 // Interface to java.lang.ref.Reference objects
 889 
 890 class java_lang_ref_Reference: AllStatic {
 891  public:
 892   enum {
 893    hc_referent_offset   = 0,
 894    hc_queue_offset      = 1,
 895    hc_next_offset       = 2,
 896    hc_discovered_offset = 3  // Is not last, see SoftRefs.
 897   };
 898   enum {
 899    hc_static_lock_offset    = 0,
 900    hc_static_pending_offset = 1
 901   };
 902 
 903   static int referent_offset;
 904   static int queue_offset;
 905   static int next_offset;
 906   static int discovered_offset;
 907   static int static_lock_offset;
 908   static int static_pending_offset;
 909   static int number_of_fake_oop_fields;
 910 
 911   // Accessors
 912   static oop referent(oop ref) {
 913     return ref->obj_field(referent_offset);
 914   }
 915   static void set_referent(oop ref, oop value) {
 916     ref->obj_field_put(referent_offset, value);
 917   }
 918   static void set_referent_raw(oop ref, oop value) {
 919     ref->obj_field_put_raw(referent_offset, value);
 920   }
 921   static HeapWord* referent_addr(oop ref) {
 922     return ref->obj_field_addr<HeapWord>(referent_offset);
 923   }
 924   static oop next(oop ref) {
 925     return ref->obj_field(next_offset);
 926   }
 927   static void set_next(oop ref, oop value) {
 928     ref->obj_field_put(next_offset, value);
 929   }
 930   static void set_next_raw(oop ref, oop value) {
 931     ref->obj_field_put_raw(next_offset, value);
 932   }
 933   static HeapWord* next_addr(oop ref) {
 934     return ref->obj_field_addr<HeapWord>(next_offset);
 935   }
 936   static oop discovered(oop ref) {
 937     return ref->obj_field(discovered_offset);
 938   }
 939   static void set_discovered(oop ref, oop value) {
 940     ref->obj_field_put(discovered_offset, value);
 941   }
 942   static void set_discovered_raw(oop ref, oop value) {
 943     ref->obj_field_put_raw(discovered_offset, value);
 944   }
 945   static HeapWord* discovered_addr(oop ref) {
 946     return ref->obj_field_addr<HeapWord>(discovered_offset);
 947   }
 948   // Accessors for statics
 949   static oop  pending_list_lock();
 950   static oop  pending_list();
 951 
 952   static HeapWord*  pending_list_lock_addr();
 953   static HeapWord*  pending_list_addr();
 954 };
 955 
 956 
 957 // Interface to java.lang.ref.SoftReference objects
 958 
 959 class java_lang_ref_SoftReference: public java_lang_ref_Reference {
 960  public:
 961   enum {
 962    // The timestamp is a long field and may need to be adjusted for alignment.
 963    hc_timestamp_offset  = hc_discovered_offset + 1
 964   };
 965   enum {
 966    hc_static_clock_offset = 0
 967   };
 968 
 969   static int timestamp_offset;
 970   static int static_clock_offset;
 971 
 972   // Accessors
 973   static jlong timestamp(oop ref);
 974 
 975   // Accessors for statics
 976   static jlong clock();
 977   static void set_clock(jlong value);
 978 };
 979 
 980 // Interface to java.lang.invoke.MethodHandle objects
 981 
 982 class MethodHandleEntry;
 983 
 984 class java_lang_invoke_MethodHandle: AllStatic {
 985   friend class JavaClasses;
 986 
 987  private:
 988   static int _type_offset;               // the MethodType of this MH
 989   static int _form_offset;               // the LambdaForm of this MH
 990 
 991   static void compute_offsets();
 992 
 993  public:
 994   // Accessors
 995   static oop            type(oop mh);
 996   static void       set_type(oop mh, oop mtype);
 997 
 998   static oop            form(oop mh);
 999   static void       set_form(oop mh, oop lform);
1000 
1001   // Testers
1002   static bool is_subclass(Klass* klass) {
1003     return klass->is_subclass_of(SystemDictionary::MethodHandle_klass());
1004   }
1005   static bool is_instance(oop obj);
1006 
1007   // Accessors for code generation:
1008   static int type_offset_in_bytes()             { return _type_offset; }
1009   static int form_offset_in_bytes()             { return _form_offset; }
1010 };
1011 
1012 // Interface to java.lang.invoke.DirectMethodHandle objects
1013 
1014 class java_lang_invoke_DirectMethodHandle: AllStatic {
1015   friend class JavaClasses;
1016 
1017  private:
1018   static int _member_offset;               // the MemberName of this DMH
1019 
1020   static void compute_offsets();
1021 
1022  public:
1023   // Accessors
1024   static oop  member(oop mh);
1025 
1026   // Testers
1027   static bool is_subclass(Klass* klass) {
1028     return klass->is_subclass_of(SystemDictionary::DirectMethodHandle_klass());
1029   }
1030   static bool is_instance(oop obj);
1031 
1032   // Accessors for code generation:
1033   static int member_offset_in_bytes()           { return _member_offset; }
1034 };
1035 
1036 // Interface to java.lang.invoke.LambdaForm objects
1037 // (These are a private interface for managing adapter code generation.)
1038 
1039 class java_lang_invoke_LambdaForm: AllStatic {
1040   friend class JavaClasses;
1041 
1042  private:
1043   static int _vmentry_offset;  // type is MemberName
1044 
1045   static void compute_offsets();
1046 
1047  public:
1048   // Accessors
1049   static oop            vmentry(oop lform);
1050   static void       set_vmentry(oop lform, oop invoker);
1051 
1052   // Testers
1053   static bool is_subclass(Klass* klass) {
1054     return SystemDictionary::LambdaForm_klass() != NULL &&
1055       klass->is_subclass_of(SystemDictionary::LambdaForm_klass());
1056   }
1057   static bool is_instance(oop obj);
1058 
1059   // Accessors for code generation:
1060   static int vmentry_offset_in_bytes()          { return _vmentry_offset; }
1061 };
1062 
1063 
1064 // Interface to java.lang.invoke.MemberName objects
1065 // (These are a private interface for Java code to query the class hierarchy.)
1066 
1067 #define MEMBERNAME_INJECTED_FIELDS(macro)                               \
1068   macro(java_lang_invoke_MemberName, vmloader, object_signature, false) \
1069   macro(java_lang_invoke_MemberName, vmindex,  intptr_signature, false) \
1070   macro(java_lang_invoke_MemberName, vmtarget, intptr_signature, false)
1071 
1072 class java_lang_invoke_MemberName: AllStatic {
1073   friend class JavaClasses;
1074 
1075  private:
1076   // From java.lang.invoke.MemberName:
1077   //    private Class<?>   clazz;       // class in which the method is defined
1078   //    private String     name;        // may be null if not yet materialized
1079   //    private Object     type;        // may be null if not yet materialized
1080   //    private int        flags;       // modifier bits; see reflect.Modifier
1081   //    private intptr     vmtarget;    // VM-specific target value
1082   //    private intptr_t   vmindex;     // member index within class or interface
1083   static int _clazz_offset;
1084   static int _name_offset;
1085   static int _type_offset;
1086   static int _flags_offset;
1087   static int _vmtarget_offset;
1088   static int _vmloader_offset;
1089   static int _vmindex_offset;
1090 
1091   static void compute_offsets();
1092 
1093  public:
1094   // Accessors
1095   static oop            clazz(oop mname);
1096   static void       set_clazz(oop mname, oop clazz);
1097 
1098   static oop            type(oop mname);
1099   static void       set_type(oop mname, oop type);
1100 
1101   static oop            name(oop mname);
1102   static void       set_name(oop mname, oop name);
1103 
1104   static int            flags(oop mname);
1105   static void       set_flags(oop mname, int flags);
1106 
1107   static Metadata*      vmtarget(oop mname);
1108   static void       set_vmtarget(oop mname, Metadata* target);
1109 
1110   static intptr_t       vmindex(oop mname);
1111   static void       set_vmindex(oop mname, intptr_t index);
1112 
1113   // Testers
1114   static bool is_subclass(Klass* klass) {
1115     return klass->is_subclass_of(SystemDictionary::MemberName_klass());
1116   }
1117   static bool is_instance(oop obj);
1118 
1119   static bool is_method(oop obj);
1120 
1121   // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):
1122   enum {
1123     MN_IS_METHOD            = 0x00010000, // method (not constructor)
1124     MN_IS_CONSTRUCTOR       = 0x00020000, // constructor
1125     MN_IS_FIELD             = 0x00040000, // field
1126     MN_IS_TYPE              = 0x00080000, // nested type
1127     MN_CALLER_SENSITIVE     = 0x00100000, // @CallerSensitive annotation detected
1128     MN_REFERENCE_KIND_SHIFT = 24, // refKind
1129     MN_REFERENCE_KIND_MASK  = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT,
1130     // The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers:
1131     MN_SEARCH_SUPERCLASSES  = 0x00100000, // walk super classes
1132     MN_SEARCH_INTERFACES    = 0x00200000  // walk implemented interfaces
1133   };
1134 
1135   // Accessors for code generation:
1136   static int clazz_offset_in_bytes()            { return _clazz_offset; }
1137   static int type_offset_in_bytes()             { return _type_offset; }
1138   static int name_offset_in_bytes()             { return _name_offset; }
1139   static int flags_offset_in_bytes()            { return _flags_offset; }
1140   static int vmtarget_offset_in_bytes()         { return _vmtarget_offset; }
1141   static int vmindex_offset_in_bytes()          { return _vmindex_offset; }
1142 };
1143 
1144 
1145 // Interface to java.lang.invoke.MethodType objects
1146 
1147 class java_lang_invoke_MethodType: AllStatic {
1148   friend class JavaClasses;
1149 
1150  private:
1151   static int _rtype_offset;
1152   static int _ptypes_offset;
1153 
1154   static void compute_offsets();
1155 
1156  public:
1157   // Accessors
1158   static oop            rtype(oop mt);
1159   static objArrayOop    ptypes(oop mt);
1160 
1161   static oop            ptype(oop mt, int index);
1162   static int            ptype_count(oop mt);
1163 
1164   static int            ptype_slot_count(oop mt);  // extra counts for long/double
1165   static int            rtype_slot_count(oop mt);  // extra counts for long/double
1166 
1167   static Symbol*        as_signature(oop mt, bool intern_if_not_found, TRAPS);
1168   static void           print_signature(oop mt, outputStream* st);
1169 
1170   static bool is_instance(oop obj);
1171 
1172   static bool equals(oop mt1, oop mt2);
1173 
1174   // Accessors for code generation:
1175   static int rtype_offset_in_bytes()            { return _rtype_offset; }
1176   static int ptypes_offset_in_bytes()           { return _ptypes_offset; }
1177 };
1178 
1179 
1180 // Interface to java.lang.invoke.CallSite objects
1181 
1182 class java_lang_invoke_CallSite: AllStatic {
1183   friend class JavaClasses;
1184 
1185 private:
1186   static int _target_offset;
1187   static int _context_offset;
1188 
1189   static void compute_offsets();
1190 
1191 public:
1192   // Accessors
1193   static oop              target(          oop site);
1194   static void         set_target(          oop site, oop target);
1195   static void         set_target_volatile( oop site, oop target);
1196 
1197   static oop              context(oop site);
1198 
1199   // Testers
1200   static bool is_subclass(Klass* klass) {
1201     return klass->is_subclass_of(SystemDictionary::CallSite_klass());
1202   }
1203   static bool is_instance(oop obj);
1204 
1205   // Accessors for code generation:
1206   static int target_offset_in_bytes()           { return _target_offset; }
1207 };
1208 
1209 // Interface to java.lang.invoke.MethodHandleNatives$CallSiteContext objects
1210 
1211 #define CALLSITECONTEXT_INJECTED_FIELDS(macro) \
1212   macro(java_lang_invoke_MethodHandleNatives_CallSiteContext, vmdependencies, intptr_signature, false)
1213 
1214 class DependencyContext;
1215 
1216 class java_lang_invoke_MethodHandleNatives_CallSiteContext : AllStatic {
1217   friend class JavaClasses;
1218 
1219 private:
1220   static int _vmdependencies_offset;
1221 
1222   static void compute_offsets();
1223 
1224 public:
1225   // Accessors
1226   static DependencyContext vmdependencies(oop context);
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(const methodHandle& method, int bci, TRAPS);
1356 
1357   // Debugging
1358   friend class JavaClasses;
1359 };
1360 
1361 
1362 class Backtrace: AllStatic {
1363  public:
1364   // Helper backtrace functions to store bci|version together.
1365   static int merge_bci_and_version(int bci, int version);
1366   static int merge_mid_and_cpref(int mid, int cpref);
1367   static int bci_at(unsigned int merged);
1368   static int version_at(unsigned int merged);
1369   static int mid_at(unsigned int merged);
1370   static int cpref_at(unsigned int merged);
1371   static int get_line_number(const methodHandle& method, int bci);
1372   static Symbol* get_source_file_name(InstanceKlass* holder, int version);
1373 
1374   // Debugging
1375   friend class JavaClasses;
1376 };
1377 
1378 // Interface to java.lang.StackFrameInfo objects
1379 
1380 #define STACKFRAMEINFO_INJECTED_FIELDS(macro)                      \
1381   macro(java_lang_StackFrameInfo, mid,     short_signature, false) \
1382   macro(java_lang_StackFrameInfo, version, short_signature, false) \
1383   macro(java_lang_StackFrameInfo, cpref,   short_signature, false)
1384 
1385 class java_lang_StackFrameInfo: AllStatic {
1386 private:
1387   static int _declaringClass_offset;
1388   static int _memberName_offset;
1389   static int _bci_offset;
1390   static int _methodName_offset;
1391   static int _fileName_offset;
1392   static int _lineNumber_offset;
1393 
1394   static int _mid_offset;
1395   static int _version_offset;
1396   static int _cpref_offset;
1397 
1398   static Method* get_method(Handle stackFrame, InstanceKlass* holder, TRAPS);
1399   static Symbol* get_file_name(Handle stackFrame, InstanceKlass* holder);
1400 
1401 public:
1402   // Setters
1403   static void set_declaringClass(oop info, oop value);
1404   static void set_method_and_bci(Handle stackFrame, const methodHandle& method, int bci);
1405   static void set_bci(oop info, int value);
1406 
1407   // set method info in an instance of StackFrameInfo
1408   static void fill_methodInfo(Handle info, TRAPS);
1409   static void set_methodName(oop info, oop value);
1410   static void set_fileName(oop info, oop value);
1411   static void set_lineNumber(oop info, int value);
1412 
1413   // these injected fields are only used if -XX:-MemberNameInStackFrame set
1414   static void set_mid(oop info, short value);
1415   static void set_version(oop info, short value);
1416   static void set_cpref(oop info, short value);
1417 
1418   static void compute_offsets();
1419 
1420   // Debugging
1421   friend class JavaClasses;
1422 };
1423 
1424 class java_lang_LiveStackFrameInfo: AllStatic {
1425  private:
1426   static int _monitors_offset;
1427   static int _locals_offset;
1428   static int _operands_offset;
1429 
1430  public:
1431   static void set_monitors(oop info, oop value);
1432   static void set_locals(oop info, oop value);
1433   static void set_operands(oop info, oop value);
1434 
1435   static void compute_offsets();
1436 
1437   // Debugging
1438   friend class JavaClasses;
1439 };
1440 
1441 // Interface to java.lang.AssertionStatusDirectives objects
1442 
1443 class java_lang_AssertionStatusDirectives: AllStatic {
1444  private:
1445   enum {
1446     hc_classes_offset,
1447     hc_classEnabled_offset,
1448     hc_packages_offset,
1449     hc_packageEnabled_offset,
1450     hc_deflt_offset
1451   };
1452 
1453   static int classes_offset;
1454   static int classEnabled_offset;
1455   static int packages_offset;
1456   static int packageEnabled_offset;
1457   static int deflt_offset;
1458 
1459  public:
1460   // Setters
1461   static void set_classes(oop obj, oop val);
1462   static void set_classEnabled(oop obj, oop val);
1463   static void set_packages(oop obj, oop val);
1464   static void set_packageEnabled(oop obj, oop val);
1465   static void set_deflt(oop obj, bool val);
1466   // Debugging
1467   friend class JavaClasses;
1468 };
1469 
1470 
1471 class java_nio_Buffer: AllStatic {
1472  private:
1473   static int _limit_offset;
1474 
1475  public:
1476   static int  limit_offset();
1477   static void compute_offsets();
1478 };
1479 
1480 class java_util_concurrent_locks_AbstractOwnableSynchronizer : AllStatic {
1481  private:
1482   static int  _owner_offset;
1483  public:
1484   static void initialize(TRAPS);
1485   static oop  get_owner_threadObj(oop obj);
1486 };
1487 
1488 // Use to declare fields that need to be injected into Java classes
1489 // for the JVM to use.  The name_index and signature_index are
1490 // declared in vmSymbols.  The may_be_java flag is used to declare
1491 // fields that might already exist in Java but should be injected if
1492 // they don't.  Otherwise the field is unconditionally injected and
1493 // the JVM uses the injected one.  This is to ensure that name
1494 // collisions don't occur.  In general may_be_java should be false
1495 // unless there's a good reason.
1496 
1497 class InjectedField {
1498  public:
1499   const SystemDictionary::WKID klass_id;
1500   const vmSymbols::SID name_index;
1501   const vmSymbols::SID signature_index;
1502   const bool           may_be_java;
1503 
1504 
1505   Klass* klass() const    { return SystemDictionary::well_known_klass(klass_id); }
1506   Symbol* name() const      { return lookup_symbol(name_index); }
1507   Symbol* signature() const { return lookup_symbol(signature_index); }
1508 
1509   int compute_offset();
1510 
1511   // Find the Symbol for this index
1512   static Symbol* lookup_symbol(int symbol_index) {
1513     return vmSymbols::symbol_at((vmSymbols::SID)symbol_index);
1514   }
1515 };
1516 
1517 #define DECLARE_INJECTED_FIELD_ENUM(klass, name, signature, may_be_java) \
1518   klass##_##name##_enum,
1519 
1520 #define ALL_INJECTED_FIELDS(macro)          \
1521   CLASS_INJECTED_FIELDS(macro)              \
1522   CLASSLOADER_INJECTED_FIELDS(macro)        \
1523   MEMBERNAME_INJECTED_FIELDS(macro)         \
1524   CALLSITECONTEXT_INJECTED_FIELDS(macro)    \
1525   STACKFRAMEINFO_INJECTED_FIELDS(macro)
1526 
1527 
1528 // Interface to hard-coded offset checking
1529 
1530 class JavaClasses : AllStatic {
1531  private:
1532 
1533   static InjectedField _injected_fields[];
1534 
1535   static bool check_offset(const char *klass_name, int offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1536   static bool check_static_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1537   static bool check_constant(const char *klass_name, int constant, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1538 
1539  public:
1540   enum InjectedFieldID {
1541     ALL_INJECTED_FIELDS(DECLARE_INJECTED_FIELD_ENUM)
1542     MAX_enum
1543   };
1544 
1545   static int compute_injected_offset(InjectedFieldID id);
1546 
1547   static void compute_hard_coded_offsets();
1548   static void compute_offsets();
1549   static void check_offsets() PRODUCT_RETURN;
1550 
1551   static InjectedField* get_injected(Symbol* class_name, int* field_count);
1552 };
1553 
1554 #undef DECLARE_INJECTED_FIELD_ENUM
1555 
1556 #endif // SHARE_VM_CLASSFILE_JAVACLASSES_HPP