libv8 8.4.255.0-universal-darwin-19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/libv8/.location.yml +1 -0
- data/ext/libv8/location.rb +89 -0
- data/ext/libv8/paths.rb +28 -0
- data/lib/libv8.rb +9 -0
- data/lib/libv8/version.rb +3 -0
- data/vendor/v8/include/cppgc/allocation.h +124 -0
- data/vendor/v8/include/cppgc/garbage-collected.h +192 -0
- data/vendor/v8/include/cppgc/heap.h +50 -0
- data/vendor/v8/include/cppgc/internal/accessors.h +26 -0
- data/vendor/v8/include/cppgc/internal/api-constants.h +44 -0
- data/vendor/v8/include/cppgc/internal/compiler-specific.h +26 -0
- data/vendor/v8/include/cppgc/internal/finalizer-trait.h +90 -0
- data/vendor/v8/include/cppgc/internal/gc-info.h +43 -0
- data/vendor/v8/include/cppgc/internal/logging.h +50 -0
- data/vendor/v8/include/cppgc/internal/persistent-node.h +109 -0
- data/vendor/v8/include/cppgc/internal/pointer-policies.h +133 -0
- data/vendor/v8/include/cppgc/internal/prefinalizer-handler.h +31 -0
- data/vendor/v8/include/cppgc/liveness-broker.h +50 -0
- data/vendor/v8/include/cppgc/macros.h +26 -0
- data/vendor/v8/include/cppgc/member.h +206 -0
- data/vendor/v8/include/cppgc/persistent.h +304 -0
- data/vendor/v8/include/cppgc/platform.h +31 -0
- data/vendor/v8/include/cppgc/prefinalizer.h +54 -0
- data/vendor/v8/include/cppgc/source-location.h +59 -0
- data/vendor/v8/include/cppgc/trace-trait.h +67 -0
- data/vendor/v8/include/cppgc/type-traits.h +109 -0
- data/vendor/v8/include/cppgc/visitor.h +137 -0
- data/vendor/v8/include/libplatform/libplatform-export.h +29 -0
- data/vendor/v8/include/libplatform/libplatform.h +85 -0
- data/vendor/v8/include/libplatform/v8-tracing.h +332 -0
- data/vendor/v8/include/v8-fast-api-calls.h +412 -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 +389 -0
- data/vendor/v8/include/v8-platform.h +577 -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 +12018 -0
- data/vendor/v8/include/v8config.h +465 -0
- data/vendor/v8/out.gn/libv8/obj/libv8_libbase.a +0 -0
- data/vendor/v8/out.gn/libv8/obj/libv8_libplatform.a +0 -0
- data/vendor/v8/out.gn/libv8/obj/libv8_monolith.a +0 -0
- data/vendor/v8/out.gn/libv8/obj/third_party/icu/libicui18n.a +0 -0
- data/vendor/v8/out.gn/libv8/obj/third_party/icu/libicuuc.a +0 -0
- data/vendor/v8/out.gn/libv8/obj/third_party/zlib/google/libcompression_utils_portable.a +0 -0
- data/vendor/v8/out.gn/libv8/obj/third_party/zlib/libchrome_zlib.a +0 -0
- metadata +138 -0
@@ -0,0 +1,67 @@
|
|
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_TRACE_TRAIT_H_
|
6
|
+
#define INCLUDE_CPPGC_TRACE_TRAIT_H_
|
7
|
+
|
8
|
+
#include <type_traits>
|
9
|
+
#include "cppgc/type-traits.h"
|
10
|
+
|
11
|
+
namespace cppgc {
|
12
|
+
|
13
|
+
class Visitor;
|
14
|
+
|
15
|
+
namespace internal {
|
16
|
+
|
17
|
+
template <typename T,
|
18
|
+
bool =
|
19
|
+
IsGarbageCollectedMixinTypeV<typename std::remove_const<T>::type>>
|
20
|
+
struct TraceTraitImpl;
|
21
|
+
|
22
|
+
} // namespace internal
|
23
|
+
|
24
|
+
using TraceCallback = void (*)(Visitor*, const void*);
|
25
|
+
|
26
|
+
// TraceDescriptor is used to describe how to trace an object.
|
27
|
+
struct TraceDescriptor {
|
28
|
+
// The adjusted base pointer of the object that should be traced.
|
29
|
+
const void* base_object_payload;
|
30
|
+
// A callback for tracing the object.
|
31
|
+
TraceCallback callback;
|
32
|
+
};
|
33
|
+
|
34
|
+
template <typename T>
|
35
|
+
struct TraceTrait {
|
36
|
+
static_assert(internal::IsTraceableV<T>, "T must have a Trace() method");
|
37
|
+
|
38
|
+
static TraceDescriptor GetTraceDescriptor(const void* self) {
|
39
|
+
return internal::TraceTraitImpl<T>::GetTraceDescriptor(
|
40
|
+
static_cast<const T*>(self));
|
41
|
+
}
|
42
|
+
|
43
|
+
static void Trace(Visitor* visitor, const void* self) {
|
44
|
+
static_cast<const T*>(self)->Trace(visitor);
|
45
|
+
}
|
46
|
+
};
|
47
|
+
|
48
|
+
namespace internal {
|
49
|
+
|
50
|
+
template <typename T>
|
51
|
+
struct TraceTraitImpl<T, false> {
|
52
|
+
static TraceDescriptor GetTraceDescriptor(const void* self) {
|
53
|
+
return {self, TraceTrait<T>::Trace};
|
54
|
+
}
|
55
|
+
};
|
56
|
+
|
57
|
+
template <typename T>
|
58
|
+
struct TraceTraitImpl<T, true> {
|
59
|
+
static TraceDescriptor GetTraceDescriptor(const void* self) {
|
60
|
+
return static_cast<const T*>(self)->GetTraceDescriptor();
|
61
|
+
}
|
62
|
+
};
|
63
|
+
|
64
|
+
} // namespace internal
|
65
|
+
} // namespace cppgc
|
66
|
+
|
67
|
+
#endif // INCLUDE_CPPGC_TRACE_TRAIT_H_
|
@@ -0,0 +1,109 @@
|
|
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_TYPE_TRAITS_H_
|
6
|
+
#define INCLUDE_CPPGC_TYPE_TRAITS_H_
|
7
|
+
|
8
|
+
#include <type_traits>
|
9
|
+
|
10
|
+
namespace cppgc {
|
11
|
+
|
12
|
+
class Visitor;
|
13
|
+
|
14
|
+
namespace internal {
|
15
|
+
|
16
|
+
// Pre-C++17 custom implementation of std::void_t.
|
17
|
+
template <typename... Ts>
|
18
|
+
struct make_void {
|
19
|
+
typedef void type;
|
20
|
+
};
|
21
|
+
template <typename... Ts>
|
22
|
+
using void_t = typename make_void<Ts...>::type;
|
23
|
+
|
24
|
+
// Not supposed to be specialized by the user.
|
25
|
+
template <typename T>
|
26
|
+
struct IsWeak : std::false_type {};
|
27
|
+
|
28
|
+
template <typename T, template <typename... V> class U>
|
29
|
+
struct IsSubclassOfTemplate {
|
30
|
+
private:
|
31
|
+
template <typename... W>
|
32
|
+
static std::true_type SubclassCheck(U<W...>*);
|
33
|
+
static std::false_type SubclassCheck(...);
|
34
|
+
|
35
|
+
public:
|
36
|
+
static constexpr bool value =
|
37
|
+
decltype(SubclassCheck(std::declval<T*>()))::value;
|
38
|
+
};
|
39
|
+
|
40
|
+
// IsTraceMethodConst is used to verify that all Trace methods are marked as
|
41
|
+
// const. It is equivalent to IsTraceable but for a non-const object.
|
42
|
+
template <typename T, typename = void>
|
43
|
+
struct IsTraceMethodConst : std::false_type {};
|
44
|
+
|
45
|
+
template <typename T>
|
46
|
+
struct IsTraceMethodConst<T, void_t<decltype(std::declval<const T>().Trace(
|
47
|
+
std::declval<Visitor*>()))>> : std::true_type {
|
48
|
+
};
|
49
|
+
|
50
|
+
template <typename T, typename = void>
|
51
|
+
struct IsTraceable : std::false_type {
|
52
|
+
static_assert(sizeof(T), "T must be fully defined");
|
53
|
+
};
|
54
|
+
|
55
|
+
template <typename T>
|
56
|
+
struct IsTraceable<
|
57
|
+
T, void_t<decltype(std::declval<T>().Trace(std::declval<Visitor*>()))>>
|
58
|
+
: std::true_type {
|
59
|
+
// All Trace methods should be marked as const. If an object of type
|
60
|
+
// 'T' is traceable then any object of type 'const T' should also
|
61
|
+
// be traceable.
|
62
|
+
static_assert(IsTraceMethodConst<T>(),
|
63
|
+
"Trace methods should be marked as const.");
|
64
|
+
};
|
65
|
+
|
66
|
+
template <typename T>
|
67
|
+
constexpr bool IsTraceableV = IsTraceable<T>::value;
|
68
|
+
|
69
|
+
template <typename T, typename = void>
|
70
|
+
struct IsGarbageCollectedMixinType : std::false_type {
|
71
|
+
static_assert(sizeof(T), "T must be fully defined");
|
72
|
+
};
|
73
|
+
|
74
|
+
template <typename T>
|
75
|
+
struct IsGarbageCollectedMixinType<
|
76
|
+
T,
|
77
|
+
void_t<typename std::remove_const_t<T>::IsGarbageCollectedMixinTypeMarker>>
|
78
|
+
: std::true_type {
|
79
|
+
static_assert(sizeof(T), "T must be fully defined");
|
80
|
+
};
|
81
|
+
|
82
|
+
template <typename T, typename = void>
|
83
|
+
struct IsGarbageCollectedType : IsGarbageCollectedMixinType<T> {
|
84
|
+
static_assert(sizeof(T), "T must be fully defined");
|
85
|
+
};
|
86
|
+
|
87
|
+
template <typename T>
|
88
|
+
struct IsGarbageCollectedType<
|
89
|
+
T, void_t<typename std::remove_const_t<T>::IsGarbageCollectedTypeMarker>>
|
90
|
+
: std::true_type {
|
91
|
+
static_assert(sizeof(T), "T must be fully defined");
|
92
|
+
};
|
93
|
+
|
94
|
+
template <typename T>
|
95
|
+
constexpr bool IsGarbageCollectedTypeV =
|
96
|
+
internal::IsGarbageCollectedType<T>::value;
|
97
|
+
|
98
|
+
template <typename T>
|
99
|
+
constexpr bool IsGarbageCollectedMixinTypeV =
|
100
|
+
internal::IsGarbageCollectedMixinType<T>::value;
|
101
|
+
|
102
|
+
} // namespace internal
|
103
|
+
|
104
|
+
template <typename T>
|
105
|
+
constexpr bool IsWeakV = internal::IsWeak<T>::value;
|
106
|
+
|
107
|
+
} // namespace cppgc
|
108
|
+
|
109
|
+
#endif // INCLUDE_CPPGC_TYPE_TRAITS_H_
|
@@ -0,0 +1,137 @@
|
|
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
|
+
namespace internal {
|
18
|
+
class VisitorBase;
|
19
|
+
} // namespace internal
|
20
|
+
|
21
|
+
using WeakCallback = void (*)(const LivenessBroker&, const void*);
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Visitor passed to trace methods. All managed pointers must have called the
|
25
|
+
* visitor's trace method on them.
|
26
|
+
*/
|
27
|
+
class Visitor {
|
28
|
+
public:
|
29
|
+
template <typename T>
|
30
|
+
void Trace(const Member<T>& member) {
|
31
|
+
const T* value = member.GetRawAtomic();
|
32
|
+
CPPGC_DCHECK(value != kSentinelPointer);
|
33
|
+
Trace(value);
|
34
|
+
}
|
35
|
+
|
36
|
+
template <typename T>
|
37
|
+
void Trace(const WeakMember<T>& weak_member) {
|
38
|
+
static_assert(sizeof(T), "T must be fully defined");
|
39
|
+
static_assert(internal::IsGarbageCollectedType<T>::value,
|
40
|
+
"T must be GarabgeCollected or GarbageCollectedMixin type");
|
41
|
+
|
42
|
+
const T* value = weak_member.GetRawAtomic();
|
43
|
+
|
44
|
+
// Bailout assumes that WeakMember emits write barrier.
|
45
|
+
if (!value) {
|
46
|
+
return;
|
47
|
+
}
|
48
|
+
|
49
|
+
// TODO(chromium:1056170): DCHECK (or similar) for deleted values as they
|
50
|
+
// should come in at a different path.
|
51
|
+
VisitWeak(value, TraceTrait<T>::GetTraceDescriptor(value),
|
52
|
+
&HandleWeak<WeakMember<T>>, &weak_member);
|
53
|
+
}
|
54
|
+
|
55
|
+
template <typename Persistent,
|
56
|
+
std::enable_if_t<Persistent::IsStrongPersistent::value>* = nullptr>
|
57
|
+
void TraceRoot(const Persistent& p, const SourceLocation& loc) {
|
58
|
+
using PointeeType = typename Persistent::PointeeType;
|
59
|
+
static_assert(sizeof(PointeeType),
|
60
|
+
"Persistent's pointee type must be fully defined");
|
61
|
+
static_assert(internal::IsGarbageCollectedType<PointeeType>::value,
|
62
|
+
"Persisent's pointee type must be GarabgeCollected or "
|
63
|
+
"GarbageCollectedMixin");
|
64
|
+
if (!p.Get()) {
|
65
|
+
return;
|
66
|
+
}
|
67
|
+
VisitRoot(p.Get(), TraceTrait<PointeeType>::GetTraceDescriptor(p.Get()),
|
68
|
+
loc);
|
69
|
+
}
|
70
|
+
|
71
|
+
template <typename Persistent,
|
72
|
+
std::enable_if_t<!Persistent::IsStrongPersistent::value>* = nullptr>
|
73
|
+
void TraceRoot(const Persistent& p, const SourceLocation& loc) {
|
74
|
+
using PointeeType = typename Persistent::PointeeType;
|
75
|
+
static_assert(sizeof(PointeeType),
|
76
|
+
"Persistent's pointee type must be fully defined");
|
77
|
+
static_assert(internal::IsGarbageCollectedType<PointeeType>::value,
|
78
|
+
"Persisent's pointee type must be GarabgeCollected or "
|
79
|
+
"GarbageCollectedMixin");
|
80
|
+
VisitWeakRoot(&p, &HandleWeak<Persistent>);
|
81
|
+
}
|
82
|
+
|
83
|
+
template <typename T, void (T::*method)(const LivenessBroker&)>
|
84
|
+
void RegisterWeakCallbackMethod(const T* obj) {
|
85
|
+
RegisterWeakCallback(&WeakCallbackMethodDelegate<T, method>, obj);
|
86
|
+
}
|
87
|
+
|
88
|
+
virtual void RegisterWeakCallback(WeakCallback, const void*) {}
|
89
|
+
|
90
|
+
protected:
|
91
|
+
virtual void Visit(const void* self, TraceDescriptor) {}
|
92
|
+
virtual void VisitWeak(const void* self, TraceDescriptor, WeakCallback,
|
93
|
+
const void* weak_member) {}
|
94
|
+
virtual void VisitRoot(const void*, TraceDescriptor,
|
95
|
+
const SourceLocation& loc) {}
|
96
|
+
virtual void VisitWeakRoot(const void*, WeakCallback) {}
|
97
|
+
|
98
|
+
private:
|
99
|
+
template <typename T, void (T::*method)(const LivenessBroker&)>
|
100
|
+
static void WeakCallbackMethodDelegate(const LivenessBroker& info,
|
101
|
+
const void* self) {
|
102
|
+
// Callback is registered through a potential const Trace method but needs
|
103
|
+
// to be able to modify fields. See HandleWeak.
|
104
|
+
(const_cast<T*>(static_cast<const T*>(self))->*method)(info);
|
105
|
+
}
|
106
|
+
|
107
|
+
template <typename PointerType>
|
108
|
+
static void HandleWeak(const LivenessBroker& info, const void* object) {
|
109
|
+
const PointerType* weak = static_cast<const PointerType*>(object);
|
110
|
+
const auto* raw = weak->Get();
|
111
|
+
if (raw && !info.IsHeapObjectAlive(raw)) {
|
112
|
+
// Object is passed down through the marker as const. Alternatives are
|
113
|
+
// - non-const Trace method;
|
114
|
+
// - mutable pointer in MemberBase;
|
115
|
+
const_cast<PointerType*>(weak)->Clear();
|
116
|
+
}
|
117
|
+
}
|
118
|
+
|
119
|
+
Visitor() = default;
|
120
|
+
|
121
|
+
template <typename T>
|
122
|
+
void Trace(const T* t) {
|
123
|
+
static_assert(sizeof(T), "T must be fully defined");
|
124
|
+
static_assert(internal::IsGarbageCollectedType<T>::value,
|
125
|
+
"T must be GarabgeCollected or GarbageCollectedMixin type");
|
126
|
+
if (!t) {
|
127
|
+
return;
|
128
|
+
}
|
129
|
+
Visit(t, TraceTrait<T>::GetTraceDescriptor(t));
|
130
|
+
}
|
131
|
+
|
132
|
+
friend class internal::VisitorBase;
|
133
|
+
};
|
134
|
+
|
135
|
+
} // namespace cppgc
|
136
|
+
|
137
|
+
#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,85 @@
|
|
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
|
+
* Pumps the message loop for the given isolate.
|
48
|
+
*
|
49
|
+
* The caller has to make sure that this is called from the right thread.
|
50
|
+
* Returns true if a task was executed, and false otherwise. If the call to
|
51
|
+
* PumpMessageLoop is nested within another call to PumpMessageLoop, only
|
52
|
+
* nestable tasks may run. Otherwise, any task may run. Unless requested through
|
53
|
+
* the |behavior| parameter, this call does not block if no task is pending. The
|
54
|
+
* |platform| has to be created using |NewDefaultPlatform|.
|
55
|
+
*/
|
56
|
+
V8_PLATFORM_EXPORT bool PumpMessageLoop(
|
57
|
+
v8::Platform* platform, v8::Isolate* isolate,
|
58
|
+
MessageLoopBehavior behavior = MessageLoopBehavior::kDoNotWait);
|
59
|
+
|
60
|
+
/**
|
61
|
+
* Runs pending idle tasks for at most |idle_time_in_seconds| seconds.
|
62
|
+
*
|
63
|
+
* The caller has to make sure that this is called from the right thread.
|
64
|
+
* This call does not block if no task is pending. The |platform| has to be
|
65
|
+
* created using |NewDefaultPlatform|.
|
66
|
+
*/
|
67
|
+
V8_PLATFORM_EXPORT void RunIdleTasks(v8::Platform* platform,
|
68
|
+
v8::Isolate* isolate,
|
69
|
+
double idle_time_in_seconds);
|
70
|
+
|
71
|
+
/**
|
72
|
+
* Attempts to set the tracing controller for the given platform.
|
73
|
+
*
|
74
|
+
* The |platform| has to be created using |NewDefaultPlatform|.
|
75
|
+
*
|
76
|
+
*/
|
77
|
+
V8_DEPRECATE_SOON("Access the DefaultPlatform directly")
|
78
|
+
V8_PLATFORM_EXPORT void SetTracingController(
|
79
|
+
v8::Platform* platform,
|
80
|
+
v8::platform::tracing::TracingController* tracing_controller);
|
81
|
+
|
82
|
+
} // namespace platform
|
83
|
+
} // namespace v8
|
84
|
+
|
85
|
+
#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_
|