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 LocalEmbedderHeapTracer()21 LocalEmbedderHeapTracer() 22 : remote_tracer_(nullptr), num_v8_marking_deque_was_empty_(0) {} 23 SetRemoteTracer(EmbedderHeapTracer * tracer)24 void SetRemoteTracer(EmbedderHeapTracer* tracer) { remote_tracer_ = tracer; } InUse()25 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(); NumberOfCachedWrappersToTrace()35 size_t NumberOfCachedWrappersToTrace() { 36 return cached_wrappers_to_trace_.size(); 37 } AddWrapperToTrace(WrapperInfo entry)38 void AddWrapperToTrace(WrapperInfo entry) { 39 cached_wrappers_to_trace_.push_back(entry); 40 } ClearCachedWrappersToTrace()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 NotifyV8MarkingDequeWasEmpty()48 void NotifyV8MarkingDequeWasEmpty() { num_v8_marking_deque_was_empty_++; } ShouldFinalizeIncrementalMarking()49 bool ShouldFinalizeIncrementalMarking() { 50 static const size_t kMaxIncrementalFixpointRounds = 3; 51 return !FLAG_incremental_marking_wrappers || !InUse() || 52 NumberOfWrappersToTrace() == 0 || 53 num_v8_marking_deque_was_empty_ > kMaxIncrementalFixpointRounds; 54 } 55 56 private: 57 typedef std::vector<WrapperInfo> WrapperCache; 58 59 EmbedderHeapTracer* remote_tracer_; 60 WrapperCache cached_wrappers_to_trace_; 61 size_t num_v8_marking_deque_was_empty_; 62 }; 63 64 } // namespace internal 65 } // namespace v8 66 67 #endif // V8_HEAP_EMBEDDER_TRACING_H_ 68