v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
virtual-memory.cc
Go to the documentation of this file.
1// Copyright 2020 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
8#include "src/base/macros.h"
9
10namespace cppgc {
11namespace internal {
12
13VirtualMemory::VirtualMemory(PageAllocator* page_allocator, size_t size,
14 size_t alignment, void* hint)
15 : page_allocator_(page_allocator) {
16 DCHECK_NOT_NULL(page_allocator);
17 DCHECK(IsAligned(size, page_allocator->CommitPageSize()));
18
19 const size_t page_size = page_allocator_->AllocatePageSize();
20 start_ = page_allocator->AllocatePages(hint, RoundUp(size, page_size),
21 RoundUp(alignment, page_size),
23 if (start_) {
24 size_ = RoundUp(size, page_size);
25 }
26}
27
33
35 : page_allocator_(std::move(other.page_allocator_)),
36 start_(std::move(other.start_)),
37 size_(std::move(other.size_)) {
38 other.Reset();
39}
40
42 DCHECK(!IsReserved());
43 page_allocator_ = std::move(other.page_allocator_);
44 start_ = std::move(other.start_);
45 size_ = std::move(other.size_);
46 other.Reset();
47 return *this;
48}
49
51 start_ = nullptr;
52 size_ = 0;
53}
54
55} // namespace internal
56} // namespace cppgc
VirtualMemory & operator=(VirtualMemory &&) V8_NOEXCEPT
virtual size_t AllocatePageSize()=0
virtual void * AllocatePages(void *address, size_t length, size_t alignment, Permission permissions)=0
virtual bool FreePages(void *address, size_t length)=0
virtual size_t CommitPageSize()=0
const int size_
Definition assembler.cc:132
uint8_t *const start_
Definition assembler.cc:131
cppgc::PageAllocator * page_allocator_
Definition cpp-heap.cc:194
#define V8_NOEXCEPT
#define DCHECK_NOT_NULL(val)
Definition logging.h:492
#define DCHECK(condition)
Definition logging.h:482
constexpr T RoundUp(T x, intptr_t m)
Definition macros.h:387
constexpr bool IsAligned(T value, U alignment)
Definition macros.h:403