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 refStack_offset;
 976  static int fp_offset;
 977  static int sp_offset;
 978  static int pc_offset;
 979  static int refSP_offset;
 980  static Method* stack_method;
 981  // Accessors
 982  static inline oop scope(oop ref);
 983  static inline oop target(oop ref);
 984  static inline oop parent(oop ref);
 985  static inline typeArrayOop stack(oop ref);
 986  static inline objArrayOop refStack(oop ref);
 987  static inline jlong fp(oop ref);
 988  static inline void set_fp(oop ref, const jlong i);
 989  static inline jint sp(oop ref);
 990  static inline void set_sp(oop ref, const jint i);
 991  static inline void* pc(oop ref);
 992  static inline void  set_pc(oop ref, const void* pc);
 993  static inline jint refSP(oop ref);
 994  static inline void set_refSP(oop ref, jint i);
 995  static inline intptr_t* entrySP(oop ref);
 996  static inline intptr_t* entryFP(oop ref);
 997  static inline void set_entryFP(oop ref, intptr_t* fp);
 998  static inline address entryPC(oop ref);
 999  static inline void set_entryPC(oop ref, address pc);
1000  static inline int stack_size(oop ref);
1001  static inline void* stack_base(oop ref);
1002  static inline HeapWord* refStack_base(oop ref);
1003  static bool on_local_stack(oop ref, address adr);
1004 };
1005 
1006 // Interface to java.lang.invoke.MethodHandle objects
1007 
1008 class MethodHandleEntry;
1009 
1010 class java_lang_invoke_MethodHandle: AllStatic {
1011   friend class JavaClasses;
1012 
1013  private:
1014   static int _type_offset;               // the MethodType of this MH
1015   static int _form_offset;               // the LambdaForm of this MH
1016 
1017   static void compute_offsets();
1018 
1019  public:
1020   static void serialize(SerializeClosure* f) NOT_CDS_RETURN;
1021 
1022   // Accessors
1023   static oop            type(oop mh);
1024   static void       set_type(oop mh, oop mtype);
1025 
1026   static oop            form(oop mh);
1027   static void       set_form(oop mh, oop lform);
1028 
1029   // Testers
1030   static bool is_subclass(Klass* klass) {
1031     return klass->is_subclass_of(SystemDictionary::MethodHandle_klass());
1032   }
1033   static bool is_instance(oop obj);
1034 
1035   // Accessors for code generation:
1036   static int type_offset_in_bytes()             { return _type_offset; }
1037   static int form_offset_in_bytes()             { return _form_offset; }
1038 };
1039 
1040 // Interface to java.lang.invoke.DirectMethodHandle objects
1041 
1042 class java_lang_invoke_DirectMethodHandle: AllStatic {
1043   friend class JavaClasses;
1044 
1045  private:
1046   static int _member_offset;               // the MemberName of this DMH
1047 
1048   static void compute_offsets();
1049 
1050  public:
1051   static void serialize(SerializeClosure* f) NOT_CDS_RETURN;
1052 
1053   // Accessors
1054   static oop  member(oop mh);
1055 
1056   // Testers
1057   static bool is_subclass(Klass* klass) {
1058     return klass->is_subclass_of(SystemDictionary::DirectMethodHandle_klass());
1059   }
1060   static bool is_instance(oop obj);
1061 
1062   // Accessors for code generation:
1063   static int member_offset_in_bytes()           { return _member_offset; }
1064 };
1065 
1066 // Interface to java.lang.invoke.LambdaForm objects
1067 // (These are a private interface for managing adapter code generation.)
1068 
1069 class java_lang_invoke_LambdaForm: AllStatic {
1070   friend class JavaClasses;
1071 
1072  private:
1073   static int _vmentry_offset;  // type is MemberName
1074 
1075   static void compute_offsets();
1076 
1077  public:
1078   static void serialize(SerializeClosure* f) NOT_CDS_RETURN;
1079 
1080   // Accessors
1081   static oop            vmentry(oop lform);
1082   static void       set_vmentry(oop lform, oop invoker);
1083 
1084   // Testers
1085   static bool is_subclass(Klass* klass) {
1086     return SystemDictionary::LambdaForm_klass() != NULL &&
1087       klass->is_subclass_of(SystemDictionary::LambdaForm_klass());
1088   }
1089   static bool is_instance(oop obj);
1090 
1091   // Accessors for code generation:
1092   static int vmentry_offset_in_bytes()          { return _vmentry_offset; }
1093 };
1094 
1095 
1096 // Interface to java.lang.invoke.MemberName objects
1097 // (These are a private interface for Java code to query the class hierarchy.)
1098 
1099 #define RESOLVEDMETHOD_INJECTED_FIELDS(macro)                                   \
1100   macro(java_lang_invoke_ResolvedMethodName, vmholder, object_signature, false) \
1101   macro(java_lang_invoke_ResolvedMethodName, vmtarget, intptr_signature, false)
1102 
1103 class java_lang_invoke_ResolvedMethodName : AllStatic {
1104   friend class JavaClasses;
1105 
1106   static int _vmtarget_offset;
1107   static int _vmholder_offset;
1108 
1109   static void compute_offsets();
1110  public:
1111   static void serialize(SerializeClosure* f) NOT_CDS_RETURN;
1112 
1113   static int vmtarget_offset_in_bytes() { return _vmtarget_offset; }
1114 
1115   static Method* vmtarget(oop resolved_method);
1116   static void set_vmtarget(oop resolved_method, Method* method);
1117 
1118   // find or create resolved member name
1119   static oop find_resolved_method(const methodHandle& m, TRAPS);
1120 
1121   static bool is_instance(oop resolved_method);
1122 };
1123 
1124 
1125 #define MEMBERNAME_INJECTED_FIELDS(macro)                               \
1126   macro(java_lang_invoke_MemberName, vmindex,  intptr_signature, false)
1127 
1128 
1129 class java_lang_invoke_MemberName: AllStatic {
1130   friend class JavaClasses;
1131 
1132  private:
1133   // From java.lang.invoke.MemberName:
1134   //    private Class<?>   clazz;       // class in which the method is defined
1135   //    private String     name;        // may be null if not yet materialized
1136   //    private Object     type;        // may be null if not yet materialized
1137   //    private int        flags;       // modifier bits; see reflect.Modifier
1138   //    private ResolvedMethodName method;    // holds VM-specific target value
1139   //    private intptr_t   vmindex;     // member index within class or interface
1140   static int _clazz_offset;
1141   static int _name_offset;
1142   static int _type_offset;
1143   static int _flags_offset;
1144   static int _method_offset;
1145   static int _vmindex_offset;
1146 
1147   static void compute_offsets();
1148 
1149  public:
1150   static void serialize(SerializeClosure* f) NOT_CDS_RETURN;
1151   // Accessors
1152   static oop            clazz(oop mname);
1153   static void       set_clazz(oop mname, oop clazz);
1154 
1155   static oop            type(oop mname);
1156   static void       set_type(oop mname, oop type);
1157 
1158   static oop            name(oop mname);
1159   static void       set_name(oop mname, oop name);
1160 
1161   static int            flags(oop mname);
1162   static void       set_flags(oop mname, int flags);
1163 
1164   // Link through ResolvedMethodName field to get Method*
1165   static Method*        vmtarget(oop mname);
1166   static void       set_method(oop mname, oop method);
1167 
1168   static intptr_t       vmindex(oop mname);
1169   static void       set_vmindex(oop mname, intptr_t index);
1170 
1171   // Testers
1172   static bool is_subclass(Klass* klass) {
1173     return klass->is_subclass_of(SystemDictionary::MemberName_klass());
1174   }
1175   static bool is_instance(oop obj);
1176 
1177   static bool is_method(oop obj);
1178 
1179   // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):
1180   enum {
1181     MN_IS_METHOD            = 0x00010000, // method (not constructor)
1182     MN_IS_CONSTRUCTOR       = 0x00020000, // constructor
1183     MN_IS_FIELD             = 0x00040000, // field
1184     MN_IS_TYPE              = 0x00080000, // nested type
1185     MN_CALLER_SENSITIVE     = 0x00100000, // @CallerSensitive annotation detected
1186     MN_REFERENCE_KIND_SHIFT = 24, // refKind
1187     MN_REFERENCE_KIND_MASK  = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT,
1188     // The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers:
1189     MN_SEARCH_SUPERCLASSES  = 0x00100000, // walk super classes
1190     MN_SEARCH_INTERFACES    = 0x00200000  // walk implemented interfaces
1191   };
1192 
1193   // Accessors for code generation:
1194   static int clazz_offset_in_bytes()            { return _clazz_offset; }
1195   static int type_offset_in_bytes()             { return _type_offset; }
1196   static int name_offset_in_bytes()             { return _name_offset; }
1197   static int flags_offset_in_bytes()            { return _flags_offset; }
1198   static int method_offset_in_bytes()           { return _method_offset; }
1199   static int vmindex_offset_in_bytes()          { return _vmindex_offset; }
1200 };
1201 
1202 
1203 // Interface to java.lang.invoke.MethodType objects
1204 
1205 class java_lang_invoke_MethodType: AllStatic {
1206   friend class JavaClasses;
1207 
1208  private:
1209   static int _rtype_offset;
1210   static int _ptypes_offset;
1211 
1212   static void compute_offsets();
1213 
1214  public:
1215   static void serialize(SerializeClosure* f) NOT_CDS_RETURN;
1216   // Accessors
1217   static oop            rtype(oop mt);
1218   static objArrayOop    ptypes(oop mt);
1219 
1220   static oop            ptype(oop mt, int index);
1221   static int            ptype_count(oop mt);
1222 
1223   static int            ptype_slot_count(oop mt);  // extra counts for long/double
1224   static int            rtype_slot_count(oop mt);  // extra counts for long/double
1225 
1226   static Symbol*        as_signature(oop mt, bool intern_if_not_found, TRAPS);
1227   static void           print_signature(oop mt, outputStream* st);
1228 
1229   static bool is_instance(oop obj);
1230 
1231   static bool equals(oop mt1, oop mt2);
1232 
1233   // Accessors for code generation:
1234   static int rtype_offset_in_bytes()            { return _rtype_offset; }
1235   static int ptypes_offset_in_bytes()           { return _ptypes_offset; }
1236 };
1237 
1238 
1239 // Interface to java.lang.invoke.CallSite objects
1240 
1241 class java_lang_invoke_CallSite: AllStatic {
1242   friend class JavaClasses;
1243 
1244 private:
1245   static int _target_offset;
1246   static int _context_offset;
1247 
1248   static void compute_offsets();
1249 
1250 public:
1251   static void serialize(SerializeClosure* f) NOT_CDS_RETURN;
1252   // Accessors
1253   static oop              target(          oop site);
1254   static void         set_target(          oop site, oop target);
1255   static void         set_target_volatile( oop site, oop target);
1256 
1257   static oop              context(oop site);
1258 
1259   // Testers
1260   static bool is_subclass(Klass* klass) {
1261     return klass->is_subclass_of(SystemDictionary::CallSite_klass());
1262   }
1263   static bool is_instance(oop obj);
1264 
1265   // Accessors for code generation:
1266   static int target_offset_in_bytes()           { return _target_offset; }
1267 };
1268 
1269 // Interface to java.lang.invoke.MethodHandleNatives$CallSiteContext objects
1270 
1271 #define CALLSITECONTEXT_INJECTED_FIELDS(macro) \
1272   macro(java_lang_invoke_MethodHandleNatives_CallSiteContext, vmdependencies, intptr_signature, false)
1273 
1274 class DependencyContext;
1275 
1276 class java_lang_invoke_MethodHandleNatives_CallSiteContext : AllStatic {
1277   friend class JavaClasses;
1278 
1279 private:
1280   static int _vmdependencies_offset;
1281 
1282   static void compute_offsets();
1283 
1284 public:
1285   static void serialize(SerializeClosure* f) NOT_CDS_RETURN;
1286   // Accessors
1287   static DependencyContext vmdependencies(oop context);
1288 
1289   // Testers
1290   static bool is_subclass(Klass* klass) {
1291     return klass->is_subclass_of(SystemDictionary::Context_klass());
1292   }
1293   static bool is_instance(oop obj);
1294 };
1295 
1296 // Interface to java.security.AccessControlContext objects
1297 
1298 class java_security_AccessControlContext: AllStatic {
1299  private:
1300   // Note that for this class the layout changed between JDK1.2 and JDK1.3,
1301   // so we compute the offsets at startup rather than hard-wiring them.
1302   static int _context_offset;
1303   static int _privilegedContext_offset;
1304   static int _isPrivileged_offset;
1305   static int _isAuthorized_offset;
1306 
1307   static void compute_offsets();
1308  public:
1309   static void serialize(SerializeClosure* f) NOT_CDS_RETURN;
1310   static oop create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS);
1311 
1312   static bool is_authorized(Handle context);
1313 
1314   // Debugging/initialization
1315   friend class JavaClasses;
1316 };
1317 
1318 
1319 // Interface to java.lang.ClassLoader objects
1320 
1321 #define CLASSLOADER_INJECTED_FIELDS(macro)                            \
1322   macro(java_lang_ClassLoader, loader_data,  intptr_signature, false)
1323 
1324 class java_lang_ClassLoader : AllStatic {
1325  private:
1326   static int _loader_data_offset;
1327   static bool offsets_computed;
1328   static int parent_offset;
1329   static int parallelCapable_offset;
1330   static int name_offset;
1331   static int unnamedModule_offset;
1332 
1333  public:
1334   static void compute_offsets();
1335   static void serialize(SerializeClosure* f) NOT_CDS_RETURN;
1336 
1337   static ClassLoaderData* loader_data(oop loader);
1338   static ClassLoaderData* cmpxchg_loader_data(ClassLoaderData* new_data, oop loader, ClassLoaderData* expected_data);
1339 
1340   static oop parent(oop loader);
1341   static oop name(oop loader);
1342   static bool isAncestor(oop loader, oop cl);
1343 
1344   // Support for parallelCapable field
1345   static bool parallelCapable(oop the_class_mirror);
1346 
1347   static bool is_trusted_loader(oop loader);
1348 
1349   // Return true if this is one of the class loaders associated with
1350   // the generated bytecodes for reflection.
1351   static bool is_reflection_class_loader(oop loader);
1352 
1353   // Fix for 4474172
1354   static oop  non_reflection_class_loader(oop loader);
1355 
1356   // Testers
1357   static bool is_subclass(Klass* klass) {
1358     return klass->is_subclass_of(SystemDictionary::ClassLoader_klass());
1359   }
1360   static bool is_instance(oop obj);
1361 
1362   static oop unnamedModule(oop loader);
1363 
1364   // Debugging
1365   friend class JavaClasses;
1366   friend class ClassFileParser; // access to number_of_fake_fields
1367 
1368   // Describe ClassLoader for exceptions, tracing ...
1369   // Prints "<name>" (instance of <classname>, child of "<name>" <classname>).
1370   // If a classloader has no name, it prints <unnamed> instead. The output
1371   // for well known loaders (system/platform) is abbreviated.
1372   static const char* describe_external(const oop loader);
1373 };
1374 
1375 
1376 // Interface to java.lang.System objects
1377 
1378 class java_lang_System : AllStatic {
1379  private:
1380   static int  static_in_offset;
1381   static int static_out_offset;
1382   static int static_err_offset;
1383   static int static_security_offset;
1384 
1385  public:
1386   static int  in_offset_in_bytes();
1387   static int out_offset_in_bytes();
1388   static int err_offset_in_bytes();
1389 
1390   static bool has_security_manager();
1391 
1392   static void compute_offsets();
1393   static void serialize(SerializeClosure* f) NOT_CDS_RETURN;
1394 
1395   // Debugging
1396   friend class JavaClasses;
1397 };
1398 
1399 
1400 // Interface to java.lang.StackTraceElement objects
1401 
1402 class java_lang_StackTraceElement: AllStatic {
1403  private:
1404   static int declaringClassObject_offset;
1405   static int classLoaderName_offset;
1406   static int moduleName_offset;
1407   static int moduleVersion_offset;
1408   static int declaringClass_offset;
1409   static int methodName_offset;
1410   static int fileName_offset;
1411   static int lineNumber_offset;
1412 
1413   // Setters
1414   static void set_classLoaderName(oop element, oop value);
1415   static void set_moduleName(oop element, oop value);
1416   static void set_moduleVersion(oop element, oop value);
1417   static void set_declaringClass(oop element, oop value);
1418   static void set_methodName(oop element, oop value);
1419   static void set_fileName(oop element, oop value);
1420   static void set_lineNumber(oop element, int value);
1421   static void set_declaringClassObject(oop element, oop value);
1422 
1423  public:
1424   // Create an instance of StackTraceElement
1425   static oop create(const methodHandle& method, int bci, TRAPS);
1426 
1427   static void fill_in(Handle element, InstanceKlass* holder, const methodHandle& method,
1428                       int version, int bci, Symbol* name, TRAPS);
1429 
1430   static void compute_offsets();
1431   static void serialize(SerializeClosure* f) NOT_CDS_RETURN;
1432 
1433   // Debugging
1434   friend class JavaClasses;
1435 };
1436 
1437 
1438 class Backtrace: AllStatic {
1439  public:
1440   // Helper backtrace functions to store bci|version together.
1441   static int merge_bci_and_version(int bci, int version);
1442   static int merge_mid_and_cpref(int mid, int cpref);
1443   static int bci_at(unsigned int merged);
1444   static int version_at(unsigned int merged);
1445   static int mid_at(unsigned int merged);
1446   static int cpref_at(unsigned int merged);
1447   static int get_line_number(const methodHandle& method, int bci);
1448   static Symbol* get_source_file_name(InstanceKlass* holder, int version);
1449 
1450   // Debugging
1451   friend class JavaClasses;
1452 };
1453 
1454 // Interface to java.lang.StackFrameInfo objects
1455 
1456 #define STACKFRAMEINFO_INJECTED_FIELDS(macro)                      \
1457   macro(java_lang_StackFrameInfo, version, short_signature, false)
1458 
1459 class java_lang_StackFrameInfo: AllStatic {
1460 private:
1461   static int _memberName_offset;
1462   static int _bci_offset;
1463   static int _version_offset;
1464 
1465   static Method* get_method(Handle stackFrame, InstanceKlass* holder, TRAPS);
1466 
1467 public:
1468   // Setters
1469   static void set_method_and_bci(Handle stackFrame, const methodHandle& method, int bci, TRAPS);
1470   static void set_bci(oop info, int value);
1471 
1472   static void set_version(oop info, short value);
1473 
1474   static void compute_offsets();
1475   static void serialize(SerializeClosure* f) NOT_CDS_RETURN;
1476 
1477   static void to_stack_trace_element(Handle stackFrame, Handle stack_trace_element, TRAPS);
1478 
1479   // Debugging
1480   friend class JavaClasses;
1481 };
1482 
1483 class java_lang_LiveStackFrameInfo: AllStatic {
1484  private:
1485   static int _monitors_offset;
1486   static int _locals_offset;
1487   static int _operands_offset;
1488   static int _mode_offset;
1489 
1490  public:
1491   static void set_monitors(oop info, oop value);
1492   static void set_locals(oop info, oop value);
1493   static void set_operands(oop info, oop value);
1494   static void set_mode(oop info, int value);
1495 
1496   static void compute_offsets();
1497   static void serialize(SerializeClosure* f) NOT_CDS_RETURN;
1498 
1499   // Debugging
1500   friend class JavaClasses;
1501 };
1502 
1503 // Interface to java.lang.AssertionStatusDirectives objects
1504 
1505 class java_lang_AssertionStatusDirectives: AllStatic {
1506  private:
1507   static int classes_offset;
1508   static int classEnabled_offset;
1509   static int packages_offset;
1510   static int packageEnabled_offset;
1511   static int deflt_offset;
1512 
1513  public:
1514   // Setters
1515   static void set_classes(oop obj, oop val);
1516   static void set_classEnabled(oop obj, oop val);
1517   static void set_packages(oop obj, oop val);
1518   static void set_packageEnabled(oop obj, oop val);
1519   static void set_deflt(oop obj, bool val);
1520 
1521   static void compute_offsets();
1522   static void serialize(SerializeClosure* f) NOT_CDS_RETURN;
1523 
1524   // Debugging
1525   friend class JavaClasses;
1526 };
1527 
1528 
1529 class java_nio_Buffer: AllStatic {
1530  private:
1531   static int _limit_offset;
1532 
1533  public:
1534   static int  limit_offset();
1535   static void compute_offsets();
1536   static void serialize(SerializeClosure* f) NOT_CDS_RETURN;
1537 };
1538 
1539 class java_util_concurrent_locks_AbstractOwnableSynchronizer : AllStatic {
1540  private:
1541   static int  _owner_offset;
1542  public:
1543   static void initialize(TRAPS);
1544   static oop  get_owner_threadObj(oop obj);
1545 };
1546 
1547 // Use to declare fields that need to be injected into Java classes
1548 // for the JVM to use.  The name_index and signature_index are
1549 // declared in vmSymbols.  The may_be_java flag is used to declare
1550 // fields that might already exist in Java but should be injected if
1551 // they don't.  Otherwise the field is unconditionally injected and
1552 // the JVM uses the injected one.  This is to ensure that name
1553 // collisions don't occur.  In general may_be_java should be false
1554 // unless there's a good reason.
1555 
1556 class InjectedField {
1557  public:
1558   const SystemDictionary::WKID klass_id;
1559   const vmSymbols::SID name_index;
1560   const vmSymbols::SID signature_index;
1561   const bool           may_be_java;
1562 
1563 
1564   Klass* klass() const    { return SystemDictionary::well_known_klass(klass_id); }
1565   Symbol* name() const      { return lookup_symbol(name_index); }
1566   Symbol* signature() const { return lookup_symbol(signature_index); }
1567 
1568   int compute_offset();
1569 
1570   // Find the Symbol for this index
1571   static Symbol* lookup_symbol(int symbol_index) {
1572     return vmSymbols::symbol_at((vmSymbols::SID)symbol_index);
1573   }
1574 };
1575 
1576 #define DECLARE_INJECTED_FIELD_ENUM(klass, name, signature, may_be_java) \
1577   klass##_##name##_enum,
1578 
1579 #define ALL_INJECTED_FIELDS(macro)          \
1580   CLASS_INJECTED_FIELDS(macro)              \
1581   CLASSLOADER_INJECTED_FIELDS(macro)        \
1582   RESOLVEDMETHOD_INJECTED_FIELDS(macro)     \
1583   MEMBERNAME_INJECTED_FIELDS(macro)         \
1584   CALLSITECONTEXT_INJECTED_FIELDS(macro)    \
1585   STACKFRAMEINFO_INJECTED_FIELDS(macro)     \
1586   MODULE_INJECTED_FIELDS(macro)
1587 
1588 // Interface to hard-coded offset checking
1589 
1590 class JavaClasses : AllStatic {
1591  private:
1592 
1593   static InjectedField _injected_fields[];
1594 
1595   static bool check_offset(const char *klass_name, int offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1596  public:
1597   enum InjectedFieldID {
1598     ALL_INJECTED_FIELDS(DECLARE_INJECTED_FIELD_ENUM)
1599     MAX_enum
1600   };
1601 
1602   static int compute_injected_offset(InjectedFieldID id);
1603 
1604   static void compute_hard_coded_offsets();
1605   static void compute_offsets();
1606   static void check_offsets() PRODUCT_RETURN;
1607 
1608   static InjectedField* get_injected(Symbol* class_name, int* field_count);
1609 };
1610 
1611 #undef DECLARE_INJECTED_FIELD_ENUM
1612 
1613 #endif // SHARE_VM_CLASSFILE_JAVACLASSES_HPP