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