changeset 406:cf0d7432acfd

Destruct @State objects after the run: among other things, this also resets @Params for the next non-forked run.
author shade
date Tue, 18 Feb 2014 16:55:00 +0400
parents 5a5adf4bdb6c
children d349049dc58b
files jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java jmh-core/src/main/java/org/openjdk/jmh/processor/internal/StateObjectHandler.java
diffstat 2 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java	Tue Feb 18 02:07:05 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/GenerateMicroBenchmarkProcessor.java	Tue Feb 18 16:55:00 2014 +0400
@@ -1049,6 +1049,7 @@
 
         writer.println(ident(prefix) + "if (control.isLastIteration()) {");
         for (String s : states.getRunTearDowns(method)) writer.println(ident(prefix + 1) + s);
+        for (String s : states.getStateDestructors(method)) writer.println(ident(prefix + 1) + s);
         writer.println(ident(prefix) + "}");
     }
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/StateObjectHandler.java	Tue Feb 18 02:07:05 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/StateObjectHandler.java	Tue Feb 18 16:55:00 2014 +0400
@@ -461,6 +461,29 @@
         return result;
     }
 
+    public Collection<String> getStateDestructors(Element method) {
+        List<String> result = new ArrayList<String>();
+        for (StateObject so : cons(args.get(method.getSimpleName().toString()), implicits.values())) {
+            if (so.scope != Scope.Benchmark) continue;
+            result.add("synchronized(this.getClass()) {");
+            result.add("    " + so.fieldIdentifier + " = null;");
+            result.add("}");
+        }
+
+        for (StateObject so : cons(args.get(method.getSimpleName().toString()), implicits.values())) {
+            if (so.scope != Scope.Thread) continue;
+            result.add("" + so.fieldIdentifier + " = null;");
+        }
+
+        for (StateObject so : cons(args.get(method.getSimpleName().toString()), implicits.values())) {
+            if (so.scope != Scope.Group) continue;
+            result.add("synchronized(this.getClass()) {");
+            result.add("    " + so.fieldIdentifier + "_map.remove(threadControl.group);");
+            result.add("}");
+        }
+        return result;
+    }
+
     public List<String> getStateGetters(Element method) {
         List<String> result = new ArrayList<String>();
         for (StateObject so : cons(args.get(method.getSimpleName().toString()), implicits.values(), getControls())) {