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