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