Commit 0787194d authored by Keishi Hattori's avatar Keishi Hattori Committed by Commit Bot

Oilpan: Add Unit Tests in HeapCompaction for IncrementalMarking

This CLs added 3 unit tests in HeapCompaction for IncrementalMarking.
One of tests checks that slots is collected if the slot content is nullptr of inline buffer.
Another case checks whether compaction is correctly working if collected slot is dropped references.
Moreover, we check whether compaction is correctly working if collected slot is destructed by mutator.

Bug: 864425
Change-Id: I3038c9a6e2607f3ed81a5f438a1ab415fa96df9a
Reviewed-on: https://chromium-review.googlesource.com/1152750
Commit-Queue: Keishi Hattori <keishi@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarKeishi Hattori <keishi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582313}
parent 3963b98d
......@@ -331,12 +331,6 @@ bool HeapCompact::ShouldCompact(ThreadHeap* heap,
<< " count=" << gc_count_since_last_compaction_
<< " free=" << free_list_size_;
gc_count_since_last_compaction_++;
// It is only safe to compact during non-conservative GCs.
// TODO: for the main thread, limit this further to only idle GCs.
if (reason != BlinkGC::GCReason::kIdleGC &&
reason != BlinkGC::GCReason::kPreciseGC &&
reason != BlinkGC::GCReason::kForcedGC)
return false;
// If the GCing thread requires a stack scan, do not compact.
// Why? Should the stack contain an iterator pointing into its
......@@ -345,10 +339,22 @@ bool HeapCompact::ShouldCompact(ThreadHeap* heap,
if (stack_state == BlinkGC::kHeapPointersOnStack)
return false;
if (reason == BlinkGC::GCReason::kTesting) {
UpdateHeapResidency();
return force_compaction_gc_;
}
// TODO(keishi): Should be enable after fixing the crashes.
if (marking_type == BlinkGC::kIncrementalMarking)
return false;
// TODO(harukamt): Add kIncrementalIdleGC and kIncrementalV8FollowupGC when we
// enable heap compaction for incremental marking.
if (reason != BlinkGC::GCReason::kIdleGC &&
reason != BlinkGC::GCReason::kPreciseGC &&
reason != BlinkGC::GCReason::kForcedGC)
return false;
// Compaction enable rules:
// - It's been a while since the last time.
// - "Considerable" amount of heap memory is bound up in freelist
......
......@@ -36,12 +36,18 @@
namespace blink {
namespace incremental_marking_test {
class IncrementalMarkingTestDriver;
}
class NormalPageArena;
class BasePage;
class ThreadState;
class ThreadHeap;
class PLATFORM_EXPORT HeapCompact final {
friend class incremental_marking_test::IncrementalMarkingTestDriver;
public:
static std::unique_ptr<HeapCompact> Create(ThreadHeap* heap) {
return base::WrapUnique(new HeapCompact(heap));
......
......@@ -10,6 +10,7 @@
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/heap/heap_allocator.h"
#include "third_party/blink/renderer/platform/heap/heap_buildflags.h"
#include "third_party/blink/renderer/platform/heap/heap_compact.h"
#include "third_party/blink/renderer/platform/heap/heap_terminated_array.h"
#include "third_party/blink/renderer/platform/heap/heap_terminated_array_builder.h"
#include "third_party/blink/renderer/platform/heap/member.h"
......@@ -1630,6 +1631,11 @@ class IncrementalMarkingTestDriver {
thread_state_->CompleteSweep();
}
HashSet<MovableReference*>& GetTracedSlot() {
HeapCompact* compaction = ThreadState::Current()->Heap().Compaction();
return compaction->traced_slots_;
}
private:
ThreadState* const thread_state_;
};
......@@ -1717,6 +1723,82 @@ TEST(IncrementalMarkingTest, NoBackingFreeDuringIncrementalMarking) {
driver.FinishGC();
}
TEST(IncrementalMarkingTest, DropReferenceWithHeapCompaction) {
using Store = HeapHashCountedSet<Member<Object>>;
Persistent<Store> persistent(new Store);
persistent->insert(Object::Create());
IncrementalMarkingTestDriver driver(ThreadState::Current());
HeapCompact::ScheduleCompactionGCForTesting(true);
driver.Start();
driver.FinishSteps();
persistent->clear();
// Registration of movable and updatable references should not crash because
// if a slot have nullptr reference, it doesn't call registeration method.
driver.FinishGC();
}
TEST(IncrementalMarkingTest, HasInlineCapacityCollectionWithHeapCompaction) {
using Store = HeapVector<Member<Object>, 2>;
Persistent<Store> persistent(new Store);
Persistent<Store> persistent2(new Store);
IncrementalMarkingTestDriver driver(ThreadState::Current());
HeapCompact::ScheduleCompactionGCForTesting(true);
persistent->push_back(Object::Create());
driver.Start();
driver.FinishSteps();
// Should collect also slots that has only inline buffer and nullptr
// references.
EXPECT_EQ(driver.GetTracedSlot().size(), 2u);
driver.FinishGC();
}
TEST(IncrementalMarkingTest, SlotDestruction) {
IncrementalMarkingTestDriver driver(ThreadState::Current());
HeapCompact::ScheduleCompactionGCForTesting(true);
Vector<MovableReference*> ref(7);
{
Object* obj = Object::Create();
PersistentHeapHashSet<Member<Object>> p_hashset;
PersistentHeapHashMap<Member<Object>, Member<Object>> p_hashmap;
PersistentHeapLinkedHashSet<Member<Object>> p_linkedhashset;
PersistentHeapListHashSet<Member<Object>> p_listhashset;
PersistentHeapHashCountedSet<Member<Object>> p_hashcountedset;
PersistentHeapVector<Member<Object>> p_vector;
PersistentHeapDeque<Member<Object>> p_deque;
p_hashset.insert(obj);
p_hashmap.insert(obj, obj);
p_linkedhashset.insert(obj);
p_listhashset.insert(obj);
p_hashcountedset.insert(obj);
p_vector.push_back(obj);
p_deque.push_back(obj);
ref[0] = reinterpret_cast<MovableReference*>(&p_hashset);
ref[1] = reinterpret_cast<MovableReference*>(&p_hashmap);
ref[2] = reinterpret_cast<MovableReference*>(&p_linkedhashset);
ref[3] = reinterpret_cast<MovableReference*>(&p_listhashset);
ref[4] = reinterpret_cast<MovableReference*>(&p_hashcountedset);
ref[5] = reinterpret_cast<MovableReference*>(&p_vector);
ref[6] = reinterpret_cast<MovableReference*>(&p_deque);
driver.Start();
driver.FinishSteps();
for (size_t i = 0; i < ref.size(); ++i) {
EXPECT_TRUE(driver.GetTracedSlot().Contains(ref[i]));
}
}
for (size_t i = 0; i < ref.size(); ++i) {
EXPECT_FALSE(driver.GetTracedSlot().Contains(ref[i]));
}
}
} // namespace incremental_marking_test
} // namespace blink
......
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