libv8-node 15.5.1.0.beta1-arm64-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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 459b4d84a8411c96abb43c762e1d82851476f1a2e21ca3ae88b3dd34065e9891
|
4
|
+
data.tar.gz: 7bc0449465bbb30b47e3d6d3be4b668af0fc33b5f5e244135062726a77297960
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f42012c36645bd6f937b5fca6de7ea2ce861236296cd862c8994899943a036046c692b36a5831d49f8ce064513227c35c32d13d4899500fc817bfc5704ab8ea2
|
7
|
+
data.tar.gz: 11b5e12913e0b7c99016d8b02ded1cb80a90edf350756b98095e7e420335b8096d2efd0e5b414aa7adc5fc7c866e5d726921c310c385c5303954ae57b7519de5
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'pathname'
|
3
|
+
require File.expand_path '../paths', __FILE__
|
4
|
+
|
5
|
+
module Libv8; end
|
6
|
+
|
7
|
+
module Libv8::Node
|
8
|
+
class Location
|
9
|
+
def install!
|
10
|
+
File.open(Pathname(__FILE__).dirname.join('.location.yml'), "w") do |f|
|
11
|
+
f.write self.to_yaml
|
12
|
+
end
|
13
|
+
return 0
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.load!
|
17
|
+
File.open(Pathname(__FILE__).dirname.join('.location.yml')) do |f|
|
18
|
+
YAML.load f
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Vendor < Location
|
23
|
+
def install!
|
24
|
+
require File.expand_path '../builder', __FILE__
|
25
|
+
builder = Libv8::Node::Builder.new
|
26
|
+
exit_status = builder.build_libv8!
|
27
|
+
super if exit_status == 0
|
28
|
+
verify_installation!
|
29
|
+
return exit_status
|
30
|
+
end
|
31
|
+
|
32
|
+
def configure(context = MkmfContext.new)
|
33
|
+
context.incflags.insert 0, Libv8::Node::Paths.include_paths.map{ |p| "-I#{p}" }.join(" ") + " "
|
34
|
+
context.ldflags.insert 0, Libv8::Node::Paths.object_paths.join(" ") + " "
|
35
|
+
end
|
36
|
+
|
37
|
+
def verify_installation!
|
38
|
+
include_paths = Libv8::Node::Paths.include_paths
|
39
|
+
unless include_paths.detect { |p| Pathname(p).join('v8.h').exist? }
|
40
|
+
fail HeaderNotFound, "Unable to locate 'v8.h' in the libv8 header paths: #{include_paths.inspect}"
|
41
|
+
end
|
42
|
+
Libv8::Node::Paths.object_paths.each do |p|
|
43
|
+
fail ArchiveNotFound, p unless File.exist? p
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class HeaderNotFound < StandardError; end
|
48
|
+
|
49
|
+
class ArchiveNotFound < StandardError
|
50
|
+
def initialize(filename)
|
51
|
+
super "libv8 did not install properly, expected binary v8 archive '#{filename}'to exist, but it was not found"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class System < Location
|
57
|
+
def configure(context = MkmfContext.new)
|
58
|
+
context.send(:dir_config, 'v8')
|
59
|
+
context.send(:find_header, 'v8.h') or fail NotFoundError
|
60
|
+
context.send(:find_header, 'libplatform/libplatform.h') or fail NotFoundError
|
61
|
+
context.send(:have_library, 'v8') or fail NotFoundError
|
62
|
+
end
|
63
|
+
|
64
|
+
class NotFoundError < StandardError
|
65
|
+
def initialize(*args)
|
66
|
+
super(<<-EOS)
|
67
|
+
By using --with-system-v8, you have chosen to use the version
|
68
|
+
of V8 found on your system and *not* the one that is bundled with
|
69
|
+
the libv8 rubygem.
|
70
|
+
|
71
|
+
However, your system version of v8 could not be located.
|
72
|
+
|
73
|
+
Please make sure your system version of v8 that is compatible
|
74
|
+
with #{Libv8::Node::VERSION} installed. You may need to use the
|
75
|
+
--with-v8-dir option if it is installed in a non-standard location
|
76
|
+
EOS
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class MkmfContext
|
82
|
+
def incflags
|
83
|
+
$INCFLAGS
|
84
|
+
end
|
85
|
+
|
86
|
+
def ldflags
|
87
|
+
$LDFLAGS
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
require 'shellwords'
|
3
|
+
|
4
|
+
module Libv8; end
|
5
|
+
|
6
|
+
module Libv8::Node
|
7
|
+
module Paths
|
8
|
+
module_function
|
9
|
+
|
10
|
+
def include_paths
|
11
|
+
[Shellwords.escape(File.join(vendored_source_path, 'include'))]
|
12
|
+
end
|
13
|
+
|
14
|
+
def object_paths
|
15
|
+
[Shellwords.escape(File.join(vendored_source_path,
|
16
|
+
'out.gn',
|
17
|
+
'libv8',
|
18
|
+
'obj',
|
19
|
+
"libv8_monolith.#{config['LIBEXT']}"))]
|
20
|
+
end
|
21
|
+
|
22
|
+
def config
|
23
|
+
RbConfig::MAKEFILE_CONFIG
|
24
|
+
end
|
25
|
+
|
26
|
+
def vendored_source_path
|
27
|
+
File.expand_path "../../../vendor/v8", __FILE__
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/libv8/node.rb
ADDED
data/lib/libv8-node.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'libv8/node'
|
@@ -0,0 +1,173 @@
|
|
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_ALLOCATION_H_
|
6
|
+
#define INCLUDE_CPPGC_ALLOCATION_H_
|
7
|
+
|
8
|
+
#include <stdint.h>
|
9
|
+
|
10
|
+
#include <atomic>
|
11
|
+
|
12
|
+
#include "cppgc/custom-space.h"
|
13
|
+
#include "cppgc/garbage-collected.h"
|
14
|
+
#include "cppgc/internal/api-constants.h"
|
15
|
+
#include "cppgc/internal/gc-info.h"
|
16
|
+
|
17
|
+
namespace cppgc {
|
18
|
+
|
19
|
+
template <typename T>
|
20
|
+
class MakeGarbageCollectedTraitBase;
|
21
|
+
|
22
|
+
namespace internal {
|
23
|
+
class ObjectAllocator;
|
24
|
+
} // namespace internal
|
25
|
+
|
26
|
+
/**
|
27
|
+
* AllocationHandle is used to allocate garbage-collected objects.
|
28
|
+
*/
|
29
|
+
class AllocationHandle;
|
30
|
+
|
31
|
+
namespace internal {
|
32
|
+
|
33
|
+
class V8_EXPORT MakeGarbageCollectedTraitInternal {
|
34
|
+
protected:
|
35
|
+
static inline void MarkObjectAsFullyConstructed(const void* payload) {
|
36
|
+
// See api_constants for an explanation of the constants.
|
37
|
+
std::atomic<uint16_t>* atomic_mutable_bitfield =
|
38
|
+
reinterpret_cast<std::atomic<uint16_t>*>(
|
39
|
+
const_cast<uint16_t*>(reinterpret_cast<const uint16_t*>(
|
40
|
+
reinterpret_cast<const uint8_t*>(payload) -
|
41
|
+
api_constants::kFullyConstructedBitFieldOffsetFromPayload)));
|
42
|
+
uint16_t value = atomic_mutable_bitfield->load(std::memory_order_relaxed);
|
43
|
+
value = value | api_constants::kFullyConstructedBitMask;
|
44
|
+
atomic_mutable_bitfield->store(value, std::memory_order_release);
|
45
|
+
}
|
46
|
+
|
47
|
+
static void* Allocate(cppgc::AllocationHandle& handle, size_t size,
|
48
|
+
GCInfoIndex index);
|
49
|
+
static void* Allocate(cppgc::AllocationHandle& handle, size_t size,
|
50
|
+
GCInfoIndex index, CustomSpaceIndex space_index);
|
51
|
+
|
52
|
+
friend class HeapObjectHeader;
|
53
|
+
};
|
54
|
+
|
55
|
+
} // namespace internal
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Base trait that provides utilities for advancers users that have custom
|
59
|
+
* allocation needs (e.g., overriding size). It's expected that users override
|
60
|
+
* MakeGarbageCollectedTrait (see below) and inherit from
|
61
|
+
* MakeGarbageCollectedTraitBase and make use of the low-level primitives
|
62
|
+
* offered to allocate and construct an object.
|
63
|
+
*/
|
64
|
+
template <typename T>
|
65
|
+
class MakeGarbageCollectedTraitBase
|
66
|
+
: private internal::MakeGarbageCollectedTraitInternal {
|
67
|
+
private:
|
68
|
+
template <typename U, typename CustomSpace>
|
69
|
+
struct SpacePolicy {
|
70
|
+
static void* Allocate(AllocationHandle& handle, size_t size) {
|
71
|
+
// Custom space.
|
72
|
+
static_assert(std::is_base_of<CustomSpaceBase, CustomSpace>::value,
|
73
|
+
"Custom space must inherit from CustomSpaceBase.");
|
74
|
+
return internal::MakeGarbageCollectedTraitInternal::Allocate(
|
75
|
+
handle, size, internal::GCInfoTrait<T>::Index(),
|
76
|
+
CustomSpace::kSpaceIndex);
|
77
|
+
}
|
78
|
+
};
|
79
|
+
|
80
|
+
template <typename U>
|
81
|
+
struct SpacePolicy<U, void> {
|
82
|
+
static void* Allocate(AllocationHandle& handle, size_t size) {
|
83
|
+
// Default space.
|
84
|
+
return internal::MakeGarbageCollectedTraitInternal::Allocate(
|
85
|
+
handle, size, internal::GCInfoTrait<T>::Index());
|
86
|
+
}
|
87
|
+
};
|
88
|
+
|
89
|
+
protected:
|
90
|
+
/**
|
91
|
+
* Allocates memory for an object of type T.
|
92
|
+
*
|
93
|
+
* \param handle AllocationHandle identifying the heap to allocate the object
|
94
|
+
* on.
|
95
|
+
* \param size The size that should be reserved for the object.
|
96
|
+
* \returns the memory to construct an object of type T on.
|
97
|
+
*/
|
98
|
+
static void* Allocate(AllocationHandle& handle, size_t size) {
|
99
|
+
return SpacePolicy<T, typename SpaceTrait<T>::Space>::Allocate(handle,
|
100
|
+
size);
|
101
|
+
}
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Marks an object as fully constructed, resulting in precise handling by the
|
105
|
+
* garbage collector.
|
106
|
+
*
|
107
|
+
* \param payload The base pointer the object is allocated at.
|
108
|
+
*/
|
109
|
+
static void MarkObjectAsFullyConstructed(const void* payload) {
|
110
|
+
internal::MakeGarbageCollectedTraitInternal::MarkObjectAsFullyConstructed(
|
111
|
+
payload);
|
112
|
+
}
|
113
|
+
};
|
114
|
+
|
115
|
+
/**
|
116
|
+
* Default trait class that specifies how to construct an object of type T.
|
117
|
+
* Advanced users may override how an object is constructed using the utilities
|
118
|
+
* that are provided through MakeGarbageCollectedTraitBase.
|
119
|
+
*
|
120
|
+
* Any trait overriding construction must
|
121
|
+
* - allocate through MakeGarbageCollectedTraitBase<T>::Allocate;
|
122
|
+
* - mark the object as fully constructed using
|
123
|
+
* MakeGarbageCollectedTraitBase<T>::MarkObjectAsFullyConstructed;
|
124
|
+
*/
|
125
|
+
template <typename T>
|
126
|
+
class MakeGarbageCollectedTrait : public MakeGarbageCollectedTraitBase<T> {
|
127
|
+
public:
|
128
|
+
template <typename... Args>
|
129
|
+
static T* Call(AllocationHandle& handle, Args&&... args) {
|
130
|
+
static_assert(internal::IsGarbageCollectedType<T>::value,
|
131
|
+
"T needs to be a garbage collected object");
|
132
|
+
static_assert(
|
133
|
+
!internal::IsGarbageCollectedMixinType<T>::value ||
|
134
|
+
sizeof(T) <= internal::api_constants::kLargeObjectSizeThreshold,
|
135
|
+
"GarbageCollectedMixin may not be a large object");
|
136
|
+
void* memory =
|
137
|
+
MakeGarbageCollectedTraitBase<T>::Allocate(handle, sizeof(T));
|
138
|
+
T* object = ::new (memory) T(std::forward<Args>(args)...);
|
139
|
+
MakeGarbageCollectedTraitBase<T>::MarkObjectAsFullyConstructed(object);
|
140
|
+
return object;
|
141
|
+
}
|
142
|
+
};
|
143
|
+
|
144
|
+
/**
|
145
|
+
* Allows users to specify a post-construction callback for specific types. The
|
146
|
+
* callback is invoked on the instance of type T right after it has been
|
147
|
+
* constructed. This can be useful when the callback requires a
|
148
|
+
* fully-constructed object to be able to dispatch to virtual methods.
|
149
|
+
*/
|
150
|
+
template <typename T, typename = void>
|
151
|
+
struct PostConstructionCallbackTrait {
|
152
|
+
static void Call(T*) {}
|
153
|
+
};
|
154
|
+
|
155
|
+
/**
|
156
|
+
* Constructs a managed object of type T where T transitively inherits from
|
157
|
+
* GarbageCollected.
|
158
|
+
*
|
159
|
+
* \param args List of arguments with which an instance of T will be
|
160
|
+
* constructed.
|
161
|
+
* \returns an instance of type T.
|
162
|
+
*/
|
163
|
+
template <typename T, typename... Args>
|
164
|
+
T* MakeGarbageCollected(AllocationHandle& handle, Args&&... args) {
|
165
|
+
T* object =
|
166
|
+
MakeGarbageCollectedTrait<T>::Call(handle, std::forward<Args>(args)...);
|
167
|
+
PostConstructionCallbackTrait<T>::Call(object);
|
168
|
+
return object;
|
169
|
+
}
|
170
|
+
|
171
|
+
} // namespace cppgc
|
172
|
+
|
173
|
+
#endif // INCLUDE_CPPGC_ALLOCATION_H_
|
@@ -0,0 +1,26 @@
|
|
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_COMMON_H_
|
6
|
+
#define INCLUDE_CPPGC_COMMON_H_
|
7
|
+
|
8
|
+
// TODO(chromium:1056170): Remove dependency on v8.
|
9
|
+
#include "v8config.h" // NOLINT(build/include_directory)
|
10
|
+
|
11
|
+
namespace cppgc {
|
12
|
+
|
13
|
+
// Indicator for the stack state of the embedder.
|
14
|
+
enum class EmbedderStackState {
|
15
|
+
kMayContainHeapPointers,
|
16
|
+
kNoHeapPointers,
|
17
|
+
kUnknown V8_ENUM_DEPRECATE_SOON("Use kMayContainHeapPointers") =
|
18
|
+
kMayContainHeapPointers,
|
19
|
+
kNonEmpty V8_ENUM_DEPRECATE_SOON("Use kMayContainHeapPointers") =
|
20
|
+
kMayContainHeapPointers,
|
21
|
+
kEmpty V8_ENUM_DEPRECATE_SOON("Use kNoHeapPointers") = kNoHeapPointers,
|
22
|
+
};
|
23
|
+
|
24
|
+
} // namespace cppgc
|
25
|
+
|
26
|
+
#endif // INCLUDE_CPPGC_COMMON_H_
|
@@ -0,0 +1,62 @@
|
|
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_CUSTOM_SPACE_H_
|
6
|
+
#define INCLUDE_CPPGC_CUSTOM_SPACE_H_
|
7
|
+
|
8
|
+
#include <stddef.h>
|
9
|
+
|
10
|
+
namespace cppgc {
|
11
|
+
|
12
|
+
struct CustomSpaceIndex {
|
13
|
+
CustomSpaceIndex(size_t value) : value(value) {} // NOLINT
|
14
|
+
size_t value;
|
15
|
+
};
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Top-level base class for custom spaces. Users must inherit from CustomSpace
|
19
|
+
* below.
|
20
|
+
*/
|
21
|
+
class CustomSpaceBase {
|
22
|
+
public:
|
23
|
+
virtual ~CustomSpaceBase() = default;
|
24
|
+
virtual CustomSpaceIndex GetCustomSpaceIndex() const = 0;
|
25
|
+
};
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Base class custom spaces should directly inherit from. The class inheriting
|
29
|
+
* from CustomSpace must define kSpaceIndex as unique space index. These
|
30
|
+
* indices need for form a sequence starting at 0.
|
31
|
+
*
|
32
|
+
* Example:
|
33
|
+
* \code
|
34
|
+
* class CustomSpace1 : public CustomSpace<CustomSpace1> {
|
35
|
+
* public:
|
36
|
+
* static constexpr CustomSpaceIndex kSpaceIndex = 0;
|
37
|
+
* };
|
38
|
+
* class CustomSpace2 : public CustomSpace<CustomSpace2> {
|
39
|
+
* public:
|
40
|
+
* static constexpr CustomSpaceIndex kSpaceIndex = 1;
|
41
|
+
* };
|
42
|
+
* \endcode
|
43
|
+
*/
|
44
|
+
template <typename ConcreteCustomSpace>
|
45
|
+
class CustomSpace : public CustomSpaceBase {
|
46
|
+
public:
|
47
|
+
CustomSpaceIndex GetCustomSpaceIndex() const final {
|
48
|
+
return ConcreteCustomSpace::kSpaceIndex;
|
49
|
+
}
|
50
|
+
};
|
51
|
+
|
52
|
+
/**
|
53
|
+
* User-overridable trait that allows pinning types to custom spaces.
|
54
|
+
*/
|
55
|
+
template <typename T, typename = void>
|
56
|
+
struct SpaceTrait {
|
57
|
+
using Space = void;
|
58
|
+
};
|
59
|
+
|
60
|
+
} // namespace cppgc
|
61
|
+
|
62
|
+
#endif // INCLUDE_CPPGC_CUSTOM_SPACE_H_
|
@@ -0,0 +1,76 @@
|
|
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_DEFAULT_PLATFORM_H_
|
6
|
+
#define INCLUDE_CPPGC_DEFAULT_PLATFORM_H_
|
7
|
+
|
8
|
+
#include <memory>
|
9
|
+
#include <thread> // NOLINT(build/c++11)
|
10
|
+
#include <vector>
|
11
|
+
|
12
|
+
#include "cppgc/platform.h"
|
13
|
+
#include "v8config.h" // NOLINT(build/include_directory)
|
14
|
+
|
15
|
+
namespace cppgc {
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Default task runner implementation. Keep posted tasks in a list that can be
|
19
|
+
* processed by calling RunSingleTask() or RunUntilIdle().
|
20
|
+
*/
|
21
|
+
class V8_EXPORT DefaultTaskRunner final : public cppgc::TaskRunner {
|
22
|
+
public:
|
23
|
+
DefaultTaskRunner() = default;
|
24
|
+
|
25
|
+
DefaultTaskRunner(const DefaultTaskRunner&) = delete;
|
26
|
+
DefaultTaskRunner& operator=(const DefaultTaskRunner&) = delete;
|
27
|
+
|
28
|
+
void PostTask(std::unique_ptr<cppgc::Task> task) override;
|
29
|
+
void PostNonNestableTask(std::unique_ptr<cppgc::Task> task) override;
|
30
|
+
void PostDelayedTask(std::unique_ptr<cppgc::Task> task, double) override;
|
31
|
+
void PostNonNestableDelayedTask(std::unique_ptr<cppgc::Task> task,
|
32
|
+
double) override;
|
33
|
+
|
34
|
+
void PostIdleTask(std::unique_ptr<cppgc::IdleTask> task) override;
|
35
|
+
bool IdleTasksEnabled() override { return true; }
|
36
|
+
|
37
|
+
bool RunSingleTask();
|
38
|
+
bool RunSingleIdleTask(double duration_in_seconds);
|
39
|
+
|
40
|
+
void RunUntilIdle();
|
41
|
+
|
42
|
+
private:
|
43
|
+
std::vector<std::unique_ptr<cppgc::Task>> tasks_;
|
44
|
+
std::vector<std::unique_ptr<cppgc::IdleTask>> idle_tasks_;
|
45
|
+
};
|
46
|
+
|
47
|
+
/**
|
48
|
+
* Default platform implementation that uses std::thread for spawning job tasks.
|
49
|
+
*/
|
50
|
+
class V8_EXPORT DefaultPlatform final : public Platform {
|
51
|
+
public:
|
52
|
+
DefaultPlatform();
|
53
|
+
~DefaultPlatform() noexcept override;
|
54
|
+
|
55
|
+
cppgc::PageAllocator* GetPageAllocator() final;
|
56
|
+
|
57
|
+
double MonotonicallyIncreasingTime() final;
|
58
|
+
|
59
|
+
std::shared_ptr<cppgc::TaskRunner> GetForegroundTaskRunner() final;
|
60
|
+
|
61
|
+
std::unique_ptr<cppgc::JobHandle> PostJob(
|
62
|
+
cppgc::TaskPriority priority,
|
63
|
+
std::unique_ptr<cppgc::JobTask> job_task) final;
|
64
|
+
|
65
|
+
void WaitAllForegroundTasks();
|
66
|
+
void WaitAllBackgroundTasks();
|
67
|
+
|
68
|
+
private:
|
69
|
+
std::unique_ptr<PageAllocator> page_allocator_;
|
70
|
+
std::shared_ptr<DefaultTaskRunner> foreground_task_runner_;
|
71
|
+
std::vector<std::shared_ptr<std::thread>> job_threads_;
|
72
|
+
};
|
73
|
+
|
74
|
+
} // namespace cppgc
|
75
|
+
|
76
|
+
#endif // INCLUDE_CPPGC_DEFAULT_PLATFORM_H_
|
@@ -0,0 +1,116 @@
|
|
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_GARBAGE_COLLECTED_H_
|
6
|
+
#define INCLUDE_CPPGC_GARBAGE_COLLECTED_H_
|
7
|
+
|
8
|
+
#include <type_traits>
|
9
|
+
|
10
|
+
#include "cppgc/internal/api-constants.h"
|
11
|
+
#include "cppgc/platform.h"
|
12
|
+
#include "cppgc/trace-trait.h"
|
13
|
+
#include "cppgc/type-traits.h"
|
14
|
+
|
15
|
+
namespace cppgc {
|
16
|
+
|
17
|
+
class Visitor;
|
18
|
+
|
19
|
+
namespace internal {
|
20
|
+
|
21
|
+
class GarbageCollectedBase {
|
22
|
+
public:
|
23
|
+
// Must use MakeGarbageCollected.
|
24
|
+
void* operator new(size_t) = delete;
|
25
|
+
void* operator new[](size_t) = delete;
|
26
|
+
// The garbage collector is taking care of reclaiming the object. Also,
|
27
|
+
// virtual destructor requires an unambiguous, accessible 'operator delete'.
|
28
|
+
void operator delete(void*) {
|
29
|
+
#ifdef V8_ENABLE_CHECKS
|
30
|
+
internal::Abort();
|
31
|
+
#endif // V8_ENABLE_CHECKS
|
32
|
+
}
|
33
|
+
void operator delete[](void*) = delete;
|
34
|
+
|
35
|
+
protected:
|
36
|
+
GarbageCollectedBase() = default;
|
37
|
+
};
|
38
|
+
|
39
|
+
} // namespace internal
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Base class for managed objects. Only descendent types of GarbageCollected
|
43
|
+
* can be constructed using MakeGarbageCollected. Must be inherited from as
|
44
|
+
* left-most base class.
|
45
|
+
*
|
46
|
+
* Types inheriting from GarbageCollected must provide a method of
|
47
|
+
* signature `void Trace(cppgc::Visitor*) const` that dispatchs all managed
|
48
|
+
* pointers to the visitor and delegates to garbage-collected base classes.
|
49
|
+
* The method must be virtual if the type is not directly a child of
|
50
|
+
* GarbageCollected and marked as final.
|
51
|
+
*
|
52
|
+
* \code
|
53
|
+
* // Example using final class.
|
54
|
+
* class FinalType final : public GarbageCollected<FinalType> {
|
55
|
+
* public:
|
56
|
+
* void Trace(cppgc::Visitor* visitor) const {
|
57
|
+
* // Dispatch using visitor->Trace(...);
|
58
|
+
* }
|
59
|
+
* };
|
60
|
+
*
|
61
|
+
* // Example using non-final base class.
|
62
|
+
* class NonFinalBase : public GarbageCollected<NonFinalBase> {
|
63
|
+
* public:
|
64
|
+
* virtual void Trace(cppgc::Visitor*) const {}
|
65
|
+
* };
|
66
|
+
*
|
67
|
+
* class FinalChild final : public NonFinalBase {
|
68
|
+
* public:
|
69
|
+
* void Trace(cppgc::Visitor* visitor) const final {
|
70
|
+
* // Dispatch using visitor->Trace(...);
|
71
|
+
* NonFinalBase::Trace(visitor);
|
72
|
+
* }
|
73
|
+
* };
|
74
|
+
* \endcode
|
75
|
+
*/
|
76
|
+
template <typename>
|
77
|
+
class GarbageCollected : public internal::GarbageCollectedBase {
|
78
|
+
public:
|
79
|
+
using IsGarbageCollectedTypeMarker = void;
|
80
|
+
|
81
|
+
protected:
|
82
|
+
GarbageCollected() = default;
|
83
|
+
};
|
84
|
+
|
85
|
+
/**
|
86
|
+
* Base class for managed mixin objects. Such objects cannot be constructed
|
87
|
+
* directly but must be mixed into the inheritance hierarchy of a
|
88
|
+
* GarbageCollected object.
|
89
|
+
*
|
90
|
+
* Types inheriting from GarbageCollectedMixin must override a virtual method
|
91
|
+
* of signature `void Trace(cppgc::Visitor*) const` that dispatchs all managed
|
92
|
+
* pointers to the visitor and delegates to base classes.
|
93
|
+
*
|
94
|
+
* \code
|
95
|
+
* class Mixin : public GarbageCollectedMixin {
|
96
|
+
* public:
|
97
|
+
* void Trace(cppgc::Visitor* visitor) const override {
|
98
|
+
* // Dispatch using visitor->Trace(...);
|
99
|
+
* }
|
100
|
+
* };
|
101
|
+
* \endcode
|
102
|
+
*/
|
103
|
+
class GarbageCollectedMixin : public internal::GarbageCollectedBase {
|
104
|
+
public:
|
105
|
+
using IsGarbageCollectedMixinTypeMarker = void;
|
106
|
+
|
107
|
+
/**
|
108
|
+
* This Trace method must be overriden by objects inheriting from
|
109
|
+
* GarbageCollectedMixin.
|
110
|
+
*/
|
111
|
+
virtual void Trace(cppgc::Visitor*) const {}
|
112
|
+
};
|
113
|
+
|
114
|
+
} // namespace cppgc
|
115
|
+
|
116
|
+
#endif // INCLUDE_CPPGC_GARBAGE_COLLECTED_H_
|