changeset 287:332e380452df

@CompilerControl: only create the compile hint list once.
author shade
date Mon, 02 Dec 2013 17:42:17 +0400
parents bec0afa5489c
children fdca4b1af8b7
files jmh-core/src/main/java/org/openjdk/jmh/runner/CompilerHints.java jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java
diffstat 2 files changed, 28 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/CompilerHints.java	Mon Dec 02 17:35:24 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/CompilerHints.java	Mon Dec 02 17:42:17 2013 +0400
@@ -25,7 +25,10 @@
 package org.openjdk.jmh.runner;
 
 import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileWriter;
 import java.io.IOException;
+import java.io.PrintWriter;
 import java.io.Reader;
 import java.util.Set;
 import java.util.TreeSet;
@@ -34,6 +37,8 @@
 
     public static final String LIST = "/META-INF/CompilerHints";
     private static volatile CompilerHints defaultList;
+    private static volatile String hintsFile;
+
 
     private final Set<String> hints;
 
@@ -44,6 +49,28 @@
         return defaultList;
     }
 
+    public static String hintsFile() {
+        if (hintsFile == null) {
+            try {
+                File file = File.createTempFile("jmh", "compilecommand");
+
+                FileWriter writer = new FileWriter(file);
+                PrintWriter pw = new PrintWriter(writer);
+                pw.println("quiet");
+                for (String l : defaultList().get()) {
+                    pw.println(l);
+                }
+                pw.close();
+                writer.close();
+
+                hintsFile = file.getAbsolutePath();
+            } catch (IOException e) {
+                throw new IllegalStateException("Error creating compiler hints file", e);
+            }
+        }
+        return hintsFile;
+    }
+
     public static CompilerHints fromResource(String resource) {
         return new CompilerHints(null, resource, null);
     }
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Mon Dec 02 17:35:24 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Mon Dec 02 17:42:17 2013 +0400
@@ -475,26 +475,7 @@
         }
 
         // add any compiler oracle hints
-        {
-            Set<String> hints = CompilerHints.defaultList().get();
-            if (!hints.isEmpty()) {
-                try {
-                    File file = File.createTempFile("jmh", "compilecommand");
-                    command.add("-XX:CompileCommandFile=" + file.getAbsolutePath());
-
-                    FileWriter writer = new FileWriter(file);
-                    PrintWriter pw = new PrintWriter(writer);
-                    pw.println("quiet");
-                    for (String l : hints) {
-                        pw.println(l);
-                    }
-                    pw.close();
-                    writer.close();
-                } catch (IOException e) {
-                    throw new IllegalStateException("Error creating compiler hints file", e);
-                }
-            }
-        }
+        command.add("-XX:CompileCommandFile=" + CompilerHints.hintsFile());
 
         // assemble final process command
         command.add("-cp");