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     RUNNING       = 2,
 525     PARKING       = 3,
 526     PARKED        = 4,
 527     PINNED        = 5,
 528     TIMED_PARKING = 6,
 529     TIMED_PARKED  = 7,
 530     TIMED_PINNED  = 8,
 531     UNPARKED      = 9,
 532     YIELDING      = 10,
 533     YIELDED       = 11,
 534     TERMINATED    = 99,
 535 
 536     // additional state bits
 537     SUSPENDED    = 1 << 8,   // suspended when unmounted
 538   };
 539 
 540   static void compute_offsets();
 541   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 542 
 543   // Testers
 544   static bool is_subclass(Klass* klass) {
 545     return klass->is_subclass_of(vmClasses::VirtualThread_klass());
 546   }
 547   static bool is_instance(oop obj);
 548 
 549   static oop vthread_scope();
 550   static oop carrier_thread(oop vthread);
 551   static oop continuation(oop vthread);
 552   static int state(oop vthread);
 553   static JavaThreadStatus map_state_to_thread_status(int state);
 554 };
 555 
 556 
 557 // Interface to java.lang.Throwable objects
 558 
 559 class java_lang_Throwable: AllStatic {
 560   friend class BacktraceBuilder;
 561   friend class BacktraceIterator;
 562 
 563  private:
 564   // Trace constants
 565   enum {
 566     trace_methods_offset = 0,
 567     trace_bcis_offset    = 1,
 568     trace_mirrors_offset = 2,
 569     trace_names_offset   = 3,
 570     trace_conts_offset   = 4,
 571     trace_next_offset    = 5,
 572     trace_hidden_offset  = 6,
 573     trace_size           = 7,
 574     trace_chunk_size     = 32
 575   };
 576 
 577   static int _backtrace_offset;
 578   static int _detailMessage_offset;
 579   static int _stackTrace_offset;
 580   static int _depth_offset;
 581   static int _cause_offset;
 582   static int _static_unassigned_stacktrace_offset;
 583 
 584   // StackTrace (programmatic access, new since 1.4)
 585   static void clear_stacktrace(oop throwable);
 586   // Stacktrace (post JDK 1.7.0 to allow immutability protocol to be followed)
 587   static void set_stacktrace(oop throwable, oop st_element_array);
 588   static oop unassigned_stacktrace();
 589 
 590  public:
 591   // Backtrace
 592   static oop backtrace(oop throwable);
 593   static void set_backtrace(oop throwable, oop value);
 594   static int depth(oop throwable);
 595   static void set_depth(oop throwable, int value);
 596   static int get_detailMessage_offset() { CHECK_INIT(_detailMessage_offset); }
 597   // Message
 598   static oop message(oop throwable);
 599   static oop cause(oop throwable);
 600   static void set_message(oop throwable, oop value);
 601   static Symbol* detail_message(oop throwable);
 602   static void print_stack_element(outputStream *st, Method* method, int bci);
 603 
 604   static void compute_offsets();
 605   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 606 
 607   // Allocate space for backtrace (created but stack trace not filled in)
 608   static void allocate_backtrace(Handle throwable, TRAPS);
 609   // Fill in current stack trace for throwable with preallocated backtrace (no GC)
 610   static void fill_in_stack_trace_of_preallocated_backtrace(Handle throwable);
 611   // Fill in current stack trace, can cause GC
 612   static void fill_in_stack_trace(Handle throwable, const methodHandle& method, TRAPS);
 613   static void fill_in_stack_trace(Handle throwable, const methodHandle& method = methodHandle());
 614 
 615   // Programmatic access to stack trace
 616   static void get_stack_trace_elements(int depth, Handle backtrace, objArrayHandle stack_trace, TRAPS);
 617 
 618   // For recreating class initialization error exceptions.
 619   static Handle create_initialization_error(JavaThread* current, Handle throwable);
 620 
 621   // Printing
 622   static void print(oop throwable, outputStream* st);
 623   static void print_stack_trace(Handle throwable, outputStream* st);
 624   static void java_printStackTrace(Handle throwable, TRAPS);
 625   // Debugging
 626   friend class JavaClasses;
 627   // Gets the method and bci of the top frame (TOS). Returns false if this failed.
 628   static bool get_top_method_and_bci(oop throwable, Method** method, int* bci);
 629 };
 630 
 631 
 632 // Interface to java.lang.reflect.AccessibleObject objects
 633 
 634 class java_lang_reflect_AccessibleObject: AllStatic {
 635  private:
 636   // Note that to reduce dependencies on the JDK we compute these
 637   // offsets at run-time.
 638   static int _override_offset;
 639 
 640   static void compute_offsets();
 641 
 642  public:
 643   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 644 
 645   // Accessors
 646   static jboolean override(oop reflect);
 647   static void set_override(oop reflect, jboolean value);
 648 
 649   // Debugging
 650   friend class JavaClasses;
 651 };
 652 
 653 
 654 // Interface to java.lang.reflect.Method objects
 655 
 656 class java_lang_reflect_Method : public java_lang_reflect_AccessibleObject {
 657  private:
 658   // Note that to reduce dependencies on the JDK we compute these
 659   // offsets at run-time.
 660   static int _clazz_offset;
 661   static int _name_offset;
 662   static int _returnType_offset;
 663   static int _parameterTypes_offset;
 664   static int _exceptionTypes_offset;
 665   static int _slot_offset;
 666   static int _modifiers_offset;
 667   static int _signature_offset;
 668   static int _annotations_offset;
 669   static int _parameter_annotations_offset;
 670   static int _annotation_default_offset;
 671 
 672   static void compute_offsets();
 673  public:
 674   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 675 
 676   // Allocation
 677   static Handle create(TRAPS);
 678 
 679   // Accessors
 680   static oop clazz(oop reflect);
 681   static void set_clazz(oop reflect, oop value);
 682 
 683   static void set_name(oop method, oop value);
 684 
 685   static oop return_type(oop method);
 686   static void set_return_type(oop method, oop value);
 687 
 688   static oop parameter_types(oop method);
 689   static void set_parameter_types(oop method, oop value);
 690 
 691   static int slot(oop reflect);
 692   static void set_slot(oop reflect, int value);
 693 
 694   static void set_exception_types(oop method, oop value);
 695   static void set_modifiers(oop method, int value);
 696   static void set_signature(oop method, oop value);
 697   static void set_annotations(oop method, oop value);
 698   static void set_parameter_annotations(oop method, oop value);
 699   static void set_annotation_default(oop method, oop value);
 700 
 701   // Debugging
 702   friend class JavaClasses;
 703 };
 704 
 705 
 706 // Interface to java.lang.reflect.Constructor objects
 707 
 708 class java_lang_reflect_Constructor : public java_lang_reflect_AccessibleObject {
 709  private:
 710   // Note that to reduce dependencies on the JDK we compute these
 711   // offsets at run-time.
 712   static int _clazz_offset;
 713   static int _parameterTypes_offset;
 714   static int _exceptionTypes_offset;
 715   static int _slot_offset;
 716   static int _modifiers_offset;
 717   static int _signature_offset;
 718   static int _annotations_offset;
 719   static int _parameter_annotations_offset;
 720 
 721   static void compute_offsets();
 722  public:
 723   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 724 
 725   // Allocation
 726   static Handle create(TRAPS);
 727 
 728   // Accessors
 729   static oop clazz(oop reflect);
 730   static void set_clazz(oop reflect, oop value);
 731 
 732   static oop parameter_types(oop constructor);
 733   static void set_parameter_types(oop constructor, oop value);
 734 
 735   static int slot(oop reflect);
 736   static void set_slot(oop reflect, int value);
 737 
 738   static void set_exception_types(oop constructor, oop value);
 739   static void set_modifiers(oop constructor, int value);
 740   static void set_signature(oop constructor, oop value);
 741   static void set_annotations(oop constructor, oop value);
 742   static void set_parameter_annotations(oop method, oop value);
 743 
 744   // Debugging
 745   friend class JavaClasses;
 746 };
 747 
 748 
 749 // Interface to java.lang.reflect.Field objects
 750 
 751 class java_lang_reflect_Field : public java_lang_reflect_AccessibleObject {
 752  private:
 753   // Note that to reduce dependencies on the JDK we compute these
 754   // offsets at run-time.
 755   static int _clazz_offset;
 756   static int _name_offset;
 757   static int _type_offset;
 758   static int _slot_offset;
 759   static int _modifiers_offset;
 760   static int _trusted_final_offset;
 761   static int _signature_offset;
 762   static int _annotations_offset;
 763 
 764   static void compute_offsets();
 765 
 766  public:
 767   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 768 
 769   // Allocation
 770   static Handle create(TRAPS);
 771 
 772   // Accessors
 773   static oop clazz(oop reflect);
 774   static void set_clazz(oop reflect, oop value);
 775 
 776   static oop name(oop field);
 777   static void set_name(oop field, oop value);
 778 
 779   static oop type(oop field);
 780   static void set_type(oop field, oop value);
 781 
 782   static int slot(oop reflect);
 783   static void set_slot(oop reflect, int value);
 784 
 785   static int modifiers(oop field);
 786   static void set_modifiers(oop field, int value);
 787 
 788   static void set_trusted_final(oop field);
 789 
 790   static void set_signature(oop constructor, oop value);
 791   static void set_annotations(oop constructor, oop value);
 792 
 793   // Debugging
 794   friend class JavaClasses;
 795 };
 796 
 797 class java_lang_reflect_Parameter {
 798  private:
 799   // Note that to reduce dependencies on the JDK we compute these
 800   // offsets at run-time.
 801   static int _name_offset;
 802   static int _modifiers_offset;
 803   static int _index_offset;
 804   static int _executable_offset;
 805 
 806   static void compute_offsets();
 807 
 808  public:
 809   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 810 
 811   // Allocation
 812   static Handle create(TRAPS);
 813 
 814   // Accessors
 815   static oop name(oop field);
 816   static void set_name(oop field, oop value);
 817 
 818   static int index(oop reflect);
 819   static void set_index(oop reflect, int value);
 820 
 821   static int modifiers(oop reflect);
 822   static void set_modifiers(oop reflect, int value);
 823 
 824   static oop executable(oop constructor);
 825   static void set_executable(oop constructor, oop value);
 826 
 827   friend class JavaClasses;
 828 };
 829 
 830 #define MODULE_INJECTED_FIELDS(macro)                            \
 831   macro(java_lang_Module, module_entry, intptr_signature, false)
 832 
 833 class java_lang_Module {
 834   private:
 835     static int _loader_offset;
 836     static int _name_offset;
 837     static int _module_entry_offset;
 838 
 839     static void compute_offsets();
 840 
 841   public:
 842     static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 843 
 844     // Allocation
 845     static Handle create(Handle loader, Handle module_name, TRAPS);
 846 
 847     // Testers
 848     static bool is_instance(oop obj);
 849 
 850     // Accessors
 851     static oop loader(oop module);
 852     static void set_loader(oop module, oop value);
 853 
 854     static oop name(oop module);
 855     static void set_name(oop module, oop value);
 856 
 857     static ModuleEntry* module_entry(oop module);
 858     static ModuleEntry* module_entry_raw(oop module);
 859     static void set_module_entry(oop module, ModuleEntry* module_entry);
 860 
 861   friend class JavaClasses;
 862 };
 863 
 864 // Interface to jdk.internal.reflect.ConstantPool objects
 865 class reflect_ConstantPool {
 866  private:
 867   // Note that to reduce dependencies on the JDK we compute these
 868   // offsets at run-time.
 869   static int _oop_offset;
 870 
 871   static void compute_offsets();
 872 
 873  public:
 874   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 875 
 876   // Allocation
 877   static Handle create(TRAPS);
 878 
 879   // Accessors
 880   static void set_cp(oop reflect, ConstantPool* value);
 881   static int oop_offset() { CHECK_INIT(_oop_offset); }
 882 
 883   static ConstantPool* get_cp(oop reflect);
 884 
 885   // Debugging
 886   friend class JavaClasses;
 887 };
 888 
 889 // Interface to jdk.internal.reflect.UnsafeStaticFieldAccessorImpl objects
 890 class reflect_UnsafeStaticFieldAccessorImpl {
 891  private:
 892   static int _base_offset;
 893   static void compute_offsets();
 894 
 895  public:
 896   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 897 
 898   static int base_offset() { CHECK_INIT(_base_offset); }
 899 
 900   // Debugging
 901   friend class JavaClasses;
 902 };
 903 
 904 // Interface to java.lang primitive type boxing objects:
 905 //  - java.lang.Boolean
 906 //  - java.lang.Character
 907 //  - java.lang.Float
 908 //  - java.lang.Double
 909 //  - java.lang.Byte
 910 //  - java.lang.Short
 911 //  - java.lang.Integer
 912 //  - java.lang.Long
 913 
 914 // This could be separated out into 8 individual classes.
 915 
 916 class java_lang_boxing_object: AllStatic {
 917  private:
 918   static int _value_offset;
 919   static int _long_value_offset;
 920 
 921   static void compute_offsets();
 922   static oop initialize_and_allocate(BasicType type, TRAPS);
 923  public:
 924   // Allocation. Returns a boxed value, or null for invalid type.
 925   static oop create(BasicType type, jvalue* value, TRAPS);
 926   // Accessors. Returns the basic type being boxed, or T_ILLEGAL for invalid oop.
 927   static BasicType get_value(oop box, jvalue* value);
 928   static BasicType set_value(oop box, jvalue* value);
 929   static BasicType basic_type(oop box);
 930   static bool is_instance(oop box)                 { return basic_type(box) != T_ILLEGAL; }
 931   static bool is_instance(oop box, BasicType type) { return basic_type(box) == type; }
 932   static void print(oop box, outputStream* st)     { jvalue value;  print(get_value(box, &value), &value, st); }
 933   static void print(BasicType type, jvalue* value, outputStream* st);
 934 
 935   static int value_offset(BasicType type) {
 936     return is_double_word_type(type) ? _long_value_offset : _value_offset;
 937   }
 938 
 939   static void serialize_offsets(SerializeClosure* f);
 940 
 941   // Debugging
 942   friend class JavaClasses;
 943 };
 944 
 945 
 946 
 947 // Interface to java.lang.ref.Reference objects
 948 
 949 class java_lang_ref_Reference: AllStatic {
 950   static int _referent_offset;
 951   static int _queue_offset;
 952   static int _next_offset;
 953   static int _discovered_offset;
 954 
 955   static bool _offsets_initialized;
 956 
 957  public:
 958   // Accessors
 959   static inline oop weak_referent_no_keepalive(oop ref);
 960   static inline oop weak_referent(oop ref);
 961   static inline oop phantom_referent_no_keepalive(oop ref);
 962   static inline oop unknown_referent_no_keepalive(oop ref);
 963   static inline void clear_referent(oop ref);
 964   static inline void clear_referent_raw(oop ref);
 965   static inline HeapWord* referent_addr_raw(oop ref);
 966   static inline oop next(oop ref);
 967   static inline void set_next(oop ref, oop value);
 968   static inline void set_next_raw(oop ref, oop value);
 969   static inline HeapWord* next_addr_raw(oop ref);
 970   static inline oop discovered(oop ref);
 971   static inline void set_discovered(oop ref, oop value);
 972   static inline void set_discovered_raw(oop ref, oop value);
 973   static inline HeapWord* discovered_addr_raw(oop ref);
 974   static bool is_referent_field(oop obj, ptrdiff_t offset);
 975   static inline bool is_final(oop ref);
 976   static inline bool is_phantom(oop ref);
 977   static inline bool is_weak(oop ref);
 978   static inline bool is_soft(oop ref);
 979 
 980   static int referent_offset()    { CHECK_INIT(_referent_offset); }
 981   static int queue_offset()       { CHECK_INIT(_queue_offset); }
 982   static int next_offset()        { CHECK_INIT(_next_offset); }
 983   static int discovered_offset()  { CHECK_INIT(_discovered_offset); }
 984 
 985   static void compute_offsets();
 986   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 987 };
 988 
 989 
 990 // Interface to java.lang.ref.SoftReference objects
 991 
 992 class java_lang_ref_SoftReference: public java_lang_ref_Reference {
 993   static int _timestamp_offset;
 994   static int _static_clock_offset;
 995 
 996  public:
 997   // Accessors
 998   static jlong timestamp(oop ref);
 999 
1000   // Accessors for statics
1001   static jlong clock();
1002   static void set_clock(jlong value);
1003 
1004   static void compute_offsets();
1005   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1006 };
1007 
1008 // Interface to java.lang.invoke.MethodHandle objects
1009 
1010 class java_lang_invoke_MethodHandle: AllStatic {
1011   friend class JavaClasses;
1012 
1013  private:
1014   static int _type_offset;               // the MethodType of this MH
1015   static int _form_offset;               // the LambdaForm of this MH
1016 
1017   static void compute_offsets();
1018 
1019  public:
1020   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1021 
1022   // Accessors
1023   static oop            type(oop mh);
1024   static void       set_type(oop mh, oop mtype);
1025 
1026   static oop            form(oop mh);
1027   static void       set_form(oop mh, oop lform);
1028 
1029   // Testers
1030   static bool is_subclass(Klass* klass) {
1031     return klass->is_subclass_of(vmClasses::MethodHandle_klass());
1032   }
1033   static bool is_instance(oop obj);
1034 
1035   // Accessors for code generation:
1036   static int type_offset()             { CHECK_INIT(_type_offset); }
1037   static int form_offset()             { CHECK_INIT(_form_offset); }
1038 };
1039 
1040 // Interface to java.lang.invoke.DirectMethodHandle objects
1041 
1042 class java_lang_invoke_DirectMethodHandle: AllStatic {
1043   friend class JavaClasses;
1044 
1045  private:
1046   static int _member_offset;               // the MemberName of this DMH
1047 
1048   static void compute_offsets();
1049 
1050  public:
1051   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1052 
1053   // Accessors
1054   static oop  member(oop mh);
1055 
1056   // Testers
1057   static bool is_subclass(Klass* klass) {
1058     return klass->is_subclass_of(vmClasses::DirectMethodHandle_klass());
1059   }
1060   static bool is_instance(oop obj);
1061 
1062   // Accessors for code generation:
1063   static int member_offset()           { CHECK_INIT(_member_offset); }
1064 };
1065 
1066 // Interface to java.lang.invoke.LambdaForm objects
1067 // (These are a private interface for managing adapter code generation.)
1068 
1069 class java_lang_invoke_LambdaForm: AllStatic {
1070   friend class JavaClasses;
1071 
1072  private:
1073   static int _vmentry_offset;  // type is MemberName
1074 
1075   static void compute_offsets();
1076 
1077  public:
1078   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1079 
1080   // Accessors
1081   static oop            vmentry(oop lform);
1082 
1083   // Testers
1084   static bool is_subclass(Klass* klass) {
1085     return vmClasses::LambdaForm_klass() != nullptr &&
1086       klass->is_subclass_of(vmClasses::LambdaForm_klass());
1087   }
1088   static bool is_instance(oop obj);
1089 
1090   // Accessors for code generation:
1091   static int vmentry_offset()          { CHECK_INIT(_vmentry_offset); }
1092 };
1093 
1094 // Interface to java.lang.invoke.NativeEntryPoint objects
1095 // (These are a private interface for managing adapter code generation.)
1096 
1097 class jdk_internal_foreign_abi_NativeEntryPoint: AllStatic {
1098   friend class JavaClasses;
1099 
1100  private:
1101   static int _method_type_offset;
1102   static int _downcall_stub_address_offset;
1103 
1104   static void compute_offsets();
1105 
1106  public:
1107   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1108 
1109   // Accessors
1110   static oop        method_type(oop entry);
1111   static jlong      downcall_stub_address(oop entry);
1112 
1113   // Testers
1114   static bool is_subclass(Klass* klass) {
1115     return vmClasses::NativeEntryPoint_klass() != nullptr &&
1116       klass->is_subclass_of(vmClasses::NativeEntryPoint_klass());
1117   }
1118   static bool is_instance(oop obj);
1119 
1120   // Accessors for code generation:
1121   static int method_type_offset_in_bytes()           { return _method_type_offset; }
1122   static int downcall_stub_address_offset_in_bytes() { return _downcall_stub_address_offset; }
1123 };
1124 
1125 class jdk_internal_foreign_abi_ABIDescriptor: AllStatic {
1126   friend class JavaClasses;
1127 
1128  private:
1129   static int _inputStorage_offset;
1130   static int _outputStorage_offset;
1131   static int _volatileStorage_offset;
1132   static int _stackAlignment_offset;
1133   static int _shadowSpace_offset;
1134   static int _scratch1_offset;
1135   static int _scratch2_offset;
1136 
1137   static void compute_offsets();
1138 
1139  public:
1140   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1141 
1142   // Accessors
1143   static objArrayOop inputStorage(oop entry);
1144   static objArrayOop outputStorage(oop entry);
1145   static objArrayOop volatileStorage(oop entry);
1146   static jint        stackAlignment(oop entry);
1147   static jint        shadowSpace(oop entry);
1148   static oop         scratch1(oop entry);
1149   static oop         scratch2(oop entry);
1150 
1151   // Testers
1152   static bool is_subclass(Klass* klass) {
1153     return vmClasses::ABIDescriptor_klass() != nullptr &&
1154       klass->is_subclass_of(vmClasses::ABIDescriptor_klass());
1155   }
1156   static bool is_instance(oop obj);
1157 };
1158 
1159 class jdk_internal_foreign_abi_VMStorage: AllStatic {
1160   friend class JavaClasses;
1161 
1162  private:
1163   static int _type_offset;
1164   static int _indexOrOffset_offset;
1165   static int _segmentMaskOrSize_offset;
1166   static int _debugName_offset;
1167 
1168   static void compute_offsets();
1169 
1170  public:
1171   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1172 
1173   // Accessors
1174   static jbyte  type(oop entry);
1175   static jint   index_or_offset(oop entry);
1176   static jshort segment_mask_or_size(oop entry);
1177   static oop    debugName(oop entry);
1178 
1179   // Testers
1180   static bool is_subclass(Klass* klass) {
1181     return vmClasses::VMStorage_klass() != nullptr &&
1182       klass->is_subclass_of(vmClasses::VMStorage_klass());
1183   }
1184   static bool is_instance(oop obj);
1185 };
1186 
1187 class jdk_internal_foreign_abi_CallConv: AllStatic {
1188   friend class JavaClasses;
1189 
1190  private:
1191   static int _argRegs_offset;
1192   static int _retRegs_offset;
1193 
1194   static void compute_offsets();
1195 
1196  public:
1197   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1198 
1199   // Accessors
1200   static objArrayOop argRegs(oop entry);
1201   static objArrayOop retRegs(oop entry);
1202 
1203   // Testers
1204   static bool is_subclass(Klass* klass) {
1205     return vmClasses::CallConv_klass() != nullptr &&
1206       klass->is_subclass_of(vmClasses::CallConv_klass());
1207   }
1208   static bool is_instance(oop obj);
1209 };
1210 
1211 // Interface to java.lang.invoke.MemberName objects
1212 // (These are a private interface for Java code to query the class hierarchy.)
1213 
1214 #define RESOLVEDMETHOD_INJECTED_FIELDS(macro)                                   \
1215   macro(java_lang_invoke_ResolvedMethodName, vmholder, object_signature, false) \
1216   macro(java_lang_invoke_ResolvedMethodName, vmtarget, intptr_signature, false)
1217 
1218 class java_lang_invoke_ResolvedMethodName : AllStatic {
1219   friend class JavaClasses;
1220 
1221   static int _vmtarget_offset;
1222   static int _vmholder_offset;
1223 
1224   static void compute_offsets();
1225  public:
1226   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1227 
1228   static int vmtarget_offset() { CHECK_INIT(_vmtarget_offset); }
1229 
1230   static Method* vmtarget(oop resolved_method);
1231   static void set_vmtarget(oop resolved_method, Method* method);
1232 
1233   static void set_vmholder(oop resolved_method, oop holder);
1234 
1235   // find or create resolved member name
1236   static oop find_resolved_method(const methodHandle& m, TRAPS);
1237 
1238   static bool is_instance(oop resolved_method);
1239 };
1240 
1241 
1242 #define MEMBERNAME_INJECTED_FIELDS(macro)                               \
1243   macro(java_lang_invoke_MemberName, vmindex,  intptr_signature, false)
1244 
1245 
1246 class java_lang_invoke_MemberName: AllStatic {
1247   friend class JavaClasses;
1248 
1249  private:
1250   // From java.lang.invoke.MemberName:
1251   //    private Class<?>   clazz;       // class in which the method is defined
1252   //    private String     name;        // may be null if not yet materialized
1253   //    private Object     type;        // may be null if not yet materialized
1254   //    private int        flags;       // modifier bits; see reflect.Modifier
1255   //    private ResolvedMethodName method;    // holds VM-specific target value
1256   //    private intptr_t   vmindex;     // member index within class or interface
1257   static int _clazz_offset;
1258   static int _name_offset;
1259   static int _type_offset;
1260   static int _flags_offset;
1261   static int _method_offset;
1262   static int _vmindex_offset;
1263 
1264   static void compute_offsets();
1265 
1266  public:
1267   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1268   // Accessors
1269   static oop            clazz(oop mname);
1270   static void       set_clazz(oop mname, oop clazz);
1271 
1272   static oop            type(oop mname);
1273   static void       set_type(oop mname, oop type);
1274 
1275   static oop            name(oop mname);
1276   static void       set_name(oop mname, oop name);
1277 
1278   static int            flags(oop mname);
1279   static void       set_flags(oop mname, int flags);
1280 
1281   // Link through ResolvedMethodName field to get Method*
1282   static Method*        vmtarget(oop mname);
1283   static void       set_method(oop mname, oop method);
1284 
1285   static intptr_t       vmindex(oop mname);
1286   static void       set_vmindex(oop mname, intptr_t index);
1287 
1288   // Testers
1289   static bool is_subclass(Klass* klass) {
1290     return klass->is_subclass_of(vmClasses::MemberName_klass());
1291   }
1292   static bool is_instance(oop obj);
1293 
1294   static bool is_method(oop obj);
1295 
1296   // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):
1297   enum {
1298     MN_IS_METHOD             = 0x00010000, // method (not constructor)
1299     MN_IS_CONSTRUCTOR        = 0x00020000, // constructor
1300     MN_IS_FIELD              = 0x00040000, // field
1301     MN_IS_TYPE               = 0x00080000, // nested type
1302     MN_CALLER_SENSITIVE      = 0x00100000, // @CallerSensitive annotation detected
1303     MN_TRUSTED_FINAL         = 0x00200000, // trusted final field
1304     MN_REFERENCE_KIND_SHIFT  = 24, // refKind
1305     MN_REFERENCE_KIND_MASK   = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT,
1306     MN_NESTMATE_CLASS        = 0x00000001,
1307     MN_HIDDEN_CLASS          = 0x00000002,
1308     MN_STRONG_LOADER_LINK    = 0x00000004,
1309     MN_ACCESS_VM_ANNOTATIONS = 0x00000008,
1310     // Lookup modes
1311     MN_MODULE_MODE           = 0x00000010,
1312     MN_UNCONDITIONAL_MODE    = 0x00000020,
1313     MN_TRUSTED_MODE          = -1
1314   };
1315 
1316   // Accessors for code generation:
1317   static int clazz_offset()   { CHECK_INIT(_clazz_offset); }
1318   static int type_offset()    { CHECK_INIT(_type_offset); }
1319   static int flags_offset()   { CHECK_INIT(_flags_offset); }
1320   static int method_offset()  { CHECK_INIT(_method_offset); }
1321   static int vmindex_offset() { CHECK_INIT(_vmindex_offset); }
1322 };
1323 
1324 
1325 // Interface to java.lang.invoke.MethodType objects
1326 
1327 class java_lang_invoke_MethodType: AllStatic {
1328   friend class JavaClasses;
1329 
1330  private:
1331   static int _rtype_offset;
1332   static int _ptypes_offset;
1333 
1334   static void compute_offsets();
1335 
1336  public:
1337   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1338   // Accessors
1339   static oop            rtype(oop mt);
1340   static objArrayOop    ptypes(oop mt);
1341 
1342   static oop            ptype(oop mt, int index);
1343   static int            ptype_count(oop mt);
1344 
1345   static int            ptype_slot_count(oop mt);  // extra counts for long/double
1346   static int            rtype_slot_count(oop mt);  // extra counts for long/double
1347 
1348   static Symbol*        as_signature(oop mt, bool intern_if_not_found);
1349   static void           print_signature(oop mt, outputStream* st);
1350 
1351   static bool is_instance(oop obj);
1352 
1353   static bool equals(oop mt1, oop mt2);
1354 
1355   // Accessors for code generation:
1356   static int rtype_offset()  { CHECK_INIT(_rtype_offset); }
1357   static int ptypes_offset() { CHECK_INIT(_ptypes_offset); }
1358 };
1359 
1360 
1361 // Interface to java.lang.invoke.CallSite objects
1362 
1363 class java_lang_invoke_CallSite: AllStatic {
1364   friend class JavaClasses;
1365 
1366 private:
1367   static int _target_offset;
1368   static int _context_offset;
1369 
1370   static void compute_offsets();
1371 
1372 public:
1373   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1374   // Accessors
1375   static oop              target(          oop site);
1376   static void         set_target(          oop site, oop target);
1377   static void         set_target_volatile( oop site, oop target);
1378 
1379   static oop context_no_keepalive(oop site);
1380 
1381   // Testers
1382   static bool is_subclass(Klass* klass) {
1383     return klass->is_subclass_of(vmClasses::CallSite_klass());
1384   }
1385   static bool is_instance(oop obj);
1386 
1387   // Accessors for code generation:
1388   static int target_offset()  { CHECK_INIT(_target_offset); }
1389   static int context_offset() { CHECK_INIT(_context_offset); }
1390 };
1391 
1392 // Interface to java.lang.invoke.ConstantCallSite objects
1393 
1394 class java_lang_invoke_ConstantCallSite: AllStatic {
1395   friend class JavaClasses;
1396 
1397 private:
1398   static int _is_frozen_offset;
1399 
1400   static void compute_offsets();
1401 
1402 public:
1403   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1404   // Accessors
1405   static jboolean is_frozen(oop site);
1406 
1407   // Testers
1408   static bool is_subclass(Klass* klass) {
1409     return klass->is_subclass_of(vmClasses::ConstantCallSite_klass());
1410   }
1411   static bool is_instance(oop obj);
1412 };
1413 
1414 // Interface to java.lang.invoke.MethodHandleNatives$CallSiteContext objects
1415 
1416 #define CALLSITECONTEXT_INJECTED_FIELDS(macro) \
1417   macro(java_lang_invoke_MethodHandleNatives_CallSiteContext, vmdependencies, intptr_signature, false) \
1418   macro(java_lang_invoke_MethodHandleNatives_CallSiteContext, last_cleanup, long_signature, false)
1419 
1420 class DependencyContext;
1421 
1422 class java_lang_invoke_MethodHandleNatives_CallSiteContext : AllStatic {
1423   friend class JavaClasses;
1424 
1425 private:
1426   static int _vmdependencies_offset;
1427   static int _last_cleanup_offset;
1428 
1429   static void compute_offsets();
1430 
1431 public:
1432   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1433   // Accessors
1434   static DependencyContext vmdependencies(oop context);
1435 
1436   // Testers
1437   static bool is_subclass(Klass* klass) {
1438     return klass->is_subclass_of(vmClasses::Context_klass());
1439   }
1440   static bool is_instance(oop obj);
1441 };
1442 
1443 // Interface to java.security.AccessControlContext objects
1444 
1445 class java_security_AccessControlContext: AllStatic {
1446  private:
1447   // Note that for this class the layout changed between JDK1.2 and JDK1.3,
1448   // so we compute the offsets at startup rather than hard-wiring them.
1449   static int _context_offset;
1450   static int _privilegedContext_offset;
1451   static int _isPrivileged_offset;
1452   static int _isAuthorized_offset;
1453 
1454   static void compute_offsets();
1455  public:
1456   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1457   static oop create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS);
1458 
1459   // Debugging/initialization
1460   friend class JavaClasses;
1461 };
1462 
1463 
1464 // Interface to java.lang.ClassLoader objects
1465 
1466 #define CLASSLOADER_INJECTED_FIELDS(macro)                            \
1467   macro(java_lang_ClassLoader, loader_data,  intptr_signature, false)
1468 
1469 class java_lang_ClassLoader : AllStatic {
1470  private:
1471   static int _loader_data_offset;
1472   static int _parent_offset;
1473   static int _parallelCapable_offset;
1474   static int _name_offset;
1475   static int _nameAndId_offset;
1476   static int _unnamedModule_offset;
1477 
1478   static void compute_offsets();
1479 
1480  public:
1481   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
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 reflection.
1500   static bool is_reflection_class_loader(oop loader);
1501 
1502   // Fix for 4474172
1503   static oop  non_reflection_class_loader(oop loader);
1504 
1505   // Testers
1506   static bool is_subclass(Klass* klass) {
1507     return klass->is_subclass_of(vmClasses::ClassLoader_klass());
1508   }
1509   static bool is_instance(oop obj);
1510 
1511   static oop unnamedModule(oop loader);
1512 
1513   // Debugging
1514   friend class JavaClasses;
1515 };
1516 
1517 
1518 // Interface to java.lang.System objects
1519 
1520 class java_lang_System : AllStatic {
1521  private:
1522   static int _static_in_offset;
1523   static int _static_out_offset;
1524   static int _static_err_offset;
1525   static int _static_security_offset;
1526   static int _static_allow_security_offset;
1527   static int _static_never_offset;
1528 
1529  public:
1530   static int  in_offset() { CHECK_INIT(_static_in_offset); }
1531   static int out_offset() { CHECK_INIT(_static_out_offset); }
1532   static int err_offset() { CHECK_INIT(_static_err_offset); }
1533   static bool allow_security_manager();
1534   static bool has_security_manager();
1535 
1536   static void compute_offsets();
1537   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1538 
1539   // Debugging
1540   friend class JavaClasses;
1541 };
1542 
1543 
1544 // Interface to java.lang.StackTraceElement objects
1545 
1546 class java_lang_StackTraceElement: AllStatic {
1547  private:
1548   static int _declaringClassObject_offset;
1549   static int _classLoaderName_offset;
1550   static int _moduleName_offset;
1551   static int _moduleVersion_offset;
1552   static int _declaringClass_offset;
1553   static int _methodName_offset;
1554   static int _fileName_offset;
1555   static int _lineNumber_offset;
1556 
1557   // Setters
1558   static void set_classLoaderName(oop element, oop value);
1559   static void set_moduleName(oop element, oop value);
1560   static void set_moduleVersion(oop element, oop value);
1561   static void set_declaringClass(oop element, oop value);
1562   static void set_methodName(oop element, oop value);
1563   static void set_fileName(oop element, oop value);
1564   static void set_lineNumber(oop element, int value);
1565   static void set_declaringClassObject(oop element, oop value);
1566 
1567   static void decode_file_and_line(Handle java_mirror, InstanceKlass* holder, int version,
1568                                    const methodHandle& method, int bci,
1569                                    Symbol*& source, oop& source_file, int& line_number, TRAPS);
1570 
1571  public:
1572   // Create an instance of StackTraceElement
1573   static oop create(const methodHandle& method, int bci, TRAPS);
1574 
1575   static void fill_in(Handle element, InstanceKlass* holder, const methodHandle& method,
1576                       int version, int bci, Symbol* name, TRAPS);
1577 
1578   static void compute_offsets();
1579   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1580 
1581 #if INCLUDE_JVMCI
1582   static void decode(const methodHandle& method, int bci, Symbol*& fileName, int& lineNumber, TRAPS);
1583 #endif
1584 
1585   // Debugging
1586   friend class JavaClasses;
1587 };
1588 
1589 
1590 class Backtrace: AllStatic {
1591  public:
1592   // Helper backtrace functions to store bci|version together.
1593   static int merge_bci_and_version(int bci, int version);
1594   static int merge_mid_and_cpref(int mid, int cpref);
1595   static int bci_at(unsigned int merged);
1596   static int version_at(unsigned int merged);
1597   static int mid_at(unsigned int merged);
1598   static int cpref_at(unsigned int merged);
1599   static int get_line_number(Method* method, int bci);
1600   static Symbol* get_source_file_name(InstanceKlass* holder, int version);
1601 
1602   // Debugging
1603   friend class JavaClasses;
1604 };
1605 
1606 // Interface to java.lang.StackFrameInfo objects
1607 
1608 #define STACKFRAMEINFO_INJECTED_FIELDS(macro)                      \
1609   macro(java_lang_StackFrameInfo, version, short_signature, false)
1610 
1611 class java_lang_StackFrameInfo: AllStatic {
1612 private:
1613   static int _memberName_offset;
1614   static int _bci_offset;
1615   static int _version_offset;
1616   static int _contScope_offset;
1617 
1618   static Method* get_method(Handle stackFrame, InstanceKlass* holder, TRAPS);
1619 
1620 public:
1621   // Setters
1622   static void set_method_and_bci(Handle stackFrame, const methodHandle& method, int bci, oop cont, TRAPS);
1623   static void set_bci(oop info, int value);
1624 
1625   static void set_version(oop info, short value);
1626   static void set_contScope(oop info, oop value);
1627 
1628   static void compute_offsets();
1629   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1630 
1631   static void to_stack_trace_element(Handle stackFrame, Handle stack_trace_element, TRAPS);
1632 
1633   // Debugging
1634   friend class JavaClasses;
1635 };
1636 
1637 class java_lang_LiveStackFrameInfo: AllStatic {
1638  private:
1639   static int _monitors_offset;
1640   static int _locals_offset;
1641   static int _operands_offset;
1642   static int _mode_offset;
1643 
1644  public:
1645   static void set_monitors(oop info, oop value);
1646   static void set_locals(oop info, oop value);
1647   static void set_operands(oop info, oop value);
1648   static void set_mode(oop info, int value);
1649 
1650   static void compute_offsets();
1651   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1652 
1653   // Debugging
1654   friend class JavaClasses;
1655 };
1656 
1657 // Interface to java.lang.reflect.RecordComponent objects
1658 
1659 class java_lang_reflect_RecordComponent: AllStatic {
1660  private:
1661   static int _clazz_offset;
1662   static int _name_offset;
1663   static int _type_offset;
1664   static int _accessor_offset;
1665   static int _signature_offset;
1666   static int _annotations_offset;
1667   static int _typeAnnotations_offset;
1668 
1669   // Setters
1670   static void set_clazz(oop element, oop value);
1671   static void set_name(oop element, oop value);
1672   static void set_type(oop element, oop value);
1673   static void set_accessor(oop element, oop value);
1674   static void set_signature(oop element, oop value);
1675   static void set_annotations(oop element, oop value);
1676   static void set_typeAnnotations(oop element, oop value);
1677 
1678  public:
1679   // Create an instance of RecordComponent
1680   static oop create(InstanceKlass* holder, RecordComponent* component, TRAPS);
1681 
1682   static void compute_offsets();
1683   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1684 
1685   // Debugging
1686   friend class JavaClasses;
1687 };
1688 
1689 
1690 // Interface to java.lang.AssertionStatusDirectives objects
1691 
1692 class java_lang_AssertionStatusDirectives: AllStatic {
1693  private:
1694   static int _classes_offset;
1695   static int _classEnabled_offset;
1696   static int _packages_offset;
1697   static int _packageEnabled_offset;
1698   static int _deflt_offset;
1699 
1700  public:
1701   // Setters
1702   static void set_classes(oop obj, oop val);
1703   static void set_classEnabled(oop obj, oop val);
1704   static void set_packages(oop obj, oop val);
1705   static void set_packageEnabled(oop obj, oop val);
1706   static void set_deflt(oop obj, bool val);
1707 
1708   static void compute_offsets();
1709   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1710 
1711   // Debugging
1712   friend class JavaClasses;
1713 };
1714 
1715 
1716 class java_util_concurrent_locks_AbstractOwnableSynchronizer : AllStatic {
1717  private:
1718   static int  _owner_offset;
1719  public:
1720   static void compute_offsets();
1721   static oop  get_owner_threadObj(oop obj);
1722   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1723 };
1724 
1725  // Interface to jdk.internal.misc.UnsafeConsants
1726 
1727 class jdk_internal_misc_UnsafeConstants : AllStatic {
1728  public:
1729   static void set_unsafe_constants();
1730   static void compute_offsets() { }
1731   static void serialize_offsets(SerializeClosure* f) { }
1732 };
1733 
1734 // Interface to jdk.internal.vm.vector.VectorSupport.VectorPayload objects
1735 
1736 class vector_VectorPayload : AllStatic {
1737  private:
1738   static int _payload_offset;
1739  public:
1740   static void set_payload(oop o, oop val);
1741 
1742   static void compute_offsets();
1743   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1744 
1745   // Testers
1746   static bool is_subclass(Klass* klass) {
1747     return klass->is_subclass_of(vmClasses::vector_VectorPayload_klass());
1748   }
1749   static bool is_instance(oop obj);
1750 };
1751 
1752 class java_lang_Integer : AllStatic {
1753 public:
1754   static jint value(oop obj);
1755 };
1756 
1757 class java_lang_Long : AllStatic {
1758 public:
1759   static jlong value(oop obj);
1760 };
1761 
1762 class java_lang_Character : AllStatic {
1763 public:
1764   static jchar value(oop obj);
1765 };
1766 
1767 class java_lang_Short : AllStatic {
1768 public:
1769   static jshort value(oop obj);
1770 };
1771 
1772 class java_lang_Byte : AllStatic {
1773 public:
1774   static jbyte value(oop obj);
1775 };
1776 
1777 class java_lang_Boolean : AllStatic {
1778  private:
1779   static int _static_TRUE_offset;
1780   static int _static_FALSE_offset;
1781  public:
1782   static Symbol* symbol();
1783   static void compute_offsets(InstanceKlass* k);
1784   static oop  get_TRUE(InstanceKlass *k);
1785   static oop  get_FALSE(InstanceKlass *k);
1786   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1787   static jboolean value(oop obj);
1788 };
1789 
1790 class java_lang_Integer_IntegerCache : AllStatic {
1791  private:
1792   static int _static_cache_offset;
1793  public:
1794   static Symbol* symbol();
1795   static void compute_offsets(InstanceKlass* k);
1796   static objArrayOop  cache(InstanceKlass *k);
1797   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1798 };
1799 
1800 class java_lang_Long_LongCache : AllStatic {
1801  private:
1802   static int _static_cache_offset;
1803  public:
1804   static Symbol* symbol();
1805   static void compute_offsets(InstanceKlass* k);
1806   static objArrayOop  cache(InstanceKlass *k);
1807   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1808 };
1809 
1810 class java_lang_Character_CharacterCache : AllStatic {
1811  private:
1812   static int _static_cache_offset;
1813  public:
1814   static Symbol* symbol();
1815   static void compute_offsets(InstanceKlass* k);
1816   static objArrayOop  cache(InstanceKlass *k);
1817   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1818 };
1819 
1820 class java_lang_Short_ShortCache : AllStatic {
1821  private:
1822   static int _static_cache_offset;
1823  public:
1824   static Symbol* symbol();
1825   static void compute_offsets(InstanceKlass* k);
1826   static objArrayOop  cache(InstanceKlass *k);
1827   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1828 };
1829 
1830 class java_lang_Byte_ByteCache : AllStatic {
1831  private:
1832   static int _static_cache_offset;
1833  public:
1834   static Symbol* symbol();
1835   static void compute_offsets(InstanceKlass* k);
1836   static objArrayOop  cache(InstanceKlass *k);
1837   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1838 };
1839 
1840 
1841 // Interface to java.lang.InternalError objects
1842 
1843 #define INTERNALERROR_INJECTED_FIELDS(macro)                      \
1844   macro(java_lang_InternalError, during_unsafe_access, bool_signature, false)
1845 
1846 class java_lang_InternalError : AllStatic {
1847  private:
1848   static int _during_unsafe_access_offset;
1849  public:
1850   static jboolean during_unsafe_access(oop internal_error);
1851   static void set_during_unsafe_access(oop internal_error);
1852   static void compute_offsets();
1853   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1854 };
1855 
1856 // Use to declare fields that need to be injected into Java classes
1857 // for the JVM to use.  The name_index and signature_index are
1858 // declared in vmSymbols.  The may_be_java flag is used to declare
1859 // fields that might already exist in Java but should be injected if
1860 // they don't.  Otherwise the field is unconditionally injected and
1861 // the JVM uses the injected one.  This is to ensure that name
1862 // collisions don't occur.  In general may_be_java should be false
1863 // unless there's a good reason.
1864 
1865 class InjectedField {
1866  public:
1867   const vmClassID klass_id;
1868   const vmSymbolID name_index;
1869   const vmSymbolID signature_index;
1870   const bool           may_be_java;
1871 
1872 
1873   Klass* klass() const      { return vmClasses::klass_at(klass_id); }
1874   Symbol* name() const      { return lookup_symbol(name_index); }
1875   Symbol* signature() const { return lookup_symbol(signature_index); }
1876 
1877   int compute_offset();
1878 
1879   // Find the Symbol for this index
1880   static Symbol* lookup_symbol(vmSymbolID symbol_index) {
1881     return Symbol::vm_symbol_at(symbol_index);
1882   }
1883 };
1884 
1885 
1886 // Interface to hard-coded offset checking
1887 
1888 enum class InjectedFieldID : int;
1889 
1890 class JavaClasses : AllStatic {
1891  private:
1892 
1893   static InjectedField _injected_fields[];
1894 
1895   static bool check_offset(const char *klass_name, int offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1896  public:
1897 
1898   static int compute_injected_offset(InjectedFieldID id);
1899 
1900   static void compute_offsets();
1901   static void check_offsets() PRODUCT_RETURN;
1902   static void serialize_offsets(SerializeClosure* soc) NOT_CDS_RETURN;
1903   static InjectedField* get_injected(Symbol* class_name, int* field_count);
1904   static bool is_supported_for_archiving(oop obj) NOT_CDS_JAVA_HEAP_RETURN_(false);
1905 
1906   static void compute_offset(int &dest_offset,
1907                              InstanceKlass* ik, Symbol* name_symbol, Symbol* signature_symbol,
1908                              bool is_static = false);
1909   static void compute_offset(int& dest_offset, InstanceKlass* ik,
1910                              const char* name_string, Symbol* signature_symbol,
1911                              bool is_static = false);
1912 };
1913 
1914 #undef CHECK_INIT
1915 
1916 #endif // SHARE_CLASSFILE_JAVACLASSES_HPP