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   friend class JVMCIVMStructs;
 244 
 245  private:
 246   // The fake offsets are added by the class loader when java.lang.Class is loaded
 247 
 248   static int _klass_offset;
 249   static int _array_klass_offset;
 250 
 251   static int _oop_size_offset;
 252   static int _static_oop_field_count_offset;
 253 
 254   static int _protection_domain_offset;
 255   static int _init_lock_offset;
 256   static int _signers_offset;
 257   static int _class_loader_offset;
 258   static int _component_mirror_offset;
 259 
 260   static bool offsets_computed;
 261   static int classRedefinedCount_offset;
 262 
 263   static GrowableArray<Klass*>* _fixup_mirror_list;
 264 
 265   static void set_init_lock(oop java_class, oop init_lock);
 266   static void set_protection_domain(oop java_class, oop protection_domain);
 267   static void set_class_loader(oop java_class, oop class_loader);
 268   static void set_component_mirror(oop java_class, oop comp_mirror);
 269   static void initialize_mirror_fields(KlassHandle k, Handle mirror, Handle protection_domain, TRAPS);
 270  public:
 271   static void compute_offsets();
 272 
 273   // Instance creation
 274   static void create_mirror(KlassHandle k, Handle class_loader,
 275                             Handle protection_domain, TRAPS);
 276   static void fixup_mirror(KlassHandle k, TRAPS);
 277   static oop  create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS);
 278   // Conversion
 279   static Klass* as_Klass(oop java_class);
 280   static void set_klass(oop java_class, Klass* klass);
 281   static BasicType as_BasicType(oop java_class, Klass** reference_klass = NULL);
 282   static BasicType as_BasicType(oop java_class, KlassHandle* reference_klass) {
 283     Klass* refk_oop = NULL;
 284     BasicType result = as_BasicType(java_class, &refk_oop);
 285     (*reference_klass) = KlassHandle(refk_oop);
 286     return result;
 287   }
 288   static Symbol* as_signature(oop java_class, bool intern_if_not_found, TRAPS);
 289   static void print_signature(oop java_class, outputStream *st);
 290   static const char* as_external_name(oop java_class);
 291   // Testing
 292   static bool is_instance(oop obj);
 293 
 294   static bool is_primitive(oop java_class);
 295   static BasicType primitive_type(oop java_class);
 296   static oop primitive_mirror(BasicType t);
 297   // JVM_NewArray support
 298   static Klass* array_klass(oop java_class);
 299   static void set_array_klass(oop java_class, Klass* klass);
 300   // compiler support for class operations
 301   static int klass_offset_in_bytes()                { return _klass_offset; }
 302   static int array_klass_offset_in_bytes()          { return _array_klass_offset; }
 303   // Support for classRedefinedCount field
 304   static int classRedefinedCount(oop the_class_mirror);
 305   static void set_classRedefinedCount(oop the_class_mirror, int value);
 306 
 307   // Support for embedded per-class oops
 308   static oop  protection_domain(oop java_class);
 309   static oop  init_lock(oop java_class);
 310   static oop  component_mirror(oop java_class);
 311   static objArrayOop  signers(oop java_class);
 312   static void set_signers(oop java_class, objArrayOop signers);
 313 
 314   static oop class_loader(oop java_class);
 315 
 316   static int oop_size(oop java_class);
 317   static void set_oop_size(oop java_class, int size);
 318   static int static_oop_field_count(oop java_class);
 319   static void set_static_oop_field_count(oop java_class, int size);
 320 
 321   static GrowableArray<Klass*>* fixup_mirror_list() {
 322     return _fixup_mirror_list;
 323   }
 324   static void set_fixup_mirror_list(GrowableArray<Klass*>* v) {
 325     _fixup_mirror_list = v;
 326   }
 327   // Debugging
 328   friend class JavaClasses;
 329   friend class InstanceKlass;   // verification code accesses offsets
 330   friend class ClassFileParser; // access to number_of_fake_fields
 331 };
 332 
 333 // Interface to java.lang.Thread objects
 334 
 335 class java_lang_Thread : AllStatic {
 336  private:
 337   // Note that for this class the layout changed between JDK1.2 and JDK1.3,
 338   // so we compute the offsets at startup rather than hard-wiring them.
 339   static int _name_offset;
 340   static int _group_offset;
 341   static int _contextClassLoader_offset;
 342   static int _inheritedAccessControlContext_offset;
 343   static int _priority_offset;
 344   static int _eetop_offset;
 345   static int _daemon_offset;
 346   static int _stillborn_offset;
 347   static int _stackSize_offset;
 348   static int _tid_offset;
 349   static int _thread_status_offset;
 350   static int _park_blocker_offset;
 351   static int _park_event_offset ;
 352 
 353   static void compute_offsets();
 354 
 355  public:
 356   // Instance creation
 357   static oop create();
 358   // Returns the JavaThread associated with the thread obj
 359   static JavaThread* thread(oop java_thread);
 360   // Set JavaThread for instance
 361   static void set_thread(oop java_thread, JavaThread* thread);
 362   // Name
 363   static oop name(oop java_thread);
 364   static void set_name(oop java_thread, oop name);
 365   // Priority
 366   static ThreadPriority priority(oop java_thread);
 367   static void set_priority(oop java_thread, ThreadPriority priority);
 368   // Thread group
 369   static oop  threadGroup(oop java_thread);
 370   // Stillborn
 371   static bool is_stillborn(oop java_thread);
 372   static void set_stillborn(oop java_thread);
 373   // Alive (NOTE: this is not really a field, but provides the correct
 374   // definition without doing a Java call)
 375   static bool is_alive(oop java_thread);
 376   // Daemon
 377   static bool is_daemon(oop java_thread);
 378   static void set_daemon(oop java_thread);
 379   // Context ClassLoader
 380   static oop context_class_loader(oop java_thread);
 381   // Control context
 382   static oop inherited_access_control_context(oop java_thread);
 383   // Stack size hint
 384   static jlong stackSize(oop java_thread);
 385   // Thread ID
 386   static jlong thread_id(oop java_thread);
 387 
 388   // Blocker object responsible for thread parking
 389   static oop park_blocker(oop java_thread);
 390 
 391   // Pointer to type-stable park handler, encoded as jlong.
 392   // Should be set when apparently null
 393   // For details, see unsafe.cpp Unsafe_Unpark
 394   static jlong park_event(oop java_thread);
 395   static bool set_park_event(oop java_thread, jlong ptr);
 396 
 397   // Java Thread Status for JVMTI and M&M use.
 398   // This thread status info is saved in threadStatus field of
 399   // java.lang.Thread java class.
 400   enum ThreadStatus {
 401     NEW                      = 0,
 402     RUNNABLE                 = JVMTI_THREAD_STATE_ALIVE +          // runnable / running
 403                                JVMTI_THREAD_STATE_RUNNABLE,
 404     SLEEPING                 = JVMTI_THREAD_STATE_ALIVE +          // Thread.sleep()
 405                                JVMTI_THREAD_STATE_WAITING +
 406                                JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
 407                                JVMTI_THREAD_STATE_SLEEPING,
 408     IN_OBJECT_WAIT           = JVMTI_THREAD_STATE_ALIVE +          // Object.wait()
 409                                JVMTI_THREAD_STATE_WAITING +
 410                                JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
 411                                JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
 412     IN_OBJECT_WAIT_TIMED     = JVMTI_THREAD_STATE_ALIVE +          // Object.wait(long)
 413                                JVMTI_THREAD_STATE_WAITING +
 414                                JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
 415                                JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
 416     PARKED                   = JVMTI_THREAD_STATE_ALIVE +          // LockSupport.park()
 417                                JVMTI_THREAD_STATE_WAITING +
 418                                JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
 419                                JVMTI_THREAD_STATE_PARKED,
 420     PARKED_TIMED             = JVMTI_THREAD_STATE_ALIVE +          // LockSupport.park(long)
 421                                JVMTI_THREAD_STATE_WAITING +
 422                                JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
 423                                JVMTI_THREAD_STATE_PARKED,
 424     BLOCKED_ON_MONITOR_ENTER = JVMTI_THREAD_STATE_ALIVE +          // (re-)entering a synchronization block
 425                                JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER,
 426     TERMINATED               = JVMTI_THREAD_STATE_TERMINATED
 427   };
 428   // Write thread status info to threadStatus field of java.lang.Thread.
 429   static void set_thread_status(oop java_thread_oop, ThreadStatus status);
 430   // Read thread status info from threadStatus field of java.lang.Thread.
 431   static ThreadStatus get_thread_status(oop java_thread_oop);
 432 
 433   static const char*  thread_status_name(oop java_thread_oop);
 434 
 435   // Debugging
 436   friend class JavaClasses;
 437 };
 438 
 439 // Interface to java.lang.ThreadGroup objects
 440 
 441 class java_lang_ThreadGroup : AllStatic {
 442  private:
 443   static int _parent_offset;
 444   static int _name_offset;
 445   static int _threads_offset;
 446   static int _groups_offset;
 447   static int _maxPriority_offset;
 448   static int _destroyed_offset;
 449   static int _daemon_offset;
 450   static int _vmAllowSuspension_offset;
 451   static int _nthreads_offset;
 452   static int _ngroups_offset;
 453 
 454   static void compute_offsets();
 455 
 456  public:
 457   // parent ThreadGroup
 458   static oop  parent(oop java_thread_group);
 459   // name
 460   static const char* name(oop java_thread_group);
 461   // ("name as oop" accessor is not necessary)
 462   // Number of threads in group
 463   static int nthreads(oop java_thread_group);
 464   // threads
 465   static objArrayOop threads(oop java_thread_group);
 466   // Number of threads in group
 467   static int ngroups(oop java_thread_group);
 468   // groups
 469   static objArrayOop groups(oop java_thread_group);
 470   // maxPriority in group
 471   static ThreadPriority maxPriority(oop java_thread_group);
 472   // Destroyed
 473   static bool is_destroyed(oop java_thread_group);
 474   // Daemon
 475   static bool is_daemon(oop java_thread_group);
 476   // vmAllowSuspension
 477   static bool is_vmAllowSuspension(oop java_thread_group);
 478   // Debugging
 479   friend class JavaClasses;
 480 };
 481 
 482 
 483 
 484 // Interface to java.lang.Throwable objects
 485 
 486 class java_lang_Throwable: AllStatic {
 487   friend class BacktraceBuilder;
 488 
 489  private:
 490   // Offsets
 491   enum {
 492     hc_backtrace_offset     =  0,
 493     hc_detailMessage_offset =  1,
 494     hc_cause_offset         =  2,  // New since 1.4
 495     hc_stackTrace_offset    =  3   // New since 1.4
 496   };
 497   enum {
 498       hc_static_unassigned_stacktrace_offset = 0  // New since 1.7
 499   };
 500   // Trace constants
 501   enum {
 502     trace_methods_offset = 0,
 503     trace_bcis_offset    = 1,
 504     trace_mirrors_offset = 2,
 505     trace_cprefs_offset  = 3,
 506     trace_next_offset    = 4,
 507     trace_size           = 5,
 508     trace_chunk_size     = 32
 509   };
 510 
 511   static int backtrace_offset;
 512   static int detailMessage_offset;
 513   static int cause_offset;
 514   static int stackTrace_offset;
 515   static int static_unassigned_stacktrace_offset;
 516 
 517   // Printing
 518   static char* print_stack_element_to_buffer(Handle mirror, int method, int version, int bci, int cpref);
 519   // StackTrace (programmatic access, new since 1.4)
 520   static void clear_stacktrace(oop throwable);
 521   // No stack trace available
 522   static const char* no_stack_trace_message();
 523   // Stacktrace (post JDK 1.7.0 to allow immutability protocol to be followed)
 524   static void set_stacktrace(oop throwable, oop st_element_array);
 525   static oop unassigned_stacktrace();
 526 
 527  public:
 528   // Backtrace
 529   static oop backtrace(oop throwable);
 530   static void set_backtrace(oop throwable, oop value);
 531   // Needed by JVMTI to filter out this internal field.
 532   static int get_backtrace_offset() { return backtrace_offset;}
 533   static int get_detailMessage_offset() { return detailMessage_offset;}
 534   // Message
 535   static oop message(oop throwable);
 536   static oop message(Handle throwable);
 537   static void set_message(oop throwable, oop value);
 538   static Symbol* detail_message(oop throwable);
 539   static void print_stack_element(outputStream *st, Handle mirror, int method,
 540                                   int version, int bci, int cpref);
 541   static void print_stack_element(outputStream *st, const methodHandle& method, int bci);
 542   static void print_stack_usage(Handle stream);
 543 
 544   // Allocate space for backtrace (created but stack trace not filled in)
 545   static void allocate_backtrace(Handle throwable, TRAPS);
 546   // Fill in current stack trace for throwable with preallocated backtrace (no GC)
 547   static void fill_in_stack_trace_of_preallocated_backtrace(Handle throwable);
 548   // Fill in current stack trace, can cause GC
 549   static void fill_in_stack_trace(Handle throwable, const methodHandle& method, TRAPS);
 550   static void fill_in_stack_trace(Handle throwable, const methodHandle& method = methodHandle());
 551   // Programmatic access to stack trace
 552   static oop  get_stack_trace_element(oop throwable, int index, TRAPS);
 553   static int  get_stack_trace_depth(oop throwable, TRAPS);
 554   // Printing
 555   static void print(Handle throwable, outputStream* st);
 556   static void print_stack_trace(Handle 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  // If not last, see SoftReference and Ephemeron.
 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.WeakReference objects
 959 
 960 class java_lang_ref_WeakReference: public java_lang_ref_Reference {
 961 };
 962 
 963 
 964 // Interface to java.lang.ref.Ephemeron objects
 965 
 966 class java_lang_ref_Ephemeron : public java_lang_ref_WeakReference {
 967  public:
 968   enum {
 969     hc_value_offset = hc_discovered_offset + 1
 970   };
 971    
 972   static int value_offset;
 973 
 974   // Accessors
 975   static oop value(oop ref) {
 976     return ref->obj_field(value_offset);
 977   }
 978   static void set_value(oop ref, oop value) {
 979     ref->obj_field_put(value_offset, value);
 980   }
 981   static void set_value_raw(oop ref, oop value) {
 982     ref->obj_field_put_raw(value_offset, value);
 983   }
 984   static HeapWord* value_addr(oop ref) {
 985     return ref->obj_field_addr<HeapWord>(value_offset);
 986   }    
 987 };
 988 
 989 
 990 // Interface to java.lang.ref.SoftReference objects
 991 
 992 class java_lang_ref_SoftReference: public java_lang_ref_Reference {
 993  public:
 994   enum {
 995    // The timestamp is a long field and may need to be adjusted for alignment.
 996    hc_timestamp_offset  = hc_discovered_offset + 1
 997   };
 998   enum {
 999    hc_static_clock_offset = 0
1000   };
1001 
1002   static int timestamp_offset;
1003   static int static_clock_offset;
1004 
1005   // Accessors
1006   static jlong timestamp(oop ref);
1007 
1008   // Accessors for statics
1009   static jlong clock();
1010   static void set_clock(jlong value);
1011 };
1012 
1013 // Interface to java.lang.invoke.MethodHandle objects
1014 
1015 class MethodHandleEntry;
1016 
1017 class java_lang_invoke_MethodHandle: AllStatic {
1018   friend class JavaClasses;
1019 
1020  private:
1021   static int _type_offset;               // the MethodType of this MH
1022   static int _form_offset;               // the LambdaForm of this MH
1023 
1024   static void compute_offsets();
1025 
1026  public:
1027   // Accessors
1028   static oop            type(oop mh);
1029   static void       set_type(oop mh, oop mtype);
1030 
1031   static oop            form(oop mh);
1032   static void       set_form(oop mh, oop lform);
1033 
1034   // Testers
1035   static bool is_subclass(Klass* klass) {
1036     return klass->is_subclass_of(SystemDictionary::MethodHandle_klass());
1037   }
1038   static bool is_instance(oop obj);
1039 
1040   // Accessors for code generation:
1041   static int type_offset_in_bytes()             { return _type_offset; }
1042   static int form_offset_in_bytes()             { return _form_offset; }
1043 };
1044 
1045 // Interface to java.lang.invoke.DirectMethodHandle objects
1046 
1047 class java_lang_invoke_DirectMethodHandle: AllStatic {
1048   friend class JavaClasses;
1049 
1050  private:
1051   static int _member_offset;               // the MemberName of this DMH
1052 
1053   static void compute_offsets();
1054 
1055  public:
1056   // Accessors
1057   static oop  member(oop mh);
1058 
1059   // Testers
1060   static bool is_subclass(Klass* klass) {
1061     return klass->is_subclass_of(SystemDictionary::DirectMethodHandle_klass());
1062   }
1063   static bool is_instance(oop obj);
1064 
1065   // Accessors for code generation:
1066   static int member_offset_in_bytes()           { return _member_offset; }
1067 };
1068 
1069 // Interface to java.lang.invoke.LambdaForm objects
1070 // (These are a private interface for managing adapter code generation.)
1071 
1072 class java_lang_invoke_LambdaForm: AllStatic {
1073   friend class JavaClasses;
1074 
1075  private:
1076   static int _vmentry_offset;  // type is MemberName
1077 
1078   static void compute_offsets();
1079 
1080  public:
1081   // Accessors
1082   static oop            vmentry(oop lform);
1083   static void       set_vmentry(oop lform, oop invoker);
1084 
1085   // Testers
1086   static bool is_subclass(Klass* klass) {
1087     return SystemDictionary::LambdaForm_klass() != NULL &&
1088       klass->is_subclass_of(SystemDictionary::LambdaForm_klass());
1089   }
1090   static bool is_instance(oop obj);
1091 
1092   // Accessors for code generation:
1093   static int vmentry_offset_in_bytes()          { return _vmentry_offset; }
1094 };
1095 
1096 
1097 // Interface to java.lang.invoke.MemberName objects
1098 // (These are a private interface for Java code to query the class hierarchy.)
1099 
1100 #define MEMBERNAME_INJECTED_FIELDS(macro)                               \
1101   macro(java_lang_invoke_MemberName, vmloader, object_signature, false) \
1102   macro(java_lang_invoke_MemberName, vmindex,  intptr_signature, false) \
1103   macro(java_lang_invoke_MemberName, vmtarget, intptr_signature, false)
1104 
1105 class java_lang_invoke_MemberName: AllStatic {
1106   friend class JavaClasses;
1107 
1108  private:
1109   // From java.lang.invoke.MemberName:
1110   //    private Class<?>   clazz;       // class in which the method is defined
1111   //    private String     name;        // may be null if not yet materialized
1112   //    private Object     type;        // may be null if not yet materialized
1113   //    private int        flags;       // modifier bits; see reflect.Modifier
1114   //    private intptr     vmtarget;    // VM-specific target value
1115   //    private intptr_t   vmindex;     // member index within class or interface
1116   static int _clazz_offset;
1117   static int _name_offset;
1118   static int _type_offset;
1119   static int _flags_offset;
1120   static int _vmtarget_offset;
1121   static int _vmloader_offset;
1122   static int _vmindex_offset;
1123 
1124   static void compute_offsets();
1125 
1126  public:
1127   // Accessors
1128   static oop            clazz(oop mname);
1129   static void       set_clazz(oop mname, oop clazz);
1130 
1131   static oop            type(oop mname);
1132   static void       set_type(oop mname, oop type);
1133 
1134   static oop            name(oop mname);
1135   static void       set_name(oop mname, oop name);
1136 
1137   static int            flags(oop mname);
1138   static void       set_flags(oop mname, int flags);
1139 
1140   static Metadata*      vmtarget(oop mname);
1141   static void       set_vmtarget(oop mname, Metadata* target);
1142 
1143   static intptr_t       vmindex(oop mname);
1144   static void       set_vmindex(oop mname, intptr_t index);
1145 
1146   // Testers
1147   static bool is_subclass(Klass* klass) {
1148     return klass->is_subclass_of(SystemDictionary::MemberName_klass());
1149   }
1150   static bool is_instance(oop obj);
1151 
1152   static bool is_method(oop obj);
1153 
1154   // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):
1155   enum {
1156     MN_IS_METHOD            = 0x00010000, // method (not constructor)
1157     MN_IS_CONSTRUCTOR       = 0x00020000, // constructor
1158     MN_IS_FIELD             = 0x00040000, // field
1159     MN_IS_TYPE              = 0x00080000, // nested type
1160     MN_CALLER_SENSITIVE     = 0x00100000, // @CallerSensitive annotation detected
1161     MN_REFERENCE_KIND_SHIFT = 24, // refKind
1162     MN_REFERENCE_KIND_MASK  = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT,
1163     // The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers:
1164     MN_SEARCH_SUPERCLASSES  = 0x00100000, // walk super classes
1165     MN_SEARCH_INTERFACES    = 0x00200000  // walk implemented interfaces
1166   };
1167 
1168   // Accessors for code generation:
1169   static int clazz_offset_in_bytes()            { return _clazz_offset; }
1170   static int type_offset_in_bytes()             { return _type_offset; }
1171   static int name_offset_in_bytes()             { return _name_offset; }
1172   static int flags_offset_in_bytes()            { return _flags_offset; }
1173   static int vmtarget_offset_in_bytes()         { return _vmtarget_offset; }
1174   static int vmindex_offset_in_bytes()          { return _vmindex_offset; }
1175 };
1176 
1177 
1178 // Interface to java.lang.invoke.MethodType objects
1179 
1180 class java_lang_invoke_MethodType: AllStatic {
1181   friend class JavaClasses;
1182 
1183  private:
1184   static int _rtype_offset;
1185   static int _ptypes_offset;
1186 
1187   static void compute_offsets();
1188 
1189  public:
1190   // Accessors
1191   static oop            rtype(oop mt);
1192   static objArrayOop    ptypes(oop mt);
1193 
1194   static oop            ptype(oop mt, int index);
1195   static int            ptype_count(oop mt);
1196 
1197   static int            ptype_slot_count(oop mt);  // extra counts for long/double
1198   static int            rtype_slot_count(oop mt);  // extra counts for long/double
1199 
1200   static Symbol*        as_signature(oop mt, bool intern_if_not_found, TRAPS);
1201   static void           print_signature(oop mt, outputStream* st);
1202 
1203   static bool is_instance(oop obj);
1204 
1205   static bool equals(oop mt1, oop mt2);
1206 
1207   // Accessors for code generation:
1208   static int rtype_offset_in_bytes()            { return _rtype_offset; }
1209   static int ptypes_offset_in_bytes()           { return _ptypes_offset; }
1210 };
1211 
1212 
1213 // Interface to java.lang.invoke.CallSite objects
1214 
1215 class java_lang_invoke_CallSite: AllStatic {
1216   friend class JavaClasses;
1217 
1218 private:
1219   static int _target_offset;
1220   static int _context_offset;
1221 
1222   static void compute_offsets();
1223 
1224 public:
1225   // Accessors
1226   static oop              target(          oop site);
1227   static void         set_target(          oop site, oop target);
1228   static void         set_target_volatile( oop site, oop target);
1229 
1230   static oop              context(oop site);
1231 
1232   // Testers
1233   static bool is_subclass(Klass* klass) {
1234     return klass->is_subclass_of(SystemDictionary::CallSite_klass());
1235   }
1236   static bool is_instance(oop obj);
1237 
1238   // Accessors for code generation:
1239   static int target_offset_in_bytes()           { return _target_offset; }
1240 };
1241 
1242 // Interface to java.lang.invoke.MethodHandleNatives$CallSiteContext objects
1243 
1244 #define CALLSITECONTEXT_INJECTED_FIELDS(macro) \
1245   macro(java_lang_invoke_MethodHandleNatives_CallSiteContext, vmdependencies, intptr_signature, false)
1246 
1247 class DependencyContext;
1248 
1249 class java_lang_invoke_MethodHandleNatives_CallSiteContext : AllStatic {
1250   friend class JavaClasses;
1251 
1252 private:
1253   static int _vmdependencies_offset;
1254 
1255   static void compute_offsets();
1256 
1257 public:
1258   // Accessors
1259   static DependencyContext vmdependencies(oop context);
1260 
1261   // Testers
1262   static bool is_subclass(Klass* klass) {
1263     return klass->is_subclass_of(SystemDictionary::Context_klass());
1264   }
1265   static bool is_instance(oop obj);
1266 };
1267 
1268 // Interface to java.security.AccessControlContext objects
1269 
1270 class java_security_AccessControlContext: AllStatic {
1271  private:
1272   // Note that for this class the layout changed between JDK1.2 and JDK1.3,
1273   // so we compute the offsets at startup rather than hard-wiring them.
1274   static int _context_offset;
1275   static int _privilegedContext_offset;
1276   static int _isPrivileged_offset;
1277   static int _isAuthorized_offset;
1278 
1279   static void compute_offsets();
1280  public:
1281   static oop create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS);
1282 
1283   static bool is_authorized(Handle context);
1284 
1285   // Debugging/initialization
1286   friend class JavaClasses;
1287 };
1288 
1289 
1290 // Interface to java.lang.ClassLoader objects
1291 
1292 #define CLASSLOADER_INJECTED_FIELDS(macro)                            \
1293   macro(java_lang_ClassLoader, loader_data,  intptr_signature, false)
1294 
1295 class java_lang_ClassLoader : AllStatic {
1296  private:
1297   // The fake offsets are added by the class loader when java.lang.Class is loaded
1298   enum {
1299    hc_parent_offset = 0
1300   };
1301   static int _loader_data_offset;
1302   static bool offsets_computed;
1303   static int parent_offset;
1304   static int parallelCapable_offset;
1305 
1306  public:
1307   static void compute_offsets();
1308 
1309   static ClassLoaderData** loader_data_addr(oop loader);
1310   static ClassLoaderData* loader_data(oop loader);
1311 
1312   static oop parent(oop loader);
1313   static bool isAncestor(oop loader, oop cl);
1314 
1315   // Support for parallelCapable field
1316   static bool parallelCapable(oop the_class_mirror);
1317 
1318   static bool is_trusted_loader(oop loader);
1319 
1320   // Fix for 4474172
1321   static oop  non_reflection_class_loader(oop loader);
1322 
1323   // Testers
1324   static bool is_subclass(Klass* klass) {
1325     return klass->is_subclass_of(SystemDictionary::ClassLoader_klass());
1326   }
1327   static bool is_instance(oop obj);
1328 
1329   // Debugging
1330   friend class JavaClasses;
1331   friend class ClassFileParser; // access to number_of_fake_fields
1332 };
1333 
1334 
1335 // Interface to java.lang.System objects
1336 
1337 class java_lang_System : AllStatic {
1338  private:
1339   enum {
1340    hc_static_in_offset  = 0,
1341    hc_static_out_offset = 1,
1342    hc_static_err_offset = 2,
1343    hc_static_security_offset = 3
1344   };
1345 
1346   static int  static_in_offset;
1347   static int static_out_offset;
1348   static int static_err_offset;
1349   static int static_security_offset;
1350 
1351  public:
1352   static int  in_offset_in_bytes();
1353   static int out_offset_in_bytes();
1354   static int err_offset_in_bytes();
1355 
1356   static bool has_security_manager();
1357 
1358   // Debugging
1359   friend class JavaClasses;
1360 };
1361 
1362 
1363 // Interface to java.lang.StackTraceElement objects
1364 
1365 class java_lang_StackTraceElement: AllStatic {
1366  private:
1367   enum {
1368     hc_declaringClass_offset  = 0,
1369     hc_methodName_offset = 1,
1370     hc_fileName_offset   = 2,
1371     hc_lineNumber_offset = 3
1372   };
1373 
1374   static int declaringClass_offset;
1375   static int methodName_offset;
1376   static int fileName_offset;
1377   static int lineNumber_offset;
1378 
1379  public:
1380   // Setters
1381   static void set_declaringClass(oop element, oop value);
1382   static void set_methodName(oop element, oop value);
1383   static void set_fileName(oop element, oop value);
1384   static void set_lineNumber(oop element, int value);
1385 
1386   // Create an instance of StackTraceElement
1387   static oop create(Handle mirror, int method, int version, int bci, int cpref, TRAPS);
1388   static oop create(const methodHandle& method, int bci, TRAPS);
1389 
1390   // Debugging
1391   friend class JavaClasses;
1392 };
1393 
1394 
1395 class Backtrace: AllStatic {
1396  public:
1397   // Helper backtrace functions to store bci|version together.
1398   static int merge_bci_and_version(int bci, int version);
1399   static int merge_mid_and_cpref(int mid, int cpref);
1400   static int bci_at(unsigned int merged);
1401   static int version_at(unsigned int merged);
1402   static int mid_at(unsigned int merged);
1403   static int cpref_at(unsigned int merged);
1404   static int get_line_number(const methodHandle& method, int bci);
1405   static Symbol* get_source_file_name(InstanceKlass* holder, int version);
1406 
1407   // Debugging
1408   friend class JavaClasses;
1409 };
1410 
1411 // Interface to java.lang.StackFrameInfo objects
1412 
1413 #define STACKFRAMEINFO_INJECTED_FIELDS(macro)                      \
1414   macro(java_lang_StackFrameInfo, mid,     short_signature, false) \
1415   macro(java_lang_StackFrameInfo, version, short_signature, false) \
1416   macro(java_lang_StackFrameInfo, cpref,   short_signature, false)
1417 
1418 class java_lang_StackFrameInfo: AllStatic {
1419 private:
1420   static int _declaringClass_offset;
1421   static int _memberName_offset;
1422   static int _bci_offset;
1423   static int _methodName_offset;
1424   static int _fileName_offset;
1425   static int _lineNumber_offset;
1426 
1427   static int _mid_offset;
1428   static int _version_offset;
1429   static int _cpref_offset;
1430 
1431   static Method* get_method(Handle stackFrame, InstanceKlass* holder, TRAPS);
1432   static Symbol* get_file_name(Handle stackFrame, InstanceKlass* holder);
1433 
1434 public:
1435   // Setters
1436   static void set_declaringClass(oop info, oop value);
1437   static void set_method_and_bci(Handle stackFrame, const methodHandle& method, int bci);
1438   static void set_bci(oop info, int value);
1439 
1440   // set method info in an instance of StackFrameInfo
1441   static void fill_methodInfo(Handle info, TRAPS);
1442   static void set_methodName(oop info, oop value);
1443   static void set_fileName(oop info, oop value);
1444   static void set_lineNumber(oop info, int value);
1445 
1446   // these injected fields are only used if -XX:-MemberNameInStackFrame set
1447   static void set_mid(oop info, short value);
1448   static void set_version(oop info, short value);
1449   static void set_cpref(oop info, short value);
1450 
1451   static void compute_offsets();
1452 
1453   // Debugging
1454   friend class JavaClasses;
1455 };
1456 
1457 class java_lang_LiveStackFrameInfo: AllStatic {
1458  private:
1459   static int _monitors_offset;
1460   static int _locals_offset;
1461   static int _operands_offset;
1462 
1463  public:
1464   static void set_monitors(oop info, oop value);
1465   static void set_locals(oop info, oop value);
1466   static void set_operands(oop info, oop value);
1467 
1468   static void compute_offsets();
1469 
1470   // Debugging
1471   friend class JavaClasses;
1472 };
1473 
1474 // Interface to java.lang.AssertionStatusDirectives objects
1475 
1476 class java_lang_AssertionStatusDirectives: AllStatic {
1477  private:
1478   enum {
1479     hc_classes_offset,
1480     hc_classEnabled_offset,
1481     hc_packages_offset,
1482     hc_packageEnabled_offset,
1483     hc_deflt_offset
1484   };
1485 
1486   static int classes_offset;
1487   static int classEnabled_offset;
1488   static int packages_offset;
1489   static int packageEnabled_offset;
1490   static int deflt_offset;
1491 
1492  public:
1493   // Setters
1494   static void set_classes(oop obj, oop val);
1495   static void set_classEnabled(oop obj, oop val);
1496   static void set_packages(oop obj, oop val);
1497   static void set_packageEnabled(oop obj, oop val);
1498   static void set_deflt(oop obj, bool val);
1499   // Debugging
1500   friend class JavaClasses;
1501 };
1502 
1503 
1504 class java_nio_Buffer: AllStatic {
1505  private:
1506   static int _limit_offset;
1507 
1508  public:
1509   static int  limit_offset();
1510   static void compute_offsets();
1511 };
1512 
1513 class java_util_concurrent_locks_AbstractOwnableSynchronizer : AllStatic {
1514  private:
1515   static int  _owner_offset;
1516  public:
1517   static void initialize(TRAPS);
1518   static oop  get_owner_threadObj(oop obj);
1519 };
1520 
1521 // Use to declare fields that need to be injected into Java classes
1522 // for the JVM to use.  The name_index and signature_index are
1523 // declared in vmSymbols.  The may_be_java flag is used to declare
1524 // fields that might already exist in Java but should be injected if
1525 // they don't.  Otherwise the field is unconditionally injected and
1526 // the JVM uses the injected one.  This is to ensure that name
1527 // collisions don't occur.  In general may_be_java should be false
1528 // unless there's a good reason.
1529 
1530 class InjectedField {
1531  public:
1532   const SystemDictionary::WKID klass_id;
1533   const vmSymbols::SID name_index;
1534   const vmSymbols::SID signature_index;
1535   const bool           may_be_java;
1536 
1537 
1538   Klass* klass() const    { return SystemDictionary::well_known_klass(klass_id); }
1539   Symbol* name() const      { return lookup_symbol(name_index); }
1540   Symbol* signature() const { return lookup_symbol(signature_index); }
1541 
1542   int compute_offset();
1543 
1544   // Find the Symbol for this index
1545   static Symbol* lookup_symbol(int symbol_index) {
1546     return vmSymbols::symbol_at((vmSymbols::SID)symbol_index);
1547   }
1548 };
1549 
1550 #define DECLARE_INJECTED_FIELD_ENUM(klass, name, signature, may_be_java) \
1551   klass##_##name##_enum,
1552 
1553 #define ALL_INJECTED_FIELDS(macro)          \
1554   CLASS_INJECTED_FIELDS(macro)              \
1555   CLASSLOADER_INJECTED_FIELDS(macro)        \
1556   MEMBERNAME_INJECTED_FIELDS(macro)         \
1557   CALLSITECONTEXT_INJECTED_FIELDS(macro)    \
1558   STACKFRAMEINFO_INJECTED_FIELDS(macro)
1559 
1560 
1561 // Interface to hard-coded offset checking
1562 
1563 class JavaClasses : AllStatic {
1564  private:
1565 
1566   static InjectedField _injected_fields[];
1567 
1568   static bool check_offset(const char *klass_name, int offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1569   static bool check_static_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1570   static bool check_constant(const char *klass_name, int constant, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1571 
1572  public:
1573   enum InjectedFieldID {
1574     ALL_INJECTED_FIELDS(DECLARE_INJECTED_FIELD_ENUM)
1575     MAX_enum
1576   };
1577 
1578   static int compute_injected_offset(InjectedFieldID id);
1579 
1580   static void compute_hard_coded_offsets();
1581   static void compute_offsets();
1582   static void check_offsets() PRODUCT_RETURN;
1583 
1584   static InjectedField* get_injected(Symbol* class_name, int* field_count);
1585 };
1586 
1587 #undef DECLARE_INJECTED_FIELD_ENUM
1588 
1589 #endif // SHARE_VM_CLASSFILE_JAVACLASSES_HPP