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 {
namespace internal {
namespace testing {
class TestWithHeap;
} // namespace testing
class FatalOutOfMemoryHandler;
class PageBackend;
class PreFinalizerHandler;
......@@ -125,6 +121,7 @@ class V8_EXPORT_PRIVATE HeapBase : public cppgc::HeapHandle {
}
MarkerBase* marker() const { return marker_.get(); }
std::unique_ptr<MarkerBase>& GetMarkerRefForTesting() { return marker_; }
Compactor& compactor() { return compactor_; }
......@@ -277,7 +274,6 @@ class V8_EXPORT_PRIVATE HeapBase : public cppgc::HeapHandle {
int creation_thread_id_ = v8::base::OS::GetCurrentThreadId();
friend class MarkerBase::IncrementalMarkingTask;
friend class testing::TestWithHeap;
friend class cppgc::subtle::DisallowGarbageCollectionScope;
friend class cppgc::subtle::NoGarbageCollectionScope;
friend class cppgc::testing::Heap;
......
......@@ -92,9 +92,17 @@ Heap::Heap(std::shared_ptr<cppgc::Platform> platform,
}
Heap::~Heap() {
// Gracefully finish already running GC if any, but don't finalize live
// objects.
FinalizeIncrementalGarbageCollectionIfRunning(
{Config::CollectionType::kMajor,
Config::StackState::kMayContainHeapPointers,
Config::MarkingType::kIncrementalAndConcurrent,
Config::SweepingType::kIncrementalAndConcurrent});
{
subtle::NoGarbageCollectionScope no_gc(*this);
// Finish already running GC if any, but don't finalize live objects.
sweeper_.FinishIfRunning();
}
}
void Heap::CollectGarbage(Config config) {
......
......@@ -88,6 +88,7 @@ class CompactorTest : public testing::TestWithPlatform {
void EndGC() {
heap()->marker()->FinishMarking(
GarbageCollector::Config::StackState::kNoHeapPointers);
heap()->GetMarkerRefForTesting().reset();
FinishCompaction();
// Sweeping also verifies the object start bitmap.
const Sweeper::SweepingConfig sweeping_config{
......
......@@ -425,7 +425,7 @@ class IncrementalMarkingTest : public testing::TestWithHeap {
MarkerFactory::CreateAndStartMarking<Marker>(heap, platform, config);
}
MarkerBase* marker() const { return GetMarkerRef().get(); }
MarkerBase* marker() const { return Heap::From(GetHeap())->marker(); }
private:
bool SingleStep(MarkingConfig::StackState stack_state) {
......
......@@ -103,11 +103,7 @@ class TestWithHeap : public TestWithPlatform {
}
std::unique_ptr<MarkerBase>& GetMarkerRef() {
return Heap::From(GetHeap())->marker_;
}
const std::unique_ptr<MarkerBase>& GetMarkerRef() const {
return Heap::From(GetHeap())->marker_;
return Heap::From(GetHeap())->GetMarkerRefForTesting();
}
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