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

Unified Diff: src/defaults.cc

Issue 40233002: Avoid calling OS::TotalPhysicalMemory in defaults.cc, since this fails in the chrome renderer sandb… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 2 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
« src/d8.cc ('K') | « src/d8.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/defaults.cc
diff --git a/src/defaults.cc b/src/defaults.cc
index cbbe53729ebd171772106b589ae8b8c6fb4488d1..196ec776af1111406bac5a97aee10cc0b18a4ac2 100644
--- a/src/defaults.cc
+++ b/src/defaults.cc
@@ -30,12 +30,14 @@
#undef USING_V8_SHARED
#include "../include/v8-defaults.h"
+#include "lazy-instance.h"
#include "platform.h"
#include "globals.h"
#include "v8.h"
namespace v8 {
+namespace internal {
#if V8_OS_ANDROID
const bool kOsHasSwap = false;
@@ -43,6 +45,17 @@ const bool kOsHasSwap = false;
const bool kOsHasSwap = true;
#endif
+static uint64_t g_total_physical_memory = 0;
Benedikt Meurer 2013/10/24 18:09:02 Please no more global state. See comment in v8-def
+static LazyInstance<Mutex>::type g_mutex = LAZY_INSTANCE_INITIALIZER;
+
+}
+
+
+void InitializeDefaultsForCurrentPlatform(uint64_t total_physical_memory) {
+ i::LockGuard<i::Mutex>(i::g_mutex.Pointer());
+ i::g_total_physical_memory = total_physical_memory;
+}
+
bool ConfigureResourceConstraintsForCurrentPlatform(
ResourceConstraints* constraints) {
@@ -50,20 +63,25 @@ bool ConfigureResourceConstraintsForCurrentPlatform(
return false;
}
- uint64_t physical_memory = i::OS::TotalPhysicalMemory();
+ i::LockGuard<i::Mutex>(i::g_mutex.Pointer());
+ uint64_t physical_memory = i::g_total_physical_memory;
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) {
+ if (physical_memory == 0) {
+ // InitializeDefaultsForCurrentPlatform has not been called, leave
+ // ResourceConstraints empty so that non-platform default values are used.
+ return false;
+ } else 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)) {
+ } else if (physical_memory <= (i::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)) {
+ } else if (physical_memory <= (i::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);
« src/d8.cc ('K') | « src/d8.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698