< prev index next >
src/hotspot/share/jfr/recorder/repository/jfrEmergencyDump.cpp
Print this page
*** 332,343 ****
/*
* We are just about to exit the VM, so we will be very aggressive
* at this point in order to increase overall success of dumping jfr data:
*
! * 1. if the thread state is not "_thread_in_vm", we will quick transition
! * it to "_thread_in_vm".
* 2. if the thread is the owner of some critical lock(s), unlock them.
*
* If we end up deadlocking in the attempt of dumping out jfr data,
* we rely on the WatcherThread task "is_error_reported()",
* to exit the VM after a hard-coded timeout (disallow WatcherThread to emergency dump).
--- 332,342 ----
/*
* We are just about to exit the VM, so we will be very aggressive
* at this point in order to increase overall success of dumping jfr data:
*
! * 1. if current thread is JavaThread, thread state need to be set to "_thread_in_vm".
* 2. if the thread is the owner of some critical lock(s), unlock them.
*
* If we end up deadlocking in the attempt of dumping out jfr data,
* we rely on the WatcherThread task "is_error_reported()",
* to exit the VM after a hard-coded timeout (disallow WatcherThread to emergency dump).
*** 353,365 ****
if (thread->is_Watcher_thread()) {
// need WatcherThread as a safeguard against potential deadlocks
return false;
}
! if (thread->is_Java_thread()) {
! ((JavaThread*)thread)->set_thread_state(_thread_in_vm);
! }
#ifdef ASSERT
Mutex* owned_lock = thread->owned_locks();
while (owned_lock != NULL) {
Mutex* next = owned_lock->next();
--- 352,362 ----
if (thread->is_Watcher_thread()) {
// need WatcherThread as a safeguard against potential deadlocks
return false;
}
! assert(thread->is_Java_thread() && (((JavaThread*)thread)->thread_state() == _thread_in_vm), "invariant");
#ifdef ASSERT
Mutex* owned_lock = thread->owned_locks();
while (owned_lock != NULL) {
Mutex* next = owned_lock->next();
*** 426,436 ****
static bool guard_reentrancy() {
return Atomic::cmpxchg(1, &jfr_shutdown_lock, 0) == 0;
}
! void JfrEmergencyDump::on_vm_shutdown(bool exception_handler) {
if (!(guard_reentrancy() && prepare_for_emergency_dump())) {
return;
}
EventDumpReason event;
if (event.should_commit()) {
--- 423,463 ----
static bool guard_reentrancy() {
return Atomic::cmpxchg(1, &jfr_shutdown_lock, 0) == 0;
}
! class ThreadInVMForJFR : public StackObj {
! private:
! JavaThread* _jt;
! JavaThreadState _original_state;
!
! public:
!
! ThreadInVMForJFR(Thread* thread) : _jt(NULL),
! _original_state(_thread_max_state) {
! if ((thread != NULL) && thread->is_Java_thread()) {
! _jt = (JavaThread*)thread;
! _original_state = _jt->thread_state();
! _jt->set_thread_state(_thread_in_vm);
! }
! }
!
! ~ThreadInVMForJFR() {
! if (_jt != NULL) {
! _jt->set_thread_state(_original_state);
! }
! }
!
! };
!
! void JfrEmergencyDump::on_vm_shutdown(Thread* thread, bool exception_handler) {
! /*
! * if the thread state is not "_thread_in_vm", we will quick transition
! * it to "_thread_in_vm" via ThreadInVMForJFR.
! */
! ThreadInVMForJFR tiv(thread);
!
if (!(guard_reentrancy() && prepare_for_emergency_dump())) {
return;
}
EventDumpReason event;
if (event.should_commit()) {
< prev index next >