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