v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
heap-visitor.h
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
#ifndef V8_HEAP_CPPGC_HEAP_VISITOR_H_
6
#define V8_HEAP_CPPGC_HEAP_VISITOR_H_
7
8
#include "
src/heap/cppgc/heap-page.h
"
9
#include "
src/heap/cppgc/heap-space.h
"
10
#include "
src/heap/cppgc/raw-heap.h
"
11
12
namespace
cppgc
{
13
namespace
internal
{
14
15
// Visitor for heap, which also implements the accept (traverse) interface.
16
// Implements preorder traversal of the heap. The order of traversal is defined.
17
// Implemented as a CRTP visitor to avoid virtual calls and support better
18
// inlining.
19
template
<
typename
Derived>
20
class
HeapVisitor
{
21
public
:
22
void
Traverse
(
RawHeap
&
heap
) {
23
if
(
VisitHeapImpl
(
heap
))
return
;
24
for
(
auto
& space :
heap
) {
25
Traverse
(*space.get());
26
}
27
}
28
29
void
Traverse
(
BaseSpace
& space) {
30
const
bool
is_stopped =
31
space.is_large()
32
?
VisitLargePageSpaceImpl
(
LargePageSpace::From
(space))
33
:
VisitNormalPageSpaceImpl
(
NormalPageSpace::From
(space));
34
if
(is_stopped)
return
;
35
for
(
auto
* page : space) {
36
Traverse
(*page);
37
}
38
}
39
40
void
Traverse
(
BasePage
& page) {
41
if
(page.is_large()) {
42
auto
* large_page =
LargePage::From
(&page);
43
if
(
VisitLargePageImpl
(*large_page))
return
;
44
VisitHeapObjectHeaderImpl
(*large_page->ObjectHeader());
45
}
else
{
46
auto
* normal_page =
NormalPage::From
(&page);
47
if
(
VisitNormalPageImpl
(*normal_page))
return
;
48
for
(
auto
& header : *normal_page) {
49
VisitHeapObjectHeaderImpl
(header);
50
}
51
}
52
}
53
54
protected
:
55
// Visitor functions return true if no deeper processing is required.
56
// Users are supposed to override functions that need special treatment.
57
bool
VisitHeap
(
RawHeap
&) {
return
false
; }
58
bool
VisitNormalPageSpace
(
NormalPageSpace
&) {
return
false
; }
59
bool
VisitLargePageSpace
(
LargePageSpace
&) {
return
false
; }
60
bool
VisitNormalPage
(
NormalPage
&) {
return
false
; }
61
bool
VisitLargePage
(
LargePage
&) {
return
false
; }
62
bool
VisitHeapObjectHeader
(
HeapObjectHeader
&) {
return
false
; }
63
64
private
:
65
Derived&
ToDerived
() {
return
static_cast<
Derived&
>
(*this); }
66
67
bool
VisitHeapImpl
(
RawHeap
&
heap
) {
return
ToDerived
().VisitHeap(
heap
); }
68
bool
VisitNormalPageSpaceImpl
(
NormalPageSpace
& space) {
69
return
ToDerived
().VisitNormalPageSpace(space);
70
}
71
bool
VisitLargePageSpaceImpl
(
LargePageSpace
& space) {
72
return
ToDerived
().VisitLargePageSpace(space);
73
}
74
bool
VisitNormalPageImpl
(
NormalPage
& page) {
75
return
ToDerived
().VisitNormalPage(page);
76
}
77
bool
VisitLargePageImpl
(
LargePage
& page) {
78
return
ToDerived
().VisitLargePage(page);
79
}
80
bool
VisitHeapObjectHeaderImpl
(
HeapObjectHeader
& header) {
81
return
ToDerived
().VisitHeapObjectHeader(header);
82
}
83
};
84
85
}
// namespace internal
86
}
// namespace cppgc
87
88
#endif
// V8_HEAP_CPPGC_HEAP_VISITOR_H_
cppgc::internal::BasePage
Definition
heap-page.h:30
cppgc::internal::BaseSpace
Definition
heap-space.h:22
cppgc::internal::HeapObjectHeader
Definition
heap-object-header.h:58
cppgc::internal::HeapVisitor
Definition
heap-visitor.h:20
cppgc::internal::HeapVisitor::VisitHeapImpl
bool VisitHeapImpl(RawHeap &heap)
Definition
heap-visitor.h:67
cppgc::internal::HeapVisitor::Traverse
void Traverse(RawHeap &heap)
Definition
heap-visitor.h:22
cppgc::internal::HeapVisitor::VisitHeapObjectHeader
bool VisitHeapObjectHeader(HeapObjectHeader &)
Definition
heap-visitor.h:62
cppgc::internal::HeapVisitor::VisitHeap
bool VisitHeap(RawHeap &)
Definition
heap-visitor.h:57
cppgc::internal::HeapVisitor::Traverse
void Traverse(BaseSpace &space)
Definition
heap-visitor.h:29
cppgc::internal::HeapVisitor::VisitHeapObjectHeaderImpl
bool VisitHeapObjectHeaderImpl(HeapObjectHeader &header)
Definition
heap-visitor.h:80
cppgc::internal::HeapVisitor::VisitLargePageImpl
bool VisitLargePageImpl(LargePage &page)
Definition
heap-visitor.h:77
cppgc::internal::HeapVisitor::VisitLargePage
bool VisitLargePage(LargePage &)
Definition
heap-visitor.h:61
cppgc::internal::HeapVisitor::VisitNormalPageSpaceImpl
bool VisitNormalPageSpaceImpl(NormalPageSpace &space)
Definition
heap-visitor.h:68
cppgc::internal::HeapVisitor::VisitLargePageSpaceImpl
bool VisitLargePageSpaceImpl(LargePageSpace &space)
Definition
heap-visitor.h:71
cppgc::internal::HeapVisitor::VisitNormalPageSpace
bool VisitNormalPageSpace(NormalPageSpace &)
Definition
heap-visitor.h:58
cppgc::internal::HeapVisitor::ToDerived
Derived & ToDerived()
Definition
heap-visitor.h:65
cppgc::internal::HeapVisitor::Traverse
void Traverse(BasePage &page)
Definition
heap-visitor.h:40
cppgc::internal::HeapVisitor::VisitNormalPageImpl
bool VisitNormalPageImpl(NormalPage &page)
Definition
heap-visitor.h:74
cppgc::internal::HeapVisitor::VisitLargePageSpace
bool VisitLargePageSpace(LargePageSpace &)
Definition
heap-visitor.h:59
cppgc::internal::HeapVisitor::VisitNormalPage
bool VisitNormalPage(NormalPage &)
Definition
heap-visitor.h:60
cppgc::internal::LargePageSpace
Definition
heap-space.h:116
cppgc::internal::LargePageSpace::From
static LargePageSpace & From(BaseSpace &space)
Definition
heap-space.h:118
cppgc::internal::LargePage
Definition
heap-page.h:256
cppgc::internal::LargePage::From
static LargePage * From(BasePage *page)
Definition
heap-page.h:275
cppgc::internal::NormalPageSpace
Definition
heap-space.h:68
cppgc::internal::NormalPageSpace::From
static NormalPageSpace & From(BaseSpace &space)
Definition
heap-space.h:93
cppgc::internal::NormalPage
Definition
heap-page.h:152
cppgc::internal::NormalPage::From
static NormalPage * From(BasePage *page)
Definition
heap-page.h:205
cppgc::internal::RawHeap
Definition
raw-heap.h:23
heap-page.h
heap-space.h
cppgc
Definition
cross-heap-remembered-set.h:14
heap
Definition
platform.h:72
v8::internal::internal
internal
Definition
wasm-objects-inl.h:458
raw-heap.h
src
heap
cppgc
heap-visitor.h
Generated on Sun Apr 6 2025 21:08:54 for v8 by
1.12.0