Reduce lock contention when starting process (1/N)
- Synchronize by itself instead of global lock. - ArrayList is more efficient if the size is small. Bug: 204870457 Test: CtsWindowManagerDeviceTestCases Change-Id: Ieb167c8b2ecd783afba9b5e8218415653be5c239
This commit is contained in:
@@ -6363,7 +6363,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;
|
||||
@@ -6371,7 +6371,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;
|
||||
@@ -6379,14 +6379,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;
|
||||
@@ -6510,18 +6510,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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1717,7 +1717,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;
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -73,6 +73,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;
|
||||
@@ -115,7 +116,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;
|
||||
@@ -640,18 +642,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);
|
||||
|
||||
Reference in New Issue
Block a user