Chromium Code Reviews| Index: base/sys_info_android.cc |
| diff --git a/base/sys_info_android.cc b/base/sys_info_android.cc |
| index 53801703845c972ff6449fea1da152427af674e5..0f1f61c4a8df1093572190532e836421432087ea 100644 |
| --- a/base/sys_info_android.cc |
| +++ b/base/sys_info_android.cc |
| @@ -44,21 +44,23 @@ void ParseOSVersionNumbers(const char* os_version_str, |
| *bugfix_version = kDefaultAndroidBugfixVersion; |
| } |
| -int ParseHeapSize(const base::StringPiece& str) { |
| +// Parses a size (specified with unit 'k','m' or 'g'). |
| +// Returns a value in bytes. |
| +int64 ParseSizeBytes(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; |
| + int64 unit_multiplier = 1; |
| size_t length = str.size(); |
| if (str[length - 1] == 'k') { |
| - factor = KB; |
| + unit_multiplier = KB; |
| length--; |
| } else if (str[length - 1] == 'm') { |
| - factor = MB; |
| + unit_multiplier = MB; |
| length--; |
| } else if (str[length - 1] == 'g') { |
| - factor = GB; |
| + unit_multiplier = GB; |
| length--; |
| } else { |
| CHECK('0' <= str[length - 1] && str[length - 1] <= '9'); |
|
jar (doing other things)
2013/02/13 21:54:11
It is bothersome that the un-tagged number is limi
epenner
2013/02/14 04:18:36
Sorry, how do you figure it's limited to 10billion
jar (doing other things)
2013/02/15 00:18:23
You are correct. I misread the code in a fast (mi
|
| @@ -66,17 +68,29 @@ int ParseHeapSize(const base::StringPiece& str) { |
| 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); |
| + return result * unit_multiplier; |
|
jar (doing other things)
2013/02/13 21:54:11
This newer code is still problematic, as it ignore
epenner
2013/02/14 04:18:36
Thanks, good point! So, I guess I'll need to add o
|
| } |
| int GetDalvikHeapSizeMB() { |
| char heap_size_str[PROP_VALUE_MAX]; |
| __system_property_get("dalvik.vm.heapsize", heap_size_str); |
| - return ParseHeapSize(heap_size_str); |
| + // dalvik.vm.heapsize property is writable by a root user. |
| + // Clamp it to reasonable range as a sanity check. |
| + const int64 MB = 1024 * 1024; |
| + int64 result = ParseSizeBytes(heap_size_str); |
| + result = std::min<int64>(std::max<int64>(32 * MB, result), 1024 * MB) / MB; |
|
jar (doing other things)
2013/02/13 21:54:11
This bounding was partially (almost) done on line
epenner
2013/02/14 04:18:36
Since we will want to re-use the parsing function
jar (doing other things)
2013/02/15 00:18:23
OK.
On 2013/02/14 04:18:36, epenner wrote:
|
| + return static_cast<int>(result); |
| +} |
| + |
| +int GetDalvikHeapGrowthLimitMB() { |
| + char heap_size_str[PROP_VALUE_MAX]; |
| + __system_property_get("dalvik.vm.heapgrowthlimit", heap_size_str); |
| + // dalvik.vm.heapgrowthlimit property is writable by a root user. |
| + // Clamp it to reasonable range as a sanity check. |
| + const int64 MB = 1024 * 1024; |
| + int64 result = ParseSizeBytes(heap_size_str); |
| + result = std::min<int64>(std::max<int64>(16 * MB, result), 1024 * MB) / MB; |
|
jar (doing other things)
2013/02/14 01:48:41
Why do you clamp this to a different range than th
epenner
2013/02/14 04:18:36
The heap growth limit is typically half of the hea
jar (doing other things)
2013/02/15 00:18:23
nit: Please add comments explaining where these bo
|
| + return static_cast<int>(result); |
| } |
| } // anonymous namespace |
| @@ -122,4 +136,10 @@ int SysInfo::DalvikHeapSizeMB() { |
| return heap_size; |
| } |
| +int SysInfo::DalvikHeapGrowthLimitMB() { |
| + static int heap_growth_limit = GetDalvikHeapGrowthLimitMB(); |
| + return heap_growth_limit; |
| +} |
| + |
| + |
| } // namespace base |