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