This PR adds a new `MAX_COMPILE_THREADS` gradle property to to limit the number 
of build-time parallel compilation threads to the smaller of this property and 
the number of avialable processors.

Our gradle build spawns up to `NUM_COMPILE_THREADS` compilation tasks in 
parallel when building native libraries. By default, `NUM_COMPILE_THREADS` is 
set to the value returned by `Runtime.getRuntime().availableProcessors()`. That 
value can be overridden on the command line by setting the 
`NUM_COMPILE_THREADS` gradle property. We need a way to clamp 
`NUM_COMPILE_THREADS` at some maximum value without the caller having to 
compute it.

The change in `build.gradle` is simple:

* Define a new `MAX_COMPILE_THREADS` gradle property, which will default to 0 
(meaning unlimited) for compatibility with current behavior.

* Set the default value of `NUM_COMPILE_THREADS` as follows:


    NUM_COMPILE_THREADS = MAX_COMPILE_THREADS > 0
                        ? Math.min(MAX_COMPILE_THREADS, availableProcessors)
                        : availableProcessors(


This will allow a test scripts that runs on a number of different platforms to 
clamp to a maximum value without having to use jshell or similar to implement 
`Math.min(MAX_COMPILE_THREADS, Runtime.getRuntime().availableProcessors())` in 
the script.

We have a practical need for this in our headful test systems, several of which 
report a higher number of processors than they can effectively support. Without 
clamping, the build will either run slower (due to too much swapping) or fail 
altogether when building WebKit.

-------------

Commit messages:
 - 8374153: Add a MAX_COMPILE_THREADS gradle property to limit number of threads

Changes: https://git.openjdk.org/jfx/pull/2014/files
  Webrev: https://webrevs.openjdk.org/?repo=jfx&pr=2014&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8374153
  Stats: 23 lines in 2 files changed: 20 ins; 0 del; 3 mod
  Patch: https://git.openjdk.org/jfx/pull/2014.diff
  Fetch: git fetch https://git.openjdk.org/jfx.git pull/2014/head:pull/2014

PR: https://git.openjdk.org/jfx/pull/2014

Reply via email to