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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 #include "src/runtime-profiler.h" | 62 #include "src/runtime-profiler.h" |
63 #include "src/runtime/runtime.h" | 63 #include "src/runtime/runtime.h" |
64 #include "src/simulator.h" | 64 #include "src/simulator.h" |
65 #include "src/snapshot/code-serializer.h" | 65 #include "src/snapshot/code-serializer.h" |
66 #include "src/snapshot/natives.h" | 66 #include "src/snapshot/natives.h" |
67 #include "src/snapshot/snapshot.h" | 67 #include "src/snapshot/snapshot.h" |
68 #include "src/startup-data-util.h" | 68 #include "src/startup-data-util.h" |
69 #include "src/tracing/trace-event.h" | 69 #include "src/tracing/trace-event.h" |
70 #include "src/trap-handler/trap-handler.h" | 70 #include "src/trap-handler/trap-handler.h" |
71 #include "src/unicode-inl.h" | 71 #include "src/unicode-inl.h" |
| 72 #include "src/utils.h" |
72 #include "src/v8.h" | 73 #include "src/v8.h" |
73 #include "src/v8threads.h" | 74 #include "src/v8threads.h" |
74 #include "src/value-serializer.h" | 75 #include "src/value-serializer.h" |
75 #include "src/version.h" | 76 #include "src/version.h" |
76 #include "src/vm-state-inl.h" | 77 #include "src/vm-state-inl.h" |
77 #include "src/wasm/wasm-module.h" | 78 #include "src/wasm/wasm-module.h" |
78 #include "src/wasm/wasm-objects.h" | 79 #include "src/wasm/wasm-objects.h" |
79 #include "src/wasm/wasm-result.h" | 80 #include "src/wasm/wasm-result.h" |
80 | 81 |
81 namespace v8 { | 82 namespace v8 { |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 | 868 |
868 ResourceConstraints::ResourceConstraints() | 869 ResourceConstraints::ResourceConstraints() |
869 : max_semi_space_size_(0), | 870 : max_semi_space_size_(0), |
870 max_old_space_size_(0), | 871 max_old_space_size_(0), |
871 stack_limit_(NULL), | 872 stack_limit_(NULL), |
872 code_range_size_(0), | 873 code_range_size_(0), |
873 max_zone_pool_size_(0) {} | 874 max_zone_pool_size_(0) {} |
874 | 875 |
875 void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory, | 876 void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory, |
876 uint64_t virtual_memory_limit) { | 877 uint64_t virtual_memory_limit) { |
877 #if V8_OS_ANDROID | 878 set_max_semi_space_size(ComputeMaxSemiSpaceSize(physical_memory)); |
878 // Android has higher physical memory requirements before raising the maximum | 879 set_max_old_space_size(ComputeMaxOldGenerationSize(physical_memory)); |
879 // heap size limits since it has no swap space. | 880 set_max_zone_pool_size(i::AccountingAllocator::kMaxPoolSize); |
880 const uint64_t low_limit = 512ul * i::MB; | |
881 const uint64_t medium_limit = 1ul * i::GB; | |
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 | 881 |
910 if (virtual_memory_limit > 0 && i::kRequiresCodeRange) { | 882 if (virtual_memory_limit > 0 && i::kRequiresCodeRange) { |
911 // Reserve no more than 1/8 of the memory for the code range, but at most | 883 // Reserve no more than 1/8 of the memory for the code range, but at most |
912 // kMaximalCodeRangeSize. | 884 // kMaximalCodeRangeSize. |
913 set_code_range_size( | 885 set_code_range_size( |
914 i::Min(i::kMaximalCodeRangeSize / i::MB, | 886 i::Min(i::kMaximalCodeRangeSize / i::MB, |
915 static_cast<size_t>((virtual_memory_limit >> 3) / i::MB))); | 887 static_cast<size_t>((virtual_memory_limit >> 3) / i::MB))); |
916 } | 888 } |
917 } | 889 } |
918 | 890 |
| 891 int ResourceConstraints::ComputeMaxOldGenerationSize(uint64_t physical_memory) { |
| 892 const int old_space_physical_memory_factor = 4; |
| 893 int value = i::Max(i::Min(static_cast<int>(physical_memory / i::MB / |
| 894 old_space_physical_memory_factor * |
| 895 i::Heap::kPointerMultiplier), |
| 896 i::Heap::kMaxOldSpaceSize), |
| 897 i::Heap::kMinOldSpaceSize); |
| 898 return value; |
| 899 } |
| 900 |
| 901 int ResourceConstraints::ComputeMaxSemiSpaceSize(uint64_t physical_memory) { |
| 902 const uint64_t semi_space_physical_memory_factor = 512; |
| 903 return i::Max(i::Min(static_cast<int>(physical_memory / i::MB / |
| 904 semi_space_physical_memory_factor * |
| 905 i::Heap::kPointerMultiplier), |
| 906 i::Heap::kMaxSemiSpaceSize), |
| 907 i::Heap::kMinSemiSpaceSize); |
| 908 } |
919 | 909 |
920 void SetResourceConstraints(i::Isolate* isolate, | 910 void SetResourceConstraints(i::Isolate* isolate, |
921 const ResourceConstraints& constraints) { | 911 const ResourceConstraints& constraints) { |
922 int semi_space_size = constraints.max_semi_space_size(); | 912 int semi_space_size = constraints.max_semi_space_size(); |
923 int old_space_size = constraints.max_old_space_size(); | 913 int old_space_size = constraints.max_old_space_size(); |
924 size_t code_range_size = constraints.code_range_size(); | 914 size_t code_range_size = constraints.code_range_size(); |
925 size_t max_pool_size = constraints.max_zone_pool_size(); | 915 size_t max_pool_size = constraints.max_zone_pool_size(); |
926 if (semi_space_size != 0 || old_space_size != 0 || code_range_size != 0) { | 916 if (semi_space_size != 0 || old_space_size != 0 || code_range_size != 0) { |
927 isolate->heap()->ConfigureHeap(semi_space_size, old_space_size, | 917 isolate->heap()->ConfigureHeap(semi_space_size, old_space_size, |
928 code_range_size); | 918 code_range_size); |
(...skipping 9583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10512 Address callback_address = | 10502 Address callback_address = |
10513 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 10503 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
10514 VMState<EXTERNAL> state(isolate); | 10504 VMState<EXTERNAL> state(isolate); |
10515 ExternalCallbackScope call_scope(isolate, callback_address); | 10505 ExternalCallbackScope call_scope(isolate, callback_address); |
10516 callback(info); | 10506 callback(info); |
10517 } | 10507 } |
10518 | 10508 |
10519 | 10509 |
10520 } // namespace internal | 10510 } // namespace internal |
10521 } // namespace v8 | 10511 } // namespace v8 |
OLD | NEW |