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