libv8-node 15.5.1.0.beta1-arm64-darwin-20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/ext/libv8-node/.location.yml +2 -0
  3. data/ext/libv8-node/location.rb +91 -0
  4. data/ext/libv8-node/paths.rb +30 -0
  5. data/lib/libv8-node.rb +1 -0
  6. data/lib/libv8/node.rb +11 -0
  7. data/lib/libv8/node/version.rb +7 -0
  8. data/vendor/v8/include/cppgc/allocation.h +173 -0
  9. data/vendor/v8/include/cppgc/common.h +26 -0
  10. data/vendor/v8/include/cppgc/custom-space.h +62 -0
  11. data/vendor/v8/include/cppgc/default-platform.h +76 -0
  12. data/vendor/v8/include/cppgc/garbage-collected.h +116 -0
  13. data/vendor/v8/include/cppgc/heap.h +139 -0
  14. data/vendor/v8/include/cppgc/internal/api-constants.h +47 -0
  15. data/vendor/v8/include/cppgc/internal/atomic-entry-flag.h +48 -0
  16. data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +67 -0
  17. data/vendor/v8/include/cppgc/internal/compiler-specific.h +38 -0
  18. data/vendor/v8/include/cppgc/internal/finalizer-trait.h +90 -0
  19. data/vendor/v8/include/cppgc/internal/gc-info.h +45 -0
  20. data/vendor/v8/include/cppgc/internal/logging.h +50 -0
  21. data/vendor/v8/include/cppgc/internal/persistent-node.h +116 -0
  22. data/vendor/v8/include/cppgc/internal/pointer-policies.h +134 -0
  23. data/vendor/v8/include/cppgc/internal/prefinalizer-handler.h +30 -0
  24. data/vendor/v8/include/cppgc/internal/process-heap.h +34 -0
  25. data/vendor/v8/include/cppgc/internal/write-barrier.h +78 -0
  26. data/vendor/v8/include/cppgc/liveness-broker.h +68 -0
  27. data/vendor/v8/include/cppgc/macros.h +24 -0
  28. data/vendor/v8/include/cppgc/member.h +226 -0
  29. data/vendor/v8/include/cppgc/persistent.h +341 -0
  30. data/vendor/v8/include/cppgc/platform.h +130 -0
  31. data/vendor/v8/include/cppgc/prefinalizer.h +52 -0
  32. data/vendor/v8/include/cppgc/source-location.h +91 -0
  33. data/vendor/v8/include/cppgc/trace-trait.h +111 -0
  34. data/vendor/v8/include/cppgc/type-traits.h +109 -0
  35. data/vendor/v8/include/cppgc/visitor.h +213 -0
  36. data/vendor/v8/include/libplatform/libplatform-export.h +29 -0
  37. data/vendor/v8/include/libplatform/libplatform.h +106 -0
  38. data/vendor/v8/include/libplatform/v8-tracing.h +332 -0
  39. data/vendor/v8/include/v8-cppgc.h +226 -0
  40. data/vendor/v8/include/v8-fast-api-calls.h +388 -0
  41. data/vendor/v8/include/v8-inspector-protocol.h +13 -0
  42. data/vendor/v8/include/v8-inspector.h +327 -0
  43. data/vendor/v8/include/v8-internal.h +427 -0
  44. data/vendor/v8/include/v8-metrics.h +133 -0
  45. data/vendor/v8/include/v8-platform.h +684 -0
  46. data/vendor/v8/include/v8-profiler.h +1059 -0
  47. data/vendor/v8/include/v8-util.h +652 -0
  48. data/vendor/v8/include/v8-value-serializer-version.h +24 -0
  49. data/vendor/v8/include/v8-version-string.h +38 -0
  50. data/vendor/v8/include/v8-version.h +20 -0
  51. data/vendor/v8/include/v8-wasm-trap-handler-posix.h +31 -0
  52. data/vendor/v8/include/v8-wasm-trap-handler-win.h +28 -0
  53. data/vendor/v8/include/v8.h +12098 -0
  54. data/vendor/v8/include/v8config.h +484 -0
  55. data/vendor/v8/out.gn/libv8/obj/libv8_monolith.a +0 -0
  56. metadata +112 -0
@@ -0,0 +1,213 @@
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_VISITOR_H_
6
+ #define INCLUDE_CPPGC_VISITOR_H_
7
+
8
+ #include "cppgc/garbage-collected.h"
9
+ #include "cppgc/internal/logging.h"
10
+ #include "cppgc/internal/pointer-policies.h"
11
+ #include "cppgc/liveness-broker.h"
12
+ #include "cppgc/member.h"
13
+ #include "cppgc/source-location.h"
14
+ #include "cppgc/trace-trait.h"
15
+
16
+ namespace cppgc {
17
+
18
+ namespace internal {
19
+ template <typename T, typename WeaknessPolicy, typename LocationPolicy,
20
+ typename CheckingPolicy>
21
+ class BasicPersistent;
22
+ class ConservativeTracingVisitor;
23
+ class VisitorBase;
24
+ class VisitorFactory;
25
+
26
+ } // namespace internal
27
+
28
+ using WeakCallback = void (*)(const LivenessBroker&, const void*);
29
+
30
+ /**
31
+ * Visitor passed to trace methods. All managed pointers must have called the
32
+ * Visitor's trace method on them.
33
+ *
34
+ * \code
35
+ * class Foo final : public GarbageCollected<Foo> {
36
+ * public:
37
+ * void Trace(Visitor* visitor) const {
38
+ * visitor->Trace(foo_);
39
+ * visitor->Trace(weak_foo_);
40
+ * }
41
+ * private:
42
+ * Member<Foo> foo_;
43
+ * WeakMember<Foo> weak_foo_;
44
+ * };
45
+ * \endcode
46
+ */
47
+ class Visitor {
48
+ public:
49
+ class Key {
50
+ private:
51
+ Key() = default;
52
+ friend class internal::VisitorFactory;
53
+ };
54
+
55
+ explicit Visitor(Key) {}
56
+
57
+ virtual ~Visitor() = default;
58
+
59
+ /**
60
+ * Trace method for Member.
61
+ *
62
+ * \param member Member reference retaining an object.
63
+ */
64
+ template <typename T>
65
+ void Trace(const Member<T>& member) {
66
+ const T* value = member.GetRawAtomic();
67
+ CPPGC_DCHECK(value != kSentinelPointer);
68
+ Trace(value);
69
+ }
70
+
71
+ /**
72
+ * Trace method for WeakMember.
73
+ *
74
+ * \param weak_member WeakMember reference weakly retaining an object.
75
+ */
76
+ template <typename T>
77
+ void Trace(const WeakMember<T>& weak_member) {
78
+ static_assert(sizeof(T), "Pointee type must be fully defined.");
79
+ static_assert(internal::IsGarbageCollectedType<T>::value,
80
+ "T must be GarbageCollected or GarbageCollectedMixin type");
81
+
82
+ const T* value = weak_member.GetRawAtomic();
83
+
84
+ // Bailout assumes that WeakMember emits write barrier.
85
+ if (!value) {
86
+ return;
87
+ }
88
+
89
+ // TODO(chromium:1056170): DCHECK (or similar) for deleted values as they
90
+ // should come in at a different path.
91
+ VisitWeak(value, TraceTrait<T>::GetTraceDescriptor(value),
92
+ &HandleWeak<WeakMember<T>>, &weak_member);
93
+ }
94
+
95
+ /**
96
+ * Trace method for inlined objects that are not allocated themselves but
97
+ * otherwise follow managed heap layout and have a Trace() method.
98
+ *
99
+ * \param object reference of the inlined object.
100
+ */
101
+ template <typename T>
102
+ void Trace(const T& object) {
103
+ #if V8_ENABLE_CHECKS
104
+ // This object is embedded in potentially multiple nested objects. The
105
+ // outermost object must not be in construction as such objects are (a) not
106
+ // processed immediately, and (b) only processed conservatively if not
107
+ // otherwise possible.
108
+ CheckObjectNotInConstruction(&object);
109
+ #endif // V8_ENABLE_CHECKS
110
+ TraceTrait<T>::Trace(this, &object);
111
+ }
112
+
113
+ /**
114
+ * Registers a weak callback method on the object of type T. See
115
+ * LivenessBroker for an usage example.
116
+ *
117
+ * \param object of type T specifying a weak callback method.
118
+ */
119
+ template <typename T, void (T::*method)(const LivenessBroker&)>
120
+ void RegisterWeakCallbackMethod(const T* object) {
121
+ RegisterWeakCallback(&WeakCallbackMethodDelegate<T, method>, object);
122
+ }
123
+
124
+ /**
125
+ * Registers a weak callback that is invoked during garbage collection.
126
+ *
127
+ * \param callback to be invoked.
128
+ * \param data custom data that is passed to the callback.
129
+ */
130
+ virtual void RegisterWeakCallback(WeakCallback callback, const void* data) {}
131
+
132
+ protected:
133
+ virtual void Visit(const void* self, TraceDescriptor) {}
134
+ virtual void VisitWeak(const void* self, TraceDescriptor, WeakCallback,
135
+ const void* weak_member) {}
136
+ virtual void VisitRoot(const void*, TraceDescriptor) {}
137
+ virtual void VisitWeakRoot(const void* self, TraceDescriptor, WeakCallback,
138
+ const void* weak_root) {}
139
+
140
+ private:
141
+ template <typename T, void (T::*method)(const LivenessBroker&)>
142
+ static void WeakCallbackMethodDelegate(const LivenessBroker& info,
143
+ const void* self) {
144
+ // Callback is registered through a potential const Trace method but needs
145
+ // to be able to modify fields. See HandleWeak.
146
+ (const_cast<T*>(static_cast<const T*>(self))->*method)(info);
147
+ }
148
+
149
+ template <typename PointerType>
150
+ static void HandleWeak(const LivenessBroker& info, const void* object) {
151
+ const PointerType* weak = static_cast<const PointerType*>(object);
152
+ // Sentinel values are preserved for weak pointers.
153
+ if (*weak == kSentinelPointer) return;
154
+ const auto* raw = weak->Get();
155
+ if (!info.IsHeapObjectAlive(raw)) {
156
+ weak->ClearFromGC();
157
+ }
158
+ }
159
+
160
+ template <typename Persistent,
161
+ std::enable_if_t<Persistent::IsStrongPersistent::value>* = nullptr>
162
+ void TraceRoot(const Persistent& p, const SourceLocation& loc) {
163
+ using PointeeType = typename Persistent::PointeeType;
164
+ static_assert(sizeof(PointeeType),
165
+ "Persistent's pointee type must be fully defined");
166
+ static_assert(internal::IsGarbageCollectedType<PointeeType>::value,
167
+ "Persistent's pointee type must be GarbageCollected or "
168
+ "GarbageCollectedMixin");
169
+ if (!p.Get()) {
170
+ return;
171
+ }
172
+ VisitRoot(p.Get(), TraceTrait<PointeeType>::GetTraceDescriptor(p.Get()));
173
+ }
174
+
175
+ template <
176
+ typename WeakPersistent,
177
+ std::enable_if_t<!WeakPersistent::IsStrongPersistent::value>* = nullptr>
178
+ void TraceRoot(const WeakPersistent& p, const SourceLocation& loc) {
179
+ using PointeeType = typename WeakPersistent::PointeeType;
180
+ static_assert(sizeof(PointeeType),
181
+ "Persistent's pointee type must be fully defined");
182
+ static_assert(internal::IsGarbageCollectedType<PointeeType>::value,
183
+ "Persistent's pointee type must be GarbageCollected or "
184
+ "GarbageCollectedMixin");
185
+ VisitWeakRoot(p.Get(), TraceTrait<PointeeType>::GetTraceDescriptor(p.Get()),
186
+ &HandleWeak<WeakPersistent>, &p);
187
+ }
188
+
189
+ template <typename T>
190
+ void Trace(const T* t) {
191
+ static_assert(sizeof(T), "Pointee type must be fully defined.");
192
+ static_assert(internal::IsGarbageCollectedType<T>::value,
193
+ "T must be GarbageCollected or GarbageCollectedMixin type");
194
+ if (!t) {
195
+ return;
196
+ }
197
+ Visit(t, TraceTrait<T>::GetTraceDescriptor(t));
198
+ }
199
+
200
+ #if V8_ENABLE_CHECKS
201
+ V8_EXPORT void CheckObjectNotInConstruction(const void* address);
202
+ #endif // V8_ENABLE_CHECKS
203
+
204
+ template <typename T, typename WeaknessPolicy, typename LocationPolicy,
205
+ typename CheckingPolicy>
206
+ friend class internal::BasicPersistent;
207
+ friend class internal::ConservativeTracingVisitor;
208
+ friend class internal::VisitorBase;
209
+ };
210
+
211
+ } // namespace cppgc
212
+
213
+ #endif // INCLUDE_CPPGC_VISITOR_H_
@@ -0,0 +1,29 @@
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_LIBPLATFORM_EXPORT_H_
6
+ #define V8_LIBPLATFORM_LIBPLATFORM_EXPORT_H_
7
+
8
+ #if defined(_WIN32)
9
+
10
+ #ifdef BUILDING_V8_PLATFORM_SHARED
11
+ #define V8_PLATFORM_EXPORT __declspec(dllexport)
12
+ #elif USING_V8_PLATFORM_SHARED
13
+ #define V8_PLATFORM_EXPORT __declspec(dllimport)
14
+ #else
15
+ #define V8_PLATFORM_EXPORT
16
+ #endif // BUILDING_V8_PLATFORM_SHARED
17
+
18
+ #else // defined(_WIN32)
19
+
20
+ // Setup for Linux shared library export.
21
+ #ifdef BUILDING_V8_PLATFORM_SHARED
22
+ #define V8_PLATFORM_EXPORT __attribute__((visibility("default")))
23
+ #else
24
+ #define V8_PLATFORM_EXPORT
25
+ #endif
26
+
27
+ #endif // defined(_WIN32)
28
+
29
+ #endif // V8_LIBPLATFORM_LIBPLATFORM_EXPORT_H_
@@ -0,0 +1,106 @@
1
+ // Copyright 2014 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_LIBPLATFORM_H_
6
+ #define V8_LIBPLATFORM_LIBPLATFORM_H_
7
+
8
+ #include <memory>
9
+
10
+ #include "libplatform/libplatform-export.h"
11
+ #include "libplatform/v8-tracing.h"
12
+ #include "v8-platform.h" // NOLINT(build/include_directory)
13
+ #include "v8config.h" // NOLINT(build/include_directory)
14
+
15
+ namespace v8 {
16
+ namespace platform {
17
+
18
+ enum class IdleTaskSupport { kDisabled, kEnabled };
19
+ enum class InProcessStackDumping { kDisabled, kEnabled };
20
+
21
+ enum class MessageLoopBehavior : bool {
22
+ kDoNotWait = false,
23
+ kWaitForWork = true
24
+ };
25
+
26
+ /**
27
+ * Returns a new instance of the default v8::Platform implementation.
28
+ *
29
+ * The caller will take ownership of the returned pointer. |thread_pool_size|
30
+ * is the number of worker threads to allocate for background jobs. If a value
31
+ * of zero is passed, a suitable default based on the current number of
32
+ * processors online will be chosen.
33
+ * If |idle_task_support| is enabled then the platform will accept idle
34
+ * tasks (IdleTasksEnabled will return true) and will rely on the embedder
35
+ * calling v8::platform::RunIdleTasks to process the idle tasks.
36
+ * If |tracing_controller| is nullptr, the default platform will create a
37
+ * v8::platform::TracingController instance and use it.
38
+ */
39
+ V8_PLATFORM_EXPORT std::unique_ptr<v8::Platform> NewDefaultPlatform(
40
+ int thread_pool_size = 0,
41
+ IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
42
+ InProcessStackDumping in_process_stack_dumping =
43
+ InProcessStackDumping::kDisabled,
44
+ std::unique_ptr<v8::TracingController> tracing_controller = {});
45
+
46
+ /**
47
+ * Returns a new instance of the default v8::JobHandle implementation.
48
+ *
49
+ * The job will be executed by spawning up to |num_worker_threads| many worker
50
+ * threads on the provided |platform| with the given |priority|.
51
+ */
52
+ V8_PLATFORM_EXPORT std::unique_ptr<v8::JobHandle> NewDefaultJobHandle(
53
+ v8::Platform* platform, v8::TaskPriority priority,
54
+ std::unique_ptr<v8::JobTask> job_task, size_t num_worker_threads);
55
+
56
+ /**
57
+ * Pumps the message loop for the given isolate.
58
+ *
59
+ * The caller has to make sure that this is called from the right thread.
60
+ * Returns true if a task was executed, and false otherwise. If the call to
61
+ * PumpMessageLoop is nested within another call to PumpMessageLoop, only
62
+ * nestable tasks may run. Otherwise, any task may run. Unless requested through
63
+ * the |behavior| parameter, this call does not block if no task is pending. The
64
+ * |platform| has to be created using |NewDefaultPlatform|.
65
+ */
66
+ V8_PLATFORM_EXPORT bool PumpMessageLoop(
67
+ v8::Platform* platform, v8::Isolate* isolate,
68
+ MessageLoopBehavior behavior = MessageLoopBehavior::kDoNotWait);
69
+
70
+ /**
71
+ * Runs pending idle tasks for at most |idle_time_in_seconds| seconds.
72
+ *
73
+ * The caller has to make sure that this is called from the right thread.
74
+ * This call does not block if no task is pending. The |platform| has to be
75
+ * created using |NewDefaultPlatform|.
76
+ */
77
+ V8_PLATFORM_EXPORT void RunIdleTasks(v8::Platform* platform,
78
+ v8::Isolate* isolate,
79
+ double idle_time_in_seconds);
80
+
81
+ /**
82
+ * Attempts to set the tracing controller for the given platform.
83
+ *
84
+ * The |platform| has to be created using |NewDefaultPlatform|.
85
+ *
86
+ */
87
+ V8_DEPRECATE_SOON("Access the DefaultPlatform directly")
88
+ V8_PLATFORM_EXPORT void SetTracingController(
89
+ v8::Platform* platform,
90
+ v8::platform::tracing::TracingController* tracing_controller);
91
+
92
+ /**
93
+ * Notifies the given platform about the Isolate getting deleted soon. Has to be
94
+ * called for all Isolates which are deleted - unless we're shutting down the
95
+ * platform.
96
+ *
97
+ * The |platform| has to be created using |NewDefaultPlatform|.
98
+ *
99
+ */
100
+ V8_PLATFORM_EXPORT void NotifyIsolateShutdown(v8::Platform* platform,
101
+ Isolate* isolate);
102
+
103
+ } // namespace platform
104
+ } // namespace v8
105
+
106
+ #endif // V8_LIBPLATFORM_LIBPLATFORM_H_
@@ -0,0 +1,332 @@
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
+ private:
129
+ // Disallow copy and assign
130
+ TraceWriter(const TraceWriter&) = delete;
131
+ void operator=(const TraceWriter&) = delete;
132
+ };
133
+
134
+ class V8_PLATFORM_EXPORT TraceBufferChunk {
135
+ public:
136
+ explicit TraceBufferChunk(uint32_t seq);
137
+
138
+ void Reset(uint32_t new_seq);
139
+ bool IsFull() const { return next_free_ == kChunkSize; }
140
+ TraceObject* AddTraceEvent(size_t* event_index);
141
+ TraceObject* GetEventAt(size_t index) { return &chunk_[index]; }
142
+
143
+ uint32_t seq() const { return seq_; }
144
+ size_t size() const { return next_free_; }
145
+
146
+ static const size_t kChunkSize = 64;
147
+
148
+ private:
149
+ size_t next_free_ = 0;
150
+ TraceObject chunk_[kChunkSize];
151
+ uint32_t seq_;
152
+
153
+ // Disallow copy and assign
154
+ TraceBufferChunk(const TraceBufferChunk&) = delete;
155
+ void operator=(const TraceBufferChunk&) = delete;
156
+ };
157
+
158
+ class V8_PLATFORM_EXPORT TraceBuffer {
159
+ public:
160
+ TraceBuffer() = default;
161
+ virtual ~TraceBuffer() = default;
162
+
163
+ virtual TraceObject* AddTraceEvent(uint64_t* handle) = 0;
164
+ virtual TraceObject* GetEventByHandle(uint64_t handle) = 0;
165
+ virtual bool Flush() = 0;
166
+
167
+ static const size_t kRingBufferChunks = 1024;
168
+
169
+ static TraceBuffer* CreateTraceBufferRingBuffer(size_t max_chunks,
170
+ TraceWriter* trace_writer);
171
+
172
+ private:
173
+ // Disallow copy and assign
174
+ TraceBuffer(const TraceBuffer&) = delete;
175
+ void operator=(const TraceBuffer&) = delete;
176
+ };
177
+
178
+ // Options determines how the trace buffer stores data.
179
+ enum TraceRecordMode {
180
+ // Record until the trace buffer is full.
181
+ RECORD_UNTIL_FULL,
182
+
183
+ // Record until the user ends the trace. The trace buffer is a fixed size
184
+ // and we use it as a ring buffer during recording.
185
+ RECORD_CONTINUOUSLY,
186
+
187
+ // Record until the trace buffer is full, but with a huge buffer size.
188
+ RECORD_AS_MUCH_AS_POSSIBLE,
189
+
190
+ // Echo to console. Events are discarded.
191
+ ECHO_TO_CONSOLE,
192
+ };
193
+
194
+ class V8_PLATFORM_EXPORT TraceConfig {
195
+ public:
196
+ typedef std::vector<std::string> StringList;
197
+
198
+ static TraceConfig* CreateDefaultTraceConfig();
199
+
200
+ TraceConfig() : enable_systrace_(false), enable_argument_filter_(false) {}
201
+ TraceRecordMode GetTraceRecordMode() const { return record_mode_; }
202
+ const StringList& GetEnabledCategories() const {
203
+ return included_categories_;
204
+ }
205
+ bool IsSystraceEnabled() const { return enable_systrace_; }
206
+ bool IsArgumentFilterEnabled() const { return enable_argument_filter_; }
207
+
208
+ void SetTraceRecordMode(TraceRecordMode mode) { record_mode_ = mode; }
209
+ void EnableSystrace() { enable_systrace_ = true; }
210
+ void EnableArgumentFilter() { enable_argument_filter_ = true; }
211
+
212
+ void AddIncludedCategory(const char* included_category);
213
+
214
+ bool IsCategoryGroupEnabled(const char* category_group) const;
215
+
216
+ private:
217
+ TraceRecordMode record_mode_;
218
+ bool enable_systrace_ : 1;
219
+ bool enable_argument_filter_ : 1;
220
+ StringList included_categories_;
221
+
222
+ // Disallow copy and assign
223
+ TraceConfig(const TraceConfig&) = delete;
224
+ void operator=(const TraceConfig&) = delete;
225
+ };
226
+
227
+ #if defined(_MSC_VER)
228
+ #define V8_PLATFORM_NON_EXPORTED_BASE(code) \
229
+ __pragma(warning(suppress : 4275)) code
230
+ #else
231
+ #define V8_PLATFORM_NON_EXPORTED_BASE(code) code
232
+ #endif // defined(_MSC_VER)
233
+
234
+ class V8_PLATFORM_EXPORT TracingController
235
+ : public V8_PLATFORM_NON_EXPORTED_BASE(v8::TracingController) {
236
+ public:
237
+ TracingController();
238
+ ~TracingController() override;
239
+
240
+ #if defined(V8_USE_PERFETTO)
241
+ // Must be called before StartTracing() if V8_USE_PERFETTO is true. Provides
242
+ // the output stream for the JSON trace data.
243
+ void InitializeForPerfetto(std::ostream* output_stream);
244
+ // Provide an optional listener for testing that will receive trace events.
245
+ // Must be called before StartTracing().
246
+ void SetTraceEventListenerForTesting(TraceEventListener* listener);
247
+ #else // defined(V8_USE_PERFETTO)
248
+ // The pointer returned from GetCategoryGroupEnabled() points to a value with
249
+ // zero or more of the following bits. Used in this class only. The
250
+ // TRACE_EVENT macros should only use the value as a bool. These values must
251
+ // be in sync with macro values in TraceEvent.h in Blink.
252
+ enum CategoryGroupEnabledFlags {
253
+ // Category group enabled for the recording mode.
254
+ ENABLED_FOR_RECORDING = 1 << 0,
255
+ // Category group enabled by SetEventCallbackEnabled().
256
+ ENABLED_FOR_EVENT_CALLBACK = 1 << 2,
257
+ // Category group enabled to export events to ETW.
258
+ ENABLED_FOR_ETW_EXPORT = 1 << 3
259
+ };
260
+
261
+ // Takes ownership of |trace_buffer|.
262
+ void Initialize(TraceBuffer* trace_buffer);
263
+
264
+ // v8::TracingController implementation.
265
+ const uint8_t* GetCategoryGroupEnabled(const char* category_group) override;
266
+ uint64_t AddTraceEvent(
267
+ char phase, const uint8_t* category_enabled_flag, const char* name,
268
+ const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
269
+ const char** arg_names, const uint8_t* arg_types,
270
+ const uint64_t* arg_values,
271
+ std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
272
+ unsigned int flags) override;
273
+ uint64_t AddTraceEventWithTimestamp(
274
+ char phase, const uint8_t* category_enabled_flag, const char* name,
275
+ const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
276
+ const char** arg_names, const uint8_t* arg_types,
277
+ const uint64_t* arg_values,
278
+ std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
279
+ unsigned int flags, int64_t timestamp) override;
280
+ void UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
281
+ const char* name, uint64_t handle) override;
282
+
283
+ static const char* GetCategoryGroupName(const uint8_t* category_enabled_flag);
284
+ #endif // !defined(V8_USE_PERFETTO)
285
+
286
+ void AddTraceStateObserver(
287
+ v8::TracingController::TraceStateObserver* observer) override;
288
+ void RemoveTraceStateObserver(
289
+ v8::TracingController::TraceStateObserver* observer) override;
290
+
291
+ void StartTracing(TraceConfig* trace_config);
292
+ void StopTracing();
293
+
294
+ protected:
295
+ #if !defined(V8_USE_PERFETTO)
296
+ virtual int64_t CurrentTimestampMicroseconds();
297
+ virtual int64_t CurrentCpuTimestampMicroseconds();
298
+ #endif // !defined(V8_USE_PERFETTO)
299
+
300
+ private:
301
+ #if !defined(V8_USE_PERFETTO)
302
+ void UpdateCategoryGroupEnabledFlag(size_t category_index);
303
+ void UpdateCategoryGroupEnabledFlags();
304
+ #endif // !defined(V8_USE_PERFETTO)
305
+
306
+ std::unique_ptr<base::Mutex> mutex_;
307
+ std::unique_ptr<TraceConfig> trace_config_;
308
+ std::atomic_bool recording_{false};
309
+ std::unordered_set<v8::TracingController::TraceStateObserver*> observers_;
310
+
311
+ #if defined(V8_USE_PERFETTO)
312
+ std::ostream* output_stream_ = nullptr;
313
+ std::unique_ptr<perfetto::trace_processor::TraceProcessorStorage>
314
+ trace_processor_;
315
+ TraceEventListener* listener_for_testing_ = nullptr;
316
+ std::unique_ptr<perfetto::TracingSession> tracing_session_;
317
+ #else // !defined(V8_USE_PERFETTO)
318
+ std::unique_ptr<TraceBuffer> trace_buffer_;
319
+ #endif // !defined(V8_USE_PERFETTO)
320
+
321
+ // Disallow copy and assign
322
+ TracingController(const TracingController&) = delete;
323
+ void operator=(const TracingController&) = delete;
324
+ };
325
+
326
+ #undef V8_PLATFORM_NON_EXPORTED_BASE
327
+
328
+ } // namespace tracing
329
+ } // namespace platform
330
+ } // namespace v8
331
+
332
+ #endif // V8_LIBPLATFORM_V8_TRACING_H_