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
5
#include "
src/heap/cppgc/virtual-memory.h
"
6
7
#include "
include/cppgc/platform.h
"
8
#include "
src/base/macros.h
"
9
10
namespace
cppgc
{
11
namespace
internal
{
12
13
VirtualMemory::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),
22
PageAllocator::kNoAccess
);
23
if
(
start_
) {
24
size_
=
RoundUp
(size, page_size);
25
}
26
}
27
28
VirtualMemory::~VirtualMemory
()
V8_NOEXCEPT
{
29
if
(
IsReserved
()) {
30
page_allocator_
->
FreePages
(
start_
,
size_
);
31
}
32
}
33
34
VirtualMemory::VirtualMemory
(
VirtualMemory
&& other)
V8_NOEXCEPT
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
41
VirtualMemory
&
VirtualMemory::operator=
(
VirtualMemory
&& other)
V8_NOEXCEPT
{
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
50
void
VirtualMemory::Reset
() {
51
start_
=
nullptr
;
52
size_
= 0;
53
}
54
55
}
// namespace internal
56
}
// namespace cppgc
cppgc::internal::VirtualMemory
Definition
virtual-memory.h:17
cppgc::internal::VirtualMemory::IsReserved
bool IsReserved() const
Definition
virtual-memory.h:36
cppgc::internal::VirtualMemory::size_
size_t size_
Definition
virtual-memory.h:54
cppgc::internal::VirtualMemory::start_
void * start_
Definition
virtual-memory.h:53
cppgc::internal::VirtualMemory::Reset
void Reset()
Definition
virtual-memory.cc:50
cppgc::internal::VirtualMemory::VirtualMemory
VirtualMemory()=default
cppgc::internal::VirtualMemory::page_allocator_
PageAllocator * page_allocator_
Definition
virtual-memory.h:52
cppgc::internal::VirtualMemory::~VirtualMemory
~VirtualMemory() V8_NOEXCEPT
Definition
virtual-memory.cc:28
cppgc::internal::VirtualMemory::operator=
VirtualMemory & operator=(VirtualMemory &&) V8_NOEXCEPT
Definition
virtual-memory.cc:41
v8::PageAllocator
Definition
v8-platform.h:455
v8::PageAllocator::kNoAccess
@ kNoAccess
Definition
v8-platform.h:487
v8::PageAllocator::AllocatePageSize
virtual size_t AllocatePageSize()=0
v8::PageAllocator::AllocatePages
virtual void * AllocatePages(void *address, size_t length, size_t alignment, Permission permissions)=0
v8::PageAllocator::FreePages
virtual bool FreePages(void *address, size_t length)=0
v8::PageAllocator::CommitPageSize
virtual size_t CommitPageSize()=0
size_
const int size_
Definition
assembler.cc:132
start_
uint8_t *const start_
Definition
assembler.cc:131
page_allocator_
cppgc::PageAllocator * page_allocator_
Definition
cpp-heap.cc:194
platform.h
cppgc
Definition
cross-heap-remembered-set.h:14
v8::internal::internal
internal
Definition
wasm-objects-inl.h:458
V8_NOEXCEPT
#define V8_NOEXCEPT
Definition
compiler-specific.h:105
DCHECK_NOT_NULL
#define DCHECK_NOT_NULL(val)
Definition
logging.h:492
DCHECK
#define DCHECK(condition)
Definition
logging.h:482
macros.h
RoundUp
constexpr T RoundUp(T x, intptr_t m)
Definition
macros.h:387
IsAligned
constexpr bool IsAligned(T value, U alignment)
Definition
macros.h:403
virtual-memory.h
src
heap
cppgc
virtual-memory.cc
Generated on Sun Apr 6 2025 21:08:54 for v8 by
1.12.0