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 #include "src/heap/embedder-tracing.h" 6 7 #include "src/base/logging.h" 8 9 namespace v8 { 10 namespace internal { 11 TracePrologue()12void LocalEmbedderHeapTracer::TracePrologue() { 13 if (!InUse()) return; 14 15 CHECK(cached_wrappers_to_trace_.empty()); 16 num_v8_marking_worklist_was_empty_ = 0; 17 remote_tracer_->TracePrologue(); 18 } 19 TraceEpilogue()20void LocalEmbedderHeapTracer::TraceEpilogue() { 21 if (!InUse()) return; 22 23 CHECK(cached_wrappers_to_trace_.empty()); 24 remote_tracer_->TraceEpilogue(); 25 } 26 AbortTracing()27void LocalEmbedderHeapTracer::AbortTracing() { 28 if (!InUse()) return; 29 30 cached_wrappers_to_trace_.clear(); 31 remote_tracer_->AbortTracing(); 32 } 33 EnterFinalPause()34void LocalEmbedderHeapTracer::EnterFinalPause() { 35 if (!InUse()) return; 36 37 remote_tracer_->EnterFinalPause(embedder_stack_state_); 38 // Resetting to state unknown as there may be follow up garbage collections 39 // triggered from callbacks that have a different stack state. 40 embedder_stack_state_ = EmbedderHeapTracer::kUnknown; 41 } 42 Trace(double deadline)43bool LocalEmbedderHeapTracer::Trace(double deadline) { 44 if (!InUse()) return true; 45 46 DCHECK_EQ(0, NumberOfCachedWrappersToTrace()); 47 return remote_tracer_->AdvanceTracing(deadline); 48 } 49 IsRemoteTracingDone()50bool LocalEmbedderHeapTracer::IsRemoteTracingDone() { 51 return (InUse()) ? cached_wrappers_to_trace_.empty() && 52 remote_tracer_->IsTracingDone() 53 : true; 54 } 55 RegisterWrappersWithRemoteTracer()56void LocalEmbedderHeapTracer::RegisterWrappersWithRemoteTracer() { 57 if (!InUse()) return; 58 59 if (cached_wrappers_to_trace_.empty()) { 60 return; 61 } 62 63 remote_tracer_->RegisterV8References(cached_wrappers_to_trace_); 64 cached_wrappers_to_trace_.clear(); 65 } 66 RequiresImmediateWrapperProcessing()67bool LocalEmbedderHeapTracer::RequiresImmediateWrapperProcessing() { 68 const size_t kTooManyWrappers = 16000; 69 return cached_wrappers_to_trace_.size() > kTooManyWrappers; 70 } 71 SetEmbedderStackStateForNextFinalization(EmbedderHeapTracer::EmbedderStackState stack_state)72void LocalEmbedderHeapTracer::SetEmbedderStackStateForNextFinalization( 73 EmbedderHeapTracer::EmbedderStackState stack_state) { 74 if (!InUse()) return; 75 76 embedder_stack_state_ = stack_state; 77 } 78 79 } // namespace internal 80 } // namespace v8 81