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