Merge "Reduce lock contention when starting process (1/N)"

This commit is contained in:
Riddle Hsu
2023-01-09 13:29:59 +00:00
committed by Android (Google) Code Review
4 changed files with 23 additions and 13 deletions

View File

@@ -6344,7 +6344,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
int wakefulness) {
synchronized (mGlobalLock) {
if (mHomeProcess != null && (dumpPackage == null
|| mHomeProcess.mPkgList.contains(dumpPackage))) {
|| mHomeProcess.containsPackage(dumpPackage))) {
if (needSep) {
pw.println();
needSep = false;
@@ -6352,7 +6352,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
pw.println(" mHomeProcess: " + mHomeProcess);
}
if (mPreviousProcess != null && (dumpPackage == null
|| mPreviousProcess.mPkgList.contains(dumpPackage))) {
|| mPreviousProcess.containsPackage(dumpPackage))) {
if (needSep) {
pw.println();
needSep = false;
@@ -6360,14 +6360,14 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
pw.println(" mPreviousProcess: " + mPreviousProcess);
}
if (dumpAll && (mPreviousProcess == null || dumpPackage == null
|| mPreviousProcess.mPkgList.contains(dumpPackage))) {
|| mPreviousProcess.containsPackage(dumpPackage))) {
StringBuilder sb = new StringBuilder(128);
sb.append(" mPreviousProcessVisibleTime: ");
TimeUtils.formatDuration(mPreviousProcessVisibleTime, sb);
pw.println(sb);
}
if (mHeavyWeightProcess != null && (dumpPackage == null
|| mHeavyWeightProcess.mPkgList.contains(dumpPackage))) {
|| mHeavyWeightProcess.containsPackage(dumpPackage))) {
if (needSep) {
pw.println();
needSep = false;
@@ -6491,18 +6491,18 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
}
if (mHomeProcess != null && (dumpPackage == null
|| mHomeProcess.mPkgList.contains(dumpPackage))) {
|| mHomeProcess.containsPackage(dumpPackage))) {
mHomeProcess.dumpDebug(proto, HOME_PROC);
}
if (mPreviousProcess != null && (dumpPackage == null
|| mPreviousProcess.mPkgList.contains(dumpPackage))) {
|| mPreviousProcess.containsPackage(dumpPackage))) {
mPreviousProcess.dumpDebug(proto, PREVIOUS_PROC);
proto.write(PREVIOUS_PROC_VISIBLE_TIME_MS, mPreviousProcessVisibleTime);
}
if (mHeavyWeightProcess != null && (dumpPackage == null
|| mHeavyWeightProcess.mPkgList.contains(dumpPackage))) {
|| mHeavyWeightProcess.containsPackage(dumpPackage))) {
mHeavyWeightProcess.dumpDebug(proto, HEAVY_WEIGHT_PROC);
}

View File

@@ -1714,7 +1714,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
// Don't kill the home process along with tasks from the same package.
continue;
}
if (!proc.mPkgList.contains(pkg)) {
if (!proc.containsPackage(pkg)) {
// Don't kill process that is not associated with this task.
continue;
}

View File

@@ -566,7 +566,7 @@ public final class CompatModePackages {
SparseArray<WindowProcessController> pidMap = mService.mProcessMap.getPidMap();
for (int i = pidMap.size() - 1; i >= 0; i--) {
final WindowProcessController app = pidMap.valueAt(i);
if (!app.mPkgList.contains(packageName)) {
if (!app.containsPackage(packageName)) {
continue;
}
try {

View File

@@ -76,6 +76,7 @@ import android.util.Slog;
import android.util.proto.ProtoOutputStream;
import android.view.IRemoteAnimationRunner;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.HeavyWeightSwitcherActivity;
import com.android.internal.protolog.common.ProtoLog;
@@ -118,7 +119,8 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
// communicate back to the activity manager side.
public final Object mOwner;
// List of packages running in the process
final ArraySet<String> mPkgList = new ArraySet<>();
@GuardedBy("itself")
private final ArrayList<String> mPkgList = new ArrayList<>(1);
private final WindowProcessListener mListener;
private final ActivityTaskManagerService mAtm;
private final BackgroundLaunchProcessController mBgLaunchController;
@@ -645,18 +647,26 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
@HotPath(caller = HotPath.PROCESS_CHANGE)
public void addPackage(String packageName) {
synchronized (mAtm.mGlobalLockWithoutBoost) {
mPkgList.add(packageName);
synchronized (mPkgList) {
if (!mPkgList.contains(packageName)) {
mPkgList.add(packageName);
}
}
}
@HotPath(caller = HotPath.PROCESS_CHANGE)
public void clearPackageList() {
synchronized (mAtm.mGlobalLockWithoutBoost) {
synchronized (mPkgList) {
mPkgList.clear();
}
}
boolean containsPackage(String packageName) {
synchronized (mPkgList) {
return mPkgList.contains(packageName);
}
}
void addActivityIfNeeded(ActivityRecord r) {
// even if we already track this activity, note down that it has been launched
setLastActivityLaunchTime(r.lastLaunchTime);