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