From cc82ea21171dc70e2db84dae5cde0f0f6c3f56dc Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 12 Jun 2020 00:23:16 +0200 Subject: [PATCH 1/3] src: minor updates to FastHrtime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Don’t use 12 as a magic number for the buffer size - Mark the object as weak (which is conceptually the right thing to do, even if there is little practical impact) - Keep a reference to the `ArrayBuffer` in question for memory tracking --- src/node_process_methods.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index d580f74478cbf7..304eda9754df54 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -448,8 +448,9 @@ class FastHrtime : public BaseObject { Local obj = otmpl->NewInstance(env->context()).ToLocalChecked(); - Local ab = ArrayBuffer::New(env->isolate(), 12); - new FastHrtime(env, obj, ab->GetBackingStore()); + Local ab = + ArrayBuffer::New(env->isolate(), sizeof(uint32_t) * 3); + new FastHrtime(env, obj, ab); obj->Set( env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "buffer"), ab) .ToChecked(); @@ -460,11 +461,16 @@ class FastHrtime : public BaseObject { private: FastHrtime(Environment* env, Local object, - std::shared_ptr backing_store) - : BaseObject(env, object), backing_store_(backing_store) {} - - void MemoryInfo(MemoryTracker* tracker) const override {} + Local ab) + : BaseObject(env, object), + array_buffer_(env->isolate(), ab), + backing_store_(ab->GetBackingStore()) { + MakeWeak(); + } + void MemoryInfo(MemoryTracker* tracker) const override { + tracker->TrackField("array_buffer", array_buffer_); + } SET_MEMORY_INFO_NAME(FastHrtime) SET_SELF_SIZE(FastHrtime) @@ -499,6 +505,7 @@ class FastHrtime : public BaseObject { FastBigInt(FromJSObject(args.Holder())); } + v8::Global array_buffer_; std::shared_ptr backing_store_; }; From 10d349a6f5d93fcef053e5aa9fb8e61bdd0d8230 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 12 Jun 2020 00:45:54 +0200 Subject: [PATCH 2/3] fixup! src: minor updates to FastHrtime --- src/node_process_methods.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index 304eda9754df54..385fcc02f5e1f5 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -1,6 +1,7 @@ #include "base_object-inl.h" #include "debug_utils-inl.h" #include "env-inl.h" +#include "memory_tracker-inl.h" #include "node.h" #include "node_errors.h" #include "node_internals.h" From 7183372f0fdbd21675ac68e37cdb8b408073dd47 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 12 Jun 2020 23:51:30 +0200 Subject: [PATCH 3/3] fixup! fixup! src: minor updates to FastHrtime --- src/node_process_methods.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index 385fcc02f5e1f5..657d16fbdca70c 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -450,7 +450,8 @@ class FastHrtime : public BaseObject { Local obj = otmpl->NewInstance(env->context()).ToLocalChecked(); Local ab = - ArrayBuffer::New(env->isolate(), sizeof(uint32_t) * 3); + ArrayBuffer::New(env->isolate(), + std::max(sizeof(uint64_t), sizeof(uint32_t) * 3)); new FastHrtime(env, obj, ab); obj->Set( env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "buffer"), ab)