diff options
Diffstat (limited to 'deps/v8/src/heap/remembered-set.h')
-rw-r--r-- | deps/v8/src/heap/remembered-set.h | 131 |
1 files changed, 62 insertions, 69 deletions
diff --git a/deps/v8/src/heap/remembered-set.h b/deps/v8/src/heap/remembered-set.h index e59457b10d..b6b442b56e 100644 --- a/deps/v8/src/heap/remembered-set.h +++ b/deps/v8/src/heap/remembered-set.h @@ -116,7 +116,7 @@ class RememberedSet : public AllStatic { // The callback should take (MemoryChunk* chunk) and return void. template <typename Callback> static void IterateMemoryChunks(Heap* heap, Callback callback) { - MemoryChunkIterator it(heap); + OldGenerationMemoryChunkIterator it(heap); MemoryChunk* chunk; while ((chunk = it.next()) != nullptr) { SlotSet* slots = chunk->slot_set<type>(); @@ -190,21 +190,21 @@ class RememberedSet : public AllStatic { // Given a page and a typed slot in that page, this function adds the slot // to the remembered set. - static void InsertTyped(Page* page, Address host_addr, SlotType slot_type, - Address slot_addr) { + static void InsertTyped(MemoryChunk* memory_chunk, SlotType slot_type, + uint32_t offset) { + TypedSlotSet* slot_set = memory_chunk->typed_slot_set<type>(); + if (slot_set == nullptr) { + slot_set = memory_chunk->AllocateTypedSlotSet<type>(); + } + slot_set->Insert(slot_type, offset); + } + + static void MergeTyped(MemoryChunk* page, std::unique_ptr<TypedSlots> slots) { TypedSlotSet* slot_set = page->typed_slot_set<type>(); if (slot_set == nullptr) { slot_set = page->AllocateTypedSlotSet<type>(); } - if (host_addr == kNullAddress) { - host_addr = page->address(); - } - uintptr_t offset = slot_addr - page->address(); - uintptr_t host_offset = host_addr - page->address(); - DCHECK_LT(offset, static_cast<uintptr_t>(TypedSlotSet::kMaxOffset)); - DCHECK_LT(host_offset, static_cast<uintptr_t>(TypedSlotSet::kMaxOffset)); - slot_set->Insert(slot_type, static_cast<uint32_t>(host_offset), - static_cast<uint32_t>(offset)); + slot_set->Merge(slots.get()); } // Given a page and a range of typed slots in that page, this function removes @@ -213,8 +213,7 @@ class RememberedSet : public AllStatic { TypedSlotSet* slots = page->typed_slot_set<type>(); if (slots != nullptr) { slots->Iterate( - [start, end](SlotType slot_type, Address host_addr, - Address slot_addr) { + [=](SlotType slot_type, Address slot_addr) { return start <= slot_addr && slot_addr < end ? REMOVE_SLOT : KEEP_SLOT; }, @@ -223,7 +222,7 @@ class RememberedSet : public AllStatic { } // Iterates and filters the remembered set with the given callback. - // The callback should take (SlotType slot_type, SlotAddress slot) and return + // The callback should take (SlotType slot_type, Address addr) and return // SlotCallbackResult. template <typename Callback> static void IterateTyped(Heap* heap, RememberedSetIterationMode mode, @@ -237,7 +236,7 @@ class RememberedSet : public AllStatic { // Iterates and filters typed old to old pointers in the given memory chunk // with the given callback. The callback should take (SlotType slot_type, - // Address slot_addr) and return SlotCallbackResult. + // Address addr) and return SlotCallbackResult. template <typename Callback> static void IterateTyped(MemoryChunk* chunk, Callback callback) { TypedSlotSet* slots = chunk->typed_slot_set<type>(); @@ -252,7 +251,7 @@ class RememberedSet : public AllStatic { // Clear all old to old slots from the remembered set. static void ClearAll(Heap* heap) { STATIC_ASSERT(type == OLD_TO_OLD); - MemoryChunkIterator it(heap); + OldGenerationMemoryChunkIterator it(heap); MemoryChunk* chunk; while ((chunk = it.next()) != nullptr) { chunk->ReleaseSlotSet<OLD_TO_OLD>(); @@ -261,45 +260,66 @@ class RememberedSet : public AllStatic { } } - // Eliminates all stale slots from the remembered set, i.e. - // slots that are not part of live objects anymore. This method must be - // called after marking, when the whole transitive closure is known and - // must be called before sweeping when mark bits are still intact. - static void ClearInvalidTypedSlots(Heap* heap, MemoryChunk* chunk); - private: - static bool IsValidSlot(Heap* heap, MemoryChunk* chunk, Object** slot); + static bool IsValidSlot(Heap* heap, MemoryChunk* chunk, ObjectSlot slot); }; class UpdateTypedSlotHelper { public: + // Updates a typed slot using an untyped slot callback. + // The callback accepts MaybeObjectSlot and returns SlotCallbackResult. + template <typename Callback> + static SlotCallbackResult UpdateTypedSlot(Heap* heap, SlotType slot_type, + Address addr, Callback callback) { + switch (slot_type) { + case CODE_TARGET_SLOT: { + RelocInfo rinfo(addr, RelocInfo::CODE_TARGET, 0, Code()); + return UpdateCodeTarget(&rinfo, callback); + } + case CODE_ENTRY_SLOT: { + return UpdateCodeEntry(addr, callback); + } + case EMBEDDED_OBJECT_SLOT: { + RelocInfo rinfo(addr, RelocInfo::EMBEDDED_OBJECT, 0, Code()); + return UpdateEmbeddedPointer(heap, &rinfo, callback); + } + case OBJECT_SLOT: { + // TODO(ishell): the incoming addr represents MaybeObjectSlot(addr). + STATIC_ASSERT(kTaggedSize == kSystemPointerSize); + return callback(FullMaybeObjectSlot(addr)); + } + case CLEARED_SLOT: + break; + } + UNREACHABLE(); + } + + private: // Updates a code entry slot using an untyped slot callback. - // The callback accepts Object** and returns SlotCallbackResult. + // The callback accepts FullMaybeObjectSlot and returns SlotCallbackResult. template <typename Callback> static SlotCallbackResult UpdateCodeEntry(Address entry_address, Callback callback) { - Object* code = Code::GetObjectFromEntryAddress(entry_address); - Object* old_code = code; - SlotCallbackResult result = - callback(reinterpret_cast<MaybeObject**>(&code)); - DCHECK(!HasWeakHeapObjectTag(code)); + Code code = Code::GetObjectFromEntryAddress(entry_address); + Code old_code = code; + SlotCallbackResult result = callback(FullMaybeObjectSlot(&code)); + DCHECK(!HasWeakHeapObjectTag(code.ptr())); if (code != old_code) { - Memory<Address>(entry_address) = reinterpret_cast<Code*>(code)->entry(); + Memory<Address>(entry_address) = code->entry(); } return result; } // Updates a code target slot using an untyped slot callback. - // The callback accepts Object** and returns SlotCallbackResult. + // The callback accepts FullMaybeObjectSlot and returns SlotCallbackResult. template <typename Callback> static SlotCallbackResult UpdateCodeTarget(RelocInfo* rinfo, Callback callback) { DCHECK(RelocInfo::IsCodeTargetMode(rinfo->rmode())); - Code* old_target = Code::GetCodeFromTargetAddress(rinfo->target_address()); - Object* new_target = old_target; - SlotCallbackResult result = - callback(reinterpret_cast<MaybeObject**>(&new_target)); - DCHECK(!HasWeakHeapObjectTag(new_target)); + Code old_target = Code::GetCodeFromTargetAddress(rinfo->target_address()); + Code new_target = old_target; + SlotCallbackResult result = callback(FullMaybeObjectSlot(&new_target)); + DCHECK(!HasWeakHeapObjectTag(new_target.ptr())); if (new_target != old_target) { rinfo->set_target_address( Code::cast(new_target)->raw_instruction_start()); @@ -308,47 +328,20 @@ class UpdateTypedSlotHelper { } // Updates an embedded pointer slot using an untyped slot callback. - // The callback accepts Object** and returns SlotCallbackResult. + // The callback accepts FullMaybeObjectSlot and returns SlotCallbackResult. template <typename Callback> static SlotCallbackResult UpdateEmbeddedPointer(Heap* heap, RelocInfo* rinfo, Callback callback) { DCHECK(rinfo->rmode() == RelocInfo::EMBEDDED_OBJECT); - HeapObject* old_target = rinfo->target_object(); - Object* new_target = old_target; - SlotCallbackResult result = - callback(reinterpret_cast<MaybeObject**>(&new_target)); - DCHECK(!HasWeakHeapObjectTag(new_target)); + HeapObject old_target = rinfo->target_object(); + HeapObject new_target = old_target; + SlotCallbackResult result = callback(FullMaybeObjectSlot(&new_target)); + DCHECK(!HasWeakHeapObjectTag(new_target->ptr())); if (new_target != old_target) { rinfo->set_target_object(heap, HeapObject::cast(new_target)); } return result; } - - // Updates a typed slot using an untyped slot callback. - // The callback accepts MaybeObject** and returns SlotCallbackResult. - template <typename Callback> - static SlotCallbackResult UpdateTypedSlot(Heap* heap, SlotType slot_type, - Address addr, Callback callback) { - switch (slot_type) { - case CODE_TARGET_SLOT: { - RelocInfo rinfo(addr, RelocInfo::CODE_TARGET, 0, nullptr); - return UpdateCodeTarget(&rinfo, callback); - } - case CODE_ENTRY_SLOT: { - return UpdateCodeEntry(addr, callback); - } - case EMBEDDED_OBJECT_SLOT: { - RelocInfo rinfo(addr, RelocInfo::EMBEDDED_OBJECT, 0, nullptr); - return UpdateEmbeddedPointer(heap, &rinfo, callback); - } - case OBJECT_SLOT: { - return callback(reinterpret_cast<MaybeObject**>(addr)); - } - case CLEARED_SLOT: - break; - } - UNREACHABLE(); - } }; inline SlotType SlotTypeForRelocInfoMode(RelocInfo::Mode rmode) { |