src: make process binding data weak · nodejs/node@4a1ce45 · GitHub
Skip to content

Commit 4a1ce45

Browse files
legendecastargos
authored andcommitted
src: make process binding data weak
Avoid the realm being strongly referenced by the process binding data. PR-URL: #48655 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 342a83e commit 4a1ce45

3 files changed

Lines changed: 52 additions & 33 deletions

File tree

lib/internal/process/per_thread.js

Lines changed: 2 additions & 3 deletions

src/node_process.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,20 @@ void PatchProcessObject(const v8::FunctionCallbackInfo<v8::Value>& args);
4848
namespace process {
4949
class BindingData : public SnapshotableObject {
5050
public:
51+
struct InternalFieldInfo : public node::InternalFieldInfoBase {
52+
AliasedBufferIndex hrtime_buffer;
53+
};
54+
5155
static void AddMethods(v8::Isolate* isolate,
5256
v8::Local<v8::ObjectTemplate> target);
5357
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
5458

55-
using InternalFieldInfo = InternalFieldInfoBase;
56-
5759
SERIALIZABLE_OBJECT_METHODS()
5860
SET_BINDING_ID(process_binding_data)
5961

60-
BindingData(Realm* realm, v8::Local<v8::Object> object);
62+
BindingData(Realm* realm,
63+
v8::Local<v8::Object> object,
64+
InternalFieldInfo* info = nullptr);
6165

6266
void MemoryInfo(MemoryTracker* tracker) const override;
6367
SET_MEMORY_INFO_NAME(BindingData)
@@ -81,10 +85,10 @@ class BindingData : public SnapshotableObject {
8185
static void SlowBigInt(const v8::FunctionCallbackInfo<v8::Value>& args);
8286

8387
private:
84-
static constexpr size_t kBufferSize =
85-
std::max(sizeof(uint64_t), sizeof(uint32_t) * 3);
86-
v8::Global<v8::ArrayBuffer> array_buffer_;
87-
std::shared_ptr<v8::BackingStore> backing_store_;
88+
// Buffer length in uint32.
89+
static constexpr size_t kHrTimeBufferLength = 3;
90+
AliasedUint32Array hrtime_buffer_;
91+
InternalFieldInfo* internal_field_info_ = nullptr;
8892

8993
// These need to be static so that we have their addresses available to
9094
// register as external references in the snapshot at environment creation

src/node_process_methods.cc

Lines changed: 39 additions & 23 deletions

0 commit comments

Comments
 (0)