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"
15
16namespace cppgc::internal {
17
18class HeapBase;
19class ConcurrentSweeperTest;
20class BaseSpace;
21
23 public:
25 public:
28
29 virtual void Start() = 0;
30 virtual void End() = 0;
31
32 private:
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
45#endif
46 }
47
48 explicit Sweeper(HeapBase&);
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,
75
76 private:
77 void WaitForConcurrentSweepingForTesting();
78
79 class SweeperImpl;
80
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_
Sweeper & operator=(const Sweeper &)=delete
std::unique_ptr< SweeperImpl > impl_
Definition sweeper.h:82
Sweeper(const Sweeper &)=delete
static constexpr bool CanDiscardMemory()
Definition sweeper.h:36
constexpr bool CheckMemoryIsInaccessibleIsNoop()
Definition memory.h:74
#define V8_EXPORT_PRIVATE
Definition macros.h:460