summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2010-11-01 10:27:33 +0000
committerBen Murdoch <benm@google.com>2010-11-09 10:09:42 +0000
commitf7093befbbc64d324b6d4c41e98ae69bbed4cd31 (patch)
tree166089878bcfd1234418a670768736e8ff008da8 /core/java
parentb7d633c7abc93477a1ee9d195e2e2f662a434a95 (diff)
downloadframeworks_base-f7093befbbc64d324b6d4c41e98ae69bbed4cd31.zip
frameworks_base-f7093befbbc64d324b6d4c41e98ae69bbed4cd31.tar.gz
frameworks_base-f7093befbbc64d324b6d4c41e98ae69bbed4cd31.tar.bz2
Calculate memory thresholds that V8 can use to control GC.
V8 can be smarter about the memory it uses and the frequency of garbage collection but we need to inform it of the values to use. As this varies device to device look it up and store it on the WebViewCore to be read by native code over JNI. See also https://android-git.corp.google.com/g/#change,78691 Bug: 3075565 Change-Id: Ib52f4df775b80b386fc98f1d71b5687f01c12b2e
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/webkit/WebViewCore.java21
1 files changed, 21 insertions, 0 deletions
diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java
index 1b7eb2a..6e927a6 100644
--- a/core/java/android/webkit/WebViewCore.java
+++ b/core/java/android/webkit/WebViewCore.java
@@ -16,6 +16,7 @@
package android.webkit;
+import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.database.Cursor;
@@ -125,6 +126,9 @@ final class WebViewCore {
private DeviceMotionService mDeviceMotionService;
private DeviceOrientationService mDeviceOrientationService;
+ private int mLowMemoryUsageThresholdMb;
+ private int mHighMemoryUsageThresholdMb;
+
// The thread name used to identify the WebCore thread and for use in
// debugging other classes that require operation within the WebCore thread.
/* package */ static final String THREAD_NAME = "WebViewCoreThread";
@@ -170,6 +174,23 @@ final class WebViewCore {
WebStorage.getInstance().createUIHandler();
// Create the UI handler for GeolocationPermissions
GeolocationPermissions.getInstance().createUIHandler();
+
+ // Get the memory class of the current device. V8 will use these values
+ // to GC more effectively.
+ ActivityManager manager = (ActivityManager) mContext.getSystemService(
+ Context.ACTIVITY_SERVICE);
+ ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
+ manager.getMemoryInfo(memInfo);
+
+ // Allow us to use up to our memory class value before V8's GC kicks in.
+ // These values have been determined by experimentation.
+ mLowMemoryUsageThresholdMb = manager.getMemoryClass();
+ // If things get crazy, allow V8 to use up to 3 times our memory class, or a third of the
+ // device's total available memory, whichever is smaller. At that point V8 will start
+ // attempting more aggressive garbage collection.
+ mHighMemoryUsageThresholdMb = Math.min(mLowMemoryUsageThresholdMb * 3,
+ (int) (memInfo.availMem / 3) >> 20);
+
// Send a message to initialize the WebViewCore.
Message init = sWebCoreHandler.obtainMessage(
WebCoreThread.INITIALIZE, this);