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