--- old/src/hotspot/share/runtime/serviceThread.cpp 2019-05-25 10:47:53.734887830 -0400 +++ new/src/hotspot/share/runtime/serviceThread.cpp 2019-05-25 10:47:52.750887779 -0400 @@ -156,10 +156,13 @@ (oopstorage_work = needs_oopstorage_cleanup(oopstorages, oopstorages_cleanup, oopstorage_count)) | - (deflate_idle_monitors = ObjectSynchronizer::gOmShouldDeflateIdleMonitors()) + (deflate_idle_monitors = ObjectSynchronizer::is_async_deflation_needed()) ) == 0) { // Wait until notified that there is some work to do. - ml.wait(); + // If AsyncDeflateIdleMonitors, then we wait for + // GuaranteedSafepointInterval so that is_async_deflation_needed() + // is checked at the same interval. + ml.wait(AsyncDeflateIdleMonitors ? GuaranteedSafepointInterval : 0); } if (has_jvmti_events) { @@ -205,9 +208,22 @@ if (deflate_idle_monitors) { // Deflate any global idle monitors. + ObjectSynchronizer::deflate_global_idle_monitors_using_JT(); + // deflate_per_thread_idle_monitors_using_JT() is called by // each JavaThread from ObjectSynchronizer::omAlloc() as needed. - ObjectSynchronizer::deflate_global_idle_monitors_using_JT(); + int count = 0; + for (JavaThreadIteratorWithHandle jtiwh; JavaThread *jt = jtiwh.next(); ) { + if (jt->omInUseCount > 0) { + // This JavaThread is using monitors so mark it. + jt->omShouldDeflateIdleMonitors = true; + count++; + } + } + if (count > 0) { + log_debug(monitorinflation)("requesting async deflation of idle monitors for %d thread(s).", count); + } + ObjectSynchronizer::set_is_async_deflation_requested(false); // async deflation has been requested } } }