< 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

111     type##Oop    obj() const                     { return (type##Oop)Handle::obj(); } \
112     type##Oop    non_null_obj() const            { return (type##Oop)Handle::non_null_obj(); } \
113                                                  \
114    public:                                       \
115     /* Constructors */                           \
116     type##Handle ()                              : Handle() {} \
117     inline type##Handle (Thread* thread, type##Oop obj); \
118     type##Handle (oop *handle, bool dummy)       : Handle(handle, dummy) {} \
119                                                  \
120     /* Operators for ease of use */              \
121     type##Oop    operator () () const            { return obj(); } \
122     type##Oop    operator -> () const            { return non_null_obj(); } \
123   };
124 
125 
126 DEF_HANDLE(instance         , is_instance_noinline         )
127 DEF_HANDLE(stackChunk       , is_stackChunk_noinline       )
128 DEF_HANDLE(array            , is_array_noinline            )
129 DEF_HANDLE(objArray         , is_objArray_noinline         )
130 DEF_HANDLE(typeArray        , is_typeArray_noinline        )

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

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