summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Narayan Kamath <narayan@google.com> 2018-08-13 12:53:38 +0100
committer Narayan Kamath <narayan@google.com> 2018-08-17 11:50:29 +0100
commitbc95621811b0c15904a4783aae34e94aa109f764 (patch)
treed6a29b391abed451ec7bfffcbab7119bd2f3bc2e
parentf989a15ed89774ec40ec2562541806212a70e526 (diff)
ResourceManager: Disable APK Assets cache.
The WeakReference based cache of Assets in use elsewhere in the process remains unchanged. Note that this change is larger than it needs to be because it is an error to create an LruCache of size zero. There seems to be no measurable difference as measured by the standard app startup benchmarks. Test: atest -v google/perf/app-startup/benchmark-app-hermetic/cold-dropcache-test Bug: 111385832 Change-Id: I432c069e90124e884bddc5cd5be43a28e1b16d07
-rw-r--r--core/java/android/app/ResourcesManager.java53
1 files changed, 35 insertions, 18 deletions
diff --git a/core/java/android/app/ResourcesManager.java b/core/java/android/app/ResourcesManager.java
index 30256b42e6a1..f9929712255c 100644
--- a/core/java/android/app/ResourcesManager.java
+++ b/core/java/android/app/ResourcesManager.java
@@ -121,10 +121,13 @@ public class ResourcesManager {
}
}
+ private static final boolean ENABLE_APK_ASSETS_CACHE = true;
+
/**
* The ApkAssets we are caching and intend to hold strong references to.
*/
- private final LruCache<ApkKey, ApkAssets> mLoadedApkAssets = new LruCache<>(3);
+ private final LruCache<ApkKey, ApkAssets> mLoadedApkAssets =
+ (ENABLE_APK_ASSETS_CACHE) ? new LruCache<>(3) : null;
/**
* The ApkAssets that are being referenced in the wild that we can reuse, even if they aren't
@@ -310,9 +313,12 @@ public class ResourcesManager {
private @NonNull ApkAssets loadApkAssets(String path, boolean sharedLib, boolean overlay)
throws IOException {
final ApkKey newKey = new ApkKey(path, sharedLib, overlay);
- ApkAssets apkAssets = mLoadedApkAssets.get(newKey);
- if (apkAssets != null) {
- return apkAssets;
+ ApkAssets apkAssets = null;
+ if (mLoadedApkAssets != null) {
+ apkAssets = mLoadedApkAssets.get(newKey);
+ if (apkAssets != null) {
+ return apkAssets;
+ }
}
// Optimistically check if this ApkAssets exists somewhere else.
@@ -320,7 +326,10 @@ public class ResourcesManager {
if (apkAssetsRef != null) {
apkAssets = apkAssetsRef.get();
if (apkAssets != null) {
- mLoadedApkAssets.put(newKey, apkAssets);
+ if (mLoadedApkAssets != null) {
+ mLoadedApkAssets.put(newKey, apkAssets);
+ }
+
return apkAssets;
} else {
// Clean up the reference.
@@ -335,7 +344,11 @@ public class ResourcesManager {
} else {
apkAssets = ApkAssets.loadFromPath(path, false /*system*/, sharedLib);
}
- mLoadedApkAssets.put(newKey, apkAssets);
+
+ if (mLoadedApkAssets != null) {
+ mLoadedApkAssets.put(newKey, apkAssets);
+ }
+
mCachedApkAssets.put(newKey, new WeakReference<>(apkAssets));
return apkAssets;
}
@@ -434,18 +447,22 @@ public class ResourcesManager {
pw.println("ResourcesManager:");
pw.increaseIndent();
- pw.print("cached apks: total=");
- pw.print(mLoadedApkAssets.size());
- pw.print(" created=");
- pw.print(mLoadedApkAssets.createCount());
- pw.print(" evicted=");
- pw.print(mLoadedApkAssets.evictionCount());
- pw.print(" hit=");
- pw.print(mLoadedApkAssets.hitCount());
- pw.print(" miss=");
- pw.print(mLoadedApkAssets.missCount());
- pw.print(" max=");
- pw.print(mLoadedApkAssets.maxSize());
+ if (mLoadedApkAssets != null) {
+ pw.print("cached apks: total=");
+ pw.print(mLoadedApkAssets.size());
+ pw.print(" created=");
+ pw.print(mLoadedApkAssets.createCount());
+ pw.print(" evicted=");
+ pw.print(mLoadedApkAssets.evictionCount());
+ pw.print(" hit=");
+ pw.print(mLoadedApkAssets.hitCount());
+ pw.print(" miss=");
+ pw.print(mLoadedApkAssets.missCount());
+ pw.print(" max=");
+ pw.print(mLoadedApkAssets.maxSize());
+ } else {
+ pw.print("cached apks: 0 [cache disabled]");
+ }
pw.println();
pw.print("total apks: ");