v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
sweeper.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_SWEEPER_H_
6
#define V8_HEAP_CPPGC_SWEEPER_H_
7
8
#include <memory>
9
10
#include "
src/base/macros.h
"
11
#include "
src/base/platform/time.h
"
12
#include "
src/heap/cppgc/heap-config.h
"
13
#include "
src/heap/cppgc/memory.h
"
14
#include "
src/heap/cppgc/stats-collector.h
"
15
16
namespace
cppgc::internal
{
17
18
class
HeapBase;
19
class
ConcurrentSweeperTest;
20
class
BaseSpace;
21
22
class
V8_EXPORT_PRIVATE
Sweeper
final {
23
public
:
24
class
V8_EXPORT_PRIVATE
SweepingOnMutatorThreadObserver
{
25
public
:
26
explicit
SweepingOnMutatorThreadObserver
(
Sweeper
&);
27
virtual
~SweepingOnMutatorThreadObserver
();
28
29
virtual
void
Start
() = 0;
30
virtual
void
End
() = 0;
31
32
private
:
33
Sweeper
&
sweeper_
;
34
};
35
36
static
constexpr
bool
CanDiscardMemory
() {
37
#if defined(V8_OS_WIN)
38
// Discarding memory on Windows does not decommit the memory and does not
39
// contribute to reduce the memory footprint. On the other hand, these
40
// calls become expensive the more memory is allocated in the system and
41
// can result in hangs. Thus, it is better to not discard on Windows.
42
return
false
;
43
#else
44
return
CheckMemoryIsInaccessibleIsNoop
();
45
#endif
46
}
47
48
explicit
Sweeper
(
HeapBase
&);
49
~Sweeper
();
50
51
Sweeper
(
const
Sweeper
&) =
delete
;
52
Sweeper
&
operator=
(
const
Sweeper
&) =
delete
;
53
54
// Starts sweeping. Assumes that the heap holds no linear allocation buffers.
55
// Will not finish sweeping in case SweepingConfig::sweeping_type is
56
// SweepingType::kAtomic but rely on the caller to finish sweeping
57
// immediately.
58
void
Start(
SweepingConfig
);
59
// Returns true when sweeping was finished and false if it was not running or
60
// couldn't be finished due to being a recursive sweep call.
61
bool
FinishIfRunning();
62
void
FinishIfOutOfWork();
63
// SweepForAllocationIfRunning sweeps the given `space` until a slot that can
64
// fit an allocation of `min_wanted_size` bytes is found. Returns true if a
65
// slot was found. Aborts after `max_duration`.
66
bool
SweepForAllocationIfRunning(
BaseSpace
* space,
size_t
min_wanted_size,
67
v8::base::TimeDelta
max_duration);
68
69
bool
IsSweepingOnMutatorThread()
const
;
70
bool
IsSweepingInProgress()
const
;
71
72
// Assist with sweeping. Returns true if sweeping is done.
73
bool
PerformSweepOnMutatorThread(
v8::base::TimeDelta
max_duration,
74
StatsCollector::ScopeId
);
75
76
private
:
77
void
WaitForConcurrentSweepingForTesting();
78
79
class
SweeperImpl
;
80
81
HeapBase
&
heap_
;
82
std::unique_ptr<SweeperImpl>
impl_
;
83
84
friend
class
ConcurrentSweeperTest;
85
};
86
87
}
// namespace cppgc::internal
88
89
#endif
// V8_HEAP_CPPGC_SWEEPER_H_
cppgc::internal::BaseSpace
Definition
heap-space.h:22
cppgc::internal::HeapBase
Definition
heap-base.h:82
cppgc::internal::StatsCollector::ScopeId
ScopeId
Definition
stats-collector.h:95
cppgc::internal::Sweeper::SweeperImpl
Definition
sweeper.cc:961
cppgc::internal::Sweeper::SweepingOnMutatorThreadObserver
Definition
sweeper.h:24
cppgc::internal::Sweeper::SweepingOnMutatorThreadObserver::sweeper_
Sweeper & sweeper_
Definition
sweeper.h:33
cppgc::internal::Sweeper::SweepingOnMutatorThreadObserver::End
virtual void End()=0
cppgc::internal::Sweeper::SweepingOnMutatorThreadObserver::Start
virtual void Start()=0
cppgc::internal::Sweeper
Definition
sweeper.h:22
cppgc::internal::Sweeper::~Sweeper
~Sweeper()
cppgc::internal::Sweeper::operator=
Sweeper & operator=(const Sweeper &)=delete
cppgc::internal::Sweeper::heap_
HeapBase & heap_
Definition
sweeper.h:81
cppgc::internal::Sweeper::impl_
std::unique_ptr< SweeperImpl > impl_
Definition
sweeper.h:82
cppgc::internal::Sweeper::Sweeper
Sweeper(const Sweeper &)=delete
cppgc::internal::Sweeper::CanDiscardMemory
static constexpr bool CanDiscardMemory()
Definition
sweeper.h:36
v8::base::TimeDelta
Definition
time.h:67
heap-config.h
memory.h
cppgc::internal
Definition
cross-heap-remembered-set.h:14
cppgc::internal::CheckMemoryIsInaccessibleIsNoop
constexpr bool CheckMemoryIsInaccessibleIsNoop()
Definition
memory.h:74
macros.h
V8_EXPORT_PRIVATE
#define V8_EXPORT_PRIVATE
Definition
macros.h:460
stats-collector.h
cppgc::internal::SweepingConfig
Definition
heap-config.h:47
time.h
src
heap
cppgc
sweeper.h
Generated on Sun Apr 6 2025 21:08:54 for v8 by
1.12.0