Skip to content

Commit

Permalink
8318757: VM_ThreadDump asserts in interleaved ObjectMonitor::deflate_…
Browse files Browse the repository at this point in the history
…monitor calls

8319896: Remove monitor deflation from final audit
8320515: assert(monitor->object_peek() != nullptr) failed: Owned monitors should not have a dead object
8325437: Safepoint polling in monitor deflation can cause massive logs

Reviewed-by: stefank, adinn
Backport-of: 87be6b69fe985eee01fc3344f9153d774db792c1
  • Loading branch information
shipilev committed Mar 18, 2024
1 parent cc65d0d commit d1af31b
Show file tree
Hide file tree
Showing 17 changed files with 642 additions and 267 deletions.
3 changes: 2 additions & 1 deletion make/test/JtregNativeHotspot.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ BUILD_HOTSPOT_JTREG_EXECUTABLES_LIBS_exesigtest := -ljvm

ifeq ($(call isTargetOs, windows), true)
BUILD_HOTSPOT_JTREG_EXECUTABLES_CFLAGS_exeFPRegs := -MT
BUILD_HOTSPOT_JTREG_EXCLUDE += exesigtest.c libterminatedThread.c libTestJNI.c libCompleteExit.c libTestPsig.c libnativeStack.c exeGetCreatedJavaVMs.c
BUILD_HOTSPOT_JTREG_EXCLUDE += exesigtest.c libterminatedThread.c libTestJNI.c libCompleteExit.c libMonitorWithDeadObjectTest.c libTestPsig.c libnativeStack.c exeGetCreatedJavaVMs.c
BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libatExit := jvm.lib
BUILD_HOTSPOT_JTREG_EXECUTABLES_LIBS_exedaemonDestroy := jvm.lib
else
Expand Down Expand Up @@ -1508,6 +1508,7 @@ else
BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libterminatedThread += -lpthread
BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libatExit += -ljvm
BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libCompleteExit += -lpthread
BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libMonitorWithDeadObjectTest += -lpthread
BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libnativeStack += -lpthread
BUILD_HOTSPOT_JTREG_EXECUTABLES_LIBS_exeGetCreatedJavaVMs := -ljvm -lpthread
endif
Expand Down
11 changes: 9 additions & 2 deletions src/hotspot/share/prims/jvmtiEnvBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ JvmtiEnvBase::get_owned_monitors(JavaThread *calling_thread, JavaThread* java_th

// Get off stack monitors. (e.g. acquired via jni MonitorEnter).
JvmtiMonitorClosure jmc(calling_thread, owned_monitors_list, this);
ObjectSynchronizer::monitors_iterate(&jmc, java_thread);
ObjectSynchronizer::owned_monitors_iterate(&jmc, java_thread);
err = jmc.error();

return err;
Expand All @@ -1015,7 +1015,7 @@ JvmtiEnvBase::get_owned_monitors(JavaThread* calling_thread, JavaThread* java_th

// Get off stack monitors. (e.g. acquired via jni MonitorEnter).
JvmtiMonitorClosure jmc(calling_thread, owned_monitors_list, this);
ObjectSynchronizer::monitors_iterate(&jmc, java_thread);
ObjectSynchronizer::owned_monitors_iterate(&jmc, java_thread);
err = jmc.error();

return err;
Expand Down Expand Up @@ -2178,6 +2178,13 @@ JvmtiMonitorClosure::do_monitor(ObjectMonitor* mon) {
}
// Filter out on stack monitors collected during stack walk.
oop obj = mon->object();

if (obj == nullptr) {
// This can happen if JNI code drops all references to the
// owning object.
return;
}

bool found = false;
for (int j = 0; j < _owned_monitors_list->length(); j++) {
jobject jobj = ((jvmtiMonitorStackDepthInfo*)_owned_monitors_list->at(j))->monitor;
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/prims/whitebox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1833,7 +1833,7 @@ WB_END

WB_ENTRY(jboolean, WB_DeflateIdleMonitors(JNIEnv* env, jobject wb))
log_info(monitorinflation)("WhiteBox initiated DeflateIdleMonitors");
return ObjectSynchronizer::request_deflate_idle_monitors();
return ObjectSynchronizer::request_deflate_idle_monitors_from_wb();
WB_END

WB_ENTRY(void, WB_ForceSafepoint(JNIEnv* env, jobject wb))
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/runtime/monitorDeflationThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ void MonitorDeflationThread::monitor_deflation_thread_entry(JavaThread* jt, TRAP
}
}

(void)ObjectSynchronizer::deflate_idle_monitors(/* ObjectMonitorsHashtable is not needed here */ nullptr);
(void)ObjectSynchronizer::deflate_idle_monitors();
}
}
10 changes: 0 additions & 10 deletions src/hotspot/share/runtime/objectMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,16 +509,6 @@ bool ObjectMonitor::deflate_monitor() {
return false;
}

if (ObjectSynchronizer::is_final_audit() && owner_is_DEFLATER_MARKER()) {
// The final audit can see an already deflated ObjectMonitor on the
// in-use list because MonitorList::unlink_deflated() might have
// blocked for the final safepoint before unlinking all the deflated
// monitors.
assert(contentions() < 0, "must be negative: contentions=%d", contentions());
// Already returned 'true' when it was originally deflated.
return false;
}

const oop obj = object_peek();

if (obj == nullptr) {
Expand Down
Loading

1 comment on commit d1af31b

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.