From 0cf7c9686dd05aaa277639fcf580d87f818396fc Mon Sep 17 00:00:00 2001 From: Jared Duke Date: Wed, 20 Apr 2022 20:28:33 +0000 Subject: [PATCH] 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 --- java/config/config.go | 12 +++++++++++- java/config/makevars.go | 3 ++- java/dex.go | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/java/config/config.go b/java/config/config.go index 95b841fa7..46c91a2f6 100644 --- a/java/config/config.go +++ b/java/config/config.go @@ -81,7 +81,17 @@ func init() { 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 df447a129..bc6848fc3 100644 --- a/java/config/makevars.go +++ b/java/config/makevars.go @@ -78,7 +78,8 @@ func makeVarsProvider(ctx android.MakeVarsContext) { 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 84665e7b5..13d6e4a01 100644 --- a/java/dex.go +++ b/java/dex.go @@ -95,7 +95,7 @@ var d8, d8RE = pctx.MultiCommandRemoteStaticRules("d8", 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 @@ var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8", `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} ` +