1 /*
   2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_CLASSFILE_JAVACLASSES_HPP
  26 #define SHARE_VM_CLASSFILE_JAVACLASSES_HPP
  27 
  28 #include "classfile/systemDictionary.hpp"
  29 #include "jvmtifiles/jvmti.h"
  30 #include "oops/oop.hpp"
  31 #include "runtime/os.hpp"
  32 #include "utilities/utf8.hpp"
  33 
  34 // Interface for manipulating the basic Java classes.
  35 //
  36 // All dependencies on layout of actual Java classes should be kept here.
  37 // If the layout of any of the classes above changes the offsets must be adjusted.
  38 //
  39 // For most classes we hardwire the offsets for performance reasons. In certain
  40 // cases (e.g. java.security.AccessControlContext) we compute the offsets at
  41 // startup since the layout here differs between JDK1.2 and JDK1.3.
  42 //
  43 // Note that fields (static and non-static) are arranged with oops before non-oops
  44 // on a per class basis. The offsets below have to reflect this ordering.
  45 //
  46 // When editing the layouts please update the check_offset verification code
  47 // correspondingly. The names in the enums must be identical to the actual field
  48 // names in order for the verification code to work.
  49 
  50 
  51 // Interface to java.lang.String objects
  52 
  53 class java_lang_String : AllStatic {
  54  private:
  55   static int value_offset;
  56   static int hash_offset;
  57   static int coder_offset;
  58 
  59   static bool initialized;
  60 
  61   static Handle basic_create(int length, bool byte_arr, TRAPS);
  62 
  63   static inline void set_coder(oop string, jbyte coder);
  64 
  65  public:
  66 
  67   // Coders
  68   enum Coder {
  69     CODER_LATIN1 =  0,
  70     CODER_UTF16  =  1
  71   };
  72 
  73   static void compute_offsets();
  74 
  75   // Instance creation
  76   static Handle create_from_unicode(jchar* unicode, int len, TRAPS);
  77   static oop    create_oop_from_unicode(jchar* unicode, int len, TRAPS);
  78   static Handle create_from_str(const char* utf8_str, TRAPS);
  79   static oop    create_oop_from_str(const char* utf8_str, TRAPS);
  80   static Handle create_from_symbol(Symbol* symbol, TRAPS);
  81   static Handle create_from_platform_dependent_str(const char* str, TRAPS);
  82   static Handle char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS);
  83 
  84   static bool has_hash_field()  {
  85     assert(initialized, "Must be initialized");
  86     return (hash_offset > 0);
  87   }
  88   static bool has_coder_field()  {
  89     assert(initialized, "Must be initialized");
  90     return (coder_offset > 0);
  91   }
  92 
  93   static void set_compact_strings(bool value);
  94 
  95   static int value_offset_in_bytes()  {
  96     assert(initialized && (value_offset > 0), "Must be initialized");
  97     return value_offset;
  98   }
  99   static int hash_offset_in_bytes()   {
 100     assert(initialized && (hash_offset > 0), "Must be initialized");
 101     return hash_offset;
 102   }
 103   static int coder_offset_in_bytes()   {
 104     assert(initialized && (coder_offset > 0), "Must be initialized");
 105     return coder_offset;
 106   }
 107 
 108   static inline void set_value_raw(oop string, typeArrayOop buffer);
 109   static inline void set_value(oop string, typeArrayOop buffer);
 110   static inline void set_hash(oop string, unsigned int hash);
 111 
 112   // Accessors
 113   static inline typeArrayOop value(oop java_string);
 114   static inline unsigned int hash(oop java_string);
 115   static inline bool is_latin1(oop java_string);
 116   static inline int length(oop java_string);
 117   static int utf8_length(oop java_string);
 118 
 119   // String converters
 120   static char*  as_utf8_string(oop java_string);
 121   static char*  as_utf8_string(oop java_string, char* buf, int buflen);
 122   static char*  as_utf8_string(oop java_string, int start, int len);
 123   static char*  as_utf8_string(oop java_string, int start, int len, char* buf, int buflen);
 124   static char*  as_platform_dependent_str(Handle java_string, TRAPS);
 125   static jchar* as_unicode_string(oop java_string, int& length, TRAPS);
 126   // produce an ascii string with all other values quoted using \u####
 127   static char*  as_quoted_ascii(oop java_string);
 128 
 129   // Compute the hash value for a java.lang.String object which would
 130   // contain the characters passed in.
 131   //
 132   // As the hash value used by the String object itself, in
 133   // String.hashCode().  This value is normally calculated in Java code
 134   // in the String.hashCode method(), but is precomputed for String
 135   // objects in the shared archive file.
 136   // hash P(31) from Kernighan & Ritchie
 137   //
 138   // For this reason, THIS ALGORITHM MUST MATCH String.hashCode().
 139   static unsigned int hash_code(const jchar* s, int len) {
 140     unsigned int h = 0;
 141     while (len-- > 0) {
 142       h = 31*h + (unsigned int) *s;
 143       s++;
 144     }
 145     return h;
 146   }
 147 
 148   static unsigned int hash_code(const jbyte* s, int len) {
 149     unsigned int h = 0;
 150     while (len-- > 0) {
 151       h = 31*h + (((unsigned int) *s) & 0xFF);
 152       s++;
 153     }
 154     return h;
 155   }
 156 
 157   static unsigned int hash_code(oop java_string);
 158   static unsigned int latin1_hash_code(typeArrayOop value, int len);
 159 
 160   // This is the string hash code used by the StringTable, which may be
 161   // the same as String.hashCode or an alternate hash code.
 162   static unsigned int hash_string(oop java_string);
 163 
 164   static bool equals(oop java_string, jchar* chars, int len);
 165   static bool equals(oop str1, oop str2);
 166 
 167   // Conversion between '.' and '/' formats
 168   static Handle externalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '/', '.', THREAD); }
 169   static Handle internalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '.', '/', THREAD); }
 170 
 171   // Conversion
 172   static Symbol* as_symbol(Handle java_string, TRAPS);
 173   static Symbol* as_symbol_or_null(oop java_string);
 174 
 175   // Testers
 176   static bool is_instance(oop obj);
 177   static inline bool is_instance_inlined(oop obj);
 178 
 179   // Debugging
 180   static void print(oop java_string, outputStream* st);
 181   friend class JavaClasses;
 182   friend class StringTable;
 183 };
 184 
 185 
 186 // Interface to java.lang.Class objects
 187 
 188 #define CLASS_INJECTED_FIELDS(macro)                                       \
 189   macro(java_lang_Class, klass,                  intptr_signature,  false) \
 190   macro(java_lang_Class, array_klass,            intptr_signature,  false) \
 191   macro(java_lang_Class, oop_size,               int_signature,     false) \
 192   macro(java_lang_Class, static_oop_field_count, int_signature,     false) \
 193   macro(java_lang_Class, protection_domain,      object_signature,  false) \
 194   macro(java_lang_Class, signers,                object_signature,  false)
 195 
 196 class java_lang_Class : AllStatic {
 197   friend class VMStructs;
 198   friend class JVMCIVMStructs;
 199 
 200  private:
 201   // The fake offsets are added by the class loader when java.lang.Class is loaded
 202 
 203   static int _klass_offset;
 204   static int _array_klass_offset;
 205 
 206   static int _oop_size_offset;
 207   static int _static_oop_field_count_offset;
 208 
 209   static int _protection_domain_offset;
 210   static int _init_lock_offset;
 211   static int _signers_offset;
 212   static int _class_loader_offset;
 213   static int _component_mirror_offset;
 214 
 215   static bool offsets_computed;
 216   static int classRedefinedCount_offset;
 217 
 218   static GrowableArray<Klass*>* _fixup_mirror_list;
 219 
 220   static void set_init_lock(oop java_class, oop init_lock);
 221   static void set_protection_domain(oop java_class, oop protection_domain);
 222   static void set_class_loader(oop java_class, oop class_loader);
 223   static void set_component_mirror(oop java_class, oop comp_mirror);
 224   static void initialize_mirror_fields(KlassHandle k, Handle mirror, Handle protection_domain, TRAPS);
 225  public:
 226   static void compute_offsets();
 227 
 228   // Instance creation
 229   static void create_mirror(KlassHandle k, Handle class_loader,
 230                             Handle protection_domain, TRAPS);
 231   static void fixup_mirror(KlassHandle k, TRAPS);
 232   static oop  create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS);
 233   // Conversion
 234   static Klass* as_Klass(oop java_class);
 235   static void set_klass(oop java_class, Klass* klass);
 236   static BasicType as_BasicType(oop java_class, Klass** reference_klass = NULL);
 237   static BasicType as_BasicType(oop java_class, KlassHandle* reference_klass) {
 238     Klass* refk_oop = NULL;
 239     BasicType result = as_BasicType(java_class, &refk_oop);
 240     (*reference_klass) = KlassHandle(refk_oop);
 241     return result;
 242   }
 243   static Symbol* as_signature(oop java_class, bool intern_if_not_found, TRAPS);
 244   static void print_signature(oop java_class, outputStream *st);
 245   static const char* as_external_name(oop java_class);
 246   // Testing
 247   static bool is_instance(oop obj);
 248 
 249   static bool is_primitive(oop java_class);
 250   static BasicType primitive_type(oop java_class);
 251   static oop primitive_mirror(BasicType t);
 252   // JVM_NewArray support
 253   static Klass* array_klass(oop java_class);
 254   static void set_array_klass(oop java_class, Klass* klass);
 255   // compiler support for class operations
 256   static int klass_offset_in_bytes()                { return _klass_offset; }
 257   static int array_klass_offset_in_bytes()          { return _array_klass_offset; }
 258   // Support for classRedefinedCount field
 259   static int classRedefinedCount(oop the_class_mirror);
 260   static void set_classRedefinedCount(oop the_class_mirror, int value);
 261 
 262   // Support for embedded per-class oops
 263   static oop  protection_domain(oop java_class);
 264   static oop  init_lock(oop java_class);
 265   static oop  component_mirror(oop java_class);
 266   static objArrayOop  signers(oop java_class);
 267   static void set_signers(oop java_class, objArrayOop signers);
 268 
 269   static oop class_loader(oop java_class);
 270 
 271   static int oop_size(oop java_class);
 272   static void set_oop_size(oop java_class, int size);
 273   static int static_oop_field_count(oop java_class);
 274   static void set_static_oop_field_count(oop java_class, int size);
 275 
 276   static GrowableArray<Klass*>* fixup_mirror_list() {
 277     return _fixup_mirror_list;
 278   }
 279   static void set_fixup_mirror_list(GrowableArray<Klass*>* v) {
 280     _fixup_mirror_list = v;
 281   }
 282   // Debugging
 283   friend class JavaClasses;
 284   friend class InstanceKlass;   // verification code accesses offsets
 285   friend class ClassFileParser; // access to number_of_fake_fields
 286 };
 287 
 288 // Interface to java.lang.Thread objects
 289 
 290 class java_lang_Thread : AllStatic {
 291  private:
 292   // Note that for this class the layout changed between JDK1.2 and JDK1.3,
 293   // so we compute the offsets at startup rather than hard-wiring them.
 294   static int _name_offset;
 295   static int _group_offset;
 296   static int _contextClassLoader_offset;
 297   static int _inheritedAccessControlContext_offset;
 298   static int _priority_offset;
 299   static int _eetop_offset;
 300   static int _daemon_offset;
 301   static int _stillborn_offset;
 302   static int _stackSize_offset;
 303   static int _tid_offset;
 304   static int _thread_status_offset;
 305   static int _park_blocker_offset;
 306   static int _park_event_offset ;
 307 
 308   static void compute_offsets();
 309 
 310  public:
 311   // Instance creation
 312   static oop create();
 313   // Returns the JavaThread associated with the thread obj
 314   static JavaThread* thread(oop java_thread);
 315   // Set JavaThread for instance
 316   static void set_thread(oop java_thread, JavaThread* thread);
 317   // Name
 318   static oop name(oop java_thread);
 319   static void set_name(oop java_thread, oop name);
 320   // Priority
 321   static ThreadPriority priority(oop java_thread);
 322   static void set_priority(oop java_thread, ThreadPriority priority);
 323   // Thread group
 324   static oop  threadGroup(oop java_thread);
 325   // Stillborn
 326   static bool is_stillborn(oop java_thread);
 327   static void set_stillborn(oop java_thread);
 328   // Alive (NOTE: this is not really a field, but provides the correct
 329   // definition without doing a Java call)
 330   static bool is_alive(oop java_thread);
 331   // Daemon
 332   static bool is_daemon(oop java_thread);
 333   static void set_daemon(oop java_thread);
 334   // Context ClassLoader
 335   static oop context_class_loader(oop java_thread);
 336   // Control context
 337   static oop inherited_access_control_context(oop java_thread);
 338   // Stack size hint
 339   static jlong stackSize(oop java_thread);
 340   // Thread ID
 341   static jlong thread_id(oop java_thread);
 342 
 343   // Blocker object responsible for thread parking
 344   static oop park_blocker(oop java_thread);
 345 
 346   // Pointer to type-stable park handler, encoded as jlong.
 347   // Should be set when apparently null
 348   // For details, see unsafe.cpp Unsafe_Unpark
 349   static jlong park_event(oop java_thread);
 350   static bool set_park_event(oop java_thread, jlong ptr);
 351 
 352   // Java Thread Status for JVMTI and M&M use.
 353   // This thread status info is saved in threadStatus field of
 354   // java.lang.Thread java class.
 355   enum ThreadStatus {
 356     NEW                      = 0,
 357     RUNNABLE                 = JVMTI_THREAD_STATE_ALIVE +          // runnable / running
 358                                JVMTI_THREAD_STATE_RUNNABLE,
 359     SLEEPING                 = JVMTI_THREAD_STATE_ALIVE +          // Thread.sleep()
 360                                JVMTI_THREAD_STATE_WAITING +
 361                                JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
 362                                JVMTI_THREAD_STATE_SLEEPING,
 363     IN_OBJECT_WAIT           = JVMTI_THREAD_STATE_ALIVE +          // Object.wait()
 364                                JVMTI_THREAD_STATE_WAITING +
 365                                JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
 366                                JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
 367     IN_OBJECT_WAIT_TIMED     = JVMTI_THREAD_STATE_ALIVE +          // Object.wait(long)
 368                                JVMTI_THREAD_STATE_WAITING +
 369                                JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
 370                                JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
 371     PARKED                   = JVMTI_THREAD_STATE_ALIVE +          // LockSupport.park()
 372                                JVMTI_THREAD_STATE_WAITING +
 373                                JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
 374                                JVMTI_THREAD_STATE_PARKED,
 375     PARKED_TIMED             = JVMTI_THREAD_STATE_ALIVE +          // LockSupport.park(long)
 376                                JVMTI_THREAD_STATE_WAITING +
 377                                JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
 378                                JVMTI_THREAD_STATE_PARKED,
 379     BLOCKED_ON_MONITOR_ENTER = JVMTI_THREAD_STATE_ALIVE +          // (re-)entering a synchronization block
 380                                JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER,
 381     TERMINATED               = JVMTI_THREAD_STATE_TERMINATED
 382   };
 383   // Write thread status info to threadStatus field of java.lang.Thread.
 384   static void set_thread_status(oop java_thread_oop, ThreadStatus status);
 385   // Read thread status info from threadStatus field of java.lang.Thread.
 386   static ThreadStatus get_thread_status(oop java_thread_oop);
 387 
 388   static const char*  thread_status_name(oop java_thread_oop);
 389 
 390   // Debugging
 391   friend class JavaClasses;
 392 };
 393 
 394 // Interface to java.lang.ThreadGroup objects
 395 
 396 class java_lang_ThreadGroup : AllStatic {
 397  private:
 398   static int _parent_offset;
 399   static int _name_offset;
 400   static int _threads_offset;
 401   static int _groups_offset;
 402   static int _maxPriority_offset;
 403   static int _destroyed_offset;
 404   static int _daemon_offset;
 405   static int _vmAllowSuspension_offset;
 406   static int _nthreads_offset;
 407   static int _ngroups_offset;
 408 
 409   static void compute_offsets();
 410 
 411  public:
 412   // parent ThreadGroup
 413   static oop  parent(oop java_thread_group);
 414   // name
 415   static const char* name(oop java_thread_group);
 416   // ("name as oop" accessor is not necessary)
 417   // Number of threads in group
 418   static int nthreads(oop java_thread_group);
 419   // threads
 420   static objArrayOop threads(oop java_thread_group);
 421   // Number of threads in group
 422   static int ngroups(oop java_thread_group);
 423   // groups
 424   static objArrayOop groups(oop java_thread_group);
 425   // maxPriority in group
 426   static ThreadPriority maxPriority(oop java_thread_group);
 427   // Destroyed
 428   static bool is_destroyed(oop java_thread_group);
 429   // Daemon
 430   static bool is_daemon(oop java_thread_group);
 431   // vmAllowSuspension
 432   static bool is_vmAllowSuspension(oop java_thread_group);
 433   // Debugging
 434   friend class JavaClasses;
 435 };
 436 
 437 
 438 
 439 // Interface to java.lang.Throwable objects
 440 
 441 class java_lang_Throwable: AllStatic {
 442   friend class BacktraceBuilder;

 443 
 444  private:
 445   // Offsets
 446   enum {
 447     hc_backtrace_offset     =  0,
 448     hc_detailMessage_offset =  1,
 449     hc_cause_offset         =  2,  // New since 1.4
 450     hc_stackTrace_offset    =  3   // New since 1.4
 451   };
 452   enum {
 453       hc_static_unassigned_stacktrace_offset = 0  // New since 1.7
 454   };
 455   // Trace constants
 456   enum {
 457     trace_methods_offset = 0,
 458     trace_bcis_offset    = 1,
 459     trace_mirrors_offset = 2,
 460     trace_cprefs_offset  = 3,
 461     trace_next_offset    = 4,
 462     trace_size           = 5,
 463     trace_chunk_size     = 32
 464   };
 465 
 466   static int backtrace_offset;
 467   static int detailMessage_offset;
 468   static int cause_offset;
 469   static int stackTrace_offset;

 470   static int static_unassigned_stacktrace_offset;
 471 
 472   // Printing
 473   static char* print_stack_element_to_buffer(Handle mirror, int method, int version, int bci, int cpref);
 474   // StackTrace (programmatic access, new since 1.4)
 475   static void clear_stacktrace(oop throwable);
 476   // No stack trace available
 477   static const char* no_stack_trace_message();
 478   // Stacktrace (post JDK 1.7.0 to allow immutability protocol to be followed)
 479   static void set_stacktrace(oop throwable, oop st_element_array);
 480   static oop unassigned_stacktrace();
 481 
 482  public:
 483   // Backtrace
 484   static oop backtrace(oop throwable);
 485   static void set_backtrace(oop throwable, oop value);

 486   // Needed by JVMTI to filter out this internal field.
 487   static int get_backtrace_offset() { return backtrace_offset;}
 488   static int get_detailMessage_offset() { return detailMessage_offset;}
 489   // Message
 490   static oop message(oop throwable);
 491   static oop message(Handle throwable);
 492   static void set_message(oop throwable, oop value);
 493   static Symbol* detail_message(oop throwable);
 494   static void print_stack_element(outputStream *st, Handle mirror, int method,
 495                                   int version, int bci, int cpref);
 496   static void print_stack_element(outputStream *st, const methodHandle& method, int bci);
 497   static void print_stack_usage(Handle stream);
 498 


 499   // Allocate space for backtrace (created but stack trace not filled in)
 500   static void allocate_backtrace(Handle throwable, TRAPS);
 501   // Fill in current stack trace for throwable with preallocated backtrace (no GC)
 502   static void fill_in_stack_trace_of_preallocated_backtrace(Handle throwable);
 503   // Fill in current stack trace, can cause GC
 504   static void fill_in_stack_trace(Handle throwable, const methodHandle& method, TRAPS);
 505   static void fill_in_stack_trace(Handle throwable, const methodHandle& method = methodHandle());
 506   // Programmatic access to stack trace
 507   static oop  get_stack_trace_element(oop throwable, int index, TRAPS);
 508   static int  get_stack_trace_depth(oop throwable, TRAPS);
 509   // Printing
 510   static void print(Handle throwable, outputStream* st);
 511   static void print_stack_trace(Handle throwable, outputStream* st);
 512   static void java_printStackTrace(Handle throwable, TRAPS);
 513   // Debugging
 514   friend class JavaClasses;
 515 };
 516 
 517 
 518 // Interface to java.lang.reflect.AccessibleObject objects
 519 
 520 class java_lang_reflect_AccessibleObject: AllStatic {
 521  private:
 522   // Note that to reduce dependencies on the JDK we compute these
 523   // offsets at run-time.
 524   static int override_offset;
 525 
 526   static void compute_offsets();
 527 
 528  public:
 529   // Accessors
 530   static jboolean override(oop reflect);
 531   static void set_override(oop reflect, jboolean value);
 532 
 533   // Debugging
 534   friend class JavaClasses;
 535 };
 536 
 537 
 538 // Interface to java.lang.reflect.Method objects
 539 
 540 class java_lang_reflect_Method : public java_lang_reflect_AccessibleObject {
 541  private:
 542   // Note that to reduce dependencies on the JDK we compute these
 543   // offsets at run-time.
 544   static int clazz_offset;
 545   static int name_offset;
 546   static int returnType_offset;
 547   static int parameterTypes_offset;
 548   static int exceptionTypes_offset;
 549   static int slot_offset;
 550   static int modifiers_offset;
 551   static int signature_offset;
 552   static int annotations_offset;
 553   static int parameter_annotations_offset;
 554   static int annotation_default_offset;
 555   static int type_annotations_offset;
 556 
 557   static void compute_offsets();
 558 
 559  public:
 560   // Allocation
 561   static Handle create(TRAPS);
 562 
 563   // Accessors
 564   static oop clazz(oop reflect);
 565   static void set_clazz(oop reflect, oop value);
 566 
 567   static oop name(oop method);
 568   static void set_name(oop method, oop value);
 569 
 570   static oop return_type(oop method);
 571   static void set_return_type(oop method, oop value);
 572 
 573   static oop parameter_types(oop method);
 574   static void set_parameter_types(oop method, oop value);
 575 
 576   static oop exception_types(oop method);
 577   static void set_exception_types(oop method, oop value);
 578 
 579   static int slot(oop reflect);
 580   static void set_slot(oop reflect, int value);
 581 
 582   static int modifiers(oop method);
 583   static void set_modifiers(oop method, int value);
 584 
 585   static bool has_signature_field();
 586   static oop signature(oop method);
 587   static void set_signature(oop method, oop value);
 588 
 589   static bool has_annotations_field();
 590   static oop annotations(oop method);
 591   static void set_annotations(oop method, oop value);
 592 
 593   static bool has_parameter_annotations_field();
 594   static oop parameter_annotations(oop method);
 595   static void set_parameter_annotations(oop method, oop value);
 596 
 597   static bool has_annotation_default_field();
 598   static oop annotation_default(oop method);
 599   static void set_annotation_default(oop method, oop value);
 600 
 601   static bool has_type_annotations_field();
 602   static oop type_annotations(oop method);
 603   static void set_type_annotations(oop method, oop value);
 604 
 605   // Debugging
 606   friend class JavaClasses;
 607 };
 608 
 609 
 610 // Interface to java.lang.reflect.Constructor objects
 611 
 612 class java_lang_reflect_Constructor : public java_lang_reflect_AccessibleObject {
 613  private:
 614   // Note that to reduce dependencies on the JDK we compute these
 615   // offsets at run-time.
 616   static int clazz_offset;
 617   static int parameterTypes_offset;
 618   static int exceptionTypes_offset;
 619   static int slot_offset;
 620   static int modifiers_offset;
 621   static int signature_offset;
 622   static int annotations_offset;
 623   static int parameter_annotations_offset;
 624   static int type_annotations_offset;
 625 
 626   static void compute_offsets();
 627 
 628  public:
 629   // Allocation
 630   static Handle create(TRAPS);
 631 
 632   // Accessors
 633   static oop clazz(oop reflect);
 634   static void set_clazz(oop reflect, oop value);
 635 
 636   static oop parameter_types(oop constructor);
 637   static void set_parameter_types(oop constructor, oop value);
 638 
 639   static oop exception_types(oop constructor);
 640   static void set_exception_types(oop constructor, oop value);
 641 
 642   static int slot(oop reflect);
 643   static void set_slot(oop reflect, int value);
 644 
 645   static int modifiers(oop constructor);
 646   static void set_modifiers(oop constructor, int value);
 647 
 648   static bool has_signature_field();
 649   static oop signature(oop constructor);
 650   static void set_signature(oop constructor, oop value);
 651 
 652   static bool has_annotations_field();
 653   static oop annotations(oop constructor);
 654   static void set_annotations(oop constructor, oop value);
 655 
 656   static bool has_parameter_annotations_field();
 657   static oop parameter_annotations(oop method);
 658   static void set_parameter_annotations(oop method, oop value);
 659 
 660   static bool has_type_annotations_field();
 661   static oop type_annotations(oop constructor);
 662   static void set_type_annotations(oop constructor, oop value);
 663 
 664   // Debugging
 665   friend class JavaClasses;
 666 };
 667 
 668 
 669 // Interface to java.lang.reflect.Field objects
 670 
 671 class java_lang_reflect_Field : public java_lang_reflect_AccessibleObject {
 672  private:
 673   // Note that to reduce dependencies on the JDK we compute these
 674   // offsets at run-time.
 675   static int clazz_offset;
 676   static int name_offset;
 677   static int type_offset;
 678   static int slot_offset;
 679   static int modifiers_offset;
 680   static int signature_offset;
 681   static int annotations_offset;
 682   static int type_annotations_offset;
 683 
 684   static void compute_offsets();
 685 
 686  public:
 687   // Allocation
 688   static Handle create(TRAPS);
 689 
 690   // Accessors
 691   static oop clazz(oop reflect);
 692   static void set_clazz(oop reflect, oop value);
 693 
 694   static oop name(oop field);
 695   static void set_name(oop field, oop value);
 696 
 697   static oop type(oop field);
 698   static void set_type(oop field, oop value);
 699 
 700   static int slot(oop reflect);
 701   static void set_slot(oop reflect, int value);
 702 
 703   static int modifiers(oop field);
 704   static void set_modifiers(oop field, int value);
 705 
 706   static bool has_signature_field();
 707   static oop signature(oop constructor);
 708   static void set_signature(oop constructor, oop value);
 709 
 710   static bool has_annotations_field();
 711   static oop annotations(oop constructor);
 712   static void set_annotations(oop constructor, oop value);
 713 
 714   static bool has_parameter_annotations_field();
 715   static oop parameter_annotations(oop method);
 716   static void set_parameter_annotations(oop method, oop value);
 717 
 718   static bool has_annotation_default_field();
 719   static oop annotation_default(oop method);
 720   static void set_annotation_default(oop method, oop value);
 721 
 722   static bool has_type_annotations_field();
 723   static oop type_annotations(oop field);
 724   static void set_type_annotations(oop field, oop value);
 725 
 726   // Debugging
 727   friend class JavaClasses;
 728 };
 729 
 730 class java_lang_reflect_Parameter {
 731  private:
 732   // Note that to reduce dependencies on the JDK we compute these
 733   // offsets at run-time.
 734   static int name_offset;
 735   static int modifiers_offset;
 736   static int index_offset;
 737   static int executable_offset;
 738 
 739   static void compute_offsets();
 740 
 741  public:
 742   // Allocation
 743   static Handle create(TRAPS);
 744 
 745   // Accessors
 746   static oop name(oop field);
 747   static void set_name(oop field, oop value);
 748 
 749   static int index(oop reflect);
 750   static void set_index(oop reflect, int value);
 751 
 752   static int modifiers(oop reflect);
 753   static void set_modifiers(oop reflect, int value);
 754 
 755   static oop executable(oop constructor);
 756   static void set_executable(oop constructor, oop value);
 757 
 758   friend class JavaClasses;
 759 };
 760 
 761 // Interface to sun.reflect.ConstantPool objects
 762 class sun_reflect_ConstantPool {
 763  private:
 764   // Note that to reduce dependencies on the JDK we compute these
 765   // offsets at run-time.
 766   static int _oop_offset;
 767 
 768   static void compute_offsets();
 769 
 770  public:
 771   // Allocation
 772   static Handle create(TRAPS);
 773 
 774   // Accessors
 775   static void set_cp(oop reflect, ConstantPool* value);
 776   static int oop_offset() {
 777     return _oop_offset;
 778   }
 779 
 780   static ConstantPool* get_cp(oop reflect);
 781 
 782   // Debugging
 783   friend class JavaClasses;
 784 };
 785 
 786 // Interface to sun.reflect.UnsafeStaticFieldAccessorImpl objects
 787 class sun_reflect_UnsafeStaticFieldAccessorImpl {
 788  private:
 789   static int _base_offset;
 790   static void compute_offsets();
 791 
 792  public:
 793   static int base_offset() {
 794     return _base_offset;
 795   }
 796 
 797   // Debugging
 798   friend class JavaClasses;
 799 };
 800 
 801 // Interface to java.lang primitive type boxing objects:
 802 //  - java.lang.Boolean
 803 //  - java.lang.Character
 804 //  - java.lang.Float
 805 //  - java.lang.Double
 806 //  - java.lang.Byte
 807 //  - java.lang.Short
 808 //  - java.lang.Integer
 809 //  - java.lang.Long
 810 
 811 // This could be separated out into 8 individual classes.
 812 
 813 class java_lang_boxing_object: AllStatic {
 814  private:
 815   enum {
 816    hc_value_offset = 0
 817   };
 818   static int value_offset;
 819   static int long_value_offset;
 820 
 821   static oop initialize_and_allocate(BasicType type, TRAPS);
 822  public:
 823   // Allocation. Returns a boxed value, or NULL for invalid type.
 824   static oop create(BasicType type, jvalue* value, TRAPS);
 825   // Accessors. Returns the basic type being boxed, or T_ILLEGAL for invalid oop.
 826   static BasicType get_value(oop box, jvalue* value);
 827   static BasicType set_value(oop box, jvalue* value);
 828   static BasicType basic_type(oop box);
 829   static bool is_instance(oop box)                 { return basic_type(box) != T_ILLEGAL; }
 830   static bool is_instance(oop box, BasicType type) { return basic_type(box) == type; }
 831   static void print(oop box, outputStream* st)     { jvalue value;  print(get_value(box, &value), &value, st); }
 832   static void print(BasicType type, jvalue* value, outputStream* st);
 833 
 834   static int value_offset_in_bytes(BasicType type) {
 835     return ( type == T_LONG || type == T_DOUBLE ) ? long_value_offset :
 836                                                     value_offset;
 837   }
 838 
 839   // Debugging
 840   friend class JavaClasses;
 841 };
 842 
 843 
 844 
 845 // Interface to java.lang.ref.Reference objects
 846 
 847 class java_lang_ref_Reference: AllStatic {
 848  public:
 849   enum {
 850    hc_referent_offset   = 0,
 851    hc_queue_offset      = 1,
 852    hc_next_offset       = 2,
 853    hc_discovered_offset = 3  // Is not last, see SoftRefs.
 854   };
 855   enum {
 856    hc_static_lock_offset    = 0,
 857    hc_static_pending_offset = 1
 858   };
 859 
 860   static int referent_offset;
 861   static int queue_offset;
 862   static int next_offset;
 863   static int discovered_offset;
 864   static int static_lock_offset;
 865   static int static_pending_offset;
 866   static int number_of_fake_oop_fields;
 867 
 868   // Accessors
 869   static inline oop referent(oop ref);
 870   static inline void set_referent(oop ref, oop value);
 871   static inline void set_referent_raw(oop ref, oop value);
 872   static inline HeapWord* referent_addr(oop ref);
 873   static inline oop next(oop ref);
 874   static inline void set_next(oop ref, oop value);
 875   static inline void set_next_raw(oop ref, oop value);
 876   static inline HeapWord* next_addr(oop ref);
 877   static inline oop discovered(oop ref);
 878   static inline void set_discovered(oop ref, oop value);
 879   static inline void set_discovered_raw(oop ref, oop value);
 880   static inline HeapWord* discovered_addr(oop ref);
 881 
 882   // Accessors for statics
 883   static oop  pending_list_lock();
 884   static oop  pending_list();
 885 
 886   static HeapWord*  pending_list_lock_addr();
 887   static HeapWord*  pending_list_addr();
 888 };
 889 
 890 
 891 // Interface to java.lang.ref.SoftReference objects
 892 
 893 class java_lang_ref_SoftReference: public java_lang_ref_Reference {
 894  public:
 895   enum {
 896    // The timestamp is a long field and may need to be adjusted for alignment.
 897    hc_timestamp_offset  = hc_discovered_offset + 1
 898   };
 899   enum {
 900    hc_static_clock_offset = 0
 901   };
 902 
 903   static int timestamp_offset;
 904   static int static_clock_offset;
 905 
 906   // Accessors
 907   static jlong timestamp(oop ref);
 908 
 909   // Accessors for statics
 910   static jlong clock();
 911   static void set_clock(jlong value);
 912 };
 913 
 914 // Interface to java.lang.invoke.MethodHandle objects
 915 
 916 class MethodHandleEntry;
 917 
 918 class java_lang_invoke_MethodHandle: AllStatic {
 919   friend class JavaClasses;
 920 
 921  private:
 922   static int _type_offset;               // the MethodType of this MH
 923   static int _form_offset;               // the LambdaForm of this MH
 924 
 925   static void compute_offsets();
 926 
 927  public:
 928   // Accessors
 929   static oop            type(oop mh);
 930   static void       set_type(oop mh, oop mtype);
 931 
 932   static oop            form(oop mh);
 933   static void       set_form(oop mh, oop lform);
 934 
 935   // Testers
 936   static bool is_subclass(Klass* klass) {
 937     return klass->is_subclass_of(SystemDictionary::MethodHandle_klass());
 938   }
 939   static bool is_instance(oop obj);
 940 
 941   // Accessors for code generation:
 942   static int type_offset_in_bytes()             { return _type_offset; }
 943   static int form_offset_in_bytes()             { return _form_offset; }
 944 };
 945 
 946 // Interface to java.lang.invoke.DirectMethodHandle objects
 947 
 948 class java_lang_invoke_DirectMethodHandle: AllStatic {
 949   friend class JavaClasses;
 950 
 951  private:
 952   static int _member_offset;               // the MemberName of this DMH
 953 
 954   static void compute_offsets();
 955 
 956  public:
 957   // Accessors
 958   static oop  member(oop mh);
 959 
 960   // Testers
 961   static bool is_subclass(Klass* klass) {
 962     return klass->is_subclass_of(SystemDictionary::DirectMethodHandle_klass());
 963   }
 964   static bool is_instance(oop obj);
 965 
 966   // Accessors for code generation:
 967   static int member_offset_in_bytes()           { return _member_offset; }
 968 };
 969 
 970 // Interface to java.lang.invoke.LambdaForm objects
 971 // (These are a private interface for managing adapter code generation.)
 972 
 973 class java_lang_invoke_LambdaForm: AllStatic {
 974   friend class JavaClasses;
 975 
 976  private:
 977   static int _vmentry_offset;  // type is MemberName
 978 
 979   static void compute_offsets();
 980 
 981  public:
 982   // Accessors
 983   static oop            vmentry(oop lform);
 984   static void       set_vmentry(oop lform, oop invoker);
 985 
 986   // Testers
 987   static bool is_subclass(Klass* klass) {
 988     return SystemDictionary::LambdaForm_klass() != NULL &&
 989       klass->is_subclass_of(SystemDictionary::LambdaForm_klass());
 990   }
 991   static bool is_instance(oop obj);
 992 
 993   // Accessors for code generation:
 994   static int vmentry_offset_in_bytes()          { return _vmentry_offset; }
 995 };
 996 
 997 
 998 // Interface to java.lang.invoke.MemberName objects
 999 // (These are a private interface for Java code to query the class hierarchy.)
1000 
1001 #define MEMBERNAME_INJECTED_FIELDS(macro)                               \
1002   macro(java_lang_invoke_MemberName, vmloader, object_signature, false) \
1003   macro(java_lang_invoke_MemberName, vmindex,  intptr_signature, false) \
1004   macro(java_lang_invoke_MemberName, vmtarget, intptr_signature, false)
1005 
1006 class java_lang_invoke_MemberName: AllStatic {
1007   friend class JavaClasses;
1008 
1009  private:
1010   // From java.lang.invoke.MemberName:
1011   //    private Class<?>   clazz;       // class in which the method is defined
1012   //    private String     name;        // may be null if not yet materialized
1013   //    private Object     type;        // may be null if not yet materialized
1014   //    private int        flags;       // modifier bits; see reflect.Modifier
1015   //    private intptr     vmtarget;    // VM-specific target value
1016   //    private intptr_t   vmindex;     // member index within class or interface
1017   static int _clazz_offset;
1018   static int _name_offset;
1019   static int _type_offset;
1020   static int _flags_offset;
1021   static int _vmtarget_offset;
1022   static int _vmloader_offset;
1023   static int _vmindex_offset;
1024 
1025   static void compute_offsets();
1026 
1027  public:
1028   // Accessors
1029   static oop            clazz(oop mname);
1030   static void       set_clazz(oop mname, oop clazz);
1031 
1032   static oop            type(oop mname);
1033   static void       set_type(oop mname, oop type);
1034 
1035   static oop            name(oop mname);
1036   static void       set_name(oop mname, oop name);
1037 
1038   static int            flags(oop mname);
1039   static void       set_flags(oop mname, int flags);
1040 
1041   static Metadata*      vmtarget(oop mname);
1042   static void       set_vmtarget(oop mname, Metadata* target);
1043 
1044   static intptr_t       vmindex(oop mname);
1045   static void       set_vmindex(oop mname, intptr_t index);
1046 
1047   // Testers
1048   static bool is_subclass(Klass* klass) {
1049     return klass->is_subclass_of(SystemDictionary::MemberName_klass());
1050   }
1051   static bool is_instance(oop obj);
1052 
1053   static bool is_method(oop obj);
1054 
1055   // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):
1056   enum {
1057     MN_IS_METHOD            = 0x00010000, // method (not constructor)
1058     MN_IS_CONSTRUCTOR       = 0x00020000, // constructor
1059     MN_IS_FIELD             = 0x00040000, // field
1060     MN_IS_TYPE              = 0x00080000, // nested type
1061     MN_CALLER_SENSITIVE     = 0x00100000, // @CallerSensitive annotation detected
1062     MN_REFERENCE_KIND_SHIFT = 24, // refKind
1063     MN_REFERENCE_KIND_MASK  = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT,
1064     // The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers:
1065     MN_SEARCH_SUPERCLASSES  = 0x00100000, // walk super classes
1066     MN_SEARCH_INTERFACES    = 0x00200000  // walk implemented interfaces
1067   };
1068 
1069   // Accessors for code generation:
1070   static int clazz_offset_in_bytes()            { return _clazz_offset; }
1071   static int type_offset_in_bytes()             { return _type_offset; }
1072   static int name_offset_in_bytes()             { return _name_offset; }
1073   static int flags_offset_in_bytes()            { return _flags_offset; }
1074   static int vmtarget_offset_in_bytes()         { return _vmtarget_offset; }
1075   static int vmindex_offset_in_bytes()          { return _vmindex_offset; }
1076 };
1077 
1078 
1079 // Interface to java.lang.invoke.MethodType objects
1080 
1081 class java_lang_invoke_MethodType: AllStatic {
1082   friend class JavaClasses;
1083 
1084  private:
1085   static int _rtype_offset;
1086   static int _ptypes_offset;
1087 
1088   static void compute_offsets();
1089 
1090  public:
1091   // Accessors
1092   static oop            rtype(oop mt);
1093   static objArrayOop    ptypes(oop mt);
1094 
1095   static oop            ptype(oop mt, int index);
1096   static int            ptype_count(oop mt);
1097 
1098   static int            ptype_slot_count(oop mt);  // extra counts for long/double
1099   static int            rtype_slot_count(oop mt);  // extra counts for long/double
1100 
1101   static Symbol*        as_signature(oop mt, bool intern_if_not_found, TRAPS);
1102   static void           print_signature(oop mt, outputStream* st);
1103 
1104   static bool is_instance(oop obj);
1105 
1106   static bool equals(oop mt1, oop mt2);
1107 
1108   // Accessors for code generation:
1109   static int rtype_offset_in_bytes()            { return _rtype_offset; }
1110   static int ptypes_offset_in_bytes()           { return _ptypes_offset; }
1111 };
1112 
1113 
1114 // Interface to java.lang.invoke.CallSite objects
1115 
1116 class java_lang_invoke_CallSite: AllStatic {
1117   friend class JavaClasses;
1118 
1119 private:
1120   static int _target_offset;
1121   static int _context_offset;
1122 
1123   static void compute_offsets();
1124 
1125 public:
1126   // Accessors
1127   static oop              target(          oop site);
1128   static void         set_target(          oop site, oop target);
1129   static void         set_target_volatile( oop site, oop target);
1130 
1131   static oop              context(oop site);
1132 
1133   // Testers
1134   static bool is_subclass(Klass* klass) {
1135     return klass->is_subclass_of(SystemDictionary::CallSite_klass());
1136   }
1137   static bool is_instance(oop obj);
1138 
1139   // Accessors for code generation:
1140   static int target_offset_in_bytes()           { return _target_offset; }
1141 };
1142 
1143 // Interface to java.lang.invoke.MethodHandleNatives$CallSiteContext objects
1144 
1145 #define CALLSITECONTEXT_INJECTED_FIELDS(macro) \
1146   macro(java_lang_invoke_MethodHandleNatives_CallSiteContext, vmdependencies, intptr_signature, false)
1147 
1148 class DependencyContext;
1149 
1150 class java_lang_invoke_MethodHandleNatives_CallSiteContext : AllStatic {
1151   friend class JavaClasses;
1152 
1153 private:
1154   static int _vmdependencies_offset;
1155 
1156   static void compute_offsets();
1157 
1158 public:
1159   // Accessors
1160   static DependencyContext vmdependencies(oop context);
1161 
1162   // Testers
1163   static bool is_subclass(Klass* klass) {
1164     return klass->is_subclass_of(SystemDictionary::Context_klass());
1165   }
1166   static bool is_instance(oop obj);
1167 };
1168 
1169 // Interface to java.security.AccessControlContext objects
1170 
1171 class java_security_AccessControlContext: AllStatic {
1172  private:
1173   // Note that for this class the layout changed between JDK1.2 and JDK1.3,
1174   // so we compute the offsets at startup rather than hard-wiring them.
1175   static int _context_offset;
1176   static int _privilegedContext_offset;
1177   static int _isPrivileged_offset;
1178   static int _isAuthorized_offset;
1179 
1180   static void compute_offsets();
1181  public:
1182   static oop create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS);
1183 
1184   static bool is_authorized(Handle context);
1185 
1186   // Debugging/initialization
1187   friend class JavaClasses;
1188 };
1189 
1190 
1191 // Interface to java.lang.ClassLoader objects
1192 
1193 #define CLASSLOADER_INJECTED_FIELDS(macro)                            \
1194   macro(java_lang_ClassLoader, loader_data,  intptr_signature, false)
1195 
1196 class java_lang_ClassLoader : AllStatic {
1197  private:
1198   // The fake offsets are added by the class loader when java.lang.Class is loaded
1199   enum {
1200    hc_parent_offset = 0
1201   };
1202   static int _loader_data_offset;
1203   static bool offsets_computed;
1204   static int parent_offset;
1205   static int parallelCapable_offset;
1206 
1207  public:
1208   static void compute_offsets();
1209 
1210   static ClassLoaderData** loader_data_addr(oop loader);
1211   static ClassLoaderData* loader_data(oop loader);
1212 
1213   static oop parent(oop loader);
1214   static bool isAncestor(oop loader, oop cl);
1215 
1216   // Support for parallelCapable field
1217   static bool parallelCapable(oop the_class_mirror);
1218 
1219   static bool is_trusted_loader(oop loader);
1220 
1221   // Fix for 4474172
1222   static oop  non_reflection_class_loader(oop loader);
1223 
1224   // Testers
1225   static bool is_subclass(Klass* klass) {
1226     return klass->is_subclass_of(SystemDictionary::ClassLoader_klass());
1227   }
1228   static bool is_instance(oop obj);
1229 
1230   // Debugging
1231   friend class JavaClasses;
1232   friend class ClassFileParser; // access to number_of_fake_fields
1233 };
1234 
1235 
1236 // Interface to java.lang.System objects
1237 
1238 class java_lang_System : AllStatic {
1239  private:
1240   enum {
1241    hc_static_in_offset  = 0,
1242    hc_static_out_offset = 1,
1243    hc_static_err_offset = 2,
1244    hc_static_security_offset = 3
1245   };
1246 
1247   static int  static_in_offset;
1248   static int static_out_offset;
1249   static int static_err_offset;
1250   static int static_security_offset;
1251 
1252  public:
1253   static int  in_offset_in_bytes();
1254   static int out_offset_in_bytes();
1255   static int err_offset_in_bytes();
1256 
1257   static bool has_security_manager();
1258 
1259   // Debugging
1260   friend class JavaClasses;
1261 };
1262 
1263 
1264 // Interface to java.lang.StackTraceElement objects
1265 
1266 class java_lang_StackTraceElement: AllStatic {
1267  private:
1268   enum {
1269     hc_declaringClass_offset  = 0,
1270     hc_methodName_offset = 1,
1271     hc_fileName_offset   = 2,
1272     hc_lineNumber_offset = 3
1273   };
1274 
1275   static int declaringClass_offset;
1276   static int methodName_offset;
1277   static int fileName_offset;
1278   static int lineNumber_offset;
1279 
1280  public:
1281   // Setters
1282   static void set_declaringClass(oop element, oop value);
1283   static void set_methodName(oop element, oop value);
1284   static void set_fileName(oop element, oop value);
1285   static void set_lineNumber(oop element, int value);
1286 

1287   // Create an instance of StackTraceElement
1288   static oop create(Handle mirror, int method, int version, int bci, int cpref, TRAPS);
1289   static oop create(const methodHandle& method, int bci, TRAPS);



1290 
1291   // Debugging
1292   friend class JavaClasses;
1293 };
1294 
1295 
1296 class Backtrace: AllStatic {
1297  public:
1298   // Helper backtrace functions to store bci|version together.
1299   static int merge_bci_and_version(int bci, int version);
1300   static int merge_mid_and_cpref(int mid, int cpref);
1301   static int bci_at(unsigned int merged);
1302   static int version_at(unsigned int merged);
1303   static int mid_at(unsigned int merged);
1304   static int cpref_at(unsigned int merged);
1305   static int get_line_number(const methodHandle& method, int bci);
1306   static Symbol* get_source_file_name(InstanceKlass* holder, int version);
1307 
1308   // Debugging
1309   friend class JavaClasses;
1310 };
1311 
1312 // Interface to java.lang.StackFrameInfo objects
1313 
1314 #define STACKFRAMEINFO_INJECTED_FIELDS(macro)                      \
1315   macro(java_lang_StackFrameInfo, mid,     short_signature, false) \
1316   macro(java_lang_StackFrameInfo, version, short_signature, false) \
1317   macro(java_lang_StackFrameInfo, cpref,   short_signature, false)
1318 
1319 class java_lang_StackFrameInfo: AllStatic {
1320 private:
1321   static int _declaringClass_offset;
1322   static int _memberName_offset;
1323   static int _bci_offset;
1324   static int _methodName_offset;
1325   static int _fileName_offset;
1326   static int _lineNumber_offset;
1327 
1328   static int _mid_offset;
1329   static int _version_offset;
1330   static int _cpref_offset;
1331 
1332   static Method* get_method(Handle stackFrame, InstanceKlass* holder, TRAPS);
1333   static Symbol* get_file_name(Handle stackFrame, InstanceKlass* holder);
1334 
1335 public:
1336   // Setters
1337   static void set_declaringClass(oop info, oop value);
1338   static void set_method_and_bci(Handle stackFrame, const methodHandle& method, int bci);
1339   static void set_bci(oop info, int value);
1340 
1341   // set method info in an instance of StackFrameInfo
1342   static void fill_methodInfo(Handle info, TRAPS);
1343   static void set_methodName(oop info, oop value);
1344   static void set_fileName(oop info, oop value);
1345   static void set_lineNumber(oop info, int value);
1346 
1347   // these injected fields are only used if -XX:-MemberNameInStackFrame set
1348   static void set_mid(oop info, short value);
1349   static void set_version(oop info, short value);
1350   static void set_cpref(oop info, short value);
1351 
1352   static void compute_offsets();
1353 
1354   // Debugging
1355   friend class JavaClasses;
1356 };
1357 
1358 class java_lang_LiveStackFrameInfo: AllStatic {
1359  private:
1360   static int _monitors_offset;
1361   static int _locals_offset;
1362   static int _operands_offset;
1363 
1364  public:
1365   static void set_monitors(oop info, oop value);
1366   static void set_locals(oop info, oop value);
1367   static void set_operands(oop info, oop value);
1368 
1369   static void compute_offsets();
1370 
1371   // Debugging
1372   friend class JavaClasses;
1373 };
1374 
1375 // Interface to java.lang.AssertionStatusDirectives objects
1376 
1377 class java_lang_AssertionStatusDirectives: AllStatic {
1378  private:
1379   enum {
1380     hc_classes_offset,
1381     hc_classEnabled_offset,
1382     hc_packages_offset,
1383     hc_packageEnabled_offset,
1384     hc_deflt_offset
1385   };
1386 
1387   static int classes_offset;
1388   static int classEnabled_offset;
1389   static int packages_offset;
1390   static int packageEnabled_offset;
1391   static int deflt_offset;
1392 
1393  public:
1394   // Setters
1395   static void set_classes(oop obj, oop val);
1396   static void set_classEnabled(oop obj, oop val);
1397   static void set_packages(oop obj, oop val);
1398   static void set_packageEnabled(oop obj, oop val);
1399   static void set_deflt(oop obj, bool val);
1400   // Debugging
1401   friend class JavaClasses;
1402 };
1403 
1404 
1405 class java_nio_Buffer: AllStatic {
1406  private:
1407   static int _limit_offset;
1408 
1409  public:
1410   static int  limit_offset();
1411   static void compute_offsets();
1412 };
1413 
1414 class java_util_concurrent_locks_AbstractOwnableSynchronizer : AllStatic {
1415  private:
1416   static int  _owner_offset;
1417  public:
1418   static void initialize(TRAPS);
1419   static oop  get_owner_threadObj(oop obj);
1420 };
1421 
1422 // Use to declare fields that need to be injected into Java classes
1423 // for the JVM to use.  The name_index and signature_index are
1424 // declared in vmSymbols.  The may_be_java flag is used to declare
1425 // fields that might already exist in Java but should be injected if
1426 // they don't.  Otherwise the field is unconditionally injected and
1427 // the JVM uses the injected one.  This is to ensure that name
1428 // collisions don't occur.  In general may_be_java should be false
1429 // unless there's a good reason.
1430 
1431 class InjectedField {
1432  public:
1433   const SystemDictionary::WKID klass_id;
1434   const vmSymbols::SID name_index;
1435   const vmSymbols::SID signature_index;
1436   const bool           may_be_java;
1437 
1438 
1439   Klass* klass() const    { return SystemDictionary::well_known_klass(klass_id); }
1440   Symbol* name() const      { return lookup_symbol(name_index); }
1441   Symbol* signature() const { return lookup_symbol(signature_index); }
1442 
1443   int compute_offset();
1444 
1445   // Find the Symbol for this index
1446   static Symbol* lookup_symbol(int symbol_index) {
1447     return vmSymbols::symbol_at((vmSymbols::SID)symbol_index);
1448   }
1449 };
1450 
1451 #define DECLARE_INJECTED_FIELD_ENUM(klass, name, signature, may_be_java) \
1452   klass##_##name##_enum,
1453 
1454 #define ALL_INJECTED_FIELDS(macro)          \
1455   CLASS_INJECTED_FIELDS(macro)              \
1456   CLASSLOADER_INJECTED_FIELDS(macro)        \
1457   MEMBERNAME_INJECTED_FIELDS(macro)         \
1458   CALLSITECONTEXT_INJECTED_FIELDS(macro)    \
1459   STACKFRAMEINFO_INJECTED_FIELDS(macro)
1460 
1461 
1462 // Interface to hard-coded offset checking
1463 
1464 class JavaClasses : AllStatic {
1465  private:
1466 
1467   static InjectedField _injected_fields[];
1468 
1469   static bool check_offset(const char *klass_name, int offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1470   static bool check_static_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1471   static bool check_constant(const char *klass_name, int constant, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1472 
1473  public:
1474   enum InjectedFieldID {
1475     ALL_INJECTED_FIELDS(DECLARE_INJECTED_FIELD_ENUM)
1476     MAX_enum
1477   };
1478 
1479   static int compute_injected_offset(InjectedFieldID id);
1480 
1481   static void compute_hard_coded_offsets();
1482   static void compute_offsets();
1483   static void check_offsets() PRODUCT_RETURN;
1484 
1485   static InjectedField* get_injected(Symbol* class_name, int* field_count);
1486 };
1487 
1488 #undef DECLARE_INJECTED_FIELD_ENUM
1489 
1490 #endif // SHARE_VM_CLASSFILE_JAVACLASSES_HPP
--- EOF ---