Commit 62ff82e4 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

cppgc: Add tests for in-construction during ctor

Adds explicit tests that check that an object is marked as in
construction while running the constructor.

Bug: chromium:1056170
Change-Id: I7f7340832e1bc31cec98784c261ed86deb402e72
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2811238
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarOmer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73869}
parent 660e87d2
...@@ -156,5 +156,86 @@ TEST_F(GarbageCollectedTestWithHeap, PostConstructionCallbackForMixin) { ...@@ -156,5 +156,86 @@ TEST_F(GarbageCollectedTestWithHeap, PostConstructionCallbackForMixin) {
EXPECT_EQ(1u, MixinWithPostConstructionCallback::cb_callcount); EXPECT_EQ(1u, MixinWithPostConstructionCallback::cb_callcount);
} }
namespace {
int GetDummyValue() {
static std::mutex mutex;
static int ret = 43;
// Global lock access to avoid reordering.
std::lock_guard<std::mutex> guard(mutex);
return ret;
}
class CheckObjectInConstructionBeforeInitializerList final
: public GarbageCollected<CheckObjectInConstructionBeforeInitializerList> {
public:
CheckObjectInConstructionBeforeInitializerList()
: in_construction_before_initializer_list_(
HeapObjectHeader::FromPayload(this).IsInConstruction()),
unused_int_(GetDummyValue()) {
EXPECT_TRUE(in_construction_before_initializer_list_);
EXPECT_TRUE(HeapObjectHeader::FromPayload(this).IsInConstruction());
}
void Trace(Visitor*) const {}
private:
bool in_construction_before_initializer_list_;
int unused_int_;
};
class CheckMixinInConstructionBeforeInitializerList
: public GarbageCollectedMixin {
public:
explicit CheckMixinInConstructionBeforeInitializerList(void* payload_start)
: in_construction_before_initializer_list_(
HeapObjectHeader::FromPayload(payload_start).IsInConstruction()),
unused_int_(GetDummyValue()) {
EXPECT_TRUE(in_construction_before_initializer_list_);
EXPECT_TRUE(
HeapObjectHeader::FromPayload(payload_start).IsInConstruction());
}
void Trace(Visitor*) const override {}
private:
bool in_construction_before_initializer_list_;
int unused_int_;
};
class UnmanagedMixinForcingVTable {
protected:
virtual void ForceVTable() {}
};
class CheckGCedWithMixinInConstructionBeforeInitializerList
: public GarbageCollected<
CheckGCedWithMixinInConstructionBeforeInitializerList>,
public UnmanagedMixinForcingVTable,
public CheckMixinInConstructionBeforeInitializerList {
public:
CheckGCedWithMixinInConstructionBeforeInitializerList()
: CheckMixinInConstructionBeforeInitializerList(this) {
// Ensure that compiler indeed generated an inner object.
CHECK_NE(
this,
static_cast<void*>(
static_cast<CheckMixinInConstructionBeforeInitializerList*>(this)));
}
};
} // namespace
TEST_F(GarbageCollectedTestWithHeap, GarbageCollectedInConstructionDuringCtor) {
MakeGarbageCollected<CheckObjectInConstructionBeforeInitializerList>(
GetAllocationHandle());
}
TEST_F(GarbageCollectedTestWithHeap,
GarbageCollectedMixinInConstructionDuringCtor) {
MakeGarbageCollected<CheckGCedWithMixinInConstructionBeforeInitializerList>(
GetAllocationHandle());
}
} // namespace internal } // namespace internal
} // namespace cppgc } // 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