Commit a75cc46d authored by Dominik Inführ's avatar Dominik Inführ Committed by Commit Bot

[heap] Return Optional from GlobalMemoryAvailable

Return no value when global memory scheduling is off. Previously
returned new_space->Capacity()+1 since this value was used in the
callers to compare the result to.

Bug: v8:10315
Change-Id: I7c7289ee9319fe9c791c3cb9b9b46cca54815904
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2235704
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68251}
parent 8bdd4e86
......@@ -1763,10 +1763,12 @@ void Heap::StartIncrementalMarkingIfAllocationLimitIsReachedBackground() {
}
const size_t old_generation_space_available = OldGenerationSpaceAvailable();
const size_t global_memory_available = GlobalMemoryAvailable();
const base::Optional<size_t> global_memory_available =
GlobalMemoryAvailable();
if (old_generation_space_available < new_space_->Capacity() ||
global_memory_available < new_space_->Capacity()) {
(global_memory_available &&
*global_memory_available < new_space_->Capacity())) {
incremental_marking()->incremental_marking_job()->ScheduleTask(this);
}
}
......@@ -5047,12 +5049,15 @@ Heap::HeapGrowingMode Heap::CurrentHeapGrowingMode() {
return Heap::HeapGrowingMode::kDefault;
}
size_t Heap::GlobalMemoryAvailable() {
return UseGlobalMemoryScheduling()
? GlobalSizeOfObjects() < global_allocation_limit_
? global_allocation_limit_ - GlobalSizeOfObjects()
: 0
: new_space_->Capacity() + 1;
base::Optional<size_t> Heap::GlobalMemoryAvailable() {
if (!UseGlobalMemoryScheduling()) return {};
size_t global_size = GlobalSizeOfObjects();
if (global_size < global_allocation_limit_)
return global_allocation_limit_ - global_size;
return 0;
}
double Heap::PercentToOldGenerationLimit() {
......@@ -5135,10 +5140,12 @@ Heap::IncrementalMarkingLimit Heap::IncrementalMarkingLimitReached() {
}
size_t old_generation_space_available = OldGenerationSpaceAvailable();
const size_t global_memory_available = GlobalMemoryAvailable();
const base::Optional<size_t> global_memory_available =
GlobalMemoryAvailable();
if (old_generation_space_available > new_space_->Capacity() &&
(global_memory_available > new_space_->Capacity())) {
(!global_memory_available ||
global_memory_available > new_space_->Capacity())) {
return IncrementalMarkingLimit::kNoLimit;
}
if (ShouldOptimizeForMemoryUsage()) {
......@@ -5150,7 +5157,7 @@ Heap::IncrementalMarkingLimit Heap::IncrementalMarkingLimitReached() {
if (old_generation_space_available == 0) {
return IncrementalMarkingLimit::kHardLimit;
}
if (global_memory_available == 0) {
if (global_memory_available && *global_memory_available == 0) {
return IncrementalMarkingLimit::kHardLimit;
}
return IncrementalMarkingLimit::kSoftLimit;
......
......@@ -1885,7 +1885,7 @@ class Heap {
return FLAG_global_gc_scheduling && local_embedder_heap_tracer();
}
size_t GlobalMemoryAvailable();
base::Optional<size_t> GlobalMemoryAvailable();
void RecomputeLimits(GarbageCollector collector);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment