Commit 725c163d authored by Shu-yu Guo's avatar Shu-yu Guo Committed by V8 LUCI CQ

[heap] Fix recording OLD_TO_SHARED slots of Code-embedded pointers

Code in client heaps can embed pointers to shared objects. In non-shared
GC, these pointers can be weak. During shared GC, unconditionally
consider Code-embedded client->shared pointers as strong so we don't
have to deoptimize and clear embedded objects in all client Isolates'
Code instances.

Bug: v8:13027
Change-Id: Id34d7e707153191639e8e531fc12d917b9382a26
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3739231Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81559}
parent 6db9f2ba
......@@ -1308,11 +1308,20 @@ class MarkCompactCollector::SharedHeapObjectVisitor final
void VisitCodeTarget(Code host, RelocInfo* rinfo) override {
Code target = Code::GetCodeFromTargetAddress(rinfo->target_address());
if (!target.InSharedWritableHeap()) return;
RecordRelocSlot(host, rinfo, target);
}
void VisitEmbeddedPointer(Code host, RelocInfo* rinfo) override {
HeapObject target = rinfo->target_object(cage_base());
if (!target.InSharedWritableHeap()) return;
// Treat all embedded shared pointers in client Code as strong regardless of
// weakness, because we shouldn't deoptimize and clear embedded objects in
// optimized code in client heaps during shared GC.
//
// In other words, embedded shared HeapObjects may take longer to be
// collected.
collector_->MarkRootObject(Root::kClientHeap, target);
RecordRelocSlot(host, rinfo, target);
}
......@@ -1329,16 +1338,16 @@ class MarkCompactCollector::SharedHeapObjectVisitor final
V8_INLINE void RecordRelocSlot(Code host, RelocInfo* rinfo,
HeapObject target) {
if (ShouldRecordRelocSlot(host, rinfo, target)) {
RecordRelocSlotInfo info = ProcessRelocInfo(host, rinfo, target);
RememberedSet<OLD_TO_SHARED>::InsertTyped(info.memory_chunk,
info.slot_type, info.offset);
}
}
V8_INLINE bool ShouldRecordRelocSlot(Code host, RelocInfo* rinfo,
HeapObject target) {
return BasicMemoryChunk::FromHeapObject(target)->InSharedHeap();
DCHECK(target.InSharedWritableHeap());
RecordRelocSlotInfo info = ProcessRelocInfo(host, rinfo, target);
// Access to TypeSlots need to be protected, since LocalHeaps might
// publish code in the background thread.
base::Optional<base::MutexGuard> opt_guard;
if (FLAG_concurrent_sparkplug) {
opt_guard.emplace(info.memory_chunk->mutex());
}
RememberedSet<OLD_TO_SHARED>::InsertTyped(info.memory_chunk, info.slot_type,
info.offset);
}
MarkCompactCollector* const collector_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment