55 //
56 // Handles are specialized for different oop types to provide extra type
57 // information and avoid unnecessary casting. For each oop type xxxOop
58 // there is a corresponding handle called xxxHandle.
59
60 //------------------------------------------------------------------------------------------------------------------------
61 // Base class for all handles. Provides overloading of frequently
62 // used operators for ease of use.
63
64 class Handle {
65 private:
66 oop* _handle;
67
68 protected:
69 oop obj() const { return _handle == NULL ? (oop)NULL : *_handle; }
70 oop non_null_obj() const { assert(_handle != NULL, "resolving NULL handle"); return *_handle; }
71
72 public:
73 // Constructors
74 Handle() { _handle = NULL; }
75 Handle(Thread* thread, oop obj);
76
77 // General access
78 oop operator () () const { return obj(); }
79 oop operator -> () const { return non_null_obj(); }
80 bool operator == (oop o) const { return obj() == o; }
81 bool operator == (const Handle& h) const { return obj() == h.obj(); }
82
83 // Null checks
84 bool is_null() const { return _handle == NULL; }
85 bool not_null() const { return _handle != NULL; }
86
87 // Debugging
88 void print() { obj()->print(); }
89
90 // Direct interface, use very sparingly.
91 // Used by JavaCalls to quickly convert handles and to create handles static data structures.
92 // Constructor takes a dummy argument to prevent unintentional type conversion in C++.
93 Handle(oop *handle, bool dummy) { _handle = handle; }
94
95 // Raw handle access. Allows easy duplication of Handles. This can be very unsafe
96 // since duplicates is only valid as long as original handle is alive.
97 oop* raw_value() { return _handle; }
98 static oop raw_resolve(oop *handle) { return handle == NULL ? (oop)NULL : *handle; }
99 };
100
101 // Specific Handles for different oop types
102 #define DEF_HANDLE(type, is_a) \
103 class type##Handle: public Handle { \
104 protected: \
105 type##Oop obj() const { return (type##Oop)Handle::obj(); } \
106 type##Oop non_null_obj() const { return (type##Oop)Handle::non_null_obj(); } \
107 \
108 public: \
109 /* Constructors */ \
110 type##Handle () : Handle() {} \
111 type##Handle (Thread* thread, type##Oop obj) : Handle(thread, (oop)obj) { \
112 assert(is_null() || ((oop)obj)->is_a(), "illegal type"); \
113 } \
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
|
55 //
56 // Handles are specialized for different oop types to provide extra type
57 // information and avoid unnecessary casting. For each oop type xxxOop
58 // there is a corresponding handle called xxxHandle.
59
60 //------------------------------------------------------------------------------------------------------------------------
61 // Base class for all handles. Provides overloading of frequently
62 // used operators for ease of use.
63
64 class Handle {
65 private:
66 oop* _handle;
67
68 protected:
69 oop obj() const { return _handle == NULL ? (oop)NULL : *_handle; }
70 oop non_null_obj() const { assert(_handle != NULL, "resolving NULL handle"); return *_handle; }
71
72 public:
73 // Constructors
74 Handle() { _handle = NULL; }
75 inline Handle(Thread* thread, oop obj);
76
77 // General access
78 oop operator () () const { return obj(); }
79 oop operator -> () const { return non_null_obj(); }
80 bool operator == (oop o) const { return obj() == o; }
81 bool operator == (const Handle& h) const { return obj() == h.obj(); }
82
83 // Null checks
84 bool is_null() const { return _handle == NULL; }
85 bool not_null() const { return _handle != NULL; }
86
87 // Debugging
88 void print() { obj()->print(); }
89
90 // Direct interface, use very sparingly.
91 // Used by JavaCalls to quickly convert handles and to create handles static data structures.
92 // Constructor takes a dummy argument to prevent unintentional type conversion in C++.
93 Handle(oop *handle, bool dummy) { _handle = handle; }
94
95 // Raw handle access. Allows easy duplication of Handles. This can be very unsafe
96 // since duplicates is only valid as long as original handle is alive.
97 oop* raw_value() { return _handle; }
98 static oop raw_resolve(oop *handle) { return handle == NULL ? (oop)NULL : *handle; }
99 };
100
101 // Specific Handles for different oop types
102 #define DEF_HANDLE(type, is_a) \
103 class type##Handle: public Handle { \
104 protected: \
105 type##Oop obj() const { return (type##Oop)Handle::obj(); } \
106 type##Oop non_null_obj() const { return (type##Oop)Handle::non_null_obj(); } \
107 \
108 public: \
109 /* Constructors */ \
110 type##Handle () : Handle() {} \
111 inline type##Handle (Thread* thread, type##Oop obj); \
112 \
113 /* Operators for ease of use */ \
114 type##Oop operator () () const { return obj(); } \
115 type##Oop operator -> () const { return non_null_obj(); } \
116 };
117
118
119 DEF_HANDLE(instance , is_instance_noinline )
120 DEF_HANDLE(array , is_array_noinline )
121 DEF_HANDLE(objArray , is_objArray_noinline )
122 DEF_HANDLE(typeArray , is_typeArray_noinline )
123
124 //------------------------------------------------------------------------------------------------------------------------
125
126 // Metadata Handles. Unlike oop Handles these are needed to prevent metadata
127 // from being reclaimed by RedefineClasses.
128 // Metadata Handles should be passed around as const references to avoid copy construction
129 // and destruction for parameters.
130
131 // Specific Handles for different oop types
|