mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 23:34:52 +02:00
8235390: JfrEmergencyDump::on_vm_shutdown crashes
Reviewed-by: egahlin
This commit is contained in:
parent
261f4bffae
commit
ffdf1dea9b
5 changed files with 69 additions and 21 deletions
|
@ -53,12 +53,15 @@ EventEmitter::~EventEmitter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventEmitter::emit(ObjectSampler* sampler, int64_t cutoff_ticks, bool emit_all) {
|
void EventEmitter::emit(ObjectSampler* sampler, int64_t cutoff_ticks, bool emit_all) {
|
||||||
assert(JfrStream_lock->owned_by_self(), "invariant");
|
|
||||||
assert(sampler != NULL, "invariant");
|
assert(sampler != NULL, "invariant");
|
||||||
ResourceMark rm;
|
ResourceMark rm;
|
||||||
EdgeStore edge_store;
|
EdgeStore edge_store;
|
||||||
if (cutoff_ticks <= 0) {
|
if (cutoff_ticks <= 0) {
|
||||||
// no reference chains
|
// no reference chains
|
||||||
|
MutexLocker lock(JfrStream_lock, Mutex::_no_safepoint_check_flag);
|
||||||
|
// The lock is needed here to prevent the recorder thread (running flush())
|
||||||
|
// from writing old object events out from the thread local buffer
|
||||||
|
// before the required constant pools have been serialized.
|
||||||
JfrTicks time_stamp = JfrTicks::now();
|
JfrTicks time_stamp = JfrTicks::now();
|
||||||
EventEmitter emitter(time_stamp, time_stamp);
|
EventEmitter emitter(time_stamp, time_stamp);
|
||||||
emitter.write_events(sampler, &edge_store, emit_all);
|
emitter.write_events(sampler, &edge_store, emit_all);
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
#include "jfr/recorder/service/jfrOptionSet.hpp"
|
#include "jfr/recorder/service/jfrOptionSet.hpp"
|
||||||
#include "logging/log.hpp"
|
#include "logging/log.hpp"
|
||||||
#include "memory/iterator.hpp"
|
#include "memory/iterator.hpp"
|
||||||
#include "runtime/mutexLocker.hpp"
|
|
||||||
#include "runtime/thread.inline.hpp"
|
#include "runtime/thread.inline.hpp"
|
||||||
#include "runtime/vmThread.hpp"
|
#include "runtime/vmThread.hpp"
|
||||||
|
|
||||||
|
@ -83,7 +82,6 @@ void LeakProfiler::emit_events(int64_t cutoff_ticks, bool emit_all) {
|
||||||
if (!is_running()) {
|
if (!is_running()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MutexLocker lock(JfrStream_lock);
|
|
||||||
// exclusive access to object sampler instance
|
// exclusive access to object sampler instance
|
||||||
ObjectSampler* const sampler = ObjectSampler::acquire();
|
ObjectSampler* const sampler = ObjectSampler::acquire();
|
||||||
assert(sampler != NULL, "invariant");
|
assert(sampler != NULL, "invariant");
|
||||||
|
|
|
@ -359,7 +359,7 @@ bool JfrRecorderService::is_recording() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void JfrRecorderService::start() {
|
void JfrRecorderService::start() {
|
||||||
MutexLocker lock(JfrStream_lock);
|
MutexLocker lock(JfrStream_lock, Mutex::_no_safepoint_check_flag);
|
||||||
log_debug(jfr, system)("Request to START recording");
|
log_debug(jfr, system)("Request to START recording");
|
||||||
assert(!is_recording(), "invariant");
|
assert(!is_recording(), "invariant");
|
||||||
clear();
|
clear();
|
||||||
|
@ -402,6 +402,7 @@ void JfrRecorderService::post_safepoint_clear() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void JfrRecorderService::open_new_chunk(bool vm_error) {
|
void JfrRecorderService::open_new_chunk(bool vm_error) {
|
||||||
|
assert(JfrStream_lock->owned_by_self(), "invariant");
|
||||||
JfrChunkRotation::on_rotation();
|
JfrChunkRotation::on_rotation();
|
||||||
const bool valid_chunk = _repository.open_chunk(vm_error);
|
const bool valid_chunk = _repository.open_chunk(vm_error);
|
||||||
_storage.control().set_to_disk(valid_chunk);
|
_storage.control().set_to_disk(valid_chunk);
|
||||||
|
@ -411,24 +412,61 @@ void JfrRecorderService::open_new_chunk(bool vm_error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void stop() {
|
static void stop() {
|
||||||
|
assert(JfrStream_lock->owned_by_self(), "invariant");
|
||||||
assert(JfrRecorderService::is_recording(), "invariant");
|
assert(JfrRecorderService::is_recording(), "invariant");
|
||||||
log_debug(jfr, system)("Recording STOPPED");
|
log_debug(jfr, system)("Recording STOPPED");
|
||||||
set_recording_state(false);
|
set_recording_state(false);
|
||||||
assert(!JfrRecorderService::is_recording(), "invariant");
|
assert(!JfrRecorderService::is_recording(), "invariant");
|
||||||
}
|
}
|
||||||
|
|
||||||
void JfrRecorderService::prepare_for_vm_error_rotation() {
|
// 'rotation_safepoint_pending' is currently only relevant in the unusual case of an emergency dump.
|
||||||
assert(JfrStream_lock->owned_by_self(), "invariant");
|
// Since the JfrStream_lock must be acquired using _no_safepoint_check,
|
||||||
if (!_chunkwriter.is_valid()) {
|
// if the thread running the emergency dump is a JavaThread, a pending safepoint, induced by rotation,
|
||||||
open_new_chunk(true);
|
// would lead to a deadlock. This deadlock, although unpleasant, is not completely horrendous at this
|
||||||
|
// location because the WatcherThread will terminate the VM after a timeout.
|
||||||
|
// Deadlock avoidance is done not to affect the stability of general VM error reporting.
|
||||||
|
static bool rotation_safepoint_pending = false;
|
||||||
|
|
||||||
|
static bool is_rotation_safepoint_pending() {
|
||||||
|
return Atomic::load_acquire(&rotation_safepoint_pending);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_rotation_safepoint_pending(bool value) {
|
||||||
|
assert(value ? !is_rotation_safepoint_pending() : is_rotation_safepoint_pending(), "invariant");
|
||||||
|
Atomic::release_store(&rotation_safepoint_pending, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool vm_error = false;
|
||||||
|
static const Thread* vm_error_thread = NULL;
|
||||||
|
|
||||||
|
static bool prepare_for_vm_error_rotation() {
|
||||||
|
assert(!JfrStream_lock->owned_by_self(), "invariant");
|
||||||
|
Thread* const t = Thread::current();
|
||||||
|
assert(t != NULL, "invariant");
|
||||||
|
if (is_rotation_safepoint_pending() && t->is_Java_thread()) {
|
||||||
|
// A safepoint is pending, avoid deadlock.
|
||||||
|
log_warning(jfr, system)("Unable to issue successful emergency dump");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
_checkpoint_manager.register_service_thread(Thread::current());
|
vm_error_thread = t;
|
||||||
|
vm_error = true;
|
||||||
|
OrderAccess::fence();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JfrRecorderService::vm_error_rotation() {
|
void JfrRecorderService::vm_error_rotation() {
|
||||||
assert(JfrStream_lock->owned_by_self(), "invariant");
|
assert(JfrStream_lock->owned_by_self(), "invariant");
|
||||||
|
assert(vm_error, "invariant");
|
||||||
|
Thread* const t = Thread::current();
|
||||||
|
if (vm_error_thread != t) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
assert(vm_error_thread == t, "invariant");
|
||||||
|
if (!_chunkwriter.is_valid()) {
|
||||||
|
open_new_chunk(true);
|
||||||
|
}
|
||||||
if (_chunkwriter.is_valid()) {
|
if (_chunkwriter.is_valid()) {
|
||||||
Thread* const t = Thread::current();
|
_checkpoint_manager.register_service_thread(t);
|
||||||
_storage.flush_regular_buffer(t->jfr_thread_local()->native_buffer(), t);
|
_storage.flush_regular_buffer(t->jfr_thread_local()->native_buffer(), t);
|
||||||
_chunkwriter.mark_chunk_final();
|
_chunkwriter.mark_chunk_final();
|
||||||
invoke_flush();
|
invoke_flush();
|
||||||
|
@ -441,18 +479,21 @@ void JfrRecorderService::vm_error_rotation() {
|
||||||
|
|
||||||
void JfrRecorderService::rotate(int msgs) {
|
void JfrRecorderService::rotate(int msgs) {
|
||||||
assert(!JfrStream_lock->owned_by_self(), "invariant");
|
assert(!JfrStream_lock->owned_by_self(), "invariant");
|
||||||
MutexLocker lock(JfrStream_lock);
|
|
||||||
static bool vm_error = false;
|
|
||||||
if (msgs & MSGBIT(MSG_VM_ERROR)) {
|
if (msgs & MSGBIT(MSG_VM_ERROR)) {
|
||||||
vm_error = true;
|
// emergency dump
|
||||||
prepare_for_vm_error_rotation();
|
if (!prepare_for_vm_error_rotation()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!_storage.control().to_disk()) {
|
MutexLocker lock(JfrStream_lock, Mutex::_no_safepoint_check_flag);
|
||||||
in_memory_rotation();
|
if (vm_error) {
|
||||||
} else if (vm_error) {
|
|
||||||
vm_error_rotation();
|
vm_error_rotation();
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
|
if (_storage.control().to_disk()) {
|
||||||
chunk_rotation();
|
chunk_rotation();
|
||||||
|
} else {
|
||||||
|
in_memory_rotation();
|
||||||
}
|
}
|
||||||
if (msgs & (MSGBIT(MSG_STOP))) {
|
if (msgs & (MSGBIT(MSG_STOP))) {
|
||||||
stop();
|
stop();
|
||||||
|
@ -478,7 +519,10 @@ void JfrRecorderService::chunk_rotation() {
|
||||||
|
|
||||||
void JfrRecorderService::finalize_current_chunk() {
|
void JfrRecorderService::finalize_current_chunk() {
|
||||||
assert(_chunkwriter.is_valid(), "invariant");
|
assert(_chunkwriter.is_valid(), "invariant");
|
||||||
|
assert(!is_rotation_safepoint_pending(), "invariant");
|
||||||
|
set_rotation_safepoint_pending(true);
|
||||||
write();
|
write();
|
||||||
|
assert(!is_rotation_safepoint_pending(), "invariant");
|
||||||
}
|
}
|
||||||
|
|
||||||
void JfrRecorderService::write() {
|
void JfrRecorderService::write() {
|
||||||
|
@ -491,6 +535,7 @@ void JfrRecorderService::write() {
|
||||||
|
|
||||||
void JfrRecorderService::pre_safepoint_write() {
|
void JfrRecorderService::pre_safepoint_write() {
|
||||||
assert(_chunkwriter.is_valid(), "invariant");
|
assert(_chunkwriter.is_valid(), "invariant");
|
||||||
|
assert(is_rotation_safepoint_pending(), "invariant");
|
||||||
if (LeakProfiler::is_running()) {
|
if (LeakProfiler::is_running()) {
|
||||||
// Exclusive access to the object sampler instance.
|
// Exclusive access to the object sampler instance.
|
||||||
// The sampler is released (unlocked) later in post_safepoint_write.
|
// The sampler is released (unlocked) later in post_safepoint_write.
|
||||||
|
@ -512,6 +557,8 @@ void JfrRecorderService::invoke_safepoint_write() {
|
||||||
|
|
||||||
void JfrRecorderService::safepoint_write() {
|
void JfrRecorderService::safepoint_write() {
|
||||||
assert(SafepointSynchronize::is_at_safepoint(), "invariant");
|
assert(SafepointSynchronize::is_at_safepoint(), "invariant");
|
||||||
|
assert(is_rotation_safepoint_pending(), "invariant");
|
||||||
|
set_rotation_safepoint_pending(false);
|
||||||
if (_string_pool.is_modified()) {
|
if (_string_pool.is_modified()) {
|
||||||
write_stringpool_safepoint(_string_pool, _chunkwriter);
|
write_stringpool_safepoint(_string_pool, _chunkwriter);
|
||||||
}
|
}
|
||||||
|
@ -524,6 +571,7 @@ void JfrRecorderService::safepoint_write() {
|
||||||
|
|
||||||
void JfrRecorderService::post_safepoint_write() {
|
void JfrRecorderService::post_safepoint_write() {
|
||||||
assert(_chunkwriter.is_valid(), "invariant");
|
assert(_chunkwriter.is_valid(), "invariant");
|
||||||
|
assert(!is_rotation_safepoint_pending(), "invariant");
|
||||||
// During the safepoint tasks just completed, the system transitioned to a new epoch.
|
// During the safepoint tasks just completed, the system transitioned to a new epoch.
|
||||||
// Type tagging is epoch relative which entails we are able to write out the
|
// Type tagging is epoch relative which entails we are able to write out the
|
||||||
// already tagged artifacts for the previous epoch. We can accomplish this concurrently
|
// already tagged artifacts for the previous epoch. We can accomplish this concurrently
|
||||||
|
@ -606,7 +654,7 @@ void JfrRecorderService::invoke_flush() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void JfrRecorderService::flushpoint() {
|
void JfrRecorderService::flushpoint() {
|
||||||
MutexLocker lock(JfrStream_lock);
|
MutexLocker lock(JfrStream_lock, Mutex::_no_safepoint_check_flag);
|
||||||
invoke_flush();
|
invoke_flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,6 @@ class JfrRecorderService : public StackObj {
|
||||||
void chunk_rotation();
|
void chunk_rotation();
|
||||||
void in_memory_rotation();
|
void in_memory_rotation();
|
||||||
void finalize_current_chunk();
|
void finalize_current_chunk();
|
||||||
void prepare_for_vm_error_rotation();
|
|
||||||
void vm_error_rotation();
|
void vm_error_rotation();
|
||||||
void invoke_flush();
|
void invoke_flush();
|
||||||
|
|
||||||
|
|
|
@ -311,7 +311,7 @@ void mutex_init() {
|
||||||
#if INCLUDE_JFR
|
#if INCLUDE_JFR
|
||||||
def(JfrMsg_lock , PaddedMonitor, leaf, true, _safepoint_check_always);
|
def(JfrMsg_lock , PaddedMonitor, leaf, true, _safepoint_check_always);
|
||||||
def(JfrBuffer_lock , PaddedMutex , leaf, true, _safepoint_check_never);
|
def(JfrBuffer_lock , PaddedMutex , leaf, true, _safepoint_check_never);
|
||||||
def(JfrStream_lock , PaddedMutex , nonleaf + 1, false, _safepoint_check_always);
|
def(JfrStream_lock , PaddedMutex , nonleaf + 1, false, _safepoint_check_never);
|
||||||
def(JfrStacktrace_lock , PaddedMutex , special, true, _safepoint_check_never);
|
def(JfrStacktrace_lock , PaddedMutex , special, true, _safepoint_check_never);
|
||||||
def(JfrThreadSampler_lock , PaddedMonitor, leaf, true, _safepoint_check_never);
|
def(JfrThreadSampler_lock , PaddedMonitor, leaf, true, _safepoint_check_never);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue