V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
embedder-tracing.h
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 class JSObject;
17 
18 class V8_EXPORT_PRIVATE LocalEmbedderHeapTracer final {
19  public:
20  typedef std::pair<void*, void*> WrapperInfo;
21  typedef std::vector<WrapperInfo> WrapperCache;
22 
23  class V8_EXPORT_PRIVATE ProcessingScope {
24  public:
25  explicit ProcessingScope(LocalEmbedderHeapTracer* tracer);
26  ~ProcessingScope();
27 
28  void TracePossibleWrapper(JSObject* js_object);
29 
30  void AddWrapperInfoForTesting(WrapperInfo info);
31 
32  private:
33  static constexpr size_t kWrapperCacheSize = 1000;
34 
35  void FlushWrapperCacheIfFull();
36 
37  LocalEmbedderHeapTracer* const tracer_;
38  WrapperCache wrapper_cache_;
39  };
40 
41  explicit LocalEmbedderHeapTracer(Isolate* isolate) : isolate_(isolate) {}
42 
44  if (remote_tracer_) remote_tracer_->isolate_ = nullptr;
45  }
46 
47  bool InUse() const { return remote_tracer_ != nullptr; }
48  EmbedderHeapTracer* remote_tracer() const { return remote_tracer_; }
49 
50  void SetRemoteTracer(EmbedderHeapTracer* tracer);
51  void TracePrologue();
52  void TraceEpilogue();
53  void EnterFinalPause();
54  bool Trace(double deadline);
55  bool IsRemoteTracingDone();
56 
57  void NotifyV8MarkingWorklistWasEmpty() {
58  num_v8_marking_worklist_was_empty_++;
59  }
60 
61  bool ShouldFinalizeIncrementalMarking() {
62  static const size_t kMaxIncrementalFixpointRounds = 3;
63  return !FLAG_incremental_marking_wrappers || !InUse() ||
64  (IsRemoteTracingDone() && embedder_worklist_empty_) ||
65  num_v8_marking_worklist_was_empty_ > kMaxIncrementalFixpointRounds;
66  }
67 
68  void SetEmbedderStackStateForNextFinalization(
69  EmbedderHeapTracer::EmbedderStackState stack_state);
70 
71  void SetEmbedderWorklistEmpty(bool is_empty) {
72  embedder_worklist_empty_ = is_empty;
73  }
74 
75  private:
76  Isolate* const isolate_;
77  EmbedderHeapTracer* remote_tracer_ = nullptr;
78 
79  size_t num_v8_marking_worklist_was_empty_ = 0;
80  EmbedderHeapTracer::EmbedderStackState embedder_stack_state_ =
81  EmbedderHeapTracer::kUnknown;
82  // Indicates whether the embedder worklist was observed empty on the main
83  // thread. This is opportunistic as concurrent marking tasks may hold local
84  // segments of potential embedder fields to move to the main thread.
85  bool embedder_worklist_empty_ = false;
86 
87  friend class EmbedderStackStateScope;
88 };
89 
90 class V8_EXPORT_PRIVATE EmbedderStackStateScope final {
91  public:
93  EmbedderHeapTracer::EmbedderStackState stack_state)
94  : local_tracer_(local_tracer),
95  old_stack_state_(local_tracer_->embedder_stack_state_) {
96  local_tracer_->embedder_stack_state_ = stack_state;
97  }
98 
100  local_tracer_->embedder_stack_state_ = old_stack_state_;
101  }
102 
103  private:
104  LocalEmbedderHeapTracer* const local_tracer_;
105  const EmbedderHeapTracer::EmbedderStackState old_stack_state_;
106 };
107 
108 } // namespace internal
109 } // namespace v8
110 
111 #endif // V8_HEAP_EMBEDDER_TRACING_H_
Definition: libplatform.h:13