forked from v8/v8
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtual-memory.cc
More file actions
56 lines (46 loc) · 1.6 KB
/
virtual-memory.cc
File metadata and controls
56 lines (46 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/heap/cppgc/virtual-memory.h"
#include "include/cppgc/platform.h"
#include "src/base/macros.h"
namespace cppgc {
namespace internal {
VirtualMemory::VirtualMemory(PageAllocator* page_allocator, size_t size,
size_t alignment, void* hint)
: page_allocator_(page_allocator) {
DCHECK_NOT_NULL(page_allocator);
DCHECK(IsAligned(size, page_allocator->CommitPageSize()));
const size_t page_size = page_allocator_->AllocatePageSize();
start_ = page_allocator->AllocatePages(hint, RoundUp(size, page_size),
RoundUp(alignment, page_size),
PageAllocator::kNoAccess);
if (start_) {
size_ = RoundUp(size, page_size);
}
}
VirtualMemory::~VirtualMemory() V8_NOEXCEPT {
if (IsReserved()) {
page_allocator_->FreePages(start_, size_);
}
}
VirtualMemory::VirtualMemory(VirtualMemory&& other) V8_NOEXCEPT
: page_allocator_(std::move(other.page_allocator_)),
start_(std::move(other.start_)),
size_(std::move(other.size_)) {
other.Reset();
}
VirtualMemory& VirtualMemory::operator=(VirtualMemory&& other) V8_NOEXCEPT {
DCHECK(!IsReserved());
page_allocator_ = std::move(other.page_allocator_);
start_ = std::move(other.start_);
size_ = std::move(other.size_);
other.Reset();
return *this;
}
void VirtualMemory::Reset() {
start_ = nullptr;
size_ = 0;
}
} // namespace internal
} // namespace cppgc