[PATCH]: Forking benchmarks with long classpath on Windows (7)
Dávid Karnok
akarnokd at gmail.com
Thu Dec 21 10:01:51 UTC 2017
Index: jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java (revision
1434:1ddf31f810a3100b9433c3fedf24615e85b1d1a7)
+++ jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java (revision
1434+:1ddf31f810a3+)
@@ -47,6 +47,8 @@
import java.nio.channels.OverlappingFileLockException;
import java.util.*;
import java.util.concurrent.TimeUnit;
+import java.util.jar.*;
+import java.util.zip.*;
/**
* Runner executes JMH benchmarks.
@@ -826,7 +828,34 @@
// assemble final process command
command.add("-cp");
if (Utils.isWindows()) {
- command.add('"' + System.getProperty("java.class.path") + '"');
+ try {
+ File tmpFile = File.createTempFile("jmh-classpath-file",
".jar");
+ tmpFile.deleteOnExit();
+
+ StringBuilder pw = new StringBuilder();
+ for (String cp :
System.getProperty("java.class.path").split(";")) {
+ pw.append("/");
+ pw.append(cp.replace('\\', '/').replace(" ", "%20"));
+ if (!cp.endsWith(".jar")) {
+ pw.append('/');
+ }
+ pw.append(" ");
+ }
+
+ Manifest manifest = new Manifest();
+ Attributes attributes = manifest.getMainAttributes();
+ attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
+ attributes.putValue("Class-Path", pw.toString().trim());
+
+ try (JarOutputStream zout = new JarOutputStream(new
FileOutputStream(tmpFile), manifest)) {
+ ZipEntry ze = new ZipEntry("META-INF/");
+ zout.putNextEntry(ze);
+ }
+
+ command.add("\"" + tmpFile.getAbsolutePath() + "\"");
+ } catch (IOException ex) {
+ command.add('"' + System.getProperty("java.class.path") +
'"');
+ }
} else {
command.add(System.getProperty("java.class.path"));
}
2017-12-21 8:24 GMT+01:00 Aleksey Shipilev <shade at redhat.com>:
> Hi David,
>
> On 12/12/2017 11:36 AM, Dávid Karnok wrote:
> > I'd like to submit a patch (attached) to JMH's
> > org.openjdk.jmh.runner.Runner.java that creates a temporary jar file
> with
> > all classpath entries on Windows so that the command line doesn't
> overflow.
>
> The patch got stripped by the mailing list, apparently. (Wrong MIME type?)
>
> Thanks,
> -Aleksey
>
>
--
Best regards,
David Karnok
More information about the jmh-dev
mailing list