blob: 403c99b05712ec53d2920b40e5ee6ff9e3a2f84c [file] [log] [blame]
Ben Murdoch097c5b22016-05-18 11:27:45 +01001// 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#include "src/heap/remembered-set.h"
6#include "src/heap/heap-inl.h"
7#include "src/heap/heap.h"
8#include "src/heap/mark-compact.h"
9#include "src/heap/slot-set.h"
10#include "src/heap/spaces.h"
11#include "src/heap/store-buffer.h"
12
13namespace v8 {
14namespace internal {
15
16template <PointerDirection direction>
17void RememberedSet<direction>::ClearInvalidSlots(Heap* heap) {
18 STATIC_ASSERT(direction == OLD_TO_NEW);
19 PageIterator it(heap->old_space());
20 MemoryChunk* chunk;
21 while (it.has_next()) {
22 chunk = it.next();
23 SlotSet* slots = GetSlotSet(chunk);
24 if (slots != nullptr) {
Ben Murdochda12d292016-06-02 14:46:10 +010025 slots->Iterate([heap, chunk](Address addr) {
Ben Murdoch097c5b22016-05-18 11:27:45 +010026 Object** slot = reinterpret_cast<Object**>(addr);
Ben Murdochda12d292016-06-02 14:46:10 +010027 return IsValidSlot(heap, chunk, slot) ? KEEP_SLOT : REMOVE_SLOT;
Ben Murdoch097c5b22016-05-18 11:27:45 +010028 });
29 }
30 }
31}
32
33template <PointerDirection direction>
34void RememberedSet<direction>::VerifyValidSlots(Heap* heap) {
Ben Murdoch097c5b22016-05-18 11:27:45 +010035 Iterate(heap, [heap](Address addr) {
Ben Murdochda12d292016-06-02 14:46:10 +010036 HeapObject* obj =
37 heap->mark_compact_collector()->FindBlackObjectBySlotSlow(addr);
38 if (obj == nullptr) {
39 // The slot is in dead object.
40 MemoryChunk* chunk = MemoryChunk::FromAnyPointerAddress(heap, addr);
41 AllocationSpace owner = chunk->owner()->identity();
42 // The old to old remembered set should not have dead slots.
43 CHECK_NE(direction, OLD_TO_OLD);
44 // The old to new remembered set is allowed to have slots in dead
45 // objects only in map and large object space because these space
46 // cannot have raw untagged pointers.
47 CHECK(owner == MAP_SPACE || owner == LO_SPACE);
48 } else {
49 int offset = static_cast<int>(addr - obj->address());
50 CHECK(obj->IsValidSlot(offset));
Ben Murdoch097c5b22016-05-18 11:27:45 +010051 }
Ben Murdochda12d292016-06-02 14:46:10 +010052 return KEEP_SLOT;
Ben Murdoch097c5b22016-05-18 11:27:45 +010053 });
54}
55
56template <PointerDirection direction>
Ben Murdochda12d292016-06-02 14:46:10 +010057bool RememberedSet<direction>::IsValidSlot(Heap* heap, MemoryChunk* chunk,
58 Object** slot) {
Ben Murdoch097c5b22016-05-18 11:27:45 +010059 STATIC_ASSERT(direction == OLD_TO_NEW);
60 Object* object = *slot;
61 if (!heap->InNewSpace(object)) {
62 return false;
63 }
64 HeapObject* heap_object = HeapObject::cast(object);
65 // If the target object is not black, the source slot must be part
66 // of a non-black (dead) object.
67 return Marking::IsBlack(Marking::MarkBitFrom(heap_object)) &&
Ben Murdochda12d292016-06-02 14:46:10 +010068 heap->mark_compact_collector()->IsSlotInBlackObject(
69 chunk, reinterpret_cast<Address>(slot));
Ben Murdoch097c5b22016-05-18 11:27:45 +010070}
71
72template void RememberedSet<OLD_TO_NEW>::ClearInvalidSlots(Heap* heap);
73template void RememberedSet<OLD_TO_NEW>::VerifyValidSlots(Heap* heap);
Ben Murdochda12d292016-06-02 14:46:10 +010074template void RememberedSet<OLD_TO_OLD>::VerifyValidSlots(Heap* heap);
Ben Murdoch097c5b22016-05-18 11:27:45 +010075
76} // namespace internal
77} // namespace v8