Index: src/heap/heap.cc |
diff --git a/src/heap/heap.cc b/src/heap/heap.cc |
index 2472d45b7faf8eced8091f8205348530c80902b7..ce1c06b61eedcc3f022ca9dffaa11afff4b90e19 100644 |
--- a/src/heap/heap.cc |
+++ b/src/heap/heap.cc |
@@ -162,6 +162,8 @@ Heap::Heap() |
deserialization_complete_(false), |
strong_roots_list_(NULL), |
heap_iterator_depth_(0), |
+ embedder_heap_tracer_(nullptr), |
+ embedder_reference_reporter_(new TracePossibleWrapperReporter(this)), |
force_oom_(false) { |
// Allow build-time customization of the max semispace size. Building |
// V8 with snapshots and a non-default max semispace size is much |
@@ -1615,7 +1617,7 @@ void Heap::Scavenge() { |
// Register found wrappers with embedder so it can add them to its marking |
// deque and correctly manage the case when v8 scavenger collects the |
// wrappers by either keeping wrappables alive, or cleaning marking deque. |
- mark_compact_collector()->RegisterWrappersWithEmbedderHeapTracer(); |
+ RegisterWrappersWithEmbedderHeapTracer(); |
} |
// Flip the semispaces. After flipping, to space is empty, from space has |
@@ -4214,10 +4216,8 @@ void Heap::ReduceNewSpaceSize() { |
bool Heap::MarkingDequesAreEmpty() { |
return mark_compact_collector()->marking_deque()->IsEmpty() && |
(!UsingEmbedderHeapTracer() || |
- (mark_compact_collector()->wrappers_to_trace() == 0 && |
- mark_compact_collector() |
- ->embedder_heap_tracer() |
- ->NumberOfWrappersToTrace() == 0)); |
+ (wrappers_to_trace() == 0 && |
+ embedder_heap_tracer()->NumberOfWrappersToTrace() == 0)); |
} |
void Heap::FinalizeIncrementalMarkingIfComplete( |
@@ -5561,15 +5561,36 @@ void Heap::NotifyDeserializationComplete() { |
} |
void Heap::SetEmbedderHeapTracer(EmbedderHeapTracer* tracer) { |
- mark_compact_collector()->SetEmbedderHeapTracer(tracer); |
+ DCHECK_NOT_NULL(tracer); |
+ CHECK_NULL(embedder_heap_tracer_); |
+ embedder_heap_tracer_ = tracer; |
} |
-bool Heap::UsingEmbedderHeapTracer() { |
- return mark_compact_collector()->UsingEmbedderHeapTracer(); |
+void Heap::RegisterWrappersWithEmbedderHeapTracer() { |
+ DCHECK(UsingEmbedderHeapTracer()); |
+ if (wrappers_to_trace_.empty()) { |
+ return; |
+ } |
+ embedder_heap_tracer()->RegisterV8References(wrappers_to_trace_); |
+ wrappers_to_trace_.clear(); |
} |
void Heap::TracePossibleWrapper(JSObject* js_object) { |
- mark_compact_collector()->TracePossibleWrapper(js_object); |
+ DCHECK(js_object->WasConstructedFromApiFunction()); |
+ if (js_object->GetInternalFieldCount() >= 2 && |
+ js_object->GetInternalField(0) && |
+ js_object->GetInternalField(0) != undefined_value() && |
+ js_object->GetInternalField(1) != undefined_value()) { |
+ DCHECK(reinterpret_cast<intptr_t>(js_object->GetInternalField(0)) % 2 == 0); |
+ wrappers_to_trace_.push_back(std::pair<void*, void*>( |
+ reinterpret_cast<void*>(js_object->GetInternalField(0)), |
+ reinterpret_cast<void*>(js_object->GetInternalField(1)))); |
+ } |
+} |
+ |
+bool Heap::RequiresImmediateWrapperProcessing() { |
+ const size_t kTooManyWrappers = 16000; |
+ return wrappers_to_trace_.size() > kTooManyWrappers; |
} |
void Heap::RegisterExternallyReferencedObject(Object** object) { |
@@ -5714,6 +5735,9 @@ void Heap::TearDown() { |
delete memory_allocator_; |
memory_allocator_ = nullptr; |
+ |
+ delete embedder_reference_reporter_; |
+ embedder_reference_reporter_ = nullptr; |
} |