| Index: src/heap/heap.cc
|
| diff --git a/src/heap/heap.cc b/src/heap/heap.cc
|
| index cfeda5d55711a71cd650131edd145da162d9e986..db69962fe0d45342781a2e68bd57b540162c4437 100644
|
| --- a/src/heap/heap.cc
|
| +++ b/src/heap/heap.cc
|
| @@ -1712,7 +1712,7 @@ void Heap::Scavenge() {
|
| Address new_space_front = new_space_->ToSpaceStart();
|
| promotion_queue_.Initialize();
|
|
|
| - ScavengeVisitor scavenge_visitor(this);
|
| + RootScavengeVisitor root_scavenge_visitor(this);
|
|
|
| isolate()->global_handles()->IdentifyWeakUnmodifiedObjects(
|
| &IsUnmodifiedHeapObject);
|
| @@ -1720,7 +1720,7 @@ void Heap::Scavenge() {
|
| {
|
| // Copy roots.
|
| TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_ROOTS);
|
| - IterateRoots(&scavenge_visitor, VISIT_ALL_IN_SCAVENGE);
|
| + IterateRoots(&root_scavenge_visitor, VISIT_ALL_IN_SCAVENGE);
|
| }
|
|
|
| {
|
| @@ -1745,8 +1745,7 @@ void Heap::Scavenge() {
|
|
|
| {
|
| TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_WEAK);
|
| - // Copy objects reachable from the encountered weak collections list.
|
| - scavenge_visitor.VisitPointer(&encountered_weak_collections_);
|
| + IterateEncounteredWeakCollections(&root_scavenge_visitor);
|
| }
|
|
|
| {
|
| @@ -1754,13 +1753,14 @@ void Heap::Scavenge() {
|
| TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_CODE_FLUSH_CANDIDATES);
|
| MarkCompactCollector* collector = mark_compact_collector();
|
| if (collector->is_code_flushing_enabled()) {
|
| - collector->code_flusher()->IteratePointersToFromSpace(&scavenge_visitor);
|
| + collector->code_flusher()->IteratePointersToFromSpace(
|
| + &root_scavenge_visitor);
|
| }
|
| }
|
|
|
| {
|
| TRACE_GC(tracer(), GCTracer::Scope::SCAVENGER_SEMISPACE);
|
| - new_space_front = DoScavenge(&scavenge_visitor, new_space_front);
|
| + new_space_front = DoScavenge(new_space_front);
|
| }
|
|
|
| isolate()->global_handles()->MarkNewSpaceWeakUnmodifiedObjectsPending(
|
| @@ -1769,8 +1769,9 @@ void Heap::Scavenge() {
|
| isolate()
|
| ->global_handles()
|
| ->IterateNewSpaceWeakUnmodifiedRoots<
|
| - GlobalHandles::HANDLE_PHANTOM_NODES_VISIT_OTHERS>(&scavenge_visitor);
|
| - new_space_front = DoScavenge(&scavenge_visitor, new_space_front);
|
| + GlobalHandles::HANDLE_PHANTOM_NODES_VISIT_OTHERS>(
|
| + &root_scavenge_visitor);
|
| + new_space_front = DoScavenge(new_space_front);
|
|
|
| UpdateNewSpaceReferencesInExternalStringTable(
|
| &UpdateNewSpaceReferenceInExternalStringTableEntry);
|
| @@ -1958,12 +1959,12 @@ void Heap::VisitExternalResources(v8::ExternalResourceVisitor* visitor) {
|
| DisallowHeapAllocation no_allocation;
|
| // All external strings are listed in the external string table.
|
|
|
| - class ExternalStringTableVisitorAdapter : public ObjectVisitor {
|
| + class ExternalStringTableVisitorAdapter : public RootVisitor {
|
| public:
|
| explicit ExternalStringTableVisitorAdapter(
|
| v8::ExternalResourceVisitor* visitor)
|
| : visitor_(visitor) {}
|
| - virtual void VisitPointers(Object** start, Object** end) {
|
| + virtual void VisitRootPointers(Root root, Object** start, Object** end) {
|
| for (Object** p = start; p < end; p++) {
|
| DCHECK((*p)->IsExternalString());
|
| visitor_->VisitExternalString(
|
| @@ -1978,8 +1979,7 @@ void Heap::VisitExternalResources(v8::ExternalResourceVisitor* visitor) {
|
| external_string_table_.IterateAll(&external_string_table_visitor);
|
| }
|
|
|
| -Address Heap::DoScavenge(ObjectVisitor* scavenge_visitor,
|
| - Address new_space_front) {
|
| +Address Heap::DoScavenge(Address new_space_front) {
|
| do {
|
| SemiSpace::AssertValidRange(new_space_front, new_space_->top());
|
| // The addresses new_space_front and new_space_.top() define a
|
| @@ -4772,7 +4772,6 @@ bool Heap::RootIsImmortalImmovable(int root_index) {
|
| }
|
| }
|
|
|
| -
|
| #ifdef VERIFY_HEAP
|
| void Heap::Verify() {
|
| CHECK(HasBeenSetUp());
|
| @@ -4904,15 +4903,14 @@ void Heap::IterateAndScavengePromotedObject(HeapObject* target, int size,
|
| }
|
| }
|
|
|
| -
|
| -void Heap::IterateRoots(ObjectVisitor* v, VisitMode mode) {
|
| +void Heap::IterateRoots(RootVisitor* v, VisitMode mode) {
|
| IterateStrongRoots(v, mode);
|
| IterateWeakRoots(v, mode);
|
| }
|
|
|
| -
|
| -void Heap::IterateWeakRoots(ObjectVisitor* v, VisitMode mode) {
|
| - v->VisitPointer(reinterpret_cast<Object**>(&roots_[kStringTableRootIndex]));
|
| +void Heap::IterateWeakRoots(RootVisitor* v, VisitMode mode) {
|
| + v->VisitRootPointer(Root::kStringTable, reinterpret_cast<Object**>(
|
| + &roots_[kStringTableRootIndex]));
|
| v->Synchronize(VisitorSynchronization::kStringTable);
|
| if (mode != VISIT_ALL_IN_SCAVENGE && mode != VISIT_ALL_IN_SWEEP_NEWSPACE) {
|
| // Scavenge collections have special processing for this.
|
| @@ -4921,27 +4919,32 @@ void Heap::IterateWeakRoots(ObjectVisitor* v, VisitMode mode) {
|
| v->Synchronize(VisitorSynchronization::kExternalStringsTable);
|
| }
|
|
|
| -
|
| -void Heap::IterateSmiRoots(ObjectVisitor* v) {
|
| +void Heap::IterateSmiRoots(RootVisitor* v) {
|
| // Acquire execution access since we are going to read stack limit values.
|
| ExecutionAccess access(isolate());
|
| - v->VisitPointers(&roots_[kSmiRootsStart], &roots_[kRootListLength]);
|
| + v->VisitRootPointers(Root::kSmiRootList, &roots_[kSmiRootsStart],
|
| + &roots_[kRootListLength]);
|
| v->Synchronize(VisitorSynchronization::kSmiRootList);
|
| }
|
|
|
| +void Heap::IterateEncounteredWeakCollections(RootVisitor* visitor) {
|
| + visitor->VisitRootPointer(Root::kWeakCollections,
|
| + &encountered_weak_collections_);
|
| +}
|
| +
|
| // We cannot avoid stale handles to left-trimmed objects, but can only make
|
| // sure all handles still needed are updated. Filter out a stale pointer
|
| // and clear the slot to allow post processing of handles (needed because
|
| // the sweeper might actually free the underlying page).
|
| -class FixStaleLeftTrimmedHandlesVisitor : public ObjectVisitor {
|
| +class FixStaleLeftTrimmedHandlesVisitor : public RootVisitor {
|
| public:
|
| explicit FixStaleLeftTrimmedHandlesVisitor(Heap* heap) : heap_(heap) {
|
| USE(heap_);
|
| }
|
|
|
| - void VisitPointer(Object** p) override { FixHandle(p); }
|
| + void VisitRootPointer(Root root, Object** p) override { FixHandle(p); }
|
|
|
| - void VisitPointers(Object** start, Object** end) override {
|
| + void VisitRootPointers(Root root, Object** start, Object** end) override {
|
| for (Object** p = start; p < end; p++) FixHandle(p);
|
| }
|
|
|
| @@ -4973,8 +4976,9 @@ class FixStaleLeftTrimmedHandlesVisitor : public ObjectVisitor {
|
| Heap* heap_;
|
| };
|
|
|
| -void Heap::IterateStrongRoots(ObjectVisitor* v, VisitMode mode) {
|
| - v->VisitPointers(&roots_[0], &roots_[kStrongRootListLength]);
|
| +void Heap::IterateStrongRoots(RootVisitor* v, VisitMode mode) {
|
| + v->VisitRootPointers(Root::kStrongRootList, &roots_[0],
|
| + &roots_[kStrongRootListLength]);
|
| v->Synchronize(VisitorSynchronization::kStrongRootList);
|
| // The serializer/deserializer iterates the root list twice, first to pick
|
| // off immortal immovable roots to make sure they end up on the first page,
|
| @@ -5044,7 +5048,7 @@ void Heap::IterateStrongRoots(ObjectVisitor* v, VisitMode mode) {
|
|
|
| // Iterate over other strong roots (currently only identity maps).
|
| for (StrongRootsList* list = strong_roots_list_; list; list = list->next) {
|
| - v->VisitPointers(list->start, list->end);
|
| + v->VisitRootPointers(Root::kStrongRoots, list->start, list->end);
|
| }
|
| v->Synchronize(VisitorSynchronization::kStrongRoots);
|
|
|
| @@ -5937,9 +5941,9 @@ void Heap::FatalProcessOutOfMemory(const char* location, bool is_heap_oom) {
|
|
|
| #ifdef DEBUG
|
|
|
| -class PrintHandleVisitor : public ObjectVisitor {
|
| +class PrintHandleVisitor : public RootVisitor {
|
| public:
|
| - void VisitPointers(Object** start, Object** end) override {
|
| + void VisitRootPointers(Root root, Object** start, Object** end) override {
|
| for (Object** p = start; p < end; p++)
|
| PrintF(" handle %p to %p\n", reinterpret_cast<void*>(p),
|
| reinterpret_cast<void*>(*p));
|
| @@ -5955,13 +5959,13 @@ void Heap::PrintHandles() {
|
|
|
| #endif
|
|
|
| -class CheckHandleCountVisitor : public ObjectVisitor {
|
| +class CheckHandleCountVisitor : public RootVisitor {
|
| public:
|
| CheckHandleCountVisitor() : handle_count_(0) {}
|
| ~CheckHandleCountVisitor() override {
|
| CHECK(handle_count_ < HandleScope::kCheckHandleThreshold);
|
| }
|
| - void VisitPointers(Object** start, Object** end) override {
|
| + void VisitRootPointers(Root root, Object** start, Object** end) override {
|
| handle_count_ += end - start;
|
| }
|
|
|
| @@ -6117,11 +6121,27 @@ class UnreachableObjectsFilter : public HeapObjectsFilter {
|
| }
|
|
|
| private:
|
| - class MarkingVisitor : public ObjectVisitor {
|
| + class MarkingVisitor : public ObjectVisitor, public RootVisitor {
|
| public:
|
| MarkingVisitor() : marking_stack_(10) {}
|
|
|
| void VisitPointers(Object** start, Object** end) override {
|
| + MarkPointers(start, end);
|
| + }
|
| +
|
| + void VisitRootPointers(Root root, Object** start, Object** end) override {
|
| + MarkPointers(start, end);
|
| + }
|
| +
|
| + void TransitiveClosure() {
|
| + while (!marking_stack_.is_empty()) {
|
| + HeapObject* obj = marking_stack_.RemoveLast();
|
| + obj->Iterate(this);
|
| + }
|
| + }
|
| +
|
| + private:
|
| + void MarkPointers(Object** start, Object** end) {
|
| for (Object** p = start; p < end; p++) {
|
| if (!(*p)->IsHeapObject()) continue;
|
| HeapObject* obj = HeapObject::cast(*p);
|
| @@ -6135,15 +6155,6 @@ class UnreachableObjectsFilter : public HeapObjectsFilter {
|
| }
|
| }
|
| }
|
| -
|
| - void TransitiveClosure() {
|
| - while (!marking_stack_.is_empty()) {
|
| - HeapObject* obj = marking_stack_.RemoveLast();
|
| - obj->Iterate(this);
|
| - }
|
| - }
|
| -
|
| - private:
|
| List<HeapObject*> marking_stack_;
|
| };
|
|
|
|
|