Line data Source code
1 : // Copyright 2016 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_EMBEDDER_TRACING_H_
6 : #define V8_HEAP_EMBEDDER_TRACING_H_
7 :
8 : #include "include/v8.h"
9 : #include "src/flags.h"
10 : #include "src/globals.h"
11 :
12 : namespace v8 {
13 : namespace internal {
14 :
15 : class Heap;
16 :
17 : class V8_EXPORT_PRIVATE LocalEmbedderHeapTracer final {
18 : public:
19 : typedef std::pair<void*, void*> WrapperInfo;
20 :
21 : LocalEmbedderHeapTracer()
22 110018 : : remote_tracer_(nullptr), num_v8_marking_worklist_was_empty_(0) {}
23 :
24 9 : void SetRemoteTracer(EmbedderHeapTracer* tracer) { remote_tracer_ = tracer; }
25 84034 : bool InUse() { return remote_tracer_ != nullptr; }
26 :
27 : void TracePrologue();
28 : void TraceEpilogue();
29 : void AbortTracing();
30 : void EnterFinalPause();
31 : bool Trace(double deadline,
32 : EmbedderHeapTracer::AdvanceTracingActions actions);
33 :
34 : size_t NumberOfWrappersToTrace();
35 : size_t NumberOfCachedWrappersToTrace() {
36 7 : return cached_wrappers_to_trace_.size();
37 : }
38 : void AddWrapperToTrace(WrapperInfo entry) {
39 4 : cached_wrappers_to_trace_.push_back(entry);
40 : }
41 : void ClearCachedWrappersToTrace() { cached_wrappers_to_trace_.clear(); }
42 : void RegisterWrappersWithRemoteTracer();
43 :
44 : // In order to avoid running out of memory we force tracing wrappers if there
45 : // are too many of them.
46 : bool RequiresImmediateWrapperProcessing();
47 :
48 : void NotifyV8MarkingWorklistWasEmpty() {
49 0 : num_v8_marking_worklist_was_empty_++;
50 : }
51 90752 : bool ShouldFinalizeIncrementalMarking() {
52 : static const size_t kMaxIncrementalFixpointRounds = 3;
53 90752 : return !FLAG_incremental_marking_wrappers || !InUse() ||
54 45376 : NumberOfWrappersToTrace() == 0 ||
55 45376 : num_v8_marking_worklist_was_empty_ > kMaxIncrementalFixpointRounds;
56 : }
57 :
58 : private:
59 : typedef std::vector<WrapperInfo> WrapperCache;
60 :
61 : EmbedderHeapTracer* remote_tracer_;
62 : WrapperCache cached_wrappers_to_trace_;
63 : size_t num_v8_marking_worklist_was_empty_;
64 : };
65 :
66 : } // namespace internal
67 : } // namespace v8
68 :
69 : #endif // V8_HEAP_EMBEDDER_TRACING_H_
|