cppgc: Support virtual prefinalizers
Bug: chromium:1252634, chromium:1056170 Change-Id: Ifdecca29dbff4ed3d6ee2acd547a20add482d59f Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3183167 Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Commit-Queue: Omer Katz <omerkatz@chromium.org> Cr-Commit-Position: refs/heads/main@{#77087}
This commit is contained in:
parent
6af3eb8f35
commit
14cc79ccf5
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user