Enable physical memory argument to be passed as an argument to ConfigureResourceConst...
authorrmcilroy@chromium.org <rmcilroy@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 13 Nov 2013 14:05:06 +0000 (14:05 +0000)
committerrmcilroy@chromium.org <rmcilroy@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 13 Nov 2013 14:05:06 +0000 (14:05 +0000)
BUG=312241
R=svenpanne@chromium.org

Review URL: https://codereview.chromium.org/68203003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17696 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

include/v8-defaults.h
include/v8.h
src/api.cc
src/d8.cc
src/defaults.cc

index 381a482..b55c07f 100644 (file)
  */
 namespace v8 {
 
-/**
- * Configures the constraints with reasonable default values based on the
- * capabilities of the current device the VM is running on.
- */
-bool V8_EXPORT ConfigureResourceConstraintsForCurrentPlatform(
-    ResourceConstraints* constraints);
+V8_DEPRECATED("Use ResourceConstraints::ConfigureDefaults instead",
+    bool V8_EXPORT ConfigureResourceConstraintsForCurrentPlatform(
+        ResourceConstraints* constraints));
 
 
-/**
- * Convience function which performs SetResourceConstraints with the settings
- * returned by ConfigureResourceConstraintsForCurrentPlatform.
- */
-bool V8_EXPORT SetDefaultResourceConstraintsForCurrentPlatform();
+V8_DEPRECATED("Use ResourceConstraints::ConfigureDefaults instead",
+    bool V8_EXPORT SetDefaultResourceConstraintsForCurrentPlatform());
 
 }  // namespace v8
 
index f8ef7c1..d6678c5 100644 (file)
@@ -3803,6 +3803,16 @@ V8_INLINE Handle<Boolean> False(Isolate* isolate);
 class V8_EXPORT ResourceConstraints {
  public:
   ResourceConstraints();
+
+  /**
+   * Configures the constraints with reasonable default values based on the
+   * capabilities of the current device the VM is running on.
+   *
+   * \param physical_memory The total amount of physical memory on the current
+   *   device, in bytes.
+   */
+  void ConfigureDefaults(uint64_t physical_memory);
+
   int max_young_space_size() const { return max_young_space_size_; }
   void set_max_young_space_size(int value) { max_young_space_size_ = value; }
   int max_old_space_size() const { return max_old_space_size_; }
index 65e7345..4a405a9 100644 (file)
@@ -566,6 +566,42 @@ ResourceConstraints::ResourceConstraints()
     stack_limit_(NULL) { }
 
 
+void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory) {
+  const int lump_of_memory = (i::kPointerSize / 4) * i::MB;
+#if V8_OS_ANDROID
+  // Android has higher physical memory requirements before raising the maximum
+  // heap size limits since it has no swap space.
+  const uint64_t low_limit = 512ul * i::MB;
+  const uint64_t medium_limit = 1ul * i::GB;
+  const uint64_t high_limit = 2ul * i::GB;
+#else
+  const uint64_t low_limit = 512ul * i::MB;
+  const uint64_t medium_limit = 768ul * i::MB;
+  const uint64_t high_limit = 1ul  * i::GB;
+#endif
+
+  // The young_space_size should be a power of 2 and old_generation_size should
+  // be a multiple of Page::kPageSize.
+  if (physical_memory <= low_limit) {
+    set_max_young_space_size(2 * lump_of_memory);
+    set_max_old_space_size(128 * lump_of_memory);
+    set_max_executable_size(96 * lump_of_memory);
+  } else if (physical_memory <= medium_limit) {
+    set_max_young_space_size(8 * lump_of_memory);
+    set_max_old_space_size(256 * lump_of_memory);
+    set_max_executable_size(192 * lump_of_memory);
+  } else if (physical_memory <= high_limit) {
+    set_max_young_space_size(16 * lump_of_memory);
+    set_max_old_space_size(512 * lump_of_memory);
+    set_max_executable_size(256 * lump_of_memory);
+  } else {
+    set_max_young_space_size(16 * lump_of_memory);
+    set_max_old_space_size(700 * lump_of_memory);
+    set_max_executable_size(256 * lump_of_memory);
+  }
+}
+
+
 bool SetResourceConstraints(ResourceConstraints* constraints) {
   i::Isolate* isolate = EnterIsolateIfNeeded();
   return SetResourceConstraints(reinterpret_cast<Isolate*>(isolate),
index 17bd671..a71b33b 100644 (file)
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -1679,11 +1679,13 @@ int Shell::Main(int argc, char* argv[]) {
 #else
   SetStandaloneFlagsViaCommandLine();
 #endif
-  v8::SetDefaultResourceConstraintsForCurrentPlatform();
   ShellArrayBufferAllocator array_buffer_allocator;
   v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
   int result = 0;
   Isolate* isolate = Isolate::GetCurrent();
+  v8::ResourceConstraints constraints;
+  constraints.ConfigureDefaults(i::OS::TotalPhysicalMemory());
+  v8::SetResourceConstraints(isolate, &constraints);
   DumbLineEditor dumb_line_editor(isolate);
   {
     Initialize(isolate);
index a03cf69..6bfbfef 100644 (file)
@@ -37,6 +37,7 @@
 namespace v8 {
 
 
+// TODO(rmcilroy): Remove this function once it is no longer used in Chrome.
 bool ConfigureResourceConstraintsForCurrentPlatform(
     ResourceConstraints* constraints) {
   if (constraints == NULL) {
@@ -60,6 +61,7 @@ bool ConfigureResourceConstraintsForCurrentPlatform(
 }
 
 
+// TODO(rmcilroy): Remove this function once it is no longer used in Chrome.
 bool SetDefaultResourceConstraintsForCurrentPlatform() {
   ResourceConstraints constraints;
   if (!ConfigureResourceConstraintsForCurrentPlatform(&constraints))