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

[API] Prepare deprecation of second OnCriticalMemoryPressure

The new method is not implemented in Chrome or Node, and the issue has
no activity since 2018, so let's rip out the incomplete new API.

Drive-by: Sprinke a few V8_LIKELY and V8_UNLIKELY.

R=mlippautz@chromium.org

Bug: chromium:634547
Change-Id: I0dabad520d459277d7196fa69c1bbceaf4d53596
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3780528Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81923}
parent e2f66413
...@@ -941,10 +941,7 @@ class Platform { ...@@ -941,10 +941,7 @@ class Platform {
* error. * error.
* Embedder overrides of this function must NOT call back into V8. * Embedder overrides of this function must NOT call back into V8.
*/ */
virtual void OnCriticalMemoryPressure() { virtual void OnCriticalMemoryPressure() {}
// TODO(bbudge) Remove this when embedders override the following method.
// See crbug.com/634547.
}
/** /**
* Enables the embedder to respond in cases where V8 can't allocate large * Enables the embedder to respond in cases where V8 can't allocate large
...@@ -955,6 +952,7 @@ class Platform { ...@@ -955,6 +952,7 @@ class Platform {
* *
* Embedder overrides of this function must NOT call back into V8. * Embedder overrides of this function must NOT call back into V8.
*/ */
V8_DEPRECATE_SOON("Use the method without informative parameter")
virtual bool OnCriticalMemoryPressure(size_t length) { return false; } virtual bool OnCriticalMemoryPressure(size_t length) { return false; }
/** /**
......
...@@ -36,10 +36,6 @@ class PredictablePlatform final : public Platform { ...@@ -36,10 +36,6 @@ class PredictablePlatform final : public Platform {
platform_->OnCriticalMemoryPressure(); platform_->OnCriticalMemoryPressure();
} }
bool OnCriticalMemoryPressure(size_t length) override {
return platform_->OnCriticalMemoryPressure(length);
}
std::shared_ptr<TaskRunner> GetForegroundTaskRunner( std::shared_ptr<TaskRunner> GetForegroundTaskRunner(
v8::Isolate* isolate) override { v8::Isolate* isolate) override {
return platform_->GetForegroundTaskRunner(isolate); return platform_->GetForegroundTaskRunner(isolate);
...@@ -151,10 +147,6 @@ class DelayedTasksPlatform final : public Platform { ...@@ -151,10 +147,6 @@ class DelayedTasksPlatform final : public Platform {
platform_->OnCriticalMemoryPressure(); platform_->OnCriticalMemoryPressure();
} }
bool OnCriticalMemoryPressure(size_t length) override {
return platform_->OnCriticalMemoryPressure(length);
}
std::shared_ptr<TaskRunner> GetForegroundTaskRunner( std::shared_ptr<TaskRunner> GetForegroundTaskRunner(
v8::Isolate* isolate) override { v8::Isolate* isolate) override {
std::shared_ptr<TaskRunner> runner = std::shared_ptr<TaskRunner> runner =
......
...@@ -110,7 +110,7 @@ v8::PageAllocator* SetPlatformPageAllocatorForTesting( ...@@ -110,7 +110,7 @@ v8::PageAllocator* SetPlatformPageAllocatorForTesting(
void* Malloced::operator new(size_t size) { void* Malloced::operator new(size_t size) {
void* result = AllocWithRetry(size); void* result = AllocWithRetry(size);
if (result == nullptr) { if (V8_UNLIKELY(result == nullptr)) {
V8::FatalProcessOutOfMemory(nullptr, "Malloced operator new"); V8::FatalProcessOutOfMemory(nullptr, "Malloced operator new");
} }
return result; return result;
...@@ -139,8 +139,8 @@ void* AllocWithRetry(size_t size, MallocFn malloc_fn) { ...@@ -139,8 +139,8 @@ void* AllocWithRetry(size_t size, MallocFn malloc_fn) {
void* result = nullptr; void* result = nullptr;
for (int i = 0; i < kAllocationTries; ++i) { for (int i = 0; i < kAllocationTries; ++i) {
result = malloc_fn(size); result = malloc_fn(size);
if (result != nullptr) break; if (V8_LIKELY(result != nullptr)) break;
if (!OnCriticalMemoryPressure(size)) break; OnCriticalMemoryPressure();
} }
return result; return result;
} }
...@@ -151,13 +151,10 @@ void* AlignedAlloc(size_t size, size_t alignment) { ...@@ -151,13 +151,10 @@ void* AlignedAlloc(size_t size, size_t alignment) {
void* result = nullptr; void* result = nullptr;
for (int i = 0; i < kAllocationTries; ++i) { for (int i = 0; i < kAllocationTries; ++i) {
result = AlignedAllocInternal(size, alignment); result = AlignedAllocInternal(size, alignment);
if (result != nullptr) break; if (V8_LIKELY(result != nullptr)) return result;
if (!OnCriticalMemoryPressure(size + alignment)) break; OnCriticalMemoryPressure();
} }
if (result == nullptr) { V8::FatalProcessOutOfMemory(nullptr, "AlignedAlloc");
V8::FatalProcessOutOfMemory(nullptr, "AlignedAlloc");
}
return result;
} }
void AlignedFree(void* ptr) { void AlignedFree(void* ptr) {
...@@ -194,9 +191,8 @@ void* AllocatePages(v8::PageAllocator* page_allocator, void* hint, size_t size, ...@@ -194,9 +191,8 @@ void* AllocatePages(v8::PageAllocator* page_allocator, void* hint, size_t size,
void* result = nullptr; void* result = nullptr;
for (int i = 0; i < kAllocationTries; ++i) { for (int i = 0; i < kAllocationTries; ++i) {
result = page_allocator->AllocatePages(hint, size, alignment, access); result = page_allocator->AllocatePages(hint, size, alignment, access);
if (result != nullptr) break; if (V8_LIKELY(result != nullptr)) break;
size_t request_size = size + alignment - page_allocator->AllocatePageSize(); OnCriticalMemoryPressure();
if (!OnCriticalMemoryPressure(request_size)) break;
} }
return result; return result;
} }
...@@ -222,13 +218,8 @@ bool SetPermissions(v8::PageAllocator* page_allocator, void* address, ...@@ -222,13 +218,8 @@ bool SetPermissions(v8::PageAllocator* page_allocator, void* address,
return page_allocator->SetPermissions(address, size, access); return page_allocator->SetPermissions(address, size, access);
} }
bool OnCriticalMemoryPressure(size_t length) { void OnCriticalMemoryPressure() {
// TODO(bbudge) Rework retry logic once embedders implement the more V8::GetCurrentPlatform()->OnCriticalMemoryPressure();
// informative overload.
if (!V8::GetCurrentPlatform()->OnCriticalMemoryPressure(length)) {
V8::GetCurrentPlatform()->OnCriticalMemoryPressure();
}
return true;
} }
VirtualMemory::VirtualMemory() = default; VirtualMemory::VirtualMemory() = default;
......
...@@ -31,11 +31,15 @@ class V8_EXPORT_PRIVATE Malloced { ...@@ -31,11 +31,15 @@ class V8_EXPORT_PRIVATE Malloced {
static void operator delete(void* p); static void operator delete(void* p);
}; };
// Function that may release reserved memory regions to allow failed allocations
// to succeed.
V8_EXPORT_PRIVATE void OnCriticalMemoryPressure();
template <typename T> template <typename T>
T* NewArray(size_t size) { T* NewArray(size_t size) {
T* result = new (std::nothrow) T[size]; T* result = new (std::nothrow) T[size];
if (result == nullptr) { if (V8_UNLIKELY(result == nullptr)) {
V8::GetCurrentPlatform()->OnCriticalMemoryPressure(); OnCriticalMemoryPressure();
result = new (std::nothrow) T[size]; result = new (std::nothrow) T[size];
if (result == nullptr) V8::FatalProcessOutOfMemory(nullptr, "NewArray"); if (result == nullptr) V8::FatalProcessOutOfMemory(nullptr, "NewArray");
} }
...@@ -172,11 +176,6 @@ inline bool SetPermissions(v8::PageAllocator* page_allocator, Address address, ...@@ -172,11 +176,6 @@ inline bool SetPermissions(v8::PageAllocator* page_allocator, Address address,
access); access);
} }
// Function that may release reserved memory regions to allow failed allocations
// to succeed. |length| is the amount of memory needed. Returns |true| if memory
// could be released, false otherwise.
V8_EXPORT_PRIVATE bool OnCriticalMemoryPressure(size_t length);
// Defines whether the address space reservation is going to be used for // Defines whether the address space reservation is going to be used for
// allocating executable pages. // allocating executable pages.
enum class JitPermission { kNoJit, kMapAsJittable }; enum class JitPermission { kNoJit, kMapAsJittable };
......
...@@ -471,10 +471,6 @@ void TestPlatform::OnCriticalMemoryPressure() { ...@@ -471,10 +471,6 @@ void TestPlatform::OnCriticalMemoryPressure() {
CcTest::default_platform()->OnCriticalMemoryPressure(); CcTest::default_platform()->OnCriticalMemoryPressure();
} }
bool TestPlatform::OnCriticalMemoryPressure(size_t length) {
return CcTest::default_platform()->OnCriticalMemoryPressure(length);
}
int TestPlatform::NumberOfWorkerThreads() { int TestPlatform::NumberOfWorkerThreads() {
return CcTest::default_platform()->NumberOfWorkerThreads(); return CcTest::default_platform()->NumberOfWorkerThreads();
} }
......
...@@ -719,7 +719,6 @@ class TestPlatform : public v8::Platform { ...@@ -719,7 +719,6 @@ class TestPlatform : public v8::Platform {
// v8::Platform implementation. // v8::Platform implementation.
v8::PageAllocator* GetPageAllocator() override; v8::PageAllocator* GetPageAllocator() override;
void OnCriticalMemoryPressure() override; void OnCriticalMemoryPressure() override;
bool OnCriticalMemoryPressure(size_t length) override;
int NumberOfWorkerThreads() override; int NumberOfWorkerThreads() override;
std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner( std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(
v8::Isolate* isolate) override; v8::Isolate* isolate) override;
......
...@@ -36,11 +36,6 @@ class AllocationPlatform : public TestPlatform { ...@@ -36,11 +36,6 @@ class AllocationPlatform : public TestPlatform {
void OnCriticalMemoryPressure() override { oom_callback_called = true; } void OnCriticalMemoryPressure() override { oom_callback_called = true; }
bool OnCriticalMemoryPressure(size_t length) override {
oom_callback_called = true;
return true;
}
static AllocationPlatform* current_platform; static AllocationPlatform* current_platform;
bool oom_callback_called = false; bool oom_callback_called = false;
}; };
......
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