diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/heap_utils.cc | 9 | ||||
-rw-r--r-- | src/inspector_profiler.cc | 12 | ||||
-rw-r--r-- | src/node_external_reference.h | 9 | ||||
-rw-r--r-- | src/node_serdes.cc | 36 | ||||
-rw-r--r-- | src/node_snapshotable.h | 3 | ||||
-rw-r--r-- | src/node_v8.cc | 41 | ||||
-rw-r--r-- | src/node_v8.h | 7 | ||||
-rw-r--r-- | src/stream_wrap.cc | 20 | ||||
-rw-r--r-- | src/stream_wrap.h | 3 | ||||
-rw-r--r-- | src/uv.cc | 12 |
10 files changed, 130 insertions, 22 deletions
diff --git a/src/heap_utils.cc b/src/heap_utils.cc index c0c9ac2bdc7..bc779489637 100644 --- a/src/heap_utils.cc +++ b/src/heap_utils.cc @@ -1,6 +1,7 @@ #include "diagnosticfilename-inl.h" #include "env-inl.h" #include "memory_tracker-inl.h" +#include "node_external_reference.h" #include "stream_base-inl.h" #include "util-inl.h" @@ -399,7 +400,15 @@ void Initialize(Local<Object> target, env->SetMethod(target, "createHeapSnapshotStream", CreateHeapSnapshotStream); } +void RegisterExternalReferences(ExternalReferenceRegistry* registry) { + registry->Register(BuildEmbedderGraph); + registry->Register(TriggerHeapSnapshot); + registry->Register(CreateHeapSnapshotStream); +} + } // namespace heap } // namespace node NODE_MODULE_CONTEXT_AWARE_INTERNAL(heap_utils, node::heap::Initialize) +NODE_MODULE_EXTERNAL_REFERENCE(heap_utils, + node::heap::RegisterExternalReferences) diff --git a/src/inspector_profiler.cc b/src/inspector_profiler.cc index 092b263ada2..e40b4b99cc8 100644 --- a/src/inspector_profiler.cc +++ b/src/inspector_profiler.cc @@ -3,8 +3,9 @@ #include "debug_utils-inl.h" #include "diagnosticfilename-inl.h" #include "memory_tracker-inl.h" -#include "node_file.h" #include "node_errors.h" +#include "node_external_reference.h" +#include "node_file.h" #include "node_internals.h" #include "util-inl.h" #include "v8-inspector.h" @@ -519,7 +520,16 @@ static void Initialize(Local<Object> target, env->SetMethod(target, "stopCoverage", StopCoverage); } +void RegisterExternalReferences(ExternalReferenceRegistry* registry) { + registry->Register(SetCoverageDirectory); + registry->Register(SetSourceMapCacheGetter); + registry->Register(TakeCoverage); + registry->Register(StopCoverage); +} + } // namespace profiler } // namespace node NODE_MODULE_CONTEXT_AWARE_INTERNAL(profiler, node::profiler::Initialize) +NODE_MODULE_EXTERNAL_REFERENCE(profiler, + node::profiler::RegisterExternalReferences) diff --git a/src/node_external_reference.h b/src/node_external_reference.h index 71d155cdb92..316d1d7b865 100644 --- a/src/node_external_reference.h +++ b/src/node_external_reference.h @@ -56,6 +56,7 @@ class ExternalReferenceRegistry { V(fs) \ V(fs_dir) \ V(handle_wrap) \ + V(heap_utils) \ V(messaging) \ V(native_module) \ V(process_methods) \ @@ -63,10 +64,14 @@ class ExternalReferenceRegistry { V(task_queue) \ V(url) \ V(util) \ + V(serdes) \ V(string_decoder) \ + V(stream_wrap) \ V(trace_events) \ V(timers) \ V(types) \ + V(uv) \ + V(v8) \ V(worker) #if NODE_HAVE_I18N_SUPPORT @@ -76,7 +81,9 @@ class ExternalReferenceRegistry { #endif // NODE_HAVE_I18N_SUPPORT #if HAVE_INSPECTOR -#define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V) V(inspector) +#define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V) \ + V(inspector) \ + V(profiler) #else #define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V) #endif // HAVE_INSPECTOR diff --git a/src/node_serdes.cc b/src/node_serdes.cc index 879253f9bc2..be16f4dd053 100644 --- a/src/node_serdes.cc +++ b/src/node_serdes.cc @@ -1,8 +1,9 @@ -#include "node_internals.h" +#include "base_object-inl.h" #include "node_buffer.h" #include "node_errors.h" +#include "node_external_reference.h" +#include "node_internals.h" #include "util-inl.h" -#include "base_object-inl.h" namespace node { @@ -26,7 +27,7 @@ using v8::Value; using v8::ValueDeserializer; using v8::ValueSerializer; -namespace { +namespace serdes { class SerializerContext : public BaseObject, public ValueSerializer::Delegate { @@ -503,7 +504,32 @@ void Initialize(Local<Object> target, env->SetConstructorFunction(target, "Deserializer", des); } -} // anonymous namespace +void RegisterExternalReferences(ExternalReferenceRegistry* registry) { + registry->Register(SerializerContext::New); + + registry->Register(SerializerContext::WriteHeader); + registry->Register(SerializerContext::WriteValue); + registry->Register(SerializerContext::ReleaseBuffer); + registry->Register(SerializerContext::TransferArrayBuffer); + registry->Register(SerializerContext::WriteUint32); + registry->Register(SerializerContext::WriteUint64); + registry->Register(SerializerContext::WriteDouble); + registry->Register(SerializerContext::WriteRawBytes); + registry->Register(SerializerContext::SetTreatArrayBufferViewsAsHostObjects); + + registry->Register(DeserializerContext::New); + registry->Register(DeserializerContext::ReadHeader); + registry->Register(DeserializerContext::ReadValue); + registry->Register(DeserializerContext::GetWireFormatVersion); + registry->Register(DeserializerContext::TransferArrayBuffer); + registry->Register(DeserializerContext::ReadUint32); + registry->Register(DeserializerContext::ReadUint64); + registry->Register(DeserializerContext::ReadDouble); + registry->Register(DeserializerContext::ReadRawBytes); +} + +} // namespace serdes } // namespace node -NODE_MODULE_CONTEXT_AWARE_INTERNAL(serdes, node::Initialize) +NODE_MODULE_CONTEXT_AWARE_INTERNAL(serdes, node::serdes::Initialize) +NODE_MODULE_EXTERNAL_REFERENCE(serdes, node::serdes::RegisterExternalReferences) diff --git a/src/node_snapshotable.h b/src/node_snapshotable.h index d0fbce800a6..3a0d3e42f4c 100644 --- a/src/node_snapshotable.h +++ b/src/node_snapshotable.h @@ -13,7 +13,8 @@ class Environment; struct EnvSerializeInfo; #define SERIALIZABLE_OBJECT_TYPES(V) \ - V(fs_binding_data, fs::BindingData) + V(fs_binding_data, fs::BindingData) \ + V(v8_binding_data, v8_utils::BindingData) enum class EmbedderObjectType : uint8_t { k_default = 0, diff --git a/src/node_v8.cc b/src/node_v8.cc index 4354e1e1772..c1098e2d339 100644 --- a/src/node_v8.cc +++ b/src/node_v8.cc @@ -24,6 +24,7 @@ #include "env-inl.h" #include "memory_tracker-inl.h" #include "node.h" +#include "node_external_reference.h" #include "util-inl.h" #include "v8.h" @@ -32,6 +33,7 @@ namespace v8_utils { using v8::Array; using v8::Context; using v8::FunctionCallbackInfo; +using v8::HandleScope; using v8::HeapCodeStatistics; using v8::HeapSpaceStatistics; using v8::HeapStatistics; @@ -45,6 +47,7 @@ using v8::Uint32; using v8::V8; using v8::Value; + #define HEAP_STATISTICS_PROPERTIES(V) \ V(0, total_heap_size, kTotalHeapSizeIndex) \ V(1, total_heap_size_executable, kTotalHeapSizeExecutableIndex) \ @@ -85,7 +88,7 @@ static const size_t kHeapCodeStatisticsPropertiesCount = #undef V BindingData::BindingData(Environment* env, Local<Object> obj) - : BaseObject(env, obj), + : SnapshotableObject(env, obj, type_int), heap_statistics_buffer(env->isolate(), kHeapStatisticsPropertiesCount), heap_space_statistics_buffer(env->isolate(), kHeapSpaceStatisticsPropertiesCount), @@ -105,6 +108,32 @@ BindingData::BindingData(Environment* env, Local<Object> obj) .Check(); } +void BindingData::PrepareForSerialization(Local<Context> context, + v8::SnapshotCreator* creator) { + // We'll just re-initialize the buffers in the constructor since their + // contents can be thrown away once consumed in the previous call. + heap_statistics_buffer.Release(); + heap_space_statistics_buffer.Release(); + heap_code_statistics_buffer.Release(); +} + +void BindingData::Deserialize(Local<Context> context, + Local<Object> holder, + int index, + InternalFieldInfo* info) { + DCHECK_EQ(index, BaseObject::kSlot); + HandleScope scope(context->GetIsolate()); + Environment* env = Environment::GetCurrent(context); + BindingData* binding = env->AddBindingData<BindingData>(context, holder); + CHECK_NOT_NULL(binding); +} + +InternalFieldInfo* BindingData::Serialize(int index) { + DCHECK_EQ(index, BaseObject::kSlot); + InternalFieldInfo* info = InternalFieldInfo::New(type()); + return info; +} + void BindingData::MemoryInfo(MemoryTracker* tracker) const { tracker->TrackField("heap_statistics_buffer", heap_statistics_buffer); tracker->TrackField("heap_space_statistics_buffer", @@ -168,7 +197,6 @@ void SetFlagsFromString(const FunctionCallbackInfo<Value>& args) { V8::SetFlagsFromString(*flags, static_cast<size_t>(flags.length())); } - void Initialize(Local<Object> target, Local<Value> unused, Local<Context> context, @@ -223,7 +251,16 @@ void Initialize(Local<Object> target, env->SetMethod(target, "setFlagsFromString", SetFlagsFromString); } +void RegisterExternalReferences(ExternalReferenceRegistry* registry) { + registry->Register(CachedDataVersionTag); + registry->Register(UpdateHeapStatisticsBuffer); + registry->Register(UpdateHeapCodeStatisticsBuffer); + registry->Register(UpdateHeapSpaceStatisticsBuffer); + registry->Register(SetFlagsFromString); +} + } // namespace v8_utils } // namespace node NODE_MODULE_CONTEXT_AWARE_INTERNAL(v8, node::v8_utils::Initialize) +NODE_MODULE_EXTERNAL_REFERENCE(v8, node::v8_utils::RegisterExternalReferences) diff --git a/src/node_v8.h b/src/node_v8.h index 745c6580b84..5de8cb3f9c6 100644 --- a/src/node_v8.h +++ b/src/node_v8.h @@ -5,18 +5,23 @@ #include "aliased_buffer.h" #include "base_object.h" +#include "node_snapshotable.h" #include "util.h" #include "v8.h" namespace node { class Environment; +struct InternalFieldInfo; namespace v8_utils { -class BindingData : public BaseObject { +class BindingData : public SnapshotableObject { public: BindingData(Environment* env, v8::Local<v8::Object> obj); + SERIALIZABLE_OBJECT_METHODS() static constexpr FastStringKey type_name{"node::v8::BindingData"}; + static constexpr EmbedderObjectType type_int = + EmbedderObjectType::k_v8_binding_data; AliasedFloat64Array heap_statistics_buffer; AliasedFloat64Array heap_space_statistics_buffer; diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index a1fa5e94b73..78d20f912b4 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -25,6 +25,7 @@ #include "env-inl.h" #include "handle_wrap.h" #include "node_buffer.h" +#include "node_external_reference.h" #include "pipe_wrap.h" #include "req_wrap-inl.h" #include "tcp_wrap.h" @@ -51,6 +52,10 @@ using v8::ReadOnly; using v8::Signature; using v8::Value; +void IsConstructCallCallback(const FunctionCallbackInfo<Value>& args) { + CHECK(args.IsConstructCall()); + StreamReq::ResetObject(args.This()); +} void LibuvStreamWrap::Initialize(Local<Object> target, Local<Value> unused, @@ -58,13 +63,8 @@ void LibuvStreamWrap::Initialize(Local<Object> target, void* priv) { Environment* env = Environment::GetCurrent(context); - auto is_construct_call_callback = - [](const FunctionCallbackInfo<Value>& args) { - CHECK(args.IsConstructCall()); - StreamReq::ResetObject(args.This()); - }; Local<FunctionTemplate> sw = - FunctionTemplate::New(env->isolate(), is_construct_call_callback); + FunctionTemplate::New(env->isolate(), IsConstructCallCallback); sw->InstanceTemplate()->SetInternalFieldCount(StreamReq::kInternalFieldCount); // we need to set handle and callback to null, @@ -88,7 +88,7 @@ void LibuvStreamWrap::Initialize(Local<Object> target, env->set_shutdown_wrap_template(sw->InstanceTemplate()); Local<FunctionTemplate> ww = - FunctionTemplate::New(env->isolate(), is_construct_call_callback); + FunctionTemplate::New(env->isolate(), IsConstructCallCallback); ww->InstanceTemplate()->SetInternalFieldCount( StreamReq::kInternalFieldCount); ww->Inherit(AsyncWrap::GetConstructorTemplate(env)); @@ -103,6 +103,10 @@ void LibuvStreamWrap::Initialize(Local<Object> target, env->stream_base_state().GetJSArray()).Check(); } +void LibuvStreamWrap::RegisterExternalReferences( + ExternalReferenceRegistry* registry) { + registry->Register(IsConstructCallCallback); +} LibuvStreamWrap::LibuvStreamWrap(Environment* env, Local<Object> object, @@ -396,3 +400,5 @@ void LibuvStreamWrap::AfterUvWrite(uv_write_t* req, int status) { NODE_MODULE_CONTEXT_AWARE_INTERNAL(stream_wrap, node::LibuvStreamWrap::Initialize) +NODE_MODULE_EXTERNAL_REFERENCE( + stream_wrap, node::LibuvStreamWrap::RegisterExternalReferences) diff --git a/src/stream_wrap.h b/src/stream_wrap.h index 816f557ee6c..3016e8d89cd 100644 --- a/src/stream_wrap.h +++ b/src/stream_wrap.h @@ -31,6 +31,7 @@ namespace node { class Environment; +class ExternalReferenceRegistry; class LibuvStreamWrap : public HandleWrap, public StreamBase { public: @@ -38,7 +39,7 @@ class LibuvStreamWrap : public HandleWrap, public StreamBase { v8::Local<v8::Value> unused, v8::Local<v8::Context> context, void* priv); - + static void RegisterExternalReferences(ExternalReferenceRegistry* registry); int GetFD() override; bool IsAlive() override; bool IsClosing() override; diff --git a/src/uv.cc b/src/uv.cc index 7347826cab0..0e6672c4726 100644 --- a/src/uv.cc +++ b/src/uv.cc @@ -22,6 +22,7 @@ #include "uv.h" #include "env-inl.h" #include "node.h" +#include "node_external_reference.h" #include "node_process.h" namespace node { @@ -42,7 +43,7 @@ static const struct UVError uv_errors_map[] = { }; } // namespace per_process -namespace { +namespace uv { using v8::Array; using v8::Context; @@ -130,7 +131,12 @@ void Initialize(Local<Object> target, env->SetMethod(target, "getErrorMap", GetErrMap); } -} // anonymous namespace +void RegisterExternalReferences(ExternalReferenceRegistry* registry) { + registry->Register(ErrName); + registry->Register(GetErrMap); +} +} // namespace uv } // namespace node -NODE_MODULE_CONTEXT_AWARE_INTERNAL(uv, node::Initialize) +NODE_MODULE_CONTEXT_AWARE_INTERNAL(uv, node::uv::Initialize) +NODE_MODULE_EXTERNAL_REFERENCE(uv, node::uv::RegisterExternalReferences) |