1 /*
   2  * Copyright 1997-2007 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  *
  23  */
  24 
  25 // Interface for manipulating the basic Java classes.
  26 //
  27 // All dependencies on layout of actual Java classes should be kept here.
  28 // If the layout of any of the classes above changes the offsets must be adjusted.
  29 //
  30 // For most classes we hardwire the offsets for performance reasons. In certain
  31 // cases (e.g. java.security.AccessControlContext) we compute the offsets at
  32 // startup since the layout here differs between JDK1.2 and JDK1.3.
  33 //
  34 // Note that fields (static and non-static) are arranged with oops before non-oops
  35 // on a per class basis. The offsets below have to reflect this ordering.
  36 //
  37 // When editing the layouts please update the check_offset verification code
  38 // correspondingly. The names in the enums must be identical to the actual field
  39 // names in order for the verification code to work.
  40 
  41 
  42 // Interface to java.lang.String objects
  43 
  44 class java_lang_String : AllStatic {
  45  private:
  46   enum {
  47     hc_value_offset  = 0,
  48     hc_offset_offset = 1
  49     //hc_count_offset = 2  -- not a word-scaled offset
  50     //hc_hash_offset  = 3  -- not a word-scaled offset
  51   };
  52 
  53   static int value_offset;
  54   static int offset_offset;
  55   static int count_offset;
  56   static int hash_offset;
  57 
  58   static Handle basic_create(int length, bool tenured, TRAPS);
  59   static Handle basic_create_from_unicode(jchar* unicode, int length, bool tenured, TRAPS);
  60 
  61   static void set_value( oop string, typeArrayOop buffer) { string->obj_field_put(value_offset,  (oop)buffer); }
  62   static void set_offset(oop string, int offset)          { string->int_field_put(offset_offset, offset); }
  63   static void set_count( oop string, int count)           { string->int_field_put(count_offset,  count);  }
  64 
  65  public:
  66   // Instance creation
  67   static Handle create_from_unicode(jchar* unicode, int len, TRAPS);
  68   static Handle create_tenured_from_unicode(jchar* unicode, int len, TRAPS);
  69   static oop    create_oop_from_unicode(jchar* unicode, int len, TRAPS);
  70   static Handle create_from_str(const char* utf8_str, TRAPS);
  71   static oop    create_oop_from_str(const char* utf8_str, TRAPS);
  72   static Handle create_from_symbol(symbolHandle symbol, TRAPS);
  73   static Handle create_from_platform_dependent_str(const char* str, TRAPS);
  74   static Handle char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS);
  75 
  76   static int value_offset_in_bytes()  { return value_offset;  }
  77   static int count_offset_in_bytes()  { return count_offset;  }
  78   static int offset_offset_in_bytes() { return offset_offset; }
  79   static int hash_offset_in_bytes()   { return hash_offset;   }
  80 
  81   // Accessors
  82   static typeArrayOop value(oop java_string) {
  83     assert(is_instance(java_string), "must be java_string");
  84     return (typeArrayOop) java_string->obj_field(value_offset);
  85   }
  86   static int offset(oop java_string) {
  87     assert(is_instance(java_string), "must be java_string");
  88     return java_string->int_field(offset_offset);
  89   }
  90   static int length(oop java_string) {
  91     assert(is_instance(java_string), "must be java_string");
  92     return java_string->int_field(count_offset);
  93   }
  94   static int utf8_length(oop java_string);
  95 
  96   // String converters
  97   static char*  as_utf8_string(oop java_string);
  98   static char*  as_utf8_string(oop java_string, int start, int len);
  99   static jchar* as_unicode_string(oop java_string, int& length);
 100 
 101   static bool equals(oop java_string, jchar* chars, int len);
 102 
 103   // Conversion between '.' and '/' formats
 104   static Handle externalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '/', '.', THREAD); }
 105   static Handle internalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '.', '/', THREAD); }
 106 
 107   // Conversion
 108   static symbolHandle as_symbol(Handle java_string, TRAPS);
 109 
 110   // Testers
 111   static bool is_instance(oop obj) {
 112     return obj != NULL && obj->klass() == SystemDictionary::string_klass();
 113   }
 114 
 115   // Debugging
 116   static void print(Handle java_string, outputStream* st);
 117   friend class JavaClasses;
 118 };
 119 
 120 
 121 // Interface to java.lang.Class objects
 122 
 123 class java_lang_Class : AllStatic {
 124    friend class VMStructs;
 125  private:
 126   // The fake offsets are added by the class loader when java.lang.Class is loaded
 127 
 128   enum {
 129     hc_klass_offset                = 0,
 130     hc_array_klass_offset          = 1,
 131     hc_resolved_constructor_offset = 2,
 132     hc_number_of_fake_oop_fields   = 3
 133   };
 134 
 135   static int klass_offset;
 136   static int resolved_constructor_offset;
 137   static int array_klass_offset;
 138   static int number_of_fake_oop_fields;
 139 
 140   static void compute_offsets();
 141   static bool offsets_computed;
 142   static int classRedefinedCount_offset;
 143 
 144  public:
 145   // Instance creation
 146   static oop  create_mirror(KlassHandle k, TRAPS);
 147   static oop  create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS);
 148   // Conversion
 149   static klassOop as_klassOop(oop java_class);
 150   // Testing
 151   static bool is_instance(oop obj) {
 152     return obj != NULL && obj->klass() == SystemDictionary::class_klass();
 153   }
 154   static bool is_primitive(oop java_class);
 155   static BasicType primitive_type(oop java_class);
 156   static oop primitive_mirror(BasicType t);
 157   // JVM_NewInstance support
 158   static methodOop resolved_constructor(oop java_class);
 159   static void set_resolved_constructor(oop java_class, methodOop constructor);
 160   // JVM_NewArray support
 161   static klassOop array_klass(oop java_class);
 162   static void set_array_klass(oop java_class, klassOop klass);
 163   // compiler support for class operations
 164   static int klass_offset_in_bytes() { return klass_offset; }
 165   static int resolved_constructor_offset_in_bytes() { return resolved_constructor_offset; }
 166   static int array_klass_offset_in_bytes() { return array_klass_offset; }
 167   // Support for classRedefinedCount field
 168   static int classRedefinedCount(oop the_class_mirror);
 169   static void set_classRedefinedCount(oop the_class_mirror, int value);
 170   // Debugging
 171   friend class JavaClasses;
 172   friend class instanceKlass;   // verification code accesses offsets
 173   friend class ClassFileParser; // access to number_of_fake_fields
 174 };
 175 
 176 // Interface to java.lang.Thread objects
 177 
 178 class java_lang_Thread : AllStatic {
 179  private:
 180   // Note that for this class the layout changed between JDK1.2 and JDK1.3,
 181   // so we compute the offsets at startup rather than hard-wiring them.
 182   static int _name_offset;
 183   static int _group_offset;
 184   static int _contextClassLoader_offset;
 185   static int _inheritedAccessControlContext_offset;
 186   static int _priority_offset;
 187   static int _eetop_offset;
 188   static int _daemon_offset;
 189   static int _stillborn_offset;
 190   static int _stackSize_offset;
 191   static int _tid_offset;
 192   static int _thread_status_offset;
 193   static int _park_blocker_offset;
 194   static int _park_event_offset ;
 195 
 196   static void compute_offsets();
 197 
 198  public:
 199   // Instance creation
 200   static oop create();
 201   // Returns the JavaThread associated with the thread obj
 202   static JavaThread* thread(oop java_thread);
 203   // Set JavaThread for instance
 204   static void set_thread(oop java_thread, JavaThread* thread);
 205   // Name
 206   static typeArrayOop name(oop java_thread);
 207   static void set_name(oop java_thread, typeArrayOop name);
 208   // Priority
 209   static ThreadPriority priority(oop java_thread);
 210   static void set_priority(oop java_thread, ThreadPriority priority);
 211   // Thread group
 212   static oop  threadGroup(oop java_thread);
 213   // Stillborn
 214   static bool is_stillborn(oop java_thread);
 215   static void set_stillborn(oop java_thread);
 216   // Alive (NOTE: this is not really a field, but provides the correct
 217   // definition without doing a Java call)
 218   static bool is_alive(oop java_thread);
 219   // Daemon
 220   static bool is_daemon(oop java_thread);
 221   static void set_daemon(oop java_thread);
 222   // Context ClassLoader
 223   static oop context_class_loader(oop java_thread);
 224   // Control context
 225   static oop inherited_access_control_context(oop java_thread);
 226   // Stack size hint
 227   static jlong stackSize(oop java_thread);
 228   // Thread ID
 229   static jlong thread_id(oop java_thread);
 230 
 231   // Blocker object responsible for thread parking
 232   static oop park_blocker(oop java_thread);
 233 
 234   // Pointer to type-stable park handler, encoded as jlong.
 235   // Should be set when apparently null
 236   // For details, see unsafe.cpp Unsafe_Unpark
 237   static jlong park_event(oop java_thread);
 238   static bool set_park_event(oop java_thread, jlong ptr);
 239 
 240   // Java Thread Status for JVMTI and M&M use.
 241   // This thread status info is saved in threadStatus field of
 242   // java.lang.Thread java class.
 243   enum ThreadStatus {
 244     NEW                      = 0,
 245     RUNNABLE                 = JVMTI_THREAD_STATE_ALIVE +          // runnable / running
 246                                JVMTI_THREAD_STATE_RUNNABLE,
 247     SLEEPING                 = JVMTI_THREAD_STATE_ALIVE +          // Thread.sleep()
 248                                JVMTI_THREAD_STATE_WAITING +
 249                                JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
 250                                JVMTI_THREAD_STATE_SLEEPING,
 251     IN_OBJECT_WAIT           = JVMTI_THREAD_STATE_ALIVE +          // Object.wait()
 252                                JVMTI_THREAD_STATE_WAITING +
 253                                JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
 254                                JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
 255     IN_OBJECT_WAIT_TIMED     = JVMTI_THREAD_STATE_ALIVE +          // Object.wait(long)
 256                                JVMTI_THREAD_STATE_WAITING +
 257                                JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
 258                                JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
 259     PARKED                   = JVMTI_THREAD_STATE_ALIVE +          // LockSupport.park()
 260                                JVMTI_THREAD_STATE_WAITING +
 261                                JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
 262                                JVMTI_THREAD_STATE_PARKED,
 263     PARKED_TIMED             = JVMTI_THREAD_STATE_ALIVE +          // LockSupport.park(long)
 264                                JVMTI_THREAD_STATE_WAITING +
 265                                JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
 266                                JVMTI_THREAD_STATE_PARKED,
 267     BLOCKED_ON_MONITOR_ENTER = JVMTI_THREAD_STATE_ALIVE +          // (re-)entering a synchronization block
 268                                JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER,
 269     TERMINATED               = JVMTI_THREAD_STATE_TERMINATED
 270   };
 271   // Write thread status info to threadStatus field of java.lang.Thread.
 272   static void set_thread_status(oop java_thread_oop, ThreadStatus status);
 273   // Read thread status info from threadStatus field of java.lang.Thread.
 274   static ThreadStatus get_thread_status(oop java_thread_oop);
 275 
 276   static const char*  thread_status_name(oop java_thread_oop);
 277 
 278   // Debugging
 279   friend class JavaClasses;
 280 };
 281 
 282 // Interface to java.lang.ThreadGroup objects
 283 
 284 class java_lang_ThreadGroup : AllStatic {
 285  private:
 286   static int _parent_offset;
 287   static int _name_offset;
 288   static int _threads_offset;
 289   static int _groups_offset;
 290   static int _maxPriority_offset;
 291   static int _destroyed_offset;
 292   static int _daemon_offset;
 293   static int _vmAllowSuspension_offset;
 294   static int _nthreads_offset;
 295   static int _ngroups_offset;
 296 
 297   static void compute_offsets();
 298 
 299  public:
 300   // parent ThreadGroup
 301   static oop  parent(oop java_thread_group);
 302   // name
 303   static typeArrayOop name(oop java_thread_group);
 304   // ("name as oop" accessor is not necessary)
 305   // Number of threads in group
 306   static int nthreads(oop java_thread_group);
 307   // threads
 308   static objArrayOop threads(oop java_thread_group);
 309   // Number of threads in group
 310   static int ngroups(oop java_thread_group);
 311   // groups
 312   static objArrayOop groups(oop java_thread_group);
 313   // maxPriority in group
 314   static ThreadPriority maxPriority(oop java_thread_group);
 315   // Destroyed
 316   static bool is_destroyed(oop java_thread_group);
 317   // Daemon
 318   static bool is_daemon(oop java_thread_group);
 319   // vmAllowSuspension
 320   static bool is_vmAllowSuspension(oop java_thread_group);
 321   // Debugging
 322   friend class JavaClasses;
 323 };
 324 
 325 
 326 
 327 // Interface to java.lang.Throwable objects
 328 
 329 class java_lang_Throwable: AllStatic {
 330   friend class BacktraceBuilder;
 331 
 332  private:
 333   // Offsets
 334   enum {
 335     hc_backtrace_offset     =  0,
 336     hc_detailMessage_offset =  1,
 337     hc_cause_offset         =  2,  // New since 1.4
 338     hc_stackTrace_offset    =  3   // New since 1.4
 339   };
 340   // Trace constants
 341   enum {
 342     trace_methods_offset = 0,
 343     trace_bcis_offset    = 1,
 344     trace_next_offset    = 2,
 345     trace_size           = 3,
 346     trace_chunk_size     = 32
 347   };
 348 
 349   static int backtrace_offset;
 350   static int detailMessage_offset;
 351   static int cause_offset;
 352   static int stackTrace_offset;
 353 
 354   // Printing
 355   static char* print_stack_element_to_buffer(methodOop method, int bci);
 356   static void print_to_stream(Handle stream, const char* str);
 357   // StackTrace (programmatic access, new since 1.4)
 358   static void clear_stacktrace(oop throwable);
 359   // No stack trace available
 360   static const char* no_stack_trace_message();
 361 
 362  public:
 363   // Backtrace
 364   static oop backtrace(oop throwable);
 365   static void set_backtrace(oop throwable, oop value);
 366   // Needed by JVMTI to filter out this internal field.
 367   static int get_backtrace_offset() { return backtrace_offset;}
 368   static int get_detailMessage_offset() { return detailMessage_offset;}
 369   // Message
 370   static oop message(oop throwable);
 371   static oop message(Handle throwable);
 372   static void set_message(oop throwable, oop value);
 373   // Print stack trace stored in exception by call-back to Java
 374   // Note: this is no longer used in Merlin, but we still suppport
 375   // it for compatibility.
 376   static void print_stack_trace(oop throwable, oop print_stream);
 377   static void print_stack_element(Handle stream, methodOop method, int bci);
 378   static void print_stack_element(outputStream *st, methodOop method, int bci);
 379   static void print_stack_usage(Handle stream);
 380 
 381   // Allocate space for backtrace (created but stack trace not filled in)
 382   static void allocate_backtrace(Handle throwable, TRAPS);
 383   // Fill in current stack trace for throwable with preallocated backtrace (no GC)
 384   static void fill_in_stack_trace_of_preallocated_backtrace(Handle throwable);
 385 
 386   // Fill in current stack trace, can cause GC
 387   static void fill_in_stack_trace(Handle throwable, TRAPS);
 388   static void fill_in_stack_trace(Handle throwable);
 389   // Programmatic access to stack trace
 390   static oop  get_stack_trace_element(oop throwable, int index, TRAPS);
 391   static int  get_stack_trace_depth(oop throwable, TRAPS);
 392   // Printing
 393   static void print(oop throwable, outputStream* st);
 394   static void print(Handle throwable, outputStream* st);
 395   static void print_stack_trace(oop throwable, outputStream* st);
 396   // Debugging
 397   friend class JavaClasses;
 398 };
 399 
 400 
 401 // Interface to java.lang.reflect.AccessibleObject objects
 402 
 403 class java_lang_reflect_AccessibleObject: AllStatic {
 404  private:
 405   // Note that to reduce dependencies on the JDK we compute these
 406   // offsets at run-time.
 407   static int override_offset;
 408 
 409   static void compute_offsets();
 410 
 411  public:
 412   // Accessors
 413   static jboolean override(oop reflect);
 414   static void set_override(oop reflect, jboolean value);
 415 
 416   // Debugging
 417   friend class JavaClasses;
 418 };
 419 
 420 
 421 // Interface to java.lang.reflect.Method objects
 422 
 423 class java_lang_reflect_Method : public java_lang_reflect_AccessibleObject {
 424  private:
 425   // Note that to reduce dependencies on the JDK we compute these
 426   // offsets at run-time.
 427   static int clazz_offset;
 428   static int name_offset;
 429   static int returnType_offset;
 430   static int parameterTypes_offset;
 431   static int exceptionTypes_offset;
 432   static int slot_offset;
 433   static int modifiers_offset;
 434   static int signature_offset;
 435   static int annotations_offset;
 436   static int parameter_annotations_offset;
 437   static int annotation_default_offset;
 438 
 439   static void compute_offsets();
 440 
 441  public:
 442   // Allocation
 443   static Handle create(TRAPS);
 444 
 445   // Accessors
 446   static oop clazz(oop reflect);
 447   static void set_clazz(oop reflect, oop value);
 448 
 449   static oop name(oop method);
 450   static void set_name(oop method, oop value);
 451 
 452   static oop return_type(oop method);
 453   static void set_return_type(oop method, oop value);
 454 
 455   static oop parameter_types(oop method);
 456   static void set_parameter_types(oop method, oop value);
 457 
 458   static oop exception_types(oop method);
 459   static void set_exception_types(oop method, oop value);
 460 
 461   static int slot(oop reflect);
 462   static void set_slot(oop reflect, int value);
 463 
 464   static int modifiers(oop method);
 465   static void set_modifiers(oop method, int value);
 466 
 467   static bool has_signature_field();
 468   static oop signature(oop method);
 469   static void set_signature(oop method, oop value);
 470 
 471   static bool has_annotations_field();
 472   static oop annotations(oop method);
 473   static void set_annotations(oop method, oop value);
 474 
 475   static bool has_parameter_annotations_field();
 476   static oop parameter_annotations(oop method);
 477   static void set_parameter_annotations(oop method, oop value);
 478 
 479   static bool has_annotation_default_field();
 480   static oop annotation_default(oop method);
 481   static void set_annotation_default(oop method, oop value);
 482 
 483   // Debugging
 484   friend class JavaClasses;
 485 };
 486 
 487 
 488 // Interface to java.lang.reflect.Constructor objects
 489 
 490 class java_lang_reflect_Constructor : public java_lang_reflect_AccessibleObject {
 491  private:
 492   // Note that to reduce dependencies on the JDK we compute these
 493   // offsets at run-time.
 494   static int clazz_offset;
 495   static int parameterTypes_offset;
 496   static int exceptionTypes_offset;
 497   static int slot_offset;
 498   static int modifiers_offset;
 499   static int signature_offset;
 500   static int annotations_offset;
 501   static int parameter_annotations_offset;
 502 
 503   static void compute_offsets();
 504 
 505  public:
 506   // Allocation
 507   static Handle create(TRAPS);
 508 
 509   // Accessors
 510   static oop clazz(oop reflect);
 511   static void set_clazz(oop reflect, oop value);
 512 
 513   static oop parameter_types(oop constructor);
 514   static void set_parameter_types(oop constructor, oop value);
 515 
 516   static oop exception_types(oop constructor);
 517   static void set_exception_types(oop constructor, oop value);
 518 
 519   static int slot(oop reflect);
 520   static void set_slot(oop reflect, int value);
 521 
 522   static int modifiers(oop constructor);
 523   static void set_modifiers(oop constructor, int value);
 524 
 525   static bool has_signature_field();
 526   static oop signature(oop constructor);
 527   static void set_signature(oop constructor, oop value);
 528 
 529   static bool has_annotations_field();
 530   static oop annotations(oop constructor);
 531   static void set_annotations(oop constructor, oop value);
 532 
 533   static bool has_parameter_annotations_field();
 534   static oop parameter_annotations(oop method);
 535   static void set_parameter_annotations(oop method, oop value);
 536 
 537   // Debugging
 538   friend class JavaClasses;
 539 };
 540 
 541 
 542 // Interface to java.lang.reflect.Field objects
 543 
 544 class java_lang_reflect_Field : public java_lang_reflect_AccessibleObject {
 545  private:
 546   // Note that to reduce dependencies on the JDK we compute these
 547   // offsets at run-time.
 548   static int clazz_offset;
 549   static int name_offset;
 550   static int type_offset;
 551   static int slot_offset;
 552   static int modifiers_offset;
 553   static int signature_offset;
 554   static int annotations_offset;
 555 
 556   static void compute_offsets();
 557 
 558  public:
 559   // Allocation
 560   static Handle create(TRAPS);
 561 
 562   // Accessors
 563   static oop clazz(oop reflect);
 564   static void set_clazz(oop reflect, oop value);
 565 
 566   static oop name(oop field);
 567   static void set_name(oop field, oop value);
 568 
 569   static oop type(oop field);
 570   static void set_type(oop field, oop value);
 571 
 572   static int slot(oop reflect);
 573   static void set_slot(oop reflect, int value);
 574 
 575   static int modifiers(oop field);
 576   static void set_modifiers(oop field, int value);
 577 
 578   static bool has_signature_field();
 579   static oop signature(oop constructor);
 580   static void set_signature(oop constructor, oop value);
 581 
 582   static bool has_annotations_field();
 583   static oop annotations(oop constructor);
 584   static void set_annotations(oop constructor, oop value);
 585 
 586   static bool has_parameter_annotations_field();
 587   static oop parameter_annotations(oop method);
 588   static void set_parameter_annotations(oop method, oop value);
 589 
 590   static bool has_annotation_default_field();
 591   static oop annotation_default(oop method);
 592   static void set_annotation_default(oop method, oop value);
 593 
 594   // Debugging
 595   friend class JavaClasses;
 596 };
 597 
 598 // Interface to sun.reflect.ConstantPool objects
 599 class sun_reflect_ConstantPool {
 600  private:
 601   // Note that to reduce dependencies on the JDK we compute these
 602   // offsets at run-time.
 603   static int _cp_oop_offset;
 604 
 605   static void compute_offsets();
 606 
 607  public:
 608   // Allocation
 609   static Handle create(TRAPS);
 610 
 611   // Accessors
 612   static oop cp_oop(oop reflect);
 613   static void set_cp_oop(oop reflect, oop value);
 614   static int cp_oop_offset() {
 615     return _cp_oop_offset;
 616   }
 617 
 618   // Debugging
 619   friend class JavaClasses;
 620 };
 621 
 622 // Interface to sun.reflect.UnsafeStaticFieldAccessorImpl objects
 623 class sun_reflect_UnsafeStaticFieldAccessorImpl {
 624  private:
 625   static int _base_offset;
 626   static void compute_offsets();
 627 
 628  public:
 629   static int base_offset() {
 630     return _base_offset;
 631   }
 632 
 633   // Debugging
 634   friend class JavaClasses;
 635 };
 636 
 637 // Interface to java.lang primitive type boxing objects:
 638 //  - java.lang.Boolean
 639 //  - java.lang.Character
 640 //  - java.lang.Float
 641 //  - java.lang.Double
 642 //  - java.lang.Byte
 643 //  - java.lang.Short
 644 //  - java.lang.Integer
 645 //  - java.lang.Long
 646 
 647 // This could be separated out into 8 individual classes.
 648 
 649 class java_lang_boxing_object: AllStatic {
 650  private:
 651   enum {
 652    hc_value_offset = 0
 653   };
 654   static int value_offset;
 655 
 656   static oop initialize_and_allocate(BasicType type, TRAPS);
 657  public:
 658   // Allocation. Returns a boxed value, or NULL for invalid type.
 659   static oop create(BasicType type, jvalue* value, TRAPS);
 660   // Accessors. Returns the basic type being boxed, or T_ILLEGAL for invalid oop.
 661   static BasicType get_value(oop box, jvalue* value);
 662   static BasicType set_value(oop box, jvalue* value);
 663   static BasicType basic_type(oop box);
 664   static bool is_instance(oop box)                 { return basic_type(box) != T_ILLEGAL; }
 665   static bool is_instance(oop box, BasicType type) { return basic_type(box) == type; }
 666 
 667   static int value_offset_in_bytes() { return value_offset; }
 668 
 669   // Debugging
 670   friend class JavaClasses;
 671 };
 672 
 673 
 674 
 675 // Interface to java.lang.ref.Reference objects
 676 
 677 class java_lang_ref_Reference: AllStatic {
 678  public:
 679   enum {
 680    hc_referent_offset   = 0,
 681    hc_queue_offset      = 1,
 682    hc_next_offset       = 2,
 683    hc_discovered_offset = 3  // Is not last, see SoftRefs.
 684   };
 685   enum {
 686    hc_static_lock_offset    = 0,
 687    hc_static_pending_offset = 1
 688   };
 689 
 690   static int referent_offset;
 691   static int queue_offset;
 692   static int next_offset;
 693   static int discovered_offset;
 694   static int static_lock_offset;
 695   static int static_pending_offset;
 696   static int number_of_fake_oop_fields;
 697 
 698   // Accessors
 699   static oop referent(oop ref)        { return *referent_addr(ref); }
 700   static void set_referent(oop ref, oop value);
 701   static oop* referent_addr(oop ref);
 702 
 703   static oop next(oop ref)            { return *next_addr(ref); }
 704   static void set_next(oop ref, oop value);
 705   static oop* next_addr(oop ref);
 706 
 707   static oop discovered(oop ref)      { return *discovered_addr(ref); }
 708   static void set_discovered(oop ref, oop value);
 709   static oop* discovered_addr(oop ref);
 710 
 711   // Accessors for statics
 712   static oop  pending_list_lock()     { return *pending_list_lock_addr(); }
 713   static oop  pending_list()          { return *pending_list_addr(); }
 714 
 715   static oop* pending_list_lock_addr();
 716   static oop* pending_list_addr();
 717 };
 718 
 719 
 720 // Interface to java.lang.ref.SoftReference objects
 721 
 722 class java_lang_ref_SoftReference: public java_lang_ref_Reference {
 723  public:
 724   enum {
 725    // The timestamp is a long field and may need to be adjusted for alignment.
 726    hc_timestamp_offset    = align_object_offset_(hc_discovered_offset + 1)
 727   };
 728   enum {
 729    hc_static_clock_offset = 0
 730   };
 731 
 732   static int timestamp_offset;
 733   static int static_clock_offset;
 734 
 735   // Accessors
 736   static jlong timestamp(oop ref);
 737 
 738   // Accessors for statics
 739   static jlong clock();
 740   static void set_clock(jlong value);
 741 };
 742 
 743 
 744 // Interface to java.security.AccessControlContext objects
 745 
 746 class java_security_AccessControlContext: AllStatic {
 747  private:
 748   // Note that for this class the layout changed between JDK1.2 and JDK1.3,
 749   // so we compute the offsets at startup rather than hard-wiring them.
 750   static int _context_offset;
 751   static int _privilegedContext_offset;
 752   static int _isPrivileged_offset;
 753 
 754   static void compute_offsets();
 755  public:
 756   static oop create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS);
 757 
 758   // Debugging/initialization
 759   friend class JavaClasses;
 760 };
 761 
 762 
 763 // Interface to java.lang.ClassLoader objects
 764 
 765 class java_lang_ClassLoader : AllStatic {
 766  private:
 767   enum {
 768    hc_parent_offset = 0
 769   };
 770 
 771   static int parent_offset;
 772 
 773  public:
 774   static oop parent(oop loader);
 775 
 776   static bool is_trusted_loader(oop loader);
 777 
 778   // Fix for 4474172
 779   static oop  non_reflection_class_loader(oop loader);
 780 
 781   // Debugging
 782   friend class JavaClasses;
 783 };
 784 
 785 
 786 // Interface to java.lang.System objects
 787 
 788 class java_lang_System : AllStatic {
 789  private:
 790   enum {
 791    hc_static_in_offset  = 0,
 792    hc_static_out_offset = 1,
 793    hc_static_err_offset = 2
 794   };
 795 
 796   static int offset_of_static_fields;
 797   static int  static_in_offset;
 798   static int static_out_offset;
 799   static int static_err_offset;
 800 
 801   static void compute_offsets();
 802 
 803  public:
 804   static int  in_offset_in_bytes();
 805   static int out_offset_in_bytes();
 806   static int err_offset_in_bytes();
 807 
 808   // Debugging
 809   friend class JavaClasses;
 810 };
 811 
 812 
 813 // Interface to java.lang.StackTraceElement objects
 814 
 815 class java_lang_StackTraceElement: AllStatic {
 816  private:
 817   enum {
 818     hc_declaringClass_offset  = 0,
 819     hc_methodName_offset = 1,
 820     hc_fileName_offset   = 2,
 821     hc_lineNumber_offset = 3
 822   };
 823 
 824   static int declaringClass_offset;
 825   static int methodName_offset;
 826   static int fileName_offset;
 827   static int lineNumber_offset;
 828 
 829  public:
 830   // Setters
 831   static void set_declaringClass(oop element, oop value);
 832   static void set_methodName(oop element, oop value);
 833   static void set_fileName(oop element, oop value);
 834   static void set_lineNumber(oop element, int value);
 835 
 836   // Create an instance of StackTraceElement
 837   static oop create(methodHandle m, int bci, TRAPS);
 838 
 839   // Debugging
 840   friend class JavaClasses;
 841 };
 842 
 843 
 844 // Interface to java.lang.AssertionStatusDirectives objects
 845 
 846 class java_lang_AssertionStatusDirectives: AllStatic {
 847  private:
 848   enum {
 849     hc_classes_offset,
 850     hc_classEnabled_offset,
 851     hc_packages_offset,
 852     hc_packageEnabled_offset,
 853     hc_deflt_offset
 854   };
 855 
 856   static int classes_offset;
 857   static int classEnabled_offset;
 858   static int packages_offset;
 859   static int packageEnabled_offset;
 860   static int deflt_offset;
 861 
 862  public:
 863   // Setters
 864   static void set_classes(oop obj, oop val);
 865   static void set_classEnabled(oop obj, oop val);
 866   static void set_packages(oop obj, oop val);
 867   static void set_packageEnabled(oop obj, oop val);
 868   static void set_deflt(oop obj, bool val);
 869   // Debugging
 870   friend class JavaClasses;
 871 };
 872 
 873 
 874 class java_nio_Buffer: AllStatic {
 875  private:
 876   static int _limit_offset;
 877 
 878  public:
 879   static int  limit_offset();
 880   static void compute_offsets();
 881 };
 882 
 883 class sun_misc_AtomicLongCSImpl: AllStatic {
 884  private:
 885   static int _value_offset;
 886 
 887  public:
 888   static int  value_offset();
 889   static void compute_offsets();
 890 };
 891 
 892 class java_util_concurrent_locks_AbstractOwnableSynchronizer : AllStatic {
 893  private:
 894   static int  _owner_offset;
 895  public:
 896   static void initialize(TRAPS);
 897   static oop  get_owner_threadObj(oop obj);
 898 };
 899 
 900 // Interface to hard-coded offset checking
 901 
 902 class JavaClasses : AllStatic {
 903  private:
 904   static bool check_offset(const char *klass_name, int offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
 905   static bool check_static_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
 906   static bool check_constant(const char *klass_name, int constant, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
 907  public:
 908   static void compute_hard_coded_offsets();
 909   static void compute_offsets();
 910   static void check_offsets() PRODUCT_RETURN;
 911 };