Commit f42c7a25 authored by Andrew Grieve's avatar Andrew Grieve Committed by Chromium LUCI CQ

Android: Add more debugging information to DexFixer

Bug: 1152970
Change-Id: I3eab1ea2535c6f03b041519cf3ccf257488f0318
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2634924Reviewed-by: default avatarSam Maier <smaier@chromium.org>
Commit-Queue: Sam Maier <smaier@chromium.org>
Auto-Submit: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844591}
parent a7ddad19
...@@ -196,6 +196,10 @@ public class PiiElider { ...@@ -196,6 +196,10 @@ public class PiiElider {
*/ */
@UsedByReflection("jni_android.cc") @UsedByReflection("jni_android.cc")
public static String sanitizeStacktrace(String stacktrace) { public static String sanitizeStacktrace(String stacktrace) {
// TODO(crbug.com/1152970): Remove once debugged.
if (stacktrace.contains("DexFixerException")) {
return stacktrace;
}
String[] frames = stacktrace.split("\\n"); String[] frames = stacktrace.split("\\n");
// Sanitize first stacktrace line which contains the exception message. // Sanitize first stacktrace line which contains the exception message.
frames[0] = elideUrl(frames[0]); frames[0] = elideUrl(frames[0]);
......
...@@ -20,6 +20,7 @@ import org.chromium.base.BuildInfo; ...@@ -20,6 +20,7 @@ import org.chromium.base.BuildInfo;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.JavaExceptionReporter; import org.chromium.base.JavaExceptionReporter;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.annotations.UsedByReflection;
import org.chromium.base.compat.ApiHelperForM; import org.chromium.base.compat.ApiHelperForM;
import org.chromium.base.compat.ApiHelperForO; import org.chromium.base.compat.ApiHelperForO;
import org.chromium.base.library_loader.NativeLibraries; import org.chromium.base.library_loader.NativeLibraries;
...@@ -43,6 +44,8 @@ public class DexFixer { ...@@ -43,6 +44,8 @@ public class DexFixer {
private static final String TAG = "DexFixer"; private static final String TAG = "DexFixer";
private static boolean sHasIsolatedSplits; private static boolean sHasIsolatedSplits;
// TODO(crbug.com/1152970): Remove once debugged.
@UsedByReflection("Disable rename for PiiElider")
private static class DexFixerException extends Exception { private static class DexFixerException extends Exception {
DexFixerException(String reason, Throwable causedBy) { DexFixerException(String reason, Throwable causedBy) {
super(reason, causedBy); super(reason, causedBy);
...@@ -85,7 +88,7 @@ public class DexFixer { ...@@ -85,7 +88,7 @@ public class DexFixer {
int reason = needsDexCompile(appInfo); int reason = needsDexCompile(appInfo);
if (reason > DexFixerReason.NOT_NEEDED) { if (reason > DexFixerReason.NOT_NEEDED) {
Log.w(TAG, "Triggering dex compile. Reason=%d", reason); Log.w(TAG, "Triggering dex compile. Reason=%d", reason);
String cmd = "cmd package compile -r shared "; String cmd = "/system/bin/cmd package compile -r shared ";
if (reason == DexFixerReason.NOT_READABLE && BuildConfig.ISOLATED_SPLITS_ENABLED) { if (reason == DexFixerReason.NOT_READABLE && BuildConfig.ISOLATED_SPLITS_ENABLED) {
// Isolated processes need only access the base split. // Isolated processes need only access the base split.
String apkBaseName = new File(appInfo.sourceDir).getName(); String apkBaseName = new File(appInfo.sourceDir).getName();
...@@ -95,14 +98,25 @@ public class DexFixer { ...@@ -95,14 +98,25 @@ public class DexFixer {
try { try {
runtime.exec(cmd); runtime.exec(cmd);
} catch (IOException e) { } catch (IOException e) {
DexFixerException dfException = // Maybe a retry will help?
new DexFixerException(String.format("Reason: %s Name: %s", reason, try {
new File(appInfo.sourceDir).getName()), Thread.sleep(5000);
e); } catch (InterruptedException interruptedException) {
// TODO(agrieve): Remove reportException() once some data is collected. }
PostTask.postTask(UiThreadTaskTraits.BEST_EFFORT, try {
() -> JavaExceptionReporter.reportException(dfException)); runtime.exec(cmd);
reason = DexFixerReason.FAILED_TO_RUN; } catch (IOException e2) {
// TODO(agrieve): Remove reportException() once some data is collected.
DexFixerException dfException = new DexFixerException(
String.format("Reason: %s apkName: %s exists: %s canExecute: %s",
reason, new File(appInfo.sourceDir).getName(),
new File("/system/bin/cmd").exists(),
new File("/system/bin/cmd").canExecute()),
e2);
PostTask.postTask(UiThreadTaskTraits.BEST_EFFORT,
() -> JavaExceptionReporter.reportException(dfException));
reason = DexFixerReason.FAILED_TO_RUN;
}
} }
} }
RecordHistogram.recordEnumeratedHistogram("Android.DexFixer", reason, DexFixerReason.COUNT); RecordHistogram.recordEnumeratedHistogram("Android.DexFixer", reason, DexFixerReason.COUNT);
...@@ -190,8 +204,16 @@ public class DexFixer { ...@@ -190,8 +204,16 @@ public class DexFixer {
} }
} catch (ErrnoException e) { } catch (ErrnoException e) {
// TODO(agrieve): Remove reportException() once some data is collected. // TODO(agrieve): Remove reportException() once some data is collected.
String arm64Path = oatPath.replace("arm/", "arm64/");
Boolean dexoptNeeded = null;
try {
dexoptNeeded = DexFile.isDexOptNeeded(appInfo.sourceDir);
} catch (IOException ioException) {
}
DexFixerException dfException = new DexFixerException( DexFixerException dfException = new DexFixerException(
String.format("Path: %s exists: %s", oatPath, new File(oatPath).exists()), e); String.format("Path: %s exists: %s arm64_exists: %s dexopt: %s", oatPath,
new File(oatPath).exists(), new File(arm64Path).exists(), dexoptNeeded),
e);
PostTask.postTask(UiThreadTaskTraits.BEST_EFFORT, PostTask.postTask(UiThreadTaskTraits.BEST_EFFORT,
() -> JavaExceptionReporter.reportException(dfException)); () -> JavaExceptionReporter.reportException(dfException));
return DexFixerReason.STAT_FAILED; return DexFixerReason.STAT_FAILED;
......
...@@ -93,7 +93,8 @@ public class DexFixerTest { ...@@ -93,7 +93,8 @@ public class DexFixerTest {
private void verifyDexOpt() { private void verifyDexOpt() {
try { try {
verify(mMockRuntime).exec(Mockito.matches("cmd package compile -r shared \\S+")); verify(mMockRuntime)
.exec(Mockito.matches("/system/bin/cmd package compile -r shared \\S+"));
} catch (IOException e) { } catch (IOException e) {
// Mocks don't actually throw... // Mocks don't actually throw...
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment