v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
caged-heap-local-data.cc
Go to the documentation of this file.
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
6
7#include <algorithm>
8#include <type_traits>
9
11#include "src/base/macros.h"
12
13namespace cppgc {
14namespace internal {
15
16#if defined(CPPGC_YOUNG_GENERATION)
17
18static_assert(
19 std::is_trivially_default_constructible_v<AgeTable>,
20 "To support lazy committing, AgeTable must be trivially constructible");
21
22void AgeTable::SetAgeForRange(uintptr_t offset_begin, uintptr_t offset_end,
23 Age age,
24 AdjacentCardsPolicy adjacent_cards_policy) {
25 // First, mark inner cards.
26 const uintptr_t inner_card_offset_begin =
27 RoundUp(offset_begin, kCardSizeInBytes);
28 const uintptr_t outer_card_offset_end =
29 RoundDown(offset_end, kCardSizeInBytes);
30
31 for (auto inner_offset = inner_card_offset_begin;
32 inner_offset < outer_card_offset_end; inner_offset += kCardSizeInBytes)
33 SetAge(inner_offset, age);
34
35 // If outer cards are not card-aligned and are not of the same age, mark them
36 // as mixed.
37 const auto set_age_for_outer_card =
38 [this, age, adjacent_cards_policy](uintptr_t offset) {
39 if (IsAligned(offset, kCardSizeInBytes)) return;
40 if (adjacent_cards_policy == AdjacentCardsPolicy::kIgnore)
41 SetAge(offset, age);
42 else if (GetAge(offset) != age)
43 SetAge(offset, AgeTable::Age::kMixed);
44 };
45
46 set_age_for_outer_card(offset_begin);
47 set_age_for_outer_card(offset_end);
48}
49
50AgeTable::Age AgeTable::GetAgeForRange(uintptr_t offset_begin,
51 uintptr_t offset_end) const {
52 Age result = GetAge(offset_begin);
53 for (auto offset = offset_begin + kCardSizeInBytes; offset < offset_end;
54 offset += kCardSizeInBytes) {
55 if (result != GetAge(offset)) result = Age::kMixed;
56 }
57 return result;
58}
59
60void AgeTable::ResetForTesting() {
61 std::fill(&table_[0], &table_[CagedHeapBase::GetAgeTableSize()], Age::kOld);
62}
63
64#endif // defined(CPPGC_YOUNG_GENERATION)
65
66} // namespace internal
67} // namespace cppgc
int32_t offset
ZoneVector< RpoNumber > & result
SourcePositionTable *const table_
Definition pipeline.cc:227
constexpr T RoundUp(T x, intptr_t m)
Definition macros.h:387
constexpr T RoundDown(T x, intptr_t m)
Definition macros.h:371
constexpr bool IsAligned(T value, U alignment)
Definition macros.h:403