Commit fda8b057 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

cppgc: Remove object during sweep

The dummy sweeping algorithm didn't actually remove objects from the
internal list.

Bug: chromium:1056170
Change-Id: I29a93a2ac7fc36ca95125805076ff5ce257de8a4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2138433
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarAnton Bikineev <bikineev@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67033}
parent 79249d3d
......@@ -50,20 +50,22 @@ Heap::Heap()
: stack_(std::make_unique<Stack>(v8::base::Stack::GetStackStart())) {}
void Heap::CollectGarbage(GCConfig config) {
current_config_ = config;
// TODO(chromium:1056170): Replace with proper mark-sweep algorithm.
// "Marking".
if (NeedsConservativeStackScan(current_config_)) {
if (NeedsConservativeStackScan(config)) {
StackMarker marker(objects_);
stack_->IteratePointers(&marker);
}
// "Sweeping and finalization".
for (HeapObjectHeader* header : objects_) {
for (auto it = objects_.begin(); it != objects_.end();) {
HeapObjectHeader* header = *it;
if (header->IsMarked()) {
header->Unmark();
++it;
} else {
header->Finalize();
free(header);
it = objects_.erase(it);
}
}
}
......
......@@ -40,8 +40,6 @@ class V8_EXPORT_PRIVATE Heap final : public cppgc::Heap {
void CollectGarbage(GCConfig config = GCConfig::Default());
private:
GCConfig current_config_;
std::unique_ptr<Stack> stack_;
std::vector<HeapObjectHeader*> objects_;
};
......
......@@ -39,21 +39,25 @@ size_t Foo::destructor_callcount;
} // namespace
TEST_F(GCHeapTest, PreciseGCReclaimsObjectOnStack) {
Foo* volatile do_not_acces = MakeGarbageCollected<Foo>(GetHeap());
USE(do_not_acces);
Foo* volatile do_not_access = MakeGarbageCollected<Foo>(GetHeap());
USE(do_not_access);
EXPECT_EQ(0u, Foo::destructor_callcount);
PreciseGC();
EXPECT_EQ(1u, Foo::destructor_callcount);
PreciseGC();
EXPECT_EQ(1u, Foo::destructor_callcount);
}
TEST_F(GCHeapTest, ConservaitveGCRetainsObjectOnStack) {
Foo* volatile do_not_acces = MakeGarbageCollected<Foo>(GetHeap());
USE(do_not_acces);
Foo* volatile do_not_access = MakeGarbageCollected<Foo>(GetHeap());
USE(do_not_access);
EXPECT_EQ(0u, Foo::destructor_callcount);
ConservativeGC();
EXPECT_EQ(0u, Foo::destructor_callcount);
PreciseGC();
EXPECT_EQ(1u, Foo::destructor_callcount);
PreciseGC();
EXPECT_EQ(1u, Foo::destructor_callcount);
}
} // namespace internal
......
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