Commit 39a2c91f authored by Michael Lippautz's avatar Michael Lippautz Committed by V8 LUCI CQ

[heap] Fix allocation timeout

Fix underflow in allocation timeout which is used by fuzzers to trigger
garabge collection.

Bug: chromium:1337646
Change-Id: Iffa70497c2945a26242e9e67820197bd5e61f04c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3711758
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarNikolaos Papaspyrou <nikolaos@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81246}
parent 3cb521fe
...@@ -156,7 +156,9 @@ void HeapAllocator::SetAllocationGcInterval(int allocation_gc_interval) { ...@@ -156,7 +156,9 @@ void HeapAllocator::SetAllocationGcInterval(int allocation_gc_interval) {
std::atomic<int> HeapAllocator::allocation_gc_interval_{-1}; std::atomic<int> HeapAllocator::allocation_gc_interval_{-1};
void HeapAllocator::SetAllocationTimeout(int allocation_timeout) { void HeapAllocator::SetAllocationTimeout(int allocation_timeout) {
allocation_timeout_ = allocation_timeout; // See `allocation_timeout_` for description. We map negative values to 0 to
// avoid underflows as allocation decrements this value as well.
allocation_timeout_ = std::max(0, allocation_timeout);
} }
void HeapAllocator::UpdateAllocationTimeout() { void HeapAllocator::UpdateAllocationTimeout() {
......
...@@ -69,6 +69,7 @@ class V8_EXPORT_PRIVATE HeapAllocator final { ...@@ -69,6 +69,7 @@ class V8_EXPORT_PRIVATE HeapAllocator final {
#ifdef V8_ENABLE_ALLOCATION_TIMEOUT #ifdef V8_ENABLE_ALLOCATION_TIMEOUT
void UpdateAllocationTimeout(); void UpdateAllocationTimeout();
// See `allocation_timeout_`.
void SetAllocationTimeout(int allocation_timeout); void SetAllocationTimeout(int allocation_timeout);
static void SetAllocationGcInterval(int allocation_gc_interval); static void SetAllocationGcInterval(int allocation_gc_interval);
...@@ -110,14 +111,15 @@ class V8_EXPORT_PRIVATE HeapAllocator final { ...@@ -110,14 +111,15 @@ class V8_EXPORT_PRIVATE HeapAllocator final {
ConcurrentAllocator* shared_map_allocator_; ConcurrentAllocator* shared_map_allocator_;
#ifdef V8_ENABLE_ALLOCATION_TIMEOUT #ifdef V8_ENABLE_ALLOCATION_TIMEOUT
// If the {allocation_gc_interval_} is set to a positive value, this variable // Specifies how many allocations should be performed until returning
// holds the value indicating the number of allocations remain until the // allocation failure (which will eventually lead to garbage collection).
// next failure and garbage collection. // Allocation will fail for any values <=0. See `UpdateAllocationTimeout()`
// for how the new timeout is computed.
int allocation_timeout_ = 0; int allocation_timeout_ = 0;
// The configured GC interval, initialized from --gc-interval during // The configured GC interval, initialized from --gc-interval during
// {InitializeOncePerProcess} and potentially dynamically updated by // `InitializeOncePerProcess` and potentially dynamically updated by
// %SetAllocationTimeout. // `%SetAllocationTimeout()`.
static std::atomic<int> allocation_gc_interval_; static std::atomic<int> allocation_gc_interval_;
#endif // V8_ENABLE_ALLOCATION_TIMEOUT #endif // V8_ENABLE_ALLOCATION_TIMEOUT
}; };
......
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