Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Unified Diff: src/heap/mark-compact.cc

Issue 2045263002: [heap] Avoid the use of cells to point from code to new-space objects. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/heap/mark-compact.cc
diff --git a/src/heap/mark-compact.cc b/src/heap/mark-compact.cc
index 5c2c012f04f7d32386eb085405d1185a8e8e9df0..d5983431b311b344ec2250de3c83c69fb878e626 100644
--- a/src/heap/mark-compact.cc
+++ b/src/heap/mark-compact.cc
@@ -1563,6 +1563,7 @@ class RecordMigratedSlotVisitor final : public ObjectVisitor {
DCHECK(RelocInfo::IsCodeTarget(rinfo->rmode()));
Code* target = Code::GetCodeFromTargetAddress(rinfo->target_address());
Code* host = rinfo->host();
+ collector_->RecordRelocSlotToNewSpace(host, rinfo, target);
collector_->RecordRelocSlot(host, rinfo, target);
}
@@ -1571,6 +1572,7 @@ class RecordMigratedSlotVisitor final : public ObjectVisitor {
rinfo->IsPatchedDebugBreakSlotSequence());
Code* target = Code::GetCodeFromTargetAddress(rinfo->debug_call_address());
Code* host = rinfo->host();
+ collector_->RecordRelocSlotToNewSpace(host, rinfo, target);
collector_->RecordRelocSlot(host, rinfo, target);
}
@@ -1578,6 +1580,7 @@ class RecordMigratedSlotVisitor final : public ObjectVisitor {
DCHECK(rinfo->rmode() == RelocInfo::EMBEDDED_OBJECT);
HeapObject* object = HeapObject::cast(rinfo->target_object());
Code* host = rinfo->host();
+ collector_->RecordRelocSlotToNewSpace(host, rinfo, object);
collector_->RecordRelocSlot(host, rinfo, object);
}
@@ -1585,6 +1588,7 @@ class RecordMigratedSlotVisitor final : public ObjectVisitor {
DCHECK(rinfo->rmode() == RelocInfo::CELL);
Cell* cell = rinfo->target_cell();
Code* host = rinfo->host();
+ collector_->RecordRelocSlotToNewSpace(host, rinfo, cell);
collector_->RecordRelocSlot(host, rinfo, cell);
}
@@ -2448,6 +2452,33 @@ void MarkCompactCollector::MarkDependentCodeForDeoptimization(
current = current->next_link();
}
+ {
+ ArrayList* list = heap_->weak_code_to_new_space_ref_list();
+ int counter = 0;
+ for (int i = 0; i < list->Length(); i += 2) {
+ WeakCell* obj = WeakCell::cast(list->Get(i));
+ WeakCell* dep = WeakCell::cast(list->Get(i + 1));
+ if (obj->cleared() || dep->cleared()) {
+ if (!dep->cleared()) {
+ Code* code = Code::cast(dep->value());
+ if (!code->marked_for_deoptimization()) {
+ DependentCode::SetMarkedForDeoptimization(
+ code, DependentCode::DependencyGroup::kWeakCodeGroup);
+ code->InvalidateEmbeddedObjects();
+ have_code_to_deoptimize_ = true;
+ }
+ }
+ } else {
+ list->Set(counter, obj, SKIP_WRITE_BARRIER);
+ RecordSlot(list, list->Slot(counter), obj);
+ counter++;
+ list->Set(counter, dep, SKIP_WRITE_BARRIER);
+ RecordSlot(list, list->Slot(counter), dep);
+ counter++;
+ }
+ }
+ }
+
WeakHashTable* table = heap_->weak_object_to_code_table();
uint32_t capacity = table->Capacity();
for (uint32_t i = 0; i < capacity; i++) {
@@ -2806,6 +2837,37 @@ static inline SlotType SlotTypeForRMode(RelocInfo::Mode rmode) {
return NUMBER_OF_SLOT_TYPES;
}
+namespace {
+void GetAddressAndSlotType(RelocInfo::Mode rmode, RelocInfo* rinfo,
+ Address& addr, SlotType& slot_type) {
+ addr = rinfo->pc();
+ slot_type = SlotTypeForRMode(rmode);
+ if (rinfo->IsInConstantPool()) {
+ addr = rinfo->constant_pool_entry_address();
+ if (RelocInfo::IsCodeTarget(rmode)) {
+ slot_type = CODE_ENTRY_SLOT;
+ } else {
+ DCHECK(RelocInfo::IsEmbeddedObject(rmode));
+ slot_type = OBJECT_SLOT;
+ }
+ }
+}
+} // namespace
+
+void MarkCompactCollector::RecordRelocSlotToNewSpace(Code* host,
+ RelocInfo* rinfo,
+ Object* target) {
+ Page* source_page = Page::FromAddress(reinterpret_cast<Address>(host));
+ RelocInfo::Mode rmode = rinfo->rmode();
+ if (heap()->InNewSpace(target)) {
+ Address addr;
+ SlotType slot_type;
+ GetAddressAndSlotType(rmode, rinfo, addr, slot_type);
+ RememberedSet<OLD_TO_NEW>::InsertTyped(
+ source_page, reinterpret_cast<Address>(host), slot_type, addr);
+ }
+}
+
void MarkCompactCollector::RecordRelocSlot(Code* host, RelocInfo* rinfo,
Object* target) {
Page* target_page = Page::FromAddress(reinterpret_cast<Address>(target));
@@ -2814,17 +2876,9 @@ void MarkCompactCollector::RecordRelocSlot(Code* host, RelocInfo* rinfo,
if (target_page->IsEvacuationCandidate() &&
(rinfo->host() == NULL ||
!ShouldSkipEvacuationSlotRecording(rinfo->host()))) {
- Address addr = rinfo->pc();
- SlotType slot_type = SlotTypeForRMode(rmode);
- if (rinfo->IsInConstantPool()) {
- addr = rinfo->constant_pool_entry_address();
- if (RelocInfo::IsCodeTarget(rmode)) {
- slot_type = CODE_ENTRY_SLOT;
- } else {
- DCHECK(RelocInfo::IsEmbeddedObject(rmode));
- slot_type = OBJECT_SLOT;
- }
- }
+ Address addr;
+ SlotType slot_type;
+ GetAddressAndSlotType(rmode, rinfo, addr, slot_type);
RememberedSet<OLD_TO_OLD>::InsertTyped(
source_page, reinterpret_cast<Address>(host), slot_type, addr);
}
@@ -3432,6 +3486,12 @@ int MarkCompactCollector::Sweeper::RawSweep(PagedSpace* space, Page* p,
}
void MarkCompactCollector::InvalidateCode(Code* code) {
+ Page* page = Page::FromAddress(code->address());
+ Address start = code->instruction_start();
+ Address end = code->address() + code->Size();
+
+ RememberedSet<OLD_TO_NEW>::RemoveRangeTyped(page, start, end);
+
if (heap_->incremental_marking()->IsCompacting() &&
!ShouldSkipEvacuationSlotRecording(code)) {
DCHECK(compacting_);
@@ -3443,11 +3503,7 @@ void MarkCompactCollector::InvalidateCode(Code* code) {
// Ignore all slots that might have been recorded in the body of the
// deoptimized code object. Assumption: no slots will be recorded for
// this object after invalidating it.
- Page* page = Page::FromAddress(code->address());
- Address start = code->instruction_start();
- Address end = code->address() + code->Size();
RememberedSet<OLD_TO_OLD>::RemoveRangeTyped(page, start, end);
- RememberedSet<OLD_TO_NEW>::RemoveRangeTyped(page, start, end);
}
}
@@ -3993,6 +4049,7 @@ void MarkCompactCollector::RecordCodeTargetPatch(Address pc, Code* target) {
MarkBit mark_bit = Marking::MarkBitFrom(host);
if (Marking::IsBlack(mark_bit)) {
RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host);
+ RecordRelocSlotToNewSpace(host, &rinfo, target);
RecordRelocSlot(host, &rinfo, target);
}
}

Powered by Google App Engine
This is Rietveld 408576698