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