@encharm/cws 4.3.0 → 4.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -7
- package/dist/bindings/cws_darwin_arm64_node108.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node83.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node93.node +0 -0
- package/dist/bindings/cws_darwin_x64_node108.node +0 -0
- package/dist/bindings/cws_darwin_x64_node115.node +0 -0
- package/dist/bindings/cws_darwin_x64_node83.node +0 -0
- package/dist/bindings/cws_darwin_x64_node93.node +0 -0
- package/dist/bindings/cws_linux_arm64_node108.node +0 -0
- package/dist/bindings/cws_linux_arm64_node115.node +0 -0
- package/dist/bindings/cws_linux_arm64_node83.node +0 -0
- package/dist/bindings/cws_linux_arm64_node93.node +0 -0
- package/dist/bindings/cws_linux_x64_node108.node +0 -0
- package/dist/bindings/cws_linux_x64_node115.node +0 -0
- package/dist/bindings/cws_linux_x64_node83.node +0 -0
- package/dist/bindings/cws_linux_x64_node93.node +0 -0
- package/dist/bindings/cws_win32_x64_node108.node +0 -0
- package/dist/bindings/cws_win32_x64_node115.node +0 -0
- package/dist/bindings/cws_win32_x64_node83.node +0 -0
- package/dist/bindings/cws_win32_x64_node93.node +0 -0
- package/dist/shared.js +1 -1
- package/package.json +5 -5
- package/src/Addon.cpp +4 -12
- package/src/Addon.h +67 -91
- package/src/Socket.h +1 -0
- package/src/cSNode.cpp +3 -8
- package/src/headers/20/acorn_version.h +6 -0
- package/src/headers/20/aliased_buffer-inl.h +243 -0
- package/src/headers/20/aliased_buffer.h +206 -0
- package/src/headers/20/aliased_struct-inl.h +54 -0
- package/src/headers/20/aliased_struct.h +63 -0
- package/src/headers/20/async_wrap-inl.h +93 -0
- package/src/headers/20/async_wrap.h +252 -0
- package/src/headers/20/base64-inl.h +193 -0
- package/src/headers/20/base64.h +53 -0
- package/src/headers/20/base64_version.h +6 -0
- package/src/headers/20/base_object-inl.h +316 -0
- package/src/headers/20/base_object.h +320 -0
- package/src/headers/20/base_object_types.h +73 -0
- package/src/headers/20/blob_serializer_deserializer-inl.h +361 -0
- package/src/headers/20/blob_serializer_deserializer.h +132 -0
- package/src/headers/20/callback_queue-inl.h +97 -0
- package/src/headers/20/callback_queue.h +79 -0
- package/src/headers/20/cares_wrap.h +524 -0
- package/src/headers/20/cjs_module_lexer_version.h +6 -0
- package/src/headers/20/cleanup_queue-inl.h +62 -0
- package/src/headers/20/cleanup_queue.h +85 -0
- package/src/headers/20/connect_wrap.h +26 -0
- package/src/headers/20/connection_wrap.h +30 -0
- package/src/headers/20/cppgc/DEPS +8 -0
- package/src/headers/20/cppgc/OWNERS +2 -0
- package/src/headers/20/cppgc/README.md +135 -0
- package/src/headers/20/cppgc/allocation.h +310 -0
- package/src/headers/20/cppgc/common.h +28 -0
- package/src/headers/20/cppgc/cross-thread-persistent.h +466 -0
- package/src/headers/20/cppgc/custom-space.h +97 -0
- package/src/headers/20/cppgc/default-platform.h +67 -0
- package/src/headers/20/cppgc/ephemeron-pair.h +30 -0
- package/src/headers/20/cppgc/explicit-management.h +100 -0
- package/src/headers/20/cppgc/garbage-collected.h +106 -0
- package/src/headers/20/cppgc/heap-consistency.h +309 -0
- package/src/headers/20/cppgc/heap-handle.h +48 -0
- package/src/headers/20/cppgc/heap-state.h +82 -0
- package/src/headers/20/cppgc/heap-statistics.h +120 -0
- package/src/headers/20/cppgc/heap.h +202 -0
- package/src/headers/20/cppgc/internal/api-constants.h +68 -0
- package/src/headers/20/cppgc/internal/atomic-entry-flag.h +48 -0
- package/src/headers/20/cppgc/internal/base-page-handle.h +45 -0
- package/src/headers/20/cppgc/internal/caged-heap-local-data.h +111 -0
- package/src/headers/20/cppgc/internal/caged-heap.h +61 -0
- package/src/headers/20/cppgc/internal/compiler-specific.h +38 -0
- package/src/headers/20/cppgc/internal/finalizer-trait.h +93 -0
- package/src/headers/20/cppgc/internal/gc-info.h +157 -0
- package/src/headers/20/cppgc/internal/logging.h +50 -0
- package/src/headers/20/cppgc/internal/member-storage.h +248 -0
- package/src/headers/20/cppgc/internal/name-trait.h +137 -0
- package/src/headers/20/cppgc/internal/persistent-node.h +214 -0
- package/src/headers/20/cppgc/internal/pointer-policies.h +243 -0
- package/src/headers/20/cppgc/internal/write-barrier.h +487 -0
- package/src/headers/20/cppgc/liveness-broker.h +78 -0
- package/src/headers/20/cppgc/macros.h +35 -0
- package/src/headers/20/cppgc/member.h +604 -0
- package/src/headers/20/cppgc/name-provider.h +65 -0
- package/src/headers/20/cppgc/object-size-trait.h +58 -0
- package/src/headers/20/cppgc/persistent.h +373 -0
- package/src/headers/20/cppgc/platform.h +158 -0
- package/src/headers/20/cppgc/prefinalizer.h +75 -0
- package/src/headers/20/cppgc/process-heap-statistics.h +36 -0
- package/src/headers/20/cppgc/sentinel-pointer.h +32 -0
- package/src/headers/20/cppgc/source-location.h +92 -0
- package/src/headers/20/cppgc/testing.h +106 -0
- package/src/headers/20/cppgc/trace-trait.h +120 -0
- package/src/headers/20/cppgc/type-traits.h +250 -0
- package/src/headers/20/cppgc/visitor.h +426 -0
- package/src/headers/20/crypto/crypto_clienthello.h +131 -0
- package/src/headers/20/crypto/crypto_context.h +160 -0
- package/src/headers/20/crypto/crypto_keys.h +419 -0
- package/src/headers/20/crypto/crypto_tls.h +304 -0
- package/src/headers/20/crypto/crypto_util.h +806 -0
- package/src/headers/20/crypto_clienthello.h +131 -0
- package/src/headers/20/debug_utils-inl.h +226 -0
- package/src/headers/20/debug_utils.h +188 -0
- package/src/headers/20/diagnosticfilename-inl.h +33 -0
- package/src/headers/20/encoding_binding.h +59 -0
- package/src/headers/20/env-inl.h +923 -0
- package/src/headers/20/env.h +1193 -0
- package/src/headers/20/env_properties.h +446 -0
- package/src/headers/20/handle_wrap.h +123 -0
- package/src/headers/20/histogram-inl.h +107 -0
- package/src/headers/20/histogram.h +240 -0
- package/src/headers/20/inspector_agent.h +144 -0
- package/src/headers/20/inspector_io.h +78 -0
- package/src/headers/20/inspector_profiler.h +149 -0
- package/src/headers/20/inspector_socket.h +60 -0
- package/src/headers/20/inspector_socket_server.h +110 -0
- package/src/headers/20/js_native_api.h +601 -0
- package/src/headers/20/js_native_api_types.h +168 -0
- package/src/headers/20/js_native_api_v8.h +463 -0
- package/src/headers/20/js_native_api_v8_internals.h +45 -0
- package/src/headers/20/js_stream.h +52 -0
- package/src/headers/20/json_parser.h +38 -0
- package/src/headers/20/json_utils.h +172 -0
- package/src/headers/20/memory_tracker-inl.h +356 -0
- package/src/headers/20/memory_tracker.h +289 -0
- package/src/headers/20/module_wrap.h +117 -0
- package/src/headers/20/node.h +1516 -0
- package/src/headers/20/node_api.h +261 -0
- package/src/headers/20/node_api_internals.h +42 -0
- package/src/headers/20/node_api_types.h +52 -0
- package/src/headers/20/node_binding.h +142 -0
- package/src/headers/20/node_blob.h +159 -0
- package/src/headers/20/node_bob-inl.h +36 -0
- package/src/headers/20/node_bob.h +107 -0
- package/src/headers/20/node_buffer.h +92 -0
- package/src/headers/20/node_builtins.h +197 -0
- package/src/headers/20/node_constants.h +82 -0
- package/src/headers/20/node_context_data.h +98 -0
- package/src/headers/20/node_contextify.h +206 -0
- package/src/headers/20/node_crypto.h +56 -0
- package/src/headers/20/node_dir.h +52 -0
- package/src/headers/20/node_dotenv.h +37 -0
- package/src/headers/20/node_errors.h +313 -0
- package/src/headers/20/node_exit_code.h +54 -0
- package/src/headers/20/node_external_reference.h +172 -0
- package/src/headers/20/node_file-inl.h +389 -0
- package/src/headers/20/node_file.h +537 -0
- package/src/headers/20/node_http2.h +1146 -0
- package/src/headers/20/node_http2_state.h +147 -0
- package/src/headers/20/node_http_common-inl.h +201 -0
- package/src/headers/20/node_http_common.h +532 -0
- package/src/headers/20/node_i18n.h +145 -0
- package/src/headers/20/node_internals.h +443 -0
- package/src/headers/20/node_main_instance.h +67 -0
- package/src/headers/20/node_mem-inl.h +112 -0
- package/src/headers/20/node_mem.h +45 -0
- package/src/headers/20/node_messaging.h +377 -0
- package/src/headers/20/node_metadata.h +138 -0
- package/src/headers/20/node_mutex.h +323 -0
- package/src/headers/20/node_object_wrap.h +132 -0
- package/src/headers/20/node_options-inl.h +478 -0
- package/src/headers/20/node_options.h +538 -0
- package/src/headers/20/node_perf.h +166 -0
- package/src/headers/20/node_perf_common.h +98 -0
- package/src/headers/20/node_platform.h +195 -0
- package/src/headers/20/node_process-inl.h +26 -0
- package/src/headers/20/node_process.h +99 -0
- package/src/headers/20/node_realm-inl.h +139 -0
- package/src/headers/20/node_realm.h +184 -0
- package/src/headers/20/node_report.h +42 -0
- package/src/headers/20/node_revert.h +82 -0
- package/src/headers/20/node_root_certs.h +3443 -0
- package/src/headers/20/node_sea.h +56 -0
- package/src/headers/20/node_shadow_realm.h +46 -0
- package/src/headers/20/node_snapshot_builder.h +54 -0
- package/src/headers/20/node_snapshotable.h +164 -0
- package/src/headers/20/node_sockaddr-inl.h +266 -0
- package/src/headers/20/node_sockaddr.h +405 -0
- package/src/headers/20/node_stat_watcher.h +73 -0
- package/src/headers/20/node_threadsafe_cow-inl.h +54 -0
- package/src/headers/20/node_threadsafe_cow.h +105 -0
- package/src/headers/20/node_union_bytes.h +81 -0
- package/src/headers/20/node_url.h +92 -0
- package/src/headers/20/node_v8.h +77 -0
- package/src/headers/20/node_v8_platform-inl.h +205 -0
- package/src/headers/20/node_version.h +109 -0
- package/src/headers/20/node_wasi.h +184 -0
- package/src/headers/20/node_wasm_web_api.h +55 -0
- package/src/headers/20/node_watchdog.h +154 -0
- package/src/headers/20/node_worker.h +151 -0
- package/src/headers/20/permission/child_process_permission.h +29 -0
- package/src/headers/20/permission/fs_permission.h +154 -0
- package/src/headers/20/permission/inspector_permission.h +29 -0
- package/src/headers/20/permission/permission.h +74 -0
- package/src/headers/20/permission/permission_base.h +53 -0
- package/src/headers/20/permission/worker_permission.h +29 -0
- package/src/headers/20/pipe_wrap.h +80 -0
- package/src/headers/20/req_wrap-inl.h +171 -0
- package/src/headers/20/req_wrap.h +77 -0
- package/src/headers/20/spawn_sync.h +242 -0
- package/src/headers/20/stream_base-inl.h +173 -0
- package/src/headers/20/stream_base.h +469 -0
- package/src/headers/20/stream_pipe.h +76 -0
- package/src/headers/20/stream_wrap.h +131 -0
- package/src/headers/20/string_bytes.h +120 -0
- package/src/headers/20/string_decoder-inl.h +37 -0
- package/src/headers/20/string_decoder.h +50 -0
- package/src/headers/20/string_search.h +638 -0
- package/src/headers/20/tcp_wrap.h +105 -0
- package/src/headers/20/threadpoolwork-inl.h +70 -0
- package/src/headers/20/timer_wrap-inl.h +32 -0
- package/src/headers/20/timer_wrap.h +85 -0
- package/src/headers/20/timers.h +70 -0
- package/src/headers/20/tracing/agent.h +195 -0
- package/src/headers/20/tracing/node_trace_buffer.h +83 -0
- package/src/headers/20/tracing/node_trace_writer.h +75 -0
- package/src/headers/20/tracing/trace_event.h +720 -0
- package/src/headers/20/tracing/trace_event_common.h +1109 -0
- package/src/headers/20/tracing/traced_value.h +70 -0
- package/src/headers/20/tty_wrap.h +65 -0
- package/src/headers/20/udp_wrap.h +227 -0
- package/src/headers/20/undici_version.h +6 -0
- package/src/headers/20/util-inl.h +623 -0
- package/src/headers/20/util.h +988 -0
- package/src/headers/20/v8-cppgc.h +245 -0
- package/src/headers/20/v8-fast-api-calls.h +957 -0
- package/dist/bindings/cws_darwin_arm64_node64.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node72.node +0 -0
- package/dist/bindings/cws_darwin_arm64_node79.node +0 -0
- package/dist/bindings/cws_darwin_x64_node64.node +0 -0
- package/dist/bindings/cws_darwin_x64_node72.node +0 -0
- package/dist/bindings/cws_darwin_x64_node79.node +0 -0
- package/dist/bindings/cws_linux_x64_node64.node +0 -0
- package/dist/bindings/cws_linux_x64_node72.node +0 -0
- package/dist/bindings/cws_linux_x64_node79.node +0 -0
- package/dist/bindings/cws_win32_x64_node64.node +0 -0
- package/dist/bindings/cws_win32_x64_node72.node +0 -0
- package/dist/bindings/cws_win32_x64_node79.node +0 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#ifndef SRC_CLEANUP_QUEUE_H_
|
|
2
|
+
#define SRC_CLEANUP_QUEUE_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include <cstddef>
|
|
7
|
+
#include <cstdint>
|
|
8
|
+
#include <unordered_set>
|
|
9
|
+
#include <vector>
|
|
10
|
+
|
|
11
|
+
#include "memory_tracker.h"
|
|
12
|
+
|
|
13
|
+
namespace node {
|
|
14
|
+
|
|
15
|
+
class BaseObject;
|
|
16
|
+
|
|
17
|
+
class CleanupQueue : public MemoryRetainer {
|
|
18
|
+
public:
|
|
19
|
+
typedef void (*Callback)(void*);
|
|
20
|
+
|
|
21
|
+
CleanupQueue() = default;
|
|
22
|
+
|
|
23
|
+
// Not copyable.
|
|
24
|
+
CleanupQueue(const CleanupQueue&) = delete;
|
|
25
|
+
|
|
26
|
+
SET_MEMORY_INFO_NAME(CleanupQueue)
|
|
27
|
+
inline void MemoryInfo(node::MemoryTracker* tracker) const override;
|
|
28
|
+
inline size_t SelfSize() const override;
|
|
29
|
+
|
|
30
|
+
inline bool empty() const;
|
|
31
|
+
|
|
32
|
+
inline void Add(Callback cb, void* arg);
|
|
33
|
+
inline void Remove(Callback cb, void* arg);
|
|
34
|
+
void Drain();
|
|
35
|
+
|
|
36
|
+
template <typename T>
|
|
37
|
+
inline void ForEachBaseObject(T&& iterator) const;
|
|
38
|
+
|
|
39
|
+
private:
|
|
40
|
+
class CleanupHookCallback {
|
|
41
|
+
public:
|
|
42
|
+
CleanupHookCallback(Callback fn,
|
|
43
|
+
void* arg,
|
|
44
|
+
uint64_t insertion_order_counter)
|
|
45
|
+
: fn_(fn),
|
|
46
|
+
arg_(arg),
|
|
47
|
+
insertion_order_counter_(insertion_order_counter) {}
|
|
48
|
+
|
|
49
|
+
// Only hashes `arg_`, since that is usually enough to identify the hook.
|
|
50
|
+
struct Hash {
|
|
51
|
+
size_t operator()(const CleanupHookCallback& cb) const;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// Compares by `fn_` and `arg_` being equal.
|
|
55
|
+
struct Equal {
|
|
56
|
+
bool operator()(const CleanupHookCallback& a,
|
|
57
|
+
const CleanupHookCallback& b) const;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
private:
|
|
61
|
+
friend class CleanupQueue;
|
|
62
|
+
Callback fn_;
|
|
63
|
+
void* arg_;
|
|
64
|
+
|
|
65
|
+
// We keep track of the insertion order for these objects, so that we can
|
|
66
|
+
// call the callbacks in reverse order when we are cleaning up.
|
|
67
|
+
uint64_t insertion_order_counter_;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
std::vector<CleanupHookCallback> GetOrdered() const;
|
|
71
|
+
inline BaseObject* GetBaseObject(const CleanupHookCallback& callback) const;
|
|
72
|
+
|
|
73
|
+
// Use an unordered_set, so that we have efficient insertion and removal.
|
|
74
|
+
std::unordered_set<CleanupHookCallback,
|
|
75
|
+
CleanupHookCallback::Hash,
|
|
76
|
+
CleanupHookCallback::Equal>
|
|
77
|
+
cleanup_hooks_;
|
|
78
|
+
uint64_t cleanup_hook_counter_ = 0;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
} // namespace node
|
|
82
|
+
|
|
83
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
84
|
+
|
|
85
|
+
#endif // SRC_CLEANUP_QUEUE_H_
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#ifndef SRC_CONNECT_WRAP_H_
|
|
2
|
+
#define SRC_CONNECT_WRAP_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "req_wrap-inl.h"
|
|
7
|
+
#include "async_wrap.h"
|
|
8
|
+
|
|
9
|
+
namespace node {
|
|
10
|
+
|
|
11
|
+
class ConnectWrap : public ReqWrap<uv_connect_t> {
|
|
12
|
+
public:
|
|
13
|
+
ConnectWrap(Environment* env,
|
|
14
|
+
v8::Local<v8::Object> req_wrap_obj,
|
|
15
|
+
AsyncWrap::ProviderType provider);
|
|
16
|
+
|
|
17
|
+
SET_NO_MEMORY_INFO()
|
|
18
|
+
SET_MEMORY_INFO_NAME(ConnectWrap)
|
|
19
|
+
SET_SELF_SIZE(ConnectWrap)
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
} // namespace node
|
|
23
|
+
|
|
24
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
25
|
+
|
|
26
|
+
#endif // SRC_CONNECT_WRAP_H_
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#ifndef SRC_CONNECTION_WRAP_H_
|
|
2
|
+
#define SRC_CONNECTION_WRAP_H_
|
|
3
|
+
|
|
4
|
+
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
5
|
+
|
|
6
|
+
#include "stream_wrap.h"
|
|
7
|
+
|
|
8
|
+
namespace node {
|
|
9
|
+
|
|
10
|
+
class Environment;
|
|
11
|
+
|
|
12
|
+
template <typename WrapType, typename UVType>
|
|
13
|
+
class ConnectionWrap : public LibuvStreamWrap {
|
|
14
|
+
public:
|
|
15
|
+
static void OnConnection(uv_stream_t* handle, int status);
|
|
16
|
+
static void AfterConnect(uv_connect_t* req, int status);
|
|
17
|
+
|
|
18
|
+
protected:
|
|
19
|
+
ConnectionWrap(Environment* env,
|
|
20
|
+
v8::Local<v8::Object> object,
|
|
21
|
+
ProviderType provider);
|
|
22
|
+
|
|
23
|
+
UVType handle_;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
} // namespace node
|
|
27
|
+
|
|
28
|
+
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
29
|
+
|
|
30
|
+
#endif // SRC_CONNECTION_WRAP_H_
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# Oilpan: C++ Garbage Collection
|
|
2
|
+
|
|
3
|
+
Oilpan is an open-source garbage collection library for C++ that can be used stand-alone or in collaboration with V8's JavaScript garbage collector.
|
|
4
|
+
Oilpan implements mark-and-sweep garbage collection (GC) with limited compaction (for a subset of objects).
|
|
5
|
+
|
|
6
|
+
**Key properties**
|
|
7
|
+
|
|
8
|
+
- Trace-based garbage collection;
|
|
9
|
+
- Incremental and concurrent marking;
|
|
10
|
+
- Incremental and concurrent sweeping;
|
|
11
|
+
- Precise on-heap memory layout;
|
|
12
|
+
- Conservative on-stack memory layout;
|
|
13
|
+
- Allows for collection with and without considering stack;
|
|
14
|
+
- Non-incremental and non-concurrent compaction for selected spaces;
|
|
15
|
+
|
|
16
|
+
See the [Hello World](https://chromium.googlesource.com/v8/v8/+/main/samples/cppgc/hello-world.cc) example on how to get started using Oilpan to manage C++ code.
|
|
17
|
+
|
|
18
|
+
Oilpan follows V8's project organization, see e.g. on how we accept [contributions](https://v8.dev/docs/contribute) and [provide a stable API](https://v8.dev/docs/api).
|
|
19
|
+
|
|
20
|
+
## Threading model
|
|
21
|
+
|
|
22
|
+
Oilpan features thread-local garbage collection and assumes heaps are not shared among threads.
|
|
23
|
+
In other words, objects are accessed and ultimately reclaimed by the garbage collector on the same thread that allocates them.
|
|
24
|
+
This allows Oilpan to run garbage collection in parallel with mutators running in other threads.
|
|
25
|
+
|
|
26
|
+
References to objects belonging to another thread's heap are modeled using cross-thread roots.
|
|
27
|
+
This is even true for on-heap to on-heap references.
|
|
28
|
+
|
|
29
|
+
Oilpan heaps may generally not be accessed from different threads unless otherwise noted.
|
|
30
|
+
|
|
31
|
+
## Heap partitioning
|
|
32
|
+
|
|
33
|
+
Oilpan's heaps are partitioned into spaces.
|
|
34
|
+
The space for an object is chosen depending on a number of criteria, e.g.:
|
|
35
|
+
|
|
36
|
+
- Objects over 64KiB are allocated in a large object space
|
|
37
|
+
- Objects can be assigned to a dedicated custom space.
|
|
38
|
+
Custom spaces can also be marked as compactable.
|
|
39
|
+
- Other objects are allocated in one of the normal page spaces bucketed depending on their size.
|
|
40
|
+
|
|
41
|
+
## Precise and conservative garbage collection
|
|
42
|
+
|
|
43
|
+
Oilpan supports two kinds of GCs:
|
|
44
|
+
|
|
45
|
+
1. **Conservative GC.**
|
|
46
|
+
A GC is called conservative when it is executed while the regular native stack is not empty.
|
|
47
|
+
In this case, the native stack might contain references to objects in Oilpan's heap, which should be kept alive.
|
|
48
|
+
The GC scans the native stack and treats the pointers discovered via the native stack as part of the root set.
|
|
49
|
+
This kind of GC is considered imprecise because values on stack other than references may accidentally appear as references to on-heap object, which means these objects will be kept alive despite being in practice unreachable from the application as an actual reference.
|
|
50
|
+
|
|
51
|
+
2. **Precise GC.**
|
|
52
|
+
A precise GC is triggered at the end of an event loop, which is controlled by an embedder via a platform.
|
|
53
|
+
At this point, it is guaranteed that there are no on-stack references pointing to Oilpan's heap.
|
|
54
|
+
This means there is no risk of confusing other value types with references.
|
|
55
|
+
Oilpan has precise knowledge of on-heap object layouts, and so it knows exactly where pointers lie in memory.
|
|
56
|
+
Oilpan can just start marking from the regular root set and collect all garbage precisely.
|
|
57
|
+
|
|
58
|
+
## Atomic, incremental and concurrent garbage collection
|
|
59
|
+
|
|
60
|
+
Oilpan has three modes of operation:
|
|
61
|
+
|
|
62
|
+
1. **Atomic GC.**
|
|
63
|
+
The entire GC cycle, including all its phases (e.g. see [Marking](#Marking-phase) and [Sweeping](#Sweeping-phase)), are executed back to back in a single pause.
|
|
64
|
+
This mode of operation is also known as Stop-The-World (STW) garbage collection.
|
|
65
|
+
It results in the most jank (due to a single long pause), but is overall the most efficient (e.g. no need for write barriers).
|
|
66
|
+
|
|
67
|
+
2. **Incremental GC.**
|
|
68
|
+
Garbage collection work is split up into multiple steps which are interleaved with the mutator, i.e. user code chunked into tasks.
|
|
69
|
+
Each step is a small chunk of work that is executed either as dedicated tasks between mutator tasks or, as needed, during mutator tasks.
|
|
70
|
+
Using incremental GC introduces the need for write barriers that record changes to the object graph so that a consistent state is observed and no objects are accidentally considered dead and reclaimed.
|
|
71
|
+
The incremental steps are followed by a smaller atomic pause to finalize garbage collection.
|
|
72
|
+
The smaller pause times, due to smaller chunks of work, helps with reducing jank.
|
|
73
|
+
|
|
74
|
+
3. **Concurrent GC.**
|
|
75
|
+
This is the most common type of GC.
|
|
76
|
+
It builds on top of incremental GC and offloads much of the garbage collection work away from the mutator thread and on to background threads.
|
|
77
|
+
Using concurrent GC allows the mutator thread to spend less time on GC and more on the actual mutator.
|
|
78
|
+
|
|
79
|
+
## Marking phase
|
|
80
|
+
|
|
81
|
+
The marking phase consists of the following steps:
|
|
82
|
+
|
|
83
|
+
1. Mark all objects in the root set.
|
|
84
|
+
|
|
85
|
+
2. Mark all objects transitively reachable from the root set by calling `Trace()` methods defined on each object.
|
|
86
|
+
|
|
87
|
+
3. Clear out all weak handles to unreachable objects and run weak callbacks.
|
|
88
|
+
|
|
89
|
+
The marking phase can be executed atomically in a stop-the-world manner, in which all 3 steps are executed one after the other.
|
|
90
|
+
|
|
91
|
+
Alternatively, it can also be executed incrementally/concurrently.
|
|
92
|
+
With incremental/concurrent marking, step 1 is executed in a short pause after which the mutator regains control.
|
|
93
|
+
Step 2 is repeatedly executed in an interleaved manner with the mutator.
|
|
94
|
+
When the GC is ready to finalize, i.e. step 2 is (almost) finished, another short pause is triggered in which step 2 is finished and step 3 is performed.
|
|
95
|
+
|
|
96
|
+
To prevent a user-after-free (UAF) issues it is required for Oilpan to know about all edges in the object graph.
|
|
97
|
+
This means that all pointers except on-stack pointers must be wrapped with Oilpan's handles (i.e., Persistent<>, Member<>, WeakMember<>).
|
|
98
|
+
Raw pointers to on-heap objects create an edge that Oilpan cannot observe and cause UAF issues
|
|
99
|
+
Thus, raw pointers shall not be used to reference on-heap objects (except for raw pointers on native stacks).
|
|
100
|
+
|
|
101
|
+
## Sweeping phase
|
|
102
|
+
|
|
103
|
+
The sweeping phase consists of the following steps:
|
|
104
|
+
|
|
105
|
+
1. Invoke pre-finalizers.
|
|
106
|
+
At this point, no destructors have been invoked and no memory has been reclaimed.
|
|
107
|
+
Pre-finalizers are allowed to access any other on-heap objects, even those that may get destructed.
|
|
108
|
+
|
|
109
|
+
2. Sweeping invokes destructors of the dead (unreachable) objects and reclaims memory to be reused by future allocations.
|
|
110
|
+
|
|
111
|
+
Assumptions should not be made about the order and the timing of their execution.
|
|
112
|
+
There is no guarantee on the order in which the destructors are invoked.
|
|
113
|
+
That's why destructors must not access any other on-heap objects (which might have already been destructed).
|
|
114
|
+
If some destructor unavoidably needs to access other on-heap objects, it will have to be converted to a pre-finalizer.
|
|
115
|
+
The pre-finalizer is allowed to access other on-heap objects.
|
|
116
|
+
|
|
117
|
+
The mutator is resumed before all destructors have ran.
|
|
118
|
+
For example, imagine a case where X is a client of Y, and Y holds a list of clients.
|
|
119
|
+
If the code relies on X's destructor removing X from the list, there is a risk that Y iterates the list and calls some method of X which may touch other on-heap objects.
|
|
120
|
+
This causes a use-after-free.
|
|
121
|
+
Care must be taken to make sure that X is explicitly removed from the list before the mutator resumes its execution in a way that doesn't rely on X's destructor (e.g. a pre-finalizer).
|
|
122
|
+
|
|
123
|
+
Similar to marking, sweeping can be executed in either an atomic stop-the-world manner or incrementally/concurrently.
|
|
124
|
+
With incremental/concurrent sweeping, step 2 is interleaved with mutator.
|
|
125
|
+
Incremental/concurrent sweeping can be atomically finalized in case it is needed to trigger another GC cycle.
|
|
126
|
+
Even with concurrent sweeping, destructors are guaranteed to run on the thread the object has been allocated on to preserve C++ semantics.
|
|
127
|
+
|
|
128
|
+
Notes:
|
|
129
|
+
|
|
130
|
+
* Weak processing runs only when the holder object of the WeakMember outlives the pointed object.
|
|
131
|
+
If the holder object and the pointed object die at the same time, weak processing doesn't run.
|
|
132
|
+
It is wrong to write code assuming that the weak processing always runs.
|
|
133
|
+
|
|
134
|
+
* Pre-finalizers are heavy because the thread needs to scan all pre-finalizers at each sweeping phase to determine which pre-finalizers should be invoked (the thread needs to invoke pre-finalizers of dead objects).
|
|
135
|
+
Adding pre-finalizers to frequently created objects should be avoided.
|
|
@@ -0,0 +1,310 @@
|
|
|
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 <atomic>
|
|
9
|
+
#include <cstddef>
|
|
10
|
+
#include <cstdint>
|
|
11
|
+
#include <new>
|
|
12
|
+
#include <type_traits>
|
|
13
|
+
#include <utility>
|
|
14
|
+
|
|
15
|
+
#include "cppgc/custom-space.h"
|
|
16
|
+
#include "cppgc/internal/api-constants.h"
|
|
17
|
+
#include "cppgc/internal/gc-info.h"
|
|
18
|
+
#include "cppgc/type-traits.h"
|
|
19
|
+
#include "v8config.h" // NOLINT(build/include_directory)
|
|
20
|
+
|
|
21
|
+
#if defined(__has_attribute)
|
|
22
|
+
#if __has_attribute(assume_aligned)
|
|
23
|
+
#define CPPGC_DEFAULT_ALIGNED \
|
|
24
|
+
__attribute__((assume_aligned(api_constants::kDefaultAlignment)))
|
|
25
|
+
#define CPPGC_DOUBLE_WORD_ALIGNED \
|
|
26
|
+
__attribute__((assume_aligned(2 * api_constants::kDefaultAlignment)))
|
|
27
|
+
#endif // __has_attribute(assume_aligned)
|
|
28
|
+
#endif // defined(__has_attribute)
|
|
29
|
+
|
|
30
|
+
#if !defined(CPPGC_DEFAULT_ALIGNED)
|
|
31
|
+
#define CPPGC_DEFAULT_ALIGNED
|
|
32
|
+
#endif
|
|
33
|
+
|
|
34
|
+
#if !defined(CPPGC_DOUBLE_WORD_ALIGNED)
|
|
35
|
+
#define CPPGC_DOUBLE_WORD_ALIGNED
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
namespace cppgc {
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* AllocationHandle is used to allocate garbage-collected objects.
|
|
42
|
+
*/
|
|
43
|
+
class AllocationHandle;
|
|
44
|
+
|
|
45
|
+
namespace internal {
|
|
46
|
+
|
|
47
|
+
// Similar to C++17 std::align_val_t;
|
|
48
|
+
enum class AlignVal : size_t {};
|
|
49
|
+
|
|
50
|
+
class V8_EXPORT MakeGarbageCollectedTraitInternal {
|
|
51
|
+
protected:
|
|
52
|
+
static inline void MarkObjectAsFullyConstructed(const void* payload) {
|
|
53
|
+
// See api_constants for an explanation of the constants.
|
|
54
|
+
std::atomic<uint16_t>* atomic_mutable_bitfield =
|
|
55
|
+
reinterpret_cast<std::atomic<uint16_t>*>(
|
|
56
|
+
const_cast<uint16_t*>(reinterpret_cast<const uint16_t*>(
|
|
57
|
+
reinterpret_cast<const uint8_t*>(payload) -
|
|
58
|
+
api_constants::kFullyConstructedBitFieldOffsetFromPayload)));
|
|
59
|
+
// It's safe to split use load+store here (instead of a read-modify-write
|
|
60
|
+
// operation), since it's guaranteed that this 16-bit bitfield is only
|
|
61
|
+
// modified by a single thread. This is cheaper in terms of code bloat (on
|
|
62
|
+
// ARM) and performance.
|
|
63
|
+
uint16_t value = atomic_mutable_bitfield->load(std::memory_order_relaxed);
|
|
64
|
+
value |= api_constants::kFullyConstructedBitMask;
|
|
65
|
+
atomic_mutable_bitfield->store(value, std::memory_order_release);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Dispatch based on compile-time information.
|
|
69
|
+
//
|
|
70
|
+
// Default implementation is for a custom space with >`kDefaultAlignment` byte
|
|
71
|
+
// alignment.
|
|
72
|
+
template <typename GCInfoType, typename CustomSpace, size_t alignment>
|
|
73
|
+
struct AllocationDispatcher final {
|
|
74
|
+
static void* Invoke(AllocationHandle& handle, size_t size) {
|
|
75
|
+
static_assert(std::is_base_of<CustomSpaceBase, CustomSpace>::value,
|
|
76
|
+
"Custom space must inherit from CustomSpaceBase.");
|
|
77
|
+
static_assert(
|
|
78
|
+
!CustomSpace::kSupportsCompaction,
|
|
79
|
+
"Custom spaces that support compaction do not support allocating "
|
|
80
|
+
"objects with non-default (i.e. word-sized) alignment.");
|
|
81
|
+
return MakeGarbageCollectedTraitInternal::Allocate(
|
|
82
|
+
handle, size, static_cast<AlignVal>(alignment),
|
|
83
|
+
internal::GCInfoTrait<GCInfoType>::Index(), CustomSpace::kSpaceIndex);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// Fast path for regular allocations for the default space with
|
|
88
|
+
// `kDefaultAlignment` byte alignment.
|
|
89
|
+
template <typename GCInfoType>
|
|
90
|
+
struct AllocationDispatcher<GCInfoType, void,
|
|
91
|
+
api_constants::kDefaultAlignment>
|
|
92
|
+
final {
|
|
93
|
+
static void* Invoke(AllocationHandle& handle, size_t size) {
|
|
94
|
+
return MakeGarbageCollectedTraitInternal::Allocate(
|
|
95
|
+
handle, size, internal::GCInfoTrait<GCInfoType>::Index());
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// Default space with >`kDefaultAlignment` byte alignment.
|
|
100
|
+
template <typename GCInfoType, size_t alignment>
|
|
101
|
+
struct AllocationDispatcher<GCInfoType, void, alignment> final {
|
|
102
|
+
static void* Invoke(AllocationHandle& handle, size_t size) {
|
|
103
|
+
return MakeGarbageCollectedTraitInternal::Allocate(
|
|
104
|
+
handle, size, static_cast<AlignVal>(alignment),
|
|
105
|
+
internal::GCInfoTrait<GCInfoType>::Index());
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// Custom space with `kDefaultAlignment` byte alignment.
|
|
110
|
+
template <typename GCInfoType, typename CustomSpace>
|
|
111
|
+
struct AllocationDispatcher<GCInfoType, CustomSpace,
|
|
112
|
+
api_constants::kDefaultAlignment>
|
|
113
|
+
final {
|
|
114
|
+
static void* Invoke(AllocationHandle& handle, size_t size) {
|
|
115
|
+
static_assert(std::is_base_of<CustomSpaceBase, CustomSpace>::value,
|
|
116
|
+
"Custom space must inherit from CustomSpaceBase.");
|
|
117
|
+
return MakeGarbageCollectedTraitInternal::Allocate(
|
|
118
|
+
handle, size, internal::GCInfoTrait<GCInfoType>::Index(),
|
|
119
|
+
CustomSpace::kSpaceIndex);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
private:
|
|
124
|
+
static void* CPPGC_DEFAULT_ALIGNED Allocate(cppgc::AllocationHandle&, size_t,
|
|
125
|
+
GCInfoIndex);
|
|
126
|
+
static void* CPPGC_DOUBLE_WORD_ALIGNED Allocate(cppgc::AllocationHandle&,
|
|
127
|
+
size_t, AlignVal,
|
|
128
|
+
GCInfoIndex);
|
|
129
|
+
static void* CPPGC_DEFAULT_ALIGNED Allocate(cppgc::AllocationHandle&, size_t,
|
|
130
|
+
GCInfoIndex, CustomSpaceIndex);
|
|
131
|
+
static void* CPPGC_DOUBLE_WORD_ALIGNED Allocate(cppgc::AllocationHandle&,
|
|
132
|
+
size_t, AlignVal, GCInfoIndex,
|
|
133
|
+
CustomSpaceIndex);
|
|
134
|
+
|
|
135
|
+
friend class HeapObjectHeader;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
} // namespace internal
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Base trait that provides utilities for advancers users that have custom
|
|
142
|
+
* allocation needs (e.g., overriding size). It's expected that users override
|
|
143
|
+
* MakeGarbageCollectedTrait (see below) and inherit from
|
|
144
|
+
* MakeGarbageCollectedTraitBase and make use of the low-level primitives
|
|
145
|
+
* offered to allocate and construct an object.
|
|
146
|
+
*/
|
|
147
|
+
template <typename T>
|
|
148
|
+
class MakeGarbageCollectedTraitBase
|
|
149
|
+
: private internal::MakeGarbageCollectedTraitInternal {
|
|
150
|
+
private:
|
|
151
|
+
static_assert(internal::IsGarbageCollectedType<T>::value,
|
|
152
|
+
"T needs to be a garbage collected object");
|
|
153
|
+
static_assert(!IsGarbageCollectedWithMixinTypeV<T> ||
|
|
154
|
+
sizeof(T) <=
|
|
155
|
+
internal::api_constants::kLargeObjectSizeThreshold,
|
|
156
|
+
"GarbageCollectedMixin may not be a large object");
|
|
157
|
+
|
|
158
|
+
protected:
|
|
159
|
+
/**
|
|
160
|
+
* Allocates memory for an object of type T.
|
|
161
|
+
*
|
|
162
|
+
* \param handle AllocationHandle identifying the heap to allocate the object
|
|
163
|
+
* on.
|
|
164
|
+
* \param size The size that should be reserved for the object.
|
|
165
|
+
* \returns the memory to construct an object of type T on.
|
|
166
|
+
*/
|
|
167
|
+
V8_INLINE static void* Allocate(AllocationHandle& handle, size_t size) {
|
|
168
|
+
static_assert(
|
|
169
|
+
std::is_base_of<typename T::ParentMostGarbageCollectedType, T>::value,
|
|
170
|
+
"U of GarbageCollected<U> must be a base of T. Check "
|
|
171
|
+
"GarbageCollected<T> base class inheritance.");
|
|
172
|
+
static constexpr size_t kWantedAlignment =
|
|
173
|
+
alignof(T) < internal::api_constants::kDefaultAlignment
|
|
174
|
+
? internal::api_constants::kDefaultAlignment
|
|
175
|
+
: alignof(T);
|
|
176
|
+
static_assert(
|
|
177
|
+
kWantedAlignment <= internal::api_constants::kMaxSupportedAlignment,
|
|
178
|
+
"Requested alignment larger than alignof(std::max_align_t) bytes. "
|
|
179
|
+
"Please file a bug to possibly get this restriction lifted.");
|
|
180
|
+
return AllocationDispatcher<
|
|
181
|
+
typename internal::GCInfoFolding<
|
|
182
|
+
T, typename T::ParentMostGarbageCollectedType>::ResultType,
|
|
183
|
+
typename SpaceTrait<T>::Space, kWantedAlignment>::Invoke(handle, size);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Marks an object as fully constructed, resulting in precise handling by the
|
|
188
|
+
* garbage collector.
|
|
189
|
+
*
|
|
190
|
+
* \param payload The base pointer the object is allocated at.
|
|
191
|
+
*/
|
|
192
|
+
V8_INLINE static void MarkObjectAsFullyConstructed(const void* payload) {
|
|
193
|
+
internal::MakeGarbageCollectedTraitInternal::MarkObjectAsFullyConstructed(
|
|
194
|
+
payload);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Passed to MakeGarbageCollected to specify how many bytes should be appended
|
|
200
|
+
* to the allocated object.
|
|
201
|
+
*
|
|
202
|
+
* Example:
|
|
203
|
+
* \code
|
|
204
|
+
* class InlinedArray final : public GarbageCollected<InlinedArray> {
|
|
205
|
+
* public:
|
|
206
|
+
* explicit InlinedArray(size_t bytes) : size(bytes), byte_array(this + 1) {}
|
|
207
|
+
* void Trace(Visitor*) const {}
|
|
208
|
+
|
|
209
|
+
* size_t size;
|
|
210
|
+
* char* byte_array;
|
|
211
|
+
* };
|
|
212
|
+
*
|
|
213
|
+
* auto* inlined_array = MakeGarbageCollected<InlinedArray(
|
|
214
|
+
* GetAllocationHandle(), AdditionalBytes(4), 4);
|
|
215
|
+
* for (size_t i = 0; i < 4; i++) {
|
|
216
|
+
* Process(inlined_array->byte_array[i]);
|
|
217
|
+
* }
|
|
218
|
+
* \endcode
|
|
219
|
+
*/
|
|
220
|
+
struct AdditionalBytes {
|
|
221
|
+
constexpr explicit AdditionalBytes(size_t bytes) : value(bytes) {}
|
|
222
|
+
const size_t value;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Default trait class that specifies how to construct an object of type T.
|
|
227
|
+
* Advanced users may override how an object is constructed using the utilities
|
|
228
|
+
* that are provided through MakeGarbageCollectedTraitBase.
|
|
229
|
+
*
|
|
230
|
+
* Any trait overriding construction must
|
|
231
|
+
* - allocate through `MakeGarbageCollectedTraitBase<T>::Allocate`;
|
|
232
|
+
* - mark the object as fully constructed using
|
|
233
|
+
* `MakeGarbageCollectedTraitBase<T>::MarkObjectAsFullyConstructed`;
|
|
234
|
+
*/
|
|
235
|
+
template <typename T>
|
|
236
|
+
class MakeGarbageCollectedTrait : public MakeGarbageCollectedTraitBase<T> {
|
|
237
|
+
public:
|
|
238
|
+
template <typename... Args>
|
|
239
|
+
static T* Call(AllocationHandle& handle, Args&&... args) {
|
|
240
|
+
void* memory =
|
|
241
|
+
MakeGarbageCollectedTraitBase<T>::Allocate(handle, sizeof(T));
|
|
242
|
+
T* object = ::new (memory) T(std::forward<Args>(args)...);
|
|
243
|
+
MakeGarbageCollectedTraitBase<T>::MarkObjectAsFullyConstructed(object);
|
|
244
|
+
return object;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
template <typename... Args>
|
|
248
|
+
static T* Call(AllocationHandle& handle, AdditionalBytes additional_bytes,
|
|
249
|
+
Args&&... args) {
|
|
250
|
+
void* memory = MakeGarbageCollectedTraitBase<T>::Allocate(
|
|
251
|
+
handle, sizeof(T) + additional_bytes.value);
|
|
252
|
+
T* object = ::new (memory) T(std::forward<Args>(args)...);
|
|
253
|
+
MakeGarbageCollectedTraitBase<T>::MarkObjectAsFullyConstructed(object);
|
|
254
|
+
return object;
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Allows users to specify a post-construction callback for specific types. The
|
|
260
|
+
* callback is invoked on the instance of type T right after it has been
|
|
261
|
+
* constructed. This can be useful when the callback requires a
|
|
262
|
+
* fully-constructed object to be able to dispatch to virtual methods.
|
|
263
|
+
*/
|
|
264
|
+
template <typename T, typename = void>
|
|
265
|
+
struct PostConstructionCallbackTrait {
|
|
266
|
+
static void Call(T*) {}
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Constructs a managed object of type T where T transitively inherits from
|
|
271
|
+
* GarbageCollected.
|
|
272
|
+
*
|
|
273
|
+
* \param args List of arguments with which an instance of T will be
|
|
274
|
+
* constructed.
|
|
275
|
+
* \returns an instance of type T.
|
|
276
|
+
*/
|
|
277
|
+
template <typename T, typename... Args>
|
|
278
|
+
V8_INLINE T* MakeGarbageCollected(AllocationHandle& handle, Args&&... args) {
|
|
279
|
+
T* object =
|
|
280
|
+
MakeGarbageCollectedTrait<T>::Call(handle, std::forward<Args>(args)...);
|
|
281
|
+
PostConstructionCallbackTrait<T>::Call(object);
|
|
282
|
+
return object;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Constructs a managed object of type T where T transitively inherits from
|
|
287
|
+
* GarbageCollected. Created objects will have additional bytes appended to
|
|
288
|
+
* it. Allocated memory would suffice for `sizeof(T) + additional_bytes`.
|
|
289
|
+
*
|
|
290
|
+
* \param additional_bytes Denotes how many bytes to append to T.
|
|
291
|
+
* \param args List of arguments with which an instance of T will be
|
|
292
|
+
* constructed.
|
|
293
|
+
* \returns an instance of type T.
|
|
294
|
+
*/
|
|
295
|
+
template <typename T, typename... Args>
|
|
296
|
+
V8_INLINE T* MakeGarbageCollected(AllocationHandle& handle,
|
|
297
|
+
AdditionalBytes additional_bytes,
|
|
298
|
+
Args&&... args) {
|
|
299
|
+
T* object = MakeGarbageCollectedTrait<T>::Call(handle, additional_bytes,
|
|
300
|
+
std::forward<Args>(args)...);
|
|
301
|
+
PostConstructionCallbackTrait<T>::Call(object);
|
|
302
|
+
return object;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
} // namespace cppgc
|
|
306
|
+
|
|
307
|
+
#undef CPPGC_DEFAULT_ALIGNED
|
|
308
|
+
#undef CPPGC_DOUBLE_WORD_ALIGNED
|
|
309
|
+
|
|
310
|
+
#endif // INCLUDE_CPPGC_ALLOCATION_H_
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
#include "v8config.h" // NOLINT(build/include_directory)
|
|
9
|
+
|
|
10
|
+
namespace cppgc {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Indicator for the stack state of the embedder.
|
|
14
|
+
*/
|
|
15
|
+
enum class EmbedderStackState {
|
|
16
|
+
/**
|
|
17
|
+
* Stack may contain interesting heap pointers.
|
|
18
|
+
*/
|
|
19
|
+
kMayContainHeapPointers,
|
|
20
|
+
/**
|
|
21
|
+
* Stack does not contain any interesting heap pointers.
|
|
22
|
+
*/
|
|
23
|
+
kNoHeapPointers,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
} // namespace cppgc
|
|
27
|
+
|
|
28
|
+
#endif // INCLUDE_CPPGC_COMMON_H_
|