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