Commit 62a0841b authored by Michael Lippautz's avatar Michael Lippautz Committed by V8 LUCI CQ

cppgc: Gracefully finish running GC on ~Heap

Change-Id: I38cd955d3e41861d955c529ec56890b45effccf0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3284897
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarOmer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77948}
parent 521b7a83
...@@ -62,10 +62,6 @@ class V8_EXPORT HeapHandle { ...@@ -62,10 +62,6 @@ class V8_EXPORT HeapHandle {
namespace internal { namespace internal {
namespace testing {
class TestWithHeap;
} // namespace testing
class FatalOutOfMemoryHandler; class FatalOutOfMemoryHandler;
class PageBackend; class PageBackend;
class PreFinalizerHandler; class PreFinalizerHandler;
...@@ -125,6 +121,7 @@ class V8_EXPORT_PRIVATE HeapBase : public cppgc::HeapHandle { ...@@ -125,6 +121,7 @@ class V8_EXPORT_PRIVATE HeapBase : public cppgc::HeapHandle {
} }
MarkerBase* marker() const { return marker_.get(); } MarkerBase* marker() const { return marker_.get(); }
std::unique_ptr<MarkerBase>& GetMarkerRefForTesting() { return marker_; }
Compactor& compactor() { return compactor_; } Compactor& compactor() { return compactor_; }
...@@ -277,7 +274,6 @@ class V8_EXPORT_PRIVATE HeapBase : public cppgc::HeapHandle { ...@@ -277,7 +274,6 @@ class V8_EXPORT_PRIVATE HeapBase : public cppgc::HeapHandle {
int creation_thread_id_ = v8::base::OS::GetCurrentThreadId(); int creation_thread_id_ = v8::base::OS::GetCurrentThreadId();
friend class MarkerBase::IncrementalMarkingTask; friend class MarkerBase::IncrementalMarkingTask;
friend class testing::TestWithHeap;
friend class cppgc::subtle::DisallowGarbageCollectionScope; friend class cppgc::subtle::DisallowGarbageCollectionScope;
friend class cppgc::subtle::NoGarbageCollectionScope; friend class cppgc::subtle::NoGarbageCollectionScope;
friend class cppgc::testing::Heap; friend class cppgc::testing::Heap;
......
...@@ -92,9 +92,17 @@ Heap::Heap(std::shared_ptr<cppgc::Platform> platform, ...@@ -92,9 +92,17 @@ Heap::Heap(std::shared_ptr<cppgc::Platform> platform,
} }
Heap::~Heap() { Heap::~Heap() {
subtle::NoGarbageCollectionScope no_gc(*this); // Gracefully finish already running GC if any, but don't finalize live
// Finish already running GC if any, but don't finalize live objects. // objects.
sweeper_.FinishIfRunning(); FinalizeIncrementalGarbageCollectionIfRunning(
{Config::CollectionType::kMajor,
Config::StackState::kMayContainHeapPointers,
Config::MarkingType::kIncrementalAndConcurrent,
Config::SweepingType::kIncrementalAndConcurrent});
{
subtle::NoGarbageCollectionScope no_gc(*this);
sweeper_.FinishIfRunning();
}
} }
void Heap::CollectGarbage(Config config) { void Heap::CollectGarbage(Config config) {
......
...@@ -88,6 +88,7 @@ class CompactorTest : public testing::TestWithPlatform { ...@@ -88,6 +88,7 @@ class CompactorTest : public testing::TestWithPlatform {
void EndGC() { void EndGC() {
heap()->marker()->FinishMarking( heap()->marker()->FinishMarking(
GarbageCollector::Config::StackState::kNoHeapPointers); GarbageCollector::Config::StackState::kNoHeapPointers);
heap()->GetMarkerRefForTesting().reset();
FinishCompaction(); FinishCompaction();
// Sweeping also verifies the object start bitmap. // Sweeping also verifies the object start bitmap.
const Sweeper::SweepingConfig sweeping_config{ const Sweeper::SweepingConfig sweeping_config{
......
...@@ -425,7 +425,7 @@ class IncrementalMarkingTest : public testing::TestWithHeap { ...@@ -425,7 +425,7 @@ class IncrementalMarkingTest : public testing::TestWithHeap {
MarkerFactory::CreateAndStartMarking<Marker>(heap, platform, config); MarkerFactory::CreateAndStartMarking<Marker>(heap, platform, config);
} }
MarkerBase* marker() const { return GetMarkerRef().get(); } MarkerBase* marker() const { return Heap::From(GetHeap())->marker(); }
private: private:
bool SingleStep(MarkingConfig::StackState stack_state) { bool SingleStep(MarkingConfig::StackState stack_state) {
......
...@@ -103,11 +103,7 @@ class TestWithHeap : public TestWithPlatform { ...@@ -103,11 +103,7 @@ class TestWithHeap : public TestWithPlatform {
} }
std::unique_ptr<MarkerBase>& GetMarkerRef() { std::unique_ptr<MarkerBase>& GetMarkerRef() {
return Heap::From(GetHeap())->marker_; return Heap::From(GetHeap())->GetMarkerRefForTesting();
}
const std::unique_ptr<MarkerBase>& GetMarkerRef() const {
return Heap::From(GetHeap())->marker_;
} }
void ResetLinearAllocationBuffers(); void ResetLinearAllocationBuffers();
......
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