v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
raw-heap.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 V8_HEAP_CPPGC_RAW_HEAP_H_
6#define V8_HEAP_CPPGC_RAW_HEAP_H_
7
8#include <iterator>
9#include <memory>
10#include <vector>
11
12#include "include/cppgc/heap.h"
13#include "src/base/logging.h"
14#include "src/base/macros.h"
15
16namespace cppgc {
17namespace internal {
18
19class HeapBase;
20class BaseSpace;
21
22// RawHeap is responsible for space management.
24 public:
25 // Normal spaces are used to store objects of different size classes:
26 // - kNormal1: < 32 bytes
27 // - kNormal2: < 64 bytes
28 // - kNormal3: < 128 bytes
29 // - kNormal4: >= 128 bytes
30 //
31 // Objects of size greater than 2^16 get stored in the large space.
32 //
33 // Users can override where objects are allocated via cppgc::CustomSpace to
34 // force allocation in a custom space.
35 enum class RegularSpaceType : uint8_t {
36 kNormal1,
37 kNormal2,
38 kNormal3,
39 kNormal4,
40 kLarge,
41 };
42
43 static constexpr size_t kNumberOfRegularSpaces =
44 static_cast<size_t>(RegularSpaceType::kLarge) + 1;
45
46 using Spaces = std::vector<std::unique_ptr<BaseSpace>>;
47 using iterator = Spaces::iterator;
48 using const_iterator = Spaces::const_iterator;
49
51 const std::vector<std::unique_ptr<CustomSpaceBase>>& custom_spaces);
52
53 RawHeap(const RawHeap&) = delete;
54 RawHeap& operator=(const RawHeap&) = delete;
55
57
58 // Space iteration support.
59 iterator begin() { return spaces_.begin(); }
60 const_iterator begin() const { return spaces_.begin(); }
61 iterator end() { return spaces_.end(); }
62 const_iterator end() const { return spaces_.end(); }
63
64 iterator custom_begin() { return std::next(begin(), kNumberOfRegularSpaces); }
65 iterator custom_end() { return end(); }
66
67 size_t size() const { return spaces_.size(); }
68
70 const size_t index = static_cast<size_t>(type);
71 DCHECK_GT(kNumberOfRegularSpaces, index);
72 return Space(index);
73 }
74 const BaseSpace* Space(RegularSpaceType space) const {
75 return const_cast<RawHeap&>(*this).Space(space);
76 }
77
79 return Space(SpaceIndexForCustomSpace(space_index));
80 }
81 const BaseSpace* CustomSpace(CustomSpaceIndex space_index) const {
82 return const_cast<RawHeap&>(*this).CustomSpace(space_index);
83 }
84
85 HeapBase* heap() { return main_heap_; }
86 const HeapBase* heap() const { return main_heap_; }
87
88 private:
89 size_t SpaceIndexForCustomSpace(CustomSpaceIndex space_index) const {
90 DCHECK_LT(space_index.value, spaces_.size() - kNumberOfRegularSpaces);
91 return kNumberOfRegularSpaces + space_index.value;
92 }
93
94 BaseSpace* Space(size_t space_index) {
95 DCHECK_GT(spaces_.size(), space_index);
96 BaseSpace* space = spaces_[space_index].get();
97 DCHECK(space);
98 return space;
99 }
100 const BaseSpace* Space(size_t space_index) const {
101 return const_cast<RawHeap&>(*this).Space(space_index);
102 }
103
106};
107
108} // namespace internal
109} // namespace cppgc
110
111#endif // V8_HEAP_CPPGC_RAW_HEAP_H_
const BaseSpace * CustomSpace(CustomSpaceIndex space_index) const
Definition raw-heap.h:81
RawHeap & operator=(const RawHeap &)=delete
size_t SpaceIndexForCustomSpace(CustomSpaceIndex space_index) const
Definition raw-heap.h:89
iterator custom_begin()
Definition raw-heap.h:64
const BaseSpace * Space(RegularSpaceType space) const
Definition raw-heap.h:74
const BaseSpace * Space(size_t space_index) const
Definition raw-heap.h:100
std::vector< std::unique_ptr< BaseSpace > > Spaces
Definition raw-heap.h:46
RawHeap(const RawHeap &)=delete
BaseSpace * CustomSpace(CustomSpaceIndex space_index)
Definition raw-heap.h:78
const_iterator begin() const
Definition raw-heap.h:60
Spaces::iterator iterator
Definition raw-heap.h:47
const HeapBase * heap() const
Definition raw-heap.h:86
const_iterator end() const
Definition raw-heap.h:62
BaseSpace * Space(size_t space_index)
Definition raw-heap.h:94
Spaces::const_iterator const_iterator
Definition raw-heap.h:48
size_t size() const
Definition raw-heap.h:67
BaseSpace * Space(RegularSpaceType type)
Definition raw-heap.h:69
int end
too high values may cause the compiler to set high thresholds for inlining to as much as possible avoid inlined allocation of objects that cannot escape trace load stores from virtual maglev objects use TurboFan fast string builder analyze liveness of environment slots and zap dead values trace TurboFan load elimination emit data about basic block usage in builtins to this enable builtin reordering when run mksnapshot flag for emit warnings when applying builtin profile data verify register allocation in TurboFan randomly schedule instructions to stress dependency tracking enable store store elimination in TurboFan rewrite far to near simulate GC compiler thread race related to allow float parameters to be passed in simulator mode JS Wasm Run additional turbo_optimize_inlined_js_wasm_wrappers enable experimental feedback collection in generic lowering enable Turboshaft s WasmLoadElimination enable Turboshaft s low level load elimination for JS enable Turboshaft s escape analysis for string concatenation use enable Turbolev features that we want to ship in the not too far future trace individual Turboshaft reduction steps trace intermediate Turboshaft reduction steps invocation count threshold for early optimization Enables optimizations which favor memory size over execution speed Enables sampling allocation profiler with X as a sample interval min size of a semi the new space consists of two semi spaces max size of the Collect garbage after Collect garbage after keeps maps alive for< n > old space garbage collections print one detailed trace line in allocation gc speed threshold for starting incremental marking via a task in percent of available space
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_LT(v1, v2)
Definition logging.h:489
#define DCHECK_GT(v1, v2)
Definition logging.h:487
#define V8_EXPORT_PRIVATE
Definition macros.h:460
wasm::ValueType type