v8  8.6.395 (node 15.0.1)
V8 is Google's open source JavaScript engine
caged-heap-local-data.h
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 
5 #ifndef INCLUDE_CPPGC_INTERNAL_CAGED_HEAP_LOCAL_DATA_H_
6 #define INCLUDE_CPPGC_INTERNAL_CAGED_HEAP_LOCAL_DATA_H_
7 
8 #include <array>
9 
10 #include "cppgc/internal/api-constants.h"
11 #include "cppgc/internal/logging.h"
12 #include "cppgc/platform.h"
13 
14 namespace cppgc {
15 namespace internal {
16 
17 class HeapBase;
18 
19 #if defined(CPPGC_YOUNG_GENERATION)
20 
21 // AgeTable contains entries that correspond to 4KB memory regions. Each entry
22 // can be in one of three states: kOld, kYoung or kUnknown.
23 class AgeTable final {
24  static constexpr size_t kGranularityBits = 12; // 4KiB per byte.
25 
26  public:
27  enum class Age : uint8_t { kOld, kYoung, kUnknown };
28 
29  static constexpr size_t kEntrySizeInBytes = 1 << kGranularityBits;
30 
31  Age& operator[](uintptr_t offset) { return table_[entry(offset)]; }
32  Age operator[](uintptr_t offset) const { return table_[entry(offset)]; }
33 
35 
36  private:
37  static constexpr size_t kAgeTableSize =
39 
40  size_t entry(uintptr_t offset) const {
43  return entry;
44  }
45 
47 };
48 
49 static_assert(sizeof(AgeTable) == 1 * api_constants::kMB,
50  "Size of AgeTable is 1MB");
51 
52 #endif // CPPGC_YOUNG_GENERATION
53 
54 struct CagedHeapLocalData final {
55  explicit CagedHeapLocalData(HeapBase* heap_base) : heap_base(heap_base) {}
56 
57  bool is_marking_in_progress = false;
58  HeapBase* heap_base = nullptr;
59 #if defined(CPPGC_YOUNG_GENERATION)
60  AgeTable age_table;
61 #endif
62 };
63 
64 } // namespace internal
65 } // namespace cppgc
66 
67 #endif // INCLUDE_CPPGC_INTERNAL_CAGED_HEAP_LOCAL_DATA_H_