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