# HG changeset patch # User rehn # Date 1497513164 -7200 # Node ID d20828de9e39287873b08b37b86771790bb7b4c8 # Parent 9c0aa7bc3fe34eaffd5d347eaa49a7c9f21fbb1e 8181859: Monitor deflation is not checked in cleanup path Reviewed-by: sspitsyn, dcubed, shade, cvarming diff -r 9c0aa7bc3fe3 -r d20828de9e39 hotspot/src/share/vm/runtime/globals.hpp --- a/hotspot/src/share/vm/runtime/globals.hpp Wed Jun 14 08:47:27 2017 +0200 +++ b/hotspot/src/share/vm/runtime/globals.hpp Thu Jun 15 09:52:44 2017 +0200 @@ -1184,6 +1184,12 @@ \ product(bool, MonitorInUseLists, true, "Track Monitors for Deflation") \ \ + experimental(intx, MonitorUsedDeflationThreshold, 90, \ + "Percentage of used monitors before triggering cleanup " \ + "safepoint which deflates monitors (0 is off). " \ + "The check is performed on GuaranteedSafepointInterval.") \ + range(0, 100) \ + \ experimental(intx, SyncFlags, 0, "(Unsafe, Unstable) " \ "Experimental Sync flags") \ \ diff -r 9c0aa7bc3fe3 -r d20828de9e39 hotspot/src/share/vm/runtime/safepoint.cpp --- a/hotspot/src/share/vm/runtime/safepoint.cpp Wed Jun 14 08:47:27 2017 +0200 +++ b/hotspot/src/share/vm/runtime/safepoint.cpp Thu Jun 15 09:52:44 2017 +0200 @@ -525,6 +525,8 @@ } bool SafepointSynchronize::is_cleanup_needed() { + // Need a safepoint if there are many monitors to deflate. + if (ObjectSynchronizer::is_cleanup_needed()) return true; // Need a safepoint if some inline cache buffers is non-empty if (!InlineCacheBuffer::is_empty()) return true; return false; diff -r 9c0aa7bc3fe3 -r d20828de9e39 hotspot/src/share/vm/runtime/synchronizer.cpp --- a/hotspot/src/share/vm/runtime/synchronizer.cpp Wed Jun 14 08:47:27 2017 +0200 +++ b/hotspot/src/share/vm/runtime/synchronizer.cpp Thu Jun 15 09:52:44 2017 +0200 @@ -962,6 +962,21 @@ return block; } +static bool monitors_used_above_threshold() { + if (gMonitorPopulation == 0) { + return false; + } + int monitors_used = gMonitorPopulation - gMonitorFreeCount; + int monitor_usage = (monitors_used * 100LL) / gMonitorPopulation; + return monitor_usage > MonitorUsedDeflationThreshold; +} + +bool ObjectSynchronizer::is_cleanup_needed() { + if (MonitorUsedDeflationThreshold > 0) { + return monitors_used_above_threshold(); + } + return false; +} void ObjectSynchronizer::oops_do(OopClosure* f) { if (MonitorInUseLists) { diff -r 9c0aa7bc3fe3 -r d20828de9e39 hotspot/src/share/vm/runtime/synchronizer.hpp --- a/hotspot/src/share/vm/runtime/synchronizer.hpp Wed Jun 14 08:47:27 2017 +0200 +++ b/hotspot/src/share/vm/runtime/synchronizer.hpp Thu Jun 15 09:52:44 2017 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -135,6 +135,7 @@ static bool deflate_monitor(ObjectMonitor* mid, oop obj, ObjectMonitor** freeHeadp, ObjectMonitor** freeTailp); + static bool is_cleanup_needed(); static void oops_do(OopClosure* f); // Process oops in thread local used monitors static void thread_local_used_oops_do(Thread* thread, OopClosure* f);