Skip to content

Commit 959e62c

Browse files
committed
8307521: Introduce check_oop infrastructure to check oops in the oop class
Reviewed-by: eosterlund, aboldtch, coleenp
1 parent ad0e5a9 commit 959e62c

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

src/hotspot/share/oops/oopsHierarchy.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
#ifdef CHECK_UNHANDLED_OOPS
3232

33+
CheckOopFunctionPointer check_oop_function = nullptr;
34+
3335
void oop::register_oop() {
3436
assert (CheckUnhandledOops, "should only call when CheckUnhandledOops");
3537
if (!Universe::is_fully_initialized()) return;

src/hotspot/share/oops/oopsHierarchy.hpp

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,35 +77,44 @@ class oopDesc;
7777

7878
extern "C" bool CheckUnhandledOops;
7979

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+
8085
class oop {
8186
oopDesc* _o;
8287

8388
void register_oop();
8489
void unregister_oop();
8590

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(); }
8997

9098
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(); }
94102
~oop() {
95-
if (CheckUnhandledOops) unregister_oop();
103+
on_destruction();
96104
}
97105

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(); }
101110

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(); }
104113

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; }
107116

108-
oop& operator=(const oop& o) { _o = o._o; return *this; }
117+
oop& operator=(const oop& o) { _o = o.obj(); return *this; }
109118
};
110119

111120
template<>

0 commit comments

Comments
 (0)