v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
collection-barrier.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_COLLECTION_BARRIER_H_
6#define V8_HEAP_COLLECTION_BARRIER_H_
7
8#include <atomic>
9
13#include "src/heap/local-heap.h"
15
16namespace v8 {
17namespace internal {
18
19class Heap;
20
21// This class stops and resumes all background threads waiting for GC.
23 public:
25 Heap* heap, std::shared_ptr<v8::TaskRunner> foreground_task_runner);
26
27 // Returns true when collection was requested.
28 bool WasGCRequested();
29
30 // Requests a GC from the main thread. Returns whether GC was successfully
31 // requested. Requesting a GC can fail when isolate shutdown was already
32 // initiated.
33 bool TryRequestGC();
34
35 // Resumes all threads waiting for GC when tear down starts.
37
38 // Stops the TimeToCollection timer when starting the GC.
40
41 // Resumes threads waiting for collection.
43
44 // Cancels collection if one was requested and resumes threads waiting for GC.
46
47 // This is the method use by background threads to request and wait for GC.
48 // Returns whether a GC was performed.
49 bool AwaitCollectionBackground(LocalHeap* local_heap);
50
51 private:
56
57 // Flag that main thread checks whether a GC was requested from the background
58 // thread.
59 std::atomic<bool> collection_requested_{false};
60
61 // This flag is used to detect whether to block for the GC. Only set if the
62 // main thread was actually running and is unset when GC resumes background
63 // threads.
65
66 // Set to true when a GC was performed, false in case it was canceled because
67 // the main thread parked itself without running the GC.
69
70 // Will be set as soon as Isolate starts tear down.
71 bool shutdown_requested_ = false;
72
73 // Used to post tasks on the main thread.
74 std::shared_ptr<v8::TaskRunner> foreground_task_runner_;
75};
76
77} // namespace internal
78} // namespace v8
79
80#endif // V8_HEAP_COLLECTION_BARRIER_H_
std::shared_ptr< v8::TaskRunner > foreground_task_runner_
CollectionBarrier(Heap *heap, std::shared_ptr< v8::TaskRunner > foreground_task_runner)
base::ConditionVariable cv_wakeup_
bool AwaitCollectionBackground(LocalHeap *local_heap)
std::atomic< bool > collection_requested_