Where Online Learning is simpler!
The C and C++ Include Header Files
/usr/include/node/cppgc/internal/caged-heap-local-data.h
$ cat -n /usr/include/node/cppgc/internal/caged-heap-local-data.h 1 // Copyright 2020 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef INCLUDE_CPPGC_INTERNAL_CAGED_HEAP_LOCAL_DATA_H_ 6 #define INCLUDE_CPPGC_INTERNAL_CAGED_HEAP_LOCAL_DATA_H_ 7 8 #include
9 #include
10 #include
11 12 #include "cppgc/internal/api-constants.h" 13 #include "cppgc/internal/caged-heap.h" 14 #include "cppgc/internal/logging.h" 15 #include "cppgc/platform.h" 16 #include "v8config.h" // NOLINT(build/include_directory) 17 18 #if __cpp_lib_bitopts 19 #include
20 #endif // __cpp_lib_bitopts 21 22 #if defined(CPPGC_CAGED_HEAP) 23 24 namespace cppgc { 25 namespace internal { 26 27 class HeapBase; 28 class HeapBaseHandle; 29 30 #if defined(CPPGC_YOUNG_GENERATION) 31 32 // AgeTable is the bytemap needed for the fast generation check in the write 33 // barrier. AgeTable contains entries that correspond to 4096 bytes memory 34 // regions (cards). Each entry in the table represents generation of the objects 35 // that reside on the corresponding card (young, old or mixed). 36 class V8_EXPORT AgeTable final { 37 static constexpr size_t kRequiredSize = 1 * api_constants::kMB; 38 static constexpr size_t kAllocationGranularity = 39 api_constants::kAllocationGranularity; 40 41 public: 42 // Represents age of the objects living on a single card. 43 enum class Age : uint8_t { kOld, kYoung, kMixed }; 44 // When setting age for a range, consider or ignore ages of the adjacent 45 // cards. 46 enum class AdjacentCardsPolicy : uint8_t { kConsider, kIgnore }; 47 48 static constexpr size_t kCardSizeInBytes = 49 api_constants::kCagedHeapDefaultReservationSize / kRequiredSize; 50 51 static constexpr size_t CalculateAgeTableSizeForHeapSize(size_t heap_size) { 52 return heap_size / kCardSizeInBytes; 53 } 54 55 void SetAge(uintptr_t cage_offset, Age age) { 56 table_[card(cage_offset)] = age; 57 } 58 59 V8_INLINE Age GetAge(uintptr_t cage_offset) const { 60 return table_[card(cage_offset)]; 61 } 62 63 void SetAgeForRange(uintptr_t cage_offset_begin, uintptr_t cage_offset_end, 64 Age age, AdjacentCardsPolicy adjacent_cards_policy); 65 66 Age GetAgeForRange(uintptr_t cage_offset_begin, 67 uintptr_t cage_offset_end) const; 68 69 void ResetForTesting(); 70 71 private: 72 V8_INLINE size_t card(uintptr_t offset) const { 73 constexpr size_t kGranularityBits = 74 #if __cpp_lib_bitopts 75 std::countr_zero(static_cast
(kCardSizeInBytes)); 76 #elif V8_HAS_BUILTIN_CTZ 77 __builtin_ctz(static_cast
(kCardSizeInBytes)); 78 #else //! V8_HAS_BUILTIN_CTZ 79 // Hardcode and check with assert. 80 #if defined(CPPGC_2GB_CAGE) 81 11; 82 #else // !defined(CPPGC_2GB_CAGE) 83 12; 84 #endif // !defined(CPPGC_2GB_CAGE) 85 #endif // !V8_HAS_BUILTIN_CTZ 86 static_assert((1 << kGranularityBits) == kCardSizeInBytes); 87 const size_t entry = offset >> kGranularityBits; 88 CPPGC_DCHECK(CagedHeapBase::GetAgeTableSize() > entry); 89 return entry; 90 } 91 92 #if defined(V8_CC_GNU) 93 // gcc disallows flexible arrays in otherwise empty classes. 94 Age table_[0]; 95 #else // !defined(V8_CC_GNU) 96 Age table_[]; 97 #endif // !defined(V8_CC_GNU) 98 }; 99 100 #endif // CPPGC_YOUNG_GENERATION 101 102 struct CagedHeapLocalData final { 103 V8_INLINE static CagedHeapLocalData& Get() { 104 return *reinterpret_cast
(CagedHeapBase::GetBase()); 105 } 106 107 static constexpr size_t CalculateLocalDataSizeForHeapSize(size_t heap_size) { 108 return AgeTable::CalculateAgeTableSizeForHeapSize(heap_size); 109 } 110 111 #if defined(CPPGC_YOUNG_GENERATION) 112 AgeTable age_table; 113 #endif 114 }; 115 116 } // namespace internal 117 } // namespace cppgc 118 119 #endif // defined(CPPGC_CAGED_HEAP) 120 121 #endif // INCLUDE_CPPGC_INTERNAL_CAGED_HEAP_LOCAL_DATA_H_
Contact us
|
About us
|
Term of use
|
Copyright © 2000-2026 MyWebUniversity.com ™