5 #include "src/heap/embedder-tracing.h" 7 #include "src/base/logging.h" 8 #include "src/objects/embedder-data-slot.h" 9 #include "src/objects/js-objects-inl.h" 14 void LocalEmbedderHeapTracer::SetRemoteTracer(EmbedderHeapTracer* tracer) {
15 if (remote_tracer_) remote_tracer_->isolate_ =
nullptr;
17 remote_tracer_ = tracer;
19 remote_tracer_->isolate_ =
reinterpret_cast<v8::Isolate*
>(isolate_);
22 void LocalEmbedderHeapTracer::TracePrologue() {
25 num_v8_marking_worklist_was_empty_ = 0;
26 embedder_worklist_empty_ =
false;
27 remote_tracer_->TracePrologue();
30 void LocalEmbedderHeapTracer::TraceEpilogue() {
33 remote_tracer_->TraceEpilogue();
36 void LocalEmbedderHeapTracer::EnterFinalPause() {
39 remote_tracer_->EnterFinalPause(embedder_stack_state_);
42 embedder_stack_state_ = EmbedderHeapTracer::kUnknown;
45 bool LocalEmbedderHeapTracer::Trace(
double deadline) {
46 if (!InUse())
return true;
48 return remote_tracer_->AdvanceTracing(deadline);
51 bool LocalEmbedderHeapTracer::IsRemoteTracingDone() {
52 return !InUse() || remote_tracer_->IsTracingDone();
55 void LocalEmbedderHeapTracer::SetEmbedderStackStateForNextFinalization(
56 EmbedderHeapTracer::EmbedderStackState stack_state) {
59 embedder_stack_state_ = stack_state;
62 LocalEmbedderHeapTracer::ProcessingScope::ProcessingScope(
63 LocalEmbedderHeapTracer* tracer)
65 wrapper_cache_.reserve(kWrapperCacheSize);
68 LocalEmbedderHeapTracer::ProcessingScope::~ProcessingScope() {
69 if (!wrapper_cache_.empty()) {
70 tracer_->remote_tracer()->RegisterV8References(std::move(wrapper_cache_));
74 void LocalEmbedderHeapTracer::ProcessingScope::TracePossibleWrapper(
75 JSObject* js_object) {
76 DCHECK(js_object->IsApiWrapper());
77 if (js_object->GetEmbedderFieldCount() < 2)
return;
81 if (EmbedderDataSlot(js_object, 0).ToAlignedPointer(&pointer0) && pointer0 &&
82 EmbedderDataSlot(js_object, 1).ToAlignedPointer(&pointer1)) {
83 wrapper_cache_.push_back({pointer0, pointer1});
85 FlushWrapperCacheIfFull();
88 void LocalEmbedderHeapTracer::ProcessingScope::FlushWrapperCacheIfFull() {
89 if (wrapper_cache_.size() == wrapper_cache_.capacity()) {
90 tracer_->remote_tracer()->RegisterV8References(std::move(wrapper_cache_));
91 wrapper_cache_.clear();
92 wrapper_cache_.reserve(kWrapperCacheSize);
96 void LocalEmbedderHeapTracer::ProcessingScope::AddWrapperInfoForTesting(
98 wrapper_cache_.push_back(info);
99 FlushWrapperCacheIfFull();