# HG changeset patch # User hannesw # Date 1413806957 -7200 # Node ID bf5f28dafa7c49aef52c4ca30876afd5e2e5439d # Parent 42fc6bc42daec8ad23e2612e20e1c3af2108ce5b 8060724: ant test262parallel in Nashorn spends a significant amount of time after almost all the tests are run Reviewed-by: lagergren, attila, sundar diff -r 42fc6bc42dae -r bf5f28dafa7c src/jdk/nashorn/internal/runtime/Context.java --- a/src/jdk/nashorn/internal/runtime/Context.java Mon Oct 20 18:40:42 2014 +0530 +++ b/src/jdk/nashorn/internal/runtime/Context.java Mon Oct 20 14:09:17 2014 +0200 @@ -150,6 +150,13 @@ private final Context context; private final ScriptLoader loader; private final CodeSource codeSource; + private int usageCount = 0; + private int bytesDefined = 0; + + // We reuse this installer for 10 compilations or 200000 defined bytes. Usually the first condition + // will occur much earlier, the second is a safety measure for very large scripts/functions. + private final static int MAX_USAGES = 10; + private final static int MAX_BYTES_DEFINED = 200_000; private ContextCodeInstaller(final Context context, final ScriptLoader loader, final CodeSource codeSource) { this.context = context; @@ -168,6 +175,8 @@ @Override public Class install(final String className, final byte[] bytecode) { + usageCount++; + bytesDefined += bytecode.length; final String binaryName = Compiler.binaryName(className); return loader.installClass(binaryName, bytecode, codeSource); } @@ -225,6 +234,10 @@ @Override public CodeInstaller withNewLoader() { + // Reuse this installer if we're within our limits. + if (usageCount < MAX_USAGES && bytesDefined < MAX_BYTES_DEFINED) { + return this; + } return new ContextCodeInstaller(context, context.createNewLoader(), codeSource); } diff -r 42fc6bc42dae -r bf5f28dafa7c test/src/jdk/nashorn/internal/test/framework/ParallelTestRunner.java --- a/test/src/jdk/nashorn/internal/test/framework/ParallelTestRunner.java Mon Oct 20 18:40:42 2014 +0530 +++ b/test/src/jdk/nashorn/internal/test/framework/ParallelTestRunner.java Mon Oct 20 14:09:17 2014 +0200 @@ -78,7 +78,8 @@ // ParallelTestRunner-specific private static final String TEST_JS_THREADS = "test.js.threads"; private static final String TEST_JS_REPORT_FILE = "test.js.report.file"; - private static final int THREADS = Integer.getInteger(TEST_JS_THREADS, Runtime.getRuntime().availableProcessors()); + // test262 does a lot of eval's and the JVM hates multithreaded class definition, so lower thread count is usually faster. + private static final int THREADS = Integer.getInteger(TEST_JS_THREADS, Runtime.getRuntime().availableProcessors() > 4 ? 4 : 2); private final List tests = new ArrayList<>(); private final Set orphans = new TreeSet<>();