| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -279,6 +279,7 @@ process.emitWarning = emitWarning; | |||
| 279 | 279 | ||
| 280 | 280 | // Preload modules so that they are included in the builtin snapshot. | |
| 281 | 281 | require('fs'); | |
| 282 | + require('v8'); | ||
| 282 | 283 | ||
| 283 | 284 | function setupPrepareStackTrace() { | |
| 284 | 285 | const { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -72,12 +72,13 @@ function getHeapSnapshot() { | |||
| 72 | 72 | return new HeapSnapshotStream(handle); | |
| 73 | 73 | } | |
| 74 | 74 | ||
| 75 | + // We need to get the buffer from the binding at the callsite since | ||
| 76 | + // it's re-initialized after deserialization. | ||
| 77 | + const binding = internalBinding('v8'); | ||
| 78 | + | ||
| 75 | 79 | const { | |
| 76 | 80 | cachedDataVersionTag, | |
| 77 | 81 | setFlagsFromString: _setFlagsFromString, | |
| 78 | - heapStatisticsBuffer, | ||
| 79 | - heapSpaceStatisticsBuffer, | ||
| 80 | - heapCodeStatisticsBuffer, | ||
| 81 | 82 | updateHeapStatisticsBuffer, | |
| 82 | 83 | updateHeapSpaceStatisticsBuffer, | |
| 83 | 84 | updateHeapCodeStatisticsBuffer, | |
@@ -106,7 +107,7 @@ const { | |||
| 106 | 107 | kCodeAndMetadataSizeIndex, | |
| 107 | 108 | kBytecodeAndMetadataSizeIndex, | |
| 108 | 109 | kExternalScriptSourceSizeIndex | |
| 109 | - } = internalBinding('v8'); | ||
| 110 | + } = binding; | ||
| 110 | 111 | ||
| 111 | 112 | const kNumberOfHeapSpaces = kHeapSpaces.length; | |
| 112 | 113 | ||
@@ -116,7 +117,7 @@ function setFlagsFromString(flags) { | |||
| 116 | 117 | } | |
| 117 | 118 | ||
| 118 | 119 | function getHeapStatistics() { | |
| 119 | - const buffer = heapStatisticsBuffer; | ||
| 120 | + const buffer = binding.heapStatisticsBuffer; | ||
| 120 | 121 | ||
| 121 | 122 | updateHeapStatisticsBuffer(); | |
| 122 | 123 | ||
@@ -137,7 +138,7 @@ function getHeapStatistics() { | |||
| 137 | 138 | ||
| 138 | 139 | function getHeapSpaceStatistics() { | |
| 139 | 140 | const heapSpaceStatistics = new Array(kNumberOfHeapSpaces); | |
| 140 | - const buffer = heapSpaceStatisticsBuffer; | ||
| 141 | + const buffer = binding.heapSpaceStatisticsBuffer; | ||
| 141 | 142 | ||
| 142 | 143 | for (let i = 0; i < kNumberOfHeapSpaces; i++) { | |
| 143 | 144 | updateHeapSpaceStatisticsBuffer(i); | |
@@ -154,7 +155,7 @@ function getHeapSpaceStatistics() { | |||
| 154 | 155 | } | |
| 155 | 156 | ||
| 156 | 157 | function getHeapCodeStatistics() { | |
| 157 | - const buffer = heapCodeStatisticsBuffer; | ||
| 158 | + const buffer = binding.heapCodeStatisticsBuffer; | ||
| 158 | 159 | ||
| 159 | 160 | updateHeapCodeStatisticsBuffer(); | |
| 160 | 161 | return { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | #include "diagnosticfilename-inl.h" | |
| 2 | 2 | #include "env-inl.h" | |
| 3 | 3 | #include "memory_tracker-inl.h" | |
| 4 | + #include "node_external_reference.h" | ||
| 4 | 5 | #include "stream_base-inl.h" | |
| 5 | 6 | #include "util-inl.h" | |
| 6 | 7 | ||
@@ -399,7 +400,15 @@ void Initialize(Local<Object> target, | |||
| 399 | 400 | env->SetMethod(target, "createHeapSnapshotStream", CreateHeapSnapshotStream); | |
| 400 | 401 | } | |
| 401 | 402 | ||
| 403 | + void RegisterExternalReferences(ExternalReferenceRegistry* registry) { | ||
| 404 | + registry->Register(BuildEmbedderGraph); | ||
| 405 | + registry->Register(TriggerHeapSnapshot); | ||
| 406 | + registry->Register(CreateHeapSnapshotStream); | ||
| 407 | + } | ||
| 408 | + | ||
| 402 | 409 | } // namespace heap | |
| 403 | 410 | } // namespace node | |
| 404 | 411 | ||
| 405 | 412 | NODE_MODULE_CONTEXT_AWARE_INTERNAL(heap_utils, node::heap::Initialize) | |
| 413 | + NODE_MODULE_EXTERNAL_REFERENCE(heap_utils, | ||
| 414 | + node::heap::RegisterExternalReferences) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,8 +3,9 @@ | |||
| 3 | 3 | #include "debug_utils-inl.h" | |
| 4 | 4 | #include "diagnosticfilename-inl.h" | |
| 5 | 5 | #include "memory_tracker-inl.h" | |
| 6 | - #include "node_file.h" | ||
| 7 | 6 | #include "node_errors.h" | |
| 7 | + #include "node_external_reference.h" | ||
| 8 | + #include "node_file.h" | ||
| 8 | 9 | #include "node_internals.h" | |
| 9 | 10 | #include "util-inl.h" | |
| 10 | 11 | #include "v8-inspector.h" | |
@@ -519,7 +520,16 @@ static void Initialize(Local<Object> target, | |||
| 519 | 520 | env->SetMethod(target, "stopCoverage", StopCoverage); | |
| 520 | 521 | } | |
| 521 | 522 | ||
| 523 | + void RegisterExternalReferences(ExternalReferenceRegistry* registry) { | ||
| 524 | + registry->Register(SetCoverageDirectory); | ||
| 525 | + registry->Register(SetSourceMapCacheGetter); | ||
| 526 | + registry->Register(TakeCoverage); | ||
| 527 | + registry->Register(StopCoverage); | ||
| 528 | + } | ||
| 529 | + | ||
| 522 | 530 | } // namespace profiler | |
| 523 | 531 | } // namespace node | |
| 524 | 532 | ||
| 525 | 533 | NODE_MODULE_CONTEXT_AWARE_INTERNAL(profiler, node::profiler::Initialize) | |
| 534 | + NODE_MODULE_EXTERNAL_REFERENCE(profiler, | ||
| 535 | + node::profiler::RegisterExternalReferences) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,17 +56,22 @@ class ExternalReferenceRegistry { | |||
| 56 | 56 | V(fs) \ | |
| 57 | 57 | V(fs_dir) \ | |
| 58 | 58 | V(handle_wrap) \ | |
| 59 | + V(heap_utils) \ | ||
| 59 | 60 | V(messaging) \ | |
| 60 | 61 | V(native_module) \ | |
| 61 | 62 | V(process_methods) \ | |
| 62 | 63 | V(process_object) \ | |
| 63 | 64 | V(task_queue) \ | |
| 64 | 65 | V(url) \ | |
| 65 | 66 | V(util) \ | |
| 67 | + V(serdes) \ | ||
| 66 | 68 | V(string_decoder) \ | |
| 69 | + V(stream_wrap) \ | ||
| 67 | 70 | V(trace_events) \ | |
| 68 | 71 | V(timers) \ | |
| 69 | 72 | V(types) \ | |
| 73 | + V(uv) \ | ||
| 74 | + V(v8) \ | ||
| 70 | 75 | V(worker) | |
| 71 | 76 | ||
| 72 | 77 | #if NODE_HAVE_I18N_SUPPORT | |
@@ -76,7 +81,9 @@ class ExternalReferenceRegistry { | |||
| 76 | 81 | #endif // NODE_HAVE_I18N_SUPPORT | |
| 77 | 82 | ||
| 78 | 83 | #if HAVE_INSPECTOR | |
| 79 | - #define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V) V(inspector) | ||
| 84 | + #define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V) \ | ||
| 85 | + V(inspector) \ | ||
| 86 | + V(profiler) | ||
| 80 | 87 | #else | |
| 81 | 88 | #define EXTERNAL_REFERENCE_BINDING_LIST_INSPECTOR(V) | |
| 82 | 89 | #endif // HAVE_INSPECTOR | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,9 @@ | |||
| 1 | - #include "node_internals.h" | ||
| 1 | + #include "base_object-inl.h" | ||
| 2 | 2 | #include "node_buffer.h" | |
| 3 | 3 | #include "node_errors.h" | |
| 4 | + #include "node_external_reference.h" | ||
| 5 | + #include "node_internals.h" | ||
| 4 | 6 | #include "util-inl.h" | |
| 5 | - #include "base_object-inl.h" | ||
| 6 | 7 | ||
| 7 | 8 | namespace node { | |
| 8 | 9 | ||
@@ -26,7 +27,7 @@ using v8::Value; | |||
| 26 | 27 | using v8::ValueDeserializer; | |
| 27 | 28 | using v8::ValueSerializer; | |
| 28 | 29 | ||
| 29 | - namespace { | ||
| 30 | + namespace serdes { | ||
| 30 | 31 | ||
| 31 | 32 | class SerializerContext : public BaseObject, | |
| 32 | 33 | public ValueSerializer::Delegate { | |
@@ -503,7 +504,32 @@ void Initialize(Local<Object> target, | |||
| 503 | 504 | env->SetConstructorFunction(target, "Deserializer", des); | |
| 504 | 505 | } | |
| 505 | 506 | ||
| 506 | - } // anonymous namespace | ||
| 507 | + void RegisterExternalReferences(ExternalReferenceRegistry* registry) { | ||
| 508 | + registry->Register(SerializerContext::New); | ||
| 509 | + | ||
| 510 | + registry->Register(SerializerContext::WriteHeader); | ||
| 511 | + registry->Register(SerializerContext::WriteValue); | ||
| 512 | + registry->Register(SerializerContext::ReleaseBuffer); | ||
| 513 | + registry->Register(SerializerContext::TransferArrayBuffer); | ||
| 514 | + registry->Register(SerializerContext::WriteUint32); | ||
| 515 | + registry->Register(SerializerContext::WriteUint64); | ||
| 516 | + registry->Register(SerializerContext::WriteDouble); | ||
| 517 | + registry->Register(SerializerContext::WriteRawBytes); | ||
| 518 | + registry->Register(SerializerContext::SetTreatArrayBufferViewsAsHostObjects); | ||
| 519 | + | ||
| 520 | + registry->Register(DeserializerContext::New); | ||
| 521 | + registry->Register(DeserializerContext::ReadHeader); | ||
| 522 | + registry->Register(DeserializerContext::ReadValue); | ||
| 523 | + registry->Register(DeserializerContext::GetWireFormatVersion); | ||
| 524 | + registry->Register(DeserializerContext::TransferArrayBuffer); | ||
| 525 | + registry->Register(DeserializerContext::ReadUint32); | ||
| 526 | + registry->Register(DeserializerContext::ReadUint64); | ||
| 527 | + registry->Register(DeserializerContext::ReadDouble); | ||
| 528 | + registry->Register(DeserializerContext::ReadRawBytes); | ||
| 529 | + } | ||
| 530 | + | ||
| 531 | + } // namespace serdes | ||
| 507 | 532 | } // namespace node | |
| 508 | 533 | ||
| 509 | - NODE_MODULE_CONTEXT_AWARE_INTERNAL(serdes, node::Initialize) | ||
| 534 | + NODE_MODULE_CONTEXT_AWARE_INTERNAL(serdes, node::serdes::Initialize) | ||
| 535 | + NODE_MODULE_EXTERNAL_REFERENCE(serdes, node::serdes::RegisterExternalReferences) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,8 @@ class Environment; | |||
| 13 | 13 | struct EnvSerializeInfo; | |
| 14 | 14 | ||
| 15 | 15 | #define SERIALIZABLE_OBJECT_TYPES(V) \ | |
| 16 | - V(fs_binding_data, fs::BindingData) | ||
| 16 | + V(fs_binding_data, fs::BindingData) \ | ||
| 17 | + V(v8_binding_data, v8_utils::BindingData) | ||
| 17 | 18 | ||
| 18 | 19 | enum class EmbedderObjectType : uint8_t { | |
| 19 | 20 | k_default = 0, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,6 +24,7 @@ | |||
| 24 | 24 | #include "env-inl.h" | |
| 25 | 25 | #include "memory_tracker-inl.h" | |
| 26 | 26 | #include "node.h" | |
| 27 | + #include "node_external_reference.h" | ||
| 27 | 28 | #include "util-inl.h" | |
| 28 | 29 | #include "v8.h" | |
| 29 | 30 | ||
@@ -32,6 +33,7 @@ namespace v8_utils { | |||
| 32 | 33 | using v8::Array; | |
| 33 | 34 | using v8::Context; | |
| 34 | 35 | using v8::FunctionCallbackInfo; | |
| 36 | + using v8::HandleScope; | ||
| 35 | 37 | using v8::HeapCodeStatistics; | |
| 36 | 38 | using v8::HeapSpaceStatistics; | |
| 37 | 39 | using v8::HeapStatistics; | |
@@ -45,6 +47,7 @@ using v8::Uint32; | |||
| 45 | 47 | using v8::V8; | |
| 46 | 48 | using v8::Value; | |
| 47 | 49 | ||
| 50 | + | ||
| 48 | 51 | #define HEAP_STATISTICS_PROPERTIES(V) \ | |
| 49 | 52 | V(0, total_heap_size, kTotalHeapSizeIndex) \ | |
| 50 | 53 | V(1, total_heap_size_executable, kTotalHeapSizeExecutableIndex) \ | |
@@ -85,7 +88,7 @@ static const size_t kHeapCodeStatisticsPropertiesCount = | |||
| 85 | 88 | #undef V | |
| 86 | 89 | ||
| 87 | 90 | BindingData::BindingData(Environment* env, Local<Object> obj) | |
| 88 | - : BaseObject(env, obj), | ||
| 91 | + : SnapshotableObject(env, obj, type_int), | ||
| 89 | 92 | heap_statistics_buffer(env->isolate(), kHeapStatisticsPropertiesCount), | |
| 90 | 93 | heap_space_statistics_buffer(env->isolate(), | |
| 91 | 94 | kHeapSpaceStatisticsPropertiesCount), | |
@@ -105,6 +108,32 @@ BindingData::BindingData(Environment* env, Local<Object> obj) | |||
| 105 | 108 | .Check(); | |
| 106 | 109 | } | |
| 107 | 110 | ||
| 111 | + void BindingData::PrepareForSerialization(Local<Context> context, | ||
| 112 | + v8::SnapshotCreator* creator) { | ||
| 113 | + // We'll just re-initialize the buffers in the constructor since their | ||
| 114 | + // contents can be thrown away once consumed in the previous call. | ||
| 115 | + heap_statistics_buffer.Release(); | ||
| 116 | + heap_space_statistics_buffer.Release(); | ||
| 117 | + heap_code_statistics_buffer.Release(); | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + void BindingData::Deserialize(Local<Context> context, | ||
| 121 | + Local<Object> holder, | ||
| 122 | + int index, | ||
| 123 | + InternalFieldInfo* info) { | ||
| 124 | + DCHECK_EQ(index, BaseObject::kSlot); | ||
| 125 | + HandleScope scope(context->GetIsolate()); | ||
| 126 | + Environment* env = Environment::GetCurrent(context); | ||
| 127 | + BindingData* binding = env->AddBindingData<BindingData>(context, holder); | ||
| 128 | + CHECK_NOT_NULL(binding); | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + InternalFieldInfo* BindingData::Serialize(int index) { | ||
| 132 | + DCHECK_EQ(index, BaseObject::kSlot); | ||
| 133 | + InternalFieldInfo* info = InternalFieldInfo::New(type()); | ||
| 134 | + return info; | ||
| 135 | + } | ||
| 136 | + | ||
| 108 | 137 | void BindingData::MemoryInfo(MemoryTracker* tracker) const { | |
| 109 | 138 | tracker->TrackField("heap_statistics_buffer", heap_statistics_buffer); | |
| 110 | 139 | tracker->TrackField("heap_space_statistics_buffer", | |
@@ -168,7 +197,6 @@ void SetFlagsFromString(const FunctionCallbackInfo<Value>& args) { | |||
| 168 | 197 | V8::SetFlagsFromString(*flags, static_cast<size_t>(flags.length())); | |
| 169 | 198 | } | |
| 170 | 199 | ||
| 171 | - | ||
| 172 | 200 | void Initialize(Local<Object> target, | |
| 173 | 201 | Local<Value> unused, | |
| 174 | 202 | Local<Context> context, | |
@@ -223,7 +251,16 @@ void Initialize(Local<Object> target, | |||
| 223 | 251 | env->SetMethod(target, "setFlagsFromString", SetFlagsFromString); | |
| 224 | 252 | } | |
| 225 | 253 | ||
| 254 | + void RegisterExternalReferences(ExternalReferenceRegistry* registry) { | ||
| 255 | + registry->Register(CachedDataVersionTag); | ||
| 256 | + registry->Register(UpdateHeapStatisticsBuffer); | ||
| 257 | + registry->Register(UpdateHeapCodeStatisticsBuffer); | ||
| 258 | + registry->Register(UpdateHeapSpaceStatisticsBuffer); | ||
| 259 | + registry->Register(SetFlagsFromString); | ||
| 260 | + } | ||
| 261 | + | ||
| 226 | 262 | } // namespace v8_utils | |
| 227 | 263 | } // namespace node | |
| 228 | 264 | ||
| 229 | 265 | NODE_MODULE_CONTEXT_AWARE_INTERNAL(v8, node::v8_utils::Initialize) | |
| 266 | + NODE_MODULE_EXTERNAL_REFERENCE(v8, node::v8_utils::RegisterExternalReferences) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,18 +5,23 @@ | |||
| 5 | 5 | ||
| 6 | 6 | #include "aliased_buffer.h" | |
| 7 | 7 | #include "base_object.h" | |
| 8 | + #include "node_snapshotable.h" | ||
| 8 | 9 | #include "util.h" | |
| 9 | 10 | #include "v8.h" | |
| 10 | 11 | ||
| 11 | 12 | namespace node { | |
| 12 | 13 | class Environment; | |
| 14 | + struct InternalFieldInfo; | ||
| 13 | 15 | ||
| 14 | 16 | namespace v8_utils { | |
| 15 | - class BindingData : public BaseObject { | ||
| 17 | + class BindingData : public SnapshotableObject { | ||
| 16 | 18 | public: | |
| 17 | 19 | BindingData(Environment* env, v8::Local<v8::Object> obj); | |
| 18 | 20 | ||
| 21 | + SERIALIZABLE_OBJECT_METHODS() | ||
| 19 | 22 | static constexpr FastStringKey type_name{"node::v8::BindingData"}; | |
| 23 | + static constexpr EmbedderObjectType type_int = | ||
| 24 | + EmbedderObjectType::k_v8_binding_data; | ||
| 20 | 25 | ||
| 21 | 26 | AliasedFloat64Array heap_statistics_buffer; | |
| 22 | 27 | AliasedFloat64Array heap_space_statistics_buffer; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,7 @@ | |||
| 25 | 25 | #include "env-inl.h" | |
| 26 | 26 | #include "handle_wrap.h" | |
| 27 | 27 | #include "node_buffer.h" | |
| 28 | + #include "node_external_reference.h" | ||
| 28 | 29 | #include "pipe_wrap.h" | |
| 29 | 30 | #include "req_wrap-inl.h" | |
| 30 | 31 | #include "tcp_wrap.h" | |
@@ -51,20 +52,19 @@ using v8::ReadOnly; | |||
| 51 | 52 | using v8::Signature; | |
| 52 | 53 | using v8::Value; | |
| 53 | 54 | ||
| 55 | + void IsConstructCallCallback(const FunctionCallbackInfo<Value>& args) { | ||
| 56 | + CHECK(args.IsConstructCall()); | ||
| 57 | + StreamReq::ResetObject(args.This()); | ||
| 58 | + } | ||
| 54 | 59 | ||
| 55 | 60 | void LibuvStreamWrap::Initialize(Local<Object> target, | |
| 56 | 61 | Local<Value> unused, | |
| 57 | 62 | Local<Context> context, | |
| 58 | 63 | void* priv) { | |
| 59 | 64 | Environment* env = Environment::GetCurrent(context); | |
| 60 | 65 | ||
| 61 | - auto is_construct_call_callback = | ||
| 62 | - [](const FunctionCallbackInfo<Value>& args) { | ||
| 63 | - CHECK(args.IsConstructCall()); | ||
| 64 | - StreamReq::ResetObject(args.This()); | ||
| 65 | - }; | ||
| 66 | 66 | Local<FunctionTemplate> sw = | |
| 67 | - FunctionTemplate::New(env->isolate(), is_construct_call_callback); | ||
| 67 | + FunctionTemplate::New(env->isolate(), IsConstructCallCallback); | ||
| 68 | 68 | sw->InstanceTemplate()->SetInternalFieldCount(StreamReq::kInternalFieldCount); | |
| 69 | 69 | ||
| 70 | 70 | // we need to set handle and callback to null, | |
@@ -88,7 +88,7 @@ void LibuvStreamWrap::Initialize(Local<Object> target, | |||
| 88 | 88 | env->set_shutdown_wrap_template(sw->InstanceTemplate()); | |
| 89 | 89 | ||
| 90 | 90 | Local<FunctionTemplate> ww = | |
| 91 | - FunctionTemplate::New(env->isolate(), is_construct_call_callback); | ||
| 91 | + FunctionTemplate::New(env->isolate(), IsConstructCallCallback); | ||
| 92 | 92 | ww->InstanceTemplate()->SetInternalFieldCount( | |
| 93 | 93 | StreamReq::kInternalFieldCount); | |
| 94 | 94 | ww->Inherit(AsyncWrap::GetConstructorTemplate(env)); | |
@@ -103,6 +103,10 @@ void LibuvStreamWrap::Initialize(Local<Object> target, | |||
| 103 | 103 | env->stream_base_state().GetJSArray()).Check(); | |
| 104 | 104 | } | |
| 105 | 105 | ||
| 106 | + void LibuvStreamWrap::RegisterExternalReferences( | ||
| 107 | + ExternalReferenceRegistry* registry) { | ||
| 108 | + registry->Register(IsConstructCallCallback); | ||
| 109 | + } | ||
| 106 | 110 | ||
| 107 | 111 | LibuvStreamWrap::LibuvStreamWrap(Environment* env, | |
| 108 | 112 | Local<Object> object, | |
@@ -396,3 +400,5 @@ void LibuvStreamWrap::AfterUvWrite(uv_write_t* req, int status) { | |||
| 396 | 400 | ||
| 397 | 401 | NODE_MODULE_CONTEXT_AWARE_INTERNAL(stream_wrap, | |
| 398 | 402 | node::LibuvStreamWrap::Initialize) | |
| 403 | + NODE_MODULE_EXTERNAL_REFERENCE( | ||
| 404 | + stream_wrap, node::LibuvStreamWrap::RegisterExternalReferences) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments