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

Unified Diff: webkit/glue/dalvik_heap_size_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 Created 8 years, 8 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
Index: webkit/glue/dalvik_heap_size_android.cc
diff --git a/webkit/glue/dalvik_heap_size_android.cc b/webkit/glue/dalvik_heap_size_android.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2eb82b9da9c1bc2933d4718de196910955ca3a5b
--- /dev/null
+++ b/webkit/glue/dalvik_heap_size_android.cc
@@ -0,0 +1,39 @@
+// 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 "webkit/glue/dalvik_heap_size_android.h"
jamesr 2012/04/20 00:44:26 i can't figure out why this class is here. it has
ulan 2012/04/20 08:55:43 Moved it to webkitplatformsupport_impl.cc, where i
+
+#include <sys/system_properties.h>
+
+#include "base/memory/singleton.h"
+#include "base/string_number_conversions.h"
+
+namespace webkit_glue {
+
+DalvikHeapSize* DalvikHeapSize::GetInstance() {
+ return Singleton<DalvikHeapSize>::get();
+}
+
+DalvikHeapSize::DalvikHeapSize() : heap_size_mb_(0) {
+ char heap_size_str[PROP_VALUE_MAX];
+ __system_property_get("dalvik.vm.heapsize", heap_size_str);
+ heap_size_mb_ = ParseHeapSize(std::string(heap_size_str));
+}
+
+DalvikHeapSize::~DalvikHeapSize() {}
+
+int DalvikHeapSize::HeapSizeMB() const { return heap_size_mb_; }
+
+int DalvikHeapSize::ParseHeapSize(const std::string& str) const {
+ CHECK_GT(str.size(), 0u);
+ DCHECK_EQ('m', str[str.size() - 1]);
jamesr 2012/04/20 00:44:26 this seems a bit fragile - you can't have a value
ulan 2012/04/20 08:55:43 Added handling of 'k', 'g' and switched to int64 t
+ int result = 0;
+ base::StringToInt(str.substr(0, str.size() - 1), &result);
jamesr 2012/04/20 00:44:26 base::StringToInt() returns a bool indicating if t
ulan 2012/04/20 08:55:43 Done.
+ DCHECK_GT(result, 0);
+ // dalvik.vm.heapsize property is writable by user,
+ // truncate it to reasonable value to avoid overflows later.
+ return std::min(std::max(32, result), 1024);
+}
+
+} // webkit_glue namespace

Powered by Google App Engine
This is Rietveld 408576698