v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
virtual-address-space-page-allocator.h
Go to the documentation of this file.
1// Copyright 2021 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_BASE_VIRTUAL_ADDRESS_SPACE_PAGE_ALLOCATOR_H_
6#define V8_BASE_VIRTUAL_ADDRESS_SPACE_PAGE_ALLOCATOR_H_
7
8#include <unordered_map>
9
10#include "include/v8-platform.h"
14
15namespace v8 {
16namespace base {
17
18// This class bridges a VirtualAddressSpace, the future memory management API,
19// to a PageAllocator, the current API.
21 : public v8::PageAllocator {
22 public:
23 using Address = uintptr_t;
24
26
28 delete;
30 const VirtualAddressSpacePageAllocator&) = delete;
32
33 size_t AllocatePageSize() override { return vas_->allocation_granularity(); }
34
35 size_t CommitPageSize() override { return vas_->page_size(); }
36
37 void SetRandomMmapSeed(int64_t seed) override { vas_->SetRandomSeed(seed); }
38
39 void* GetRandomMmapAddr() override {
40 return reinterpret_cast<void*>(vas_->RandomPageAddress());
41 }
42
43 void* AllocatePages(void* hint, size_t size, size_t alignment,
44 Permission access) override;
45
46 bool FreePages(void* address, size_t size) override;
47
48 bool ReleasePages(void* address, size_t size, size_t new_size) override;
49
50 bool SetPermissions(void* address, size_t size, Permission access) override;
51
52 bool RecommitPages(void* address, size_t size,
53 PageAllocator::Permission access) override;
54
55 bool DiscardSystemPages(void* address, size_t size) override;
56
57 bool DecommitPages(void* address, size_t size) override;
58
59 bool SealPages(void* address, size_t size) override;
60
61 private:
62 // Client of this class must keep the VirtualAddressSpace alive during the
63 // lifetime of this instance.
65
66 // As the VirtualAddressSpace class doesn't support ReleasePages, this map is
67 // required to keep track of the original size of resized page allocations.
68 // See the ReleasePages implementation.
69 std::unordered_map<Address, size_t> resized_allocations_;
70
71 // Mutex guarding the above map.
73};
74
75} // namespace base
76} // namespace v8
77
78#endif // V8_BASE_VIRTUAL_ADDRESS_SPACE_PAGE_ALLOCATOR_H_
#define V8_BASE_EXPORT
Definition base-export.h:26
VirtualAddressSpacePageAllocator & operator=(const VirtualAddressSpacePageAllocator &)=delete
~VirtualAddressSpacePageAllocator() override=default
VirtualAddressSpacePageAllocator(const VirtualAddressSpacePageAllocator &)=delete