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