Warning, file /include/node/cppgc/internal/caged-heap-local-data.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005 #ifndef INCLUDE_CPPGC_INTERNAL_CAGED_HEAP_LOCAL_DATA_H_
0006 #define INCLUDE_CPPGC_INTERNAL_CAGED_HEAP_LOCAL_DATA_H_
0007
0008 #include <array>
0009 #include <cstddef>
0010 #include <cstdint>
0011
0012 #include "cppgc/internal/api-constants.h"
0013 #include "cppgc/internal/caged-heap.h"
0014 #include "cppgc/internal/logging.h"
0015 #include "cppgc/platform.h"
0016 #include "v8config.h" // NOLINT(build/include_directory)
0017
0018 #if __cpp_lib_bitopts
0019 #include <bit>
0020 #endif
0021
0022 #if defined(CPPGC_CAGED_HEAP)
0023
0024 namespace cppgc {
0025 namespace internal {
0026
0027 class HeapBase;
0028 class HeapBaseHandle;
0029
0030 #if defined(CPPGC_YOUNG_GENERATION)
0031
0032
0033
0034
0035
0036 class V8_EXPORT AgeTable final {
0037 static constexpr size_t kRequiredSize = 1 * api_constants::kMB;
0038 static constexpr size_t kAllocationGranularity =
0039 api_constants::kAllocationGranularity;
0040
0041 public:
0042
0043 enum class Age : uint8_t { kOld, kYoung, kMixed };
0044
0045
0046 enum class AdjacentCardsPolicy : uint8_t { kConsider, kIgnore };
0047
0048 static constexpr size_t kCardSizeInBytes =
0049 api_constants::kCagedHeapDefaultReservationSize / kRequiredSize;
0050
0051 static constexpr size_t CalculateAgeTableSizeForHeapSize(size_t heap_size) {
0052 return heap_size / kCardSizeInBytes;
0053 }
0054
0055 void SetAge(uintptr_t cage_offset, Age age) {
0056 table_[card(cage_offset)] = age;
0057 }
0058
0059 V8_INLINE Age GetAge(uintptr_t cage_offset) const {
0060 return table_[card(cage_offset)];
0061 }
0062
0063 void SetAgeForRange(uintptr_t cage_offset_begin, uintptr_t cage_offset_end,
0064 Age age, AdjacentCardsPolicy adjacent_cards_policy);
0065
0066 Age GetAgeForRange(uintptr_t cage_offset_begin,
0067 uintptr_t cage_offset_end) const;
0068
0069 void ResetForTesting();
0070
0071 private:
0072 V8_INLINE size_t card(uintptr_t offset) const {
0073 constexpr size_t kGranularityBits =
0074 #if __cpp_lib_bitopts
0075 std::countr_zero(static_cast<uint32_t>(kCardSizeInBytes));
0076 #elif V8_HAS_BUILTIN_CTZ
0077 __builtin_ctz(static_cast<uint32_t>(kCardSizeInBytes));
0078 #else
0079
0080 #if defined(CPPGC_2GB_CAGE)
0081 11;
0082 #else
0083 12;
0084 #endif
0085 #endif
0086 static_assert((1 << kGranularityBits) == kCardSizeInBytes);
0087 const size_t entry = offset >> kGranularityBits;
0088 CPPGC_DCHECK(CagedHeapBase::GetAgeTableSize() > entry);
0089 return entry;
0090 }
0091
0092 #if defined(V8_CC_GNU)
0093
0094 Age table_[0];
0095 #else
0096 Age table_[];
0097 #endif
0098 };
0099
0100 #endif
0101
0102 struct CagedHeapLocalData final {
0103 V8_INLINE static CagedHeapLocalData& Get() {
0104 return *reinterpret_cast<CagedHeapLocalData*>(CagedHeapBase::GetBase());
0105 }
0106
0107 static constexpr size_t CalculateLocalDataSizeForHeapSize(size_t heap_size) {
0108 return AgeTable::CalculateAgeTableSizeForHeapSize(heap_size);
0109 }
0110
0111 #if defined(CPPGC_YOUNG_GENERATION)
0112 AgeTable age_table;
0113 #endif
0114 };
0115
0116 }
0117 }
0118
0119 #endif
0120
0121 #endif