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
This commit is contained in:
Jared Duke
2022-04-20 20:28:33 +00:00
parent 66e6466e0f
commit 0cf7c9686d
3 changed files with 15 additions and 4 deletions

View File

@@ -81,7 +81,17 @@ func init() {
exportedVars.ExportStringStaticVariable("ErrorProneHeapSize", "4096M") exportedVars.ExportStringStaticVariable("ErrorProneHeapSize", "4096M")
exportedVars.ExportStringStaticVariable("ErrorProneHeapFlags", "-J-Xmx${ErrorProneHeapSize}") 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:OnError="cat hs_err_pid%p.log"`,
"-JXX:CICompilerCount=6", "-JXX:CICompilerCount=6",
"-JXX:+UseDynamicNumberOfGCThreads", "-JXX:+UseDynamicNumberOfGCThreads",

View File

@@ -78,7 +78,8 @@ func makeVarsProvider(ctx android.MakeVarsContext) {
ctx.Strict("CLASS2NONSDKLIST", "${Class2NonSdkList}") ctx.Strict("CLASS2NONSDKLIST", "${Class2NonSdkList}")
ctx.Strict("HIDDENAPI", "${HiddenAPI}") 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("AIDL", "${AidlCmd}")
ctx.Strict("AAPT2", "${Aapt2Cmd}") ctx.Strict("AAPT2", "${Aapt2Cmd}")

View File

@@ -95,7 +95,7 @@ var d8, d8RE = pctx.MultiCommandRemoteStaticRules("d8",
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` + Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
`mkdir -p $$(dirname $tmpJar) && ` + `mkdir -p $$(dirname $tmpJar) && ` +
`${config.Zip2ZipCmd} -i $in -o $tmpJar -x '**/*.dex' && ` + `${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" && ` + `$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`, `${config.MergeZipsCmd} -D -stripFile "**/*.class" $mergeZipsFlags $out $outDir/classes.dex.jar $in`,
CommandDeps: []string{ CommandDeps: []string{
@@ -128,7 +128,7 @@ var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8",
`mkdir -p $$(dirname ${outUsage}) && ` + `mkdir -p $$(dirname ${outUsage}) && ` +
`mkdir -p $$(dirname $tmpJar) && ` + `mkdir -p $$(dirname $tmpJar) && ` +
`${config.Zip2ZipCmd} -i $in -o $tmpJar -x '**/*.dex' && ` + `${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 ` + `--no-data-resources ` +
`-printmapping ${outDict} ` + `-printmapping ${outDict} ` +
`-printusage ${outUsage} ` + `-printusage ${outUsage} ` +