changeset 1201:869982787a92

7901394: @TearDown(Level.Trial) should backoff when waiting
author shade
date Thu, 16 Apr 2015 23:04:20 +0300
parents 073d00004c81
children 08f4588be2f3
files jmh-core/src/main/java/org/openjdk/jmh/generators/core/StateObjectHandler.java
diffstat 1 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/core/StateObjectHandler.java	Thu Apr 16 22:27:33 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/core/StateObjectHandler.java	Thu Apr 16 23:04:20 2015 +0300
@@ -506,7 +506,21 @@
                 result.add("        " + so.type + ".tear" + helperLevel + "MutexUpdater.set(" + so.localIdentifier + ", 0);");
                 result.add("    }");
                 result.add("} else {");
+
+                // We don't need to actively busy-wait for Trial, it is way past the measurement window,
+                // and we would not need measurement threads anymore after this is over. Therefore, it
+                // is OK to exponentially back off.
+                if (helperLevel == Level.Trial) {
+                    result.add("    long " + so.localIdentifier + "_backoff = 1;");
+                }
+
                 result.add("    while (" + so.type + ".tear" + helperLevel + "MutexUpdater.get(" + so.localIdentifier + ") == 1) {");
+
+                if (helperLevel == Level.Trial) {
+                    result.add("        TimeUnit.MILLISECONDS.sleep(" + so.localIdentifier + "_backoff);");
+                    result.add("        " + so.localIdentifier + "_backoff = Math.max(1024, " + so.localIdentifier + "_backoff * 2);");
+                }
+
                 result.add("        if (Thread.interrupted()) throw new InterruptedException();");
                 result.add("    }");
                 result.add("}");