5#ifndef INCLUDE_CPPGC_INTERNAL_CAGED_HEAP_LOCAL_DATA_H_
6#define INCLUDE_CPPGC_INTERNAL_CAGED_HEAP_LOCAL_DATA_H_
22#if defined(CPPGC_CAGED_HEAP)
30#if defined(CPPGC_YOUNG_GENERATION)
37 static constexpr size_t kRequiredSize = 1 * api_constants::kMB;
39 api_constants::kAllocationGranularity;
43 enum class Age : uint8_t { kOld, kYoung, kMixed };
46 enum class AdjacentCardsPolicy : uint8_t { kConsider, kIgnore };
48 static constexpr size_t kCardSizeInBytes =
49 api_constants::kCagedHeapDefaultReservationSize / kRequiredSize;
51 static constexpr size_t CalculateAgeTableSizeForHeapSize(
size_t heap_size) {
52 return heap_size / kCardSizeInBytes;
55 void SetAge(uintptr_t cage_offset, Age age) {
56 table_[card(cage_offset)] = age;
59 V8_INLINE Age GetAge(uintptr_t cage_offset)
const {
60 return table_[card(cage_offset)];
63 void SetAgeForRange(uintptr_t cage_offset_begin, uintptr_t cage_offset_end,
64 Age age, AdjacentCardsPolicy adjacent_cards_policy);
66 Age GetAgeForRange(uintptr_t cage_offset_begin,
67 uintptr_t cage_offset_end)
const;
69 void ResetForTesting();
72 V8_INLINE size_t card(uintptr_t offset)
const {
73 constexpr size_t kGranularityBits =
75 std::countr_zero(
static_cast<uint32_t
>(kCardSizeInBytes));
76#elif V8_HAS_BUILTIN_CTZ
77 __builtin_ctz(
static_cast<uint32_t
>(kCardSizeInBytes));
80#if defined(CPPGC_2GB_CAGE)
86 static_assert((1 << kGranularityBits) == kCardSizeInBytes);
87 const size_t entry = offset >> kGranularityBits;
102struct CagedHeapLocalData final {
103 V8_INLINE static CagedHeapLocalData& Get() {
104 return *
reinterpret_cast<CagedHeapLocalData*
>(CagedHeapBase::GetBase());
107 static constexpr size_t CalculateLocalDataSizeForHeapSize(
size_t heap_size) {
108 return AgeTable::CalculateAgeTableSizeForHeapSize(heap_size);
111#if defined(CPPGC_YOUNG_GENERATION)
#define CPPGC_DCHECK(condition)
constexpr size_t kAllocationGranularity