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