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 */
24
25 #ifndef SHARE_VM_RUNTIME_HANDLES_HPP
26 #define SHARE_VM_RUNTIME_HANDLES_HPP
27
28 #include "oops/oop.hpp"
29 #include "oops/oopsHierarchy.hpp"
30
31 class InstanceKlass;
32 class Klass;
33
34 //------------------------------------------------------------------------------------------------------------------------
35 // In order to preserve oops during garbage collection, they should be
36 // allocated and passed around via Handles within the VM. A handle is
37 // simply an extra indirection allocated in a thread local handle area.
38 //
39 // A handle is a ValueObj, so it can be passed around as a value, can
40 // be used as a parameter w/o using &-passing, and can be returned as a
41 // return value.
42 //
43 // oop parameters and return types should be Handles whenever feasible.
44 //
45 // Handles are declared in a straight-forward manner, e.g.
46 //
47 // oop obj = ...;
65 // Base class for all handles. Provides overloading of frequently
66 // used operators for ease of use.
67
68 class Handle VALUE_OBJ_CLASS_SPEC {
69 private:
70 oop* _handle;
71
72 protected:
73 oop obj() const { return _handle == NULL ? (oop)NULL : *_handle; }
74 oop non_null_obj() const { assert(_handle != NULL, "resolving NULL handle"); return *_handle; }
75
76 public:
77 // Constructors
78 Handle() { _handle = NULL; }
79 Handle(oop obj);
80 Handle(Thread* thread, oop obj);
81
82 // General access
83 oop operator () () const { return obj(); }
84 oop operator -> () const { return non_null_obj(); }
85 bool operator == (oop o) const { return obj() == o; }
86 bool operator == (const Handle& h) const { return obj() == h.obj(); }
87
88 // Null checks
89 bool is_null() const { return _handle == NULL; }
90 bool not_null() const { return _handle != NULL; }
91
92 // Debugging
93 void print() { obj()->print(); }
94
95 // Direct interface, use very sparingly.
96 // Used by JavaCalls to quickly convert handles and to create handles static data structures.
97 // Constructor takes a dummy argument to prevent unintentional type conversion in C++.
98 Handle(oop *handle, bool dummy) { _handle = handle; }
99
100 // Raw handle access. Allows easy duplication of Handles. This can be very unsafe
101 // since duplicates is only valid as long as original handle is alive.
102 oop* raw_value() { return _handle; }
103 static oop raw_resolve(oop *handle) { return handle == NULL ? (oop)NULL : *handle; }
104 };
105
106 // Specific Handles for different oop types
|
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 */
24
25 #ifndef SHARE_VM_RUNTIME_HANDLES_HPP
26 #define SHARE_VM_RUNTIME_HANDLES_HPP
27
28 #include "gc/shared/barrierSet.hpp"
29 #include "oops/oop.hpp"
30 #include "oops/oopsHierarchy.hpp"
31
32 class InstanceKlass;
33 class Klass;
34
35 //------------------------------------------------------------------------------------------------------------------------
36 // In order to preserve oops during garbage collection, they should be
37 // allocated and passed around via Handles within the VM. A handle is
38 // simply an extra indirection allocated in a thread local handle area.
39 //
40 // A handle is a ValueObj, so it can be passed around as a value, can
41 // be used as a parameter w/o using &-passing, and can be returned as a
42 // return value.
43 //
44 // oop parameters and return types should be Handles whenever feasible.
45 //
46 // Handles are declared in a straight-forward manner, e.g.
47 //
48 // oop obj = ...;
66 // Base class for all handles. Provides overloading of frequently
67 // used operators for ease of use.
68
69 class Handle VALUE_OBJ_CLASS_SPEC {
70 private:
71 oop* _handle;
72
73 protected:
74 oop obj() const { return _handle == NULL ? (oop)NULL : *_handle; }
75 oop non_null_obj() const { assert(_handle != NULL, "resolving NULL handle"); return *_handle; }
76
77 public:
78 // Constructors
79 Handle() { _handle = NULL; }
80 Handle(oop obj);
81 Handle(Thread* thread, oop obj);
82
83 // General access
84 oop operator () () const { return obj(); }
85 oop operator -> () const { return non_null_obj(); }
86 bool operator == (oop o) const { return oopDesc::bs()->resolve_and_maybe_copy_oop(obj()) == oopDesc::bs()->resolve_and_maybe_copy_oop(o); }
87 bool operator == (const Handle& h) const { return oopDesc::bs()->resolve_and_maybe_copy_oop(obj()) == oopDesc::bs()->resolve_and_maybe_copy_oop(h.obj()); }
88
89 // Null checks
90 bool is_null() const { return _handle == NULL; }
91 bool not_null() const { return _handle != NULL; }
92
93 // Debugging
94 void print() { obj()->print(); }
95
96 // Direct interface, use very sparingly.
97 // Used by JavaCalls to quickly convert handles and to create handles static data structures.
98 // Constructor takes a dummy argument to prevent unintentional type conversion in C++.
99 Handle(oop *handle, bool dummy) { _handle = handle; }
100
101 // Raw handle access. Allows easy duplication of Handles. This can be very unsafe
102 // since duplicates is only valid as long as original handle is alive.
103 oop* raw_value() { return _handle; }
104 static oop raw_resolve(oop *handle) { return handle == NULL ? (oop)NULL : *handle; }
105 };
106
107 // Specific Handles for different oop types
|