changeset 1393:c51589e906ad

7901865: Blackhole.consume(Object) retains consumed objects
author shade
date Tue, 13 Dec 2016 19:45:00 +0100
parents ef24f1b5de08
children 8b06fb523516
files jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java jmh-core/src/main/java/org/openjdk/jmh/infra/Blackhole.java
diffstat 2 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java	Tue Dec 06 12:40:19 2016 +0100
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java	Tue Dec 13 19:45:00 2016 +0100
@@ -837,11 +837,13 @@
         writer.println(ident(2) + "this.iterationParams = control.iterationParams;");
         writer.println(ident(2) + "this.threadParams    = threadParams;");
         writer.println(ident(2) + "this.notifyControl   = control.notifyControl;");
-        writer.println(ident(2) + "this.blackhole       = new Blackhole(\"Today's password is swordfish. I understand instantiating Blackholes directly is dangerous.\");");
+        writer.println(ident(2) + "if (this.blackhole == null) {");
+        writer.println(ident(3) + "this.blackhole = new Blackhole(\"Today's password is swordfish. I understand instantiating Blackholes directly is dangerous.\");");
+        writer.println(ident(2) + "}");
     }
 
     private void methodEpilog(PrintWriter writer, MethodGroup methodGroup) {
-        writer.println(ident(3) + "this.blackhole = null;");
+        writer.println(ident(3) + "this.blackhole.purge();");
     }
 
     private String prefix(String argList) {
--- a/jmh-core/src/main/java/org/openjdk/jmh/infra/Blackhole.java	Tue Dec 06 12:40:19 2016 +0100
+++ b/jmh-core/src/main/java/org/openjdk/jmh/infra/Blackhole.java	Tue Dec 13 19:45:00 2016 +0100
@@ -281,6 +281,14 @@
     }
 
     /**
+     * Clear internal waste, if any.
+     */
+    public void purge() {
+        obj1 = null;
+        objs1 = null;
+    }
+
+    /**
      * Consume object. This call provides a side effect preventing JIT to eliminate dependent computations.
      *
      * @param obj object to consume.