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 #include "include/cppgc/internal/caged-heap-local-data.h" 6 7 #include <algorithm> 8 #include <type_traits> 9 10 #include "include/cppgc/platform.h" 11 #include "src/base/macros.h" 12 13 namespace cppgc { 14 namespace internal { 15 CagedHeapLocalData(HeapBase & heap_base,PageAllocator & allocator)16CagedHeapLocalData::CagedHeapLocalData(HeapBase& heap_base, 17 PageAllocator& allocator) 18 : heap_base(heap_base) { 19 #if defined(CPPGC_YOUNG_GENERATION) 20 age_table.Reset(&allocator); 21 #endif // defined(CPPGC_YOUNG_GENERATION) 22 } 23 24 #if defined(CPPGC_YOUNG_GENERATION) 25 26 static_assert( 27 std::is_trivially_default_constructible<AgeTable>::value, 28 "To support lazy committing, AgeTable must be trivially constructible"); 29 Reset(PageAllocator * allocator)30void AgeTable::Reset(PageAllocator* allocator) { 31 // TODO(chromium:1029379): Consider MADV_DONTNEED instead of MADV_FREE on 32 // POSIX platforms. 33 std::fill(table_.begin(), table_.end(), Age::kOld); 34 const uintptr_t begin = RoundUp(reinterpret_cast<uintptr_t>(table_.data()), 35 allocator->CommitPageSize()); 36 const uintptr_t end = 37 RoundDown(reinterpret_cast<uintptr_t>(table_.data() + table_.size()), 38 allocator->CommitPageSize()); 39 40 allocator->DiscardSystemPages(reinterpret_cast<void*>(begin), end - begin); 41 } 42 43 #endif // defined(CPPGC_YOUNG_GENERATION) 44 45 } // namespace internal 46 } // namespace cppgc 47