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