Commit ba07060a authored by Clemens Backes's avatar Clemens Backes Committed by V8 LUCI CQ

[wasm] Use FormattedString for OOM messages

Use the newly introduced FormattedString class
(https://crrev.com/c/3644622) for formatting OOM messages in Wasm.
Those details will soon be put in a special "OOMDetails" struct instead
of in the location (see linked bug), but we will still generate a similar
string.

R=mlippautz@chromium.org

Bug: chromium:1323177
Change-Id: I4012e8816965285ec654f67ac700befbbbbeb9e7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3644625Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80547}
parent 5696b526
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "src/base/macros.h" #include "src/base/macros.h"
#include "src/base/platform/platform.h" #include "src/base/platform/platform.h"
#include "src/base/small-vector.h" #include "src/base/small-vector.h"
#include "src/base/string-format.h"
#include "src/base/vector.h" #include "src/base/vector.h"
#include "src/codegen/assembler-inl.h" #include "src/codegen/assembler-inl.h"
#include "src/codegen/macro-assembler-inl.h" #include "src/codegen/macro-assembler-inl.h"
...@@ -620,15 +621,11 @@ size_t ReservationSize(size_t code_size_estimate, int num_declared_functions, ...@@ -620,15 +621,11 @@ size_t ReservationSize(size_t code_size_estimate, int num_declared_functions,
total_reserved / 4); total_reserved / 4);
if (V8_UNLIKELY(minimum_size > WasmCodeAllocator::kMaxCodeSpaceSize)) { if (V8_UNLIKELY(minimum_size > WasmCodeAllocator::kMaxCodeSpaceSize)) {
constexpr auto format = base::StaticCharVector( auto oom_msg = base::FormattedString{}
"wasm code reservation: required minimum (%zu) is bigger than " << "wasm code reservation: required minimum ("
"supported maximum (%zu)"); << minimum_size << ") is bigger than supported maximum ("
constexpr int kMaxMessageLength = << WasmCodeAllocator::kMaxCodeSpaceSize << ")";
format.size() - 6 + 2 * std::numeric_limits<size_t>::digits10; V8::FatalProcessOutOfMemory(nullptr, oom_msg.PrintToArray().data());
base::EmbeddedVector<char, kMaxMessageLength + 1> message;
SNPrintF(message, format.begin(), minimum_size,
WasmCodeAllocator::kMaxCodeSpaceSize);
V8::FatalProcessOutOfMemory(nullptr, message.begin());
UNREACHABLE(); UNREACHABLE();
} }
...@@ -730,13 +727,10 @@ base::Vector<byte> WasmCodeAllocator::AllocateForCodeInRegion( ...@@ -730,13 +727,10 @@ base::Vector<byte> WasmCodeAllocator::AllocateForCodeInRegion(
VirtualMemory new_mem = VirtualMemory new_mem =
code_manager->TryAllocate(reserve_size, reinterpret_cast<void*>(hint)); code_manager->TryAllocate(reserve_size, reinterpret_cast<void*>(hint));
if (!new_mem.IsReserved()) { if (!new_mem.IsReserved()) {
constexpr auto format = base::StaticCharVector( auto oom_msg = base::FormattedString{}
"Cannot allocate more code space (%zu bytes, currently %zu)"); << "Cannot allocate more code space (" << reserve_size
constexpr int kMaxMessageLength = << " bytes, currently " << total_reserved << ")";
format.size() - 6 + 2 * std::numeric_limits<size_t>::digits10; V8::FatalProcessOutOfMemory(nullptr, oom_msg.PrintToArray().data());
base::EmbeddedVector<char, kMaxMessageLength + 1> message;
SNPrintF(message, format.begin(), total_reserved, reserve_size);
V8::FatalProcessOutOfMemory(nullptr, message.begin());
UNREACHABLE(); UNREACHABLE();
} }
...@@ -2196,13 +2190,10 @@ base::AddressRegion WasmCodeManager::AllocateAssemblerBufferSpace(int size) { ...@@ -2196,13 +2190,10 @@ base::AddressRegion WasmCodeManager::AllocateAssemblerBufferSpace(int size) {
void* mapped = AllocatePages(page_allocator, nullptr, size, page_size, void* mapped = AllocatePages(page_allocator, nullptr, size, page_size,
PageAllocator::kNoAccess); PageAllocator::kNoAccess);
if (V8_UNLIKELY(!mapped)) { if (V8_UNLIKELY(!mapped)) {
constexpr auto format = base::StaticCharVector( auto oom_msg = base::FormattedString{}
"Cannot allocate %d more bytes for assembler buffers"); << "Cannot allocate " << size
constexpr int kMaxMessageLength = << " more bytes for assembler buffers";
format.size() - 3 + std::numeric_limits<size_t>::digits10; V8::FatalProcessOutOfMemory(nullptr, oom_msg.PrintToArray().data());
base::EmbeddedVector<char, kMaxMessageLength + 1> message;
SNPrintF(message, format.begin(), size);
V8::FatalProcessOutOfMemory(nullptr, message.begin());
UNREACHABLE(); UNREACHABLE();
} }
auto region = auto region =
...@@ -2263,13 +2254,10 @@ std::shared_ptr<NativeModule> WasmCodeManager::NewNativeModule( ...@@ -2263,13 +2254,10 @@ std::shared_ptr<NativeModule> WasmCodeManager::NewNativeModule(
code_space = TryAllocate(code_vmem_size); code_space = TryAllocate(code_vmem_size);
if (code_space.IsReserved()) break; if (code_space.IsReserved()) break;
if (retries == kAllocationRetries) { if (retries == kAllocationRetries) {
constexpr auto format = base::StaticCharVector( auto oom_msg = base::FormattedString{}
"NewNativeModule cannot allocate code space of %zu bytes"); << "NewNativeModule cannot allocate code space of "
constexpr int kMaxMessageLength = << code_vmem_size << " bytes";
format.size() - 3 + std::numeric_limits<size_t>::digits10; V8::FatalProcessOutOfMemory(isolate, oom_msg.PrintToArray().data());
base::EmbeddedVector<char, kMaxMessageLength + 1> message;
SNPrintF(message, format.begin(), code_vmem_size);
V8::FatalProcessOutOfMemory(isolate, message.begin());
UNREACHABLE(); UNREACHABLE();
} }
// Run one GC, then try the allocation again. // Run one GC, then try the allocation again.
......
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