@@ -77,35 +77,44 @@ class oopDesc;
77
77
78
78
extern " C" bool CheckUnhandledOops;
79
79
80
+ // Extra verification when creating and using oops.
81
+ // Used to catch broken oops as soon as possible.
82
+ using CheckOopFunctionPointer = void (*)(oopDesc*);
83
+ extern CheckOopFunctionPointer check_oop_function;
84
+
80
85
class oop {
81
86
oopDesc* _o;
82
87
83
88
void register_oop ();
84
89
void unregister_oop ();
85
90
86
- void register_if_checking () {
87
- if (CheckUnhandledOops) register_oop ();
88
- }
91
+ // Extra verification of the oop
92
+ void check_oop () const { if (check_oop_function != nullptr && _o != nullptr ) check_oop_function (_o); }
93
+
94
+ void on_usage () const { check_oop (); }
95
+ void on_construction () { check_oop (); if (CheckUnhandledOops) register_oop (); }
96
+ void on_destruction () { if (CheckUnhandledOops) unregister_oop (); }
89
97
90
98
public:
91
- oop () : _o(nullptr ) { register_if_checking (); }
92
- oop (const oop& o) : _o(o._o) { register_if_checking (); }
93
- oop (oopDesc* o) : _o(o) { register_if_checking (); }
99
+ oop () : _o(nullptr ) { on_construction (); }
100
+ oop (const oop& o) : _o(o._o) { on_construction (); }
101
+ oop (oopDesc* o) : _o(o) { on_construction (); }
94
102
~oop () {
95
- if (CheckUnhandledOops) unregister_oop ();
103
+ on_destruction ();
96
104
}
97
105
98
- oopDesc* obj () const { return _o; }
99
- oopDesc* operator ->() const { return _o; }
100
- operator oopDesc* () const { return _o; }
106
+ oopDesc* obj () const { on_usage (); return _o; }
107
+
108
+ oopDesc* operator ->() const { return obj (); }
109
+ operator oopDesc* () const { return obj (); }
101
110
102
- bool operator ==(const oop& o) const { return _o == o._o ; }
103
- bool operator !=(const oop& o) const { return _o != o._o ; }
111
+ bool operator ==(const oop& o) const { return obj () == o.obj () ; }
112
+ bool operator !=(const oop& o) const { return obj () != o.obj () ; }
104
113
105
- bool operator ==(std::nullptr_t ) const { return _o == nullptr ; }
106
- bool operator !=(std::nullptr_t ) const { return _o != nullptr ; }
114
+ bool operator ==(std::nullptr_t ) const { return obj () == nullptr ; }
115
+ bool operator !=(std::nullptr_t ) const { return obj () != nullptr ; }
107
116
108
- oop& operator =(const oop& o) { _o = o._o ; return *this ; }
117
+ oop& operator =(const oop& o) { _o = o.obj () ; return *this ; }
109
118
};
110
119
111
120
template <>
0 commit comments