149 /* Destructor */ \ 150 ~name##Handle (); \ 151 void remove(); \ 152 \ 153 /* Operators for ease of use */ \ 154 type* operator () () const { return obj(); } \ 155 type* operator -> () const { return non_null_obj(); } \ 156 \ 157 bool operator == (type* o) const { return obj() == o; } \ 158 bool operator == (const name##Handle& h) const { return obj() == h.obj(); } \ 159 \ 160 /* Null checks */ \ 161 bool is_null() const { return _value == NULL; } \ 162 bool not_null() const { return _value != NULL; } \ 163 }; 164 165 166 DEF_METADATA_HANDLE(method, Method) 167 DEF_METADATA_HANDLE(constantPool, ConstantPool) 168 169 // Writing this class explicitly, since DEF_METADATA_HANDLE(klass) doesn't 170 // provide the necessary Klass* <-> Klass* conversions. This Klass 171 // could be removed when we don't have the Klass* typedef anymore. 172 class KlassHandle : public StackObj { 173 Klass* _value; 174 protected: 175 Klass* obj() const { return _value; } 176 Klass* non_null_obj() const { assert(_value != NULL, "resolving NULL _value"); return _value; } 177 178 public: 179 KlassHandle() : _value(NULL) {} 180 KlassHandle(const Klass* obj) : _value(const_cast<Klass *>(obj)) {}; 181 KlassHandle(Thread* thread, const Klass* obj) : _value(const_cast<Klass *>(obj)) {}; 182 183 Klass* operator () () const { return obj(); } 184 Klass* operator -> () const { return non_null_obj(); } 185 186 bool operator == (Klass* o) const { return obj() == o; } 187 bool operator == (const KlassHandle& h) const { return obj() == h.obj(); } 188 189 bool is_null() const { return _value == NULL; } 190 bool not_null() const { return _value != NULL; } 191 }; 192 193 class instanceKlassHandle : public KlassHandle { 194 public: 195 /* Constructors */ 196 instanceKlassHandle () : KlassHandle() {} 197 instanceKlassHandle (const Klass* k) : KlassHandle(k) { 198 assert(k == NULL || is_instanceKlass(k), "illegal type"); 199 } 200 instanceKlassHandle (Thread* thread, const Klass* k) : KlassHandle(thread, k) { 201 assert(k == NULL || is_instanceKlass(k), "illegal type"); 202 } 203 /* Access to klass part */ 204 InstanceKlass* operator () () const { return (InstanceKlass*)obj(); } 205 InstanceKlass* operator -> () const { return (InstanceKlass*)obj(); } 206 207 debug_only(bool is_instanceKlass(const Klass* k)); 208 }; 209 210 211 //------------------------------------------------------------------------------------------------------------------------ 212 // Thread local handle area 213 class HandleArea: public Arena { 214 friend class HandleMark; 215 friend class NoHandleMark; 216 friend class ResetNoHandleMark; 217 #ifdef ASSERT 218 int _handle_mark_nesting; 219 int _no_handle_mark_nesting; 220 #endif 221 HandleArea* _prev; // link to outer (older) area 222 public: 223 // Constructor 224 HandleArea(HandleArea* prev) : Arena(mtThread, Chunk::tiny_size) { 225 debug_only(_handle_mark_nesting = 0); 226 debug_only(_no_handle_mark_nesting = 0); 227 _prev = prev; 228 } 229 230 // Handle allocation | 149 /* Destructor */ \ 150 ~name##Handle (); \ 151 void remove(); \ 152 \ 153 /* Operators for ease of use */ \ 154 type* operator () () const { return obj(); } \ 155 type* operator -> () const { return non_null_obj(); } \ 156 \ 157 bool operator == (type* o) const { return obj() == o; } \ 158 bool operator == (const name##Handle& h) const { return obj() == h.obj(); } \ 159 \ 160 /* Null checks */ \ 161 bool is_null() const { return _value == NULL; } \ 162 bool not_null() const { return _value != NULL; } \ 163 }; 164 165 166 DEF_METADATA_HANDLE(method, Method) 167 DEF_METADATA_HANDLE(constantPool, ConstantPool) 168 169 //------------------------------------------------------------------------------------------------------------------------ 170 // Thread local handle area 171 class HandleArea: public Arena { 172 friend class HandleMark; 173 friend class NoHandleMark; 174 friend class ResetNoHandleMark; 175 #ifdef ASSERT 176 int _handle_mark_nesting; 177 int _no_handle_mark_nesting; 178 #endif 179 HandleArea* _prev; // link to outer (older) area 180 public: 181 // Constructor 182 HandleArea(HandleArea* prev) : Arena(mtThread, Chunk::tiny_size) { 183 debug_only(_handle_mark_nesting = 0); 184 debug_only(_no_handle_mark_nesting = 0); 185 _prev = prev; 186 } 187 188 // Handle allocation |