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