Limit JIT tier for D8
Standalone D8 invocations tend to be shorter-lived than R8 invocations
that involve deeper layers of bytecode optimization. Introduce a
separate set of JVM flags to pass to D8 invocations which limit the
runtime JIT tiering, reducing overall compile times and significantly
reducing total CPU consumption for D8 build workloads.
Representative incremental build times with this change:
* real 6m1.388s
* user 63m32.412s
and without:
* real 6m30.624s
* user 79m12.626s
Bug: 205303544
Test: time m
Change-Id: Ic568a4316325c6a4e0da41ffebbb07f0c5f7e8e3
diff --git a/java/config/config.go b/java/config/config.go
index 95b841f..46c91a2 100644
--- a/java/config/config.go
+++ b/java/config/config.go
@@ -81,7 +81,17 @@
exportedVars.ExportStringStaticVariable("ErrorProneHeapSize", "4096M")
exportedVars.ExportStringStaticVariable("ErrorProneHeapFlags", "-J-Xmx${ErrorProneHeapSize}")
- exportedVars.ExportStringListStaticVariable("DexFlags", []string{
+ // D8 invocations are shorter lived, so we restrict their JIT tiering relative to R8.
+ // Note that the `-JXX` prefix syntax is specific to the R8/D8 invocation wrappers.
+ exportedVars.ExportStringListStaticVariable("D8Flags", []string{
+ `-JXX:OnError="cat hs_err_pid%p.log"`,
+ "-JXX:CICompilerCount=6",
+ "-JXX:+UseDynamicNumberOfGCThreads",
+ "-JXX:+TieredCompilation",
+ "-JXX:TieredStopAtLevel=1",
+ })
+
+ exportedVars.ExportStringListStaticVariable("R8Flags", []string{
`-JXX:OnError="cat hs_err_pid%p.log"`,
"-JXX:CICompilerCount=6",
"-JXX:+UseDynamicNumberOfGCThreads",
diff --git a/java/config/makevars.go b/java/config/makevars.go
index df447a1..bc6848f 100644
--- a/java/config/makevars.go
+++ b/java/config/makevars.go
@@ -78,7 +78,8 @@
ctx.Strict("CLASS2NONSDKLIST", "${Class2NonSdkList}")
ctx.Strict("HIDDENAPI", "${HiddenAPI}")
- ctx.Strict("DEX_FLAGS", "${DexFlags}")
+ ctx.Strict("D8_FLAGS", "${D8Flags}")
+ ctx.Strict("R8_FLAGS", "${R8Flags}")
ctx.Strict("AIDL", "${AidlCmd}")
ctx.Strict("AAPT2", "${Aapt2Cmd}")
diff --git a/java/dex.go b/java/dex.go
index 84665e7..13d6e4a 100644
--- a/java/dex.go
+++ b/java/dex.go
@@ -95,7 +95,7 @@
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
`mkdir -p $$(dirname $tmpJar) && ` +
`${config.Zip2ZipCmd} -i $in -o $tmpJar -x '**/*.dex' && ` +
- `$d8Template${config.D8Cmd} ${config.DexFlags} --output $outDir $d8Flags $tmpJar && ` +
+ `$d8Template${config.D8Cmd} ${config.D8Flags} --output $outDir $d8Flags $tmpJar && ` +
`$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` +
`${config.MergeZipsCmd} -D -stripFile "**/*.class" $mergeZipsFlags $out $outDir/classes.dex.jar $in`,
CommandDeps: []string{
@@ -128,7 +128,7 @@
`mkdir -p $$(dirname ${outUsage}) && ` +
`mkdir -p $$(dirname $tmpJar) && ` +
`${config.Zip2ZipCmd} -i $in -o $tmpJar -x '**/*.dex' && ` +
- `$r8Template${config.R8Cmd} ${config.DexFlags} -injars $tmpJar --output $outDir ` +
+ `$r8Template${config.R8Cmd} ${config.R8Flags} -injars $tmpJar --output $outDir ` +
`--no-data-resources ` +
`-printmapping ${outDict} ` +
`-printusage ${outUsage} ` +