Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-15282: pull tuned vm options into a separate aspect

Dawid Weisse9813bd701be
diff --git a/build.gradle b/build.gradle
index a3be7c0bee9..86938da7d17 100644
--- a/build.gradle
+++ b/build.gradle
@@ -180,6 +180,7 @@ apply from: file('gradle/hacks/solr.findbugs.gradle')
apply from: file('gradle/hacks/gradle.gradle')
apply from: file('gradle/hacks/hashmapAssertions.gradle')
+apply from: file('gradle/hacks/turbocharge-jvm-opts.gradle')
apply from: file('gradle/solr-tlp-migration/inaccessible-test-sources.gradle')
diff --git a/gradle/documentation/render-javadoc.gradle b/gradle/documentation/render-javadoc.gradle
index a0a35b2b9c8..2e462d6d8ed 100644
--- a/gradle/documentation/render-javadoc.gradle
+++ b/gradle/documentation/render-javadoc.gradle
@@ -228,6 +228,10 @@ class RenderJavadocTask extends DefaultTask {
@Input
List<String> javadocMissingIgnore = []
+ @Input
+ @Optional
+ ListProperty<String> extraOpts = project.objects.listProperty(String)
+
@Nullable
@Optional
@Input
@@ -296,6 +300,9 @@ class RenderJavadocTask extends DefaultTask {
opts << [ '-quiet' ]
+ // Add all extra options, if any.
+ opts.addAll(extraOpts.orElse([]).get())
+
def allOfflineLinks = [:]
allOfflineLinks.putAll(offlineLinks)
@@ -341,7 +348,16 @@ class RenderJavadocTask extends DefaultTask {
opts << [ '--release', 11 ]
opts << '-Xdoclint:all,-missing'
- // Temporary file that holds all javadoc options for the current task.
+ // Increase Javadoc's heap.
+ opts += [ "-J-Xmx512m" ]
+ // Force locale to be "en_US" (fix for: https://bugs.openjdk.java.net/browse/JDK-8222793)
+ opts += [ "-J-Duser.language=en", "-J-Duser.country=US" ]
+
+ // -J options have to be passed on command line, they are not interpreted if passed via args file.
+ def jOpts = opts.findAll { opt -> opt instanceof String && opt.startsWith("-J") }
+ opts.removeAll(jOpts)
+
+ // Temporary file that holds all javadoc options for the current task (except jOpts)
optionsFile.withWriter("UTF-8", { writer ->
// escapes an option with single quotes or whitespace to be passed in the options.txt file for
def escapeJavadocOption = { String s -> (s =~ /[ '"]/) ? ("'" + s.replaceAll(/[\\'"]/, /\\$0/) + "'") : s }
@@ -389,11 +405,7 @@ class RenderJavadocTask extends DefaultTask {
errorOutput = wrapped
args += [ "@${optionsFile}" ]
-
- // -J flags can't be passed via options file... (an error "javadoc: error - invalid flag: -J-Xmx512m" occurs.)
- args += [ "-J-Xmx512m" ]
- // force locale to be "en_US" (fix for: https://bugs.openjdk.java.net/browse/JDK-8222793)
- args += [ "-J-Duser.language=en", "-J-Duser.country=US" ]
+ args += jOpts
ignoreExitValue true
}
diff --git a/gradle/hacks/turbocharge-jvm-opts.gradle b/gradle/hacks/turbocharge-jvm-opts.gradle
new file mode 100644
index 00000000000..cdb226a89b3
--- /dev/null
+++ b/gradle/hacks/turbocharge-jvm-opts.gradle
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// LUCENE-9861: tune JVM options for short-lived java subprocesses.
+allprojects {
+ def vmOpts = [
+ '-XX:+UseParallelGC',
+ '-XX:TieredStopAtLevel=1'
+ ]
+
+ // Inject vm options into custom javadoc rendering. We can't refer
+ // to the task type because it's dynamic.
+ tasks.matching { it.name in ["renderJavadoc", "renderSiteJavadoc"] }.all {
+ extraOpts.addAll(vmOpts.collect {"-J" + it})
+ }
+
+ // Inject vm options into any JavaExec task... We could narrow it
+ // down but I don't think there is any harm in keeping it broad.
+ tasks.withType(JavaExec) {
+ jvmArgs += vmOpts
+ }
+}
\ No newline at end of file