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