| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/api.h" | 5 #include "src/api.h" |
| 6 | 6 |
| 7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
| 8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
| 9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
| 10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
| (...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 | 867 |
| 868 ResourceConstraints::ResourceConstraints() | 868 ResourceConstraints::ResourceConstraints() |
| 869 : max_semi_space_size_(0), | 869 : max_semi_space_size_(0), |
| 870 max_old_space_size_(0), | 870 max_old_space_size_(0), |
| 871 stack_limit_(NULL), | 871 stack_limit_(NULL), |
| 872 code_range_size_(0), | 872 code_range_size_(0), |
| 873 max_zone_pool_size_(0) {} | 873 max_zone_pool_size_(0) {} |
| 874 | 874 |
| 875 void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory, | 875 void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory, |
| 876 uint64_t virtual_memory_limit) { | 876 uint64_t virtual_memory_limit) { |
| 877 #if V8_OS_ANDROID | 877 set_max_semi_space_size( |
| 878 // Android has higher physical memory requirements before raising the maximum | 878 static_cast<int>(i::Heap::ComputeMaxSemiSpaceSize(physical_memory))); |
| 879 // heap size limits since it has no swap space. | 879 set_max_old_space_size( |
| 880 const uint64_t low_limit = 512ul * i::MB; | 880 static_cast<int>(i::Heap::ComputeMaxOldGenerationSize(physical_memory))); |
| 881 const uint64_t medium_limit = 1ul * i::GB; | 881 set_max_zone_pool_size(i::AccountingAllocator::kMaxPoolSize); |
| 882 const uint64_t high_limit = 2ul * i::GB; | |
| 883 #else | |
| 884 const uint64_t low_limit = 512ul * i::MB; | |
| 885 const uint64_t medium_limit = 768ul * i::MB; | |
| 886 const uint64_t high_limit = 1ul * i::GB; | |
| 887 #endif | |
| 888 | |
| 889 if (physical_memory <= low_limit) { | |
| 890 set_max_semi_space_size(i::Heap::kMaxSemiSpaceSizeLowMemoryDevice); | |
| 891 set_max_old_space_size(i::Heap::kMaxOldSpaceSizeLowMemoryDevice); | |
| 892 set_max_zone_pool_size(i::AccountingAllocator::kMaxPoolSizeLowMemoryDevice); | |
| 893 } else if (physical_memory <= medium_limit) { | |
| 894 set_max_semi_space_size(i::Heap::kMaxSemiSpaceSizeMediumMemoryDevice); | |
| 895 set_max_old_space_size(i::Heap::kMaxOldSpaceSizeMediumMemoryDevice); | |
| 896 set_max_zone_pool_size( | |
| 897 i::AccountingAllocator::kMaxPoolSizeMediumMemoryDevice); | |
| 898 } else if (physical_memory <= high_limit) { | |
| 899 set_max_semi_space_size(i::Heap::kMaxSemiSpaceSizeHighMemoryDevice); | |
| 900 set_max_old_space_size(i::Heap::kMaxOldSpaceSizeHighMemoryDevice); | |
| 901 set_max_zone_pool_size( | |
| 902 i::AccountingAllocator::kMaxPoolSizeHighMemoryDevice); | |
| 903 } else { | |
| 904 set_max_semi_space_size(i::Heap::kMaxSemiSpaceSizeHugeMemoryDevice); | |
| 905 set_max_old_space_size(i::Heap::kMaxOldSpaceSizeHugeMemoryDevice); | |
| 906 set_max_zone_pool_size( | |
| 907 i::AccountingAllocator::kMaxPoolSizeHugeMemoryDevice); | |
| 908 } | |
| 909 | 882 |
| 910 if (virtual_memory_limit > 0 && i::kRequiresCodeRange) { | 883 if (virtual_memory_limit > 0 && i::kRequiresCodeRange) { |
| 911 // Reserve no more than 1/8 of the memory for the code range, but at most | 884 // Reserve no more than 1/8 of the memory for the code range, but at most |
| 912 // kMaximalCodeRangeSize. | 885 // kMaximalCodeRangeSize. |
| 913 set_code_range_size( | 886 set_code_range_size( |
| 914 i::Min(i::kMaximalCodeRangeSize / i::MB, | 887 i::Min(i::kMaximalCodeRangeSize / i::MB, |
| 915 static_cast<size_t>((virtual_memory_limit >> 3) / i::MB))); | 888 static_cast<size_t>((virtual_memory_limit >> 3) / i::MB))); |
| 916 } | 889 } |
| 917 } | 890 } |
| 918 | 891 |
| 919 | |
| 920 void SetResourceConstraints(i::Isolate* isolate, | 892 void SetResourceConstraints(i::Isolate* isolate, |
| 921 const ResourceConstraints& constraints) { | 893 const ResourceConstraints& constraints) { |
| 922 int semi_space_size = constraints.max_semi_space_size(); | 894 int semi_space_size = constraints.max_semi_space_size(); |
| 923 int old_space_size = constraints.max_old_space_size(); | 895 int old_space_size = constraints.max_old_space_size(); |
| 924 size_t code_range_size = constraints.code_range_size(); | 896 size_t code_range_size = constraints.code_range_size(); |
| 925 size_t max_pool_size = constraints.max_zone_pool_size(); | 897 size_t max_pool_size = constraints.max_zone_pool_size(); |
| 926 if (semi_space_size != 0 || old_space_size != 0 || code_range_size != 0) { | 898 if (semi_space_size != 0 || old_space_size != 0 || code_range_size != 0) { |
| 927 isolate->heap()->ConfigureHeap(semi_space_size, old_space_size, | 899 isolate->heap()->ConfigureHeap(semi_space_size, old_space_size, |
| 928 code_range_size); | 900 code_range_size); |
| 929 } | 901 } |
| (...skipping 9582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10512 Address callback_address = | 10484 Address callback_address = |
| 10513 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 10485 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 10514 VMState<EXTERNAL> state(isolate); | 10486 VMState<EXTERNAL> state(isolate); |
| 10515 ExternalCallbackScope call_scope(isolate, callback_address); | 10487 ExternalCallbackScope call_scope(isolate, callback_address); |
| 10516 callback(info); | 10488 callback(info); |
| 10517 } | 10489 } |
| 10518 | 10490 |
| 10519 | 10491 |
| 10520 } // namespace internal | 10492 } // namespace internal |
| 10521 } // namespace v8 | 10493 } // namespace v8 |
| OLD | NEW |