changeset 70:8e00ee4713e8

Always initialize Scope.Benchmark objects: @TearDown may be called already.
author shade
date Tue, 04 Jun 2013 13:25:13 +0400
parents 5720d6288d56
children d1e165fb0892
files jmh-core/src/main/java/org/openjdk/jmh/processor/internal/StateObjectHandler.java
diffstat 1 files changed, 7 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/StateObjectHandler.java	Tue Jun 04 13:18:42 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/StateObjectHandler.java	Tue Jun 04 13:25:13 2013 +0400
@@ -322,17 +322,17 @@
             result.add("static volatile " + so.type + " " + so.fieldIdentifier + ";");
             result.add("");
             result.add(so.type + " tryInit_" + so.fieldIdentifier + "(" + so.type + " val) throws Throwable {");
-            result.add("    if (" + so.fieldIdentifier + " == null) {");
-            result.add("        synchronized(this.getClass()) {");
-            result.add("            if (" + so.fieldIdentifier + " == null) {");
+            result.add("    synchronized(this.getClass()) {");
+            result.add("        if (" + so.fieldIdentifier + " == null) {");
+            result.add("            " + so.fieldIdentifier + " = val;");
+            result.add("        }");
+            result.add("        if (!" + so.fieldIdentifier + ".ready" + Level.Trial + ") {");
             for (HelperMethodInvocation hmi : helpersByState.get(so)) {
                 if (hmi.helperLevel != Level.Trial) continue;
                 if (hmi.type != HelperType.SETUP) continue;
-                result.add("                val." + hmi.name + "();");
+                result.add("            " + so.fieldIdentifier + "." + hmi.name + "();");
             }
-            result.add("                " + "val.ready" + Level.Trial + " = true;");
-            result.add("                " + so.fieldIdentifier + " = val;");
-            result.add("            }");
+            result.add("            " + so.fieldIdentifier + ".ready" + Level.Trial + " = true;");
             result.add("        }");
             result.add("    }");
             result.add("    return " + so.fieldIdentifier + ";");