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

[wasm] Use new OOM API for passing details

In particular use the same "location" in any call site to make grouping
OOMs easier. Move the detail information into the new OOMDetails struct.

Since we cannot construct OOMDetails via "{.detail = ...}" yet (C++20),
we add another variants of FatalProcessOutOfMemory which receives the
detail string and internally stores it in an OOMDetails struct.

R=jkummerow@chromium.org
CC=mlippautz@chromium.org

Bug: chromium:1323177
Change-Id: Ie10cde8dd060867515fab4c61c15030f9c3ccff9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3652298Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80612}
parent 7eacc4d5
...@@ -316,6 +316,13 @@ void i::V8::FatalProcessOutOfMemory(i::Isolate* i_isolate, const char* location, ...@@ -316,6 +316,13 @@ void i::V8::FatalProcessOutOfMemory(i::Isolate* i_isolate, const char* location,
FATAL("API fatal error handler returned after process out of memory"); FATAL("API fatal error handler returned after process out of memory");
} }
void i::V8::FatalProcessOutOfMemory(i::Isolate* i_isolate, const char* location,
const char* detail) {
OOMDetails details;
details.detail = detail;
FatalProcessOutOfMemory(i_isolate, location, details);
}
void Utils::ReportApiFailure(const char* location, const char* message) { void Utils::ReportApiFailure(const char* location, const char* message) {
i::Isolate* i_isolate = i::Isolate::TryGetCurrent(); i::Isolate* i_isolate = i::Isolate::TryGetCurrent();
FatalErrorCallback callback = nullptr; FatalErrorCallback callback = nullptr;
......
...@@ -36,6 +36,12 @@ class V8 : public AllStatic { ...@@ -36,6 +36,12 @@ class V8 : public AllStatic {
V8_EXPORT_PRIVATE static const OOMDetails kNoOOMDetails; V8_EXPORT_PRIVATE static const OOMDetails kNoOOMDetails;
V8_EXPORT_PRIVATE static const OOMDetails kHeapOOM; V8_EXPORT_PRIVATE static const OOMDetails kHeapOOM;
// Another variant of FatalProcessOutOfMemory, which constructs the OOMDetails
// struct internally from another "detail" c-string.
// This can be removed once we support designated initializers (C++20).
[[noreturn]] V8_EXPORT_PRIVATE static void FatalProcessOutOfMemory(
Isolate* isolate, const char* location, const char* detail);
#ifdef V8_ENABLE_SANDBOX #ifdef V8_ENABLE_SANDBOX
static bool InitializeSandbox(); static bool InitializeSandbox();
#endif #endif
......
...@@ -621,11 +621,12 @@ size_t ReservationSize(size_t code_size_estimate, int num_declared_functions, ...@@ -621,11 +621,12 @@ 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)) {
auto oom_msg = base::FormattedString{} auto oom_detail = base::FormattedString{}
<< "wasm code reservation: required minimum (" << "required reservation minimum (" << minimum_size
<< minimum_size << ") is bigger than supported maximum (" << ") is bigger than supported maximum ("
<< WasmCodeAllocator::kMaxCodeSpaceSize << ")"; << WasmCodeAllocator::kMaxCodeSpaceSize << ")";
V8::FatalProcessOutOfMemory(nullptr, oom_msg.PrintToArray().data()); V8::FatalProcessOutOfMemory(nullptr, "Wasm code space reservation",
oom_detail.PrintToArray().data());
UNREACHABLE(); UNREACHABLE();
} }
...@@ -727,10 +728,11 @@ base::Vector<byte> WasmCodeAllocator::AllocateForCodeInRegion( ...@@ -727,10 +728,11 @@ 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()) {
auto oom_msg = base::FormattedString{} auto oom_detail = base::FormattedString{}
<< "Cannot allocate more code space (" << reserve_size << "cannot allocate more code space (" << reserve_size
<< " bytes, currently " << total_reserved << ")"; << " bytes, currently " << total_reserved << ")";
V8::FatalProcessOutOfMemory(nullptr, oom_msg.PrintToArray().data()); V8::FatalProcessOutOfMemory(nullptr, "AllocateForCode",
oom_detail.PrintToArray().data());
UNREACHABLE(); UNREACHABLE();
} }
...@@ -1912,9 +1914,12 @@ void WasmCodeManager::Commit(base::AddressRegion region) { ...@@ -1912,9 +1914,12 @@ void WasmCodeManager::Commit(base::AddressRegion region) {
while (true) { while (true) {
DCHECK_GE(max_committed_code_space_, old_value); DCHECK_GE(max_committed_code_space_, old_value);
if (region.size() > max_committed_code_space_ - old_value) { if (region.size() > max_committed_code_space_ - old_value) {
auto oom_detail = base::FormattedString{}
<< "trying to commit " << region.size()
<< ", already committed " << old_value;
V8::FatalProcessOutOfMemory( V8::FatalProcessOutOfMemory(
nullptr, nullptr, "WasmCodeManager::Commit: Exceeding maximum wasm code space",
"WasmCodeManager::Commit: Exceeding maximum wasm code space"); oom_detail.PrintToArray().data());
UNREACHABLE(); UNREACHABLE();
} }
if (total_committed_code_space_.compare_exchange_weak( if (total_committed_code_space_.compare_exchange_weak(
...@@ -1953,9 +1958,12 @@ void WasmCodeManager::Commit(base::AddressRegion region) { ...@@ -1953,9 +1958,12 @@ void WasmCodeManager::Commit(base::AddressRegion region) {
} }
if (V8_UNLIKELY(!success)) { if (V8_UNLIKELY(!success)) {
auto oom_detail = base::FormattedString{} << "region size: "
<< region.size();
V8::FatalProcessOutOfMemory( V8::FatalProcessOutOfMemory(
nullptr, nullptr,
"WasmCodeManager::Commit: Cannot make pre-reserved region writable"); "WasmCodeManager::Commit: Cannot make pre-reserved region writable",
oom_detail.PrintToArray().data());
UNREACHABLE(); UNREACHABLE();
} }
} }
...@@ -2190,10 +2198,12 @@ base::AddressRegion WasmCodeManager::AllocateAssemblerBufferSpace(int size) { ...@@ -2190,10 +2198,12 @@ 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)) {
auto oom_msg = base::FormattedString{} auto oom_detail = base::FormattedString{}
<< "Cannot allocate " << size << "cannot allocate " << size
<< " more bytes for assembler buffers"; << " more bytes for assembler buffers";
V8::FatalProcessOutOfMemory(nullptr, oom_msg.PrintToArray().data()); V8::FatalProcessOutOfMemory(
nullptr, "WasmCodeManager::AllocateAssemblerBufferSpace",
oom_detail.PrintToArray().data());
UNREACHABLE(); UNREACHABLE();
} }
auto region = auto region =
...@@ -2254,10 +2264,11 @@ std::shared_ptr<NativeModule> WasmCodeManager::NewNativeModule( ...@@ -2254,10 +2264,11 @@ 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) {
auto oom_msg = base::FormattedString{} auto oom_detail = base::FormattedString{}
<< "NewNativeModule cannot allocate code space of " << "NewNativeModule cannot allocate code space of "
<< code_vmem_size << " bytes"; << code_vmem_size << " bytes";
V8::FatalProcessOutOfMemory(isolate, oom_msg.PrintToArray().data()); V8::FatalProcessOutOfMemory(isolate, "WasmCodeManager::NewNativeModule",
oom_detail.PrintToArray().data());
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