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.cc
Go to the documentation of this file.
1// Copyright 2018 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
6
7namespace v8 {
8namespace base {
9
13
15 void* hint, size_t size, size_t alignment,
17 return reinterpret_cast<void*>(
18 vas_->AllocatePages(reinterpret_cast<Address>(hint), size, alignment,
19 static_cast<PagePermissions>(access)));
20}
21
22bool VirtualAddressSpacePageAllocator::FreePages(void* ptr, size_t size) {
23 MutexGuard guard(&mutex_);
24 Address address = reinterpret_cast<Address>(ptr);
25 // Was this allocation resized previously? If so, use the original size.
26 auto result = resized_allocations_.find(address);
27 if (result != resized_allocations_.end()) {
28 size = result->second;
30 }
31 vas_->FreePages(address, size);
32 return true;
33}
34
36 size_t new_size) {
37 // The VirtualAddressSpace class doesn't support this method because it can't
38 // be properly implemented on top of Windows placeholder mappings (they cannot
39 // be partially freed or resized while being allocated). Instead, we emulate
40 // this behaviour by decommitting the released pages, which in effect achieves
41 // exactly what ReleasePages would normally do as well. However, we still need
42 // to pass the original size to FreePages eventually, so we'll need to keep
43 // track of that.
44 DCHECK_LE(new_size, size);
45
46 MutexGuard guard(&mutex_);
47 // Will fail if the allocation was resized previously, which is desired.
48 Address address = reinterpret_cast<Address>(ptr);
49 resized_allocations_.insert({address, size});
50 CHECK(vas_->DecommitPages(address + new_size, size - new_size));
51 return true;
52}
53
55 void* address, size_t size, PageAllocator::Permission access) {
56 return vas_->SetPagePermissions(reinterpret_cast<Address>(address), size,
57 static_cast<PagePermissions>(access));
58}
59
61 void* address, size_t size, PageAllocator::Permission access) {
62 return vas_->RecommitPages(reinterpret_cast<Address>(address), size,
63 static_cast<PagePermissions>(access));
64}
65
67 size_t size) {
68 return vas_->DiscardSystemPages(reinterpret_cast<Address>(address), size);
69}
70
72 size_t size) {
73 return vas_->DecommitPages(reinterpret_cast<Address>(address), size);
74}
75
76bool VirtualAddressSpacePageAllocator::SealPages(void* address, size_t size) {
77 return false;
78}
79
80} // namespace base
81} // namespace v8
virtual V8_WARN_UNUSED_RESULT bool DiscardSystemPages(Address address, size_t size)
virtual void FreePages(Address address, size_t size)=0
virtual V8_WARN_UNUSED_RESULT bool RecommitPages(Address address, size_t size, PagePermissions permissions)=0
virtual V8_WARN_UNUSED_RESULT Address AllocatePages(Address hint, size_t size, size_t alignment, PagePermissions permissions)=0
virtual V8_WARN_UNUSED_RESULT bool SetPagePermissions(Address address, size_t size, PagePermissions permissions)=0
virtual V8_WARN_UNUSED_RESULT bool DecommitPages(Address address, size_t size)=0
void * AllocatePages(void *hint, size_t size, size_t alignment, Permission access) override
bool ReleasePages(void *address, size_t size, size_t new_size) override
bool SetPermissions(void *address, size_t size, Permission access) override
bool DecommitPages(void *address, size_t size) override
bool RecommitPages(void *address, size_t size, PageAllocator::Permission access) override
bool DiscardSystemPages(void *address, size_t size) override
ZoneVector< RpoNumber > & result
PagePermissions
#define DCHECK_LE(v1, v2)
Definition logging.h:490
#define CHECK(condition)
Definition logging.h:124