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

Unified Diff: src/api.cc

Issue 2895473003: [heap] Simplify and scale ResourceConstraints::ConfigureDefaults. (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « include/v8.h ('k') | src/heap/heap.h » ('j') | src/heap/heap.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 330174e79a2f6c4fd73aa1d22e6b2194b244bd2e..8cdb651443f55cb16c3be82db1d69374ed5965d7 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -69,6 +69,7 @@
#include "src/tracing/trace-event.h"
#include "src/trap-handler/trap-handler.h"
#include "src/unicode-inl.h"
+#include "src/utils.h"
#include "src/v8.h"
#include "src/v8threads.h"
#include "src/value-serializer.h"
@@ -874,38 +875,9 @@ ResourceConstraints::ResourceConstraints()
void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory,
uint64_t virtual_memory_limit) {
-#if V8_OS_ANDROID
- // Android has higher physical memory requirements before raising the maximum
- // heap size limits since it has no swap space.
- const uint64_t low_limit = 512ul * i::MB;
- const uint64_t medium_limit = 1ul * i::GB;
- const uint64_t high_limit = 2ul * i::GB;
-#else
- const uint64_t low_limit = 512ul * i::MB;
- const uint64_t medium_limit = 768ul * i::MB;
- const uint64_t high_limit = 1ul * i::GB;
-#endif
-
- if (physical_memory <= low_limit) {
- set_max_semi_space_size(i::Heap::kMaxSemiSpaceSizeLowMemoryDevice);
- set_max_old_space_size(i::Heap::kMaxOldSpaceSizeLowMemoryDevice);
- set_max_zone_pool_size(i::AccountingAllocator::kMaxPoolSizeLowMemoryDevice);
- } else if (physical_memory <= medium_limit) {
- set_max_semi_space_size(i::Heap::kMaxSemiSpaceSizeMediumMemoryDevice);
- set_max_old_space_size(i::Heap::kMaxOldSpaceSizeMediumMemoryDevice);
- set_max_zone_pool_size(
- i::AccountingAllocator::kMaxPoolSizeMediumMemoryDevice);
- } else if (physical_memory <= high_limit) {
- set_max_semi_space_size(i::Heap::kMaxSemiSpaceSizeHighMemoryDevice);
- set_max_old_space_size(i::Heap::kMaxOldSpaceSizeHighMemoryDevice);
- set_max_zone_pool_size(
- i::AccountingAllocator::kMaxPoolSizeHighMemoryDevice);
- } else {
- set_max_semi_space_size(i::Heap::kMaxSemiSpaceSizeHugeMemoryDevice);
- set_max_old_space_size(i::Heap::kMaxOldSpaceSizeHugeMemoryDevice);
- set_max_zone_pool_size(
- i::AccountingAllocator::kMaxPoolSizeHugeMemoryDevice);
- }
+ set_max_semi_space_size(ComputeMaxSemiSpaceSize(physical_memory));
+ set_max_old_space_size(ComputeMaxOldGenerationSize(physical_memory));
+ set_max_zone_pool_size(i::AccountingAllocator::kMaxPoolSize);
if (virtual_memory_limit > 0 && i::kRequiresCodeRange) {
// Reserve no more than 1/8 of the memory for the code range, but at most
@@ -916,6 +888,24 @@ void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory,
}
}
+int ResourceConstraints::ComputeMaxOldGenerationSize(uint64_t physical_memory) {
+ const int old_space_physical_memory_factor = 4;
+ int value = i::Max(i::Min(static_cast<int>(physical_memory / i::MB /
+ old_space_physical_memory_factor *
+ i::Heap::kPointerMultiplier),
+ i::Heap::kMaxOldSpaceSize),
+ i::Heap::kMinOldSpaceSize);
+ return value;
+}
+
+int ResourceConstraints::ComputeMaxSemiSpaceSize(uint64_t physical_memory) {
+ const uint64_t semi_space_physical_memory_factor = 512;
+ return i::Max(i::Min(static_cast<int>(physical_memory / i::MB /
+ semi_space_physical_memory_factor *
+ i::Heap::kPointerMultiplier),
+ i::Heap::kMaxSemiSpaceSize),
+ i::Heap::kMinSemiSpaceSize);
+}
void SetResourceConstraints(i::Isolate* isolate,
const ResourceConstraints& constraints) {
« no previous file with comments | « include/v8.h ('k') | src/heap/heap.h » ('j') | src/heap/heap.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698