Skip to content

Commit

Permalink
8237488: jdk/jfr/event/compiler/TestCompilerCompile.java failed due t…
Browse files Browse the repository at this point in the history
…o "RuntimeException: No thread in event"

Reviewed-by: egahlin
  • Loading branch information
Markus Grönlund committed Jul 2, 2020
1 parent dc0c0c7 commit 5a90271
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 27 deletions.
6 changes: 0 additions & 6 deletions src/hotspot/share/jfr/jfr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/jfr/jfr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
8 changes: 3 additions & 5 deletions src/hotspot/share/jfr/recorder/service/jfrRecorderService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/jfr/support/jfrThreadLocal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
19 changes: 12 additions & 7 deletions src/hotspot/share/jfr/utilities/jfrThreadIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/hotspot/share/jfr/utilities/jfrThreadIterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
Expand All @@ -63,7 +64,7 @@ class JfrNonJavaThreadIteratorAdapter {
NonJavaThread* _next;
public:
typedef NonJavaThread Type;
JfrNonJavaThreadIteratorAdapter();
JfrNonJavaThreadIteratorAdapter(bool live_only = true);
bool has_next() const;
Type* next();
};
Expand Down
6 changes: 4 additions & 2 deletions src/hotspot/share/prims/jvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/runtime/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5a90271

Please sign in to comment.