summaryrefslogtreecommitdiff
path: root/deps/v8/src/allocation.h
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/allocation.h')
-rw-r--r--deps/v8/src/allocation.h94
1 files changed, 92 insertions, 2 deletions
diff --git a/deps/v8/src/allocation.h b/deps/v8/src/allocation.h
index e0e147bb7c..a78db1a881 100644
--- a/deps/v8/src/allocation.h
+++ b/deps/v8/src/allocation.h
@@ -43,6 +43,14 @@ T* NewArray(size_t size) {
return result;
}
+template <typename T,
+ typename = typename std::enable_if<IS_TRIVIALLY_COPYABLE(T)>::type>
+T* NewArray(size_t size, T default_val) {
+ T* result = reinterpret_cast<T*>(NewArray<uint8_t>(sizeof(T) * size));
+ for (size_t i = 0; i < size; ++i) result[i] = default_val;
+ return result;
+}
+
template <typename T>
void DeleteArray(T* array) {
delete[] array;
@@ -68,9 +76,91 @@ class FreeStoreAllocationPolicy {
void* AlignedAlloc(size_t size, size_t alignment);
void AlignedFree(void *ptr);
-bool AllocVirtualMemory(size_t size, void* hint, base::VirtualMemory* result);
+// Represents and controls an area of reserved memory.
+class V8_EXPORT_PRIVATE VirtualMemory {
+ public:
+ // Empty VirtualMemory object, controlling no reserved memory.
+ VirtualMemory();
+
+ // Reserves virtual memory with size.
+ explicit VirtualMemory(size_t size, void* hint);
+
+ // Reserves virtual memory containing an area of the given size that
+ // is aligned per alignment. This may not be at the position returned
+ // by address().
+ VirtualMemory(size_t size, size_t alignment, void* hint);
+
+ // Construct a virtual memory by assigning it some already mapped address
+ // and size.
+ VirtualMemory(void* address, size_t size) : address_(address), size_(size) {}
+
+ // Releases the reserved memory, if any, controlled by this VirtualMemory
+ // object.
+ ~VirtualMemory();
+
+ // Returns whether the memory has been reserved.
+ bool IsReserved() const { return address_ != nullptr; }
+
+ // Initialize or resets an embedded VirtualMemory object.
+ void Reset();
+
+ // Returns the start address of the reserved memory.
+ // If the memory was reserved with an alignment, this address is not
+ // necessarily aligned. The user might need to round it up to a multiple of
+ // the alignment to get the start of the aligned block.
+ void* address() const {
+ DCHECK(IsReserved());
+ return address_;
+ }
+
+ void* end() const {
+ DCHECK(IsReserved());
+ return reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(address_) +
+ size_);
+ }
+
+ // Returns the size of the reserved memory. The returned value is only
+ // meaningful when IsReserved() returns true.
+ // If the memory was reserved with an alignment, this size may be larger
+ // than the requested size.
+ size_t size() const { return size_; }
+
+ // Commits real memory. Returns whether the operation succeeded.
+ bool Commit(void* address, size_t size, bool is_executable);
+
+ // Uncommit real memory. Returns whether the operation succeeded.
+ bool Uncommit(void* address, size_t size);
+
+ // Creates a single guard page at the given address.
+ bool Guard(void* address);
+
+ // Releases the memory after |free_start|. Returns the bytes released.
+ size_t ReleasePartial(void* free_start);
+
+ void Release();
+
+ // Assign control of the reserved region to a different VirtualMemory object.
+ // The old object is no longer functional (IsReserved() returns false).
+ void TakeControl(VirtualMemory* from);
+
+ bool InVM(void* address, size_t size) {
+ return (reinterpret_cast<uintptr_t>(address_) <=
+ reinterpret_cast<uintptr_t>(address)) &&
+ ((reinterpret_cast<uintptr_t>(address_) + size_) >=
+ (reinterpret_cast<uintptr_t>(address) + size));
+ }
+
+ private:
+ void* address_; // Start address of the virtual memory.
+ size_t size_; // Size of the virtual memory.
+};
+
+bool AllocVirtualMemory(size_t size, void* hint, VirtualMemory* result);
bool AlignedAllocVirtualMemory(size_t size, size_t alignment, void* hint,
- base::VirtualMemory* result);
+ VirtualMemory* result);
+
+// Generate a random address to be used for hinting mmap().
+V8_EXPORT_PRIVATE void* GetRandomMmapAddr();
} // namespace internal
} // namespace v8