1 /*
   2  * Copyright (c) 1997, 2019, 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/systemDictionary.hpp"
  29 #include "jvmtifiles/jvmti.h"
  30 #include "oops/oop.hpp"
  31 #include "runtime/os.hpp"
  32 
  33 // Interface for manipulating the basic Java classes.
  34 //
  35 // All dependencies on layout of actual Java classes should be kept here.
  36 // If the layout of any of the classes above changes the offsets must be adjusted.
  37 //
  38 // For most classes we hardwire the offsets for performance reasons. In certain
  39 // cases (e.g. java.security.AccessControlContext) we compute the offsets at
  40 // startup since the layout here differs between JDK1.2 and JDK1.3.
  41 //
  42 // Note that fields (static and non-static) are arranged with oops before non-oops
  43 // on a per class basis. The offsets below have to reflect this ordering.
  44 //
  45 // When editing the layouts please update the check_offset verification code
  46 // correspondingly. The names in the enums must be identical to the actual field
  47 // names in order for the verification code to work.
  48 
  49 #define BASIC_JAVA_CLASSES_DO_PART1(f) \
  50   f(java_lang_Class) \
  51   f(java_lang_String) \
  52   //end
  53 
  54 #define BASIC_JAVA_CLASSES_DO_PART2(f) \
  55   f(java_lang_System) \
  56   f(java_lang_ClassLoader) \
  57   f(java_lang_Throwable) \
  58   f(java_lang_Thread) \
  59   f(java_lang_ThreadGroup) \
  60   f(java_lang_AssertionStatusDirectives) \
  61   f(java_lang_ref_SoftReference) \
  62   f(java_lang_invoke_MethodHandle) \
  63   f(java_lang_invoke_DirectMethodHandle) \
  64   f(java_lang_invoke_MemberName) \
  65   f(java_lang_invoke_ResolvedMethodName) \
  66   f(java_lang_invoke_LambdaForm) \
  67   f(java_lang_invoke_MethodType) \
  68   f(java_lang_invoke_CallSite) \
  69   f(java_lang_invoke_MethodHandleNatives_CallSiteContext) \
  70   f(java_security_AccessControlContext) \
  71   f(java_lang_reflect_AccessibleObject) \
  72   f(java_lang_reflect_Method) \
  73   f(java_lang_reflect_Constructor) \
  74   f(java_lang_reflect_Field) \
  75   f(java_nio_Buffer) \
  76   f(reflect_ConstantPool) \
  77   f(reflect_UnsafeStaticFieldAccessorImpl) \
  78   f(java_lang_reflect_Parameter) \
  79   f(java_lang_Module) \
  80   f(java_lang_StackTraceElement) \
  81   f(java_lang_StackFrameInfo) \
  82   f(java_lang_LiveStackFrameInfo) \
  83   f(java_util_concurrent_locks_AbstractOwnableSynchronizer) \
  84   f(jdk_internal_misc_UnsafeConstants) \
  85   //end
  86 
  87 #define BASIC_JAVA_CLASSES_DO(f) \
  88         BASIC_JAVA_CLASSES_DO_PART1(f) \
  89         BASIC_JAVA_CLASSES_DO_PART2(f)
  90 
  91 // Interface to java.lang.Object objects
  92 
  93 class java_lang_Object : AllStatic {
  94  public:
  95   static void register_natives(TRAPS);
  96 };
  97 
  98 // Interface to java.lang.String objects
  99 
 100 class java_lang_String : AllStatic {
 101  private:
 102   static int value_offset;
 103   static int hash_offset;
 104   static int hashIsZero_offset;
 105   static int coder_offset;
 106 
 107   static bool initialized;
 108 
 109   static Handle basic_create(int length, bool byte_arr, TRAPS);
 110 
 111   static inline void set_coder(oop string, jbyte coder);
 112 
 113  public:
 114 
 115   // Coders
 116   enum Coder {
 117     CODER_LATIN1 =  0,
 118     CODER_UTF16  =  1
 119   };
 120 
 121   static void compute_offsets();
 122   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 123 
 124   // Instance creation
 125   static Handle create_from_unicode(const jchar* unicode, int len, TRAPS);
 126   static oop    create_oop_from_unicode(const jchar* unicode, int len, TRAPS);
 127   static Handle create_from_str(const char* utf8_str, TRAPS);
 128   static oop    create_oop_from_str(const char* utf8_str, TRAPS);
 129   static Handle create_from_symbol(Symbol* symbol, TRAPS);
 130   static Handle create_from_platform_dependent_str(const char* str, TRAPS);
 131   static Handle char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS);
 132 
 133   static void set_compact_strings(bool value);
 134 
 135   static int value_offset_in_bytes()  {
 136     assert(initialized && (value_offset > 0), "Must be initialized");
 137     return value_offset;
 138   }
 139   static int hash_offset_in_bytes()   {
 140     assert(initialized && (hash_offset > 0), "Must be initialized");
 141     return hash_offset;
 142   }
 143   static int hashIsZero_offset_in_bytes()   {
 144     assert(initialized && (hashIsZero_offset > 0), "Must be initialized");
 145     return hashIsZero_offset;
 146   }
 147   static int coder_offset_in_bytes()   {
 148     assert(initialized && (coder_offset > 0), "Must be initialized");
 149     return coder_offset;
 150   }
 151 
 152   static inline void set_value_raw(oop string, typeArrayOop buffer);
 153   static inline void set_value(oop string, typeArrayOop buffer);
 154 
 155   // Accessors
 156   static inline typeArrayOop value(oop java_string);
 157   static inline typeArrayOop value_no_keepalive(oop java_string);
 158   static inline bool hash_is_set(oop string);
 159   static inline bool is_latin1(oop java_string);
 160   static inline int length(oop java_string);
 161   static inline int length(oop java_string, typeArrayOop string_value);
 162   static int utf8_length(oop java_string);
 163   static int utf8_length(oop java_string, typeArrayOop string_value);
 164 
 165   // String converters
 166   static char*  as_utf8_string(oop java_string);
 167   static char*  as_utf8_string(oop java_string, char* buf, int buflen);
 168   static char*  as_utf8_string(oop java_string, int start, int len);
 169   static char*  as_utf8_string(oop java_string, typeArrayOop value, char* buf, int buflen);
 170   static char*  as_utf8_string(oop java_string, typeArrayOop value, int start, int len, char* buf, int buflen);
 171   static char*  as_platform_dependent_str(Handle java_string, TRAPS);
 172   static jchar* as_unicode_string(oop java_string, int& length, TRAPS);
 173   // produce an ascii string with all other values quoted using \u####
 174   static char*  as_quoted_ascii(oop java_string);
 175 
 176   // Compute the hash value for a java.lang.String object which would
 177   // contain the characters passed in.
 178   //
 179   // As the hash value used by the String object itself, in
 180   // String.hashCode().  This value is normally calculated in Java code
 181   // in the String.hashCode method(), but is precomputed for String
 182   // objects in the shared archive file.
 183   // hash P(31) from Kernighan & Ritchie
 184   //
 185   // For this reason, THIS ALGORITHM MUST MATCH String.hashCode().
 186   static unsigned int hash_code(const jchar* s, int len) {
 187     unsigned int h = 0;
 188     while (len-- > 0) {
 189       h = 31*h + (unsigned int) *s;
 190       s++;
 191     }
 192     return h;
 193   }
 194 
 195   static unsigned int hash_code(const jbyte* s, int len) {
 196     unsigned int h = 0;
 197     while (len-- > 0) {
 198       h = 31*h + (((unsigned int) *s) & 0xFF);
 199       s++;
 200     }
 201     return h;
 202   }
 203 
 204   static unsigned int hash_code(oop java_string);
 205 
 206   static bool equals(oop java_string, const jchar* chars, int len);
 207   static bool equals(oop str1, oop str2);
 208   static inline bool value_equals(typeArrayOop str_value1, typeArrayOop str_value2);
 209 
 210   // Conversion between '.' and '/' formats
 211   static Handle externalize_classname(Handle java_string, TRAPS) {
 212     return char_converter(java_string, JVM_SIGNATURE_SLASH, JVM_SIGNATURE_DOT, THREAD);
 213   }
 214 
 215   // Conversion
 216   static Symbol* as_symbol(oop java_string);
 217   static Symbol* as_symbol_or_null(oop java_string);
 218 
 219   // Testers
 220   static bool is_instance(oop obj);
 221   static inline bool is_instance_inlined(oop obj);
 222 
 223   // Debugging
 224   static void print(oop java_string, outputStream* st);
 225   friend class JavaClasses;
 226   friend class StringTable;
 227 };
 228 
 229 
 230 // Interface to java.lang.Class objects
 231 
 232 #define CLASS_INJECTED_FIELDS(macro)                                       \
 233   macro(java_lang_Class, klass,                  intptr_signature,  false) \
 234   macro(java_lang_Class, array_klass,            intptr_signature,  false) \
 235   macro(java_lang_Class, oop_size,               int_signature,     false) \
 236   macro(java_lang_Class, static_oop_field_count, int_signature,     false) \
 237   macro(java_lang_Class, protection_domain,      object_signature,  false) \
 238   macro(java_lang_Class, signers,                object_signature,  false) \
 239   macro(java_lang_Class, source_file,            object_signature,  false) \
 240   macro(java_lang_Class, classData,              object_signature,  false)
 241 
 242 class java_lang_Class : AllStatic {
 243   friend class VMStructs;
 244   friend class JVMCIVMStructs;
 245 
 246  private:
 247   // The fake offsets are added by the class loader when java.lang.Class is loaded
 248 
 249   static int _klass_offset;
 250   static int _array_klass_offset;
 251 
 252   static int _oop_size_offset;
 253   static int _static_oop_field_count_offset;
 254 
 255   static int _protection_domain_offset;
 256   static int _init_lock_offset;
 257   static int _signers_offset;
 258   static int _class_loader_offset;
 259   static int _module_offset;
 260   static int _component_mirror_offset;
 261   static int _name_offset;
 262   static int _source_file_offset;
 263   static int _classData_offset;
 264 
 265   static bool offsets_computed;
 266   static int classRedefinedCount_offset;
 267 
 268   static GrowableArray<Klass*>* _fixup_mirror_list;
 269   static GrowableArray<Klass*>* _fixup_module_field_list;
 270 
 271   static void set_init_lock(oop java_class, oop init_lock);
 272   static void set_protection_domain(oop java_class, oop protection_domain);
 273   static void set_class_loader(oop java_class, oop class_loader);
 274   static void set_component_mirror(oop java_class, oop comp_mirror);
 275   static void initialize_mirror_fields(Klass* k, Handle mirror, Handle protection_domain,
 276                                        Handle classData, TRAPS);
 277   static void set_mirror_module_field(Klass* K, Handle mirror, Handle module, TRAPS);
 278  public:
 279   static void allocate_fixup_lists();
 280   static void compute_offsets();
 281 
 282   // Instance creation
 283   static void create_mirror(Klass* k, Handle class_loader, Handle module,
 284                             Handle protection_domain, Handle classData, TRAPS);
 285   static void fixup_mirror(Klass* k, TRAPS);
 286   static oop  create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS);
 287   static void update_archived_primitive_mirror_native_pointers(oop archived_mirror) NOT_CDS_JAVA_HEAP_RETURN;
 288   static void update_archived_mirror_native_pointers(oop archived_mirror) NOT_CDS_JAVA_HEAP_RETURN;
 289 
 290   // Archiving
 291   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 292   static void archive_basic_type_mirrors(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
 293   static oop  archive_mirror(Klass* k, TRAPS) NOT_CDS_JAVA_HEAP_RETURN_(NULL);
 294   static oop  process_archived_mirror(Klass* k, oop mirror, oop archived_mirror, Thread *THREAD)
 295                                       NOT_CDS_JAVA_HEAP_RETURN_(NULL);
 296   static bool restore_archived_mirror(Klass *k, Handle class_loader, Handle module,
 297                                       Handle protection_domain,
 298                                       TRAPS) NOT_CDS_JAVA_HEAP_RETURN_(false);
 299 
 300   static void fixup_module_field(Klass* k, Handle module);
 301 
 302   // Conversion
 303   static Klass* as_Klass(oop java_class);
 304   static Klass* as_Klass_raw(oop java_class);
 305   static void set_klass(oop java_class, Klass* klass);
 306   static BasicType as_BasicType(oop java_class, Klass** reference_klass = NULL);
 307   static Symbol* as_signature(oop java_class, bool intern_if_not_found);
 308   static void print_signature(oop java_class, outputStream *st);
 309   static const char* as_external_name(oop java_class);
 310   // Testing
 311   static bool is_instance(oop obj);
 312 
 313   static bool is_primitive(oop java_class);
 314   static BasicType primitive_type(oop java_class);
 315   static oop primitive_mirror(BasicType t);
 316   // JVM_NewArray support
 317   static Klass* array_klass_acquire(oop java_class);
 318   static void release_set_array_klass(oop java_class, Klass* klass);
 319   // compiler support for class operations
 320   static int klass_offset_in_bytes()                { return _klass_offset; }
 321   static int array_klass_offset_in_bytes()          { return _array_klass_offset; }
 322   // Support for classRedefinedCount field
 323   static int classRedefinedCount(oop the_class_mirror);
 324   static void set_classRedefinedCount(oop the_class_mirror, int value);
 325 
 326   // Support for embedded per-class oops
 327   static oop  protection_domain(oop java_class);
 328   static oop  init_lock(oop java_class);
 329   static oop  component_mirror(oop java_class);
 330   static objArrayOop  signers(oop java_class);
 331   static void set_signers(oop java_class, objArrayOop signers);
 332   static oop  class_data(oop java_class);
 333   static void set_class_data(oop java_class, oop classData);
 334 
 335   static oop class_loader(oop java_class);
 336   static void set_module(oop java_class, oop module);
 337   static oop module(oop java_class);
 338 
 339   static oop name(Handle java_class, TRAPS);
 340 
 341   static oop source_file(oop java_class);
 342   static void set_source_file(oop java_class, oop source_file);
 343 
 344   static int oop_size(oop java_class);
 345   static int oop_size_raw(oop java_class);
 346   static void set_oop_size(HeapWord* java_class, int size);
 347   static int static_oop_field_count(oop java_class);
 348   static int static_oop_field_count_raw(oop java_class);
 349   static void set_static_oop_field_count(oop java_class, int size);
 350 
 351   static GrowableArray<Klass*>* fixup_mirror_list() {
 352     return _fixup_mirror_list;
 353   }
 354   static void set_fixup_mirror_list(GrowableArray<Klass*>* v) {
 355     _fixup_mirror_list = v;
 356   }
 357 
 358   static GrowableArray<Klass*>* fixup_module_field_list() {
 359     return _fixup_module_field_list;
 360   }
 361   static void set_fixup_module_field_list(GrowableArray<Klass*>* v) {
 362     _fixup_module_field_list = v;
 363   }
 364 
 365   // Debugging
 366   friend class JavaClasses;
 367   friend class InstanceKlass;   // verification code accesses offsets
 368   friend class ClassFileParser; // access to number_of_fake_fields
 369 };
 370 
 371 // Interface to java.lang.Thread objects
 372 
 373 class java_lang_Thread : AllStatic {
 374  private:
 375   // Note that for this class the layout changed between JDK1.2 and JDK1.3,
 376   // so we compute the offsets at startup rather than hard-wiring them.
 377   static int _name_offset;
 378   static int _group_offset;
 379   static int _contextClassLoader_offset;
 380   static int _inheritedAccessControlContext_offset;
 381   static int _priority_offset;
 382   static int _eetop_offset;
 383   static int _interrupted_offset;
 384   static int _daemon_offset;
 385   static int _stillborn_offset;
 386   static int _stackSize_offset;
 387   static int _tid_offset;
 388   static int _thread_status_offset;
 389   static int _park_blocker_offset;
 390 
 391   static void compute_offsets();
 392 
 393  public:
 394   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 395 
 396   // Instance creation
 397   static oop create();
 398   // Returns the JavaThread associated with the thread obj
 399   static JavaThread* thread(oop java_thread);
 400   // Set JavaThread for instance
 401   static void set_thread(oop java_thread, JavaThread* thread);
 402   // Interrupted status
 403   static bool interrupted(oop java_thread);
 404   static void set_interrupted(oop java_thread, bool val);
 405   // Name
 406   static oop name(oop java_thread);
 407   static void set_name(oop java_thread, oop name);
 408   // Priority
 409   static ThreadPriority priority(oop java_thread);
 410   static void set_priority(oop java_thread, ThreadPriority priority);
 411   // Thread group
 412   static oop  threadGroup(oop java_thread);
 413   // Stillborn
 414   static bool is_stillborn(oop java_thread);
 415   static void set_stillborn(oop java_thread);
 416   // Alive (NOTE: this is not really a field, but provides the correct
 417   // definition without doing a Java call)
 418   static bool is_alive(oop java_thread);
 419   // Daemon
 420   static bool is_daemon(oop java_thread);
 421   static void set_daemon(oop java_thread);
 422   // Context ClassLoader
 423   static oop context_class_loader(oop java_thread);
 424   // Control context
 425   static oop inherited_access_control_context(oop java_thread);
 426   // Stack size hint
 427   static jlong stackSize(oop java_thread);
 428   // Thread ID
 429   static jlong thread_id(oop java_thread);
 430 
 431   // Blocker object responsible for thread parking
 432   static oop park_blocker(oop java_thread);
 433 
 434   // Java Thread Status for JVMTI and M&M use.
 435   // This thread status info is saved in threadStatus field of
 436   // java.lang.Thread java class.
 437   enum ThreadStatus {
 438     NEW                      = 0,
 439     RUNNABLE                 = JVMTI_THREAD_STATE_ALIVE +          // runnable / running
 440                                JVMTI_THREAD_STATE_RUNNABLE,
 441     SLEEPING                 = JVMTI_THREAD_STATE_ALIVE +          // Thread.sleep()
 442                                JVMTI_THREAD_STATE_WAITING +
 443                                JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
 444                                JVMTI_THREAD_STATE_SLEEPING,
 445     IN_OBJECT_WAIT           = JVMTI_THREAD_STATE_ALIVE +          // Object.wait()
 446                                JVMTI_THREAD_STATE_WAITING +
 447                                JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
 448                                JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
 449     IN_OBJECT_WAIT_TIMED     = JVMTI_THREAD_STATE_ALIVE +          // Object.wait(long)
 450                                JVMTI_THREAD_STATE_WAITING +
 451                                JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
 452                                JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
 453     PARKED                   = JVMTI_THREAD_STATE_ALIVE +          // LockSupport.park()
 454                                JVMTI_THREAD_STATE_WAITING +
 455                                JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
 456                                JVMTI_THREAD_STATE_PARKED,
 457     PARKED_TIMED             = JVMTI_THREAD_STATE_ALIVE +          // LockSupport.park(long)
 458                                JVMTI_THREAD_STATE_WAITING +
 459                                JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
 460                                JVMTI_THREAD_STATE_PARKED,
 461     BLOCKED_ON_MONITOR_ENTER = JVMTI_THREAD_STATE_ALIVE +          // (re-)entering a synchronization block
 462                                JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER,
 463     TERMINATED               = JVMTI_THREAD_STATE_TERMINATED
 464   };
 465   // Write thread status info to threadStatus field of java.lang.Thread.
 466   static void set_thread_status(oop java_thread_oop, ThreadStatus status);
 467   // Read thread status info from threadStatus field of java.lang.Thread.
 468   static ThreadStatus 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   // Offsets
 528   enum {
 529     hc_backtrace_offset     =  0,
 530     hc_detailMessage_offset =  1,
 531     hc_cause_offset         =  2,  // New since 1.4
 532     hc_stackTrace_offset    =  3   // New since 1.4
 533   };
 534   // Trace constants
 535   enum {
 536     trace_methods_offset = 0,
 537     trace_bcis_offset    = 1,
 538     trace_mirrors_offset = 2,
 539     trace_names_offset   = 3,
 540     trace_next_offset    = 4,
 541     trace_hidden_offset  = 5,
 542     trace_size           = 6,
 543     trace_chunk_size     = 32
 544   };
 545 
 546   static int backtrace_offset;
 547   static int detailMessage_offset;
 548   static int stackTrace_offset;
 549   static int depth_offset;
 550   static int static_unassigned_stacktrace_offset;
 551 
 552   // StackTrace (programmatic access, new since 1.4)
 553   static void clear_stacktrace(oop throwable);
 554   // Stacktrace (post JDK 1.7.0 to allow immutability protocol to be followed)
 555   static void set_stacktrace(oop throwable, oop st_element_array);
 556   static oop unassigned_stacktrace();
 557 
 558  public:
 559   // Backtrace
 560   static oop backtrace(oop throwable);
 561   static void set_backtrace(oop throwable, oop value);
 562   static int depth(oop throwable);
 563   static void set_depth(oop throwable, int value);
 564   // Needed by JVMTI to filter out this internal field.
 565   static int get_backtrace_offset() { return backtrace_offset;}
 566   static int get_detailMessage_offset() { return detailMessage_offset;}
 567   // Message
 568   static oop message(oop throwable);
 569   static void set_message(oop throwable, oop value);
 570   static Symbol* detail_message(oop throwable);
 571   static void print_stack_element(outputStream *st, Method* method, int bci);
 572   static void print_stack_usage(Handle stream);
 573 
 574   static void compute_offsets();
 575   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 576 
 577   // Allocate space for backtrace (created but stack trace not filled in)
 578   static void allocate_backtrace(Handle throwable, TRAPS);
 579   // Fill in current stack trace for throwable with preallocated backtrace (no GC)
 580   static void fill_in_stack_trace_of_preallocated_backtrace(Handle throwable);
 581   // Fill in current stack trace, can cause GC
 582   static void fill_in_stack_trace(Handle throwable, const methodHandle& method, TRAPS);
 583   static void fill_in_stack_trace(Handle throwable, const methodHandle& method = methodHandle());
 584   // Programmatic access to stack trace
 585   static void get_stack_trace_elements(Handle throwable, objArrayHandle stack_trace, TRAPS);
 586   // Printing
 587   static void print(oop throwable, outputStream* st);
 588   static void print_stack_trace(Handle throwable, outputStream* st);
 589   static void java_printStackTrace(Handle throwable, TRAPS);
 590   // Debugging
 591   friend class JavaClasses;
 592   // Gets the method and bci of the top frame (TOS). Returns false if this failed.
 593   static bool get_top_method_and_bci(oop throwable, Method** method, int* bci);
 594 };
 595 
 596 
 597 // Interface to java.lang.reflect.AccessibleObject objects
 598 
 599 class java_lang_reflect_AccessibleObject: AllStatic {
 600  private:
 601   // Note that to reduce dependencies on the JDK we compute these
 602   // offsets at run-time.
 603   static int override_offset;
 604 
 605   static void compute_offsets();
 606 
 607  public:
 608   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 609 
 610   // Accessors
 611   static jboolean override(oop reflect);
 612   static void set_override(oop reflect, jboolean value);
 613 
 614   // Debugging
 615   friend class JavaClasses;
 616 };
 617 
 618 
 619 // Interface to java.lang.reflect.Method objects
 620 
 621 class java_lang_reflect_Method : public java_lang_reflect_AccessibleObject {
 622  private:
 623   // Note that to reduce dependencies on the JDK we compute these
 624   // offsets at run-time.
 625   static int clazz_offset;
 626   static int name_offset;
 627   static int returnType_offset;
 628   static int parameterTypes_offset;
 629   static int exceptionTypes_offset;
 630   static int slot_offset;
 631   static int modifiers_offset;
 632   static int signature_offset;
 633   static int annotations_offset;
 634   static int parameter_annotations_offset;
 635   static int annotation_default_offset;
 636 
 637   static void compute_offsets();
 638  public:
 639   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 640 
 641   // Allocation
 642   static Handle create(TRAPS);
 643 
 644   // Accessors
 645   static oop clazz(oop reflect);
 646   static void set_clazz(oop reflect, oop value);
 647 
 648   static void set_name(oop method, oop value);
 649 
 650   static oop return_type(oop method);
 651   static void set_return_type(oop method, oop value);
 652 
 653   static oop parameter_types(oop method);
 654   static void set_parameter_types(oop method, oop value);
 655 
 656   static int slot(oop reflect);
 657   static void set_slot(oop reflect, int value);
 658 
 659   static void set_exception_types(oop method, oop value);
 660   static void set_modifiers(oop method, int value);
 661   static void set_signature(oop method, oop value);
 662   static void set_annotations(oop method, oop value);
 663   static void set_parameter_annotations(oop method, oop value);
 664   static void set_annotation_default(oop method, oop value);
 665 
 666   // Debugging
 667   friend class JavaClasses;
 668 };
 669 
 670 
 671 // Interface to java.lang.reflect.Constructor objects
 672 
 673 class java_lang_reflect_Constructor : public java_lang_reflect_AccessibleObject {
 674  private:
 675   // Note that to reduce dependencies on the JDK we compute these
 676   // offsets at run-time.
 677   static int clazz_offset;
 678   static int parameterTypes_offset;
 679   static int exceptionTypes_offset;
 680   static int slot_offset;
 681   static int modifiers_offset;
 682   static int signature_offset;
 683   static int annotations_offset;
 684   static int parameter_annotations_offset;
 685 
 686   static void compute_offsets();
 687  public:
 688   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 689 
 690   // Allocation
 691   static Handle create(TRAPS);
 692 
 693   // Accessors
 694   static oop clazz(oop reflect);
 695   static void set_clazz(oop reflect, oop value);
 696 
 697   static oop parameter_types(oop constructor);
 698   static void set_parameter_types(oop constructor, oop value);
 699 
 700   static int slot(oop reflect);
 701   static void set_slot(oop reflect, int value);
 702 
 703   static void set_exception_types(oop constructor, oop value);
 704   static void set_modifiers(oop constructor, int value);
 705   static void set_signature(oop constructor, oop value);
 706   static void set_annotations(oop constructor, oop value);
 707   static void set_parameter_annotations(oop method, oop value);
 708 
 709   // Debugging
 710   friend class JavaClasses;
 711 };
 712 
 713 
 714 // Interface to java.lang.reflect.Field objects
 715 
 716 class java_lang_reflect_Field : public java_lang_reflect_AccessibleObject {
 717  private:
 718   // Note that to reduce dependencies on the JDK we compute these
 719   // offsets at run-time.
 720   static int clazz_offset;
 721   static int name_offset;
 722   static int type_offset;
 723   static int slot_offset;
 724   static int modifiers_offset;
 725   static int signature_offset;
 726   static int annotations_offset;
 727 
 728   static void compute_offsets();
 729 
 730  public:
 731   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 732 
 733   // Allocation
 734   static Handle create(TRAPS);
 735 
 736   // Accessors
 737   static oop clazz(oop reflect);
 738   static void set_clazz(oop reflect, oop value);
 739 
 740   static oop name(oop field);
 741   static void set_name(oop field, oop value);
 742 
 743   static oop type(oop field);
 744   static void set_type(oop field, oop value);
 745 
 746   static int slot(oop reflect);
 747   static void set_slot(oop reflect, int value);
 748 
 749   static int modifiers(oop field);
 750   static void set_modifiers(oop field, int value);
 751 
 752   static void set_signature(oop constructor, oop value);
 753   static void set_annotations(oop constructor, oop value);
 754   static void set_parameter_annotations(oop method, oop value);
 755   static void set_annotation_default(oop method, oop value);
 756 
 757   // Debugging
 758   friend class JavaClasses;
 759 };
 760 
 761 class java_lang_reflect_Parameter {
 762  private:
 763   // Note that to reduce dependencies on the JDK we compute these
 764   // offsets at run-time.
 765   static int name_offset;
 766   static int modifiers_offset;
 767   static int index_offset;
 768   static int executable_offset;
 769 
 770   static void compute_offsets();
 771 
 772  public:
 773   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 774 
 775   // Allocation
 776   static Handle create(TRAPS);
 777 
 778   // Accessors
 779   static oop name(oop field);
 780   static void set_name(oop field, oop value);
 781 
 782   static int index(oop reflect);
 783   static void set_index(oop reflect, int value);
 784 
 785   static int modifiers(oop reflect);
 786   static void set_modifiers(oop reflect, int value);
 787 
 788   static oop executable(oop constructor);
 789   static void set_executable(oop constructor, oop value);
 790 
 791   friend class JavaClasses;
 792 };
 793 
 794 #define MODULE_INJECTED_FIELDS(macro)                            \
 795   macro(java_lang_Module, module_entry, intptr_signature, false)
 796 
 797 class java_lang_Module {
 798   private:
 799     static int loader_offset;
 800     static int name_offset;
 801     static int _module_entry_offset;
 802     static void compute_offsets();
 803 
 804   public:
 805     static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 806 
 807     // Allocation
 808     static Handle create(Handle loader, Handle module_name, TRAPS);
 809 
 810     // Testers
 811     static bool is_instance(oop obj);
 812 
 813     // Accessors
 814     static oop loader(oop module);
 815     static void set_loader(oop module, oop value);
 816 
 817     static oop name(oop module);
 818     static void set_name(oop module, oop value);
 819 
 820     static ModuleEntry* module_entry(oop module);
 821     static void set_module_entry(oop module, ModuleEntry* module_entry);
 822 
 823   friend class JavaClasses;
 824 };
 825 
 826 // Interface to jdk.internal.reflect.ConstantPool objects
 827 class reflect_ConstantPool {
 828  private:
 829   // Note that to reduce dependencies on the JDK we compute these
 830   // offsets at run-time.
 831   static int _oop_offset;
 832 
 833   static void compute_offsets();
 834 
 835  public:
 836   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 837 
 838   // Allocation
 839   static Handle create(TRAPS);
 840 
 841   // Accessors
 842   static void set_cp(oop reflect, ConstantPool* value);
 843   static int oop_offset() {
 844     return _oop_offset;
 845   }
 846 
 847   static ConstantPool* get_cp(oop reflect);
 848 
 849   // Debugging
 850   friend class JavaClasses;
 851 };
 852 
 853 // Interface to jdk.internal.reflect.UnsafeStaticFieldAccessorImpl objects
 854 class reflect_UnsafeStaticFieldAccessorImpl {
 855  private:
 856   static int _base_offset;
 857   static void compute_offsets();
 858 
 859  public:
 860   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 861 
 862   static int base_offset() {
 863     return _base_offset;
 864   }
 865 
 866   // Debugging
 867   friend class JavaClasses;
 868 };
 869 
 870 // Interface to java.lang primitive type boxing objects:
 871 //  - java.lang.Boolean
 872 //  - java.lang.Character
 873 //  - java.lang.Float
 874 //  - java.lang.Double
 875 //  - java.lang.Byte
 876 //  - java.lang.Short
 877 //  - java.lang.Integer
 878 //  - java.lang.Long
 879 
 880 // This could be separated out into 8 individual classes.
 881 
 882 class java_lang_boxing_object: AllStatic {
 883  private:
 884   enum {
 885    hc_value_offset = 0
 886   };
 887   static int value_offset;
 888   static int long_value_offset;
 889 
 890   static oop initialize_and_allocate(BasicType type, TRAPS);
 891  public:
 892   // Allocation. Returns a boxed value, or NULL for invalid type.
 893   static oop create(BasicType type, jvalue* value, TRAPS);
 894   // Accessors. Returns the basic type being boxed, or T_ILLEGAL for invalid oop.
 895   static BasicType get_value(oop box, jvalue* value);
 896   static BasicType set_value(oop box, jvalue* value);
 897   static BasicType basic_type(oop box);
 898   static bool is_instance(oop box)                 { return basic_type(box) != T_ILLEGAL; }
 899   static bool is_instance(oop box, BasicType type) { return basic_type(box) == type; }
 900   static void print(oop box, outputStream* st)     { jvalue value;  print(get_value(box, &value), &value, st); }
 901   static void print(BasicType type, jvalue* value, outputStream* st);
 902 
 903   static int value_offset_in_bytes(BasicType type) {
 904     return ( type == T_LONG || type == T_DOUBLE ) ? long_value_offset :
 905                                                     value_offset;
 906   }
 907 
 908   // Debugging
 909   friend class JavaClasses;
 910 };
 911 
 912 
 913 
 914 // Interface to java.lang.ref.Reference objects
 915 
 916 class java_lang_ref_Reference: AllStatic {
 917  public:
 918   enum {
 919    hc_referent_offset   = 0,
 920    hc_queue_offset      = 1,
 921    hc_next_offset       = 2,
 922    hc_discovered_offset = 3  // Is not last, see SoftRefs.
 923   };
 924 
 925   static int referent_offset;
 926   static int queue_offset;
 927   static int next_offset;
 928   static int discovered_offset;
 929 
 930   // Accessors
 931   static inline oop referent(oop ref);
 932   static inline void set_referent(oop ref, oop value);
 933   static inline void set_referent_raw(oop ref, oop value);
 934   static inline HeapWord* referent_addr_raw(oop ref);
 935   static inline oop next(oop ref);
 936   static inline void set_next(oop ref, oop value);
 937   static inline void set_next_raw(oop ref, oop value);
 938   static inline HeapWord* next_addr_raw(oop ref);
 939   static inline oop discovered(oop ref);
 940   static inline void set_discovered(oop ref, oop value);
 941   static inline void set_discovered_raw(oop ref, oop value);
 942   static inline HeapWord* discovered_addr_raw(oop ref);
 943   static inline oop queue(oop ref);
 944   static inline void set_queue(oop ref, oop value);
 945   static bool is_referent_field(oop obj, ptrdiff_t offset);
 946   static inline bool is_final(oop ref);
 947   static inline bool is_phantom(oop ref);
 948 };
 949 
 950 
 951 // Interface to java.lang.ref.SoftReference objects
 952 
 953 class java_lang_ref_SoftReference: public java_lang_ref_Reference {
 954  public:
 955   static int timestamp_offset;
 956   static int static_clock_offset;
 957 
 958   // Accessors
 959   static jlong timestamp(oop ref);
 960 
 961   // Accessors for statics
 962   static jlong clock();
 963   static void set_clock(jlong value);
 964 
 965   static void compute_offsets();
 966   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 967 };
 968 
 969 // Interface to java.lang.invoke.MethodHandle objects
 970 
 971 class MethodHandleEntry;
 972 
 973 class java_lang_invoke_MethodHandle: AllStatic {
 974   friend class JavaClasses;
 975 
 976  private:
 977   static int _type_offset;               // the MethodType of this MH
 978   static int _form_offset;               // the LambdaForm of this MH
 979 
 980   static void compute_offsets();
 981 
 982  public:
 983   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
 984 
 985   // Accessors
 986   static oop            type(oop mh);
 987   static void       set_type(oop mh, oop mtype);
 988 
 989   static oop            form(oop mh);
 990   static void       set_form(oop mh, oop lform);
 991 
 992   // Testers
 993   static bool is_subclass(Klass* klass) {
 994     return klass->is_subclass_of(SystemDictionary::MethodHandle_klass());
 995   }
 996   static bool is_instance(oop obj);
 997 
 998   // Accessors for code generation:
 999   static int type_offset_in_bytes()             { return _type_offset; }
1000   static int form_offset_in_bytes()             { return _form_offset; }
1001 };
1002 
1003 // Interface to java.lang.invoke.DirectMethodHandle objects
1004 
1005 class java_lang_invoke_DirectMethodHandle: AllStatic {
1006   friend class JavaClasses;
1007 
1008  private:
1009   static int _member_offset;               // the MemberName of this DMH
1010 
1011   static void compute_offsets();
1012 
1013  public:
1014   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1015 
1016   // Accessors
1017   static oop  member(oop mh);
1018 
1019   // Testers
1020   static bool is_subclass(Klass* klass) {
1021     return klass->is_subclass_of(SystemDictionary::DirectMethodHandle_klass());
1022   }
1023   static bool is_instance(oop obj);
1024 
1025   // Accessors for code generation:
1026   static int member_offset_in_bytes()           { return _member_offset; }
1027 };
1028 
1029 // Interface to java.lang.invoke.LambdaForm objects
1030 // (These are a private interface for managing adapter code generation.)
1031 
1032 class java_lang_invoke_LambdaForm: AllStatic {
1033   friend class JavaClasses;
1034 
1035  private:
1036   static int _vmentry_offset;  // type is MemberName
1037 
1038   static void compute_offsets();
1039 
1040  public:
1041   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1042 
1043   // Accessors
1044   static oop            vmentry(oop lform);
1045   static void       set_vmentry(oop lform, oop invoker);
1046 
1047   // Testers
1048   static bool is_subclass(Klass* klass) {
1049     return SystemDictionary::LambdaForm_klass() != NULL &&
1050       klass->is_subclass_of(SystemDictionary::LambdaForm_klass());
1051   }
1052   static bool is_instance(oop obj);
1053 
1054   // Accessors for code generation:
1055   static int vmentry_offset_in_bytes()          { return _vmentry_offset; }
1056 };
1057 
1058 
1059 // Interface to java.lang.invoke.MemberName objects
1060 // (These are a private interface for Java code to query the class hierarchy.)
1061 
1062 #define RESOLVEDMETHOD_INJECTED_FIELDS(macro)                                   \
1063   macro(java_lang_invoke_ResolvedMethodName, vmholder, object_signature, false) \
1064   macro(java_lang_invoke_ResolvedMethodName, vmtarget, intptr_signature, false)
1065 
1066 class java_lang_invoke_ResolvedMethodName : AllStatic {
1067   friend class JavaClasses;
1068 
1069   static int _vmtarget_offset;
1070   static int _vmholder_offset;
1071 
1072   static void compute_offsets();
1073  public:
1074   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1075 
1076   static int vmtarget_offset_in_bytes() { return _vmtarget_offset; }
1077 
1078   static Method* vmtarget(oop resolved_method);
1079   static void set_vmtarget(oop resolved_method, Method* method);
1080 
1081   static void set_vmholder(oop resolved_method, oop holder);
1082 
1083   // find or create resolved member name
1084   static oop find_resolved_method(const methodHandle& m, TRAPS);
1085 
1086   static bool is_instance(oop resolved_method);
1087 };
1088 
1089 
1090 #define MEMBERNAME_INJECTED_FIELDS(macro)                               \
1091   macro(java_lang_invoke_MemberName, vmindex,  intptr_signature, false)
1092 
1093 
1094 class java_lang_invoke_MemberName: AllStatic {
1095   friend class JavaClasses;
1096 
1097  private:
1098   // From java.lang.invoke.MemberName:
1099   //    private Class<?>   clazz;       // class in which the method is defined
1100   //    private String     name;        // may be null if not yet materialized
1101   //    private Object     type;        // may be null if not yet materialized
1102   //    private int        flags;       // modifier bits; see reflect.Modifier
1103   //    private ResolvedMethodName method;    // holds VM-specific target value
1104   //    private intptr_t   vmindex;     // member index within class or interface
1105   static int _clazz_offset;
1106   static int _name_offset;
1107   static int _type_offset;
1108   static int _flags_offset;
1109   static int _method_offset;
1110   static int _vmindex_offset;
1111 
1112   static void compute_offsets();
1113 
1114  public:
1115   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1116   // Accessors
1117   static oop            clazz(oop mname);
1118   static void       set_clazz(oop mname, oop clazz);
1119 
1120   static oop            type(oop mname);
1121   static void       set_type(oop mname, oop type);
1122 
1123   static oop            name(oop mname);
1124   static void       set_name(oop mname, oop name);
1125 
1126   static int            flags(oop mname);
1127   static void       set_flags(oop mname, int flags);
1128 
1129   // Link through ResolvedMethodName field to get Method*
1130   static Method*        vmtarget(oop mname);
1131   static void       set_method(oop mname, oop method);
1132 
1133   static intptr_t       vmindex(oop mname);
1134   static void       set_vmindex(oop mname, intptr_t index);
1135 
1136   // Testers
1137   static bool is_subclass(Klass* klass) {
1138     return klass->is_subclass_of(SystemDictionary::MemberName_klass());
1139   }
1140   static bool is_instance(oop obj);
1141 
1142   static bool is_method(oop obj);
1143 
1144   // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):
1145   enum {
1146     MN_IS_METHOD             = 0x00010000, // method (not constructor)
1147     MN_IS_CONSTRUCTOR        = 0x00020000, // constructor
1148     MN_IS_FIELD              = 0x00040000, // field
1149     MN_IS_TYPE               = 0x00080000, // nested type
1150     MN_CALLER_SENSITIVE      = 0x00100000, // @CallerSensitive annotation detected
1151     MN_REFERENCE_KIND_SHIFT  = 24, // refKind
1152     MN_REFERENCE_KIND_MASK   = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT,
1153     // The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers:
1154     MN_SEARCH_SUPERCLASSES   = 0x00100000, // walk super classes
1155     MN_SEARCH_INTERFACES     = 0x00200000, // walk implemented interfaces
1156     MN_NESTMATE_CLASS        = 0x00000001,
1157     MN_HIDDEN_CLASS          = 0x00000002,
1158     MN_WEAK_CLASS            = 0x00000004,
1159     MN_ACCESS_VM_ANNOTATIONS = 0x00100000
1160   };
1161 
1162   // Accessors for code generation:
1163   static int clazz_offset_in_bytes()            { return _clazz_offset; }
1164   static int type_offset_in_bytes()             { return _type_offset; }
1165   static int name_offset_in_bytes()             { return _name_offset; }
1166   static int flags_offset_in_bytes()            { return _flags_offset; }
1167   static int method_offset_in_bytes()           { return _method_offset; }
1168   static int vmindex_offset_in_bytes()          { return _vmindex_offset; }
1169 };
1170 
1171 
1172 // Interface to java.lang.invoke.MethodType objects
1173 
1174 class java_lang_invoke_MethodType: AllStatic {
1175   friend class JavaClasses;
1176 
1177  private:
1178   static int _rtype_offset;
1179   static int _ptypes_offset;
1180 
1181   static void compute_offsets();
1182 
1183  public:
1184   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1185   // Accessors
1186   static oop            rtype(oop mt);
1187   static objArrayOop    ptypes(oop mt);
1188 
1189   static oop            ptype(oop mt, int index);
1190   static int            ptype_count(oop mt);
1191 
1192   static int            ptype_slot_count(oop mt);  // extra counts for long/double
1193   static int            rtype_slot_count(oop mt);  // extra counts for long/double
1194 
1195   static Symbol*        as_signature(oop mt, bool intern_if_not_found);
1196   static void           print_signature(oop mt, outputStream* st);
1197 
1198   static bool is_instance(oop obj);
1199 
1200   static bool equals(oop mt1, oop mt2);
1201 
1202   // Accessors for code generation:
1203   static int rtype_offset_in_bytes()            { return _rtype_offset; }
1204   static int ptypes_offset_in_bytes()           { return _ptypes_offset; }
1205 };
1206 
1207 
1208 // Interface to java.lang.invoke.CallSite objects
1209 
1210 class java_lang_invoke_CallSite: AllStatic {
1211   friend class JavaClasses;
1212 
1213 private:
1214   static int _target_offset;
1215   static int _context_offset;
1216 
1217   static void compute_offsets();
1218 
1219 public:
1220   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1221   // Accessors
1222   static oop              target(          oop site);
1223   static void         set_target(          oop site, oop target);
1224   static void         set_target_volatile( oop site, oop target);
1225 
1226   static oop context_no_keepalive(oop site);
1227 
1228   // Testers
1229   static bool is_subclass(Klass* klass) {
1230     return klass->is_subclass_of(SystemDictionary::CallSite_klass());
1231   }
1232   static bool is_instance(oop obj);
1233 
1234   // Accessors for code generation:
1235   static int target_offset_in_bytes()           { return _target_offset; }
1236 };
1237 
1238 // Interface to java.lang.invoke.MethodHandleNatives$CallSiteContext objects
1239 
1240 #define CALLSITECONTEXT_INJECTED_FIELDS(macro) \
1241   macro(java_lang_invoke_MethodHandleNatives_CallSiteContext, vmdependencies, intptr_signature, false) \
1242   macro(java_lang_invoke_MethodHandleNatives_CallSiteContext, last_cleanup, long_signature, false)
1243 
1244 class DependencyContext;
1245 
1246 class java_lang_invoke_MethodHandleNatives_CallSiteContext : AllStatic {
1247   friend class JavaClasses;
1248 
1249 private:
1250   static int _vmdependencies_offset;
1251   static int _last_cleanup_offset;
1252 
1253   static void compute_offsets();
1254 
1255 public:
1256   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1257   // Accessors
1258   static DependencyContext vmdependencies(oop context);
1259 
1260   // Testers
1261   static bool is_subclass(Klass* klass) {
1262     return klass->is_subclass_of(SystemDictionary::Context_klass());
1263   }
1264   static bool is_instance(oop obj);
1265 };
1266 
1267 // Interface to java.security.AccessControlContext objects
1268 
1269 class java_security_AccessControlContext: AllStatic {
1270  private:
1271   // Note that for this class the layout changed between JDK1.2 and JDK1.3,
1272   // so we compute the offsets at startup rather than hard-wiring them.
1273   static int _context_offset;
1274   static int _privilegedContext_offset;
1275   static int _isPrivileged_offset;
1276   static int _isAuthorized_offset;
1277 
1278   static void compute_offsets();
1279  public:
1280   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1281   static oop create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS);
1282 
1283   // Debugging/initialization
1284   friend class JavaClasses;
1285 };
1286 
1287 
1288 // Interface to java.lang.ClassLoader objects
1289 
1290 #define CLASSLOADER_INJECTED_FIELDS(macro)                            \
1291   macro(java_lang_ClassLoader, loader_data,  intptr_signature, false)
1292 
1293 class java_lang_ClassLoader : AllStatic {
1294  private:
1295   static int _loader_data_offset;
1296   static bool offsets_computed;
1297   static int parent_offset;
1298   static int parallelCapable_offset;
1299   static int name_offset;
1300   static int nameAndId_offset;
1301   static int unnamedModule_offset;
1302 
1303  public:
1304   static void compute_offsets();
1305   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1306 
1307   static ClassLoaderData* loader_data_acquire(oop loader);
1308   static ClassLoaderData* loader_data_raw(oop loader);
1309   static void release_set_loader_data(oop loader, ClassLoaderData* new_data);
1310 
1311   static oop parent(oop loader);
1312   static oop name(oop loader);
1313   static oop nameAndId(oop loader);
1314   static bool isAncestor(oop loader, oop cl);
1315 
1316   // Support for parallelCapable field
1317   static bool parallelCapable(oop the_class_mirror);
1318 
1319   static bool is_trusted_loader(oop loader);
1320 
1321   // Return true if this is one of the class loaders associated with
1322   // the generated bytecodes for reflection.
1323   static bool is_reflection_class_loader(oop loader);
1324 
1325   // Fix for 4474172
1326   static oop  non_reflection_class_loader(oop loader);
1327 
1328   // Testers
1329   static bool is_subclass(Klass* klass) {
1330     return klass->is_subclass_of(SystemDictionary::ClassLoader_klass());
1331   }
1332   static bool is_instance(oop obj);
1333 
1334   static oop unnamedModule(oop loader);
1335 
1336   // Debugging
1337   friend class JavaClasses;
1338   friend class ClassFileParser; // access to number_of_fake_fields
1339 };
1340 
1341 
1342 // Interface to java.lang.System objects
1343 
1344 class java_lang_System : AllStatic {
1345  private:
1346   static int  static_in_offset;
1347   static int static_out_offset;
1348   static int static_err_offset;
1349   static int static_security_offset;
1350 
1351  public:
1352   static int  in_offset_in_bytes();
1353   static int out_offset_in_bytes();
1354   static int err_offset_in_bytes();
1355 
1356   static void compute_offsets();
1357   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1358 
1359   // Debugging
1360   friend class JavaClasses;
1361 };
1362 
1363 
1364 // Interface to java.lang.StackTraceElement objects
1365 
1366 class java_lang_StackTraceElement: AllStatic {
1367  private:
1368   static int declaringClassObject_offset;
1369   static int classLoaderName_offset;
1370   static int moduleName_offset;
1371   static int moduleVersion_offset;
1372   static int declaringClass_offset;
1373   static int methodName_offset;
1374   static int fileName_offset;
1375   static int lineNumber_offset;
1376 
1377   // Setters
1378   static void set_classLoaderName(oop element, oop value);
1379   static void set_moduleName(oop element, oop value);
1380   static void set_moduleVersion(oop element, oop value);
1381   static void set_declaringClass(oop element, oop value);
1382   static void set_methodName(oop element, oop value);
1383   static void set_fileName(oop element, oop value);
1384   static void set_lineNumber(oop element, int value);
1385   static void set_declaringClassObject(oop element, oop value);
1386 
1387  public:
1388   // Create an instance of StackTraceElement
1389   static oop create(const methodHandle& method, int bci, TRAPS);
1390 
1391   static void fill_in(Handle element, InstanceKlass* holder, const methodHandle& method,
1392                       int version, int bci, Symbol* name, TRAPS);
1393 
1394   static void compute_offsets();
1395   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1396 
1397 #if INCLUDE_JVMCI
1398   static void decode(Handle mirror, int method, int version, int bci, int cpref, Symbol*& methodName, Symbol*& fileName, int& lineNumber);
1399   static void decode(Handle mirror, methodHandle method, int bci, Symbol*& methodName, Symbol*& fileName, int& lineNumber);
1400 #endif
1401 
1402   // Debugging
1403   friend class JavaClasses;
1404 };
1405 
1406 
1407 class Backtrace: AllStatic {
1408  public:
1409   // Helper backtrace functions to store bci|version together.
1410   static int merge_bci_and_version(int bci, int version);
1411   static int merge_mid_and_cpref(int mid, int cpref);
1412   static int bci_at(unsigned int merged);
1413   static int version_at(unsigned int merged);
1414   static int mid_at(unsigned int merged);
1415   static int cpref_at(unsigned int merged);
1416   static int get_line_number(Method* method, int bci);
1417   static Symbol* get_source_file_name(InstanceKlass* holder, int version);
1418 
1419   // Debugging
1420   friend class JavaClasses;
1421 };
1422 
1423 // Interface to java.lang.StackFrameInfo objects
1424 
1425 #define STACKFRAMEINFO_INJECTED_FIELDS(macro)                      \
1426   macro(java_lang_StackFrameInfo, version, short_signature, false)
1427 
1428 class java_lang_StackFrameInfo: AllStatic {
1429 private:
1430   static int _memberName_offset;
1431   static int _bci_offset;
1432   static int _version_offset;
1433 
1434   static Method* get_method(Handle stackFrame, InstanceKlass* holder, TRAPS);
1435 
1436 public:
1437   // Setters
1438   static void set_method_and_bci(Handle stackFrame, const methodHandle& method, int bci, TRAPS);
1439   static void set_bci(oop info, int value);
1440 
1441   static void set_version(oop info, short value);
1442 
1443   static void compute_offsets();
1444   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1445 
1446   static void to_stack_trace_element(Handle stackFrame, Handle stack_trace_element, TRAPS);
1447 
1448   // Debugging
1449   friend class JavaClasses;
1450 };
1451 
1452 class java_lang_LiveStackFrameInfo: AllStatic {
1453  private:
1454   static int _monitors_offset;
1455   static int _locals_offset;
1456   static int _operands_offset;
1457   static int _mode_offset;
1458 
1459  public:
1460   static void set_monitors(oop info, oop value);
1461   static void set_locals(oop info, oop value);
1462   static void set_operands(oop info, oop value);
1463   static void set_mode(oop info, int value);
1464 
1465   static void compute_offsets();
1466   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1467 
1468   // Debugging
1469   friend class JavaClasses;
1470 };
1471 
1472 // Interface to java.lang.AssertionStatusDirectives objects
1473 
1474 class java_lang_AssertionStatusDirectives: AllStatic {
1475  private:
1476   static int classes_offset;
1477   static int classEnabled_offset;
1478   static int packages_offset;
1479   static int packageEnabled_offset;
1480   static int deflt_offset;
1481 
1482  public:
1483   // Setters
1484   static void set_classes(oop obj, oop val);
1485   static void set_classEnabled(oop obj, oop val);
1486   static void set_packages(oop obj, oop val);
1487   static void set_packageEnabled(oop obj, oop val);
1488   static void set_deflt(oop obj, bool val);
1489 
1490   static void compute_offsets();
1491   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1492 
1493   // Debugging
1494   friend class JavaClasses;
1495 };
1496 
1497 
1498 class java_nio_Buffer: AllStatic {
1499  private:
1500   static int _limit_offset;
1501 
1502  public:
1503   static int  limit_offset();
1504   static void compute_offsets();
1505   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1506 };
1507 
1508 class java_util_concurrent_locks_AbstractOwnableSynchronizer : AllStatic {
1509  private:
1510   static int  _owner_offset;
1511  public:
1512   static void compute_offsets();
1513   static oop  get_owner_threadObj(oop obj);
1514   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1515 };
1516 
1517  // Interface to jdk.internal.misc.UnsafeConsants
1518 
1519 class jdk_internal_misc_UnsafeConstants : AllStatic {
1520  public:
1521   static void set_unsafe_constants();
1522   static void compute_offsets() { }
1523   static void serialize_offsets(SerializeClosure* f) { }
1524 };
1525 
1526 class java_lang_Integer : AllStatic {
1527 public:
1528   static jint value(oop obj);
1529 };
1530 
1531 class java_lang_Long : AllStatic {
1532 public:
1533   static jlong value(oop obj);
1534 };
1535 
1536 class java_lang_Character : AllStatic {
1537 public:
1538   static jchar value(oop obj);
1539 };
1540 
1541 class java_lang_Short : AllStatic {
1542 public:
1543   static jshort value(oop obj);
1544 };
1545 
1546 class java_lang_Byte : AllStatic {
1547 public:
1548   static jbyte value(oop obj);
1549 };
1550 
1551 class java_lang_Boolean : AllStatic {
1552  private:
1553   static int _static_TRUE_offset;
1554   static int _static_FALSE_offset;
1555  public:
1556   static Symbol* symbol();
1557   static void compute_offsets(InstanceKlass* k);
1558   static oop  get_TRUE(InstanceKlass *k);
1559   static oop  get_FALSE(InstanceKlass *k);
1560   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1561   static jboolean value(oop obj);
1562 };
1563 
1564 class java_lang_Integer_IntegerCache : AllStatic {
1565  private:
1566   static int _static_cache_offset;
1567  public:
1568   static Symbol* symbol();
1569   static void compute_offsets(InstanceKlass* k);
1570   static objArrayOop  cache(InstanceKlass *k);
1571   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1572 };
1573 
1574 class java_lang_Long_LongCache : AllStatic {
1575  private:
1576   static int _static_cache_offset;
1577  public:
1578   static Symbol* symbol();
1579   static void compute_offsets(InstanceKlass* k);
1580   static objArrayOop  cache(InstanceKlass *k);
1581   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1582 };
1583 
1584 class java_lang_Character_CharacterCache : AllStatic {
1585  private:
1586   static int _static_cache_offset;
1587  public:
1588   static Symbol* symbol();
1589   static void compute_offsets(InstanceKlass* k);
1590   static objArrayOop  cache(InstanceKlass *k);
1591   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1592 };
1593 
1594 class java_lang_Short_ShortCache : AllStatic {
1595  private:
1596   static int _static_cache_offset;
1597  public:
1598   static Symbol* symbol();
1599   static void compute_offsets(InstanceKlass* k);
1600   static objArrayOop  cache(InstanceKlass *k);
1601   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1602 };
1603 
1604 class java_lang_Byte_ByteCache : AllStatic {
1605  private:
1606   static int _static_cache_offset;
1607  public:
1608   static Symbol* symbol();
1609   static void compute_offsets(InstanceKlass* k);
1610   static objArrayOop  cache(InstanceKlass *k);
1611   static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;
1612 };
1613 
1614 // Use to declare fields that need to be injected into Java classes
1615 // for the JVM to use.  The name_index and signature_index are
1616 // declared in vmSymbols.  The may_be_java flag is used to declare
1617 // fields that might already exist in Java but should be injected if
1618 // they don't.  Otherwise the field is unconditionally injected and
1619 // the JVM uses the injected one.  This is to ensure that name
1620 // collisions don't occur.  In general may_be_java should be false
1621 // unless there's a good reason.
1622 
1623 class InjectedField {
1624  public:
1625   const SystemDictionary::WKID klass_id;
1626   const vmSymbols::SID name_index;
1627   const vmSymbols::SID signature_index;
1628   const bool           may_be_java;
1629 
1630 
1631   Klass* klass() const    { return SystemDictionary::well_known_klass(klass_id); }
1632   Symbol* name() const      { return lookup_symbol(name_index); }
1633   Symbol* signature() const { return lookup_symbol(signature_index); }
1634 
1635   int compute_offset();
1636 
1637   // Find the Symbol for this index
1638   static Symbol* lookup_symbol(int symbol_index) {
1639     return vmSymbols::symbol_at((vmSymbols::SID)symbol_index);
1640   }
1641 };
1642 
1643 #define DECLARE_INJECTED_FIELD_ENUM(klass, name, signature, may_be_java) \
1644   klass##_##name##_enum,
1645 
1646 #define ALL_INJECTED_FIELDS(macro)          \
1647   CLASS_INJECTED_FIELDS(macro)              \
1648   CLASSLOADER_INJECTED_FIELDS(macro)        \
1649   RESOLVEDMETHOD_INJECTED_FIELDS(macro)     \
1650   MEMBERNAME_INJECTED_FIELDS(macro)         \
1651   CALLSITECONTEXT_INJECTED_FIELDS(macro)    \
1652   STACKFRAMEINFO_INJECTED_FIELDS(macro)     \
1653   MODULE_INJECTED_FIELDS(macro)
1654 
1655 // Interface to hard-coded offset checking
1656 
1657 class JavaClasses : AllStatic {
1658  private:
1659 
1660   static InjectedField _injected_fields[];
1661 
1662   static bool check_offset(const char *klass_name, int offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1663  public:
1664   enum InjectedFieldID {
1665     ALL_INJECTED_FIELDS(DECLARE_INJECTED_FIELD_ENUM)
1666     MAX_enum
1667   };
1668 
1669   static int compute_injected_offset(InjectedFieldID id);
1670 
1671   static void compute_hard_coded_offsets();
1672   static void compute_offsets();
1673   static void check_offsets() PRODUCT_RETURN;
1674   static void serialize_offsets(SerializeClosure* soc) NOT_CDS_RETURN;
1675   static InjectedField* get_injected(Symbol* class_name, int* field_count);
1676   static bool is_supported_for_archiving(oop obj) NOT_CDS_JAVA_HEAP_RETURN_(false);
1677 };
1678 
1679 #undef DECLARE_INJECTED_FIELD_ENUM
1680 
1681 #endif // SHARE_CLASSFILE_JAVACLASSES_HPP