[heap] Clean up initialization of heap limits and fix global limits

This moves initialization of heap limits to one place: ConfigureHeap
and also initializes the global limits there.

Change-Id: I7ca76073680a97627a8b1da9a8310af003794a93
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1648259
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62573}
This commit is contained in:
Ulan Degenbaev 2019-07-08 15:16:57 +02:00 committed by Commit Bot
parent 31cd5d83d3
commit cb47987912
2 changed files with 34 additions and 22 deletions

View File

@ -185,16 +185,8 @@ class IdleScavengeObserver : public AllocationObserver {
Heap::Heap()
: isolate_(isolate()),
initial_max_old_generation_size_(max_old_generation_size_),
initial_max_old_generation_size_threshold_(0),
initial_old_generation_size_(
Min(max_old_generation_size_, kMaxInitialOldGenerationSize)),
memory_pressure_level_(MemoryPressureLevel::kNone),
old_generation_allocation_limit_(initial_old_generation_size_),
global_allocation_limit_(initial_old_generation_size_),
global_pretenuring_feedback_(kInitialFeedbackCapacity),
current_gc_callback_flags_(GCCallbackFlags::kNoGCCallbackFlags),
is_current_gc_forced_(false),
external_string_table_(this) {
// Ensure old_generation_size_ is a multiple of kPageSize.
DCHECK_EQ(0, max_old_generation_size_ & (Page::kPageSize - 1));
@ -4417,9 +4409,18 @@ void Heap::IterateBuiltins(RootVisitor* v) {
#endif // V8_EMBEDDED_BUILTINS
}
namespace {
size_t GlobalMemorySizeFromV8Size(size_t v8_size) {
const size_t kGlobalMemoryToV8Ratio = 2;
return Min(static_cast<uint64_t>(std::numeric_limits<size_t>::max()),
static_cast<uint64_t>(v8_size) * kGlobalMemoryToV8Ratio);
}
} // anonymous namespace
void Heap::ConfigureHeap(const v8::ResourceConstraints& constraints) {
// Initialize max_semi_space_size_.
{
max_semi_space_size_ = 8 * (kSystemPointerSize / 4) * MB;
if (constraints.max_young_generation_size_in_bytes() > 0) {
max_semi_space_size_ = SemiSpaceSizeFromYoungGenerationSize(
constraints.max_young_generation_size_in_bytes());
@ -4455,8 +4456,9 @@ void Heap::ConfigureHeap(const v8::ResourceConstraints& constraints) {
max_semi_space_size_ = RoundDown<Page::kPageSize>(max_semi_space_size_);
}
// Initialize max_old_generation_size_.
// Initialize max_old_generation_size_ and max_global_memory_.
{
max_old_generation_size_ = 700ul * (kSystemPointerSize / 4) * MB;
if (constraints.max_old_generation_size_in_bytes() > 0) {
max_old_generation_size_ = constraints.max_old_generation_size_in_bytes();
}
@ -4475,6 +4477,9 @@ void Heap::ConfigureHeap(const v8::ResourceConstraints& constraints) {
Max(max_old_generation_size_, MinOldGenerationSize());
max_old_generation_size_ =
RoundDown<Page::kPageSize>(max_old_generation_size_);
max_global_memory_size_ =
GlobalMemorySizeFromV8Size(max_old_generation_size_);
}
CHECK_IMPLIES(FLAG_max_heap_size > 0,
@ -4482,6 +4487,7 @@ void Heap::ConfigureHeap(const v8::ResourceConstraints& constraints) {
// Initialize initial_semispace_size_.
{
initial_semispace_size_ = kMinSemiSpaceSize;
if (max_semi_space_size_ == kMaxSemiSpaceSize) {
// Start with at least 1*MB semi-space on machines with a lot of memory.
initial_semispace_size_ =
@ -4524,6 +4530,8 @@ void Heap::ConfigureHeap(const v8::ResourceConstraints& constraints) {
// If the embedder pre-configures the initial old generation size,
// then allow V8 to skip full GCs below that threshold.
min_old_generation_size_ = initial_old_generation_size_;
min_global_memory_size_ =
GlobalMemorySizeFromV8Size(min_old_generation_size_);
}
if (FLAG_semi_space_growth_factor < 2) {
@ -4531,6 +4539,8 @@ void Heap::ConfigureHeap(const v8::ResourceConstraints& constraints) {
}
old_generation_allocation_limit_ = initial_old_generation_size_;
global_allocation_limit_ =
GlobalMemorySizeFromV8Size(old_generation_allocation_limit_);
initial_max_old_generation_size_ = max_old_generation_size_;
// We rely on being able to allocate new arrays in paged spaces.

View File

@ -1809,24 +1809,25 @@ class Heap {
// more expedient to get at the isolate directly from within Heap methods.
Isolate* isolate_ = nullptr;
// These limits are initialized in Heap::ConfigureHeap based on the resource
// constraints and flags.
size_t code_range_size_ = 0;
size_t max_semi_space_size_ = 8 * (kSystemPointerSize / 4) * MB;
size_t initial_semispace_size_ = kMinSemiSpaceSize;
size_t max_semi_space_size_ = 0;
size_t initial_semispace_size_ = 0;
// Full garbage collections can be skipped if the old generation size
// is below this threshold.
size_t min_old_generation_size_ = 0;
// If the old generation size exceeds this limit, then V8 will
// crash with out-of-memory error.
size_t max_old_generation_size_ = 700ul * (kSystemPointerSize / 4) * MB;
size_t max_old_generation_size_ = 0;
// TODO(mlippautz): Clarify whether this should take some embedder
// configurable limit into account.
size_t min_global_memory_size_ = 0;
size_t max_global_memory_size_ =
Min(static_cast<uint64_t>(std::numeric_limits<size_t>::max()),
static_cast<uint64_t>(max_old_generation_size_) * 2);
size_t initial_max_old_generation_size_;
size_t initial_max_old_generation_size_threshold_;
size_t initial_old_generation_size_;
size_t max_global_memory_size_ = 0;
size_t initial_max_old_generation_size_ = 0;
size_t initial_max_old_generation_size_threshold_ = 0;
size_t initial_old_generation_size_ = 0;
bool old_generation_size_configured_ = false;
size_t maximum_committed_ = 0;
size_t old_generation_capacity_after_bootstrap_ = 0;
@ -1929,8 +1930,8 @@ class Heap {
// is checked when we have already decided to do a GC to help determine
// which collector to invoke, before expanding a paged space in the old
// generation and on every allocation in large object space.
size_t old_generation_allocation_limit_;
size_t global_allocation_limit_;
size_t old_generation_allocation_limit_ = 0;
size_t global_allocation_limit_ = 0;
// Indicates that inline bump-pointer allocation has been globally disabled
// for all spaces. This is used to disable allocations in generated code.
@ -2031,9 +2032,10 @@ class Heap {
// Currently set GC callback flags that are used to pass information between
// the embedder and V8's GC.
GCCallbackFlags current_gc_callback_flags_;
GCCallbackFlags current_gc_callback_flags_ =
GCCallbackFlags::kNoGCCallbackFlags;
bool is_current_gc_forced_;
bool is_current_gc_forced_ = false;
ExternalStringTable external_string_table_;