libv8-node 15.5.1.0.beta1-x86_64-darwin-21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/libv8-node/.location.yml +2 -0
- data/ext/libv8-node/location.rb +91 -0
- data/ext/libv8-node/paths.rb +30 -0
- data/lib/libv8/node/version.rb +7 -0
- data/lib/libv8/node.rb +11 -0
- data/lib/libv8-node.rb +1 -0
- data/vendor/v8/include/cppgc/allocation.h +173 -0
- data/vendor/v8/include/cppgc/common.h +26 -0
- data/vendor/v8/include/cppgc/custom-space.h +62 -0
- data/vendor/v8/include/cppgc/default-platform.h +76 -0
- data/vendor/v8/include/cppgc/garbage-collected.h +116 -0
- data/vendor/v8/include/cppgc/heap.h +139 -0
- data/vendor/v8/include/cppgc/internal/api-constants.h +47 -0
- data/vendor/v8/include/cppgc/internal/atomic-entry-flag.h +48 -0
- data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +67 -0
- data/vendor/v8/include/cppgc/internal/compiler-specific.h +38 -0
- data/vendor/v8/include/cppgc/internal/finalizer-trait.h +90 -0
- data/vendor/v8/include/cppgc/internal/gc-info.h +45 -0
- data/vendor/v8/include/cppgc/internal/logging.h +50 -0
- data/vendor/v8/include/cppgc/internal/persistent-node.h +116 -0
- data/vendor/v8/include/cppgc/internal/pointer-policies.h +134 -0
- data/vendor/v8/include/cppgc/internal/prefinalizer-handler.h +30 -0
- data/vendor/v8/include/cppgc/internal/process-heap.h +34 -0
- data/vendor/v8/include/cppgc/internal/write-barrier.h +78 -0
- data/vendor/v8/include/cppgc/liveness-broker.h +68 -0
- data/vendor/v8/include/cppgc/macros.h +24 -0
- data/vendor/v8/include/cppgc/member.h +226 -0
- data/vendor/v8/include/cppgc/persistent.h +341 -0
- data/vendor/v8/include/cppgc/platform.h +130 -0
- data/vendor/v8/include/cppgc/prefinalizer.h +52 -0
- data/vendor/v8/include/cppgc/source-location.h +91 -0
- data/vendor/v8/include/cppgc/trace-trait.h +111 -0
- data/vendor/v8/include/cppgc/type-traits.h +109 -0
- data/vendor/v8/include/cppgc/visitor.h +213 -0
- data/vendor/v8/include/libplatform/libplatform-export.h +29 -0
- data/vendor/v8/include/libplatform/libplatform.h +106 -0
- data/vendor/v8/include/libplatform/v8-tracing.h +332 -0
- data/vendor/v8/include/v8-cppgc.h +226 -0
- data/vendor/v8/include/v8-fast-api-calls.h +388 -0
- data/vendor/v8/include/v8-inspector-protocol.h +13 -0
- data/vendor/v8/include/v8-inspector.h +327 -0
- data/vendor/v8/include/v8-internal.h +427 -0
- data/vendor/v8/include/v8-metrics.h +133 -0
- data/vendor/v8/include/v8-platform.h +684 -0
- data/vendor/v8/include/v8-profiler.h +1059 -0
- data/vendor/v8/include/v8-util.h +652 -0
- data/vendor/v8/include/v8-value-serializer-version.h +24 -0
- data/vendor/v8/include/v8-version-string.h +38 -0
- data/vendor/v8/include/v8-version.h +20 -0
- data/vendor/v8/include/v8-wasm-trap-handler-posix.h +31 -0
- data/vendor/v8/include/v8-wasm-trap-handler-win.h +28 -0
- data/vendor/v8/include/v8.h +12098 -0
- data/vendor/v8/include/v8config.h +484 -0
- data/vendor/v8/out.gn/libv8/obj/libv8_monolith.a +0 -0
- metadata +112 -0
@@ -0,0 +1,341 @@
|
|
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_PERSISTENT_H_
|
6
|
+
#define INCLUDE_CPPGC_PERSISTENT_H_
|
7
|
+
|
8
|
+
#include <type_traits>
|
9
|
+
|
10
|
+
#include "cppgc/internal/persistent-node.h"
|
11
|
+
#include "cppgc/internal/pointer-policies.h"
|
12
|
+
#include "cppgc/source-location.h"
|
13
|
+
#include "cppgc/type-traits.h"
|
14
|
+
#include "cppgc/visitor.h"
|
15
|
+
#include "v8config.h" // NOLINT(build/include_directory)
|
16
|
+
|
17
|
+
namespace cppgc {
|
18
|
+
|
19
|
+
class Visitor;
|
20
|
+
|
21
|
+
namespace internal {
|
22
|
+
|
23
|
+
class PersistentBase {
|
24
|
+
protected:
|
25
|
+
PersistentBase() = default;
|
26
|
+
explicit PersistentBase(void* raw) : raw_(raw) {}
|
27
|
+
|
28
|
+
void* GetValue() const { return raw_; }
|
29
|
+
void SetValue(void* value) { raw_ = value; }
|
30
|
+
|
31
|
+
PersistentNode* GetNode() const { return node_; }
|
32
|
+
void SetNode(PersistentNode* node) { node_ = node; }
|
33
|
+
|
34
|
+
// Performs a shallow clear which assumes that internal persistent nodes are
|
35
|
+
// destroyed elsewhere.
|
36
|
+
void ClearFromGC() const {
|
37
|
+
raw_ = nullptr;
|
38
|
+
node_ = nullptr;
|
39
|
+
}
|
40
|
+
|
41
|
+
private:
|
42
|
+
mutable void* raw_ = nullptr;
|
43
|
+
mutable PersistentNode* node_ = nullptr;
|
44
|
+
|
45
|
+
friend class PersistentRegion;
|
46
|
+
};
|
47
|
+
|
48
|
+
// The basic class from which all Persistent classes are generated.
|
49
|
+
template <typename T, typename WeaknessPolicy, typename LocationPolicy,
|
50
|
+
typename CheckingPolicy>
|
51
|
+
class BasicPersistent final : public PersistentBase,
|
52
|
+
public LocationPolicy,
|
53
|
+
private WeaknessPolicy,
|
54
|
+
private CheckingPolicy {
|
55
|
+
public:
|
56
|
+
using typename WeaknessPolicy::IsStrongPersistent;
|
57
|
+
using PointeeType = T;
|
58
|
+
|
59
|
+
// Null-state/sentinel constructors.
|
60
|
+
BasicPersistent( // NOLINT
|
61
|
+
const SourceLocation& loc = SourceLocation::Current())
|
62
|
+
: LocationPolicy(loc) {}
|
63
|
+
|
64
|
+
BasicPersistent(std::nullptr_t, // NOLINT
|
65
|
+
const SourceLocation& loc = SourceLocation::Current())
|
66
|
+
: LocationPolicy(loc) {}
|
67
|
+
|
68
|
+
BasicPersistent( // NOLINT
|
69
|
+
SentinelPointer s, const SourceLocation& loc = SourceLocation::Current())
|
70
|
+
: PersistentBase(s), LocationPolicy(loc) {}
|
71
|
+
|
72
|
+
// Raw value constructors.
|
73
|
+
BasicPersistent(T* raw, // NOLINT
|
74
|
+
const SourceLocation& loc = SourceLocation::Current())
|
75
|
+
: PersistentBase(raw), LocationPolicy(loc) {
|
76
|
+
if (!IsValid()) return;
|
77
|
+
SetNode(WeaknessPolicy::GetPersistentRegion(GetValue())
|
78
|
+
.AllocateNode(this, &BasicPersistent::Trace));
|
79
|
+
this->CheckPointer(Get());
|
80
|
+
}
|
81
|
+
|
82
|
+
BasicPersistent(T& raw, // NOLINT
|
83
|
+
const SourceLocation& loc = SourceLocation::Current())
|
84
|
+
: BasicPersistent(&raw, loc) {}
|
85
|
+
|
86
|
+
// Copy ctor.
|
87
|
+
BasicPersistent(const BasicPersistent& other,
|
88
|
+
const SourceLocation& loc = SourceLocation::Current())
|
89
|
+
: BasicPersistent(other.Get(), loc) {}
|
90
|
+
|
91
|
+
// Heterogeneous ctor.
|
92
|
+
template <typename U, typename OtherWeaknessPolicy,
|
93
|
+
typename OtherLocationPolicy, typename OtherCheckingPolicy,
|
94
|
+
typename = std::enable_if_t<std::is_base_of<T, U>::value>>
|
95
|
+
BasicPersistent( // NOLINT
|
96
|
+
const BasicPersistent<U, OtherWeaknessPolicy, OtherLocationPolicy,
|
97
|
+
OtherCheckingPolicy>& other,
|
98
|
+
const SourceLocation& loc = SourceLocation::Current())
|
99
|
+
: BasicPersistent(other.Get(), loc) {}
|
100
|
+
|
101
|
+
// Move ctor. The heterogeneous move ctor is not supported since e.g.
|
102
|
+
// persistent can't reuse persistent node from weak persistent.
|
103
|
+
BasicPersistent(
|
104
|
+
BasicPersistent&& other,
|
105
|
+
const SourceLocation& loc = SourceLocation::Current()) noexcept
|
106
|
+
: PersistentBase(std::move(other)), LocationPolicy(std::move(other)) {
|
107
|
+
if (!IsValid()) return;
|
108
|
+
GetNode()->UpdateOwner(this);
|
109
|
+
other.SetValue(nullptr);
|
110
|
+
other.SetNode(nullptr);
|
111
|
+
this->CheckPointer(Get());
|
112
|
+
}
|
113
|
+
|
114
|
+
// Constructor from member.
|
115
|
+
template <typename U, typename MemberBarrierPolicy,
|
116
|
+
typename MemberWeaknessTag, typename MemberCheckingPolicy,
|
117
|
+
typename = std::enable_if_t<std::is_base_of<T, U>::value>>
|
118
|
+
BasicPersistent(internal::BasicMember<U, MemberBarrierPolicy, // NOLINT
|
119
|
+
MemberWeaknessTag, MemberCheckingPolicy>
|
120
|
+
member,
|
121
|
+
const SourceLocation& loc = SourceLocation::Current())
|
122
|
+
: BasicPersistent(member.Get(), loc) {}
|
123
|
+
|
124
|
+
~BasicPersistent() { Clear(); }
|
125
|
+
|
126
|
+
// Copy assignment.
|
127
|
+
BasicPersistent& operator=(const BasicPersistent& other) {
|
128
|
+
return operator=(other.Get());
|
129
|
+
}
|
130
|
+
|
131
|
+
template <typename U, typename OtherWeaknessPolicy,
|
132
|
+
typename OtherLocationPolicy, typename OtherCheckingPolicy,
|
133
|
+
typename = std::enable_if_t<std::is_base_of<T, U>::value>>
|
134
|
+
BasicPersistent& operator=(
|
135
|
+
const BasicPersistent<U, OtherWeaknessPolicy, OtherLocationPolicy,
|
136
|
+
OtherCheckingPolicy>& other) {
|
137
|
+
return operator=(other.Get());
|
138
|
+
}
|
139
|
+
|
140
|
+
// Move assignment.
|
141
|
+
BasicPersistent& operator=(BasicPersistent&& other) {
|
142
|
+
if (this == &other) return *this;
|
143
|
+
Clear();
|
144
|
+
PersistentBase::operator=(std::move(other));
|
145
|
+
LocationPolicy::operator=(std::move(other));
|
146
|
+
if (!IsValid()) return *this;
|
147
|
+
GetNode()->UpdateOwner(this);
|
148
|
+
other.SetValue(nullptr);
|
149
|
+
other.SetNode(nullptr);
|
150
|
+
this->CheckPointer(Get());
|
151
|
+
return *this;
|
152
|
+
}
|
153
|
+
|
154
|
+
// Assignment from member.
|
155
|
+
template <typename U, typename MemberBarrierPolicy,
|
156
|
+
typename MemberWeaknessTag, typename MemberCheckingPolicy,
|
157
|
+
typename = std::enable_if_t<std::is_base_of<T, U>::value>>
|
158
|
+
BasicPersistent& operator=(
|
159
|
+
internal::BasicMember<U, MemberBarrierPolicy, MemberWeaknessTag,
|
160
|
+
MemberCheckingPolicy>
|
161
|
+
member) {
|
162
|
+
return operator=(member.Get());
|
163
|
+
}
|
164
|
+
|
165
|
+
BasicPersistent& operator=(T* other) {
|
166
|
+
Assign(other);
|
167
|
+
return *this;
|
168
|
+
}
|
169
|
+
|
170
|
+
BasicPersistent& operator=(std::nullptr_t) {
|
171
|
+
Clear();
|
172
|
+
return *this;
|
173
|
+
}
|
174
|
+
|
175
|
+
BasicPersistent& operator=(SentinelPointer s) {
|
176
|
+
Assign(s);
|
177
|
+
return *this;
|
178
|
+
}
|
179
|
+
|
180
|
+
explicit operator bool() const { return Get(); }
|
181
|
+
operator T*() const { return Get(); }
|
182
|
+
T* operator->() const { return Get(); }
|
183
|
+
T& operator*() const { return *Get(); }
|
184
|
+
|
185
|
+
// CFI cast exemption to allow passing SentinelPointer through T* and support
|
186
|
+
// heterogeneous assignments between different Member and Persistent handles
|
187
|
+
// based on their actual types.
|
188
|
+
V8_CLANG_NO_SANITIZE("cfi-unrelated-cast") T* Get() const {
|
189
|
+
return static_cast<T*>(GetValue());
|
190
|
+
}
|
191
|
+
|
192
|
+
void Clear() { Assign(nullptr); }
|
193
|
+
|
194
|
+
T* Release() {
|
195
|
+
T* result = Get();
|
196
|
+
Clear();
|
197
|
+
return result;
|
198
|
+
}
|
199
|
+
|
200
|
+
private:
|
201
|
+
static void Trace(Visitor* v, const void* ptr) {
|
202
|
+
const auto* persistent = static_cast<const BasicPersistent*>(ptr);
|
203
|
+
v->TraceRoot(*persistent, persistent->Location());
|
204
|
+
}
|
205
|
+
|
206
|
+
bool IsValid() const {
|
207
|
+
// Ideally, handling kSentinelPointer would be done by the embedder. On the
|
208
|
+
// other hand, having Persistent aware of it is beneficial since no node
|
209
|
+
// gets wasted.
|
210
|
+
return GetValue() != nullptr && GetValue() != kSentinelPointer;
|
211
|
+
}
|
212
|
+
|
213
|
+
void Assign(T* ptr) {
|
214
|
+
if (IsValid()) {
|
215
|
+
if (ptr && ptr != kSentinelPointer) {
|
216
|
+
// Simply assign the pointer reusing the existing node.
|
217
|
+
SetValue(ptr);
|
218
|
+
this->CheckPointer(ptr);
|
219
|
+
return;
|
220
|
+
}
|
221
|
+
WeaknessPolicy::GetPersistentRegion(GetValue()).FreeNode(GetNode());
|
222
|
+
SetNode(nullptr);
|
223
|
+
}
|
224
|
+
SetValue(ptr);
|
225
|
+
if (!IsValid()) return;
|
226
|
+
SetNode(WeaknessPolicy::GetPersistentRegion(GetValue())
|
227
|
+
.AllocateNode(this, &BasicPersistent::Trace));
|
228
|
+
this->CheckPointer(Get());
|
229
|
+
}
|
230
|
+
|
231
|
+
void ClearFromGC() const {
|
232
|
+
if (IsValid()) {
|
233
|
+
WeaknessPolicy::GetPersistentRegion(GetValue()).FreeNode(GetNode());
|
234
|
+
PersistentBase::ClearFromGC();
|
235
|
+
}
|
236
|
+
}
|
237
|
+
|
238
|
+
friend class cppgc::Visitor;
|
239
|
+
};
|
240
|
+
|
241
|
+
template <typename T1, typename WeaknessPolicy1, typename LocationPolicy1,
|
242
|
+
typename CheckingPolicy1, typename T2, typename WeaknessPolicy2,
|
243
|
+
typename LocationPolicy2, typename CheckingPolicy2>
|
244
|
+
bool operator==(const BasicPersistent<T1, WeaknessPolicy1, LocationPolicy1,
|
245
|
+
CheckingPolicy1>& p1,
|
246
|
+
const BasicPersistent<T2, WeaknessPolicy2, LocationPolicy2,
|
247
|
+
CheckingPolicy2>& p2) {
|
248
|
+
return p1.Get() == p2.Get();
|
249
|
+
}
|
250
|
+
|
251
|
+
template <typename T1, typename WeaknessPolicy1, typename LocationPolicy1,
|
252
|
+
typename CheckingPolicy1, typename T2, typename WeaknessPolicy2,
|
253
|
+
typename LocationPolicy2, typename CheckingPolicy2>
|
254
|
+
bool operator!=(const BasicPersistent<T1, WeaknessPolicy1, LocationPolicy1,
|
255
|
+
CheckingPolicy1>& p1,
|
256
|
+
const BasicPersistent<T2, WeaknessPolicy2, LocationPolicy2,
|
257
|
+
CheckingPolicy2>& p2) {
|
258
|
+
return !(p1 == p2);
|
259
|
+
}
|
260
|
+
|
261
|
+
template <typename T1, typename PersistentWeaknessPolicy,
|
262
|
+
typename PersistentLocationPolicy, typename PersistentCheckingPolicy,
|
263
|
+
typename T2, typename MemberWriteBarrierPolicy,
|
264
|
+
typename MemberWeaknessTag, typename MemberCheckingPolicy>
|
265
|
+
bool operator==(const BasicPersistent<T1, PersistentWeaknessPolicy,
|
266
|
+
PersistentLocationPolicy,
|
267
|
+
PersistentCheckingPolicy>& p,
|
268
|
+
BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
|
269
|
+
MemberCheckingPolicy>
|
270
|
+
m) {
|
271
|
+
return p.Get() == m.Get();
|
272
|
+
}
|
273
|
+
|
274
|
+
template <typename T1, typename PersistentWeaknessPolicy,
|
275
|
+
typename PersistentLocationPolicy, typename PersistentCheckingPolicy,
|
276
|
+
typename T2, typename MemberWriteBarrierPolicy,
|
277
|
+
typename MemberWeaknessTag, typename MemberCheckingPolicy>
|
278
|
+
bool operator!=(const BasicPersistent<T1, PersistentWeaknessPolicy,
|
279
|
+
PersistentLocationPolicy,
|
280
|
+
PersistentCheckingPolicy>& p,
|
281
|
+
BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
|
282
|
+
MemberCheckingPolicy>
|
283
|
+
m) {
|
284
|
+
return !(p == m);
|
285
|
+
}
|
286
|
+
|
287
|
+
template <typename T1, typename MemberWriteBarrierPolicy,
|
288
|
+
typename MemberWeaknessTag, typename MemberCheckingPolicy,
|
289
|
+
typename T2, typename PersistentWeaknessPolicy,
|
290
|
+
typename PersistentLocationPolicy, typename PersistentCheckingPolicy>
|
291
|
+
bool operator==(BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
|
292
|
+
MemberCheckingPolicy>
|
293
|
+
m,
|
294
|
+
const BasicPersistent<T1, PersistentWeaknessPolicy,
|
295
|
+
PersistentLocationPolicy,
|
296
|
+
PersistentCheckingPolicy>& p) {
|
297
|
+
return m.Get() == p.Get();
|
298
|
+
}
|
299
|
+
|
300
|
+
template <typename T1, typename MemberWriteBarrierPolicy,
|
301
|
+
typename MemberWeaknessTag, typename MemberCheckingPolicy,
|
302
|
+
typename T2, typename PersistentWeaknessPolicy,
|
303
|
+
typename PersistentLocationPolicy, typename PersistentCheckingPolicy>
|
304
|
+
bool operator!=(BasicMember<T2, MemberWeaknessTag, MemberWriteBarrierPolicy,
|
305
|
+
MemberCheckingPolicy>
|
306
|
+
m,
|
307
|
+
const BasicPersistent<T1, PersistentWeaknessPolicy,
|
308
|
+
PersistentLocationPolicy,
|
309
|
+
PersistentCheckingPolicy>& p) {
|
310
|
+
return !(m == p);
|
311
|
+
}
|
312
|
+
|
313
|
+
template <typename T, typename LocationPolicy, typename CheckingPolicy>
|
314
|
+
struct IsWeak<BasicPersistent<T, internal::WeakPersistentPolicy, LocationPolicy,
|
315
|
+
CheckingPolicy>> : std::true_type {};
|
316
|
+
} // namespace internal
|
317
|
+
|
318
|
+
/**
|
319
|
+
* Persistent is a way to create a strong pointer from an off-heap object to
|
320
|
+
* another on-heap object. As long as the Persistent handle is alive the GC will
|
321
|
+
* keep the object pointed to alive. The Persistent handle is always a GC root
|
322
|
+
* from the point of view of the GC. Persistent must be constructed and
|
323
|
+
* destructed in the same thread.
|
324
|
+
*/
|
325
|
+
template <typename T>
|
326
|
+
using Persistent =
|
327
|
+
internal::BasicPersistent<T, internal::StrongPersistentPolicy>;
|
328
|
+
|
329
|
+
/**
|
330
|
+
* WeakPersistent is a way to create a weak pointer from an off-heap object to
|
331
|
+
* an on-heap object. The pointer is automatically cleared when the pointee gets
|
332
|
+
* collected. WeakPersistent must be constructed and destructed in the same
|
333
|
+
* thread.
|
334
|
+
*/
|
335
|
+
template <typename T>
|
336
|
+
using WeakPersistent =
|
337
|
+
internal::BasicPersistent<T, internal::WeakPersistentPolicy>;
|
338
|
+
|
339
|
+
} // namespace cppgc
|
340
|
+
|
341
|
+
#endif // INCLUDE_CPPGC_PERSISTENT_H_
|
@@ -0,0 +1,130 @@
|
|
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_PLATFORM_H_
|
6
|
+
#define INCLUDE_CPPGC_PLATFORM_H_
|
7
|
+
|
8
|
+
#include "v8-platform.h" // NOLINT(build/include_directory)
|
9
|
+
#include "v8config.h" // NOLINT(build/include_directory)
|
10
|
+
|
11
|
+
namespace cppgc {
|
12
|
+
|
13
|
+
// TODO(v8:10346): Create separate includes for concepts that are not
|
14
|
+
// V8-specific.
|
15
|
+
using IdleTask = v8::IdleTask;
|
16
|
+
using JobHandle = v8::JobHandle;
|
17
|
+
using JobDelegate = v8::JobDelegate;
|
18
|
+
using JobTask = v8::JobTask;
|
19
|
+
using PageAllocator = v8::PageAllocator;
|
20
|
+
using Task = v8::Task;
|
21
|
+
using TaskPriority = v8::TaskPriority;
|
22
|
+
using TaskRunner = v8::TaskRunner;
|
23
|
+
|
24
|
+
/**
|
25
|
+
* Platform interface used by Heap. Contains allocators and executors.
|
26
|
+
*/
|
27
|
+
class V8_EXPORT Platform {
|
28
|
+
public:
|
29
|
+
virtual ~Platform() = default;
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Returns the allocator used by cppgc to allocate its heap and various
|
33
|
+
* support structures.
|
34
|
+
*/
|
35
|
+
virtual PageAllocator* GetPageAllocator() = 0;
|
36
|
+
|
37
|
+
/**
|
38
|
+
* Monotonically increasing time in seconds from an arbitrary fixed point in
|
39
|
+
* the past. This function is expected to return at least
|
40
|
+
* millisecond-precision values. For this reason,
|
41
|
+
* it is recommended that the fixed point be no further in the past than
|
42
|
+
* the epoch.
|
43
|
+
**/
|
44
|
+
virtual double MonotonicallyIncreasingTime() = 0;
|
45
|
+
|
46
|
+
/**
|
47
|
+
* Foreground task runner that should be used by a Heap.
|
48
|
+
*/
|
49
|
+
virtual std::shared_ptr<TaskRunner> GetForegroundTaskRunner() {
|
50
|
+
return nullptr;
|
51
|
+
}
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Posts |job_task| to run in parallel. Returns a JobHandle associated with
|
55
|
+
* the Job, which can be joined or canceled.
|
56
|
+
* This avoids degenerate cases:
|
57
|
+
* - Calling CallOnWorkerThread() for each work item, causing significant
|
58
|
+
* overhead.
|
59
|
+
* - Fixed number of CallOnWorkerThread() calls that split the work and might
|
60
|
+
* run for a long time. This is problematic when many components post
|
61
|
+
* "num cores" tasks and all expect to use all the cores. In these cases,
|
62
|
+
* the scheduler lacks context to be fair to multiple same-priority requests
|
63
|
+
* and/or ability to request lower priority work to yield when high priority
|
64
|
+
* work comes in.
|
65
|
+
* A canonical implementation of |job_task| looks like:
|
66
|
+
* class MyJobTask : public JobTask {
|
67
|
+
* public:
|
68
|
+
* MyJobTask(...) : worker_queue_(...) {}
|
69
|
+
* // JobTask:
|
70
|
+
* void Run(JobDelegate* delegate) override {
|
71
|
+
* while (!delegate->ShouldYield()) {
|
72
|
+
* // Smallest unit of work.
|
73
|
+
* auto work_item = worker_queue_.TakeWorkItem(); // Thread safe.
|
74
|
+
* if (!work_item) return;
|
75
|
+
* ProcessWork(work_item);
|
76
|
+
* }
|
77
|
+
* }
|
78
|
+
*
|
79
|
+
* size_t GetMaxConcurrency() const override {
|
80
|
+
* return worker_queue_.GetSize(); // Thread safe.
|
81
|
+
* }
|
82
|
+
* };
|
83
|
+
* auto handle = PostJob(TaskPriority::kUserVisible,
|
84
|
+
* std::make_unique<MyJobTask>(...));
|
85
|
+
* handle->Join();
|
86
|
+
*
|
87
|
+
* PostJob() and methods of the returned JobHandle/JobDelegate, must never be
|
88
|
+
* called while holding a lock that could be acquired by JobTask::Run or
|
89
|
+
* JobTask::GetMaxConcurrency -- that could result in a deadlock. This is
|
90
|
+
* because [1] JobTask::GetMaxConcurrency may be invoked while holding
|
91
|
+
* internal lock (A), hence JobTask::GetMaxConcurrency can only use a lock (B)
|
92
|
+
* if that lock is *never* held while calling back into JobHandle from any
|
93
|
+
* thread (A=>B/B=>A deadlock) and [2] JobTask::Run or
|
94
|
+
* JobTask::GetMaxConcurrency may be invoked synchronously from JobHandle
|
95
|
+
* (B=>JobHandle::foo=>B deadlock).
|
96
|
+
*
|
97
|
+
* A sufficient PostJob() implementation that uses the default Job provided in
|
98
|
+
* libplatform looks like:
|
99
|
+
* std::unique_ptr<JobHandle> PostJob(
|
100
|
+
* TaskPriority priority, std::unique_ptr<JobTask> job_task) override {
|
101
|
+
* return std::make_unique<DefaultJobHandle>(
|
102
|
+
* std::make_shared<DefaultJobState>(
|
103
|
+
* this, std::move(job_task), kNumThreads));
|
104
|
+
* }
|
105
|
+
*/
|
106
|
+
virtual std::unique_ptr<JobHandle> PostJob(
|
107
|
+
TaskPriority priority, std::unique_ptr<JobTask> job_task) {
|
108
|
+
return nullptr;
|
109
|
+
}
|
110
|
+
};
|
111
|
+
|
112
|
+
/**
|
113
|
+
* Process-global initialization of the garbage collector. Must be called before
|
114
|
+
* creating a Heap.
|
115
|
+
*/
|
116
|
+
V8_EXPORT void InitializeProcess(PageAllocator*);
|
117
|
+
|
118
|
+
/**
|
119
|
+
* Must be called after destroying the last used heap.
|
120
|
+
*/
|
121
|
+
V8_EXPORT void ShutdownProcess();
|
122
|
+
|
123
|
+
namespace internal {
|
124
|
+
|
125
|
+
V8_EXPORT void Abort();
|
126
|
+
|
127
|
+
} // namespace internal
|
128
|
+
} // namespace cppgc
|
129
|
+
|
130
|
+
#endif // INCLUDE_CPPGC_PLATFORM_H_
|
@@ -0,0 +1,52 @@
|
|
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_PREFINALIZER_H_
|
6
|
+
#define INCLUDE_CPPGC_PREFINALIZER_H_
|
7
|
+
|
8
|
+
#include "cppgc/internal/compiler-specific.h"
|
9
|
+
#include "cppgc/internal/prefinalizer-handler.h"
|
10
|
+
#include "cppgc/liveness-broker.h"
|
11
|
+
|
12
|
+
namespace cppgc {
|
13
|
+
|
14
|
+
namespace internal {
|
15
|
+
|
16
|
+
template <typename T>
|
17
|
+
class PrefinalizerRegistration final {
|
18
|
+
public:
|
19
|
+
explicit PrefinalizerRegistration(T* self) {
|
20
|
+
static_assert(sizeof(&T::InvokePreFinalizer) > 0,
|
21
|
+
"USING_PRE_FINALIZER(T) must be defined.");
|
22
|
+
|
23
|
+
cppgc::internal::PreFinalizerRegistrationDispatcher::RegisterPrefinalizer(
|
24
|
+
{self, T::InvokePreFinalizer});
|
25
|
+
}
|
26
|
+
|
27
|
+
void* operator new(size_t, void* location) = delete;
|
28
|
+
void* operator new(size_t) = delete;
|
29
|
+
};
|
30
|
+
|
31
|
+
} // namespace internal
|
32
|
+
|
33
|
+
#define CPPGC_USING_PRE_FINALIZER(Class, PreFinalizer) \
|
34
|
+
public: \
|
35
|
+
static bool InvokePreFinalizer(const cppgc::LivenessBroker& liveness_broker, \
|
36
|
+
void* object) { \
|
37
|
+
static_assert(cppgc::internal::IsGarbageCollectedTypeV<Class>, \
|
38
|
+
"Only garbage collected objects can have prefinalizers"); \
|
39
|
+
Class* self = static_cast<Class*>(object); \
|
40
|
+
if (liveness_broker.IsHeapObjectAlive(self)) return false; \
|
41
|
+
self->Class::PreFinalizer(); \
|
42
|
+
return true; \
|
43
|
+
} \
|
44
|
+
\
|
45
|
+
private: \
|
46
|
+
CPPGC_NO_UNIQUE_ADDRESS cppgc::internal::PrefinalizerRegistration<Class> \
|
47
|
+
prefinalizer_dummy_{this}; \
|
48
|
+
static_assert(true, "Force semicolon.")
|
49
|
+
|
50
|
+
} // namespace cppgc
|
51
|
+
|
52
|
+
#endif // INCLUDE_CPPGC_PREFINALIZER_H_
|
@@ -0,0 +1,91 @@
|
|
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_SOURCE_LOCATION_H_
|
6
|
+
#define INCLUDE_CPPGC_SOURCE_LOCATION_H_
|
7
|
+
|
8
|
+
#include <string>
|
9
|
+
|
10
|
+
#include "v8config.h" // NOLINT(build/include_directory)
|
11
|
+
|
12
|
+
#if defined(__has_builtin)
|
13
|
+
#define CPPGC_SUPPORTS_SOURCE_LOCATION \
|
14
|
+
(__has_builtin(__builtin_FUNCTION) && __has_builtin(__builtin_FILE) && \
|
15
|
+
__has_builtin(__builtin_LINE)) // NOLINT
|
16
|
+
#elif defined(V8_CC_GNU) && __GNUC__ >= 7
|
17
|
+
#define CPPGC_SUPPORTS_SOURCE_LOCATION 1
|
18
|
+
#elif defined(V8_CC_INTEL) && __ICC >= 1800
|
19
|
+
#define CPPGC_SUPPORTS_SOURCE_LOCATION 1
|
20
|
+
#else
|
21
|
+
#define CPPGC_SUPPORTS_SOURCE_LOCATION 0
|
22
|
+
#endif
|
23
|
+
|
24
|
+
namespace cppgc {
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Encapsulates source location information. Mimics C++20's
|
28
|
+
* std::source_location.
|
29
|
+
*/
|
30
|
+
class V8_EXPORT SourceLocation final {
|
31
|
+
public:
|
32
|
+
/**
|
33
|
+
* Construct source location information corresponding to the location of the
|
34
|
+
* call site.
|
35
|
+
*/
|
36
|
+
#if CPPGC_SUPPORTS_SOURCE_LOCATION
|
37
|
+
static constexpr SourceLocation Current(
|
38
|
+
const char* function = __builtin_FUNCTION(),
|
39
|
+
const char* file = __builtin_FILE(), size_t line = __builtin_LINE()) {
|
40
|
+
return SourceLocation(function, file, line);
|
41
|
+
}
|
42
|
+
#else
|
43
|
+
static constexpr SourceLocation Current() { return SourceLocation(); }
|
44
|
+
#endif // CPPGC_SUPPORTS_SOURCE_LOCATION
|
45
|
+
|
46
|
+
/**
|
47
|
+
* Constructs unspecified source location information.
|
48
|
+
*/
|
49
|
+
constexpr SourceLocation() = default;
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Returns the name of the function associated with the position represented
|
53
|
+
* by this object, if any.
|
54
|
+
*
|
55
|
+
* \returns the function name as cstring.
|
56
|
+
*/
|
57
|
+
constexpr const char* Function() const { return function_; }
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Returns the name of the current source file represented by this object.
|
61
|
+
*
|
62
|
+
* \returns the file name as cstring.
|
63
|
+
*/
|
64
|
+
constexpr const char* FileName() const { return file_; }
|
65
|
+
|
66
|
+
/**
|
67
|
+
* Returns the line number represented by this object.
|
68
|
+
*
|
69
|
+
* \returns the line number.
|
70
|
+
*/
|
71
|
+
constexpr size_t Line() const { return line_; }
|
72
|
+
|
73
|
+
/**
|
74
|
+
* Returns a human-readable string representing this object.
|
75
|
+
*
|
76
|
+
* \returns a human-readable string representing source location information.
|
77
|
+
*/
|
78
|
+
std::string ToString() const;
|
79
|
+
|
80
|
+
private:
|
81
|
+
constexpr SourceLocation(const char* function, const char* file, size_t line)
|
82
|
+
: function_(function), file_(file), line_(line) {}
|
83
|
+
|
84
|
+
const char* function_ = nullptr;
|
85
|
+
const char* file_ = nullptr;
|
86
|
+
size_t line_ = 0u;
|
87
|
+
};
|
88
|
+
|
89
|
+
} // namespace cppgc
|
90
|
+
|
91
|
+
#endif // INCLUDE_CPPGC_SOURCE_LOCATION_H_
|