Skip to content

Commit 33245d6

Browse files
committed
8307517: Add VMErrorCallback infrastructure to extend hs_err dumping
Reviewed-by: eosterlund, aboldtch, dholmes, stuefe
1 parent 7a1cb64 commit 33245d6

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

src/hotspot/share/runtime/thread.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Thread::Thread() {
9898
_jvmti_env_iteration_count = 0;
9999
set_allocated_bytes(0);
100100
_current_pending_raw_monitor = nullptr;
101+
_vm_error_callbacks = nullptr;
101102

102103
// thread-specific hashCode stream generator state - Marsaglia shift-xor form
103104
_hashStateX = os::random();

src/hotspot/share/runtime/thread.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class SafeThreadsListPtr;
5555
class ThreadClosure;
5656
class ThreadsList;
5757
class ThreadsSMRSupport;
58+
class VMErrorCallback;
5859

5960
class OopClosure;
6061
class CodeBlobClosure;
@@ -104,6 +105,8 @@ class JavaThread;
104105
// - this->entry_point() // set differently for each kind of JavaThread
105106

106107
class Thread: public ThreadShadow {
108+
friend class VMError;
109+
friend class VMErrorCallbackMark;
107110
friend class VMStructs;
108111
friend class JVMCIVMStructs;
109112
private:
@@ -634,6 +637,9 @@ class Thread: public ThreadShadow {
634637
Thread *cur = Thread::current_or_null_safe();
635638
return cur != nullptr && cur->in_asgct();
636639
}
640+
641+
private:
642+
VMErrorCallback* _vm_error_callbacks;
637643
};
638644

639645
class ThreadInAsgct {

src/hotspot/share/utilities/vmError.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,14 @@ void VMError::report(outputStream* st, bool _verbose) {
948948
st->cr();
949949
}
950950

951+
STEP_IF("printing registered callbacks", _verbose && _thread != nullptr);
952+
for (VMErrorCallback* callback = _thread->_vm_error_callbacks;
953+
callback != nullptr;
954+
callback = callback->_next) {
955+
callback->call(st);
956+
st->cr();
957+
}
958+
951959
STEP("printing process")
952960

953961
STEP_IF("printing process", _verbose)
@@ -1896,3 +1904,14 @@ void VMError::controlled_crash(int how) {
18961904
ShouldNotReachHere();
18971905
}
18981906
#endif // !ASSERT
1907+
1908+
VMErrorCallbackMark::VMErrorCallbackMark(VMErrorCallback* callback)
1909+
: _thread(Thread::current()) {
1910+
callback->_next = _thread->_vm_error_callbacks;
1911+
_thread->_vm_error_callbacks = callback;
1912+
}
1913+
1914+
VMErrorCallbackMark::~VMErrorCallbackMark() {
1915+
assert(_thread->_vm_error_callbacks != nullptr, "Popped too far");
1916+
_thread->_vm_error_callbacks = _thread->_vm_error_callbacks->_next;
1917+
}

src/hotspot/share/utilities/vmError.hpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,27 @@ class VMError : public AllStatic {
213213
static int prepare_log_file(const char* pattern, const char* default_pattern, bool overwrite_existing, char* buf, size_t buflen);
214214

215215
};
216+
217+
class VMErrorCallback {
218+
friend class VMError;
219+
friend class VMErrorCallbackMark;
220+
221+
// Link through all callbacks active on a thread
222+
VMErrorCallback* _next;
223+
224+
// Called by VMError reporting
225+
virtual void call(outputStream* st) = 0;
226+
227+
public:
228+
VMErrorCallback() : _next(nullptr) {}
229+
};
230+
231+
class VMErrorCallbackMark : public StackObj {
232+
Thread* _thread;
233+
234+
public:
235+
VMErrorCallbackMark(VMErrorCallback* callback);
236+
~VMErrorCallbackMark();
237+
};
238+
216239
#endif // SHARE_UTILITIES_VMERROR_HPP

0 commit comments

Comments
 (0)