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