Commit 03e7e3e7 authored by Michael Lippautz's avatar Michael Lippautz Committed by V8 LUCI CQ

heap: Move headroom for allocation behind --random-gc-interval

Keep --gc-interval precise wrt to the # of allocations needed for a
GC.

Bug: v8:12615
Change-Id: I1ff45ef709013427b5f27643e3a6135dd0f4025d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3485676Reviewed-by: 's avatarDominik Inführ <dinfuehr@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79256}
parent 4fde3328
...@@ -141,30 +141,20 @@ void HeapAllocator::SetAllocationTimeout(int allocation_timeout) { ...@@ -141,30 +141,20 @@ void HeapAllocator::SetAllocationTimeout(int allocation_timeout) {
} }
void HeapAllocator::UpdateAllocationTimeout() { void HeapAllocator::UpdateAllocationTimeout() {
if (FLAG_random_gc_interval <= 0 && FLAG_gc_interval < 0) return;
int new_timeout;
if (FLAG_random_gc_interval > 0) { if (FLAG_random_gc_interval > 0) {
new_timeout = allocation_timeout_ <= 0 const int new_timeout = allocation_timeout_ <= 0
? heap_->isolate()->fuzzer_rng()->NextInt( ? heap_->isolate()->fuzzer_rng()->NextInt(
FLAG_random_gc_interval + 1) FLAG_random_gc_interval + 1)
: allocation_timeout_; : allocation_timeout_;
// Reset the allocation timeout, but make sure to allow at least a few
} else { // allocations after a collection. The reason for this is that we have a lot
DCHECK_GE(FLAG_gc_interval, 0); // of allocation sequences and we assume that a garbage collection will
new_timeout = FLAG_gc_interval; // allow the subsequent allocation attempts to go through.
constexpr int kFewAllocationsHeadroom = 6;
allocation_timeout_ = std::max(kFewAllocationsHeadroom, new_timeout);
} else if (FLAG_gc_interval >= 0) {
allocation_timeout_ = FLAG_gc_interval;
} }
DCHECK_GE(new_timeout, 0);
// Reset the allocation timeout, but make sure to allow at least a few
// allocations after a collection. The reason for this is that we have a lot
// of allocation sequences and we assume that a garbage collection will allow
// the subsequent allocation attempts to go through.
//
// TODO(v8:12615): Move `kFewAllocationsHeadroom` behind
// `FLAG_random_gc_interval`.
constexpr int kFewAllocationsHeadroom = 6;
allocation_timeout_ = std::max(kFewAllocationsHeadroom, new_timeout);
} }
#endif // V8_ENABLE_ALLOCATION_TIMEOUT #endif // V8_ENABLE_ALLOCATION_TIMEOUT
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
// Flags: --stress-compaction --detailed-error-stack-trace --gc-interval=1 // Flags: --stress-compaction --detailed-error-stack-trace --gc-interval=6
function add(a, b) { function add(a, b) {
throw new Error(); throw new Error();
......
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