Chromium Code Reviews| 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); |