19633c4e2c
This reverts commit 164a040a2a
.
Reason for revert: roll failure: https://ci.chromium.org/ui/p/chromium/builders/try/cast_shell_linux/1164753/overview
Original change's description:
> cppgc: Add regression test and check for object start bitmap
>
> Access to the object start bitmap is only safe during marking until
> sweeping is started as the concurrent sweeper may clear and rebuild
> the bitmap at any time during sweeping.
>
> Adds a DCHECK and an additional test for a previously broken
> pre-finalizer scenario.
>
> Bug: chromium:1307471
> Change-Id: If67ade43f7cdad6de4720c0efeac11bfe8c22b3c
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3535782
> Reviewed-by: Nikolaos Papaspyrou <nikolaos@chromium.org>
> Reviewed-by: Omer Katz <omerkatz@chromium.org>
> Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#79550}
Bug: chromium:1307471
Change-Id: I181e63a34eae9369184fb86112bc64e53b8bfad5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3545317
Owners-Override: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79590}
322 lines
10 KiB
C++
322 lines
10 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 "src/heap/cppgc/marking-visitor.h"
|
|
|
|
#include "include/cppgc/allocation.h"
|
|
#include "include/cppgc/member.h"
|
|
#include "include/cppgc/persistent.h"
|
|
#include "include/cppgc/source-location.h"
|
|
#include "src/heap/cppgc/globals.h"
|
|
#include "src/heap/cppgc/heap-object-header.h"
|
|
#include "src/heap/cppgc/marker.h"
|
|
#include "src/heap/cppgc/marking-state.h"
|
|
#include "test/unittests/heap/cppgc/tests.h"
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
namespace cppgc {
|
|
namespace internal {
|
|
|
|
namespace {
|
|
|
|
class MarkingVisitorTest : public testing::TestWithHeap {
|
|
public:
|
|
MarkingVisitorTest()
|
|
: marker_(std::make_unique<Marker>(*Heap::From(GetHeap()),
|
|
GetPlatformHandle().get())) {
|
|
marker_->StartMarking();
|
|
}
|
|
~MarkingVisitorTest() override { marker_->ClearAllWorklistsForTesting(); }
|
|
|
|
Marker* GetMarker() { return marker_.get(); }
|
|
|
|
private:
|
|
std::unique_ptr<Marker> marker_;
|
|
};
|
|
|
|
class GCed : public GarbageCollected<GCed> {
|
|
public:
|
|
void Trace(cppgc::Visitor*) const {}
|
|
};
|
|
|
|
class Mixin : public GarbageCollectedMixin {};
|
|
class GCedWithMixin : public GarbageCollected<GCedWithMixin>, public Mixin {
|
|
public:
|
|
void Trace(cppgc::Visitor*) const override {}
|
|
};
|
|
|
|
class TestMarkingVisitor : public MutatorMarkingVisitor {
|
|
public:
|
|
explicit TestMarkingVisitor(Marker* marker)
|
|
: MutatorMarkingVisitor(marker->heap(),
|
|
marker->MutatorMarkingStateForTesting()) {}
|
|
~TestMarkingVisitor() { marking_state_.Publish(); }
|
|
|
|
BasicMarkingState& marking_state() { return marking_state_; }
|
|
};
|
|
|
|
} // namespace
|
|
|
|
TEST_F(MarkingVisitorTest, MarkedBytesAreInitiallyZero) {
|
|
EXPECT_EQ(0u, GetMarker()->MutatorMarkingStateForTesting().marked_bytes());
|
|
}
|
|
|
|
// Strong references are marked.
|
|
|
|
TEST_F(MarkingVisitorTest, MarkMember) {
|
|
Member<GCed> object(MakeGarbageCollected<GCed>(GetAllocationHandle()));
|
|
HeapObjectHeader& header = HeapObjectHeader::FromObject(object);
|
|
|
|
TestMarkingVisitor visitor(GetMarker());
|
|
|
|
EXPECT_FALSE(header.IsMarked());
|
|
|
|
visitor.Trace(object);
|
|
|
|
EXPECT_TRUE(header.IsMarked());
|
|
}
|
|
|
|
TEST_F(MarkingVisitorTest, MarkMemberMixin) {
|
|
GCedWithMixin* object(
|
|
MakeGarbageCollected<GCedWithMixin>(GetAllocationHandle()));
|
|
Member<Mixin> mixin(object);
|
|
HeapObjectHeader& header = HeapObjectHeader::FromObject(object);
|
|
|
|
TestMarkingVisitor visitor(GetMarker());
|
|
|
|
EXPECT_FALSE(header.IsMarked());
|
|
|
|
visitor.Trace(mixin);
|
|
|
|
EXPECT_TRUE(header.IsMarked());
|
|
}
|
|
|
|
TEST_F(MarkingVisitorTest, MarkPersistent) {
|
|
Persistent<GCed> object(MakeGarbageCollected<GCed>(GetAllocationHandle()));
|
|
HeapObjectHeader& header = HeapObjectHeader::FromObject(object);
|
|
|
|
TestMarkingVisitor visitor(GetMarker());
|
|
|
|
EXPECT_FALSE(header.IsMarked());
|
|
|
|
visitor.TraceRootForTesting(object, SourceLocation::Current());
|
|
|
|
EXPECT_TRUE(header.IsMarked());
|
|
}
|
|
|
|
TEST_F(MarkingVisitorTest, MarkPersistentMixin) {
|
|
GCedWithMixin* object(
|
|
MakeGarbageCollected<GCedWithMixin>(GetAllocationHandle()));
|
|
Persistent<Mixin> mixin(object);
|
|
HeapObjectHeader& header = HeapObjectHeader::FromObject(object);
|
|
|
|
TestMarkingVisitor visitor(GetMarker());
|
|
|
|
EXPECT_FALSE(header.IsMarked());
|
|
|
|
visitor.TraceRootForTesting(mixin, SourceLocation::Current());
|
|
|
|
EXPECT_TRUE(header.IsMarked());
|
|
}
|
|
|
|
// Weak references are not marked.
|
|
|
|
TEST_F(MarkingVisitorTest, DontMarkWeakMember) {
|
|
WeakMember<GCed> object(MakeGarbageCollected<GCed>(GetAllocationHandle()));
|
|
HeapObjectHeader& header = HeapObjectHeader::FromObject(object);
|
|
|
|
TestMarkingVisitor visitor(GetMarker());
|
|
|
|
EXPECT_FALSE(header.IsMarked());
|
|
|
|
visitor.Trace(object);
|
|
|
|
EXPECT_FALSE(header.IsMarked());
|
|
}
|
|
|
|
TEST_F(MarkingVisitorTest, DontMarkWeakMemberMixin) {
|
|
GCedWithMixin* object(
|
|
MakeGarbageCollected<GCedWithMixin>(GetAllocationHandle()));
|
|
WeakMember<Mixin> mixin(object);
|
|
HeapObjectHeader& header = HeapObjectHeader::FromObject(object);
|
|
|
|
TestMarkingVisitor visitor(GetMarker());
|
|
|
|
EXPECT_FALSE(header.IsMarked());
|
|
|
|
visitor.Trace(mixin);
|
|
|
|
EXPECT_FALSE(header.IsMarked());
|
|
}
|
|
|
|
TEST_F(MarkingVisitorTest, DontMarkWeakPersistent) {
|
|
WeakPersistent<GCed> object(
|
|
MakeGarbageCollected<GCed>(GetAllocationHandle()));
|
|
HeapObjectHeader& header = HeapObjectHeader::FromObject(object);
|
|
|
|
TestMarkingVisitor visitor(GetMarker());
|
|
|
|
EXPECT_FALSE(header.IsMarked());
|
|
|
|
visitor.TraceRootForTesting(object, SourceLocation::Current());
|
|
|
|
EXPECT_FALSE(header.IsMarked());
|
|
}
|
|
|
|
TEST_F(MarkingVisitorTest, DontMarkWeakPersistentMixin) {
|
|
GCedWithMixin* object(
|
|
MakeGarbageCollected<GCedWithMixin>(GetAllocationHandle()));
|
|
WeakPersistent<Mixin> mixin(object);
|
|
HeapObjectHeader& header = HeapObjectHeader::FromObject(object);
|
|
|
|
TestMarkingVisitor visitor(GetMarker());
|
|
|
|
EXPECT_FALSE(header.IsMarked());
|
|
|
|
visitor.TraceRootForTesting(mixin, SourceLocation::Current());
|
|
|
|
EXPECT_FALSE(header.IsMarked());
|
|
}
|
|
|
|
// In construction objects are not marked.
|
|
|
|
namespace {
|
|
|
|
class GCedWithInConstructionCallback
|
|
: public GarbageCollected<GCedWithInConstructionCallback> {
|
|
public:
|
|
template <typename Callback>
|
|
explicit GCedWithInConstructionCallback(Callback callback) {
|
|
callback(this);
|
|
}
|
|
void Trace(cppgc::Visitor*) const {}
|
|
};
|
|
|
|
class MixinWithInConstructionCallback : public GarbageCollectedMixin {
|
|
public:
|
|
template <typename Callback>
|
|
explicit MixinWithInConstructionCallback(Callback callback) {
|
|
callback(this);
|
|
}
|
|
};
|
|
class GCedWithMixinWithInConstructionCallback
|
|
: public GarbageCollected<GCedWithMixinWithInConstructionCallback>,
|
|
public MixinWithInConstructionCallback {
|
|
public:
|
|
template <typename Callback>
|
|
explicit GCedWithMixinWithInConstructionCallback(Callback callback)
|
|
: MixinWithInConstructionCallback(callback) {}
|
|
void Trace(cppgc::Visitor*) const override {}
|
|
};
|
|
|
|
} // namespace
|
|
|
|
TEST_F(MarkingVisitorTest, MarkMemberInConstruction) {
|
|
TestMarkingVisitor visitor(GetMarker());
|
|
GCedWithInConstructionCallback* gced =
|
|
MakeGarbageCollected<GCedWithInConstructionCallback>(
|
|
GetAllocationHandle(),
|
|
[&visitor](GCedWithInConstructionCallback* obj) {
|
|
Member<GCedWithInConstructionCallback> object(obj);
|
|
visitor.Trace(object);
|
|
});
|
|
HeapObjectHeader& header = HeapObjectHeader::FromObject(gced);
|
|
EXPECT_TRUE(visitor.marking_state().not_fully_constructed_worklist().Contains(
|
|
&header));
|
|
EXPECT_FALSE(header.IsMarked());
|
|
}
|
|
|
|
TEST_F(MarkingVisitorTest, MarkMemberMixinInConstruction) {
|
|
TestMarkingVisitor visitor(GetMarker());
|
|
GCedWithMixinWithInConstructionCallback* gced =
|
|
MakeGarbageCollected<GCedWithMixinWithInConstructionCallback>(
|
|
GetAllocationHandle(),
|
|
[&visitor](MixinWithInConstructionCallback* obj) {
|
|
Member<MixinWithInConstructionCallback> mixin(obj);
|
|
visitor.Trace(mixin);
|
|
});
|
|
HeapObjectHeader& header = HeapObjectHeader::FromObject(gced);
|
|
EXPECT_TRUE(visitor.marking_state().not_fully_constructed_worklist().Contains(
|
|
&header));
|
|
EXPECT_FALSE(header.IsMarked());
|
|
}
|
|
|
|
TEST_F(MarkingVisitorTest, DontMarkWeakMemberInConstruction) {
|
|
TestMarkingVisitor visitor(GetMarker());
|
|
GCedWithInConstructionCallback* gced =
|
|
MakeGarbageCollected<GCedWithInConstructionCallback>(
|
|
GetAllocationHandle(),
|
|
[&visitor](GCedWithInConstructionCallback* obj) {
|
|
WeakMember<GCedWithInConstructionCallback> object(obj);
|
|
visitor.Trace(object);
|
|
});
|
|
HeapObjectHeader& header = HeapObjectHeader::FromObject(gced);
|
|
EXPECT_FALSE(
|
|
visitor.marking_state().not_fully_constructed_worklist().Contains(
|
|
&header));
|
|
EXPECT_FALSE(header.IsMarked());
|
|
}
|
|
|
|
TEST_F(MarkingVisitorTest, DontMarkWeakMemberMixinInConstruction) {
|
|
TestMarkingVisitor visitor(GetMarker());
|
|
GCedWithMixinWithInConstructionCallback* gced =
|
|
MakeGarbageCollected<GCedWithMixinWithInConstructionCallback>(
|
|
GetAllocationHandle(),
|
|
[&visitor](MixinWithInConstructionCallback* obj) {
|
|
WeakMember<MixinWithInConstructionCallback> mixin(obj);
|
|
visitor.Trace(mixin);
|
|
});
|
|
HeapObjectHeader& header = HeapObjectHeader::FromObject(gced);
|
|
EXPECT_FALSE(
|
|
visitor.marking_state().not_fully_constructed_worklist().Contains(
|
|
&header));
|
|
EXPECT_FALSE(header.IsMarked());
|
|
}
|
|
|
|
TEST_F(MarkingVisitorTest, MarkPersistentInConstruction) {
|
|
TestMarkingVisitor visitor(GetMarker());
|
|
GCedWithInConstructionCallback* gced =
|
|
MakeGarbageCollected<GCedWithInConstructionCallback>(
|
|
GetAllocationHandle(),
|
|
[&visitor](GCedWithInConstructionCallback* obj) {
|
|
Persistent<GCedWithInConstructionCallback> object(obj);
|
|
visitor.TraceRootForTesting(object, SourceLocation::Current());
|
|
});
|
|
HeapObjectHeader& header = HeapObjectHeader::FromObject(gced);
|
|
EXPECT_TRUE(visitor.marking_state().not_fully_constructed_worklist().Contains(
|
|
&header));
|
|
EXPECT_FALSE(header.IsMarked());
|
|
}
|
|
|
|
TEST_F(MarkingVisitorTest, MarkPersistentMixinInConstruction) {
|
|
TestMarkingVisitor visitor(GetMarker());
|
|
GCedWithMixinWithInConstructionCallback* gced =
|
|
MakeGarbageCollected<GCedWithMixinWithInConstructionCallback>(
|
|
GetAllocationHandle(),
|
|
[&visitor](MixinWithInConstructionCallback* obj) {
|
|
Persistent<MixinWithInConstructionCallback> mixin(obj);
|
|
visitor.TraceRootForTesting(mixin, SourceLocation::Current());
|
|
});
|
|
HeapObjectHeader& header = HeapObjectHeader::FromObject(gced);
|
|
EXPECT_TRUE(visitor.marking_state().not_fully_constructed_worklist().Contains(
|
|
&header));
|
|
EXPECT_FALSE(header.IsMarked());
|
|
}
|
|
|
|
TEST_F(MarkingVisitorTest, StrongTracingMarksWeakMember) {
|
|
WeakMember<GCed> object(MakeGarbageCollected<GCed>(GetAllocationHandle()));
|
|
HeapObjectHeader& header = HeapObjectHeader::FromObject(object);
|
|
|
|
TestMarkingVisitor visitor(GetMarker());
|
|
|
|
EXPECT_FALSE(header.IsMarked());
|
|
|
|
visitor.TraceStrongly(object);
|
|
|
|
EXPECT_TRUE(header.IsMarked());
|
|
}
|
|
|
|
} // namespace internal
|
|
} // namespace cppgc
|