Commit 4d0446f6 authored by Omer Katz's avatar Omer Katz Committed by Commit Bot

cppgc: Last batch of unittests from heap_tests.cc

Bug: chromium:1056170
Change-Id: I64d817f9c5f56c0d7ae5a68ef3f00d3149548259
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2846882Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74138}
parent 0115a7e0
...@@ -281,8 +281,8 @@ class CompactionState final { ...@@ -281,8 +281,8 @@ class CompactionState final {
} }
void FinishCompactingPage(NormalPage* page) { void FinishCompactingPage(NormalPage* page) {
#if DEBUG || defined(LEAK_SANITIZER) || defined(ADDRESS_SANITIZER) || \ #if DEBUG || defined(V8_USE_MEMORY_SANITIZER) || \
defined(MEMORY_SANITIZER) defined(V8_USE_ADDRESS_SANITIZER)
// Zap the unused portion, until it is either compacted into or freed. // Zap the unused portion, until it is either compacted into or freed.
if (current_page_ != page) { if (current_page_ != page) {
ZapMemory(page->PayloadStart(), page->PayloadSize()); ZapMemory(page->PayloadStart(), page->PayloadSize());
...@@ -349,8 +349,8 @@ void CompactPage(NormalPage* page, CompactionState& compaction_state) { ...@@ -349,8 +349,8 @@ void CompactPage(NormalPage* page, CompactionState& compaction_state) {
// As compaction is under way, leave the freed memory accessible // As compaction is under way, leave the freed memory accessible
// while compacting the rest of the page. We just zap the payload // while compacting the rest of the page. We just zap the payload
// to catch out other finalizers trying to access it. // to catch out other finalizers trying to access it.
#if DEBUG || defined(LEAK_SANITIZER) || defined(ADDRESS_SANITIZER) || \ #if DEBUG || defined(V8_USE_MEMORY_SANITIZER) || \
defined(MEMORY_SANITIZER) defined(V8_USE_ADDRESS_SANITIZER)
ZapMemory(header, size); ZapMemory(header, size);
#endif #endif
header_address += size; header_address += size;
......
...@@ -444,5 +444,32 @@ TEST_F(MemberHeapTest, WeakMemberDoesNotRetainObject) { ...@@ -444,5 +444,32 @@ TEST_F(MemberHeapTest, WeakMemberDoesNotRetainObject) {
EXPECT_TRUE(gced_with_members->WasNestedCleared()); EXPECT_TRUE(gced_with_members->WasNestedCleared());
} }
namespace {
class GCedWithConstWeakMember
: public GarbageCollected<GCedWithConstWeakMember> {
public:
explicit GCedWithConstWeakMember(const GCedWithMembers* weak)
: weak_member_(weak) {}
void Trace(Visitor* visitor) const { visitor->Trace(weak_member_); }
const GCedWithMembers* weak_member() const { return weak_member_; }
private:
const WeakMember<const GCedWithMembers> weak_member_;
};
} // namespace
TEST_F(MemberHeapTest, ConstWeakRefIsClearedOnGC) {
const WeakPersistent<const GCedWithMembers> weak_persistent =
MakeGarbageCollected<GCedWithMembers>(GetAllocationHandle());
Persistent<GCedWithConstWeakMember> persistent =
MakeGarbageCollected<GCedWithConstWeakMember>(GetAllocationHandle(),
weak_persistent);
PreciseGC();
EXPECT_FALSE(weak_persistent);
EXPECT_FALSE(persistent->weak_member());
}
} // 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