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 {
* error.
* Embedder overrides of this function must NOT call back into V8.
*/
virtual void OnCriticalMemoryPressure() {
// TODO(bbudge) Remove this when embedders override the following method.
// See crbug.com/634547.
}
virtual void OnCriticalMemoryPressure() {}
/**
* Enables the embedder to respond in cases where V8 can't allocate large
......@@ -955,6 +952,7 @@ class Platform {
*
* 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; }
/**
......
......@@ -36,10 +36,6 @@ class PredictablePlatform final : public Platform {
platform_->OnCriticalMemoryPressure();
}
bool OnCriticalMemoryPressure(size_t length) override {
return platform_->OnCriticalMemoryPressure(length);
}
std::shared_ptr<TaskRunner> GetForegroundTaskRunner(
v8::Isolate* isolate) override {
return platform_->GetForegroundTaskRunner(isolate);
......@@ -151,10 +147,6 @@ class DelayedTasksPlatform final : public Platform {
platform_->OnCriticalMemoryPressure();
}
bool OnCriticalMemoryPressure(size_t length) override {
return platform_->OnCriticalMemoryPressure(length);
}
std::shared_ptr<TaskRunner> GetForegroundTaskRunner(
v8::Isolate* isolate) override {
std::shared_ptr<TaskRunner> runner =
......
......@@ -110,7 +110,7 @@ v8::PageAllocator* SetPlatformPageAllocatorForTesting(
void* Malloced::operator new(size_t size) {
void* result = AllocWithRetry(size);
if (result == nullptr) {
if (V8_UNLIKELY(result == nullptr)) {
V8::FatalProcessOutOfMemory(nullptr, "Malloced operator new");
}
return result;
......@@ -139,8 +139,8 @@ void* AllocWithRetry(size_t size, MallocFn malloc_fn) {
void* result = nullptr;
for (int i = 0; i < kAllocationTries; ++i) {
result = malloc_fn(size);
if (result != nullptr) break;
if (!OnCriticalMemoryPressure(size)) break;
if (V8_LIKELY(result != nullptr)) break;
OnCriticalMemoryPressure();
}
return result;
}
......@@ -151,13 +151,10 @@ void* AlignedAlloc(size_t size, size_t alignment) {
void* result = nullptr;
for (int i = 0; i < kAllocationTries; ++i) {
result = AlignedAllocInternal(size, alignment);
if (result != nullptr) break;
if (!OnCriticalMemoryPressure(size + alignment)) break;
if (V8_LIKELY(result != nullptr)) return result;
OnCriticalMemoryPressure();
}
if (result == nullptr) {
V8::FatalProcessOutOfMemory(nullptr, "AlignedAlloc");
}
return result;
}
void AlignedFree(void* ptr) {
......@@ -194,9 +191,8 @@ void* AllocatePages(v8::PageAllocator* page_allocator, void* hint, size_t size,
void* result = nullptr;
for (int i = 0; i < kAllocationTries; ++i) {
result = page_allocator->AllocatePages(hint, size, alignment, access);
if (result != nullptr) break;
size_t request_size = size + alignment - page_allocator->AllocatePageSize();
if (!OnCriticalMemoryPressure(request_size)) break;
if (V8_LIKELY(result != nullptr)) break;
OnCriticalMemoryPressure();
}
return result;
}
......@@ -222,13 +218,8 @@ bool SetPermissions(v8::PageAllocator* page_allocator, void* address,
return page_allocator->SetPermissions(address, size, access);
}
bool OnCriticalMemoryPressure(size_t length) {
// TODO(bbudge) Rework retry logic once embedders implement the more
// informative overload.
if (!V8::GetCurrentPlatform()->OnCriticalMemoryPressure(length)) {
void OnCriticalMemoryPressure() {
V8::GetCurrentPlatform()->OnCriticalMemoryPressure();
}
return true;
}
VirtualMemory::VirtualMemory() = default;
......
......@@ -31,11 +31,15 @@ class V8_EXPORT_PRIVATE Malloced {
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>
T* NewArray(size_t size) {
T* result = new (std::nothrow) T[size];
if (result == nullptr) {
V8::GetCurrentPlatform()->OnCriticalMemoryPressure();
if (V8_UNLIKELY(result == nullptr)) {
OnCriticalMemoryPressure();
result = new (std::nothrow) T[size];
if (result == nullptr) V8::FatalProcessOutOfMemory(nullptr, "NewArray");
}
......@@ -172,11 +176,6 @@ inline bool SetPermissions(v8::PageAllocator* page_allocator, Address address,
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
// allocating executable pages.
enum class JitPermission { kNoJit, kMapAsJittable };
......
......@@ -471,10 +471,6 @@ void TestPlatform::OnCriticalMemoryPressure() {
CcTest::default_platform()->OnCriticalMemoryPressure();
}
bool TestPlatform::OnCriticalMemoryPressure(size_t length) {
return CcTest::default_platform()->OnCriticalMemoryPressure(length);
}
int TestPlatform::NumberOfWorkerThreads() {
return CcTest::default_platform()->NumberOfWorkerThreads();
}
......
......@@ -719,7 +719,6 @@ class TestPlatform : public v8::Platform {
// v8::Platform implementation.
v8::PageAllocator* GetPageAllocator() override;
void OnCriticalMemoryPressure() override;
bool OnCriticalMemoryPressure(size_t length) override;
int NumberOfWorkerThreads() override;
std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(
v8::Isolate* isolate) override;
......
......@@ -36,11 +36,6 @@ class AllocationPlatform : public TestPlatform {
void OnCriticalMemoryPressure() override { oom_callback_called = true; }
bool OnCriticalMemoryPressure(size_t length) override {
oom_callback_called = true;
return true;
}
static AllocationPlatform* current_platform;
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