staticbool CollectorDoesAllowOrBroadcast() {
CollectorType type = Runtime::Current()->GetHeap()->CurrentCollectorType(); switch (type) { case CollectorType::kCollectorTypeCMS: case CollectorType::kCollectorTypeCMC: case CollectorType::kCollectorTypeCC: case CollectorType::kCollectorTypeSS: returntrue;
default: returnfalse;
}
}
staticbool CollectorDoesDisallow() {
CollectorType type = Runtime::Current()->GetHeap()->CurrentCollectorType(); switch (type) { case CollectorType::kCollectorTypeCMS: case CollectorType::kCollectorTypeCMC: returntrue;
// We use Strings because they are very easy to allocate.
Handle<mirror::String> s(hs.NewHandle(mirror::String::AllocFromModifiedUtf8(soa.Self(), "ABC")));
cswh.Set(GcRoot<mirror::Object>(s.Get()));
// Trigger a GC.
Runtime::Current()->GetHeap()->CollectGarbage(/* clear_soft_references= */ false);
// Expect the holder to have been called.
EXPECT_EQ(CollectorDoesAllowOrBroadcast() ? 1U : 0U, cswh.allow_count_);
EXPECT_EQ(CollectorDoesDisallow() ? 1U : 0U, cswh.disallow_count_); // Userfaultfd GC uses SweepSystemWeaks also for concurrent updation. // TODO: Explore this can be reverted back to unconditionally compare with 1 // once concurrent updation of native roots is full implemented in userfaultfd // GC.
size_t expected_sweep_count = gUseUserfaultfd ? 2U : 1U;
EXPECT_EQ(expected_sweep_count, cswh.sweep_count_);
// Expect the weak to not be cleared.
EXPECT_FALSE(cswh.Get().IsNull());
EXPECT_EQ(cswh.Get().Read(), s.Get());
}
// Trigger a GC.
Runtime::Current()->GetHeap()->CollectGarbage(/* clear_soft_references= */ false);
// Expect the holder to have been called.
EXPECT_EQ(CollectorDoesAllowOrBroadcast() ? 1U : 0U, cswh.allow_count_);
EXPECT_EQ(CollectorDoesDisallow() ? 1U : 0U, cswh.disallow_count_); // Userfaultfd GC uses SweepSystemWeaks also for concurrent updation. // TODO: Explore this can be reverted back to unconditionally compare with 1 // once concurrent updation of native roots is full implemented in userfaultfd // GC.
size_t expected_sweep_count = gUseUserfaultfd ? 2U : 1U;
EXPECT_EQ(expected_sweep_count, cswh.sweep_count_);
// Expect the weak to be cleared.
EXPECT_TRUE(cswh.Get().IsNull());
}
// We use Strings because they are very easy to allocate.
Handle<mirror::String> s(hs.NewHandle(mirror::String::AllocFromModifiedUtf8(soa.Self(), "ABC")));
cswh.Set(GcRoot<mirror::Object>(s.Get()));
// Trigger a GC.
Runtime::Current()->GetHeap()->CollectGarbage(/* clear_soft_references= */ false);
// Expect the holder to have been called.
ASSERT_EQ(CollectorDoesAllowOrBroadcast() ? 1U : 0U, cswh.allow_count_);
ASSERT_EQ(CollectorDoesDisallow() ? 1U : 0U, cswh.disallow_count_); // Userfaultfd GC uses SweepSystemWeaks also for concurrent updation. // TODO: Explore this can be reverted back to unconditionally compare with 1 // once concurrent updation of native roots is full implemented in userfaultfd // GC.
size_t expected_sweep_count = gUseUserfaultfd ? 2U : 1U;
EXPECT_EQ(expected_sweep_count, cswh.sweep_count_);
// Expect the weak to not be cleared.
ASSERT_FALSE(cswh.Get().IsNull());
ASSERT_EQ(cswh.Get().Read(), s.Get());
// Remove the holder.
Runtime::Current()->RemoveSystemWeakHolder(&cswh);
// Trigger another GC.
Runtime::Current()->GetHeap()->CollectGarbage(/* clear_soft_references= */ false);
// Expectation: no change in the numbers.
EXPECT_EQ(CollectorDoesAllowOrBroadcast() ? 1U : 0U, cswh.allow_count_);
EXPECT_EQ(CollectorDoesDisallow() ? 1U : 0U, cswh.disallow_count_);
EXPECT_EQ(expected_sweep_count, cswh.sweep_count_);
}
} // namespace gc
} // namespace art
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-06-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.