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