59 //------------------------------------------------------------------------------------------------------------------------
60 // Base class for all handles. Provides overloading of frequently
61 // used operators for ease of use.
62
63 class Handle {
64 private:
65 oop* _handle;
66
67 protected:
68 oop obj() const { return _handle == NULL ? (oop)NULL : *_handle; }
69 oop non_null_obj() const { assert(_handle != NULL, "resolving NULL handle"); return *_handle; }
70
71 public:
72 // Constructors
73 Handle() { _handle = NULL; }
74 inline Handle(Thread* thread, oop obj);
75
76 // General access
77 oop operator () () const { return obj(); }
78 oop operator -> () const { return non_null_obj(); }
79 bool operator == (oop o) const { return obj() == o; }
80 bool operator == (const Handle& h) const { return obj() == h.obj(); }
81
82 // Null checks
83 bool is_null() const { return _handle == NULL; }
84 bool not_null() const { return _handle != NULL; }
85
86 // Debugging
87 void print() { obj()->print(); }
88
89 // Direct interface, use very sparingly.
90 // Used by JavaCalls to quickly convert handles and to create handles static data structures.
91 // Constructor takes a dummy argument to prevent unintentional type conversion in C++.
92 Handle(oop *handle, bool dummy) { _handle = handle; }
93
94 // Raw handle access. Allows easy duplication of Handles. This can be very unsafe
95 // since duplicates is only valid as long as original handle is alive.
96 oop* raw_value() { return _handle; }
97 static oop raw_resolve(oop *handle) { return handle == NULL ? (oop)NULL : *handle; }
98 };
99
|
59 //------------------------------------------------------------------------------------------------------------------------
60 // Base class for all handles. Provides overloading of frequently
61 // used operators for ease of use.
62
63 class Handle {
64 private:
65 oop* _handle;
66
67 protected:
68 oop obj() const { return _handle == NULL ? (oop)NULL : *_handle; }
69 oop non_null_obj() const { assert(_handle != NULL, "resolving NULL handle"); return *_handle; }
70
71 public:
72 // Constructors
73 Handle() { _handle = NULL; }
74 inline Handle(Thread* thread, oop obj);
75
76 // General access
77 oop operator () () const { return obj(); }
78 oop operator -> () const { return non_null_obj(); }
79
80 bool operator == (oop o) const { return oopDesc::equals(obj(), o); }
81 bool operator == (const Handle& h) const { return oopDesc::equals(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
|