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