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() ...@@ -50,20 +50,22 @@ Heap::Heap()
: stack_(std::make_unique<Stack>(v8::base::Stack::GetStackStart())) {} : stack_(std::make_unique<Stack>(v8::base::Stack::GetStackStart())) {}
void Heap::CollectGarbage(GCConfig config) { void Heap::CollectGarbage(GCConfig config) {
current_config_ = config;
// TODO(chromium:1056170): Replace with proper mark-sweep algorithm. // TODO(chromium:1056170): Replace with proper mark-sweep algorithm.
// "Marking". // "Marking".
if (NeedsConservativeStackScan(current_config_)) { if (NeedsConservativeStackScan(config)) {
StackMarker marker(objects_); StackMarker marker(objects_);
stack_->IteratePointers(&marker); stack_->IteratePointers(&marker);
} }
// "Sweeping and finalization". // "Sweeping and finalization".
for (HeapObjectHeader* header : objects_) { for (auto it = objects_.begin(); it != objects_.end();) {
HeapObjectHeader* header = *it;
if (header->IsMarked()) { if (header->IsMarked()) {
header->Unmark(); header->Unmark();
++it;
} else { } else {
header->Finalize(); header->Finalize();
free(header); free(header);
it = objects_.erase(it);
} }
} }
} }
......
...@@ -40,8 +40,6 @@ class V8_EXPORT_PRIVATE Heap final : public cppgc::Heap { ...@@ -40,8 +40,6 @@ class V8_EXPORT_PRIVATE Heap final : public cppgc::Heap {
void CollectGarbage(GCConfig config = GCConfig::Default()); void CollectGarbage(GCConfig config = GCConfig::Default());
private: private:
GCConfig current_config_;
std::unique_ptr<Stack> stack_; std::unique_ptr<Stack> stack_;
std::vector<HeapObjectHeader*> objects_; std::vector<HeapObjectHeader*> objects_;
}; };
......
...@@ -39,21 +39,25 @@ size_t Foo::destructor_callcount; ...@@ -39,21 +39,25 @@ size_t Foo::destructor_callcount;
} // namespace } // namespace
TEST_F(GCHeapTest, PreciseGCReclaimsObjectOnStack) { TEST_F(GCHeapTest, PreciseGCReclaimsObjectOnStack) {
Foo* volatile do_not_acces = MakeGarbageCollected<Foo>(GetHeap()); Foo* volatile do_not_access = MakeGarbageCollected<Foo>(GetHeap());
USE(do_not_acces); USE(do_not_access);
EXPECT_EQ(0u, Foo::destructor_callcount); EXPECT_EQ(0u, Foo::destructor_callcount);
PreciseGC(); PreciseGC();
EXPECT_EQ(1u, Foo::destructor_callcount); EXPECT_EQ(1u, Foo::destructor_callcount);
PreciseGC();
EXPECT_EQ(1u, Foo::destructor_callcount);
} }
TEST_F(GCHeapTest, ConservaitveGCRetainsObjectOnStack) { TEST_F(GCHeapTest, ConservaitveGCRetainsObjectOnStack) {
Foo* volatile do_not_acces = MakeGarbageCollected<Foo>(GetHeap()); Foo* volatile do_not_access = MakeGarbageCollected<Foo>(GetHeap());
USE(do_not_acces); USE(do_not_access);
EXPECT_EQ(0u, Foo::destructor_callcount); EXPECT_EQ(0u, Foo::destructor_callcount);
ConservativeGC(); ConservativeGC();
EXPECT_EQ(0u, Foo::destructor_callcount); EXPECT_EQ(0u, Foo::destructor_callcount);
PreciseGC(); PreciseGC();
EXPECT_EQ(1u, Foo::destructor_callcount); EXPECT_EQ(1u, Foo::destructor_callcount);
PreciseGC();
EXPECT_EQ(1u, Foo::destructor_callcount);
} }
} // namespace internal } // 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