diff --git a/test/hotspot/jtreg/runtime/locking/TestRecursiveMonitorChurn.java b/test/hotspot/jtreg/runtime/locking/TestRecursiveMonitorChurn.java index 19dd90015bf..806f32aad88 100644 --- a/test/hotspot/jtreg/runtime/locking/TestRecursiveMonitorChurn.java +++ b/test/hotspot/jtreg/runtime/locking/TestRecursiveMonitorChurn.java @@ -70,6 +70,18 @@ public class TestRecursiveMonitorChurn { if (pre_monitor_count != post_monitor_count) { final long monitor_count_change = post_monitor_count - pre_monitor_count; System.out.println("Unexpected change in monitor count: " + monitor_count_change); + + // Intermittent deflation and inflation may occur due to running the test + // with stress flags (like DeoptimizeALot) or with added instrumentation + // which runs in the same VM. + // An arbitrary fuzzy max difference of 10 (= 0.01% of COUNT) is chosen to + // allow for these occurrences to be skipped while still catching regressions. + final long fuzzy_max_difference = 10; + if (Math.abs(monitor_count_change) < fuzzy_max_difference) { + final String type = monitor_count_change < 0 ? "deflation" : "inflation"; + throw new SkippedException("Intermittent " + type + " detected. Invalid test."); + } + if (monitor_count_change < 0) { throw new RuntimeException("Unexpected Deflation"); }