You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2021/03/23 09:39:18 UTC

[lucene] branch main updated: LUCENE-9861: pull tuned vm options into a separate aspect. (#33)

This is an automated email from the ASF dual-hosted git repository.

dweiss pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/main by this push:
     new 078d007  LUCENE-9861: pull tuned vm options into a separate aspect. (#33)
078d007 is described below

commit 078d0079d1f697dde305277b92f0a6792d6843d2
Author: Dawid Weiss <da...@carrotsearch.com>
AuthorDate: Tue Mar 23 10:39:09 2021 +0100

    LUCENE-9861: pull tuned vm options into a separate aspect. (#33)
---
 build.gradle                               |  1 +
 gradle/documentation/render-javadoc.gradle | 24 +++++++++++++++-----
 gradle/hacks/turbocharge-jvm-opts.gradle   | 36 ++++++++++++++++++++++++++++++
 gradle/validation/ecj-lint.gradle          |  3 ---
 4 files changed, 55 insertions(+), 9 deletions(-)

diff --git a/build.gradle b/build.gradle
index 2789d03..31d390e 100644
--- a/build.gradle
+++ b/build.gradle
@@ -184,3 +184,4 @@ apply from: file('gradle/documentation/render-javadoc.gradle')
 apply from: file('gradle/hacks/gradle-archives.gradle')
 apply from: file('gradle/hacks/gradle.gradle')
 apply from: file('gradle/hacks/hashmapAssertions.gradle')
+apply from: file('gradle/hacks/turbocharge-jvm-opts.gradle')
diff --git a/gradle/documentation/render-javadoc.gradle b/gradle/documentation/render-javadoc.gradle
index eecbffb..4503f8e 100644
--- a/gradle/documentation/render-javadoc.gradle
+++ b/gradle/documentation/render-javadoc.gradle
@@ -297,6 +297,10 @@ class RenderJavadocTask extends DefaultTask {
   @Input
   List<String> javadocMissingIgnore = []
 
+  @Input
+  @Optional
+  ListProperty<String> extraOpts = project.objects.listProperty(String)
+
   @Nullable
   @Optional
   @Input
@@ -365,6 +369,9 @@ class RenderJavadocTask extends DefaultTask {
 
     opts << [ '-quiet' ]
 
+    // Add all extra options, if any.
+    opts.addAll(extraOpts.orElse([]).get())
+
     def allOfflineLinks = [:]
     allOfflineLinks.putAll(offlineLinks)
 
@@ -408,7 +415,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 }
@@ -456,11 +472,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 0000000..cdb226a
--- /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
diff --git a/gradle/validation/ecj-lint.gradle b/gradle/validation/ecj-lint.gradle
index 09c4ebe..7b64157 100644
--- a/gradle/validation/ecj-lint.gradle
+++ b/gradle/validation/ecj-lint.gradle
@@ -74,9 +74,6 @@ allprojects {
         args += [ "-enableJavadoc" ]
         args += [ "-properties", file("${resources}/ecj.javadocs.prefs").absolutePath ]
 
-        // disable for now because individual file excludes cannot be applied to ecj.
-        // enabled = false
-
         doFirst {
           tmpDst.mkdirs()