Time out and dump stacks from R8 processes after 30 minutes
R8 processes are sometimes hanging on the build servers. Wrap R8 with
run_with_timeout to dump the stacks with jstack and kill the process
after 30 minutes. Switch from running with the r8-compat-proguard
shell script to running the jar directly so that jstack gets the pid
of the java process.
Bug: 181095653
Test: m checkbuild
Test: m NetworkStackNextIntegrationTests
Test: m USE_RBE=true RBE_R8=true RBE_R8_EXEC_STRATEGY=remote NetworkStackNextIntegrationTests
Change-Id: If6996bd8eb39c7a8453d79e825004339c009ade2
diff --git a/java/dex.go b/java/dex.go
index 7898e9d..6bf0143 100644
--- a/java/dex.go
+++ b/java/dex.go
@@ -84,6 +84,11 @@
return BoolDefault(d.dexProperties.Optimize.Enabled, d.dexProperties.Optimize.EnabledByDefault)
}
+func init() {
+ pctx.HostBinToolVariable("runWithTimeoutCmd", "run_with_timeout")
+ pctx.SourcePathVariable("jstackCmd", "${config.JavaToolchain}/jstack")
+}
+
var d8, d8RE = pctx.MultiCommandRemoteStaticRules("d8",
blueprint.RuleParams{
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
@@ -117,7 +122,10 @@
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
`rm -f "$outDict" && rm -rf "${outUsageDir}" && ` +
`mkdir -p $$(dirname ${outUsage}) && ` +
- `$r8Template${config.R8Cmd} ${config.DexFlags} -injars $in --output $outDir ` +
+ // TODO(b/181095653): remove R8 timeout and go back to config.R8Cmd.
+ `${runWithTimeoutCmd} -timeout 30m -on_timeout '${jstackCmd} $$PID' -- ` +
+ `$r8Template${config.JavaCmd} ${config.DexJavaFlags} -cp ${config.R8Jar} ` +
+ `com.android.tools.r8.compatproguard.CompatProguard -injars $in --output $outDir ` +
`--no-data-resources ` +
`-printmapping ${outDict} ` +
`-printusage ${outUsage} ` +
@@ -128,9 +136,10 @@
`$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` +
`${config.MergeZipsCmd} -D -stripFile "**/*.class" $out $outDir/classes.dex.jar $in`,
CommandDeps: []string{
- "${config.R8Cmd}",
+ "${config.R8Jar}",
"${config.SoongZipCmd}",
"${config.MergeZipsCmd}",
+ "${runWithTimeoutCmd}",
},
}, map[string]*remoteexec.REParams{
"$r8Template": &remoteexec.REParams{