Skip to content

Commit a715957

Browse files
mlippautzCommit bot
authored andcommitted
[heap] Iterate handles with special left-trim visitor
BUG=chromium:620553 LOG=N [email protected] Review-Url: https://codereview.chromium.org/2102243002 Cr-Commit-Position: refs/heads/master@{#37366}
1 parent 356a85b commit a715957

5 files changed

Lines changed: 45 additions & 35 deletions

File tree

src/heap/heap-inl.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -482,31 +482,6 @@ void Heap::CopyBlock(Address dst, Address src, int byte_size) {
482482
static_cast<size_t>(byte_size / kPointerSize));
483483
}
484484

485-
bool Heap::PurgeLeftTrimmedObject(Object** object) {
486-
HeapObject* current = reinterpret_cast<HeapObject*>(*object);
487-
const MapWord map_word = current->map_word();
488-
if (current->IsFiller() && !map_word.IsForwardingAddress()) {
489-
#ifdef DEBUG
490-
// We need to find a FixedArrayBase map after walking the fillers.
491-
while (current->IsFiller()) {
492-
Address next = reinterpret_cast<Address>(current);
493-
if (current->map() == one_pointer_filler_map()) {
494-
next += kPointerSize;
495-
} else if (current->map() == two_pointer_filler_map()) {
496-
next += 2 * kPointerSize;
497-
} else {
498-
next += current->Size();
499-
}
500-
current = reinterpret_cast<HeapObject*>(next);
501-
}
502-
DCHECK(current->IsFixedArrayBase());
503-
#endif // DEBUG
504-
*object = nullptr;
505-
return true;
506-
}
507-
return false;
508-
}
509-
510485
template <Heap::FindMementoMode mode>
511486
AllocationMemento* Heap::FindAllocationMemento(HeapObject* object) {
512487
// Check if there is potentially a memento behind the object. If

src/heap/heap.cc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4755,6 +4755,49 @@ void Heap::IterateSmiRoots(ObjectVisitor* v) {
47554755
v->Synchronize(VisitorSynchronization::kSmiRootList);
47564756
}
47574757

4758+
// We cannot avoid stale handles to left-trimmed objects, but can only make
4759+
// sure all handles still needed are updated. Filter out a stale pointer
4760+
// and clear the slot to allow post processing of handles (needed because
4761+
// the sweeper might actually free the underlying page).
4762+
class FixStaleLeftTrimmedHandlesVisitor : public ObjectVisitor {
4763+
public:
4764+
explicit FixStaleLeftTrimmedHandlesVisitor(Heap* heap) : heap_(heap) {
4765+
USE(heap_);
4766+
}
4767+
4768+
void VisitPointer(Object** p) override { FixHandle(p); }
4769+
4770+
void VisitPointers(Object** start, Object** end) override {
4771+
for (Object** p = start; p < end; p++) FixHandle(p);
4772+
}
4773+
4774+
private:
4775+
inline void FixHandle(Object** p) {
4776+
HeapObject* current = reinterpret_cast<HeapObject*>(*p);
4777+
if (!current->IsHeapObject()) return;
4778+
const MapWord map_word = current->map_word();
4779+
if (!map_word.IsForwardingAddress() && current->IsFiller()) {
4780+
#ifdef DEBUG
4781+
// We need to find a FixedArrayBase map after walking the fillers.
4782+
while (current->IsFiller()) {
4783+
Address next = reinterpret_cast<Address>(current);
4784+
if (current->map() == heap_->one_pointer_filler_map()) {
4785+
next += kPointerSize;
4786+
} else if (current->map() == heap_->two_pointer_filler_map()) {
4787+
next += 2 * kPointerSize;
4788+
} else {
4789+
next += current->Size();
4790+
}
4791+
current = reinterpret_cast<HeapObject*>(next);
4792+
}
4793+
DCHECK(current->IsFixedArrayBase());
4794+
#endif // DEBUG
4795+
*p = nullptr;
4796+
}
4797+
}
4798+
4799+
Heap* heap_;
4800+
};
47584801

47594802
void Heap::IterateStrongRoots(ObjectVisitor* v, VisitMode mode) {
47604803
v->VisitPointers(&roots_[0], &roots_[kStrongRootListLength]);
@@ -4777,6 +4820,8 @@ void Heap::IterateStrongRoots(ObjectVisitor* v, VisitMode mode) {
47774820
v->Synchronize(VisitorSynchronization::kCompilationCache);
47784821

47794822
// Iterate over local handles in handle scopes.
4823+
FixStaleLeftTrimmedHandlesVisitor left_trim_visitor(this);
4824+
isolate_->handle_scope_implementer()->Iterate(&left_trim_visitor);
47804825
isolate_->handle_scope_implementer()->Iterate(v);
47814826
isolate_->IterateDeferredHandles(v);
47824827
v->Synchronize(VisitorSynchronization::kHandleScope);

src/heap/heap.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -632,12 +632,6 @@ class Heap {
632632
// stored on the map to facilitate fast dispatch for {StaticVisitorBase}.
633633
static int GetStaticVisitorIdForMap(Map* map);
634634

635-
// We cannot avoid stale handles to left-trimmed objects, but can only make
636-
// sure all handles still needed are updated. Filter out a stale pointer
637-
// and clear the slot to allow post processing of handles (needed because
638-
// the sweeper might actually free the underlying page).
639-
inline bool PurgeLeftTrimmedObject(Object** object);
640-
641635
// Notifies the heap that is ok to start marking or other activities that
642636
// should not happen during deserialization.
643637
void NotifyDeserializationComplete();

src/heap/mark-compact.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,8 +1413,6 @@ class RootMarkingVisitor : public ObjectVisitor {
14131413

14141414
HeapObject* object = HeapObject::cast(*p);
14151415

1416-
if (collector_->heap()->PurgeLeftTrimmedObject(p)) return;
1417-
14181416
MarkBit mark_bit = Marking::MarkBitFrom(object);
14191417
if (Marking::IsBlackOrGrey(mark_bit)) return;
14201418

src/heap/scavenger.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,6 @@ void ScavengeVisitor::ScavengePointer(Object** p) {
445445
Object* object = *p;
446446
if (!heap_->InNewSpace(object)) return;
447447

448-
if (heap_->PurgeLeftTrimmedObject(p)) return;
449-
450448
Scavenger::ScavengeObject(reinterpret_cast<HeapObject**>(p),
451449
reinterpret_cast<HeapObject*>(object));
452450
}

0 commit comments

Comments
 (0)