v8/test/unittests/heap/cppgc/testing-unittest.cc
Michael Lippautz 7ef1fc1565 testing: OverrideEmbedderStackStateScope should only affect implicit GCs
The only user of OverrideEmbedderStackStateScope is Blink where it is
used to override stack state of top-level tasks. Adjust the behavior
here to allow using this scope broadly while still supporting explicit
garbage collection calls.

Bug: chromium:1300492
Change-Id: I78c418c5f08991bf6857147cd4a537246bfcc556
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3497744
Reviewed-by: Omer Katz <omerkatz@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79420}
2022-03-09 14:29:34 +00:00

65 lines
2.1 KiB
C++

// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "include/cppgc/testing.h"
#include "include/cppgc/allocation.h"
#include "include/cppgc/garbage-collected.h"
#include "include/cppgc/persistent.h"
#include "test/unittests/heap/cppgc/tests.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace cppgc {
namespace internal {
namespace {
class TestingTest : public testing::TestWithHeap {};
class GCed : public GarbageCollected<GCed> {
public:
void Trace(Visitor*) const {}
};
} // namespace
TEST_F(TestingTest,
OverrideEmbeddertackStateScopeDoesNotOverrideExplicitCalls) {
{
auto* gced = MakeGarbageCollected<GCed>(GetHeap()->GetAllocationHandle());
WeakPersistent<GCed> weak{gced};
internal::Heap::From(GetHeap())->CollectGarbage(
Heap::Config::PreciseAtomicConfig());
EXPECT_FALSE(weak);
}
{
auto* gced = MakeGarbageCollected<GCed>(GetHeap()->GetAllocationHandle());
WeakPersistent<GCed> weak{gced};
cppgc::testing::OverrideEmbedderStackStateScope override_stack(
GetHeap()->GetHeapHandle(),
EmbedderStackState::kMayContainHeapPointers);
internal::Heap::From(GetHeap())->CollectGarbage(
Heap::Config::PreciseAtomicConfig());
EXPECT_FALSE(weak);
}
{
auto* gced = MakeGarbageCollected<GCed>(GetHeap()->GetAllocationHandle());
WeakPersistent<GCed> weak{gced};
cppgc::testing::OverrideEmbedderStackStateScope override_stack(
GetHeap()->GetHeapHandle(), EmbedderStackState::kNoHeapPointers);
internal::Heap::From(GetHeap())->CollectGarbage(
Heap::Config::ConservativeAtomicConfig());
EXPECT_TRUE(weak);
}
}
TEST_F(TestingTest, StandaloneTestingHeap) {
// Perform garbage collection through the StandaloneTestingHeap API.
cppgc::testing::StandaloneTestingHeap heap(GetHeap()->GetHeapHandle());
heap.StartGarbageCollection();
heap.PerformMarkingStep(EmbedderStackState::kNoHeapPointers);
heap.FinalizeGarbageCollection(EmbedderStackState::kNoHeapPointers);
}
} // namespace internal
} // namespace cppgc