diff options
author | ulan@chromium.org <ulan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-25 15:31:37 +0000 |
---|---|---|
committer | ulan@chromium.org <ulan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-25 15:31:37 +0000 |
commit | 5702108f1a94abd517bae415c335404b1a0397b7 (patch) | |
tree | fbd1cefa9a60f1ed840604f0c785615767e31d84 /base | |
parent | 72f8b1933c2b845adb359de1f841de108055a96e (diff) | |
download | chromium_src-5702108f1a94abd517bae415c335404b1a0397b7.zip chromium_src-5702108f1a94abd517bae415c335404b1a0397b7.tar.gz chromium_src-5702108f1a94abd517bae415c335404b1a0397b7.tar.bz2 |
Set Android/V8 memory limits from dalvik.vm.heapsize.
Fix memory usage computation for Android.
BUG=b/6182964
Review URL: https://chromiumcodereview.appspot.com/10113009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139038 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/base.gypi | 1 | ||||
-rw-r--r-- | base/sys_info.h | 4 | ||||
-rw-r--r-- | base/sys_info_android.cc | 59 |
3 files changed, 64 insertions, 0 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 |