Skip to content
Permalink
Browse files
to avoid deadlocks ignore JVMTI events if JavaThread is in VTMT
  • Loading branch information
sspitsyn committed Mar 25, 2021
1 parent 3a92f43 commit c881822f2a73f79fd0eccbc42124bf6fde2e493a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
@@ -1349,6 +1349,9 @@ void JvmtiExport::post_class_load(JavaThread *thread, Klass* klass) {
if (state == NULL) {
return;
}
if (thread->is_in_VTMT()) {
return; // no events should be posted if thread is in a VTMT transition
}
JvmtiEnvThreadStateIterator it(state);
for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
if (ets->is_enabled(JVMTI_EVENT_CLASS_LOAD)) {
@@ -1382,6 +1385,9 @@ void JvmtiExport::post_class_prepare(JavaThread *thread, Klass* klass) {
if (state == NULL) {
return;
}
if (thread->is_in_VTMT()) {
return; // no events should be posted if thread is in a VTMT transition
}
JvmtiEnvThreadStateIterator it(state);
for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) {
if (ets->is_enabled(JVMTI_EVENT_CLASS_PREPARE)) {
@@ -1945,6 +1951,9 @@ void JvmtiExport::post_exception_throw(JavaThread *thread, Method* method, addre
if (state == NULL) {
return;
}
if (thread->is_in_VTMT()) {
return; // no events should be posted if thread is in a VTMT transition
}

EVT_TRIG_TRACE(JVMTI_EVENT_EXCEPTION, ("[%s] Trg Exception thrown triggered",
JvmtiTrace::safe_get_thread_name(thread)));
@@ -2107,6 +2116,10 @@ void JvmtiExport::post_field_access_by_jni(JavaThread *thread, oop obj,
// function don't make the call unless there is a Java context.
assert(thread->has_last_Java_frame(), "must be called with a Java context");

if (thread->is_in_VTMT()) {
return; // no events should be posted if thread is in a VTMT transition
}

ResourceMark rm;
fieldDescriptor fd;
// if get_field_descriptor finds fieldID to be invalid, then we just bail
@@ -2139,6 +2152,10 @@ void JvmtiExport::post_field_access(JavaThread *thread, Method* method,
if (state == NULL) {
return;
}
if (thread->is_in_VTMT()) {
return; // no events should be posted if thread is in a VTMT transition
}

EVT_TRIG_TRACE(JVMTI_EVENT_FIELD_ACCESS, ("[%s] Trg Field Access event triggered",
JvmtiTrace::safe_get_thread_name(thread)));
JvmtiEnvThreadStateIterator it(state);
@@ -2185,6 +2202,10 @@ void JvmtiExport::post_field_modification_by_jni(JavaThread *thread, oop obj,
// function don't make the call unless there is a Java context.
assert(thread->has_last_Java_frame(), "must be called with Java context");

if (thread->is_in_VTMT()) {
return; // no events should be posted if thread is in a VTMT transition
}

ResourceMark rm;
fieldDescriptor fd;
// if get_field_descriptor finds fieldID to be invalid, then we just bail
@@ -2212,6 +2233,10 @@ void JvmtiExport::post_raw_field_modification(JavaThread *thread, Method* method
address location, Klass* field_klass, Handle object, jfieldID field,
char sig_type, jvalue *value) {

if (thread->is_in_VTMT()) {
return; // no events should be posted if thread is in a VTMT transition
}

if (sig_type == JVM_SIGNATURE_INT || sig_type == JVM_SIGNATURE_BOOLEAN ||
sig_type == JVM_SIGNATURE_BYTE || sig_type == JVM_SIGNATURE_CHAR ||
sig_type == JVM_SIGNATURE_SHORT) {
@@ -2283,6 +2308,10 @@ void JvmtiExport::post_field_modification(JavaThread *thread, Method* method,
if (state == NULL) {
return;
}
if (thread->is_in_VTMT()) {
return; // no events should be posted if thread is in a VTMT transition
}

EVT_TRIG_TRACE(JVMTI_EVENT_FIELD_MODIFICATION,
("[%s] Trg Field Modification event triggered",
JvmtiTrace::safe_get_thread_name(thread)));
@@ -2322,6 +2351,10 @@ void JvmtiExport::post_native_method_bind(Method* method, address* function_ptr)
EVT_TRIG_TRACE(JVMTI_EVENT_NATIVE_METHOD_BIND, ("[%s] Trg Native Method Bind event triggered",
JvmtiTrace::safe_get_thread_name(thread)));

if (thread->is_in_VTMT()) {
return; // no events should be posted if thread is in a VTMT transition
}

if (JvmtiEventController::is_enabled(JVMTI_EVENT_NATIVE_METHOD_BIND)) {
JvmtiEnvIterator it;
for (JvmtiEnv* env = it.first(); env != NULL; env = it.next(env)) {
@@ -2625,6 +2658,9 @@ void JvmtiExport::post_monitor_contended_enter(JavaThread *thread, ObjectMonitor
if (state == NULL) {
return;
}
if (thread->is_in_VTMT()) {
return; // no events should be posted if thread is in a VTMT transition
}

HandleMark hm(thread);
Handle h(thread, object);
@@ -2656,6 +2692,9 @@ void JvmtiExport::post_monitor_contended_entered(JavaThread *thread, ObjectMonit
if (state == NULL) {
return;
}
if (thread->is_in_VTMT()) {
return; // no events should be posted if thread is in a VTMT transition
}

HandleMark hm(thread);
Handle h(thread, object);
@@ -2687,6 +2726,9 @@ void JvmtiExport::post_monitor_wait(JavaThread *thread, oop object,
if (state == NULL) {
return;
}
if (thread->is_in_VTMT()) {
return; // no events should be posted if thread is in a VTMT transition
}

HandleMark hm(thread);
Handle h(thread, object);
@@ -2719,6 +2761,9 @@ void JvmtiExport::post_monitor_waited(JavaThread *thread, ObjectMonitor *obj_mnt
if (state == NULL) {
return;
}
if (thread->is_in_VTMT()) {
return; // no events should be posted if thread is in a VTMT transition
}

HandleMark hm(thread);
Handle h(thread, object);
@@ -2751,6 +2796,9 @@ void JvmtiExport::post_vm_object_alloc(JavaThread *thread, oop object) {
if (object == NULL) {
return;
}
if (thread->is_in_VTMT()) {
return; // no events should be posted if thread is in a VTMT transition
}
HandleMark hm(thread);
Handle h(thread, object);
JvmtiEnvIterator it;
@@ -2783,6 +2831,9 @@ void JvmtiExport::post_sampled_object_alloc(JavaThread *thread, oop object) {
if (object == NULL) {
return;
}
if (thread->is_in_VTMT()) {
return; // no events should be posted if thread is in a VTMT transition
}
HandleMark hm(thread);
Handle h(thread, object);

@@ -220,6 +220,7 @@ JvmtiVTMTDisabler::disable_VTMT() {
ThreadBlockInVM tbivm(thread);
MonitorLocker ml(JvmtiVTMT_lock, Mutex::_no_safepoint_check_flag);

assert(!thread->is_in_VTMT(), "VTMT sanity check");
_VTMT_disable_count++;

// Block while some mount/unmount transitions are in progress.

0 comments on commit c881822

Please sign in to comment.