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