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