--- old/src/hotspot/share/runtime/serviceThread.cpp 2020-02-03 17:39:31.000000000 -0500 +++ new/src/hotspot/share/runtime/serviceThread.cpp 2020-02-03 17:39:30.000000000 -0500 @@ -110,6 +110,7 @@ bool thread_id_table_work = false; bool protection_domain_table_work = false; bool oopstorage_work = false; + bool deflate_idle_monitors = false; JvmtiDeferredEvent jvmti_event; { // Need state transition ThreadBlockInVM so that this thread @@ -136,10 +137,14 @@ (resolved_method_table_work = ResolvedMethodTable::has_work()) | (thread_id_table_work = ThreadIdTable::has_work()) | (protection_domain_table_work = SystemDictionary::pd_cache_table()->has_work()) | - (oopstorage_work = OopStorage::has_cleanup_work_and_reset()) + (oopstorage_work = OopStorage::has_cleanup_work_and_reset()) | + (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) { @@ -191,6 +196,10 @@ if (oopstorage_work) { cleanup_oopstorages(); } + + if (deflate_idle_monitors) { + ObjectSynchronizer::deflate_idle_monitors_using_JT(); + } } }