src/share/vm/ci/ciObject.hpp

Tue, 24 Jul 2012 10:51:00 -0700

author
twisti
date
Tue, 24 Jul 2012 10:51:00 -0700
changeset 3969
1d7922586cf6
parent 2933
28a9fe9534ea
child 4037
da91efe96a93
permissions
-rw-r--r--

7023639: JSR 292 method handle invocation needs a fast path for compiled code
6984705: JSR 292 method handle creation should not go through JNI
Summary: remove assembly code for JDK 7 chained method handles
Reviewed-by: jrose, twisti, kvn, mhaupt
Contributed-by: John Rose <john.r.rose@oracle.com>, Christian Thalinger <christian.thalinger@oracle.com>, Michael Haupt <michael.haupt@oracle.com>

     1 /*
     2  * Copyright (c) 1999, 2011, 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 #ifndef SHARE_VM_CI_CIOBJECT_HPP
    26 #define SHARE_VM_CI_CIOBJECT_HPP
    28 #include "ci/ciClassList.hpp"
    29 #include "memory/allocation.hpp"
    30 #include "runtime/handles.hpp"
    31 #include "runtime/jniHandles.hpp"
    33 // ciObject
    34 //
    35 // This class represents an oop in the HotSpot virtual machine.
    36 // Its subclasses are structured in a hierarchy which mirrors
    37 // an aggregate of the VM's oop and klass hierarchies (see
    38 // oopHierarchy.hpp).  Each instance of ciObject holds a handle
    39 // to a corresponding oop on the VM side and provides routines
    40 // for accessing the information in its oop.  By using the ciObject
    41 // hierarchy for accessing oops in the VM, the compiler ensures
    42 // that it is safe with respect to garbage collection; that is,
    43 // GC and compilation can proceed independently without
    44 // interference.
    45 //
    46 // Within the VM, the oop and klass hierarchies are separate.
    47 // The compiler interface does not preserve this separation --
    48 // the distinction between `klassOop' and `Klass' are not
    49 // reflected in the interface and instead the Klass hierarchy
    50 // is directly modeled as the subclasses of ciKlass.
    51 class ciObject : public ResourceObj {
    52   CI_PACKAGE_ACCESS
    53   friend class ciEnv;
    55 private:
    56   // A JNI handle referring to an oop in the VM.  This
    57   // handle may, in a small set of cases, correctly be NULL.
    58   jobject  _handle;
    59   ciKlass* _klass;
    60   uint     _ident;
    62   enum { FLAG_BITS   = 2 };
    63   enum {
    64          PERM_FLAG        = 1,
    65          SCAVENGABLE_FLAG = 2
    66        };
    67 protected:
    68   ciObject();
    69   ciObject(oop o);
    70   ciObject(Handle h);
    71   ciObject(ciKlass* klass);
    73   jobject      handle()  const { return _handle; }
    74   // Get the VM oop that this object holds.
    75   oop get_oop() const {
    76     assert(_handle != NULL, "null oop");
    77     return JNIHandles::resolve_non_null(_handle);
    78   }
    80   void init_flags_from(oop x) {
    81     int flags = 0;
    82     if (x != NULL) {
    83       if (x->is_perm())
    84         flags |= PERM_FLAG;
    85       if (x->is_scavengable())
    86         flags |= SCAVENGABLE_FLAG;
    87     }
    88     _ident |= flags;
    89   }
    91   // Virtual behavior of the print() method.
    92   virtual void print_impl(outputStream* st) {}
    94   virtual const char* type_string() { return "ciObject"; }
    96   void set_ident(uint id);
    97 public:
    98   // The klass of this ciObject.
    99   ciKlass* klass();
   101   // A number unique to this object.
   102   uint ident();
   104   // Are two ciObjects equal?
   105   bool equals(ciObject* obj);
   107   // A hash value for the convenience of compilers.
   108   int hash();
   110   // Tells if this oop has an encoding as a constant.
   111   // True if is_perm is true.
   112   // Also true if ScavengeRootsInCode is non-zero.
   113   // If it does not have an encoding, the compiler is responsible for
   114   // making other arrangements for dealing with the oop.
   115   // See ciEnv::make_array
   116   bool can_be_constant();
   118   // Tells if this oop should be made a constant.
   119   // True if is_perm is true or ScavengeRootsInCode > 1.
   120   bool should_be_constant();
   122   // Is this object guaranteed to be in the permanent part of the heap?
   123   // If so, CollectedHeap::can_elide_permanent_oop_store_barriers is relevant.
   124   // If the answer is false, no guarantees are made.
   125   bool is_perm() { return (_ident & PERM_FLAG) != 0; }
   127   // Might this object possibly move during a scavenge operation?
   128   // If the answer is true and ScavengeRootsInCode==0, the oop cannot be embedded in code.
   129   bool is_scavengable() { return (_ident & SCAVENGABLE_FLAG) != 0; }
   131   // The address which the compiler should embed into the
   132   // generated code to represent this oop.  This address
   133   // is not the true address of the oop -- it will get patched
   134   // during nmethod creation.
   135   //
   136   // Usage note: no address arithmetic allowed.  Oop must
   137   // be registered with the oopRecorder.
   138   jobject constant_encoding();
   140   // What kind of ciObject is this?
   141   virtual bool is_null_object()       const { return false; }
   142   virtual bool is_call_site()         const { return false; }
   143   virtual bool is_cpcache()           const { return false; }
   144   virtual bool is_instance()                { return false; }
   145   virtual bool is_member_name()       const { return false; }
   146   virtual bool is_method()                  { return false; }
   147   virtual bool is_method_data()             { return false; }
   148   virtual bool is_method_handle()     const { return false; }
   149   virtual bool is_array()                   { return false; }
   150   virtual bool is_obj_array()               { return false; }
   151   virtual bool is_type_array()              { return false; }
   152   virtual bool is_symbol()                  { return false; }
   153   virtual bool is_type()                    { return false; }
   154   virtual bool is_return_address()          { return false; }
   155   virtual bool is_klass()                   { return false; }
   156   virtual bool is_instance_klass()          { return false; }
   157   virtual bool is_method_klass()            { return false; }
   158   virtual bool is_array_klass()             { return false; }
   159   virtual bool is_obj_array_klass()         { return false; }
   160   virtual bool is_type_array_klass()        { return false; }
   161   virtual bool is_symbol_klass()            { return false; }
   162   virtual bool is_klass_klass()             { return false; }
   163   virtual bool is_instance_klass_klass()    { return false; }
   164   virtual bool is_array_klass_klass()       { return false; }
   165   virtual bool is_obj_array_klass_klass()   { return false; }
   166   virtual bool is_type_array_klass_klass()  { return false; }
   168   // Is this a type or value which has no associated class?
   169   // It is true of primitive types and null objects.
   170   virtual bool is_classless() const         { return false; }
   172   // Is this ciObject a Java Language Object?  That is,
   173   // is the ciObject an instance or an array
   174   virtual bool is_java_object()             { return false; }
   176   // Does this ciObject represent a Java Language class?
   177   // That is, is the ciObject an instanceKlass or arrayKlass?
   178   virtual bool is_java_klass()              { return false; }
   180   // Is this ciObject the ciInstanceKlass representing
   181   // java.lang.Object()?
   182   virtual bool is_java_lang_Object()        { return false; }
   184   // Does this ciObject refer to a real oop in the VM?
   185   //
   186   // Note: some ciObjects refer to oops which have yet to be
   187   // created.  We refer to these as "unloaded".  Specifically,
   188   // there are unloaded ciMethods, ciObjArrayKlasses, and
   189   // ciInstanceKlasses.  By convention the ciNullObject is
   190   // considered loaded, and primitive types are considered loaded.
   191   bool is_loaded() const {
   192     return handle() != NULL || is_classless();
   193   }
   195   // Subclass casting with assertions.
   196   ciNullObject*            as_null_object() {
   197     assert(is_null_object(), "bad cast");
   198     return (ciNullObject*)this;
   199   }
   200   ciCallSite*              as_call_site() {
   201     assert(is_call_site(), "bad cast");
   202     return (ciCallSite*) this;
   203   }
   204   ciCPCache*               as_cpcache() {
   205     assert(is_cpcache(), "bad cast");
   206     return (ciCPCache*) this;
   207   }
   208   ciInstance*              as_instance() {
   209     assert(is_instance(), "bad cast");
   210     return (ciInstance*)this;
   211   }
   212   ciMemberName*            as_member_name() {
   213     assert(is_member_name(), "bad cast");
   214     return (ciMemberName*)this;
   215   }
   216   ciMethod*                as_method() {
   217     assert(is_method(), "bad cast");
   218     return (ciMethod*)this;
   219   }
   220   ciMethodData*            as_method_data() {
   221     assert(is_method_data(), "bad cast");
   222     return (ciMethodData*)this;
   223   }
   224   ciMethodHandle*          as_method_handle() {
   225     assert(is_method_handle(), "bad cast");
   226     return (ciMethodHandle*) this;
   227   }
   228   ciArray*                 as_array() {
   229     assert(is_array(), "bad cast");
   230     return (ciArray*)this;
   231   }
   232   ciObjArray*              as_obj_array() {
   233     assert(is_obj_array(), "bad cast");
   234     return (ciObjArray*)this;
   235   }
   236   ciTypeArray*             as_type_array() {
   237     assert(is_type_array(), "bad cast");
   238     return (ciTypeArray*)this;
   239   }
   240   ciSymbol*                as_symbol() {
   241     assert(is_symbol(), "bad cast");
   242     return (ciSymbol*)this;
   243   }
   244   ciType*                  as_type() {
   245     assert(is_type(), "bad cast");
   246     return (ciType*)this;
   247   }
   248   ciReturnAddress*         as_return_address() {
   249     assert(is_return_address(), "bad cast");
   250     return (ciReturnAddress*)this;
   251   }
   252   ciKlass*                 as_klass() {
   253     assert(is_klass(), "bad cast");
   254     return (ciKlass*)this;
   255   }
   256   ciInstanceKlass*         as_instance_klass() {
   257     assert(is_instance_klass(), "bad cast");
   258     return (ciInstanceKlass*)this;
   259   }
   260   ciMethodKlass*           as_method_klass() {
   261     assert(is_method_klass(), "bad cast");
   262     return (ciMethodKlass*)this;
   263   }
   264   ciArrayKlass*            as_array_klass() {
   265     assert(is_array_klass(), "bad cast");
   266     return (ciArrayKlass*)this;
   267   }
   268   ciObjArrayKlass*         as_obj_array_klass() {
   269     assert(is_obj_array_klass(), "bad cast");
   270     return (ciObjArrayKlass*)this;
   271   }
   272   ciTypeArrayKlass*        as_type_array_klass() {
   273     assert(is_type_array_klass(), "bad cast");
   274     return (ciTypeArrayKlass*)this;
   275   }
   276   ciKlassKlass*            as_klass_klass() {
   277     assert(is_klass_klass(), "bad cast");
   278     return (ciKlassKlass*)this;
   279   }
   280   ciInstanceKlassKlass*    as_instance_klass_klass() {
   281     assert(is_instance_klass_klass(), "bad cast");
   282     return (ciInstanceKlassKlass*)this;
   283   }
   284   ciArrayKlassKlass*       as_array_klass_klass() {
   285     assert(is_array_klass_klass(), "bad cast");
   286     return (ciArrayKlassKlass*)this;
   287   }
   288   ciObjArrayKlassKlass*    as_obj_array_klass_klass() {
   289     assert(is_obj_array_klass_klass(), "bad cast");
   290     return (ciObjArrayKlassKlass*)this;
   291   }
   292   ciTypeArrayKlassKlass*   as_type_array_klass_klass() {
   293     assert(is_type_array_klass_klass(), "bad cast");
   294     return (ciTypeArrayKlassKlass*)this;
   295   }
   297   // Print debugging output about this ciObject.
   298   void print(outputStream* st);
   299   void print() { print(tty); }  // GDB cannot handle default arguments
   301   // Print debugging output about the oop this ciObject represents.
   302   void print_oop(outputStream* st = tty);
   303 };
   305 #endif // SHARE_VM_CI_CIOBJECT_HPP

mercurial