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