From 430ef455d626eb0f9d845ef6a283056da4883503 Mon Sep 17 00:00:00 2001 From: Calin Juravle Date: Fri, 22 Apr 2016 17:43:07 +0100 Subject: Disable StrictMode policy when setting up profile support Bug: 28304158 Change-Id: Iedf8714bd4f3526823b3060b30e0f11c6c0abcea --- core/java/android/app/LoadedApk.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/core/java/android/app/LoadedApk.java b/core/java/android/app/LoadedApk.java index 849636f5b5dd..006317dedbf9 100644 --- a/core/java/android/app/LoadedApk.java +++ b/core/java/android/app/LoadedApk.java @@ -412,6 +412,8 @@ public final class LoadedApk { private void createOrUpdateClassLoaderLocked(List addedPaths) { if (mPackageName.equals("android")) { + // Note: This branch is taken for system server and we don't need to setup + // jit profiling support. if (mClassLoader != null) { // nothing to update return; @@ -479,6 +481,7 @@ public final class LoadedApk { Slog.v(ActivityThread.TAG, "Class path: " + zip + ", JNI path: " + librarySearchPath); + boolean needToSetupJitProfiles = false; if (mClassLoader == null) { // Temporarily disable logging of disk reads on the Looper thread // as this is early and necessary. @@ -489,11 +492,15 @@ public final class LoadedApk { libraryPermittedPath, mBaseClassLoader); StrictMode.setThreadPolicy(oldPolicy); + // Setup the class loader paths for profiling. + needToSetupJitProfiles = true; } if (addedPaths != null && addedPaths.size() > 0) { final String add = TextUtils.join(File.pathSeparator, addedPaths); ApplicationLoaders.getDefault().addPath(mClassLoader, add); + // Setup the new code paths for profiling. + needToSetupJitProfiles = true; } // Setup jit profile support. @@ -501,7 +508,14 @@ public final class LoadedApk { // The runtime only keeps track of unique code paths and can handle re-registration of // the same code path. There's no need to pass `addedPaths` since any new code paths // are already in `mApplicationInfo`. - setupJitProfileSupport(); + if (needToSetupJitProfiles) { + // Temporarily disable logging of disk reads/writes on the Looper thread + // as this is early and necessary. Write is only needed to create the + // profile file if it's not already there. + StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); + setupJitProfileSupport(); + StrictMode.setThreadPolicy(oldPolicy); + } } public ClassLoader getClassLoader() { -- cgit v1.2.3-59-g8ed1b