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