From 55381261b8ee08f789bf5c3e5e03a2633473aea2 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Mon, 18 Feb 2019 17:30:42 +0100 Subject: [PATCH] src: make IsolateData store ArrayBufferAllocator This enables us to identify whether we are using an allocator that we know more about than what the generic `ArrayBuffer::Allocator` API provides, in particular whether it is `malloc()`-compatible. PR-URL: https://github.com/nodejs/node/pull/26207 Reviewed-By: James M Snell Reviewed-By: Joyee Cheung --- src/env-inl.h | 12 ++++++++++-- src/env.cc | 13 ++++++++----- src/env.h | 14 ++++++++++---- src/node.cc | 2 +- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/env-inl.h b/src/env-inl.h index 4e0a95ed424..0223e732ec8 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -47,8 +47,16 @@ inline uv_loop_t* IsolateData::event_loop() const { return event_loop_; } -inline uint32_t* IsolateData::zero_fill_field() const { - return zero_fill_field_; +inline bool IsolateData::uses_node_allocator() const { + return uses_node_allocator_; +} + +inline v8::ArrayBuffer::Allocator* IsolateData::allocator() const { + return allocator_; +} + +inline ArrayBufferAllocator* IsolateData::node_allocator() const { + return node_allocator_; } inline MultiIsolatePlatform* IsolateData::platform() const { diff --git a/src/env.cc b/src/env.cc index d76e691a53f..aaf16c5ddc8 100644 --- a/src/env.cc +++ b/src/env.cc @@ -36,11 +36,14 @@ void* Environment::kNodeContextTagPtr = const_cast( IsolateData::IsolateData(Isolate* isolate, uv_loop_t* event_loop, MultiIsolatePlatform* platform, - uint32_t* zero_fill_field) : - isolate_(isolate), - event_loop_(event_loop), - zero_fill_field_(zero_fill_field), - platform_(platform) { + ArrayBufferAllocator* node_allocator) + : isolate_(isolate), + event_loop_(event_loop), + allocator_(isolate->GetArrayBufferAllocator()), + node_allocator_(node_allocator), + uses_node_allocator_(allocator_ == node_allocator_), + platform_(platform) { + CHECK_NOT_NULL(allocator_); if (platform_ != nullptr) platform_->RegisterIsolate(isolate_, event_loop); diff --git a/src/env.h b/src/env.h index 4b678cee289..23725ff70a6 100644 --- a/src/env.h +++ b/src/env.h @@ -362,15 +362,19 @@ class Environment; class IsolateData { public: - IsolateData(v8::Isolate* isolate, uv_loop_t* event_loop, + IsolateData(v8::Isolate* isolate, + uv_loop_t* event_loop, MultiIsolatePlatform* platform = nullptr, - uint32_t* zero_fill_field = nullptr); + ArrayBufferAllocator* node_allocator = nullptr); ~IsolateData(); inline uv_loop_t* event_loop() const; - inline uint32_t* zero_fill_field() const; inline MultiIsolatePlatform* platform() const; inline std::shared_ptr options(); + inline bool uses_node_allocator() const; + inline v8::ArrayBuffer::Allocator* allocator() const; + inline ArrayBufferAllocator* node_allocator() const; + #define VP(PropertyName, StringValue) V(v8::Private, PropertyName) #define VY(PropertyName, StringValue) V(v8::Symbol, PropertyName) #define VS(PropertyName, StringValue) V(v8::String, PropertyName) @@ -401,7 +405,9 @@ class IsolateData { v8::Isolate* const isolate_; uv_loop_t* const event_loop_; - uint32_t* const zero_fill_field_; + v8::ArrayBuffer::Allocator* const allocator_; + ArrayBufferAllocator* const node_allocator_; + const bool uses_node_allocator_; MultiIsolatePlatform* platform_; std::shared_ptr options_; diff --git a/src/node.cc b/src/node.cc index aa51c0b46a1..47a13077db0 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2832,7 +2832,7 @@ IsolateData* CreateIsolateData( uv_loop_t* loop, MultiIsolatePlatform* platform, ArrayBufferAllocator* allocator) { - return new IsolateData(isolate, loop, platform, allocator->zero_fill_field()); + return new IsolateData(isolate, loop, platform, allocator); }