src/share/vm/classfile/javaClasses.hpp

Mon, 13 Sep 2010 23:24:30 -0700

author
jrose
date
Mon, 13 Sep 2010 23:24:30 -0700
changeset 2148
d257356e35f0
parent 1907
c18cbe5936b8
child 2314
f95d63e2154a
permissions
-rw-r--r--

6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
Reviewed-by: never

     1 /*
     2  * Copyright (c) 1997, 2009, 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  */
    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.
    42 // Interface to java.lang.String objects
    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   };
    53   static int value_offset;
    54   static int offset_offset;
    55   static int count_offset;
    56   static int hash_offset;
    58   static Handle basic_create(int length, bool tenured, TRAPS);
    59   static Handle basic_create_from_unicode(jchar* unicode, int length, bool tenured, TRAPS);
    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);  }
    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);
    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;   }
    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);
    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 char*  as_platform_dependent_str(Handle java_string, TRAPS);
   100   static jchar* as_unicode_string(oop java_string, int& length);
   102   static bool equals(oop java_string, jchar* chars, int len);
   104   // Conversion between '.' and '/' formats
   105   static Handle externalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '/', '.', THREAD); }
   106   static Handle internalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '.', '/', THREAD); }
   108   // Conversion
   109   static symbolHandle as_symbol(Handle java_string, TRAPS);
   110   static symbolOop as_symbol_or_null(oop java_string);
   112   // Testers
   113   static bool is_instance(oop obj) {
   114     return obj != NULL && obj->klass() == SystemDictionary::String_klass();
   115   }
   117   // Debugging
   118   static void print(Handle java_string, outputStream* st);
   119   friend class JavaClasses;
   120 };
   123 // Interface to java.lang.Class objects
   125 class java_lang_Class : AllStatic {
   126    friend class VMStructs;
   127  private:
   128   // The fake offsets are added by the class loader when java.lang.Class is loaded
   130   enum {
   131     hc_klass_offset                = 0,
   132     hc_array_klass_offset          = 1,
   133     hc_resolved_constructor_offset = 2,
   134     hc_number_of_fake_oop_fields   = 3
   135   };
   137   static int klass_offset;
   138   static int resolved_constructor_offset;
   139   static int array_klass_offset;
   140   static int number_of_fake_oop_fields;
   142   static void compute_offsets();
   143   static bool offsets_computed;
   144   static int classRedefinedCount_offset;
   145   static int parallelCapable_offset;
   147  public:
   148   // Instance creation
   149   static oop  create_mirror(KlassHandle k, TRAPS);
   150   static oop  create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS);
   151   // Conversion
   152   static klassOop as_klassOop(oop java_class);
   153   static BasicType as_BasicType(oop java_class, klassOop* reference_klass = NULL);
   154   static BasicType as_BasicType(oop java_class, KlassHandle* reference_klass) {
   155     klassOop refk_oop = NULL;
   156     BasicType result = as_BasicType(java_class, &refk_oop);
   157     (*reference_klass) = KlassHandle(refk_oop);
   158     return result;
   159   }
   160   static symbolOop as_signature(oop java_class, bool intern_if_not_found, TRAPS);
   161   static void print_signature(oop java_class, outputStream *st);
   162   // Testing
   163   static bool is_instance(oop obj) {
   164     return obj != NULL && obj->klass() == SystemDictionary::Class_klass();
   165   }
   166   static bool is_primitive(oop java_class);
   167   static BasicType primitive_type(oop java_class);
   168   static oop primitive_mirror(BasicType t);
   169   // JVM_NewInstance support
   170   static methodOop resolved_constructor(oop java_class);
   171   static void set_resolved_constructor(oop java_class, methodOop constructor);
   172   // JVM_NewArray support
   173   static klassOop array_klass(oop java_class);
   174   static void set_array_klass(oop java_class, klassOop klass);
   175   // compiler support for class operations
   176   static int klass_offset_in_bytes() { return klass_offset; }
   177   static int resolved_constructor_offset_in_bytes() { return resolved_constructor_offset; }
   178   static int array_klass_offset_in_bytes() { return array_klass_offset; }
   179   // Support for classRedefinedCount field
   180   static int classRedefinedCount(oop the_class_mirror);
   181   static void set_classRedefinedCount(oop the_class_mirror, int value);
   182   // Support for parallelCapable field
   183   static bool parallelCapable(oop the_class_mirror);
   184   // Debugging
   185   friend class JavaClasses;
   186   friend class instanceKlass;   // verification code accesses offsets
   187   friend class ClassFileParser; // access to number_of_fake_fields
   188 };
   190 // Interface to java.lang.Thread objects
   192 class java_lang_Thread : AllStatic {
   193  private:
   194   // Note that for this class the layout changed between JDK1.2 and JDK1.3,
   195   // so we compute the offsets at startup rather than hard-wiring them.
   196   static int _name_offset;
   197   static int _group_offset;
   198   static int _contextClassLoader_offset;
   199   static int _inheritedAccessControlContext_offset;
   200   static int _priority_offset;
   201   static int _eetop_offset;
   202   static int _daemon_offset;
   203   static int _stillborn_offset;
   204   static int _stackSize_offset;
   205   static int _tid_offset;
   206   static int _thread_status_offset;
   207   static int _park_blocker_offset;
   208   static int _park_event_offset ;
   210   static void compute_offsets();
   212  public:
   213   // Instance creation
   214   static oop create();
   215   // Returns the JavaThread associated with the thread obj
   216   static JavaThread* thread(oop java_thread);
   217   // Set JavaThread for instance
   218   static void set_thread(oop java_thread, JavaThread* thread);
   219   // Name
   220   static typeArrayOop name(oop java_thread);
   221   static void set_name(oop java_thread, typeArrayOop name);
   222   // Priority
   223   static ThreadPriority priority(oop java_thread);
   224   static void set_priority(oop java_thread, ThreadPriority priority);
   225   // Thread group
   226   static oop  threadGroup(oop java_thread);
   227   // Stillborn
   228   static bool is_stillborn(oop java_thread);
   229   static void set_stillborn(oop java_thread);
   230   // Alive (NOTE: this is not really a field, but provides the correct
   231   // definition without doing a Java call)
   232   static bool is_alive(oop java_thread);
   233   // Daemon
   234   static bool is_daemon(oop java_thread);
   235   static void set_daemon(oop java_thread);
   236   // Context ClassLoader
   237   static oop context_class_loader(oop java_thread);
   238   // Control context
   239   static oop inherited_access_control_context(oop java_thread);
   240   // Stack size hint
   241   static jlong stackSize(oop java_thread);
   242   // Thread ID
   243   static jlong thread_id(oop java_thread);
   245   // Blocker object responsible for thread parking
   246   static oop park_blocker(oop java_thread);
   248   // Pointer to type-stable park handler, encoded as jlong.
   249   // Should be set when apparently null
   250   // For details, see unsafe.cpp Unsafe_Unpark
   251   static jlong park_event(oop java_thread);
   252   static bool set_park_event(oop java_thread, jlong ptr);
   254   // Java Thread Status for JVMTI and M&M use.
   255   // This thread status info is saved in threadStatus field of
   256   // java.lang.Thread java class.
   257   enum ThreadStatus {
   258     NEW                      = 0,
   259     RUNNABLE                 = JVMTI_THREAD_STATE_ALIVE +          // runnable / running
   260                                JVMTI_THREAD_STATE_RUNNABLE,
   261     SLEEPING                 = JVMTI_THREAD_STATE_ALIVE +          // Thread.sleep()
   262                                JVMTI_THREAD_STATE_WAITING +
   263                                JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
   264                                JVMTI_THREAD_STATE_SLEEPING,
   265     IN_OBJECT_WAIT           = JVMTI_THREAD_STATE_ALIVE +          // Object.wait()
   266                                JVMTI_THREAD_STATE_WAITING +
   267                                JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
   268                                JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
   269     IN_OBJECT_WAIT_TIMED     = JVMTI_THREAD_STATE_ALIVE +          // Object.wait(long)
   270                                JVMTI_THREAD_STATE_WAITING +
   271                                JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
   272                                JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
   273     PARKED                   = JVMTI_THREAD_STATE_ALIVE +          // LockSupport.park()
   274                                JVMTI_THREAD_STATE_WAITING +
   275                                JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
   276                                JVMTI_THREAD_STATE_PARKED,
   277     PARKED_TIMED             = JVMTI_THREAD_STATE_ALIVE +          // LockSupport.park(long)
   278                                JVMTI_THREAD_STATE_WAITING +
   279                                JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
   280                                JVMTI_THREAD_STATE_PARKED,
   281     BLOCKED_ON_MONITOR_ENTER = JVMTI_THREAD_STATE_ALIVE +          // (re-)entering a synchronization block
   282                                JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER,
   283     TERMINATED               = JVMTI_THREAD_STATE_TERMINATED
   284   };
   285   // Write thread status info to threadStatus field of java.lang.Thread.
   286   static void set_thread_status(oop java_thread_oop, ThreadStatus status);
   287   // Read thread status info from threadStatus field of java.lang.Thread.
   288   static ThreadStatus get_thread_status(oop java_thread_oop);
   290   static const char*  thread_status_name(oop java_thread_oop);
   292   // Debugging
   293   friend class JavaClasses;
   294 };
   296 // Interface to java.lang.ThreadGroup objects
   298 class java_lang_ThreadGroup : AllStatic {
   299  private:
   300   static int _parent_offset;
   301   static int _name_offset;
   302   static int _threads_offset;
   303   static int _groups_offset;
   304   static int _maxPriority_offset;
   305   static int _destroyed_offset;
   306   static int _daemon_offset;
   307   static int _vmAllowSuspension_offset;
   308   static int _nthreads_offset;
   309   static int _ngroups_offset;
   311   static void compute_offsets();
   313  public:
   314   // parent ThreadGroup
   315   static oop  parent(oop java_thread_group);
   316   // name
   317   static typeArrayOop name(oop java_thread_group);
   318   // ("name as oop" accessor is not necessary)
   319   // Number of threads in group
   320   static int nthreads(oop java_thread_group);
   321   // threads
   322   static objArrayOop threads(oop java_thread_group);
   323   // Number of threads in group
   324   static int ngroups(oop java_thread_group);
   325   // groups
   326   static objArrayOop groups(oop java_thread_group);
   327   // maxPriority in group
   328   static ThreadPriority maxPriority(oop java_thread_group);
   329   // Destroyed
   330   static bool is_destroyed(oop java_thread_group);
   331   // Daemon
   332   static bool is_daemon(oop java_thread_group);
   333   // vmAllowSuspension
   334   static bool is_vmAllowSuspension(oop java_thread_group);
   335   // Debugging
   336   friend class JavaClasses;
   337 };
   341 // Interface to java.lang.Throwable objects
   343 class java_lang_Throwable: AllStatic {
   344   friend class BacktraceBuilder;
   346  private:
   347   // Offsets
   348   enum {
   349     hc_backtrace_offset     =  0,
   350     hc_detailMessage_offset =  1,
   351     hc_cause_offset         =  2,  // New since 1.4
   352     hc_stackTrace_offset    =  3   // New since 1.4
   353   };
   354   // Trace constants
   355   enum {
   356     trace_methods_offset = 0,
   357     trace_bcis_offset    = 1,
   358     trace_next_offset    = 2,
   359     trace_size           = 3,
   360     trace_chunk_size     = 32
   361   };
   363   static int backtrace_offset;
   364   static int detailMessage_offset;
   365   static int cause_offset;
   366   static int stackTrace_offset;
   368   // Printing
   369   static char* print_stack_element_to_buffer(methodOop method, int bci);
   370   static void print_to_stream(Handle stream, const char* str);
   371   // StackTrace (programmatic access, new since 1.4)
   372   static void clear_stacktrace(oop throwable);
   373   // No stack trace available
   374   static const char* no_stack_trace_message();
   376  public:
   377   // Backtrace
   378   static oop backtrace(oop throwable);
   379   static void set_backtrace(oop throwable, oop value);
   380   // Needed by JVMTI to filter out this internal field.
   381   static int get_backtrace_offset() { return backtrace_offset;}
   382   static int get_detailMessage_offset() { return detailMessage_offset;}
   383   // Message
   384   static oop message(oop throwable);
   385   static oop message(Handle throwable);
   386   static void set_message(oop throwable, oop value);
   387   // Print stack trace stored in exception by call-back to Java
   388   // Note: this is no longer used in Merlin, but we still suppport
   389   // it for compatibility.
   390   static void print_stack_trace(oop throwable, oop print_stream);
   391   static void print_stack_element(Handle stream, methodOop method, int bci);
   392   static void print_stack_element(outputStream *st, methodOop method, int bci);
   393   static void print_stack_usage(Handle stream);
   395   // Allocate space for backtrace (created but stack trace not filled in)
   396   static void allocate_backtrace(Handle throwable, TRAPS);
   397   // Fill in current stack trace for throwable with preallocated backtrace (no GC)
   398   static void fill_in_stack_trace_of_preallocated_backtrace(Handle throwable);
   400   // Fill in current stack trace, can cause GC
   401   static void fill_in_stack_trace(Handle throwable, TRAPS);
   402   static void fill_in_stack_trace(Handle throwable);
   403   // Programmatic access to stack trace
   404   static oop  get_stack_trace_element(oop throwable, int index, TRAPS);
   405   static int  get_stack_trace_depth(oop throwable, TRAPS);
   406   // Printing
   407   static void print(oop throwable, outputStream* st);
   408   static void print(Handle throwable, outputStream* st);
   409   static void print_stack_trace(oop throwable, outputStream* st);
   410   // Debugging
   411   friend class JavaClasses;
   412 };
   415 // Interface to java.lang.reflect.AccessibleObject objects
   417 class java_lang_reflect_AccessibleObject: AllStatic {
   418  private:
   419   // Note that to reduce dependencies on the JDK we compute these
   420   // offsets at run-time.
   421   static int override_offset;
   423   static void compute_offsets();
   425  public:
   426   // Accessors
   427   static jboolean override(oop reflect);
   428   static void set_override(oop reflect, jboolean value);
   430   // Debugging
   431   friend class JavaClasses;
   432 };
   435 // Interface to java.lang.reflect.Method objects
   437 class java_lang_reflect_Method : public java_lang_reflect_AccessibleObject {
   438  private:
   439   // Note that to reduce dependencies on the JDK we compute these
   440   // offsets at run-time.
   441   static int clazz_offset;
   442   static int name_offset;
   443   static int returnType_offset;
   444   static int parameterTypes_offset;
   445   static int exceptionTypes_offset;
   446   static int slot_offset;
   447   static int modifiers_offset;
   448   static int signature_offset;
   449   static int annotations_offset;
   450   static int parameter_annotations_offset;
   451   static int annotation_default_offset;
   453   static void compute_offsets();
   455  public:
   456   // Allocation
   457   static Handle create(TRAPS);
   459   // Accessors
   460   static oop clazz(oop reflect);
   461   static void set_clazz(oop reflect, oop value);
   463   static oop name(oop method);
   464   static void set_name(oop method, oop value);
   466   static oop return_type(oop method);
   467   static void set_return_type(oop method, oop value);
   469   static oop parameter_types(oop method);
   470   static void set_parameter_types(oop method, oop value);
   472   static oop exception_types(oop method);
   473   static void set_exception_types(oop method, oop value);
   475   static int slot(oop reflect);
   476   static void set_slot(oop reflect, int value);
   478   static int modifiers(oop method);
   479   static void set_modifiers(oop method, int value);
   481   static bool has_signature_field();
   482   static oop signature(oop method);
   483   static void set_signature(oop method, oop value);
   485   static bool has_annotations_field();
   486   static oop annotations(oop method);
   487   static void set_annotations(oop method, oop value);
   489   static bool has_parameter_annotations_field();
   490   static oop parameter_annotations(oop method);
   491   static void set_parameter_annotations(oop method, oop value);
   493   static bool has_annotation_default_field();
   494   static oop annotation_default(oop method);
   495   static void set_annotation_default(oop method, oop value);
   497   // Debugging
   498   friend class JavaClasses;
   499 };
   502 // Interface to java.lang.reflect.Constructor objects
   504 class java_lang_reflect_Constructor : public java_lang_reflect_AccessibleObject {
   505  private:
   506   // Note that to reduce dependencies on the JDK we compute these
   507   // offsets at run-time.
   508   static int clazz_offset;
   509   static int parameterTypes_offset;
   510   static int exceptionTypes_offset;
   511   static int slot_offset;
   512   static int modifiers_offset;
   513   static int signature_offset;
   514   static int annotations_offset;
   515   static int parameter_annotations_offset;
   517   static void compute_offsets();
   519  public:
   520   // Allocation
   521   static Handle create(TRAPS);
   523   // Accessors
   524   static oop clazz(oop reflect);
   525   static void set_clazz(oop reflect, oop value);
   527   static oop parameter_types(oop constructor);
   528   static void set_parameter_types(oop constructor, oop value);
   530   static oop exception_types(oop constructor);
   531   static void set_exception_types(oop constructor, oop value);
   533   static int slot(oop reflect);
   534   static void set_slot(oop reflect, int value);
   536   static int modifiers(oop constructor);
   537   static void set_modifiers(oop constructor, int value);
   539   static bool has_signature_field();
   540   static oop signature(oop constructor);
   541   static void set_signature(oop constructor, oop value);
   543   static bool has_annotations_field();
   544   static oop annotations(oop constructor);
   545   static void set_annotations(oop constructor, oop value);
   547   static bool has_parameter_annotations_field();
   548   static oop parameter_annotations(oop method);
   549   static void set_parameter_annotations(oop method, oop value);
   551   // Debugging
   552   friend class JavaClasses;
   553 };
   556 // Interface to java.lang.reflect.Field objects
   558 class java_lang_reflect_Field : public java_lang_reflect_AccessibleObject {
   559  private:
   560   // Note that to reduce dependencies on the JDK we compute these
   561   // offsets at run-time.
   562   static int clazz_offset;
   563   static int name_offset;
   564   static int type_offset;
   565   static int slot_offset;
   566   static int modifiers_offset;
   567   static int signature_offset;
   568   static int annotations_offset;
   570   static void compute_offsets();
   572  public:
   573   // Allocation
   574   static Handle create(TRAPS);
   576   // Accessors
   577   static oop clazz(oop reflect);
   578   static void set_clazz(oop reflect, oop value);
   580   static oop name(oop field);
   581   static void set_name(oop field, oop value);
   583   static oop type(oop field);
   584   static void set_type(oop field, oop value);
   586   static int slot(oop reflect);
   587   static void set_slot(oop reflect, int value);
   589   static int modifiers(oop field);
   590   static void set_modifiers(oop field, int value);
   592   static bool has_signature_field();
   593   static oop signature(oop constructor);
   594   static void set_signature(oop constructor, oop value);
   596   static bool has_annotations_field();
   597   static oop annotations(oop constructor);
   598   static void set_annotations(oop constructor, oop value);
   600   static bool has_parameter_annotations_field();
   601   static oop parameter_annotations(oop method);
   602   static void set_parameter_annotations(oop method, oop value);
   604   static bool has_annotation_default_field();
   605   static oop annotation_default(oop method);
   606   static void set_annotation_default(oop method, oop value);
   608   // Debugging
   609   friend class JavaClasses;
   610 };
   612 // Interface to sun.reflect.ConstantPool objects
   613 class sun_reflect_ConstantPool {
   614  private:
   615   // Note that to reduce dependencies on the JDK we compute these
   616   // offsets at run-time.
   617   static int _cp_oop_offset;
   619   static void compute_offsets();
   621  public:
   622   // Allocation
   623   static Handle create(TRAPS);
   625   // Accessors
   626   static oop cp_oop(oop reflect);
   627   static void set_cp_oop(oop reflect, oop value);
   628   static int cp_oop_offset() {
   629     return _cp_oop_offset;
   630   }
   632   // Debugging
   633   friend class JavaClasses;
   634 };
   636 // Interface to sun.reflect.UnsafeStaticFieldAccessorImpl objects
   637 class sun_reflect_UnsafeStaticFieldAccessorImpl {
   638  private:
   639   static int _base_offset;
   640   static void compute_offsets();
   642  public:
   643   static int base_offset() {
   644     return _base_offset;
   645   }
   647   // Debugging
   648   friend class JavaClasses;
   649 };
   651 // Interface to java.lang primitive type boxing objects:
   652 //  - java.lang.Boolean
   653 //  - java.lang.Character
   654 //  - java.lang.Float
   655 //  - java.lang.Double
   656 //  - java.lang.Byte
   657 //  - java.lang.Short
   658 //  - java.lang.Integer
   659 //  - java.lang.Long
   661 // This could be separated out into 8 individual classes.
   663 class java_lang_boxing_object: AllStatic {
   664  private:
   665   enum {
   666    hc_value_offset = 0
   667   };
   668   static int value_offset;
   669   static int long_value_offset;
   671   static oop initialize_and_allocate(BasicType type, TRAPS);
   672  public:
   673   // Allocation. Returns a boxed value, or NULL for invalid type.
   674   static oop create(BasicType type, jvalue* value, TRAPS);
   675   // Accessors. Returns the basic type being boxed, or T_ILLEGAL for invalid oop.
   676   static BasicType get_value(oop box, jvalue* value);
   677   static BasicType set_value(oop box, jvalue* value);
   678   static BasicType basic_type(oop box);
   679   static bool is_instance(oop box)                 { return basic_type(box) != T_ILLEGAL; }
   680   static bool is_instance(oop box, BasicType type) { return basic_type(box) == type; }
   681   static void print(oop box, outputStream* st)     { jvalue value;  print(get_value(box, &value), &value, st); }
   682   static void print(BasicType type, jvalue* value, outputStream* st);
   684   static int value_offset_in_bytes(BasicType type) {
   685     return ( type == T_LONG || type == T_DOUBLE ) ? long_value_offset :
   686                                                     value_offset;
   687   }
   689   // Debugging
   690   friend class JavaClasses;
   691 };
   695 // Interface to java.lang.ref.Reference objects
   697 class java_lang_ref_Reference: AllStatic {
   698  public:
   699   enum {
   700    hc_referent_offset   = 0,
   701    hc_queue_offset      = 1,
   702    hc_next_offset       = 2,
   703    hc_discovered_offset = 3  // Is not last, see SoftRefs.
   704   };
   705   enum {
   706    hc_static_lock_offset    = 0,
   707    hc_static_pending_offset = 1
   708   };
   710   static int referent_offset;
   711   static int queue_offset;
   712   static int next_offset;
   713   static int discovered_offset;
   714   static int static_lock_offset;
   715   static int static_pending_offset;
   716   static int number_of_fake_oop_fields;
   718   // Accessors
   719   static oop referent(oop ref) {
   720     return ref->obj_field(referent_offset);
   721   }
   722   static void set_referent(oop ref, oop value) {
   723     ref->obj_field_put(referent_offset, value);
   724   }
   725   static void set_referent_raw(oop ref, oop value) {
   726     ref->obj_field_raw_put(referent_offset, value);
   727   }
   728   static HeapWord* referent_addr(oop ref) {
   729     return ref->obj_field_addr<HeapWord>(referent_offset);
   730   }
   731   static oop next(oop ref) {
   732     return ref->obj_field(next_offset);
   733   }
   734   static void set_next(oop ref, oop value) {
   735     ref->obj_field_put(next_offset, value);
   736   }
   737   static void set_next_raw(oop ref, oop value) {
   738     ref->obj_field_raw_put(next_offset, value);
   739   }
   740   static HeapWord* next_addr(oop ref) {
   741     return ref->obj_field_addr<HeapWord>(next_offset);
   742   }
   743   static oop discovered(oop ref) {
   744     return ref->obj_field(discovered_offset);
   745   }
   746   static void set_discovered(oop ref, oop value) {
   747     ref->obj_field_put(discovered_offset, value);
   748   }
   749   static void set_discovered_raw(oop ref, oop value) {
   750     ref->obj_field_raw_put(discovered_offset, value);
   751   }
   752   static HeapWord* discovered_addr(oop ref) {
   753     return ref->obj_field_addr<HeapWord>(discovered_offset);
   754   }
   755   // Accessors for statics
   756   static oop  pending_list_lock();
   757   static oop  pending_list();
   759   static HeapWord*  pending_list_addr();
   760 };
   763 // Interface to java.lang.ref.SoftReference objects
   765 class java_lang_ref_SoftReference: public java_lang_ref_Reference {
   766  public:
   767   enum {
   768    // The timestamp is a long field and may need to be adjusted for alignment.
   769    hc_timestamp_offset  = hc_discovered_offset + 1
   770   };
   771   enum {
   772    hc_static_clock_offset = 0
   773   };
   775   static int timestamp_offset;
   776   static int static_clock_offset;
   778   // Accessors
   779   static jlong timestamp(oop ref);
   781   // Accessors for statics
   782   static jlong clock();
   783   static void set_clock(jlong value);
   784 };
   787 // Interface to java.dyn.MethodHandle objects
   789 class MethodHandleEntry;
   791 class java_dyn_MethodHandle: AllStatic {
   792   friend class JavaClasses;
   794  private:
   795   static int _vmentry_offset;           // assembly code trampoline for MH
   796   static int _vmtarget_offset;          // class-specific target reference
   797   static int _type_offset;              // the MethodType of this MH
   798   static int _vmslots_offset;           // OPTIONAL hoisted type.form.vmslots
   800   static void compute_offsets();
   802  public:
   803   // Accessors
   804   static oop            type(oop mh);
   805   static void       set_type(oop mh, oop mtype);
   807   static oop            vmtarget(oop mh);
   808   static void       set_vmtarget(oop mh, oop target);
   810   static MethodHandleEntry* vmentry(oop mh);
   811   static void       set_vmentry(oop mh, MethodHandleEntry* data);
   813   static int            vmslots(oop mh);
   814   static void      init_vmslots(oop mh);
   815   static int    compute_vmslots(oop mh);
   817   // Testers
   818   static bool is_subclass(klassOop klass) {
   819     return Klass::cast(klass)->is_subclass_of(SystemDictionary::MethodHandle_klass());
   820   }
   821   static bool is_instance(oop obj) {
   822     return obj != NULL && is_subclass(obj->klass());
   823   }
   825   // Accessors for code generation:
   826   static int type_offset_in_bytes()             { return _type_offset; }
   827   static int vmtarget_offset_in_bytes()         { return _vmtarget_offset; }
   828   static int vmentry_offset_in_bytes()          { return _vmentry_offset; }
   829   static int vmslots_offset_in_bytes()          { return _vmslots_offset; }
   830 };
   832 class sun_dyn_DirectMethodHandle: public java_dyn_MethodHandle {
   833   friend class JavaClasses;
   835  private:
   836   //         _vmtarget_offset;          // method   or class      or interface
   837   static int _vmindex_offset;           // negative or vtable idx or itable idx
   838   static void compute_offsets();
   840  public:
   841   // Accessors
   842   static int            vmindex(oop mh);
   843   static void       set_vmindex(oop mh, int index);
   845   // Testers
   846   static bool is_subclass(klassOop klass) {
   847     return Klass::cast(klass)->is_subclass_of(SystemDictionary::DirectMethodHandle_klass());
   848   }
   849   static bool is_instance(oop obj) {
   850     return obj != NULL && is_subclass(obj->klass());
   851   }
   853   // Accessors for code generation:
   854   static int vmindex_offset_in_bytes()          { return _vmindex_offset; }
   855 };
   857 class sun_dyn_BoundMethodHandle: public java_dyn_MethodHandle {
   858   friend class JavaClasses;
   860  private:
   861   static int _argument_offset;          // argument value bound into this MH
   862   static int _vmargslot_offset;         // relevant argument slot (<= vmslots)
   863   static void compute_offsets();
   865 public:
   866   static oop            argument(oop mh);
   867   static void       set_argument(oop mh, oop ref);
   869   static jint           vmargslot(oop mh);
   870   static void       set_vmargslot(oop mh, jint slot);
   872   // Testers
   873   static bool is_subclass(klassOop klass) {
   874     return Klass::cast(klass)->is_subclass_of(SystemDictionary::BoundMethodHandle_klass());
   875   }
   876   static bool is_instance(oop obj) {
   877     return obj != NULL && is_subclass(obj->klass());
   878   }
   880   static int argument_offset_in_bytes()         { return _argument_offset; }
   881   static int vmargslot_offset_in_bytes()        { return _vmargslot_offset; }
   882 };
   884 class sun_dyn_AdapterMethodHandle: public sun_dyn_BoundMethodHandle {
   885   friend class JavaClasses;
   887  private:
   888   static int _conversion_offset;        // type of conversion to apply
   889   static void compute_offsets();
   891  public:
   892   static int            conversion(oop mh);
   893   static void       set_conversion(oop mh, int conv);
   895   // Testers
   896   static bool is_subclass(klassOop klass) {
   897     return Klass::cast(klass)->is_subclass_of(SystemDictionary::AdapterMethodHandle_klass());
   898   }
   899   static bool is_instance(oop obj) {
   900     return obj != NULL && is_subclass(obj->klass());
   901   }
   903   // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):
   904   enum {
   905     OP_RETYPE_ONLY   = 0x0, // no argument changes; straight retype
   906     OP_RETYPE_RAW    = 0x1, // straight retype, trusted (void->int, Object->T)
   907     OP_CHECK_CAST    = 0x2, // ref-to-ref conversion; requires a Class argument
   908     OP_PRIM_TO_PRIM  = 0x3, // converts from one primitive to another
   909     OP_REF_TO_PRIM   = 0x4, // unboxes a wrapper to produce a primitive
   910     OP_PRIM_TO_REF   = 0x5, // boxes a primitive into a wrapper (NYI)
   911     OP_SWAP_ARGS     = 0x6, // swap arguments (vminfo is 2nd arg)
   912     OP_ROT_ARGS      = 0x7, // rotate arguments (vminfo is displaced arg)
   913     OP_DUP_ARGS      = 0x8, // duplicates one or more arguments (at TOS)
   914     OP_DROP_ARGS     = 0x9, // remove one or more argument slots
   915     OP_COLLECT_ARGS  = 0xA, // combine one or more arguments into a varargs (NYI)
   916     OP_SPREAD_ARGS   = 0xB, // expand in place a varargs array (of known size)
   917     OP_FLYBY         = 0xC, // operate first on reified argument list (NYI)
   918     OP_RICOCHET      = 0xD, // run an adapter chain on the return value (NYI)
   919     CONV_OP_LIMIT    = 0xE, // limit of CONV_OP enumeration
   921     CONV_OP_MASK     = 0xF00, // this nybble contains the conversion op field
   922     CONV_VMINFO_MASK = 0x0FF, // LSB is reserved for JVM use
   923     CONV_VMINFO_SHIFT     =  0, // position of bits in CONV_VMINFO_MASK
   924     CONV_OP_SHIFT         =  8, // position of bits in CONV_OP_MASK
   925     CONV_DEST_TYPE_SHIFT  = 12, // byte 2 has the adapter BasicType (if needed)
   926     CONV_SRC_TYPE_SHIFT   = 16, // byte 2 has the source BasicType (if needed)
   927     CONV_STACK_MOVE_SHIFT = 20, // high 12 bits give signed SP change
   928     CONV_STACK_MOVE_MASK  = (1 << (32 - CONV_STACK_MOVE_SHIFT)) - 1
   929   };
   931   static int conversion_offset_in_bytes()       { return _conversion_offset; }
   932 };
   935 // Interface to sun.dyn.MemberName objects
   936 // (These are a private interface for Java code to query the class hierarchy.)
   938 class sun_dyn_MemberName: AllStatic {
   939   friend class JavaClasses;
   941  private:
   942   // From java.dyn.MemberName:
   943   //    private Class<?>   clazz;       // class in which the method is defined
   944   //    private String     name;        // may be null if not yet materialized
   945   //    private Object     type;        // may be null if not yet materialized
   946   //    private int        flags;       // modifier bits; see reflect.Modifier
   947   //    private Object     vmtarget;    // VM-specific target value
   948   //    private int        vmindex;     // method index within class or interface
   949   static int _clazz_offset;
   950   static int _name_offset;
   951   static int _type_offset;
   952   static int _flags_offset;
   953   static int _vmtarget_offset;
   954   static int _vmindex_offset;
   956   static void compute_offsets();
   958  public:
   959   // Accessors
   960   static oop            clazz(oop mname);
   961   static void       set_clazz(oop mname, oop clazz);
   963   static oop            type(oop mname);
   964   static void       set_type(oop mname, oop type);
   966   static oop            name(oop mname);
   967   static void       set_name(oop mname, oop name);
   969   static int            flags(oop mname);
   970   static void       set_flags(oop mname, int flags);
   972   static int            modifiers(oop mname) { return (u2) flags(mname); }
   973   static void       set_modifiers(oop mname, int mods)
   974                                 { set_flags(mname, (flags(mname) &~ (u2)-1) | (u2)mods); }
   976   static oop            vmtarget(oop mname);
   977   static void       set_vmtarget(oop mname, oop target);
   979   static int            vmindex(oop mname);
   980   static void       set_vmindex(oop mname, int index);
   982   // Testers
   983   static bool is_subclass(klassOop klass) {
   984     return Klass::cast(klass)->is_subclass_of(SystemDictionary::MemberName_klass());
   985   }
   986   static bool is_instance(oop obj) {
   987     return obj != NULL && is_subclass(obj->klass());
   988   }
   990   // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):
   991   enum {
   992     MN_IS_METHOD           = 0x00010000, // method (not constructor)
   993     MN_IS_CONSTRUCTOR      = 0x00020000, // constructor
   994     MN_IS_FIELD            = 0x00040000, // field
   995     MN_IS_TYPE             = 0x00080000, // nested type
   996     MN_SEARCH_SUPERCLASSES = 0x00100000, // for MHN.getMembers
   997     MN_SEARCH_INTERFACES   = 0x00200000, // for MHN.getMembers
   998     VM_INDEX_UNINITIALIZED = -99
   999   };
  1001   // Accessors for code generation:
  1002   static int clazz_offset_in_bytes()            { return _clazz_offset; }
  1003   static int type_offset_in_bytes()             { return _type_offset; }
  1004   static int name_offset_in_bytes()             { return _name_offset; }
  1005   static int flags_offset_in_bytes()            { return _flags_offset; }
  1006   static int vmtarget_offset_in_bytes()         { return _vmtarget_offset; }
  1007   static int vmindex_offset_in_bytes()          { return _vmindex_offset; }
  1008 };
  1011 // Interface to java.dyn.MethodType objects
  1013 class java_dyn_MethodType: AllStatic {
  1014   friend class JavaClasses;
  1016  private:
  1017   static int _rtype_offset;
  1018   static int _ptypes_offset;
  1019   static int _form_offset;
  1021   static void compute_offsets();
  1023  public:
  1024   // Accessors
  1025   static oop            rtype(oop mt);
  1026   static objArrayOop    ptypes(oop mt);
  1027   static oop            form(oop mt);
  1029   static oop            ptype(oop mt, int index);
  1030   static int            ptype_count(oop mt);
  1032   static symbolOop      as_signature(oop mt, bool intern_if_not_found, TRAPS);
  1033   static void           print_signature(oop mt, outputStream* st);
  1035   static bool is_instance(oop obj) {
  1036     return obj != NULL && obj->klass() == SystemDictionary::MethodType_klass();
  1039   // Accessors for code generation:
  1040   static int rtype_offset_in_bytes()            { return _rtype_offset; }
  1041   static int ptypes_offset_in_bytes()           { return _ptypes_offset; }
  1042   static int form_offset_in_bytes()             { return _form_offset; }
  1043 };
  1045 class java_dyn_MethodTypeForm: AllStatic {
  1046   friend class JavaClasses;
  1048  private:
  1049   static int _vmslots_offset;           // number of argument slots needed
  1050   static int _erasedType_offset;        // erasedType = canonical MethodType
  1051   static int _genericInvoker_offset;    // genericInvoker = adapter for invokeGeneric
  1053   static void compute_offsets();
  1055  public:
  1056   // Accessors
  1057   static int            vmslots(oop mtform);
  1058   static oop            erasedType(oop mtform);
  1059   static oop            genericInvoker(oop mtform);
  1061   // Accessors for code generation:
  1062   static int vmslots_offset_in_bytes()          { return _vmslots_offset; }
  1063   static int erasedType_offset_in_bytes()       { return _erasedType_offset; }
  1064   static int genericInvoker_offset_in_bytes()   { return _genericInvoker_offset; }
  1065 };
  1068 // Interface to java.dyn.CallSite objects
  1070 class java_dyn_CallSite: AllStatic {
  1071   friend class JavaClasses;
  1073 private:
  1074   static int _target_offset;
  1075   static int _caller_method_offset;
  1076   static int _caller_bci_offset;
  1078   static void compute_offsets();
  1080 public:
  1081   // Accessors
  1082   static oop            target(oop site);
  1083   static void       set_target(oop site, oop target);
  1085   static oop            caller_method(oop site);
  1086   static void       set_caller_method(oop site, oop ref);
  1088   static jint           caller_bci(oop site);
  1089   static void       set_caller_bci(oop site, jint bci);
  1091   // Testers
  1092   static bool is_subclass(klassOop klass) {
  1093     return Klass::cast(klass)->is_subclass_of(SystemDictionary::CallSite_klass());
  1095   static bool is_instance(oop obj) {
  1096     return obj != NULL && is_subclass(obj->klass());
  1099   // Accessors for code generation:
  1100   static int target_offset_in_bytes()           { return _target_offset; }
  1101   static int caller_method_offset_in_bytes()    { return _caller_method_offset; }
  1102   static int caller_bci_offset_in_bytes()       { return _caller_bci_offset; }
  1103 };
  1106 // Interface to java.security.AccessControlContext objects
  1108 class java_security_AccessControlContext: AllStatic {
  1109  private:
  1110   // Note that for this class the layout changed between JDK1.2 and JDK1.3,
  1111   // so we compute the offsets at startup rather than hard-wiring them.
  1112   static int _context_offset;
  1113   static int _privilegedContext_offset;
  1114   static int _isPrivileged_offset;
  1116   static void compute_offsets();
  1117  public:
  1118   static oop create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS);
  1120   // Debugging/initialization
  1121   friend class JavaClasses;
  1122 };
  1125 // Interface to java.lang.ClassLoader objects
  1127 class java_lang_ClassLoader : AllStatic {
  1128  private:
  1129   enum {
  1130    hc_parent_offset = 0
  1131   };
  1133   static int parent_offset;
  1135  public:
  1136   static oop parent(oop loader);
  1138   static bool is_trusted_loader(oop loader);
  1140   // Fix for 4474172
  1141   static oop  non_reflection_class_loader(oop loader);
  1143   // Debugging
  1144   friend class JavaClasses;
  1145 };
  1148 // Interface to java.lang.System objects
  1150 class java_lang_System : AllStatic {
  1151  private:
  1152   enum {
  1153    hc_static_in_offset  = 0,
  1154    hc_static_out_offset = 1,
  1155    hc_static_err_offset = 2
  1156   };
  1158   static int offset_of_static_fields;
  1159   static int  static_in_offset;
  1160   static int static_out_offset;
  1161   static int static_err_offset;
  1163   static void compute_offsets();
  1165  public:
  1166   static int  in_offset_in_bytes();
  1167   static int out_offset_in_bytes();
  1168   static int err_offset_in_bytes();
  1170   // Debugging
  1171   friend class JavaClasses;
  1172 };
  1175 // Interface to java.lang.StackTraceElement objects
  1177 class java_lang_StackTraceElement: AllStatic {
  1178  private:
  1179   enum {
  1180     hc_declaringClass_offset  = 0,
  1181     hc_methodName_offset = 1,
  1182     hc_fileName_offset   = 2,
  1183     hc_lineNumber_offset = 3
  1184   };
  1186   static int declaringClass_offset;
  1187   static int methodName_offset;
  1188   static int fileName_offset;
  1189   static int lineNumber_offset;
  1191  public:
  1192   // Setters
  1193   static void set_declaringClass(oop element, oop value);
  1194   static void set_methodName(oop element, oop value);
  1195   static void set_fileName(oop element, oop value);
  1196   static void set_lineNumber(oop element, int value);
  1198   // Create an instance of StackTraceElement
  1199   static oop create(methodHandle m, int bci, TRAPS);
  1201   // Debugging
  1202   friend class JavaClasses;
  1203 };
  1206 // Interface to java.lang.AssertionStatusDirectives objects
  1208 class java_lang_AssertionStatusDirectives: AllStatic {
  1209  private:
  1210   enum {
  1211     hc_classes_offset,
  1212     hc_classEnabled_offset,
  1213     hc_packages_offset,
  1214     hc_packageEnabled_offset,
  1215     hc_deflt_offset
  1216   };
  1218   static int classes_offset;
  1219   static int classEnabled_offset;
  1220   static int packages_offset;
  1221   static int packageEnabled_offset;
  1222   static int deflt_offset;
  1224  public:
  1225   // Setters
  1226   static void set_classes(oop obj, oop val);
  1227   static void set_classEnabled(oop obj, oop val);
  1228   static void set_packages(oop obj, oop val);
  1229   static void set_packageEnabled(oop obj, oop val);
  1230   static void set_deflt(oop obj, bool val);
  1231   // Debugging
  1232   friend class JavaClasses;
  1233 };
  1236 class java_nio_Buffer: AllStatic {
  1237  private:
  1238   static int _limit_offset;
  1240  public:
  1241   static int  limit_offset();
  1242   static void compute_offsets();
  1243 };
  1245 class sun_misc_AtomicLongCSImpl: AllStatic {
  1246  private:
  1247   static int _value_offset;
  1249  public:
  1250   static int  value_offset();
  1251   static void compute_offsets();
  1252 };
  1254 class java_util_concurrent_locks_AbstractOwnableSynchronizer : AllStatic {
  1255  private:
  1256   static int  _owner_offset;
  1257  public:
  1258   static void initialize(TRAPS);
  1259   static oop  get_owner_threadObj(oop obj);
  1260 };
  1262 // Interface to hard-coded offset checking
  1264 class JavaClasses : AllStatic {
  1265  private:
  1266   static bool check_offset(const char *klass_name, int offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
  1267   static bool check_static_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
  1268   static bool check_constant(const char *klass_name, int constant, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
  1269  public:
  1270   static void compute_hard_coded_offsets();
  1271   static void compute_offsets();
  1272   static void check_offsets() PRODUCT_RETURN;
  1273 };

mercurial