Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // The GYP based build ends up defining USING_V8_SHARED when compiling this | 28 // The GYP based build ends up defining USING_V8_SHARED when compiling this |
| 29 // file. | 29 // file. |
| 30 #undef USING_V8_SHARED | 30 #undef USING_V8_SHARED |
| 31 #include "../include/v8-defaults.h" | 31 #include "../include/v8-defaults.h" |
| 32 | 32 |
| 33 #include "lazy-instance.h" | |
| 33 #include "platform.h" | 34 #include "platform.h" |
| 34 #include "globals.h" | 35 #include "globals.h" |
| 35 #include "v8.h" | 36 #include "v8.h" |
| 36 | 37 |
| 37 namespace v8 { | 38 namespace v8 { |
| 38 | 39 |
| 40 namespace internal { | |
| 39 | 41 |
| 40 #if V8_OS_ANDROID | 42 #if V8_OS_ANDROID |
| 41 const bool kOsHasSwap = false; | 43 const bool kOsHasSwap = false; |
| 42 #else | 44 #else |
| 43 const bool kOsHasSwap = true; | 45 const bool kOsHasSwap = true; |
| 44 #endif | 46 #endif |
| 45 | 47 |
| 48 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
| |
| 49 static LazyInstance<Mutex>::type g_mutex = LAZY_INSTANCE_INITIALIZER; | |
| 50 | |
| 51 } | |
| 52 | |
| 53 | |
| 54 void InitializeDefaultsForCurrentPlatform(uint64_t total_physical_memory) { | |
| 55 i::LockGuard<i::Mutex>(i::g_mutex.Pointer()); | |
| 56 i::g_total_physical_memory = total_physical_memory; | |
| 57 } | |
| 58 | |
| 46 | 59 |
| 47 bool ConfigureResourceConstraintsForCurrentPlatform( | 60 bool ConfigureResourceConstraintsForCurrentPlatform( |
| 48 ResourceConstraints* constraints) { | 61 ResourceConstraints* constraints) { |
| 49 if (constraints == NULL) { | 62 if (constraints == NULL) { |
| 50 return false; | 63 return false; |
| 51 } | 64 } |
| 52 | 65 |
| 53 uint64_t physical_memory = i::OS::TotalPhysicalMemory(); | 66 i::LockGuard<i::Mutex>(i::g_mutex.Pointer()); |
| 67 uint64_t physical_memory = i::g_total_physical_memory; | |
| 54 int lump_of_memory = (i::kPointerSize / 4) * i::MB; | 68 int lump_of_memory = (i::kPointerSize / 4) * i::MB; |
| 55 | 69 |
| 56 // The young_space_size should be a power of 2 and old_generation_size should | 70 // The young_space_size should be a power of 2 and old_generation_size should |
| 57 // be a multiple of Page::kPageSize. | 71 // be a multiple of Page::kPageSize. |
| 58 if (physical_memory <= 512ul * i::MB) { | 72 if (physical_memory == 0) { |
| 73 // InitializeDefaultsForCurrentPlatform has not been called, leave | |
| 74 // ResourceConstraints empty so that non-platform default values are used. | |
| 75 return false; | |
| 76 } else if (physical_memory <= 512ul * i::MB) { | |
| 59 constraints->set_max_young_space_size(2 * lump_of_memory); | 77 constraints->set_max_young_space_size(2 * lump_of_memory); |
| 60 constraints->set_max_old_space_size(128 * lump_of_memory); | 78 constraints->set_max_old_space_size(128 * lump_of_memory); |
| 61 constraints->set_max_executable_size(96 * lump_of_memory); | 79 constraints->set_max_executable_size(96 * lump_of_memory); |
| 62 } else if (physical_memory <= (kOsHasSwap ? 768ul * i::MB : 1ul * i::GB)) { | 80 } else if (physical_memory <= (i::kOsHasSwap ? 768ul * i::MB : 1ul * i::GB)) { |
| 63 constraints->set_max_young_space_size(8 * lump_of_memory); | 81 constraints->set_max_young_space_size(8 * lump_of_memory); |
| 64 constraints->set_max_old_space_size(256 * lump_of_memory); | 82 constraints->set_max_old_space_size(256 * lump_of_memory); |
| 65 constraints->set_max_executable_size(192 * lump_of_memory); | 83 constraints->set_max_executable_size(192 * lump_of_memory); |
| 66 } else if (physical_memory <= (kOsHasSwap ? 1ul * i::GB : 2ul * i::GB)) { | 84 } else if (physical_memory <= (i::kOsHasSwap ? 1ul * i::GB : 2ul * i::GB)) { |
| 67 constraints->set_max_young_space_size(16 * lump_of_memory); | 85 constraints->set_max_young_space_size(16 * lump_of_memory); |
| 68 constraints->set_max_old_space_size(512 * lump_of_memory); | 86 constraints->set_max_old_space_size(512 * lump_of_memory); |
| 69 constraints->set_max_executable_size(256 * lump_of_memory); | 87 constraints->set_max_executable_size(256 * lump_of_memory); |
| 70 } else { | 88 } else { |
| 71 constraints->set_max_young_space_size(16 * lump_of_memory); | 89 constraints->set_max_young_space_size(16 * lump_of_memory); |
| 72 constraints->set_max_old_space_size(700 * lump_of_memory); | 90 constraints->set_max_old_space_size(700 * lump_of_memory); |
| 73 constraints->set_max_executable_size(256 * lump_of_memory); | 91 constraints->set_max_executable_size(256 * lump_of_memory); |
| 74 } | 92 } |
| 75 return true; | 93 return true; |
| 76 } | 94 } |
| 77 | 95 |
| 78 | 96 |
| 79 bool SetDefaultResourceConstraintsForCurrentPlatform() { | 97 bool SetDefaultResourceConstraintsForCurrentPlatform() { |
| 80 ResourceConstraints constraints; | 98 ResourceConstraints constraints; |
| 81 if (!ConfigureResourceConstraintsForCurrentPlatform(&constraints)) | 99 if (!ConfigureResourceConstraintsForCurrentPlatform(&constraints)) |
| 82 return false; | 100 return false; |
| 83 return SetResourceConstraints(&constraints); | 101 return SetResourceConstraints(&constraints); |
| 84 } | 102 } |
| 85 | 103 |
| 86 } // namespace v8 | 104 } // namespace v8 |
| OLD | NEW |