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