summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/base.gypi1
-rw-r--r--base/sys_info.h4
-rw-r--r--base/sys_info_android.cc59
-rw-r--r--webkit/glue/webkitplatformsupport_impl.cc49
-rw-r--r--webkit/glue/webkitplatformsupport_impl.h9
5 files changed, 103 insertions, 19 deletions
diff --git a/base/base.gypi b/base/base.gypi
index 4f5961b..80634b4 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -337,6 +337,7 @@
'system_monitor/system_monitor_win.cc',
'sys_byteorder.h',
'sys_info.h',
+ 'sys_info_android.cc',
'sys_info_chromeos.cc',
'sys_info_freebsd.cc',
'sys_info_linux.cc',
diff --git a/base/sys_info.h b/base/sys_info.h
index edfa70f..242f4fb 100644
--- a/base/sys_info.h
+++ b/base/sys_info.h
@@ -80,6 +80,10 @@ class BASE_EXPORT SysInfo {
// Returns the path to the lsb-release file.
static FilePath GetLsbReleaseFilePath();
#endif // defined(OS_CHROMEOS)
+
+#if defined(OS_ANDROID)
+ static int DalvikHeapSizeMB();
+#endif // defined(OS_ANDROID)
};
} // namespace base
diff --git a/base/sys_info_android.cc b/base/sys_info_android.cc
new file mode 100644
index 0000000..b84b557
--- /dev/null
+++ b/base/sys_info_android.cc
@@ -0,0 +1,59 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/sys_info.h"
+
+#include <sys/system_properties.h>
+
+#include "base/logging.h"
+#include "base/string_number_conversions.h"
+#include "base/string_piece.h"
+
+namespace {
+
+int ParseHeapSize(const base::StringPiece& str) {
+ const int64 KB = 1024;
+ const int64 MB = 1024 * KB;
+ const int64 GB = 1024 * MB;
+ CHECK_GT(str.size(), 0u);
+ int64 factor = 1;
+ size_t length = str.size();
+ if (str[length - 1] == 'k') {
+ factor = KB;
+ length--;
+ } else if (str[length - 1] == 'm') {
+ factor = MB;
+ length--;
+ } else if (str[length - 1] == 'g') {
+ factor = GB;
+ length--;
+ } else {
+ CHECK('0' <= str[length - 1] && str[length - 1] <= '9');
+ }
+ int64 result = 0;
+ bool parsed = base::StringToInt64(str.substr(0, length), &result);
+ CHECK(parsed);
+ result = result * factor / MB;
+ // dalvik.vm.heapsize property is writable by user,
+ // truncate it to reasonable value to avoid overflows later.
+ result = std::min<int64>(std::max<int64>(32, result), 1024);
+ return static_cast<int>(result);
+}
+
+int GetDalvikHeapSizeMB() {
+ char heap_size_str[PROP_VALUE_MAX];
+ __system_property_get("dalvik.vm.heapsize", heap_size_str);
+ return ParseHeapSize(heap_size_str);
+}
+
+} // anonymous namespace
+
+namespace base {
+
+int SysInfo::DalvikHeapSizeMB() {
+ static int heap_size = GetDalvikHeapSizeMB();
+ return heap_size;
+}
+
+} // namespace base
diff --git a/webkit/glue/webkitplatformsupport_impl.cc b/webkit/glue/webkitplatformsupport_impl.cc
index 73e2e08..6003cce 100644
--- a/webkit/glue/webkitplatformsupport_impl.cc
+++ b/webkit/glue/webkitplatformsupport_impl.cc
@@ -24,6 +24,7 @@
#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "base/synchronization/lock.h"
+#include "base/sys_info.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "grit/webkit_chromium_resources.h"
@@ -668,8 +669,8 @@ WebKit::WebString WebKitPlatformSupportImpl::signedPublicKeyAndChallengeString(
return WebKit::WebString("");
}
-#if defined(OS_LINUX)
-static size_t memoryUsageMBLinux() {
+#if defined(OS_LINUX) || defined(OS_ANDROID)
+static size_t memoryUsageMB() {
struct mallinfo minfo = mallinfo();
uint64_t mem_usage =
#if defined(USE_TCMALLOC)
@@ -683,10 +684,8 @@ static size_t memoryUsageMBLinux() {
v8::V8::GetHeapStatistics(&stat);
return mem_usage + (static_cast<uint64_t>(stat.total_heap_size()) >> 20);
}
-#endif
-
-#if defined(OS_MACOSX)
-static size_t memoryUsageMBMac() {
+#elif defined(OS_MACOSX)
+static size_t memoryUsageMB() {
using base::ProcessMetrics;
static ProcessMetrics* process_metrics =
// The default port provider is sufficient to get data for the current
@@ -696,10 +695,8 @@ static size_t memoryUsageMBMac() {
DCHECK(process_metrics);
return process_metrics->GetWorkingSetSize() >> 20;
}
-#endif
-
-#if !defined(OS_LINUX) && !defined(OS_MACOSX)
-static size_t memoryUsageMBGeneric() {
+#else
+static size_t memoryUsageMB() {
using base::ProcessMetrics;
static ProcessMetrics* process_metrics =
ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle());
@@ -715,14 +712,7 @@ static size_t getMemoryUsageMB(bool bypass_cache) {
mem_usage_cache_singleton->IsCachedValueValid(&current_mem_usage))
return current_mem_usage;
- current_mem_usage =
-#if defined(OS_LINUX)
- memoryUsageMBLinux();
-#elif defined(OS_MACOSX)
- memoryUsageMBMac();
-#else
- memoryUsageMBGeneric();
-#endif
+ current_mem_usage = memoryUsageMB();
mem_usage_cache_singleton->SetMemoryValue(current_mem_usage);
return current_mem_usage;
}
@@ -735,6 +725,29 @@ size_t WebKitPlatformSupportImpl::actualMemoryUsageMB() {
return getMemoryUsageMB(true);
}
+#if defined(OS_ANDROID)
+size_t WebKitPlatformSupportImpl::lowMemoryUsageMB() {
+ // If memory usage is below this threshold, do not bother forcing GC.
+ // Allow us to use up to our memory class value before V8's GC kicks in.
+ // These values have been determined by experimentation.
+ return base::SysInfo::DalvikHeapSizeMB() / 2;
+}
+
+size_t WebKitPlatformSupportImpl::highMemoryUsageMB() {
+ // If memory usage is above this threshold, force GC more aggressively.
+ return base::SysInfo::DalvikHeapSizeMB() * 3 / 4;
+}
+
+size_t WebKitPlatformSupportImpl::highUsageDeltaMB() {
+ // If memory usage is above highMemoryUsageMB() and memory usage increased by
+ // more than highUsageDeltaMB() since the last GC, then force GC.
+ // Note that this limit should be greater than the amount of memory for V8
+ // internal data structures that are released on GC and reallocated during JS
+ // execution (about 8MB). Otherwise, it will cause too aggressive GCs.
+ return base::SysInfo::DalvikHeapSizeMB() / 8;
+}
+#endif
+
void WebKitPlatformSupportImpl::SuspendSharedTimer() {
++shared_timer_suspended_;
}
diff --git a/webkit/glue/webkitplatformsupport_impl.h b/webkit/glue/webkitplatformsupport_impl.h
index 46dd048..635e1b2 100644
--- a/webkit/glue/webkitplatformsupport_impl.h
+++ b/webkit/glue/webkitplatformsupport_impl.h
@@ -18,7 +18,9 @@
#include "webkit/glue/webthemeengine_impl_win.h"
#elif defined(OS_MACOSX)
#include "webkit/glue/webthemeengine_impl_mac.h"
-#elif defined(OS_POSIX)
+#elif defined(OS_ANDROID)
+#include "webkit/glue/webthemeengine_impl_android.h"
+#elif defined(OS_POSIX) && !defined(OS_ANDROID)
#include "webkit/glue/webthemeengine_impl_linux.h"
#endif
@@ -61,6 +63,11 @@ class WEBKIT_GLUE_EXPORT WebKitPlatformSupportImpl :
const WebKit::WebURL& url);
virtual size_t memoryUsageMB();
virtual size_t actualMemoryUsageMB();
+#if defined(OS_ANDROID) // Other OSes just use the default values.
+ virtual size_t lowMemoryUsageMB() OVERRIDE;
+ virtual size_t highMemoryUsageMB() OVERRIDE;
+ virtual size_t highUsageDeltaMB() OVERRIDE;
+#endif
virtual WebKit::WebURLLoader* createURLLoader();
virtual WebKit::WebSocketStreamHandle* createSocketStreamHandle();
virtual WebKit::WebString userAgent(const WebKit::WebURL& url);