changeset 1255:17c1ab8b1528

Amend 7901463 with cleaner VM version string when profilers are enabled.
author shade
date Mon, 13 Jul 2015 23:53:10 +0300
parents 136a27b73ec5
children a5592bff900c
files jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java jmh-core/src/main/java/org/openjdk/jmh/util/Utils.java jmh-core/src/test/java/org/openjdk/jmh/runner/RunnerTest.java
diffstat 3 files changed, 27 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Mon Jul 13 23:36:49 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Mon Jul 13 23:53:10 2015 +0300
@@ -574,9 +574,8 @@
             printOut = forcePrint || printOut;
             printErr = forcePrint || printErr;
 
-            List<String> commandString = getSeparateExecutionCommand(params, javaInvokeOptions, javaOptions);
-            List<String> forkedString  = getForkedMainCommand(commandString, server.getHost(), server.getPort());
-            List<String> versionString = getVersionMainCommand(commandString);
+            List<String> forkedString  = getForkedMainCommand(params, javaInvokeOptions, javaOptions, server.getHost(), server.getPort());
+            List<String> versionString = getVersionMainCommand(params);
 
             String opts = Utils.join(params.getJvmArgs(), " ");
             if (opts.trim().isEmpty()) {
@@ -754,15 +753,11 @@
     }
 
     /**
-     * Helper method for assembling the command to execute the forked JVM with
-     *
-     * @param benchmark benchmark to execute
-     * @param javaInvokeOptions prepend these commands before JVM invocation
-     * @param javaOptions add these options to JVM command string
-     * @return the final command to execute
+     * @param host host VM host
+     * @param port host VM port
+     * @return
      */
-    List<String> getSeparateExecutionCommand(BenchmarkParams benchmark, List<String> javaInvokeOptions, List<String> javaOptions) {
-
+    List<String> getForkedMainCommand(BenchmarkParams benchmark, List<String> javaInvokeOptions, List<String> javaOptions, String host, int port) {
         List<String> command = new ArrayList<String>();
 
         // prefix java invoke options, if any profiler wants it
@@ -788,18 +783,6 @@
             command.add(System.getProperty("java.class.path"));
         }
 
-        return command;
-    }
-
-    /**
-     * @param baseLine base options
-     * @param host host VM host
-     * @param port host VM port
-     * @return
-     */
-    List<String> getForkedMainCommand(List<String> baseLine, String host, int port) {
-        List<String> command = new ArrayList<String>(baseLine);
-
         command.add(ForkedMain.class.getName());
 
         // Forked VM assumes the exact order of arguments:
@@ -812,12 +795,24 @@
     }
 
     /**
-     * @param baseLine base options
      * @return
      */
-    List<String> getVersionMainCommand(List<String> baseLine) {
-        List<String> command = new ArrayList<String>(baseLine);
+    List<String> getVersionMainCommand(BenchmarkParams benchmark) {
+        List<String> command = new ArrayList<String>();
+
+        // use supplied jvm, if given
+        command.add(benchmark.getJvm());
+
+        // assemble final process command
+        command.add("-cp");
+        if (Utils.isWindows()) {
+            command.add('"' + System.getProperty("java.class.path") + '"');
+        } else {
+            command.add(System.getProperty("java.class.path"));
+        }
+
         command.add(VersionMain.class.getName());
+
         return command;
     }
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/Utils.java	Mon Jul 13 23:36:49 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/Utils.java	Mon Jul 13 23:53:10 2015 +0300
@@ -287,11 +287,10 @@
     public static String getCurrentJvmVersion() {
         StringWriter sw = new StringWriter();
         PrintWriter pw = new PrintWriter(sw);
-        pw.print(System.getProperty("java.vm.name"));
-        pw.print(" (");
+        pw.print("JDK ");
+        pw.print(System.getProperty("java.version"));
+        pw.print(", VM ");
         pw.print(System.getProperty("java.vm.version"));
-        pw.print("), JDK ");
-        pw.print(System.getProperty("java.version"));
         return sw.toString();
     }
 
--- a/jmh-core/src/test/java/org/openjdk/jmh/runner/RunnerTest.java	Mon Jul 13 23:36:49 2015 +0300
+++ b/jmh-core/src/test/java/org/openjdk/jmh/runner/RunnerTest.java	Mon Jul 13 23:53:10 2015 +0300
@@ -63,8 +63,7 @@
                 Mode.Throughput, null, TimeUnit.SECONDS, 1,
                 Utils.getCurrentJvm(), Collections.<String>emptyList(),
                 TimeValue.days(1));
-        List<String> command = blade.getSeparateExecutionCommand(bp, Collections.<String>emptyList(), Collections.<String>emptyList());
-        command = blade.getForkedMainCommand(command, DUMMY_HOST, DUMMY_PORT);
+        List<String> command = blade.getForkedMainCommand(bp, Collections.<String>emptyList(), Collections.<String>emptyList(), DUMMY_HOST, DUMMY_PORT);
 
         // expecting 1 compile command file
         List<String> files = CompilerHints.getCompileCommandFiles(command);
@@ -93,8 +92,7 @@
                 Mode.Throughput, null, TimeUnit.SECONDS, 1,
                 Utils.getCurrentJvm(), Arrays.asList(CompilerHints.XX_COMPILE_COMMAND_FILE + tempHints),
                 TimeValue.days(1));
-        List<String> command = blade.getSeparateExecutionCommand(bp, Collections.<String>emptyList(), Collections.<String>emptyList());
-        command = blade.getForkedMainCommand(command, DUMMY_HOST, DUMMY_PORT);
+        List<String> command = blade.getForkedMainCommand(bp, Collections.<String>emptyList(), Collections.<String>emptyList(), DUMMY_HOST, DUMMY_PORT);
 
         // expecting 1 compile command file
         List<String> files = CompilerHints.getCompileCommandFiles(command);
@@ -128,8 +126,7 @@
                 Utils.getCurrentJvm(),
                 Arrays.asList(CompilerHints.XX_COMPILE_COMMAND_FILE + tempHints1, CompilerHints.XX_COMPILE_COMMAND_FILE + tempHints2),
                 TimeValue.days(1));
-        List<String> command = blade.getSeparateExecutionCommand(bp, Collections.<String>emptyList(), Collections.<String>emptyList());
-        command = blade.getForkedMainCommand(command, DUMMY_HOST, DUMMY_PORT);
+        List<String> command = blade.getForkedMainCommand(bp, Collections.<String>emptyList(), Collections.<String>emptyList(), DUMMY_HOST, DUMMY_PORT);
 
         // expecting 1 compile command file
         List<String> files = CompilerHints.getCompileCommandFiles(command);