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