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 "runtime/handles.hpp"
  32 #include "utilities/macros.hpp"
  33 #include "utilities/vmEnums.hpp"
  34 
  35 class JvmtiThreadState;
  36 class RecordComponent;
  37 
  38 #define CHECK_INIT(offset)  assert(offset != 0, "should be initialized"); return offset;
  39 
  40 // Interface to java.lang.Object objects
  41 
  42 class java_lang_Object : AllStatic {
  43  public:
  44   static void register_natives(TRAPS);
  45 };
  46 
  47 // Interface to java.lang.String objects
  48 
  49 // The flags field is a collection of bits representing boolean values used
  50 // internally by the VM.
  51 #define STRING_INJECTED_FIELDS(macro) \
  52   macro(java_lang_String, flags, byte_signature, false)
  53 
  54 class java_lang_String : AllStatic {
  55  private:
  56   static int _value_offset;
  57   static int _hash_offset;
  58   static int _hashIsZero_offset;
  59   static int _coder_offset;
  60   static int _flags_offset;
  61 
  62   static bool _initialized;
  63 
  64   static Handle basic_create(int length, bool byte_arr, TRAPS);
  65 
  66   static inline void set_coder(oop string, jbyte coder);
  67 
  68   // Bitmasks for values in the injected flags field.
  69   static const uint8_t _deduplication_forbidden_mask = 1 << 0;
  70   static const uint8_t _deduplication_requested_mask = 1 << 1;
  71 
  72   static int flags_offset() { CHECK_INIT(_flags_offset); }
  73   // Return the address of the injected flags field.
  74   static inline uint8_t* flags_addr(oop java_string);
  75   // Test whether the designated bit of the injected flags field is set.
  76   static inline bool is_flag_set(oop java_string, uint8_t flag_mask);
  77   // Atomically test and set the designated bit of the injected flags field,
  78   // returning true if the bit was already set.
  79   static bool test_and_set_flag(oop java_string, uint8_t flag_mask);
  80 
  81   static inline unsigned int hash_code_impl(oop java_string, bool update);
  82 
  83  public:
  84 
  85   // Coders
  86   enum Coder {
  87     CODER_LATIN1 =  0,
  88     CODER_UTF16  =  1
  89   };
  90 
  91   static void compute_offsets();
  92   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
  93 
  94   // Instance creation
  95   static Handle create_from_unicode(const jchar* unicode, int len, TRAPS);
  96   static oop    create_oop_from_unicode(const jchar* unicode, int len, TRAPS);
  97   static Handle create_from_str(const char* utf8_str, TRAPS);
  98   static oop    create_oop_from_str(const char* utf8_str, TRAPS);
  99   static Handle create_from_symbol(Symbol* symbol, TRAPS);
 100   static Handle create_from_platform_dependent_str(const char* str, TRAPS);
 101 
 102   static void set_compact_strings(bool value);
 103 
 104   static int value_offset() { CHECK_INIT(_value_offset); }
 105   static int coder_offset() { CHECK_INIT(_coder_offset); }
 106 
 107   static inline void set_value_raw(oop string, typeArrayOop buffer);
 108   static inline void set_value(oop string, typeArrayOop buffer);
 109 
 110   // Set the deduplication_forbidden flag true.  This flag is sticky; once
 111   // set it never gets cleared.  This is set when a String is interned in
 112   // the StringTable, to prevent string deduplication from changing the
 113   // String's value array.
 114   static inline void set_deduplication_forbidden(oop java_string);
 115 
 116   // Test and set the deduplication_requested flag.  Returns the old value
 117   // of the flag.  This flag is sticky; once set it never gets cleared.
 118   // Some GCs may use this flag when deciding whether to request
 119   // deduplication of a String, to avoid multiple requests for the same
 120   // object.
 121   static inline bool test_and_set_deduplication_requested(oop java_string);
 122 
 123   // Accessors
 124   static inline typeArrayOop value(oop java_string);
 125   static inline typeArrayOop value_no_keepalive(oop java_string);
 126   static inline bool hash_is_set(oop string);
 127   static inline bool is_latin1(oop java_string);
 128   static inline bool deduplication_forbidden(oop java_string);
 129   static inline bool deduplication_requested(oop java_string);
 130   static inline int length(oop java_string);
 131   static inline int length(oop java_string, typeArrayOop string_value);
 132   static int utf8_length(oop java_string);
 133   static int utf8_length(oop java_string, typeArrayOop string_value);
 134 
 135   // String converters
 136   static char*  as_utf8_string(oop java_string);
 137   static char*  as_utf8_string(oop java_string, int& length);
 138   static char*  as_utf8_string_full(oop java_string, char* buf, int buflen, int& length);
 139   static char*  as_utf8_string(oop java_string, char* buf, int buflen);
 140   static char*  as_utf8_string(oop java_string, int start, int len);
 141   static char*  as_utf8_string(oop java_string, typeArrayOop value, char* buf, int buflen);
 142   static char*  as_utf8_string(oop java_string, typeArrayOop value, int start, int len, char* buf, int buflen);
 143   static char*  as_platform_dependent_str(Handle java_string, TRAPS);
 144   static jchar* as_unicode_string(oop java_string, int& length, TRAPS);
 145   static jchar* as_unicode_string_or_null(oop java_string, int& length);
 146   // produce an ascii string with all other values quoted using \u####
 147   static char*  as_quoted_ascii(oop java_string);
 148 
 149   // Compute the hash value for a java.lang.String object which would
 150   // contain the characters passed in.
 151   //
 152   // As the hash value used by the String object itself, in
 153   // String.hashCode().  This value is normally calculated in Java code
 154   // in the String.hashCode method(), but is precomputed for String
 155   // objects in the shared archive file.
 156   // hash P(31) from Kernighan & Ritchie
 157   //
 158   // For this reason, THIS ALGORITHM MUST MATCH String.hashCode().
 159   static unsigned int hash_code(const jchar* s, int len) {
 160     unsigned int h = 0;
 161     while (len-- > 0) {
 162       h = 31*h + (unsigned int) *s;
 163       s++;
 164     }
 165     return h;
 166   }
 167 
 168   static unsigned int hash_code(const jbyte* s, int len) {
 169     unsigned int h = 0;
 170     while (len-- > 0) {
 171       h = 31*h + (((unsigned int) *s) & 0xFF);
 172       s++;
 173     }
 174     return h;
 175   }
 176 
 177   static unsigned int hash_code(oop java_string);
 178   static unsigned int hash_code_noupdate(oop java_string);
 179 
 180   static bool equals(oop java_string, const jchar* chars, int len);
 181   static bool equals(oop str1, oop str2);
 182   static inline bool value_equals(typeArrayOop str_value1, typeArrayOop str_value2);
 183 
 184   // Conversion between '.' and '/' formats, and allocate a String from the result.
 185   static Handle externalize_classname(Symbol* java_name, TRAPS);
 186 
 187   // Conversion
 188   static Symbol* as_symbol(oop java_string);
 189   static Symbol* as_symbol_or_null(oop java_string);
 190 
 191   // Tester
 192   static inline bool is_instance(oop obj);
 193 
 194   // Debugging
 195   static void print(oop java_string, outputStream* st);
 196   friend class JavaClasses;
 197   friend class StringTable;
 198 };
 199 
 200 
 201 // Interface to java.lang.Class objects
 202 
 203 #define CLASS_INJECTED_FIELDS(macro)                                       \
 204   macro(java_lang_Class, klass,                  intptr_signature,  false) \
 205   macro(java_lang_Class, array_klass,            intptr_signature,  false) \
 206   macro(java_lang_Class, oop_size,               int_signature,     false) \
 207   macro(java_lang_Class, static_oop_field_count, int_signature,     false) \
 208   macro(java_lang_Class, protection_domain,      object_signature,  false) \
 209   macro(java_lang_Class, signers,                object_signature,  false) \
 210   macro(java_lang_Class, source_file,            object_signature,  false) \
 211 
 212 class java_lang_Class : AllStatic {
 213   friend class VMStructs;
 214   friend class JVMCIVMStructs;
 215 
 216  private:
 217 
 218   // The fake offsets are added by the class loader when java.lang.Class is loaded
 219 
 220   static int _klass_offset;
 221   static int _array_klass_offset;
 222 
 223   static int _oop_size_offset;
 224   static int _static_oop_field_count_offset;
 225 
 226   static int _protection_domain_offset;
 227   static int _signers_offset;
 228   static int _class_loader_offset;
 229   static int _module_offset;
 230   static int _component_mirror_offset;
 231   static int _name_offset;
 232   static int _source_file_offset;
 233   static int _classData_offset;
 234   static int _classRedefinedCount_offset;
 235 
 236   static bool _offsets_computed;
 237 
 238   static GrowableArray<Klass*>* _fixup_mirror_list;
 239   static GrowableArray<Klass*>* _fixup_module_field_list;
 240 
 241   static void set_protection_domain(oop java_class, oop protection_domain);
 242   static void set_class_loader(oop java_class, oop class_loader);
 243   static void set_component_mirror(oop java_class, oop comp_mirror);
 244   static void initialize_mirror_fields(Klass* k, Handle mirror, Handle protection_domain,
 245                                        Handle classData, TRAPS);
 246   static void set_mirror_module_field(JavaThread* current, Klass* K, Handle mirror, Handle module);
 247  public:
 248   static void allocate_fixup_lists();
 249   static void compute_offsets();
 250 
 251   // Instance creation
 252   static void allocate_mirror(Klass* k, bool is_scratch, Handle protection_domain, Handle classData,
 253                               Handle& mirror, Handle& comp_mirror, TRAPS); // returns mirror and comp_mirror
 254   static void create_mirror(Klass* k, Handle class_loader, Handle module,
 255                             Handle protection_domain, Handle classData, TRAPS);
 256   static void fixup_mirror(Klass* k, TRAPS);
 257   static oop  create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS);
 258 
 259   // Archiving
 260   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 261   static void create_scratch_mirror(Klass* k, TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
 262   static bool restore_archived_mirror(Klass *k, Handle class_loader, Handle module,
 263                                       Handle protection_domain,
 264                                       TRAPS) NOT_CDS_JAVA_HEAP_RETURN_(false);
 265 
 266   static void fixup_module_field(Klass* k, Handle module);
 267 
 268   // Conversion
 269   static Klass* as_Klass(oop java_class);
 270   static void set_klass(oop java_class, Klass* klass);
 271   static BasicType as_BasicType(oop java_class, Klass** reference_klass = nullptr);
 272   static Symbol* as_signature(oop java_class, bool intern_if_not_found);
 273   static void print_signature(oop java_class, outputStream *st);
 274   static const char* as_external_name(oop java_class);
 275   // Testing
 276   static bool is_instance(oop obj);
 277 
 278   static bool is_primitive(oop java_class);
 279   static BasicType primitive_type(oop java_class);
 280   static oop primitive_mirror(BasicType t);
 281   // JVM_NewArray support
 282   static Klass* array_klass_acquire(oop java_class);
 283   static void release_set_array_klass(oop java_class, Klass* klass);
 284   // compiler support for class operations
 285   static int klass_offset()                { CHECK_INIT(_klass_offset); }
 286   static int array_klass_offset()          { CHECK_INIT(_array_klass_offset); }
 287   // Support for classRedefinedCount field
 288   static int classRedefinedCount(oop the_class_mirror);
 289   static void set_classRedefinedCount(oop the_class_mirror, int value);
 290 
 291   // Support for embedded per-class oops
 292   static oop  protection_domain(oop java_class);
 293   static oop  component_mirror(oop java_class);
 294   static objArrayOop  signers(oop java_class);
 295   static void set_signers(oop java_class, objArrayOop signers);
 296   static oop  class_data(oop java_class);
 297   static void set_class_data(oop java_class, oop classData);
 298 
 299   static int component_mirror_offset() { return _component_mirror_offset; }
 300 
 301   static oop class_loader(oop java_class);
 302   static void set_module(oop java_class, oop module);
 303   static oop module(oop java_class);
 304 
 305   static oop name(Handle java_class, TRAPS);
 306 
 307   static oop source_file(oop java_class);
 308   static void set_source_file(oop java_class, oop source_file);
 309 
 310   static size_t oop_size(oop java_class);
 311   static void set_oop_size(HeapWord* java_class, size_t size);
 312   static int static_oop_field_count(oop java_class);
 313   static void set_static_oop_field_count(oop java_class, int size);
 314 
 315   static GrowableArray<Klass*>* fixup_mirror_list() {
 316     return _fixup_mirror_list;
 317   }
 318   static void set_fixup_mirror_list(GrowableArray<Klass*>* v) {
 319     _fixup_mirror_list = v;
 320   }
 321 
 322   static GrowableArray<Klass*>* fixup_module_field_list() {
 323     return _fixup_module_field_list;
 324   }
 325   static void set_fixup_module_field_list(GrowableArray<Klass*>* v) {
 326     _fixup_module_field_list = v;
 327   }
 328 
 329   // Debugging
 330   friend class JavaClasses;
 331 };
 332 
 333 // Interface to java.lang.Thread objects
 334 
 335 #define THREAD_INJECTED_FIELDS(macro)                                  \
 336   macro(java_lang_Thread, jvmti_thread_state, intptr_signature, false) \
 337   macro(java_lang_Thread, jvmti_VTMS_transition_disable_count, int_signature, false) \
 338   macro(java_lang_Thread, jvmti_is_in_VTMS_transition, bool_signature, false) \
 339   JFR_ONLY(macro(java_lang_Thread, jfr_epoch, short_signature, false))
 340 
 341 class java_lang_Thread : AllStatic {
 342   friend class java_lang_VirtualThread;
 343   friend class JVMCIVMStructs;
 344  private:
 345   // Note that for this class the layout changed between JDK1.2 and JDK1.3,
 346   // so we compute the offsets at startup rather than hard-wiring them.
 347   static int _holder_offset;
 348   static int _name_offset;
 349   static int _contextClassLoader_offset;
 350   static int _inheritedAccessControlContext_offset;
 351   static int _eetop_offset;
 352   static int _jvmti_thread_state_offset;
 353   static int _jvmti_VTMS_transition_disable_count_offset;
 354   static int _jvmti_is_in_VTMS_transition_offset;
 355   static int _interrupted_offset;
 356   static int _tid_offset;
 357   static int _continuation_offset;
 358   static int _park_blocker_offset;
 359   static int _scopedValueBindings_offset;
 360   JFR_ONLY(static int _jfr_epoch_offset;)
 361 
 362   static void compute_offsets();
 363 
 364  public:
 365   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 366 
 367   // Returns the JavaThread associated with the thread obj
 368   static JavaThread* thread(oop java_thread);
 369   static JavaThread* thread_acquire(oop java_thread);
 370   // Set JavaThread for instance
 371   static void set_thread(oop java_thread, JavaThread* thread);
 372   static void release_set_thread(oop java_thread, JavaThread* thread);
 373   // FieldHolder
 374   static oop holder(oop java_thread);
 375   // Interrupted status
 376   static bool interrupted(oop java_thread);
 377   static void set_interrupted(oop java_thread, bool val);
 378   // Name
 379   static oop name(oop java_thread);
 380   static void set_name(oop java_thread, oop name);
 381   // Priority
 382   static ThreadPriority priority(oop java_thread);
 383   static void set_priority(oop java_thread, ThreadPriority priority);
 384   // Thread group
 385   static oop  threadGroup(oop java_thread);
 386   // Alive (NOTE: this is not really a field, but provides the correct
 387   // definition without doing a Java call)
 388   static bool is_alive(oop java_thread);
 389   // Daemon
 390   static bool is_daemon(oop java_thread);
 391   static void set_daemon(oop java_thread);
 392   // Context ClassLoader
 393   static oop context_class_loader(oop java_thread);
 394   // Control context
 395   static oop inherited_access_control_context(oop java_thread);
 396   // Stack size hint
 397   static jlong stackSize(oop java_thread);
 398   // Thread ID
 399   static int64_t thread_id(oop java_thread);
 400   static ByteSize thread_id_offset();
 401   // Continuation
 402   static inline oop continuation(oop java_thread);
 403 
 404   static JvmtiThreadState* jvmti_thread_state(oop java_thread);
 405   static void set_jvmti_thread_state(oop java_thread, JvmtiThreadState* state);
 406   static int  VTMS_transition_disable_count(oop java_thread);
 407   static void inc_VTMS_transition_disable_count(oop java_thread);
 408   static void dec_VTMS_transition_disable_count(oop java_thread);
 409   static bool is_in_VTMS_transition(oop java_thread);
 410   static void set_is_in_VTMS_transition(oop java_thread, bool val);
 411   static int  is_in_VTMS_transition_offset();
 412 
 413   // Clear all scoped value bindings on error
 414   static void clear_scopedValueBindings(oop java_thread);
 415 
 416   // Blocker object responsible for thread parking
 417   static oop park_blocker(oop java_thread);
 418 
 419   // Write thread status info to threadStatus field of java.lang.Thread.
 420   static void set_thread_status(oop java_thread_oop, JavaThreadStatus status);
 421   // Read thread status info from threadStatus field of java.lang.Thread.
 422   static JavaThreadStatus get_thread_status(oop java_thread_oop);
 423 
 424   static const char*  thread_status_name(oop java_thread_oop);
 425 
 426   // Fill in current stack trace, can cause GC
 427   static oop async_get_stack_trace(oop java_thread, TRAPS);
 428 
 429   JFR_ONLY(static u2 jfr_epoch(oop java_thread);)
 430   JFR_ONLY(static void set_jfr_epoch(oop java_thread, u2 epoch);)
 431   JFR_ONLY(static int jfr_epoch_offset() { CHECK_INIT(_jfr_epoch_offset); })
 432 
 433   // Debugging
 434   friend class JavaClasses;
 435 };
 436 
 437 // Interface to java.lang.Thread$FieldHolder objects
 438 
 439 class java_lang_Thread_FieldHolder : AllStatic {
 440  private:
 441   static int _group_offset;
 442   static int _priority_offset;
 443   static int _stackSize_offset;
 444   static int _daemon_offset;
 445   static int _thread_status_offset;
 446 
 447   static void compute_offsets();
 448 
 449  public:
 450   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 451 
 452   static oop threadGroup(oop holder);
 453 
 454   static ThreadPriority priority(oop holder);
 455   static void set_priority(oop holder, ThreadPriority priority);
 456 
 457   static jlong stackSize(oop holder);
 458 
 459   static bool is_daemon(oop holder);
 460   static void set_daemon(oop holder, bool val);
 461 
 462   static void set_thread_status(oop holder, JavaThreadStatus status);
 463   static JavaThreadStatus get_thread_status(oop holder);
 464 
 465   friend class JavaClasses;
 466 };
 467 
 468 // Interface to java.lang.Thread$Constants objects
 469 
 470 class java_lang_Thread_Constants : AllStatic {
 471  private:
 472   static int _static_VTHREAD_GROUP_offset;
 473   static int _static_NOT_SUPPORTED_CLASSLOADER_offset;
 474 
 475   static void compute_offsets();
 476   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 477 
 478  public:
 479   static oop get_VTHREAD_GROUP();
 480 
 481   friend class JavaClasses;
 482 };
 483 
 484 // Interface to java.lang.ThreadGroup objects
 485 
 486 class java_lang_ThreadGroup : AllStatic {
 487  private:
 488   static int _parent_offset;
 489   static int _name_offset;
 490   static int _maxPriority_offset;
 491   static int _daemon_offset;
 492 
 493   static void compute_offsets();
 494  public:
 495   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 496 
 497   // parent ThreadGroup
 498   static oop parent(oop java_thread_group);
 499   // name
 500   static const char* name(oop java_thread_group);
 501   // maxPriority in group
 502   static ThreadPriority maxPriority(oop java_thread_group);
 503   // Daemon
 504   static bool is_daemon(oop java_thread_group);
 505 
 506   // Debugging
 507   friend class JavaClasses;
 508 };
 509 
 510 
 511 // Interface to java.lang.VirtualThread objects
 512 
 513 class java_lang_VirtualThread : AllStatic {
 514  private:
 515   static int static_vthread_scope_offset;
 516   static int _carrierThread_offset;
 517   static int _continuation_offset;
 518   static int _state_offset;
 519   JFR_ONLY(static int _jfr_epoch_offset;)
 520  public:
 521   enum {
 522     NEW          = 0,
 523     STARTED      = 1,
 524     RUNNABLE     = 2,
 525     RUNNING      = 3,
 526     PARKING      = 4,
 527     PARKED       = 5,
 528     PINNED       = 6,
 529     YIELDING     = 7,
 530     TERMINATED   = 99,
 531 
 532     // can be suspended from scheduling when unmounted
 533     SUSPENDED    = 1 << 8,
 534     RUNNABLE_SUSPENDED = (RUNNABLE | SUSPENDED),
 535     PARKED_SUSPENDED   = (PARKED | SUSPENDED)
 536   };
 537 
 538   static void compute_offsets();
 539   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 540 
 541   // Testers
 542   static bool is_subclass(Klass* klass) {
 543     return klass->is_subclass_of(vmClasses::VirtualThread_klass());
 544   }
 545   static bool is_instance(oop obj);
 546 
 547   static oop vthread_scope();
 548   static oop carrier_thread(oop vthread);
 549   static oop continuation(oop vthread);
 550   static int state(oop vthread);
 551   static JavaThreadStatus map_state_to_thread_status(int state);
 552 };
 553 
 554 
 555 // Interface to java.lang.Throwable objects
 556 
 557 class java_lang_Throwable: AllStatic {
 558   friend class BacktraceBuilder;
 559   friend class BacktraceIterator;
 560 
 561  private:
 562   // Trace constants
 563   enum {
 564     trace_methods_offset = 0,
 565     trace_bcis_offset    = 1,
 566     trace_mirrors_offset = 2,
 567     trace_names_offset   = 3,
 568     trace_conts_offset   = 4,
 569     trace_next_offset    = 5,
 570     trace_hidden_offset  = 6,
 571     trace_size           = 7,
 572     trace_chunk_size     = 32
 573   };
 574 
 575   static int _backtrace_offset;
 576   static int _detailMessage_offset;
 577   static int _stackTrace_offset;
 578   static int _depth_offset;
 579   static int _cause_offset;
 580   static int _static_unassigned_stacktrace_offset;
 581 
 582   // StackTrace (programmatic access, new since 1.4)
 583   static void clear_stacktrace(oop throwable);
 584   // Stacktrace (post JDK 1.7.0 to allow immutability protocol to be followed)
 585   static void set_stacktrace(oop throwable, oop st_element_array);
 586   static oop unassigned_stacktrace();
 587 
 588  public:
 589   // Backtrace
 590   static oop backtrace(oop throwable);
 591   static void set_backtrace(oop throwable, oop value);
 592   static int depth(oop throwable);
 593   static void set_depth(oop throwable, int value);
 594   static int get_detailMessage_offset() { CHECK_INIT(_detailMessage_offset); }
 595   // Message
 596   static oop message(oop throwable);
 597   static oop cause(oop throwable);
 598   static void set_message(oop throwable, oop value);
 599   static Symbol* detail_message(oop throwable);
 600   static void print_stack_element(outputStream *st, Method* method, int bci);
 601 
 602   static void compute_offsets();
 603   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 604 
 605   // Allocate space for backtrace (created but stack trace not filled in)
 606   static void allocate_backtrace(Handle throwable, TRAPS);
 607   // Fill in current stack trace for throwable with preallocated backtrace (no GC)
 608   static void fill_in_stack_trace_of_preallocated_backtrace(Handle throwable);
 609   // Fill in current stack trace, can cause GC
 610   static void fill_in_stack_trace(Handle throwable, const methodHandle& method, TRAPS);
 611   static void fill_in_stack_trace(Handle throwable, const methodHandle& method = methodHandle());
 612 
 613   // Programmatic access to stack trace
 614   static void get_stack_trace_elements(int depth, Handle backtrace, objArrayHandle stack_trace, TRAPS);
 615 
 616   // For recreating class initialization error exceptions.
 617   static Handle create_initialization_error(JavaThread* current, Handle throwable);
 618 
 619   // Printing
 620   static void print(oop throwable, outputStream* st);
 621   static void print_stack_trace(Handle throwable, outputStream* st);
 622   static void java_printStackTrace(Handle throwable, TRAPS);
 623   // Debugging
 624   friend class JavaClasses;
 625   // Gets the method and bci of the top frame (TOS). Returns false if this failed.
 626   static bool get_top_method_and_bci(oop throwable, Method** method, int* bci);
 627 };
 628 
 629 
 630 // Interface to java.lang.reflect.AccessibleObject objects
 631 
 632 class java_lang_reflect_AccessibleObject: AllStatic {
 633  private:
 634   // Note that to reduce dependencies on the JDK we compute these
 635   // offsets at run-time.
 636   static int _override_offset;
 637 
 638   static void compute_offsets();
 639 
 640  public:
 641   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 642 
 643   // Accessors
 644   static jboolean override(oop reflect);
 645   static void set_override(oop reflect, jboolean value);
 646 
 647   // Debugging
 648   friend class JavaClasses;
 649 };
 650 
 651 
 652 // Interface to java.lang.reflect.Method objects
 653 
 654 class java_lang_reflect_Method : public java_lang_reflect_AccessibleObject {
 655  private:
 656   // Note that to reduce dependencies on the JDK we compute these
 657   // offsets at run-time.
 658   static int _clazz_offset;
 659   static int _name_offset;
 660   static int _returnType_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   static int _annotation_default_offset;
 669 
 670   static void compute_offsets();
 671  public:
 672   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 673 
 674   // Allocation
 675   static Handle create(TRAPS);
 676 
 677   // Accessors
 678   static oop clazz(oop reflect);
 679   static void set_clazz(oop reflect, oop value);
 680 
 681   static void set_name(oop method, oop value);
 682 
 683   static oop return_type(oop method);
 684   static void set_return_type(oop method, oop value);
 685 
 686   static oop parameter_types(oop method);
 687   static void set_parameter_types(oop method, oop value);
 688 
 689   static int slot(oop reflect);
 690   static void set_slot(oop reflect, int value);
 691 
 692   static void set_exception_types(oop method, oop value);
 693   static void set_modifiers(oop method, int value);
 694   static void set_signature(oop method, oop value);
 695   static void set_annotations(oop method, oop value);
 696   static void set_parameter_annotations(oop method, oop value);
 697   static void set_annotation_default(oop method, oop value);
 698 
 699   // Debugging
 700   friend class JavaClasses;
 701 };
 702 
 703 
 704 // Interface to java.lang.reflect.Constructor objects
 705 
 706 class java_lang_reflect_Constructor : public java_lang_reflect_AccessibleObject {
 707  private:
 708   // Note that to reduce dependencies on the JDK we compute these
 709   // offsets at run-time.
 710   static int _clazz_offset;
 711   static int _parameterTypes_offset;
 712   static int _exceptionTypes_offset;
 713   static int _slot_offset;
 714   static int _modifiers_offset;
 715   static int _signature_offset;
 716   static int _annotations_offset;
 717   static int _parameter_annotations_offset;
 718 
 719   static void compute_offsets();
 720  public:
 721   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 722 
 723   // Allocation
 724   static Handle create(TRAPS);
 725 
 726   // Accessors
 727   static oop clazz(oop reflect);
 728   static void set_clazz(oop reflect, oop value);
 729 
 730   static oop parameter_types(oop constructor);
 731   static void set_parameter_types(oop constructor, oop value);
 732 
 733   static int slot(oop reflect);
 734   static void set_slot(oop reflect, int value);
 735 
 736   static void set_exception_types(oop constructor, oop value);
 737   static void set_modifiers(oop constructor, int value);
 738   static void set_signature(oop constructor, oop value);
 739   static void set_annotations(oop constructor, oop value);
 740   static void set_parameter_annotations(oop method, oop value);
 741 
 742   // Debugging
 743   friend class JavaClasses;
 744 };
 745 
 746 
 747 // Interface to java.lang.reflect.Field objects
 748 
 749 class java_lang_reflect_Field : public java_lang_reflect_AccessibleObject {
 750  private:
 751   // Note that to reduce dependencies on the JDK we compute these
 752   // offsets at run-time.
 753   static int _clazz_offset;
 754   static int _name_offset;
 755   static int _type_offset;
 756   static int _slot_offset;
 757   static int _modifiers_offset;
 758   static int _trusted_final_offset;
 759   static int _signature_offset;
 760   static int _annotations_offset;
 761 
 762   static void compute_offsets();
 763 
 764  public:
 765   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 766 
 767   // Allocation
 768   static Handle create(TRAPS);
 769 
 770   // Accessors
 771   static oop clazz(oop reflect);
 772   static void set_clazz(oop reflect, oop value);
 773 
 774   static oop name(oop field);
 775   static void set_name(oop field, oop value);
 776 
 777   static oop type(oop field);
 778   static void set_type(oop field, oop value);
 779 
 780   static int slot(oop reflect);
 781   static void set_slot(oop reflect, int value);
 782 
 783   static int modifiers(oop field);
 784   static void set_modifiers(oop field, int value);
 785 
 786   static void set_trusted_final(oop field);
 787 
 788   static void set_signature(oop constructor, oop value);
 789   static void set_annotations(oop constructor, oop value);
 790 
 791   // Debugging
 792   friend class JavaClasses;
 793 };
 794 
 795 class java_lang_reflect_Parameter {
 796  private:
 797   // Note that to reduce dependencies on the JDK we compute these
 798   // offsets at run-time.
 799   static int _name_offset;
 800   static int _modifiers_offset;
 801   static int _index_offset;
 802   static int _executable_offset;
 803 
 804   static void compute_offsets();
 805 
 806  public:
 807   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 808 
 809   // Allocation
 810   static Handle create(TRAPS);
 811 
 812   // Accessors
 813   static oop name(oop field);
 814   static void set_name(oop field, oop value);
 815 
 816   static int index(oop reflect);
 817   static void set_index(oop reflect, int value);
 818 
 819   static int modifiers(oop reflect);
 820   static void set_modifiers(oop reflect, int value);
 821 
 822   static oop executable(oop constructor);
 823   static void set_executable(oop constructor, oop value);
 824 
 825   friend class JavaClasses;
 826 };
 827 
 828 #define MODULE_INJECTED_FIELDS(macro)                            \
 829   macro(java_lang_Module, module_entry, intptr_signature, false)
 830 
 831 class java_lang_Module {
 832   private:
 833     static int _loader_offset;
 834     static int _name_offset;
 835     static int _module_entry_offset;
 836 
 837     static void compute_offsets();
 838 
 839   public:
 840     static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 841 
 842     // Allocation
 843     static Handle create(Handle loader, Handle module_name, TRAPS);
 844 
 845     // Testers
 846     static bool is_instance(oop obj);
 847 
 848     // Accessors
 849     static oop loader(oop module);
 850     static void set_loader(oop module, oop value);
 851 
 852     static oop name(oop module);
 853     static void set_name(oop module, oop value);
 854 
 855     static ModuleEntry* module_entry(oop module);
 856     static ModuleEntry* module_entry_raw(oop module);
 857     static void set_module_entry(oop module, ModuleEntry* module_entry);
 858 
 859   friend class JavaClasses;
 860 };
 861 
 862 // Interface to jdk.internal.reflect.ConstantPool objects
 863 class reflect_ConstantPool {
 864  private:
 865   // Note that to reduce dependencies on the JDK we compute these
 866   // offsets at run-time.
 867   static int _oop_offset;
 868 
 869   static void compute_offsets();
 870 
 871  public:
 872   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 873 
 874   // Allocation
 875   static Handle create(TRAPS);
 876 
 877   // Accessors
 878   static void set_cp(oop reflect, ConstantPool* value);
 879   static int oop_offset() { CHECK_INIT(_oop_offset); }
 880 
 881   static ConstantPool* get_cp(oop reflect);
 882 
 883   // Debugging
 884   friend class JavaClasses;
 885 };
 886 
 887 // Interface to jdk.internal.reflect.UnsafeStaticFieldAccessorImpl objects
 888 class reflect_UnsafeStaticFieldAccessorImpl {
 889  private:
 890   static int _base_offset;
 891   static void compute_offsets();
 892 
 893  public:
 894   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 895 
 896   static int base_offset() { CHECK_INIT(_base_offset); }
 897 
 898   // Debugging
 899   friend class JavaClasses;
 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, vmholder, object_signature, false) \
1214   macro(java_lang_invoke_ResolvedMethodName, vmtarget, intptr_signature, false)
1215 
1216 class java_lang_invoke_ResolvedMethodName : AllStatic {
1217   friend class JavaClasses;
1218 
1219   static int _vmtarget_offset;
1220   static int _vmholder_offset;
1221 
1222   static void compute_offsets();
1223  public:
1224   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1225 
1226   static int vmtarget_offset() { CHECK_INIT(_vmtarget_offset); }
1227 
1228   static Method* vmtarget(oop resolved_method);
1229   static void set_vmtarget(oop resolved_method, Method* method);
1230 
1231   static void set_vmholder(oop resolved_method, oop holder);
1232 
1233   // find or create resolved member name
1234   static oop find_resolved_method(const methodHandle& m, TRAPS);
1235 
1236   static bool is_instance(oop resolved_method);
1237 };
1238 
1239 
1240 #define MEMBERNAME_INJECTED_FIELDS(macro)                               \
1241   macro(java_lang_invoke_MemberName, vmindex,  intptr_signature, false)
1242 
1243 
1244 class java_lang_invoke_MemberName: AllStatic {
1245   friend class JavaClasses;
1246 
1247  private:
1248   // From java.lang.invoke.MemberName:
1249   //    private Class<?>   clazz;       // class in which the method is defined
1250   //    private String     name;        // may be null if not yet materialized
1251   //    private Object     type;        // may be null if not yet materialized
1252   //    private int        flags;       // modifier bits; see reflect.Modifier
1253   //    private ResolvedMethodName method;    // holds VM-specific target value
1254   //    private intptr_t   vmindex;     // member index within class or interface
1255   static int _clazz_offset;
1256   static int _name_offset;
1257   static int _type_offset;
1258   static int _flags_offset;
1259   static int _method_offset;
1260   static int _vmindex_offset;
1261 
1262   static void compute_offsets();
1263 
1264  public:
1265   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1266   // Accessors
1267   static oop            clazz(oop mname);
1268   static void       set_clazz(oop mname, oop clazz);
1269 
1270   static oop            type(oop mname);
1271   static void       set_type(oop mname, oop type);
1272 
1273   static oop            name(oop mname);
1274   static void       set_name(oop mname, oop name);
1275 
1276   static int            flags(oop mname);
1277   static void       set_flags(oop mname, int flags);
1278 
1279   // Link through ResolvedMethodName field to get Method*
1280   static Method*        vmtarget(oop mname);
1281   static void       set_method(oop mname, oop method);
1282 
1283   static intptr_t       vmindex(oop mname);
1284   static void       set_vmindex(oop mname, intptr_t index);
1285 
1286   // Testers
1287   static bool is_subclass(Klass* klass) {
1288     return klass->is_subclass_of(vmClasses::MemberName_klass());
1289   }
1290   static bool is_instance(oop obj);
1291 
1292   static bool is_method(oop obj);
1293 
1294   // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):
1295   enum {
1296     MN_IS_METHOD             = 0x00010000, // method (not constructor)
1297     MN_IS_CONSTRUCTOR        = 0x00020000, // constructor
1298     MN_IS_FIELD              = 0x00040000, // field
1299     MN_IS_TYPE               = 0x00080000, // nested type
1300     MN_CALLER_SENSITIVE      = 0x00100000, // @CallerSensitive annotation detected
1301     MN_TRUSTED_FINAL         = 0x00200000, // trusted final field
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   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1480 
1481   static ClassLoaderData* loader_data_acquire(oop loader);
1482   static ClassLoaderData* loader_data(oop loader);
1483   static void release_set_loader_data(oop loader, ClassLoaderData* new_data);
1484 
1485   static oop parent(oop loader);
1486   static oop parent_no_keepalive(oop loader);
1487   static oop name(oop loader);
1488   static oop nameAndId(oop loader);
1489   static bool isAncestor(oop loader, oop cl);
1490 
1491   // Support for parallelCapable field
1492   static bool parallelCapable(oop the_class_mirror);
1493 
1494   static bool is_trusted_loader(oop loader);
1495 
1496   // Return true if this is one of the class loaders associated with
1497   // the generated bytecodes for reflection.
1498   static bool is_reflection_class_loader(oop loader);
1499 
1500   // Fix for 4474172
1501   static oop  non_reflection_class_loader(oop loader);
1502 
1503   // Testers
1504   static bool is_subclass(Klass* klass) {
1505     return klass->is_subclass_of(vmClasses::ClassLoader_klass());
1506   }
1507   static bool is_instance(oop obj);
1508 
1509   static oop unnamedModule(oop loader);
1510 
1511   // Debugging
1512   friend class JavaClasses;
1513 };
1514 
1515 
1516 // Interface to java.lang.System objects
1517 
1518 class java_lang_System : AllStatic {
1519  private:
1520   static int _static_in_offset;
1521   static int _static_out_offset;
1522   static int _static_err_offset;
1523   static int _static_security_offset;
1524   static int _static_allow_security_offset;
1525   static int _static_never_offset;
1526 
1527  public:
1528   static int  in_offset() { CHECK_INIT(_static_in_offset); }
1529   static int out_offset() { CHECK_INIT(_static_out_offset); }
1530   static int err_offset() { CHECK_INIT(_static_err_offset); }
1531   static bool allow_security_manager();
1532   static bool has_security_manager();
1533 
1534   static void compute_offsets();
1535   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1536 
1537   // Debugging
1538   friend class JavaClasses;
1539 };
1540 
1541 
1542 // Interface to java.lang.StackTraceElement objects
1543 
1544 class java_lang_StackTraceElement: AllStatic {
1545  private:
1546   static int _declaringClassObject_offset;
1547   static int _classLoaderName_offset;
1548   static int _moduleName_offset;
1549   static int _moduleVersion_offset;
1550   static int _declaringClass_offset;
1551   static int _methodName_offset;
1552   static int _fileName_offset;
1553   static int _lineNumber_offset;
1554 
1555   // Setters
1556   static void set_classLoaderName(oop element, oop value);
1557   static void set_moduleName(oop element, oop value);
1558   static void set_moduleVersion(oop element, oop value);
1559   static void set_declaringClass(oop element, oop value);
1560   static void set_methodName(oop element, oop value);
1561   static void set_fileName(oop element, oop value);
1562   static void set_lineNumber(oop element, int value);
1563   static void set_declaringClassObject(oop element, oop value);
1564 
1565   static void decode_file_and_line(Handle java_mirror, InstanceKlass* holder, int version,
1566                                    const methodHandle& method, int bci,
1567                                    Symbol*& source, oop& source_file, int& line_number, TRAPS);
1568 
1569  public:
1570   // Create an instance of StackTraceElement
1571   static oop create(const methodHandle& method, int bci, TRAPS);
1572 
1573   static void fill_in(Handle element, InstanceKlass* holder, const methodHandle& method,
1574                       int version, int bci, Symbol* name, TRAPS);
1575 
1576   static void compute_offsets();
1577   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1578 
1579 #if INCLUDE_JVMCI
1580   static void decode(const methodHandle& method, int bci, Symbol*& fileName, int& lineNumber, TRAPS);
1581 #endif
1582 
1583   // Debugging
1584   friend class JavaClasses;
1585 };
1586 
1587 
1588 class Backtrace: AllStatic {
1589  public:
1590   // Helper backtrace functions to store bci|version together.
1591   static int merge_bci_and_version(int bci, int version);
1592   static int merge_mid_and_cpref(int mid, int cpref);
1593   static int bci_at(unsigned int merged);
1594   static int version_at(unsigned int merged);
1595   static int mid_at(unsigned int merged);
1596   static int cpref_at(unsigned int merged);
1597   static int get_line_number(Method* method, int bci);
1598   static Symbol* get_source_file_name(InstanceKlass* holder, int version);
1599 
1600   // Debugging
1601   friend class JavaClasses;
1602 };
1603 
1604 // Interface to java.lang.StackFrameInfo objects
1605 
1606 #define STACKFRAMEINFO_INJECTED_FIELDS(macro)                      \
1607   macro(java_lang_StackFrameInfo, version, short_signature, false)
1608 
1609 class java_lang_StackFrameInfo: AllStatic {
1610 private:
1611   static int _memberName_offset;
1612   static int _bci_offset;
1613   static int _version_offset;
1614   static int _contScope_offset;
1615 
1616   static Method* get_method(Handle stackFrame, InstanceKlass* holder, TRAPS);
1617 
1618 public:
1619   // Setters
1620   static void set_method_and_bci(Handle stackFrame, const methodHandle& method, int bci, oop cont, TRAPS);
1621   static void set_bci(oop info, int value);
1622 
1623   static void set_version(oop info, short value);
1624   static void set_contScope(oop info, oop value);
1625 
1626   static void compute_offsets();
1627   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1628 
1629   static void to_stack_trace_element(Handle stackFrame, Handle stack_trace_element, TRAPS);
1630 
1631   // Debugging
1632   friend class JavaClasses;
1633 };
1634 
1635 class java_lang_LiveStackFrameInfo: AllStatic {
1636  private:
1637   static int _monitors_offset;
1638   static int _locals_offset;
1639   static int _operands_offset;
1640   static int _mode_offset;
1641 
1642  public:
1643   static void set_monitors(oop info, oop value);
1644   static void set_locals(oop info, oop value);
1645   static void set_operands(oop info, oop value);
1646   static void set_mode(oop info, int value);
1647 
1648   static void compute_offsets();
1649   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1650 
1651   // Debugging
1652   friend class JavaClasses;
1653 };
1654 
1655 // Interface to java.lang.reflect.RecordComponent objects
1656 
1657 class java_lang_reflect_RecordComponent: AllStatic {
1658  private:
1659   static int _clazz_offset;
1660   static int _name_offset;
1661   static int _type_offset;
1662   static int _accessor_offset;
1663   static int _signature_offset;
1664   static int _annotations_offset;
1665   static int _typeAnnotations_offset;
1666 
1667   // Setters
1668   static void set_clazz(oop element, oop value);
1669   static void set_name(oop element, oop value);
1670   static void set_type(oop element, oop value);
1671   static void set_accessor(oop element, oop value);
1672   static void set_signature(oop element, oop value);
1673   static void set_annotations(oop element, oop value);
1674   static void set_typeAnnotations(oop element, oop value);
1675 
1676  public:
1677   // Create an instance of RecordComponent
1678   static oop create(InstanceKlass* holder, RecordComponent* component, TRAPS);
1679 
1680   static void compute_offsets();
1681   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1682 
1683   // Debugging
1684   friend class JavaClasses;
1685 };
1686 
1687 
1688 // Interface to java.lang.AssertionStatusDirectives objects
1689 
1690 class java_lang_AssertionStatusDirectives: AllStatic {
1691  private:
1692   static int _classes_offset;
1693   static int _classEnabled_offset;
1694   static int _packages_offset;
1695   static int _packageEnabled_offset;
1696   static int _deflt_offset;
1697 
1698  public:
1699   // Setters
1700   static void set_classes(oop obj, oop val);
1701   static void set_classEnabled(oop obj, oop val);
1702   static void set_packages(oop obj, oop val);
1703   static void set_packageEnabled(oop obj, oop val);
1704   static void set_deflt(oop obj, bool val);
1705 
1706   static void compute_offsets();
1707   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1708 
1709   // Debugging
1710   friend class JavaClasses;
1711 };
1712 
1713 
1714 class java_util_concurrent_locks_AbstractOwnableSynchronizer : AllStatic {
1715  private:
1716   static int  _owner_offset;
1717  public:
1718   static void compute_offsets();
1719   static oop  get_owner_threadObj(oop obj);
1720   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1721 };
1722 
1723  // Interface to jdk.internal.misc.UnsafeConsants
1724 
1725 class jdk_internal_misc_UnsafeConstants : AllStatic {
1726  public:
1727   static void set_unsafe_constants();
1728   static void compute_offsets() { }
1729   static void serialize_offsets(SerializeClosure* f) { }
1730 };
1731 
1732 // Interface to jdk.internal.vm.vector.VectorSupport.VectorPayload objects
1733 
1734 class vector_VectorPayload : AllStatic {
1735  private:
1736   static int _payload_offset;
1737  public:
1738   static void set_payload(oop o, oop val);
1739 
1740   static void compute_offsets();
1741   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1742 
1743   // Testers
1744   static bool is_subclass(Klass* klass) {
1745     return klass->is_subclass_of(vmClasses::vector_VectorPayload_klass());
1746   }
1747   static bool is_instance(oop obj);
1748 };
1749 
1750 class java_lang_Integer : AllStatic {
1751 public:
1752   static jint value(oop obj);
1753 };
1754 
1755 class java_lang_Long : AllStatic {
1756 public:
1757   static jlong value(oop obj);
1758 };
1759 
1760 class java_lang_Character : AllStatic {
1761 public:
1762   static jchar value(oop obj);
1763 };
1764 
1765 class java_lang_Short : AllStatic {
1766 public:
1767   static jshort value(oop obj);
1768 };
1769 
1770 class java_lang_Byte : AllStatic {
1771 public:
1772   static jbyte value(oop obj);
1773 };
1774 
1775 class java_lang_Boolean : AllStatic {
1776  private:
1777   static int _static_TRUE_offset;
1778   static int _static_FALSE_offset;
1779  public:
1780   static Symbol* symbol();
1781   static void compute_offsets(InstanceKlass* k);
1782   static oop  get_TRUE(InstanceKlass *k);
1783   static oop  get_FALSE(InstanceKlass *k);
1784   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1785   static jboolean value(oop obj);
1786 };
1787 
1788 class java_lang_Integer_IntegerCache : AllStatic {
1789  private:
1790   static int _static_cache_offset;
1791  public:
1792   static Symbol* symbol();
1793   static void compute_offsets(InstanceKlass* k);
1794   static objArrayOop  cache(InstanceKlass *k);
1795   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1796 };
1797 
1798 class java_lang_Long_LongCache : AllStatic {
1799  private:
1800   static int _static_cache_offset;
1801  public:
1802   static Symbol* symbol();
1803   static void compute_offsets(InstanceKlass* k);
1804   static objArrayOop  cache(InstanceKlass *k);
1805   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1806 };
1807 
1808 class java_lang_Character_CharacterCache : AllStatic {
1809  private:
1810   static int _static_cache_offset;
1811  public:
1812   static Symbol* symbol();
1813   static void compute_offsets(InstanceKlass* k);
1814   static objArrayOop  cache(InstanceKlass *k);
1815   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1816 };
1817 
1818 class java_lang_Short_ShortCache : AllStatic {
1819  private:
1820   static int _static_cache_offset;
1821  public:
1822   static Symbol* symbol();
1823   static void compute_offsets(InstanceKlass* k);
1824   static objArrayOop  cache(InstanceKlass *k);
1825   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1826 };
1827 
1828 class java_lang_Byte_ByteCache : AllStatic {
1829  private:
1830   static int _static_cache_offset;
1831  public:
1832   static Symbol* symbol();
1833   static void compute_offsets(InstanceKlass* k);
1834   static objArrayOop  cache(InstanceKlass *k);
1835   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1836 };
1837 
1838 
1839 // Interface to java.lang.InternalError objects
1840 
1841 #define INTERNALERROR_INJECTED_FIELDS(macro)                      \
1842   macro(java_lang_InternalError, during_unsafe_access, bool_signature, false)
1843 
1844 class java_lang_InternalError : AllStatic {
1845  private:
1846   static int _during_unsafe_access_offset;
1847  public:
1848   static jboolean during_unsafe_access(oop internal_error);
1849   static void set_during_unsafe_access(oop internal_error);
1850   static void compute_offsets();
1851   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1852 };
1853 
1854 // Use to declare fields that need to be injected into Java classes
1855 // for the JVM to use.  The name_index and signature_index are
1856 // declared in vmSymbols.  The may_be_java flag is used to declare
1857 // fields that might already exist in Java but should be injected if
1858 // they don't.  Otherwise the field is unconditionally injected and
1859 // the JVM uses the injected one.  This is to ensure that name
1860 // collisions don't occur.  In general may_be_java should be false
1861 // unless there's a good reason.
1862 
1863 class InjectedField {
1864  public:
1865   const vmClassID klass_id;
1866   const vmSymbolID name_index;
1867   const vmSymbolID signature_index;
1868   const bool           may_be_java;
1869 
1870 
1871   Klass* klass() const      { return vmClasses::klass_at(klass_id); }
1872   Symbol* name() const      { return lookup_symbol(name_index); }
1873   Symbol* signature() const { return lookup_symbol(signature_index); }
1874 
1875   int compute_offset();
1876 
1877   // Find the Symbol for this index
1878   static Symbol* lookup_symbol(vmSymbolID symbol_index) {
1879     return Symbol::vm_symbol_at(symbol_index);
1880   }
1881 };
1882 
1883 
1884 // Interface to hard-coded offset checking
1885 
1886 enum class InjectedFieldID : int;
1887 
1888 class JavaClasses : AllStatic {
1889  private:
1890 
1891   static InjectedField _injected_fields[];
1892 
1893   static bool check_offset(const char *klass_name, int offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1894  public:
1895 
1896   static int compute_injected_offset(InjectedFieldID id);
1897 
1898   static void compute_offsets();
1899   static void check_offsets() PRODUCT_RETURN;
1900   static void serialize_offsets(SerializeClosure* soc) NOT_CDS_RETURN;
1901   static InjectedField* get_injected(Symbol* class_name, int* field_count);
1902   static bool is_supported_for_archiving(oop obj) NOT_CDS_JAVA_HEAP_RETURN_(false);
1903 
1904   static void compute_offset(int &dest_offset,
1905                              InstanceKlass* ik, Symbol* name_symbol, Symbol* signature_symbol,
1906                              bool is_static = false);
1907   static void compute_offset(int& dest_offset, InstanceKlass* ik,
1908                              const char* name_string, Symbol* signature_symbol,
1909                              bool is_static = false);
1910 };
1911 
1912 #undef CHECK_INIT
1913 
1914 #endif // SHARE_CLASSFILE_JAVACLASSES_HPP