[wasm] Grow reserved code space exponentially
If a new code allocation request cannot be fulfilled, do not just reserve enough to fulfill this one request, but request at least 20 percent of the total reserved code space so far. This ensures that the reserved space grows exponentially instead of linearly. R=mstarzinger@chromium.org Bug: chromium:987560 Change-Id: I3fc4dd0f7acee2a380495a87c0425c58058551bc Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1718144 Reviewed-by: Michael Starzinger <mstarzinger@chromium.org> Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Cr-Commit-Position: refs/heads/master@{#62910}
This commit is contained in:
parent
7f1304755b
commit
9afbef1ebe
@ -480,8 +480,14 @@ Vector<byte> WasmCodeAllocator::AllocateForCode(NativeModule* native_module,
|
||||
Address hint = owned_code_space_.empty() ? kNullAddress
|
||||
: owned_code_space_.back().end();
|
||||
|
||||
// Reserve at least 20% of the total generated code size so far, and of
|
||||
// course at least {size}. Round up to the next power of two.
|
||||
size_t total_reserved = 0;
|
||||
for (auto& vmem : owned_code_space_) total_reserved += vmem.size();
|
||||
size_t reserve_size =
|
||||
base::bits::RoundUpToPowerOfTwo(std::max(size, total_reserved / 5));
|
||||
VirtualMemory new_mem =
|
||||
code_manager_->TryAllocate(size, reinterpret_cast<void*>(hint));
|
||||
code_manager_->TryAllocate(reserve_size, reinterpret_cast<void*>(hint));
|
||||
if (!new_mem.IsReserved()) {
|
||||
V8::FatalProcessOutOfMemory(nullptr, "wasm code reservation");
|
||||
UNREACHABLE();
|
||||
|
Loading…
Reference in New Issue
Block a user