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

Side by Side 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: Use static variable instead of LazyInstance 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/sys_info.h"
6
7 #include <sys/system_properties.h>
8
9 #include "base/logging.h"
10 #include "base/string_number_conversions.h"
11
12 namespace {
13
14 int ParseHeapSize(const std::string& str) {
darin (slow to review) 2012/05/24 22:27:43 nit: consider changing the parameter to base::Stri
ulan 2012/05/25 14:14:36 Done.
15 const int64 KB = 1024;
16 const int64 MB = 1024 * KB;
17 const int64 GB = 1024 * MB;
18 CHECK_GT(str.size(), 0u);
19 int64 factor = 1;
20 size_t length = str.size();
21 if (str[length - 1] == 'k') {
22 factor = KB;
23 length--;
24 } else if (str[length - 1] == 'm') {
25 factor = MB;
26 length--;
27 } else if (str[length - 1] == 'g') {
28 factor = GB;
29 length--;
30 } else {
31 CHECK('0' <= str[length - 1] && str[length - 1] <= '9');
32 }
33 int64 result = 0;
34 bool parsed = base::StringToInt64(str.substr(0, length), &result);
35 CHECK(parsed);
36 result = result * factor / MB;
37 // dalvik.vm.heapsize property is writable by user,
38 // truncate it to reasonable value to avoid overflows later.
39 result = std::min<int64>(std::max<int64>(32, result), 1024);
40 return static_cast<int>(result);
41 }
42
43 int GetDalvikHeapSizeMB() {
44 char heap_size_str[PROP_VALUE_MAX];
45 __system_property_get("dalvik.vm.heapsize", heap_size_str);
46 return ParseHeapSize(std::string(heap_size_str));
47 }
48
49 } // anonymous namespace
50
51 namespace base {
52
53 int SysInfo::DalvikHeapSizeMB() {
54 static int heap_size = GetDalvikHeapSizeMB();
55 return heap_size;
56 }
57
58 } // namespace base
OLDNEW
« no previous file with comments | « base/sys_info.h ('k') | base/sys_info_linux.cc » ('j') | base/sys_info_linux.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698