summaryrefslogtreecommitdiff
path: root/libartservice
diff options
context:
space:
mode:
author Jiakai Zhang <jiakaiz@google.com> 2024-07-16 13:16:15 +0100
committer Jiakai Zhang <jiakaiz@google.com> 2024-08-22 15:42:21 +0000
commit389112846cf90ca8e1f49a67ac8ad1df28a551cb (patch)
tree36283940fe1929fef0023e82f410bd84d3402863 /libartservice
parentd3e41fd63325930bc555d1a8ef4de09f6926a85c (diff)
Optimize DexUseManagerLocal.findOwningPackage - Step 2.
This CL adds an early return for shared libraries, which is not supposed to be a semantic change, though it's not obvious that's the case. Bug: 328673771 Test: atest ArtServiceTests Change-Id: Idc6647d5fd78e3af0f642c7e3a08d993e4ea18eb
Diffstat (limited to 'libartservice')
-rw-r--r--libartservice/service/java/com/android/server/art/DexUseManagerLocal.java47
1 files changed, 42 insertions, 5 deletions
diff --git a/libartservice/service/java/com/android/server/art/DexUseManagerLocal.java b/libartservice/service/java/com/android/server/art/DexUseManagerLocal.java
index 6c05c372ad..7eb5a69165 100644
--- a/libartservice/service/java/com/android/server/art/DexUseManagerLocal.java
+++ b/libartservice/service/java/com/android/server/art/DexUseManagerLocal.java
@@ -25,6 +25,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.pm.SharedLibraryInfo;
import android.os.Binder;
import android.os.Build;
import android.os.Environment;
@@ -53,6 +54,7 @@ import com.android.server.pm.PackageManagerLocal;
import com.android.server.pm.pkg.AndroidPackage;
import com.android.server.pm.pkg.AndroidPackageSplit;
import com.android.server.pm.pkg.PackageState;
+import com.android.server.pm.pkg.SharedLibrary;
import com.google.auto.value.AutoValue;
@@ -447,7 +449,8 @@ public class DexUseManagerLocal {
// Most likely, the package is loading its own dex file, so we check this first as an
// optimization.
PackageState loadingPkgState = Utils.getPackageStateOrThrow(snapshot, loadingPackageName);
- FindResult result = checkForPackage(loadingPkgState, dexPath);
+ FindResult result =
+ checkForPackage(loadingPkgState, dexPath, true /* checkForSharedLibraries */);
if (result != null) {
return result;
}
@@ -494,7 +497,8 @@ public class DexUseManagerLocal {
mRecentDexFilesToPackageNames.remove(dexPath);
return null;
}
- FindResult result = checkForPackage(pkgState, dexPath);
+ FindResult result =
+ checkForPackage(pkgState, dexPath, true /* checkForSharedLibraries */);
if (result != null) {
mRecentDexFilesToPackageNames.put(dexPath, packageName);
return result;
@@ -522,12 +526,14 @@ public class DexUseManagerLocal {
}
}
- // Check remaining packages.
+ // Check remaining packages. Don't check for shared libraries because it might be too
+ // expansive to do so and the time complexity is O(n) no matter we do it or not.
for (PackageState pkgState : packageStates.values()) {
if (visitedPackages.contains(pkgState.getPackageName())) {
continue;
}
- FindResult result = checkForPackage(pkgState, dexPath);
+ FindResult result =
+ checkForPackage(pkgState, dexPath, false /* checkForSharedLibraries */);
if (result != null) {
mRecentDexFilesToPackageNames.put(dexPath, pkgState.getPackageName());
return result;
@@ -539,10 +545,18 @@ public class DexUseManagerLocal {
}
@Nullable
- private FindResult checkForPackage(@NonNull PackageState pkgState, @NonNull String dexPath) {
+ private FindResult checkForPackage(@NonNull PackageState pkgState, @NonNull String dexPath,
+ boolean checkForSharedLibraries) {
if (isOwningPackageForPrimaryDex(pkgState, dexPath)) {
return new FindResult(TYPE_PRIMARY, pkgState.getPackageName());
}
+ if (checkForSharedLibraries) {
+ FindResult result =
+ checkForSharedLibraries(pkgState.getSharedLibraryDependencies(), dexPath);
+ if (result != null) {
+ return result;
+ }
+ }
synchronized (mLock) {
if (isOwningPackageForSecondaryDexLocked(pkgState, dexPath)) {
return new FindResult(TYPE_SECONDARY, pkgState.getPackageName());
@@ -585,6 +599,29 @@ public class DexUseManagerLocal {
}
@Nullable
+ private static FindResult checkForSharedLibraries(
+ @NonNull List<SharedLibrary> libraries, @NonNull String dexPath) {
+ for (SharedLibrary library : libraries) {
+ if (library.isNative()) {
+ continue;
+ }
+ if (dexPath.equals(library.getPath())) {
+ if (library.getType() == SharedLibraryInfo.TYPE_BUILTIN) {
+ // Shared libraries are considered used by other apps anyway. No need to record
+ // them.
+ return new FindResult(TYPE_DONT_RECORD, null);
+ }
+ return new FindResult(TYPE_PRIMARY, library.getPackageName());
+ }
+ FindResult result = checkForSharedLibraries(library.getDependencies(), dexPath);
+ if (result != null) {
+ return result;
+ }
+ }
+ return null;
+ }
+
+ @Nullable
private String getPackageCodeDir(@NonNull PackageState pkgState) {
AndroidPackage pkg = pkgState.getAndroidPackage();
if (pkg == null) {