< prev index next >

src/hotspot/share/runtime/handles.hpp

Print this page

 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_RUNTIME_HANDLES_HPP
 26 #define SHARE_RUNTIME_HANDLES_HPP
 27 
 28 #include "memory/arena.hpp"
 29 #include "oops/oop.hpp"
 30 #include "oops/oopsHierarchy.hpp"
 31 

 32 class InstanceKlass;
 33 class Klass;
 34 class Thread;
 35 
 36 //------------------------------------------------------------------------------------------------------------------------
 37 // In order to preserve oops during garbage collection, they should be
 38 // allocated and passed around via Handles within the VM. A handle is
 39 // simply an extra indirection allocated in a thread local handle area.
 40 //
 41 // A handle is a value object, so it can be passed around as a value, can
 42 // be used as a parameter w/o using &-passing, and can be returned as a
 43 // return value.
 44 //
 45 // oop parameters and return types should be Handles whenever feasible.
 46 //
 47 // Handles are declared in a straight-forward manner, e.g.
 48 //
 49 //   oop obj = ...;
 50 //   Handle h2(thread, obj);      // allocate a new handle in thread
 51 //   Handle h3;                   // declare handle only, no allocation occurs

107   class type##Handle: public Handle {            \
108    protected:                                    \
109     type##Oop    obj() const                     { return (type##Oop)Handle::obj(); } \
110     type##Oop    non_null_obj() const            { return (type##Oop)Handle::non_null_obj(); } \
111                                                  \
112    public:                                       \
113     /* Constructors */                           \
114     type##Handle ()                              : Handle()                 {} \
115     inline type##Handle (Thread* thread, type##Oop obj); \
116     \
117     /* Operators for ease of use */              \
118     type##Oop    operator () () const            { return obj(); } \
119     type##Oop    operator -> () const            { return non_null_obj(); } \
120   };
121 
122 
123 DEF_HANDLE(instance         , is_instance_noinline         )
124 DEF_HANDLE(array            , is_array_noinline            )
125 DEF_HANDLE(objArray         , is_objArray_noinline         )
126 DEF_HANDLE(typeArray        , is_typeArray_noinline        )

127 
128 //------------------------------------------------------------------------------------------------------------------------
129 
130 // Metadata Handles.  Unlike oop Handles these are needed to prevent metadata
131 // from being reclaimed by RedefineClasses.
132 // Metadata Handles should be passed around as const references to avoid copy construction
133 // and destruction for parameters.
134 
135 // Specific Handles for different oop types
136 #define DEF_METADATA_HANDLE(name, type)          \
137   class name##Handle;                            \
138   class name##Handle : public StackObj {         \
139     type*     _value;                            \
140     Thread*   _thread;                           \
141    protected:                                    \
142     type*        obj() const                     { return _value; } \
143     type*        non_null_obj() const            { assert(_value != NULL, "resolving NULL _value"); return _value; } \
144                                                  \
145    public:                                       \
146     /* Constructors */                           \

 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_RUNTIME_HANDLES_HPP
 26 #define SHARE_RUNTIME_HANDLES_HPP
 27 
 28 #include "memory/arena.hpp"
 29 #include "oops/oop.hpp"
 30 #include "oops/oopsHierarchy.hpp"
 31 
 32 class InlineKlass;
 33 class InstanceKlass;
 34 class Klass;
 35 class Thread;
 36 
 37 //------------------------------------------------------------------------------------------------------------------------
 38 // In order to preserve oops during garbage collection, they should be
 39 // allocated and passed around via Handles within the VM. A handle is
 40 // simply an extra indirection allocated in a thread local handle area.
 41 //
 42 // A handle is a value object, so it can be passed around as a value, can
 43 // be used as a parameter w/o using &-passing, and can be returned as a
 44 // return value.
 45 //
 46 // oop parameters and return types should be Handles whenever feasible.
 47 //
 48 // Handles are declared in a straight-forward manner, e.g.
 49 //
 50 //   oop obj = ...;
 51 //   Handle h2(thread, obj);      // allocate a new handle in thread
 52 //   Handle h3;                   // declare handle only, no allocation occurs

108   class type##Handle: public Handle {            \
109    protected:                                    \
110     type##Oop    obj() const                     { return (type##Oop)Handle::obj(); } \
111     type##Oop    non_null_obj() const            { return (type##Oop)Handle::non_null_obj(); } \
112                                                  \
113    public:                                       \
114     /* Constructors */                           \
115     type##Handle ()                              : Handle()                 {} \
116     inline type##Handle (Thread* thread, type##Oop obj); \
117     \
118     /* Operators for ease of use */              \
119     type##Oop    operator () () const            { return obj(); } \
120     type##Oop    operator -> () const            { return non_null_obj(); } \
121   };
122 
123 
124 DEF_HANDLE(instance         , is_instance_noinline         )
125 DEF_HANDLE(array            , is_array_noinline            )
126 DEF_HANDLE(objArray         , is_objArray_noinline         )
127 DEF_HANDLE(typeArray        , is_typeArray_noinline        )
128 DEF_HANDLE(flatArray        , is_flatArray_noinline        )
129 
130 //------------------------------------------------------------------------------------------------------------------------
131 
132 // Metadata Handles.  Unlike oop Handles these are needed to prevent metadata
133 // from being reclaimed by RedefineClasses.
134 // Metadata Handles should be passed around as const references to avoid copy construction
135 // and destruction for parameters.
136 
137 // Specific Handles for different oop types
138 #define DEF_METADATA_HANDLE(name, type)          \
139   class name##Handle;                            \
140   class name##Handle : public StackObj {         \
141     type*     _value;                            \
142     Thread*   _thread;                           \
143    protected:                                    \
144     type*        obj() const                     { return _value; } \
145     type*        non_null_obj() const            { assert(_value != NULL, "resolving NULL _value"); return _value; } \
146                                                  \
147    public:                                       \
148     /* Constructors */                           \
< prev index next >