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