Commit 14cc79cc authored by Omer Katz's avatar Omer Katz Committed by V8 LUCI CQ

cppgc: Support virtual prefinalizers

Bug: chromium:1252634, chromium:1056170
Change-Id: Ifdecca29dbff4ed3d6ee2acd547a20add482d59f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3183167Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77087}
parent 6af3eb8f
......@@ -38,7 +38,7 @@ class PrefinalizerRegistration final {
"Only garbage collected objects can have prefinalizers"); \
Class* self = static_cast<Class*>(object); \
if (liveness_broker.IsHeapObjectAlive(self)) return false; \
self->Class::PreFinalizer(); \
self->PreFinalizer(); \
return true; \
} \
\
......
......@@ -340,5 +340,32 @@ TEST_F(PrefinalizerTest, AllocatingPrefinalizersInMultipleGCCycles) {
USE(other_object);
}
#endif
class GCedBase : public GarbageCollected<GCedBase> {
CPPGC_USING_PRE_FINALIZER(GCedBase, PreFinalize);
public:
void Trace(Visitor*) const {}
virtual void PreFinalize() { ++prefinalizer_count_; }
static size_t prefinalizer_count_;
};
size_t GCedBase::prefinalizer_count_ = 0u;
class GCedInherited : public GCedBase {
public:
void PreFinalize() override { ++prefinalizer_count_; }
static size_t prefinalizer_count_;
};
size_t GCedInherited::prefinalizer_count_ = 0u;
TEST_F(PrefinalizerTest, VirtualPrefinalizer) {
MakeGarbageCollected<GCedInherited>(GetAllocationHandle());
GCedBase::prefinalizer_count_ = 0u;
GCedInherited::prefinalizer_count_ = 0u;
PreciseGC();
EXPECT_EQ(0u, GCedBase::prefinalizer_count_);
EXPECT_LT(0u, GCedInherited::prefinalizer_count_);
}
} // namespace internal
} // namespace cppgc
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