Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(614)

Unified Diff: base/sys_info_android.cc

Issue 10113009: Set Android/V8 memory limits from dalvik.vm.heapsize. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments, rebase Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/sys_info.h ('k') | webkit/glue/webkitplatformsupport_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/sys_info_android.cc
diff --git a/base/sys_info_android.cc b/base/sys_info_android.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b84b557ec323ad5781fff8443c32f31d18d49046
--- /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
« no previous file with comments | « base/sys_info.h ('k') | webkit/glue/webkitplatformsupport_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698