5 #ifndef V8_ALLOCATION_H_ 6 #define V8_ALLOCATION_H_ 8 #include "include/v8-platform.h" 9 #include "src/base/address-region.h" 10 #include "src/base/compiler-specific.h" 11 #include "src/base/platform/platform.h" 12 #include "src/globals.h" 26 [[noreturn]] V8_EXPORT_PRIVATE
void FatalProcessOutOfMemory(
27 Isolate* isolate,
const char* message);
32 void*
operator new(
size_t size) {
return New(size); }
33 void operator delete(
void* p) { Delete(p); }
35 static void* New(
size_t size);
36 static void Delete(
void* p);
40 T* NewArray(
size_t size) {
41 T* result =
new (std::nothrow)
T[size];
42 if (result ==
nullptr) {
43 V8::GetCurrentPlatform()->OnCriticalMemoryPressure();
44 result =
new (std::nothrow)
T[size];
45 if (result ==
nullptr) FatalProcessOutOfMemory(
nullptr,
"NewArray");
50 template <
typename T,
typename =
typename std::enable_if<
51 base::is_trivially_copyable<T>::value>::type>
52 T* NewArray(
size_t size, T default_val) {
53 T* result =
reinterpret_cast<T*
>(NewArray<uint8_t>(
sizeof(T) * size));
54 for (
size_t i = 0;
i < size; ++
i) result[
i] = default_val;
59 void DeleteArray(T* array) {
67 V8_EXPORT_PRIVATE
char* StrDup(
const char* str);
68 char* StrNDup(
const char* str,
int n);
75 V8_INLINE
void* New(
size_t size) {
return Malloced::New(size); }
76 V8_INLINE
static void Delete(
void* p) { Malloced::Delete(p); }
81 void* AllocWithRetry(
size_t size);
83 void* AlignedAlloc(
size_t size,
size_t alignment);
84 void AlignedFree(
void *ptr);
98 V8_EXPORT_PRIVATE
size_t AllocatePageSize();
101 V8_EXPORT_PRIVATE
size_t CommitPageSize();
105 V8_EXPORT_PRIVATE
void SetRandomMmapSeed(
int64_t seed);
108 V8_EXPORT_PRIVATE
void* GetRandomMmapAddr();
116 void* address,
size_t size,
124 void* address,
const size_t size);
133 void* address,
size_t size,
142 void* address,
size_t size,
146 return SetPermissions(page_allocator, reinterpret_cast<void*>(address), size,
155 void* address,
size_t* allocated);
160 V8_EXPORT_PRIVATE
bool OnCriticalMemoryPressure(
size_t length);
173 size_t alignment = 1);
178 : page_allocator_(page_allocator), region_(address, size) {
179 DCHECK_NOT_NULL(page_allocator);
198 bool IsReserved()
const {
return region_.begin() != kNullAddress; }
212 DCHECK(IsReserved());
213 return region_.begin();
217 DCHECK(IsReserved());
218 return region_.end();
225 size_t size()
const {
return region_.size(); }
229 bool SetPermissions(
Address address,
size_t size,
233 size_t Release(
Address free_start);
242 bool InVM(
Address address,
size_t size) {
243 return region_.contains(address, size);
257 #endif // V8_ALLOCATION_H_
virtual size_t AllocatePageSize()=0
virtual size_t CommitPageSize()=0