Bug 816879 - Only block on gecko in the onLowMemory android notification, not the onTrimMemory suggestion. r=snorp
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 30 Jan 2013 13:53:02 -0500
changeset 120393 2d6e2f861e19223eec179d045c95375615ade49e
parent 120392 2f0cf6930eec31774769057a8c28490f8db498f5
child 120394 ed412c2a599d8b5094a26dfa258286c64b3eb644
push id24251
push userryanvm@gmail.com
push dateThu, 31 Jan 2013 20:56:22 +0000
treeherdermozilla-central@683b08dc1afd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs816879
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 816879 - Only block on gecko in the onLowMemory android notification, not the onTrimMemory suggestion. r=snorp
mobile/android/base/MemoryMonitor.java
--- a/mobile/android/base/MemoryMonitor.java
+++ b/mobile/android/base/MemoryMonitor.java
@@ -66,17 +66,21 @@ class MemoryMonitor extends BroadcastRec
         filter.addAction(Intent.ACTION_DEVICE_STORAGE_OK);
         filter.addAction(ACTION_MEMORY_DUMP);
         filter.addAction(ACTION_FORCE_PRESSURE);
         context.getApplicationContext().registerReceiver(this, filter);
     }
 
     public void onLowMemory() {
         Log.d(LOGTAG, "onLowMemory() notification received");
-        increaseMemoryPressure(MEMORY_PRESSURE_HIGH);
+        if (increaseMemoryPressure(MEMORY_PRESSURE_HIGH)) {
+            // We need to wait on Gecko here, because if we haven't reduced
+            // memory usage enough when we return from this, Android will kill us.
+            GeckoAppShell.geckoEventSync();
+        }
     }
 
     public void onTrimMemory(int level) {
         Log.d(LOGTAG, "onTrimMemory() notification received with level " + level);
         if (Build.VERSION.SDK_INT < 14) {
             // this won't even get called pre-ICS
             return;
         }
@@ -111,57 +115,50 @@ class MemoryMonitor extends BroadcastRec
                 label = "default";
             }
             GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Memory:Dump", label));
         } else if (ACTION_FORCE_PRESSURE.equals(intent.getAction())) {
             increaseMemoryPressure(MEMORY_PRESSURE_HIGH);
         }
     }
 
-    private void increaseMemoryPressure(int level) {
+    private boolean increaseMemoryPressure(int level) {
         int oldLevel;
         synchronized (this) {
             // bump up our level if we're not already higher
             if (mMemoryPressure > level) {
-                return;
+                return false;
             }
             oldLevel = mMemoryPressure;
             mMemoryPressure = level;
         }
 
         // since we don't get notifications for when memory pressure is off,
         // we schedule our own timer to slowly back off the memory pressure level.
         // note that this will reset the time to next decrement if the decrementer
         // is already running, which is the desired behaviour because we just got
         // a new low-mem notification.
         mPressureDecrementer.start();
 
         if (oldLevel == level) {
             // if we're not going to a higher level we probably don't
             // need to run another round of the same memory reductions
             // we did on the last memory pressure increase.
-            return;
+            return false;
         }
 
         // TODO hook in memory-reduction stuff for different levels here
         if (level >= MEMORY_PRESSURE_MEDIUM) {
             if (GeckoThread.checkLaunchState(GeckoThread.LaunchState.GeckoRunning)) {
                 GeckoAppShell.onLowMemory();
             }
 
-            if (level >= MEMORY_PRESSURE_HIGH) {
-                // We need to wait on Gecko here, because this is normally called
-                // from Activity.onLowMemory. If we haven't reduced memory usage
-                // enough when we return from that, Android will kill us.
-                // Activity.onTrimMemory is more of a suggestion.
-                GeckoAppShell.geckoEventSync();
-            }
-
             Favicons.getInstance().clearMemCache();
         }
+        return true;
     }
 
     private boolean decreaseMemoryPressure() {
         int newLevel;
         synchronized (this) {
             if (mMemoryPressure <= 0) {
                 return false;
             }