Backed out changeset 62ff4a66c1c6 (bug 1750878) for causing Btime failures CLOSED TREE

This commit is contained in:
Cristian Tuns 2022-01-20 04:03:20 -05:00
Родитель 869df3c6ba
Коммит 2cb68401e0
4 изменённых файлов: 30 добавлений и 83 удалений

Просмотреть файл

@ -6,6 +6,7 @@
package org.mozilla.gecko.process;
import android.app.Service;
import android.content.ComponentCallbacks2;
import android.content.Intent;
import android.os.Binder;
import android.os.Bundle;
@ -26,11 +27,13 @@ import org.mozilla.gecko.util.ThreadUtils;
public class GeckoServiceChildProcess extends Service {
private static final String LOGTAG = "ServiceChildProcess";
// Allowed elapsed time between full GCs while under constant memory pressure
private static final long LOW_MEMORY_ONGOING_RESET_TIME_MS = 10000;
private static IProcessManager sProcessManager;
private static String sOwnerProcessId;
private final MemoryController mMemoryController = new MemoryController();
private long mLastLowMemoryNotificationTime = 0;
// Makes sure we don't reuse this process
private static boolean sCreateCalled;
@ -191,16 +194,36 @@ public class GeckoServiceChildProcess extends Service {
@Override
public void onTrimMemory(final int level) {
mMemoryController.onTrimMemory(level);
Log.i(LOGTAG, "onTrimMemory(" + level + ")");
// This is currently a no-op in Service, but let's future-proof.
super.onTrimMemory(level);
}
@Override
public void onLowMemory() {
mMemoryController.onLowMemory();
super.onLowMemory();
if (level < ComponentCallbacks2.TRIM_MEMORY_BACKGROUND) {
// We're not currently interested in trim events for non-backgrounded processes.
return;
}
// See nsIMemory.idl for descriptions of the various arguments to the "memory-pressure"
// observer.
String observerArg = null;
final long currentNotificationTime = System.currentTimeMillis();
if (level >= ComponentCallbacks2.TRIM_MEMORY_COMPLETE
|| (currentNotificationTime - mLastLowMemoryNotificationTime)
>= LOW_MEMORY_ONGOING_RESET_TIME_MS) {
// We do a full "low-memory" notification for both new and last-ditch onTrimMemory requests.
observerArg = "low-memory";
mLastLowMemoryNotificationTime = currentNotificationTime;
} else {
// If it has been less than ten seconds since the last time we sent a "low-memory"
// notification, we send a "low-memory-ongoing" notification instead.
// This prevents Gecko from re-doing full GC's repeatedly over and over in succession,
// as they are expensive and quickly result in diminishing returns.
observerArg = "low-memory-ongoing";
}
GeckoAppShell.notifyObservers("memory-pressure", observerArg);
}
/**

Просмотреть файл

@ -1,70 +0,0 @@
package org.mozilla.gecko.process;
import android.content.ComponentCallbacks2;
import android.content.res.Configuration;
import android.util.Log;
import androidx.annotation.NonNull;
import org.mozilla.gecko.GeckoAppShell;
public class MemoryController implements ComponentCallbacks2 {
private static final String LOGTAG = "MemoryController";
private long mLastLowMemoryNotificationTime = 0;
// Allowed elapsed time between full GCs while under constant memory pressure
private static final long LOW_MEMORY_ONGOING_RESET_TIME_MS = 10000;
private static final int LOW = 0;
private static final int MODERATE = 1;
private static final int CRITICAL = 2;
private int memoryLevelFromTrim(final int level) {
if (level >= ComponentCallbacks2.TRIM_MEMORY_COMPLETE
|| level == ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL) {
return CRITICAL;
} else if (level >= ComponentCallbacks2.TRIM_MEMORY_BACKGROUND) {
return MODERATE;
}
return LOW;
}
public void onTrimMemory(final int level) {
Log.i(LOGTAG, "onTrimMemory(" + level + ")");
onMemoryNotification(memoryLevelFromTrim(level));
}
@Override
public void onConfigurationChanged(final @NonNull Configuration newConfig) {}
public void onLowMemory() {
Log.i(LOGTAG, "onLowMemory");
onMemoryNotification(CRITICAL);
}
private void onMemoryNotification(final int level) {
if (level == LOW) {
// The trim level is too low to be actionable
return;
}
// See nsIMemory.idl for descriptions of the various arguments to the "memory-pressure"
// observer.
final String observerArg;
final long currentNotificationTime = System.currentTimeMillis();
if (level == CRITICAL
|| (currentNotificationTime - mLastLowMemoryNotificationTime)
>= LOW_MEMORY_ONGOING_RESET_TIME_MS) {
// We do a full "low-memory" notification for both new and last-ditch onTrimMemory requests.
observerArg = "low-memory";
mLastLowMemoryNotificationTime = currentNotificationTime;
} else {
// If it has been less than ten seconds since the last time we sent a "low-memory"
// notification, we send a "low-memory-ongoing" notification instead.
// This prevents Gecko from re-doing full GC's repeatedly over and over in succession,
// as they are expensive and quickly result in diminishing returns.
observerArg = "low-memory-ongoing";
}
GeckoAppShell.notifyObservers("memory-pressure", observerArg);
}
}

Просмотреть файл

@ -47,7 +47,6 @@ import org.mozilla.gecko.GeckoScreenOrientation.ScreenOrientation;
import org.mozilla.gecko.GeckoSystemStateListener;
import org.mozilla.gecko.GeckoThread;
import org.mozilla.gecko.annotation.WrapForJNI;
import org.mozilla.gecko.process.MemoryController;
import org.mozilla.gecko.util.BundleEventListener;
import org.mozilla.gecko.util.DebugConfig;
import org.mozilla.gecko.util.EventCallback;
@ -136,8 +135,6 @@ public final class GeckoRuntime implements Parcelable {
*/
public static final String CRASHED_PROCESS_TYPE_BACKGROUND_CHILD = "BACKGROUND_CHILD";
private final MemoryController mMemoryController = new MemoryController();
@Retention(RetentionPolicy.SOURCE)
@StringDef(
value = {
@ -555,8 +552,6 @@ public final class GeckoRuntime implements Parcelable {
throw new IllegalStateException("Failed to initialize GeckoRuntime");
}
context.registerComponentCallbacks(runtime.mMemoryController);
return runtime;
}

Просмотреть файл

@ -1387,7 +1387,6 @@ public class GeckoViewActivity extends AppCompatActivity
private void loadFromIntent(final Intent intent) {
final Uri uri = intent.getData();
if (uri != null) {
createNewTab();
mTabSessionManager
.getCurrentSession()
.load(