rev 48017 : [mq]: Access_strings

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