libv8-node 16.10.0.0-arm64-darwin
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 +1 -0
- data/ext/libv8-node/location.rb +76 -0
- data/ext/libv8-node/paths.rb +34 -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/arm64-darwin/libv8/obj/libv8_monolith.a +0 -0
- data/vendor/v8/include/cppgc/allocation.h +232 -0
- data/vendor/v8/include/cppgc/common.h +29 -0
- data/vendor/v8/include/cppgc/cross-thread-persistent.h +384 -0
- data/vendor/v8/include/cppgc/custom-space.h +97 -0
- data/vendor/v8/include/cppgc/default-platform.h +75 -0
- data/vendor/v8/include/cppgc/ephemeron-pair.h +30 -0
- data/vendor/v8/include/cppgc/explicit-management.h +82 -0
- data/vendor/v8/include/cppgc/garbage-collected.h +117 -0
- data/vendor/v8/include/cppgc/heap-consistency.h +236 -0
- data/vendor/v8/include/cppgc/heap-state.h +70 -0
- data/vendor/v8/include/cppgc/heap-statistics.h +120 -0
- data/vendor/v8/include/cppgc/heap.h +201 -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 +68 -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 +76 -0
- data/vendor/v8/include/cppgc/internal/logging.h +50 -0
- data/vendor/v8/include/cppgc/internal/name-trait.h +111 -0
- data/vendor/v8/include/cppgc/internal/persistent-node.h +172 -0
- data/vendor/v8/include/cppgc/internal/pointer-policies.h +175 -0
- data/vendor/v8/include/cppgc/internal/prefinalizer-handler.h +30 -0
- data/vendor/v8/include/cppgc/internal/write-barrier.h +396 -0
- data/vendor/v8/include/cppgc/liveness-broker.h +74 -0
- data/vendor/v8/include/cppgc/macros.h +26 -0
- data/vendor/v8/include/cppgc/member.h +286 -0
- data/vendor/v8/include/cppgc/name-provider.h +65 -0
- data/vendor/v8/include/cppgc/object-size-trait.h +58 -0
- data/vendor/v8/include/cppgc/persistent.h +365 -0
- data/vendor/v8/include/cppgc/platform.h +153 -0
- data/vendor/v8/include/cppgc/prefinalizer.h +52 -0
- data/vendor/v8/include/cppgc/process-heap-statistics.h +36 -0
- data/vendor/v8/include/cppgc/sentinel-pointer.h +32 -0
- data/vendor/v8/include/cppgc/source-location.h +92 -0
- data/vendor/v8/include/cppgc/testing.h +99 -0
- data/vendor/v8/include/cppgc/trace-trait.h +116 -0
- data/vendor/v8/include/cppgc/type-traits.h +247 -0
- data/vendor/v8/include/cppgc/visitor.h +377 -0
- data/vendor/v8/include/libplatform/libplatform-export.h +29 -0
- data/vendor/v8/include/libplatform/libplatform.h +117 -0
- data/vendor/v8/include/libplatform/v8-tracing.h +334 -0
- data/vendor/v8/include/v8-cppgc.h +325 -0
- data/vendor/v8/include/v8-fast-api-calls.h +791 -0
- data/vendor/v8/include/v8-inspector-protocol.h +13 -0
- data/vendor/v8/include/v8-inspector.h +348 -0
- data/vendor/v8/include/v8-internal.h +499 -0
- data/vendor/v8/include/v8-metrics.h +202 -0
- data/vendor/v8/include/v8-platform.h +709 -0
- data/vendor/v8/include/v8-profiler.h +1123 -0
- data/vendor/v8/include/v8-unwinder-state.h +30 -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 +12648 -0
- data/vendor/v8/include/v8config.h +515 -0
- metadata +138 -0
@@ -0,0 +1,334 @@
|
|
1
|
+
// Copyright 2016 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_LIBPLATFORM_V8_TRACING_H_
|
6
|
+
#define V8_LIBPLATFORM_V8_TRACING_H_
|
7
|
+
|
8
|
+
#include <atomic>
|
9
|
+
#include <fstream>
|
10
|
+
#include <memory>
|
11
|
+
#include <unordered_set>
|
12
|
+
#include <vector>
|
13
|
+
|
14
|
+
#include "libplatform/libplatform-export.h"
|
15
|
+
#include "v8-platform.h" // NOLINT(build/include_directory)
|
16
|
+
|
17
|
+
namespace perfetto {
|
18
|
+
namespace trace_processor {
|
19
|
+
class TraceProcessorStorage;
|
20
|
+
}
|
21
|
+
class TracingSession;
|
22
|
+
}
|
23
|
+
|
24
|
+
namespace v8 {
|
25
|
+
|
26
|
+
namespace base {
|
27
|
+
class Mutex;
|
28
|
+
} // namespace base
|
29
|
+
|
30
|
+
namespace platform {
|
31
|
+
namespace tracing {
|
32
|
+
|
33
|
+
class TraceEventListener;
|
34
|
+
|
35
|
+
const int kTraceMaxNumArgs = 2;
|
36
|
+
|
37
|
+
class V8_PLATFORM_EXPORT TraceObject {
|
38
|
+
public:
|
39
|
+
union ArgValue {
|
40
|
+
V8_DEPRECATED("use as_uint ? true : false") bool as_bool;
|
41
|
+
uint64_t as_uint;
|
42
|
+
int64_t as_int;
|
43
|
+
double as_double;
|
44
|
+
const void* as_pointer;
|
45
|
+
const char* as_string;
|
46
|
+
};
|
47
|
+
|
48
|
+
TraceObject() = default;
|
49
|
+
~TraceObject();
|
50
|
+
void Initialize(
|
51
|
+
char phase, const uint8_t* category_enabled_flag, const char* name,
|
52
|
+
const char* scope, uint64_t id, uint64_t bind_id, int num_args,
|
53
|
+
const char** arg_names, const uint8_t* arg_types,
|
54
|
+
const uint64_t* arg_values,
|
55
|
+
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
|
56
|
+
unsigned int flags, int64_t timestamp, int64_t cpu_timestamp);
|
57
|
+
void UpdateDuration(int64_t timestamp, int64_t cpu_timestamp);
|
58
|
+
void InitializeForTesting(
|
59
|
+
char phase, const uint8_t* category_enabled_flag, const char* name,
|
60
|
+
const char* scope, uint64_t id, uint64_t bind_id, int num_args,
|
61
|
+
const char** arg_names, const uint8_t* arg_types,
|
62
|
+
const uint64_t* arg_values,
|
63
|
+
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
|
64
|
+
unsigned int flags, int pid, int tid, int64_t ts, int64_t tts,
|
65
|
+
uint64_t duration, uint64_t cpu_duration);
|
66
|
+
|
67
|
+
int pid() const { return pid_; }
|
68
|
+
int tid() const { return tid_; }
|
69
|
+
char phase() const { return phase_; }
|
70
|
+
const uint8_t* category_enabled_flag() const {
|
71
|
+
return category_enabled_flag_;
|
72
|
+
}
|
73
|
+
const char* name() const { return name_; }
|
74
|
+
const char* scope() const { return scope_; }
|
75
|
+
uint64_t id() const { return id_; }
|
76
|
+
uint64_t bind_id() const { return bind_id_; }
|
77
|
+
int num_args() const { return num_args_; }
|
78
|
+
const char** arg_names() { return arg_names_; }
|
79
|
+
uint8_t* arg_types() { return arg_types_; }
|
80
|
+
ArgValue* arg_values() { return arg_values_; }
|
81
|
+
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables() {
|
82
|
+
return arg_convertables_;
|
83
|
+
}
|
84
|
+
unsigned int flags() const { return flags_; }
|
85
|
+
int64_t ts() { return ts_; }
|
86
|
+
int64_t tts() { return tts_; }
|
87
|
+
uint64_t duration() { return duration_; }
|
88
|
+
uint64_t cpu_duration() { return cpu_duration_; }
|
89
|
+
|
90
|
+
private:
|
91
|
+
int pid_;
|
92
|
+
int tid_;
|
93
|
+
char phase_;
|
94
|
+
const char* name_;
|
95
|
+
const char* scope_;
|
96
|
+
const uint8_t* category_enabled_flag_;
|
97
|
+
uint64_t id_;
|
98
|
+
uint64_t bind_id_;
|
99
|
+
int num_args_ = 0;
|
100
|
+
const char* arg_names_[kTraceMaxNumArgs];
|
101
|
+
uint8_t arg_types_[kTraceMaxNumArgs];
|
102
|
+
ArgValue arg_values_[kTraceMaxNumArgs];
|
103
|
+
std::unique_ptr<v8::ConvertableToTraceFormat>
|
104
|
+
arg_convertables_[kTraceMaxNumArgs];
|
105
|
+
char* parameter_copy_storage_ = nullptr;
|
106
|
+
unsigned int flags_;
|
107
|
+
int64_t ts_;
|
108
|
+
int64_t tts_;
|
109
|
+
uint64_t duration_;
|
110
|
+
uint64_t cpu_duration_;
|
111
|
+
|
112
|
+
// Disallow copy and assign
|
113
|
+
TraceObject(const TraceObject&) = delete;
|
114
|
+
void operator=(const TraceObject&) = delete;
|
115
|
+
};
|
116
|
+
|
117
|
+
class V8_PLATFORM_EXPORT TraceWriter {
|
118
|
+
public:
|
119
|
+
TraceWriter() = default;
|
120
|
+
virtual ~TraceWriter() = default;
|
121
|
+
virtual void AppendTraceEvent(TraceObject* trace_event) = 0;
|
122
|
+
virtual void Flush() = 0;
|
123
|
+
|
124
|
+
static TraceWriter* CreateJSONTraceWriter(std::ostream& stream);
|
125
|
+
static TraceWriter* CreateJSONTraceWriter(std::ostream& stream,
|
126
|
+
const std::string& tag);
|
127
|
+
|
128
|
+
static TraceWriter* CreateSystemInstrumentationTraceWriter();
|
129
|
+
|
130
|
+
private:
|
131
|
+
// Disallow copy and assign
|
132
|
+
TraceWriter(const TraceWriter&) = delete;
|
133
|
+
void operator=(const TraceWriter&) = delete;
|
134
|
+
};
|
135
|
+
|
136
|
+
class V8_PLATFORM_EXPORT TraceBufferChunk {
|
137
|
+
public:
|
138
|
+
explicit TraceBufferChunk(uint32_t seq);
|
139
|
+
|
140
|
+
void Reset(uint32_t new_seq);
|
141
|
+
bool IsFull() const { return next_free_ == kChunkSize; }
|
142
|
+
TraceObject* AddTraceEvent(size_t* event_index);
|
143
|
+
TraceObject* GetEventAt(size_t index) { return &chunk_[index]; }
|
144
|
+
|
145
|
+
uint32_t seq() const { return seq_; }
|
146
|
+
size_t size() const { return next_free_; }
|
147
|
+
|
148
|
+
static const size_t kChunkSize = 64;
|
149
|
+
|
150
|
+
private:
|
151
|
+
size_t next_free_ = 0;
|
152
|
+
TraceObject chunk_[kChunkSize];
|
153
|
+
uint32_t seq_;
|
154
|
+
|
155
|
+
// Disallow copy and assign
|
156
|
+
TraceBufferChunk(const TraceBufferChunk&) = delete;
|
157
|
+
void operator=(const TraceBufferChunk&) = delete;
|
158
|
+
};
|
159
|
+
|
160
|
+
class V8_PLATFORM_EXPORT TraceBuffer {
|
161
|
+
public:
|
162
|
+
TraceBuffer() = default;
|
163
|
+
virtual ~TraceBuffer() = default;
|
164
|
+
|
165
|
+
virtual TraceObject* AddTraceEvent(uint64_t* handle) = 0;
|
166
|
+
virtual TraceObject* GetEventByHandle(uint64_t handle) = 0;
|
167
|
+
virtual bool Flush() = 0;
|
168
|
+
|
169
|
+
static const size_t kRingBufferChunks = 1024;
|
170
|
+
|
171
|
+
static TraceBuffer* CreateTraceBufferRingBuffer(size_t max_chunks,
|
172
|
+
TraceWriter* trace_writer);
|
173
|
+
|
174
|
+
private:
|
175
|
+
// Disallow copy and assign
|
176
|
+
TraceBuffer(const TraceBuffer&) = delete;
|
177
|
+
void operator=(const TraceBuffer&) = delete;
|
178
|
+
};
|
179
|
+
|
180
|
+
// Options determines how the trace buffer stores data.
|
181
|
+
enum TraceRecordMode {
|
182
|
+
// Record until the trace buffer is full.
|
183
|
+
RECORD_UNTIL_FULL,
|
184
|
+
|
185
|
+
// Record until the user ends the trace. The trace buffer is a fixed size
|
186
|
+
// and we use it as a ring buffer during recording.
|
187
|
+
RECORD_CONTINUOUSLY,
|
188
|
+
|
189
|
+
// Record until the trace buffer is full, but with a huge buffer size.
|
190
|
+
RECORD_AS_MUCH_AS_POSSIBLE,
|
191
|
+
|
192
|
+
// Echo to console. Events are discarded.
|
193
|
+
ECHO_TO_CONSOLE,
|
194
|
+
};
|
195
|
+
|
196
|
+
class V8_PLATFORM_EXPORT TraceConfig {
|
197
|
+
public:
|
198
|
+
typedef std::vector<std::string> StringList;
|
199
|
+
|
200
|
+
static TraceConfig* CreateDefaultTraceConfig();
|
201
|
+
|
202
|
+
TraceConfig() : enable_systrace_(false), enable_argument_filter_(false) {}
|
203
|
+
TraceRecordMode GetTraceRecordMode() const { return record_mode_; }
|
204
|
+
const StringList& GetEnabledCategories() const {
|
205
|
+
return included_categories_;
|
206
|
+
}
|
207
|
+
bool IsSystraceEnabled() const { return enable_systrace_; }
|
208
|
+
bool IsArgumentFilterEnabled() const { return enable_argument_filter_; }
|
209
|
+
|
210
|
+
void SetTraceRecordMode(TraceRecordMode mode) { record_mode_ = mode; }
|
211
|
+
void EnableSystrace() { enable_systrace_ = true; }
|
212
|
+
void EnableArgumentFilter() { enable_argument_filter_ = true; }
|
213
|
+
|
214
|
+
void AddIncludedCategory(const char* included_category);
|
215
|
+
|
216
|
+
bool IsCategoryGroupEnabled(const char* category_group) const;
|
217
|
+
|
218
|
+
private:
|
219
|
+
TraceRecordMode record_mode_;
|
220
|
+
bool enable_systrace_ : 1;
|
221
|
+
bool enable_argument_filter_ : 1;
|
222
|
+
StringList included_categories_;
|
223
|
+
|
224
|
+
// Disallow copy and assign
|
225
|
+
TraceConfig(const TraceConfig&) = delete;
|
226
|
+
void operator=(const TraceConfig&) = delete;
|
227
|
+
};
|
228
|
+
|
229
|
+
#if defined(_MSC_VER)
|
230
|
+
#define V8_PLATFORM_NON_EXPORTED_BASE(code) \
|
231
|
+
__pragma(warning(suppress : 4275)) code
|
232
|
+
#else
|
233
|
+
#define V8_PLATFORM_NON_EXPORTED_BASE(code) code
|
234
|
+
#endif // defined(_MSC_VER)
|
235
|
+
|
236
|
+
class V8_PLATFORM_EXPORT TracingController
|
237
|
+
: public V8_PLATFORM_NON_EXPORTED_BASE(v8::TracingController) {
|
238
|
+
public:
|
239
|
+
TracingController();
|
240
|
+
~TracingController() override;
|
241
|
+
|
242
|
+
#if defined(V8_USE_PERFETTO)
|
243
|
+
// Must be called before StartTracing() if V8_USE_PERFETTO is true. Provides
|
244
|
+
// the output stream for the JSON trace data.
|
245
|
+
void InitializeForPerfetto(std::ostream* output_stream);
|
246
|
+
// Provide an optional listener for testing that will receive trace events.
|
247
|
+
// Must be called before StartTracing().
|
248
|
+
void SetTraceEventListenerForTesting(TraceEventListener* listener);
|
249
|
+
#else // defined(V8_USE_PERFETTO)
|
250
|
+
// The pointer returned from GetCategoryGroupEnabled() points to a value with
|
251
|
+
// zero or more of the following bits. Used in this class only. The
|
252
|
+
// TRACE_EVENT macros should only use the value as a bool. These values must
|
253
|
+
// be in sync with macro values in TraceEvent.h in Blink.
|
254
|
+
enum CategoryGroupEnabledFlags {
|
255
|
+
// Category group enabled for the recording mode.
|
256
|
+
ENABLED_FOR_RECORDING = 1 << 0,
|
257
|
+
// Category group enabled by SetEventCallbackEnabled().
|
258
|
+
ENABLED_FOR_EVENT_CALLBACK = 1 << 2,
|
259
|
+
// Category group enabled to export events to ETW.
|
260
|
+
ENABLED_FOR_ETW_EXPORT = 1 << 3
|
261
|
+
};
|
262
|
+
|
263
|
+
// Takes ownership of |trace_buffer|.
|
264
|
+
void Initialize(TraceBuffer* trace_buffer);
|
265
|
+
|
266
|
+
// v8::TracingController implementation.
|
267
|
+
const uint8_t* GetCategoryGroupEnabled(const char* category_group) override;
|
268
|
+
uint64_t AddTraceEvent(
|
269
|
+
char phase, const uint8_t* category_enabled_flag, const char* name,
|
270
|
+
const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
|
271
|
+
const char** arg_names, const uint8_t* arg_types,
|
272
|
+
const uint64_t* arg_values,
|
273
|
+
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
|
274
|
+
unsigned int flags) override;
|
275
|
+
uint64_t AddTraceEventWithTimestamp(
|
276
|
+
char phase, const uint8_t* category_enabled_flag, const char* name,
|
277
|
+
const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
|
278
|
+
const char** arg_names, const uint8_t* arg_types,
|
279
|
+
const uint64_t* arg_values,
|
280
|
+
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
|
281
|
+
unsigned int flags, int64_t timestamp) override;
|
282
|
+
void UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
|
283
|
+
const char* name, uint64_t handle) override;
|
284
|
+
|
285
|
+
static const char* GetCategoryGroupName(const uint8_t* category_enabled_flag);
|
286
|
+
#endif // !defined(V8_USE_PERFETTO)
|
287
|
+
|
288
|
+
void AddTraceStateObserver(
|
289
|
+
v8::TracingController::TraceStateObserver* observer) override;
|
290
|
+
void RemoveTraceStateObserver(
|
291
|
+
v8::TracingController::TraceStateObserver* observer) override;
|
292
|
+
|
293
|
+
void StartTracing(TraceConfig* trace_config);
|
294
|
+
void StopTracing();
|
295
|
+
|
296
|
+
protected:
|
297
|
+
#if !defined(V8_USE_PERFETTO)
|
298
|
+
virtual int64_t CurrentTimestampMicroseconds();
|
299
|
+
virtual int64_t CurrentCpuTimestampMicroseconds();
|
300
|
+
#endif // !defined(V8_USE_PERFETTO)
|
301
|
+
|
302
|
+
private:
|
303
|
+
#if !defined(V8_USE_PERFETTO)
|
304
|
+
void UpdateCategoryGroupEnabledFlag(size_t category_index);
|
305
|
+
void UpdateCategoryGroupEnabledFlags();
|
306
|
+
#endif // !defined(V8_USE_PERFETTO)
|
307
|
+
|
308
|
+
std::unique_ptr<base::Mutex> mutex_;
|
309
|
+
std::unique_ptr<TraceConfig> trace_config_;
|
310
|
+
std::atomic_bool recording_{false};
|
311
|
+
std::unordered_set<v8::TracingController::TraceStateObserver*> observers_;
|
312
|
+
|
313
|
+
#if defined(V8_USE_PERFETTO)
|
314
|
+
std::ostream* output_stream_ = nullptr;
|
315
|
+
std::unique_ptr<perfetto::trace_processor::TraceProcessorStorage>
|
316
|
+
trace_processor_;
|
317
|
+
TraceEventListener* listener_for_testing_ = nullptr;
|
318
|
+
std::unique_ptr<perfetto::TracingSession> tracing_session_;
|
319
|
+
#else // !defined(V8_USE_PERFETTO)
|
320
|
+
std::unique_ptr<TraceBuffer> trace_buffer_;
|
321
|
+
#endif // !defined(V8_USE_PERFETTO)
|
322
|
+
|
323
|
+
// Disallow copy and assign
|
324
|
+
TracingController(const TracingController&) = delete;
|
325
|
+
void operator=(const TracingController&) = delete;
|
326
|
+
};
|
327
|
+
|
328
|
+
#undef V8_PLATFORM_NON_EXPORTED_BASE
|
329
|
+
|
330
|
+
} // namespace tracing
|
331
|
+
} // namespace platform
|
332
|
+
} // namespace v8
|
333
|
+
|
334
|
+
#endif // V8_LIBPLATFORM_V8_TRACING_H_
|
@@ -0,0 +1,325 @@
|
|
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_V8_CPPGC_H_
|
6
|
+
#define INCLUDE_V8_CPPGC_H_
|
7
|
+
|
8
|
+
#include <cstdint>
|
9
|
+
#include <memory>
|
10
|
+
#include <vector>
|
11
|
+
|
12
|
+
#include "cppgc/common.h"
|
13
|
+
#include "cppgc/custom-space.h"
|
14
|
+
#include "cppgc/heap-statistics.h"
|
15
|
+
#include "cppgc/internal/write-barrier.h"
|
16
|
+
#include "cppgc/visitor.h"
|
17
|
+
#include "v8-internal.h" // NOLINT(build/include_directory)
|
18
|
+
#include "v8.h" // NOLINT(build/include_directory)
|
19
|
+
|
20
|
+
namespace cppgc {
|
21
|
+
class AllocationHandle;
|
22
|
+
class HeapHandle;
|
23
|
+
} // namespace cppgc
|
24
|
+
|
25
|
+
namespace v8 {
|
26
|
+
|
27
|
+
namespace internal {
|
28
|
+
class CppHeap;
|
29
|
+
} // namespace internal
|
30
|
+
|
31
|
+
class CustomSpaceStatisticsReceiver;
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Describes how V8 wrapper objects maintain references to garbage-collected C++
|
35
|
+
* objects.
|
36
|
+
*/
|
37
|
+
struct WrapperDescriptor final {
|
38
|
+
/**
|
39
|
+
* The index used on `v8::Ojbect::SetAlignedPointerFromInternalField()` and
|
40
|
+
* related APIs to add additional data to an object which is used to identify
|
41
|
+
* JS->C++ references.
|
42
|
+
*/
|
43
|
+
using InternalFieldIndex = int;
|
44
|
+
|
45
|
+
/**
|
46
|
+
* Unknown embedder id. The value is reserved for internal usages and must not
|
47
|
+
* be used with `CppHeap`.
|
48
|
+
*/
|
49
|
+
static constexpr uint16_t kUnknownEmbedderId = UINT16_MAX;
|
50
|
+
|
51
|
+
constexpr WrapperDescriptor(InternalFieldIndex wrappable_type_index,
|
52
|
+
InternalFieldIndex wrappable_instance_index,
|
53
|
+
uint16_t embedder_id_for_garbage_collected)
|
54
|
+
: wrappable_type_index(wrappable_type_index),
|
55
|
+
wrappable_instance_index(wrappable_instance_index),
|
56
|
+
embedder_id_for_garbage_collected(embedder_id_for_garbage_collected) {}
|
57
|
+
|
58
|
+
/**
|
59
|
+
* Index of the wrappable type.
|
60
|
+
*/
|
61
|
+
InternalFieldIndex wrappable_type_index;
|
62
|
+
|
63
|
+
/**
|
64
|
+
* Index of the wrappable instance.
|
65
|
+
*/
|
66
|
+
InternalFieldIndex wrappable_instance_index;
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Embedder id identifying instances of garbage-collected objects. It is
|
70
|
+
* expected that the first field of the wrappable type is a uint16_t holding
|
71
|
+
* the id. Only references to instances of wrappables types with an id of
|
72
|
+
* `embedder_id_for_garbage_collected` will be considered by CppHeap.
|
73
|
+
*/
|
74
|
+
uint16_t embedder_id_for_garbage_collected;
|
75
|
+
};
|
76
|
+
|
77
|
+
struct V8_EXPORT CppHeapCreateParams {
|
78
|
+
CppHeapCreateParams(const CppHeapCreateParams&) = delete;
|
79
|
+
CppHeapCreateParams& operator=(const CppHeapCreateParams&) = delete;
|
80
|
+
|
81
|
+
std::vector<std::unique_ptr<cppgc::CustomSpaceBase>> custom_spaces;
|
82
|
+
WrapperDescriptor wrapper_descriptor;
|
83
|
+
};
|
84
|
+
|
85
|
+
/**
|
86
|
+
* A heap for allocating managed C++ objects.
|
87
|
+
*/
|
88
|
+
class V8_EXPORT CppHeap {
|
89
|
+
public:
|
90
|
+
static std::unique_ptr<CppHeap> Create(v8::Platform* platform,
|
91
|
+
const CppHeapCreateParams& params);
|
92
|
+
|
93
|
+
virtual ~CppHeap() = default;
|
94
|
+
|
95
|
+
/**
|
96
|
+
* \returns the opaque handle for allocating objects using
|
97
|
+
* `MakeGarbageCollected()`.
|
98
|
+
*/
|
99
|
+
cppgc::AllocationHandle& GetAllocationHandle();
|
100
|
+
|
101
|
+
/**
|
102
|
+
* \returns the opaque heap handle which may be used to refer to this heap in
|
103
|
+
* other APIs. Valid as long as the underlying `CppHeap` is alive.
|
104
|
+
*/
|
105
|
+
cppgc::HeapHandle& GetHeapHandle();
|
106
|
+
|
107
|
+
/**
|
108
|
+
* Terminate clears all roots and performs multiple garbage collections to
|
109
|
+
* reclaim potentially newly created objects in destructors.
|
110
|
+
*
|
111
|
+
* After this call, object allocation is prohibited.
|
112
|
+
*/
|
113
|
+
void Terminate();
|
114
|
+
|
115
|
+
/**
|
116
|
+
* \param detail_level specifies whether should return detailed
|
117
|
+
* statistics or only brief summary statistics.
|
118
|
+
* \returns current CppHeap statistics regarding memory consumption
|
119
|
+
* and utilization.
|
120
|
+
*/
|
121
|
+
cppgc::HeapStatistics CollectStatistics(
|
122
|
+
cppgc::HeapStatistics::DetailLevel detail_level);
|
123
|
+
|
124
|
+
/**
|
125
|
+
* Collects statistics for the given spaces and reports them to the receiver.
|
126
|
+
*
|
127
|
+
* \param custom_spaces a collection of custom space indicies.
|
128
|
+
* \param receiver an object that gets the results.
|
129
|
+
*/
|
130
|
+
void CollectCustomSpaceStatisticsAtLastGC(
|
131
|
+
std::vector<cppgc::CustomSpaceIndex> custom_spaces,
|
132
|
+
std::unique_ptr<CustomSpaceStatisticsReceiver> receiver);
|
133
|
+
|
134
|
+
/**
|
135
|
+
* Enables a detached mode that allows testing garbage collection using
|
136
|
+
* `cppgc::testing` APIs. Once used, the heap cannot be attached to an
|
137
|
+
* `Isolate` anymore.
|
138
|
+
*/
|
139
|
+
void EnableDetachedGarbageCollectionsForTesting();
|
140
|
+
|
141
|
+
/**
|
142
|
+
* Performs a stop-the-world garbage collection for testing purposes.
|
143
|
+
*
|
144
|
+
* \param stack_state The stack state to assume for the garbage collection.
|
145
|
+
*/
|
146
|
+
void CollectGarbageForTesting(cppgc::EmbedderStackState stack_state);
|
147
|
+
|
148
|
+
private:
|
149
|
+
CppHeap() = default;
|
150
|
+
|
151
|
+
friend class internal::CppHeap;
|
152
|
+
};
|
153
|
+
|
154
|
+
class JSVisitor : public cppgc::Visitor {
|
155
|
+
public:
|
156
|
+
explicit JSVisitor(cppgc::Visitor::Key key) : cppgc::Visitor(key) {}
|
157
|
+
|
158
|
+
void Trace(const TracedReferenceBase& ref) {
|
159
|
+
if (ref.IsEmptyThreadSafe()) return;
|
160
|
+
Visit(ref);
|
161
|
+
}
|
162
|
+
|
163
|
+
protected:
|
164
|
+
using cppgc::Visitor::Visit;
|
165
|
+
|
166
|
+
virtual void Visit(const TracedReferenceBase& ref) {}
|
167
|
+
};
|
168
|
+
|
169
|
+
/**
|
170
|
+
* **DO NOT USE: Use the appropriate managed types.**
|
171
|
+
*
|
172
|
+
* Consistency helpers that aid in maintaining a consistent internal state of
|
173
|
+
* the garbage collector.
|
174
|
+
*/
|
175
|
+
class V8_EXPORT JSHeapConsistency final {
|
176
|
+
public:
|
177
|
+
using WriteBarrierParams = cppgc::internal::WriteBarrier::Params;
|
178
|
+
using WriteBarrierType = cppgc::internal::WriteBarrier::Type;
|
179
|
+
|
180
|
+
/**
|
181
|
+
* Gets the required write barrier type for a specific write.
|
182
|
+
*
|
183
|
+
* Note: Handling for C++ to JS references.
|
184
|
+
*
|
185
|
+
* \param ref The reference being written to.
|
186
|
+
* \param params Parameters that may be used for actual write barrier calls.
|
187
|
+
* Only filled if return value indicates that a write barrier is needed. The
|
188
|
+
* contents of the `params` are an implementation detail.
|
189
|
+
* \param callback Callback returning the corresponding heap handle. The
|
190
|
+
* callback is only invoked if the heap cannot otherwise be figured out. The
|
191
|
+
* callback must not allocate.
|
192
|
+
* \returns whether a write barrier is needed and which barrier to invoke.
|
193
|
+
*/
|
194
|
+
template <typename HeapHandleCallback>
|
195
|
+
static V8_INLINE WriteBarrierType
|
196
|
+
GetWriteBarrierType(const TracedReferenceBase& ref,
|
197
|
+
WriteBarrierParams& params, HeapHandleCallback callback) {
|
198
|
+
if (ref.IsEmpty()) return WriteBarrierType::kNone;
|
199
|
+
|
200
|
+
if (V8_LIKELY(!cppgc::internal::WriteBarrier::
|
201
|
+
IsAnyIncrementalOrConcurrentMarking())) {
|
202
|
+
return cppgc::internal::WriteBarrier::Type::kNone;
|
203
|
+
}
|
204
|
+
cppgc::HeapHandle& handle = callback();
|
205
|
+
if (!cppgc::subtle::HeapState::IsMarking(handle)) {
|
206
|
+
return cppgc::internal::WriteBarrier::Type::kNone;
|
207
|
+
}
|
208
|
+
params.heap = &handle;
|
209
|
+
#if V8_ENABLE_CHECKS
|
210
|
+
params.type = cppgc::internal::WriteBarrier::Type::kMarking;
|
211
|
+
#endif // !V8_ENABLE_CHECKS
|
212
|
+
return cppgc::internal::WriteBarrier::Type::kMarking;
|
213
|
+
}
|
214
|
+
|
215
|
+
/**
|
216
|
+
* Gets the required write barrier type for a specific write.
|
217
|
+
*
|
218
|
+
* Note: Handling for JS to C++ references.
|
219
|
+
*
|
220
|
+
* \param wrapper The wrapper that has been written into.
|
221
|
+
* \param wrapper_index The wrapper index in `wrapper` that has been written
|
222
|
+
* into.
|
223
|
+
* \param wrappable The value that was written.
|
224
|
+
* \param params Parameters that may be used for actual write barrier calls.
|
225
|
+
* Only filled if return value indicates that a write barrier is needed. The
|
226
|
+
* contents of the `params` are an implementation detail.
|
227
|
+
* \param callback Callback returning the corresponding heap handle. The
|
228
|
+
* callback is only invoked if the heap cannot otherwise be figured out. The
|
229
|
+
* callback must not allocate.
|
230
|
+
* \returns whether a write barrier is needed and which barrier to invoke.
|
231
|
+
*/
|
232
|
+
template <typename HeapHandleCallback>
|
233
|
+
static V8_INLINE WriteBarrierType GetWriteBarrierType(
|
234
|
+
v8::Local<v8::Object>& wrapper, int wrapper_index, const void* wrappable,
|
235
|
+
WriteBarrierParams& params, HeapHandleCallback callback) {
|
236
|
+
#if V8_ENABLE_CHECKS
|
237
|
+
CheckWrapper(wrapper, wrapper_index, wrappable);
|
238
|
+
#endif // V8_ENABLE_CHECKS
|
239
|
+
return cppgc::internal::WriteBarrier::
|
240
|
+
GetWriteBarrierTypeForExternallyReferencedObject(wrappable, params,
|
241
|
+
callback);
|
242
|
+
}
|
243
|
+
|
244
|
+
/**
|
245
|
+
* Conservative Dijkstra-style write barrier that processes an object if it
|
246
|
+
* has not yet been processed.
|
247
|
+
*
|
248
|
+
* \param params The parameters retrieved from `GetWriteBarrierType()`.
|
249
|
+
* \param ref The reference being written to.
|
250
|
+
*/
|
251
|
+
static V8_INLINE void DijkstraMarkingBarrier(const WriteBarrierParams& params,
|
252
|
+
cppgc::HeapHandle& heap_handle,
|
253
|
+
const TracedReferenceBase& ref) {
|
254
|
+
cppgc::internal::WriteBarrier::CheckParams(WriteBarrierType::kMarking,
|
255
|
+
params);
|
256
|
+
DijkstraMarkingBarrierSlow(heap_handle, ref);
|
257
|
+
}
|
258
|
+
|
259
|
+
/**
|
260
|
+
* Conservative Dijkstra-style write barrier that processes an object if it
|
261
|
+
* has not yet been processed.
|
262
|
+
*
|
263
|
+
* \param params The parameters retrieved from `GetWriteBarrierType()`.
|
264
|
+
* \param object The pointer to the object. May be an interior pointer to a
|
265
|
+
* an interface of the actual object.
|
266
|
+
*/
|
267
|
+
static V8_INLINE void DijkstraMarkingBarrier(const WriteBarrierParams& params,
|
268
|
+
cppgc::HeapHandle& heap_handle,
|
269
|
+
const void* object) {
|
270
|
+
cppgc::internal::WriteBarrier::DijkstraMarkingBarrier(params, object);
|
271
|
+
}
|
272
|
+
|
273
|
+
/**
|
274
|
+
* Generational barrier for maintaining consistency when running with multiple
|
275
|
+
* generations.
|
276
|
+
*
|
277
|
+
* \param params The parameters retrieved from `GetWriteBarrierType()`.
|
278
|
+
* \param ref The reference being written to.
|
279
|
+
*/
|
280
|
+
static V8_INLINE void GenerationalBarrier(const WriteBarrierParams& params,
|
281
|
+
const TracedReferenceBase& ref) {}
|
282
|
+
|
283
|
+
private:
|
284
|
+
JSHeapConsistency() = delete;
|
285
|
+
|
286
|
+
static void CheckWrapper(v8::Local<v8::Object>&, int, const void*);
|
287
|
+
|
288
|
+
static void DijkstraMarkingBarrierSlow(cppgc::HeapHandle&,
|
289
|
+
const TracedReferenceBase& ref);
|
290
|
+
};
|
291
|
+
|
292
|
+
/**
|
293
|
+
* Provided as input to `CppHeap::CollectCustomSpaceStatisticsAtLastGC()`.
|
294
|
+
*
|
295
|
+
* Its method is invoked with the results of the statistic collection.
|
296
|
+
*/
|
297
|
+
class CustomSpaceStatisticsReceiver {
|
298
|
+
public:
|
299
|
+
virtual ~CustomSpaceStatisticsReceiver() = default;
|
300
|
+
/**
|
301
|
+
* Reports the size of a space at the last GC. It is called for each space
|
302
|
+
* that was requested in `CollectCustomSpaceStatisticsAtLastGC()`.
|
303
|
+
*
|
304
|
+
* \param space_index The index of the space.
|
305
|
+
* \param bytes The total size of live objects in the space at the last GC.
|
306
|
+
* It is zero if there was no GC yet.
|
307
|
+
*/
|
308
|
+
virtual void AllocatedBytes(cppgc::CustomSpaceIndex space_index,
|
309
|
+
size_t bytes) = 0;
|
310
|
+
};
|
311
|
+
|
312
|
+
} // namespace v8
|
313
|
+
|
314
|
+
namespace cppgc {
|
315
|
+
|
316
|
+
template <typename T>
|
317
|
+
struct TraceTrait<v8::TracedReference<T>> {
|
318
|
+
static void Trace(Visitor* visitor, const v8::TracedReference<T>* self) {
|
319
|
+
static_cast<v8::JSVisitor*>(visitor)->Trace(*self);
|
320
|
+
}
|
321
|
+
};
|
322
|
+
|
323
|
+
} // namespace cppgc
|
324
|
+
|
325
|
+
#endif // INCLUDE_V8_CPPGC_H_
|