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