Commit 2f5ba83b authored by mlippautz's avatar mlippautz Committed by Commit bot

[heap] Simulate aborting compaction during --stress-compaction

How to trigger (stress bots do all steps):
1. Enable in gyp/gn: v8_enable_verify_heap
2. Start with --stress-compaction and non-zero --random-seed

R=ulan@chromium.org, hpayer@chromium.org
BUG=
CQ_EXTRA_TRYBOTS=tryserver.v8:v8_linux_arm64_gc_stress_dbg,v8_linux_gc_stress_dbg,v8_mac_gc_stress_dbg

Review-Url: https://codereview.chromium.org/2019343002
Cr-Commit-Position: refs/heads/master@{#36619}
parent 3d25ad4d
......@@ -1641,6 +1641,9 @@ class MarkCompactCollector::EvacuateVisitorBase
inline bool TryEvacuateObject(PagedSpace* target_space, HeapObject* object,
HeapObject** target_object) {
#ifdef VERIFY_HEAP
if (AbortCompactionForTesting(object)) return false;
#endif // VERIFY_HEAP
int size = object->Size();
AllocationAlignment alignment = object->RequiredAlignment();
AllocationResult allocation = target_space->AllocateRaw(size, alignment);
......@@ -1698,6 +1701,26 @@ class MarkCompactCollector::EvacuateVisitorBase
Memory::Address_at(src_addr) = dst_addr;
}
#ifdef VERIFY_HEAP
bool AbortCompactionForTesting(HeapObject* object) {
if (FLAG_stress_compaction) {
const uintptr_t mask = static_cast<uintptr_t>(FLAG_random_seed) &
Page::kPageAlignmentMask & ~kPointerAlignmentMask;
if ((reinterpret_cast<uintptr_t>(object->address()) &
Page::kPageAlignmentMask) == mask) {
Page* page = Page::FromAddress(object->address());
if (page->IsFlagSet(Page::COMPACTION_WAS_ABORTED_FOR_TESTING)) {
page->ClearFlag(Page::COMPACTION_WAS_ABORTED_FOR_TESTING);
} else {
page->SetFlag(Page::COMPACTION_WAS_ABORTED_FOR_TESTING);
return true;
}
}
}
return false;
}
#endif // VERIFY_HEAP
Heap* heap_;
CompactionSpaceCollection* compaction_spaces_;
bool profiling_;
......
......@@ -450,6 +450,11 @@ class MemoryChunk {
// has been aborted and needs special handling by the sweeper.
COMPACTION_WAS_ABORTED,
// |COMPACTION_WAS_ABORTED_FOR_TESTING|: During stress testing evacuation
// on pages is sometimes aborted. The flag is used to avoid repeatedly
// triggering on the same page.
COMPACTION_WAS_ABORTED_FOR_TESTING,
// |ANCHOR|: Flag is set if page is an anchor.
ANCHOR,
......
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