--- old/src/hotspot/share/runtime/serviceThread.cpp 2019-05-25 10:46:33.902883664 -0400 +++ new/src/hotspot/share/runtime/serviceThread.cpp 2019-05-25 10:46:33.186883626 -0400 @@ -127,6 +127,7 @@ bool protection_domain_table_work = false; bool oopstorage_work = false; bool oopstorages_cleanup[oopstorage_count] = {}; // Zero (false) initialize. + bool deflate_idle_monitors = false; JvmtiDeferredEvent jvmti_event; { // Need state transition ThreadBlockInVM so that this thread @@ -154,11 +155,14 @@ (protection_domain_table_work = SystemDictionary::pd_cache_table()->has_work()) | (oopstorage_work = needs_oopstorage_cleanup(oopstorages, oopstorages_cleanup, - oopstorage_count))) - - == 0) { + oopstorage_count)) | + (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) { @@ -201,6 +205,26 @@ if (oopstorage_work) { cleanup_oopstorages(oopstorages, oopstorages_cleanup, oopstorage_count); } + + 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. + 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 + } } }