v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
heap-space.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_HEAP_SPACE_H_
6#define V8_HEAP_CPPGC_HEAP_SPACE_H_
7
8#include <vector>
9
10#include "src/base/logging.h"
11#include "src/base/macros.h"
14
15namespace cppgc {
16namespace internal {
17
18class RawHeap;
19class BasePage;
20
21// BaseSpace is responsible for page management.
23 public:
24 using Pages = std::vector<BasePage*>;
25
26 using iterator = Pages::iterator;
27 using const_iterator = Pages::const_iterator;
28
29 BaseSpace(const BaseSpace&) = delete;
30 BaseSpace& operator=(const BaseSpace&) = delete;
31 virtual ~BaseSpace();
32
33 iterator begin() { return pages_.begin(); }
34 const_iterator begin() const { return pages_.begin(); }
35 iterator end() { return pages_.end(); }
36 const_iterator end() const { return pages_.end(); }
37
38 size_t size() const { return pages_.size(); }
39
40 bool is_large() const { return type_ == PageType::kLarge; }
41 size_t index() const { return index_; }
42
43 RawHeap* raw_heap() { return heap_; }
44 const RawHeap* raw_heap() const { return heap_; }
45
46 // Page manipulation functions.
47 void AddPage(BasePage*);
48 void RemovePage(BasePage*);
49 Pages RemoveAllPages();
50 v8::base::Mutex& pages_mutex() const { return pages_mutex_; }
51
52 bool is_compactable() const { return is_compactable_; }
53
54 protected:
55 enum class PageType { kNormal, kLarge };
56 explicit BaseSpace(RawHeap* heap, size_t index, PageType type,
57 bool is_compactable);
58
59 private:
63 const size_t index_;
65 const bool is_compactable_;
66};
67
69 public:
71 public:
72 Address Allocate(size_t alloc_size) {
73 DCHECK_GE(size_, alloc_size);
75 start_ += alloc_size;
76 size_ -= alloc_size;
77 return result;
78 }
79
80 void Set(Address ptr, size_t size) {
81 start_ = ptr;
82 size_ = size;
83 }
84
85 Address start() const { return start_; }
86 size_t size() const { return size_; }
87
88 private:
89 Address start_ = nullptr;
90 size_t size_ = 0;
91 };
92
93 static NormalPageSpace& From(BaseSpace& space) {
94 DCHECK(!space.is_large());
95 return static_cast<NormalPageSpace&>(space);
96 }
97 static const NormalPageSpace& From(const BaseSpace& space) {
98 return From(const_cast<BaseSpace&>(space));
99 }
100
101 NormalPageSpace(RawHeap* heap, size_t index, bool is_compactable);
102
105 return current_lab_;
106 }
107
109 const FreeList& free_list() const { return free_list_; }
110
111 private:
114};
115
117 public:
118 static LargePageSpace& From(BaseSpace& space) {
119 DCHECK(space.is_large());
120 return static_cast<LargePageSpace&>(space);
121 }
122 static const LargePageSpace& From(const BaseSpace& space) {
123 return From(const_cast<BaseSpace&>(space));
124 }
125
126 LargePageSpace(RawHeap* heap, size_t index);
127};
128
129} // namespace internal
130} // namespace cppgc
131
132#endif // V8_HEAP_CPPGC_HEAP_SPACE_H_
BaseSpace & operator=(const BaseSpace &)=delete
const RawHeap * raw_heap() const
Definition heap-space.h:44
Pages::iterator iterator
Definition heap-space.h:26
BaseSpace(const BaseSpace &)=delete
Pages::const_iterator const_iterator
Definition heap-space.h:27
std::vector< BasePage * > Pages
Definition heap-space.h:24
bool is_compactable() const
Definition heap-space.h:52
const_iterator end() const
Definition heap-space.h:36
v8::base::Mutex & pages_mutex() const
Definition heap-space.h:50
const_iterator begin() const
Definition heap-space.h:34
v8::base::Mutex pages_mutex_
Definition heap-space.h:62
static const LargePageSpace & From(const BaseSpace &space)
Definition heap-space.h:122
static LargePageSpace & From(BaseSpace &space)
Definition heap-space.h:118
LinearAllocationBuffer current_lab_
Definition heap-space.h:112
static NormalPageSpace & From(BaseSpace &space)
Definition heap-space.h:93
LinearAllocationBuffer & linear_allocation_buffer()
Definition heap-space.h:103
const FreeList & free_list() const
Definition heap-space.h:109
static const NormalPageSpace & From(const BaseSpace &space)
Definition heap-space.h:97
const LinearAllocationBuffer & linear_allocation_buffer() const
Definition heap-space.h:104
Register const index_
const int size_
Definition assembler.cc:132
uint8_t *const start_
Definition assembler.cc:131
const ObjectRef type_
FreeList & free_list_
Definition sweeper.cc:156
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
ZoneVector< RpoNumber > & result
uint8_t * Address
Definition globals.h:17
#define DCHECK_GE(v1, v2)
Definition logging.h:488
#define DCHECK(condition)
Definition logging.h:482
#define V8_EXPORT_PRIVATE
Definition macros.h:460
Heap * heap_