Reviewers: Sven Panne,

Message:
PTAL Sven.

Description:
Enable physical memory argument to be passed as an argument to
ConfigureResourceConstraintsForPlatform.

BUG=312241

Please review this at https://codereview.chromium.org/68203003/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+58, -8 lines):
  M include/v8-defaults.h
  M src/d8.cc
  M src/defaults.cc


Index: include/v8-defaults.h
diff --git a/include/v8-defaults.h b/include/v8-defaults.h
index 381a48210d1b9895fbda4e4c89eb0e51fa61b6d0..e0802fcb59300a95a807d9693d3d095cd78270a1 100644
--- a/include/v8-defaults.h
+++ b/include/v8-defaults.h
@@ -38,16 +38,22 @@ namespace v8 {
 /**
  * Configures the constraints with reasonable default values based on the
  * capabilities of the current device the VM is running on.
+ *
+ * \param constraints The constraints object to update
+ * \param physical_memory The total amount of physical memory on the current
+ *   device, in bytes.
  */
-bool V8_EXPORT ConfigureResourceConstraintsForCurrentPlatform(
-    ResourceConstraints* constraints);
+bool V8_EXPORT ConfigureDefaultResourceConstraints(
+    ResourceConstraints* constraints, uint64_t physical_memory);


-/**
- * Convience function which performs SetResourceConstraints with the settings
- * returned by ConfigureResourceConstraintsForCurrentPlatform.
- */
-bool V8_EXPORT SetDefaultResourceConstraintsForCurrentPlatform();
+V8_DEPRECATED("Use ConfigureDefaultResourceConstraints instead",
+    bool V8_EXPORT ConfigureResourceConstraintsForCurrentPlatform(
+        ResourceConstraints* constraints));
+
+
+V8_DEPRECATED("Use ConfigureDefaultResourceConstraints instead",
+    bool V8_EXPORT SetDefaultResourceConstraintsForCurrentPlatform());

 }  // namespace v8

Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index 17bd6713637c7054bde9ca5240975f48b4f5a307..7cdedc1eb2016b4012580608286d5027af48a812 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -1679,11 +1679,15 @@ 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;
+  if (v8::ConfigureDefaultResourceConstraints(&constraints,
+ i::OS::TotalPhysicalMemory())) {
+    v8::SetResourceConstraints(isolate, &constraints);
+  }
   DumbLineEditor dumb_line_editor(isolate);
   {
     Initialize(isolate);
Index: src/defaults.cc
diff --git a/src/defaults.cc b/src/defaults.cc
index a03cf69b088e4f7cfa0b65f5635edd43670f61e7..aee1a438f143578ece7afa23ceb56e1d73470e3b 100644
--- a/src/defaults.cc
+++ b/src/defaults.cc
@@ -37,6 +37,45 @@
 namespace v8 {


+#if V8_OS_ANDROID
+const bool kOsHasSwap = false;
+#else
+const bool kOsHasSwap = true;
+#endif
+
+
+bool ConfigureDefaultResourceConstraints(
+     ResourceConstraints* constraints, uint64_t physical_memory) {
+  if (constraints == NULL) {
+    return false;
+  }
+
+  int lump_of_memory = (i::kPointerSize / 4) * i::MB;
+
+ // The young_space_size should be a power of 2 and old_generation_size should
+  // be a multiple of Page::kPageSize.
+  if (physical_memory <= 512ul * i::MB) {
+    constraints->set_max_young_space_size(2 * lump_of_memory);
+    constraints->set_max_old_space_size(128 * lump_of_memory);
+    constraints->set_max_executable_size(96 * lump_of_memory);
+ } else if (physical_memory <= (kOsHasSwap ? 768ul * i::MB : 1ul * i::GB)) {
+    constraints->set_max_young_space_size(8 * lump_of_memory);
+    constraints->set_max_old_space_size(256 * lump_of_memory);
+    constraints->set_max_executable_size(192 * lump_of_memory);
+  } else if (physical_memory <= (kOsHasSwap ? 1ul * i::GB : 2ul * i::GB)) {
+    constraints->set_max_young_space_size(16 * lump_of_memory);
+    constraints->set_max_old_space_size(512 * lump_of_memory);
+    constraints->set_max_executable_size(256 * lump_of_memory);
+  } else {
+    constraints->set_max_young_space_size(16 * lump_of_memory);
+    constraints->set_max_old_space_size(700 * lump_of_memory);
+    constraints->set_max_executable_size(256 * lump_of_memory);
+  }
+  return true;
+}
+
+
+// TODO(rmcilroy): Remove this function once it is no longer used in Chrome.
 bool ConfigureResourceConstraintsForCurrentPlatform(
     ResourceConstraints* constraints) {
   if (constraints == NULL) {
@@ -60,6 +99,7 @@ bool ConfigureResourceConstraintsForCurrentPlatform(
 }


+// TODO(rmcilroy): Remove this function once it is no longer used in Chrome.
 bool SetDefaultResourceConstraintsForCurrentPlatform() {
   ResourceConstraints constraints;
   if (!ConfigureResourceConstraintsForCurrentPlatform(&constraints))


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to