reland: 11925 javac options (#11937)

* pass jvm args to javac  #11925

* Update net.ltgt.errorprone to the latest version so that jvm args are not overwritten, add -XX:+PrintFlagsFinal for debugging

* speed up the pure javac case too

It does not help to fork additional VMs (although error-prone will do
this since it messes with bootstrap classpath), so we avoid forking.

Instead it is best to tune org.gradle.jvmargs.

* use the flags consistently everywhere (tests and doc)

* handle the different possible alt toolchain cases

The difference is invoking 'java' versus invoking 'javac', so the args must be fed differently.

Co-authored-by: Dawid Weiss <dawid.weiss@carrotsearch.com>
This commit is contained in:
Robert Muir 2022-11-15 19:28:52 -05:00 committed by GitHub
parent 0753f48a80
commit b292151f21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 6 deletions

View File

@ -24,7 +24,7 @@ plugins {
id "org.owasp.dependencycheck" version "7.2.0"
id 'de.thetaphi.forbiddenapis' version '3.4' apply false
id "de.undercouch.download" version "5.2.0" apply false
id "net.ltgt.errorprone" version "2.0.2" apply false
id "net.ltgt.errorprone" version "3.0.1" apply false
id 'com.diffplug.spotless' version "6.5.2" apply false
id 'org.barfuin.gradle.jacocolog' version "3.0.0-RC2" apply false
}

View File

@ -68,7 +68,7 @@ systemProp.file.encoding=UTF-8
# The heap seems huge but gradle runs out of memory on lower values (don't know why).
#
# We also open up internal compiler modules for spotless/ google java format.
org.gradle.jvmargs=-Xmx3g \\
org.gradle.jvmargs=-Xmx3g -XX:TieredStopAtLevel=1 -XX:+UseParallelGC -XX:ActiveProcessorCount=1 \\
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \\
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \\
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \\

View File

@ -19,7 +19,8 @@
allprojects {
def vmOpts = [
'-XX:+UseParallelGC',
'-XX:TieredStopAtLevel=1'
'-XX:TieredStopAtLevel=1',
'-XX:ActiveProcessorCount=1'
]
// Inject vm options into custom javadoc rendering. We can't refer
@ -38,4 +39,20 @@ allprojects {
jvmArgs += vmOpts
}
// Tweak javac to not be too resource-hungry.
// This applies to any JVM when javac runs forked (e.g. error-prone)
// Avoiding the fork entirely is best.
tasks.withType(JavaCompile) { JavaCompile task ->
if (task.path == ":lucene:core:compileMain19Java") {
// uses "uschindler" toolchain method, which erases "dweiss" method, but later at configure time
task.options.forkOptions.jvmArgs += vmOpts
} else if (task.options.forkOptions.javaHome != null) {
// uses "dweiss" toolchain method
task.options.forkOptions.jvmArgs += vmOpts.collect {"-J" + it}
} else {
// native or error-prone
task.options.forkOptions.jvmArgs += vmOpts
}
}
}

View File

@ -47,7 +47,7 @@ allprojects {
description: "Number of forked test JVMs"],
[propName: 'tests.haltonfailure', value: true, description: "Halt processing on test failure."],
[propName: 'tests.jvmargs',
value: { -> propertyOrEnvOrDefault("tests.jvmargs", "TEST_JVM_ARGS", "-XX:TieredStopAtLevel=1") },
value: { -> propertyOrEnvOrDefault("tests.jvmargs", "TEST_JVM_ARGS", "-XX:TieredStopAtLevel=1 -XX:+UseParallelGC -XX:ActiveProcessorCount=1") },
description: "Arguments passed to each forked JVM."],
// Other settings.
[propName: 'tests.neverUpToDate', value: true,

View File

@ -47,7 +47,7 @@ separately from the gradle workers, for example:
tests.jvms=3
tests.heapsize=512m
tests.minheapsize=512m
tests.jvmargs=-XX:+UseParallelGC -XX:TieredStopAtLevel=1
tests.jvmargs=-XX:+UseParallelGC -XX:TieredStopAtLevel=1 -XX:ActiveProcessorCount=1
Gradle Daemon
-------------