gst-code-collection / tools /node-v22.19.0-linux-x64 /include /node /cppgc /internal /caged-heap-local-data.h
Download tools/node-v22.19.0-linux-x64/include/node/cppgc/internal/caged-heap-local-data.h from SitongGong/gst-code-collection: direct link, hf CLI and curl.
- Browser
- Download file 3.7 kB
-
https://huggingface.co/datasets/SitongGong/gst-code-collection/resolve/main/tools/node-v22.19.0-linux-x64/include/node/cppgc/internal/caged-heap-local-data.h
- Command line
-
hf download hf://datasets/SitongGong/gst-code-collection/tools/node-v22.19.0-linux-x64/include/node/cppgc/internal/caged-heap-local-data.h
-
curl -L -o caged-heap-local-data.h https://huggingface.co/datasets/SitongGong/gst-code-collection/resolve/main/tools/node-v22.19.0-linux-x64/include/node/cppgc/internal/caged-heap-local-data.h
3.7 kB
| // Copyright 2020 the V8 project authors. All rights reserved. | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| namespace cppgc { | |
| namespace internal { | |
| class HeapBase; | |
| class HeapBaseHandle; | |
| // AgeTable is the bytemap needed for the fast generation check in the write | |
| // barrier. AgeTable contains entries that correspond to 4096 bytes memory | |
| // regions (cards). Each entry in the table represents generation of the objects | |
| // that reside on the corresponding card (young, old or mixed). | |
| class V8_EXPORT AgeTable final { | |
| static constexpr size_t kRequiredSize = 1 * api_constants::kMB; | |
| static constexpr size_t kAllocationGranularity = | |
| api_constants::kAllocationGranularity; | |
| public: | |
| // Represents age of the objects living on a single card. | |
| enum class Age : uint8_t { kOld, kYoung, kMixed }; | |
| // When setting age for a range, consider or ignore ages of the adjacent | |
| // cards. | |
| enum class AdjacentCardsPolicy : uint8_t { kConsider, kIgnore }; | |
| static constexpr size_t kCardSizeInBytes = | |
| api_constants::kCagedHeapDefaultReservationSize / kRequiredSize; | |
| static constexpr size_t CalculateAgeTableSizeForHeapSize(size_t heap_size) { | |
| return heap_size / kCardSizeInBytes; | |
| } | |
| void SetAge(uintptr_t cage_offset, Age age) { | |
| table_[card(cage_offset)] = age; | |
| } | |
| V8_INLINE Age GetAge(uintptr_t cage_offset) const { | |
| return table_[card(cage_offset)]; | |
| } | |
| void SetAgeForRange(uintptr_t cage_offset_begin, uintptr_t cage_offset_end, | |
| Age age, AdjacentCardsPolicy adjacent_cards_policy); | |
| Age GetAgeForRange(uintptr_t cage_offset_begin, | |
| uintptr_t cage_offset_end) const; | |
| void ResetForTesting(); | |
| private: | |
| V8_INLINE size_t card(uintptr_t offset) const { | |
| constexpr size_t kGranularityBits = | |
| std::countr_zero(static_cast<uint32_t>(kCardSizeInBytes)); | |
| __builtin_ctz(static_cast<uint32_t>(kCardSizeInBytes)); | |
| // Hardcode and check with assert. | |
| 11; | |
| 12; | |
| static_assert((1 << kGranularityBits) == kCardSizeInBytes); | |
| const size_t entry = offset >> kGranularityBits; | |
| CPPGC_DCHECK(CagedHeapBase::GetAgeTableSize() > entry); | |
| return entry; | |
| } | |
| // gcc disallows flexible arrays in otherwise empty classes. | |
| Age table_[0]; | |
| Age table_[]; | |
| }; | |
| struct CagedHeapLocalData final { | |
| V8_INLINE static CagedHeapLocalData& Get() { | |
| return *reinterpret_cast<CagedHeapLocalData*>(CagedHeapBase::GetBase()); | |
| } | |
| static constexpr size_t CalculateLocalDataSizeForHeapSize(size_t heap_size) { | |
| return AgeTable::CalculateAgeTableSizeForHeapSize(heap_size); | |
| } | |
| AgeTable age_table; | |
| }; | |
| } // namespace internal | |
| } // namespace cppgc | |