8237488: jdk/jfr/event/compiler/TestCompilerCompile.java failed due to "RuntimeException: No thread in event"

Reviewed-by: egahlin
This commit is contained in:
Markus Grönlund 2020-07-02 21:13:41 +02:00
parent dc0c0c7eca
commit 5a90271d01
9 changed files with 25 additions and 27 deletions

View File

@ -90,12 +90,6 @@ bool Jfr::is_excluded(Thread* t) {
return t != NULL && t->jfr_thread_local()->is_excluded();
}
void Jfr::on_java_thread_dismantle(JavaThread* jt) {
if (JfrRecorder::is_recording()) {
JfrCheckpointManager::write_thread_checkpoint(jt);
}
}
void Jfr::on_vm_shutdown(bool exception_handler) {
if (JfrRecorder::is_recording()) {
JfrEmergencyDump::on_vm_shutdown(exception_handler);

View File

@ -49,7 +49,6 @@ class Jfr : AllStatic {
static void on_unloading_classes();
static void on_thread_start(Thread* thread);
static void on_thread_exit(Thread* thread);
static void on_java_thread_dismantle(JavaThread* jt);
static void on_vm_shutdown(bool exception_handler = false);
static bool on_flight_recorder_option(const JavaVMOption** option, char* delimiter);
static bool on_start_flight_recording_option(const JavaVMOption** option, char* delimiter);

View File

@ -108,7 +108,7 @@ void JfrCheckpointThreadClosure::do_thread(Thread* t) {
void JfrThreadConstantSet::serialize(JfrCheckpointWriter& writer) {
JfrCheckpointThreadClosure tc(writer);
JfrJavaThreadIterator javathreads;
JfrJavaThreadIterator javathreads(false); // include not yet live threads (_thread_new)
while (javathreads.has_next()) {
tc.do_thread(javathreads.next());
}

View File

@ -400,8 +400,8 @@ static RecorderState recorder_state = STOPPED;
static void set_recorder_state(RecorderState from, RecorderState to) {
assert(from == recorder_state, "invariant");
OrderAccess::storestore();
recorder_state = to;
OrderAccess::fence();
}
static void start_recorder() {
@ -417,18 +417,16 @@ static void stop_recorder() {
}
bool JfrRecorderService::is_recording() {
const bool is_running = recorder_state == RUNNING;
OrderAccess::loadload();
return is_running;
return recorder_state == RUNNING;
}
void JfrRecorderService::start() {
JfrRotationLock lock;
assert(!is_recording(), "invariant");
clear();
open_new_chunk();
start_recorder();
assert(is_recording(), "invariant");
open_new_chunk();
}
static void stop() {

View File

@ -92,8 +92,8 @@ void JfrThreadLocal::on_start(Thread* t) {
assert(Thread::current() == t, "invariant");
JfrJavaSupport::on_thread_start(t);
if (JfrRecorder::is_recording()) {
JfrCheckpointManager::write_thread_checkpoint(t);
if (!t->jfr_thread_local()->is_excluded()) {
JfrCheckpointManager::write_thread_checkpoint(t);
if (t->is_Java_thread()) {
send_java_thread_start_event((JavaThread*)t);
}

View File

@ -32,14 +32,17 @@ static bool thread_inclusion_predicate(Thread* t) {
return !t->jfr_thread_local()->is_dead();
}
static bool java_thread_inclusion_predicate(JavaThread* jt) {
static bool java_thread_inclusion_predicate(JavaThread* jt, bool live_only) {
assert(jt != NULL, "invariant");
return thread_inclusion_predicate(jt) && jt->thread_state() != _thread_new;
if (live_only && jt->thread_state() == _thread_new) {
return false;
}
return thread_inclusion_predicate(jt);
}
static JavaThread* next_java_thread(JavaThreadIteratorWithHandle& iter) {
static JavaThread* next_java_thread(JavaThreadIteratorWithHandle& iter, bool live_only) {
JavaThread* next = iter.next();
while (next != NULL && !java_thread_inclusion_predicate(next)) {
while (next != NULL && !java_thread_inclusion_predicate(next, live_only)) {
next = iter.next();
}
return next;
@ -57,17 +60,19 @@ static NonJavaThread* next_non_java_thread(NonJavaThread::Iterator& iter) {
return NULL;
}
JfrJavaThreadIteratorAdapter::JfrJavaThreadIteratorAdapter() : _iter(), _next(next_java_thread(_iter)) {}
JfrJavaThreadIteratorAdapter::JfrJavaThreadIteratorAdapter(bool live_only /* true */) : _iter(),
_next(next_java_thread(_iter, live_only)),
_live_only(live_only) {}
JavaThread* JfrJavaThreadIteratorAdapter::next() {
assert(has_next(), "invariant");
Type* const temp = _next;
_next = next_java_thread(_iter);
_next = next_java_thread(_iter, _live_only);
assert(temp != _next, "invariant");
return temp;
}
JfrNonJavaThreadIteratorAdapter::JfrNonJavaThreadIteratorAdapter() : _iter(), _next(next_non_java_thread(_iter)) {}
JfrNonJavaThreadIteratorAdapter::JfrNonJavaThreadIteratorAdapter(bool live_only /* true */) : _iter(), _next(next_non_java_thread(_iter)) {}
bool JfrNonJavaThreadIteratorAdapter::has_next() const {
return _next != NULL;

View File

@ -34,7 +34,7 @@ class JfrThreadIterator : public AP {
private:
Adapter _adapter;
public:
JfrThreadIterator() : _adapter() {}
JfrThreadIterator(bool live_only = true) : _adapter(live_only) {}
typename Adapter::Type* next() {
assert(has_next(), "invariant");
return _adapter.next();
@ -48,9 +48,10 @@ class JfrJavaThreadIteratorAdapter {
private:
JavaThreadIteratorWithHandle _iter;
JavaThread* _next;
bool _live_only;
public:
typedef JavaThread Type;
JfrJavaThreadIteratorAdapter();
JfrJavaThreadIteratorAdapter(bool live_only = true);
bool has_next() const {
return _next != NULL;
}
@ -63,7 +64,7 @@ class JfrNonJavaThreadIteratorAdapter {
NonJavaThread* _next;
public:
typedef NonJavaThread Type;
JfrNonJavaThreadIteratorAdapter();
JfrNonJavaThreadIteratorAdapter(bool live_only = true);
bool has_next() const;
Type* next();
};

View File

@ -95,9 +95,11 @@
#if INCLUDE_CDS
#include "classfile/systemDictionaryShared.hpp"
#endif
#if INCLUDE_JFR
#include "jfr/jfr.hpp"
#endif
#include <errno.h>
#include <jfr/recorder/jfrRecorder.hpp>
/*
NOTE about use of any ctor or function call that can trigger a safepoint/GC:
@ -3076,7 +3078,7 @@ JVM_ENTRY(void, JVM_StartThread(JNIEnv* env, jobject jthread))
}
#if INCLUDE_JFR
if (JfrRecorder::is_recording() && EventThreadStart::is_enabled() &&
if (Jfr::is_recording() && EventThreadStart::is_enabled() &&
EventThreadStart::is_stacktrace_enabled()) {
JfrThreadLocal* tl = native_thread->jfr_thread_local();
// skip Thread.start() and Thread.start0()

View File

@ -2045,7 +2045,6 @@ void JavaThread::exit(bool destroy_vm, ExitType exit_type) {
CLEAR_PENDING_EXCEPTION;
}
}
JFR_ONLY(Jfr::on_java_thread_dismantle(this);)
// Call Thread.exit(). We try 3 times in case we got another Thread.stop during
// the execution of the method. If that is not enough, then we don't really care. Thread.stop