Commit 2d277529 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[utils] Fix Malloced implementation

According to the specification, class-specific {operator new} and
{operator delete} should be static methods. Interestingly, if the
{static} keyword is missing, the methods are implicitly static anyway.
This is confusing, so this CL adds the {static} keywords explicitly.
It also removes the redundant {Malloced::New} and {Malloced::Delete}
methods.

R=mlippautz@chromium.org

Bug: v8:9396
Change-Id: I1db7c87b816567cc1a9153d0b18e3dd4ae81dd6f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1700080Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62703}
parent 87896ff1
......@@ -84,7 +84,7 @@ v8::PageAllocator* SetPlatformPageAllocatorForTesting(
return old_page_allocator;
}
void* Malloced::New(size_t size) {
void* Malloced::operator new(size_t size) {
void* result = AllocWithRetry(size);
if (result == nullptr) {
V8::FatalProcessOutOfMemory(nullptr, "Malloced operator new");
......@@ -92,7 +92,7 @@ void* Malloced::New(size_t size) {
return result;
}
void Malloced::Delete(void* p) { free(p); }
void Malloced::operator delete(void* p) { free(p); }
char* StrDup(const char* str) {
size_t length = strlen(str);
......
......@@ -29,11 +29,8 @@ class Isolate;
// Superclass for classes managed with new & delete.
class V8_EXPORT_PRIVATE Malloced {
public:
void* operator new(size_t size) { return New(size); }
void operator delete(void* p) { Delete(p); }
static void* New(size_t size);
static void Delete(void* p);
static void* operator new(size_t size);
static void operator delete(void* p);
};
template <typename T>
......@@ -70,8 +67,8 @@ char* StrNDup(const char* str, int n);
// and free. Used as the default policy for lists.
class FreeStoreAllocationPolicy {
public:
V8_INLINE void* New(size_t size) { return Malloced::New(size); }
V8_INLINE static void Delete(void* p) { Malloced::Delete(p); }
V8_INLINE void* New(size_t size) { return Malloced::operator new(size); }
V8_INLINE static void Delete(void* p) { Malloced::operator delete(p); }
};
// Performs a malloc, with retry logic on failure. Returns nullptr on failure.
......
......@@ -139,7 +139,7 @@ TEST(MallocedOperatorNewOOM) {
CcTest::isolate()->SetFatalErrorHandler(OnMallocedOperatorNewOOM);
// On failure, this won't return, since a Malloced::New failure is fatal.
// In that case, behavior is checked in OnMallocedOperatorNewOOM before exit.
void* result = v8::internal::Malloced::New(GetHugeMemoryAmount());
void* result = v8::internal::Malloced::operator new(GetHugeMemoryAmount());
// On a few systems, allocation somehow succeeds.
CHECK_EQ(result == nullptr, platform.oom_callback_called);
}
......
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