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