Skip to content

Commit d800a65

Browse files
mlippautzCommit bot
authored andcommitted
[heap] Filter out stale left-trimmed handles
BUG=chromium:620553 LOG=N [email protected] Review-Url: https://codereview.chromium.org/2078403002 Cr-Commit-Position: refs/heads/master@{#37108}
1 parent 9611a4d commit d800a65

4 files changed

Lines changed: 44 additions & 34 deletions

File tree

src/heap/heap.cc

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3162,10 +3162,6 @@ FixedArrayBase* Heap::LeftTrimFixedArray(FixedArrayBase* object,
31623162
DCHECK(!lo_space()->Contains(object));
31633163
DCHECK(object->map() != fixed_cow_array_map());
31643164

3165-
// Ensure that the no handle-scope has more than one pointer to the same
3166-
// backing-store.
3167-
SLOW_DCHECK(CountHandlesForObject(object) <= 1);
3168-
31693165
STATIC_ASSERT(FixedArrayBase::kMapOffset == 0);
31703166
STATIC_ASSERT(FixedArrayBase::kLengthOffset == kPointerSize);
31713167
STATIC_ASSERT(FixedArrayBase::kHeaderSize == 2 * kPointerSize);
@@ -5672,32 +5668,6 @@ void Heap::PrintHandles() {
56725668

56735669
#endif
56745670

5675-
#ifdef ENABLE_SLOW_DCHECKS
5676-
5677-
class CountHandleVisitor : public ObjectVisitor {
5678-
public:
5679-
explicit CountHandleVisitor(Object* object) : object_(object) {}
5680-
5681-
void VisitPointers(Object** start, Object** end) override {
5682-
for (Object** p = start; p < end; p++) {
5683-
if (object_ == reinterpret_cast<Object*>(*p)) count_++;
5684-
}
5685-
}
5686-
5687-
int count() { return count_; }
5688-
5689-
private:
5690-
Object* object_;
5691-
int count_ = 0;
5692-
};
5693-
5694-
int Heap::CountHandlesForObject(Object* object) {
5695-
CountHandleVisitor v(object);
5696-
isolate_->handle_scope_implementer()->Iterate(&v);
5697-
return v.count();
5698-
}
5699-
#endif
5700-
57015671
class CheckHandleCountVisitor : public ObjectVisitor {
57025672
public:
57035673
CheckHandleCountVisitor() : handle_count_(0) {}

src/heap/heap.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,9 +1411,6 @@ class Heap {
14111411
void ReportHeapStatistics(const char* title);
14121412
void ReportCodeStatistics(const char* title);
14131413
#endif
1414-
#ifdef ENABLE_SLOW_DCHECKS
1415-
int CountHandlesForObject(Object* object);
1416-
#endif
14171414

14181415
private:
14191416
class PretenuringScope;

src/heap/mark-compact.cc

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1433,8 +1433,34 @@ class RootMarkingVisitor : public ObjectVisitor {
14331433
void MarkObjectByPointer(Object** p) {
14341434
if (!(*p)->IsHeapObject()) return;
14351435

1436-
// Replace flat cons strings in place.
14371436
HeapObject* object = HeapObject::cast(*p);
1437+
1438+
// We cannot avoid stale handles to left-trimmed objects, but can only make
1439+
// sure all handles still needed are updated. Filter out any stale pointers
1440+
// and clear the slot to allow post processing of handles (needed because
1441+
// the sweeper might actually free the underlying page).
1442+
if (object->IsFiller()) {
1443+
#ifdef DEBUG
1444+
// We need to find a FixedArrayBase map after walking the fillers.
1445+
Heap* heap = collector_->heap();
1446+
HeapObject* current = object;
1447+
while (current->IsFiller()) {
1448+
Address next = reinterpret_cast<Address>(current);
1449+
if (current->map() == heap->one_pointer_filler_map()) {
1450+
next += kPointerSize;
1451+
} else if (current->map() == heap->two_pointer_filler_map()) {
1452+
next += 2 * kPointerSize;
1453+
} else {
1454+
next += current->Size();
1455+
}
1456+
current = reinterpret_cast<HeapObject*>(next);
1457+
}
1458+
DCHECK(current->IsFixedArrayBase());
1459+
#endif // DEBUG
1460+
*p = nullptr;
1461+
return;
1462+
}
1463+
14381464
MarkBit mark_bit = Marking::MarkBitFrom(object);
14391465
if (Marking::IsBlackOrGrey(mark_bit)) return;
14401466

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
// Flags: --expose-gc
6+
7+
var o0 = [];
8+
var o1 = [];
9+
var cnt = 0;
10+
o1.__defineGetter__(0, function() {
11+
if (cnt++ > 2) return;
12+
o0.shift();
13+
gc();
14+
o0.push(0);
15+
o0.concat(o1);
16+
});
17+
o1[0];

0 commit comments

Comments
 (0)