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