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

Side by Side Diff: base/android/dalvik_heap_size.cc

Issue 10113009: Set Android/V8 memory limits from dalvik.vm.heapsize. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove redundant includes 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/android/dalvik_heap_size.h"
6
7 #include <sys/system_properties.h>
8
Xianzhu 2012/05/15 21:10:25 Should include "base/logging.h" for CHECK and DCHE
ulan 2012/05/16 09:25:52 Added "base/logging.h" and removed "base/memory/si
9 #include "base/memory/singleton.h"
10 #include "base/string_number_conversions.h"
11
12 namespace base {
13 namespace android{
Xianzhu 2012/05/15 21:10:25 Nit: space before '{'
ulan 2012/05/16 09:25:52 Done.
14
15 DalvikHeapSize::DalvikHeapSize() : heap_size_mb_(0) {
16 char heap_size_str[PROP_VALUE_MAX];
17 __system_property_get("dalvik.vm.heapsize", heap_size_str);
18 heap_size_mb_ = ParseHeapSize(std::string(heap_size_str));
19 }
20
21 DalvikHeapSize::~DalvikHeapSize() {}
22
23 int DalvikHeapSize::HeapSizeMB() const {
24 return heap_size_mb_;
25 }
26
27 int DalvikHeapSize::ParseHeapSize(const std::string& str) const {
28 const int64 KB = 1024;
29 const int64 MB = 1024 * KB;
30 const int64 GB = 1024 * MB;
31 CHECK_GT(str.size(), 0u);
32 int64 factor = 1;
33 size_t length = str.size();
34 if (str[length - 1] == 'k') {
35 factor = KB;
36 length--;
37 } else if (str[length - 1] == 'm') {
38 factor = MB;
39 length--;
40 } else if (str[length - 1] == 'g') {
41 factor = GB;
42 length--;
43 } else {
44 CHECK('0' <= str[length - 1] && str[length - 1] <= '9');
45 }
46 int64 result = 0;
47 bool parsed = base::StringToInt64(str.substr(0, length), &result);
48 CHECK(parsed);
49 result = result * factor / MB;
50 // dalvik.vm.heapsize property is writable by user,
51 // truncate it to reasonable value to avoid overflows later.
52 result = std::min<int64>(std::max<int64>(32, result), 1024);
53 return static_cast<int>(result);
54 }
55
56 } // namespace android
57 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698