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));
82 static_assert((1 << kGranularityBits) == kCardSizeInBytes);
83 const size_t entry = offset >> kGranularityBits;
98struct CagedHeapLocalData final {
99 V8_INLINE static CagedHeapLocalData& Get() {
100 return *
reinterpret_cast<CagedHeapLocalData*
>(CagedHeapBase::GetBase());
103 static constexpr size_t CalculateLocalDataSizeForHeapSize(
size_t heap_size) {
104 return AgeTable::CalculateAgeTableSizeForHeapSize(heap_size);
107#if defined(CPPGC_YOUNG_GENERATION)
#define CPPGC_DCHECK(condition)
Definition: logging.h:36
constexpr size_t kAllocationGranularity
Definition: api-constants.h:75
Definition: allocation.h:38
#define V8_EXPORT
Definition: v8config.h:793
#define V8_INLINE
Definition: v8config.h:499