From 520da4a1f866584a12666c849db2866d6e9cdf3e Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 29 Apr 2020 18:08:13 +0800 Subject: [PATCH] src: separate owning and non-owning AliasedBuffers Move the reserve() method into an owning variant of AliasedBuffer, and split the two constructors to different classes to make the contract explicit instead of relying on run time CHECKs. Also deletes unused assignment operator and copy/move constructors to make sure they don't get copied by accident. --- src/aliased_buffer.h | 215 ++++++++++-------- src/env-inl.h | 15 +- src/env.h | 28 +-- src/node_file-inl.h | 6 +- src/node_file.h | 4 +- src/node_http2.cc | 20 +- src/node_http2_state.h | 14 +- src/node_perf.cc | 10 +- src/node_perf_common.h | 6 +- src/node_v8.cc | 12 +- .../binding.cc | 2 +- test/cctest/test_aliased_buffer.cc | 25 +- 12 files changed, 190 insertions(+), 167 deletions(-) diff --git a/src/aliased_buffer.h b/src/aliased_buffer.h index e762e8ede8ebee..3797b87e9981ca 100644 --- a/src/aliased_buffer.h +++ b/src/aliased_buffer.h @@ -9,6 +9,18 @@ namespace node { +template ::value>> +class OwningAliasedBufferBase; + +template ::value>> +class AliasedBufferViewBase; + /** * Do not use this class directly when creating instances of it - use the * Aliased*Array defined at the end of this file instead. @@ -26,83 +38,9 @@ namespace node { * The encapsulation herein provides a placeholder where such writes can be * observed. Any notification APIs will be left as a future exercise. */ -template ::value>> +template class AliasedBufferBase { public: - AliasedBufferBase(v8::Isolate* isolate, const size_t count) - : isolate_(isolate), count_(count), byte_offset_(0) { - CHECK_GT(count, 0); - const v8::HandleScope handle_scope(isolate_); - const size_t size_in_bytes = - MultiplyWithOverflowCheck(sizeof(NativeT), count); - - // allocate v8 ArrayBuffer - v8::Local ab = v8::ArrayBuffer::New( - isolate_, size_in_bytes); - buffer_ = static_cast(ab->GetBackingStore()->Data()); - - // allocate v8 TypedArray - v8::Local js_array = V8T::New(ab, byte_offset_, count); - js_array_ = v8::Global(isolate, js_array); - } - - /** - * Create an AliasedBufferBase over a sub-region of another aliased buffer. - * The two will share a v8::ArrayBuffer instance & - * a native buffer, but will each read/write to different sections of the - * native buffer. - * - * Note that byte_offset must by aligned by sizeof(NativeT). - */ - // TODO(refack): refactor into a non-owning `AliasedBufferBaseView` - AliasedBufferBase( - v8::Isolate* isolate, - const size_t byte_offset, - const size_t count, - const AliasedBufferBase& backing_buffer) - : isolate_(isolate), count_(count), byte_offset_(byte_offset) { - const v8::HandleScope handle_scope(isolate_); - - v8::Local ab = backing_buffer.GetArrayBuffer(); - - // validate that the byte_offset is aligned with sizeof(NativeT) - CHECK_EQ(byte_offset & (sizeof(NativeT) - 1), 0); - // validate this fits inside the backing buffer - CHECK_LE(MultiplyWithOverflowCheck(sizeof(NativeT), count), - ab->ByteLength() - byte_offset); - - buffer_ = reinterpret_cast( - const_cast(backing_buffer.GetNativeBuffer() + byte_offset)); - - v8::Local js_array = V8T::New(ab, byte_offset, count); - js_array_ = v8::Global(isolate, js_array); - } - - AliasedBufferBase(const AliasedBufferBase& that) - : isolate_(that.isolate_), - count_(that.count_), - byte_offset_(that.byte_offset_), - buffer_(that.buffer_) { - js_array_ = v8::Global(that.isolate_, that.GetJSArray()); - } - - AliasedBufferBase& operator=(AliasedBufferBase&& that) noexcept { - this->~AliasedBufferBase(); - isolate_ = that.isolate_; - count_ = that.count_; - byte_offset_ = that.byte_offset_; - buffer_ = that.buffer_; - - js_array_.Reset(isolate_, that.js_array_.Get(isolate_)); - - that.buffer_ = nullptr; - that.js_array_.Reset(); - return *this; - } - /** * Helper class that is returned from operator[] to support assignment into * a specified location. @@ -212,50 +150,133 @@ class AliasedBufferBase { return count_; } + friend class OwningAliasedBufferBase; + friend class AliasedBufferViewBase; + + private: + AliasedBufferBase(v8::Isolate* isolate, const size_t count) + : isolate_(isolate), count_(count) {} + + v8::Isolate* isolate_; + size_t count_; + NativeT* buffer_; + v8::Global js_array_; +}; + +template +class OwningAliasedBufferBase : public AliasedBufferBase { + typedef AliasedBufferBase BaseType; + + public: + OwningAliasedBufferBase(v8::Isolate* isolate, const size_t count) + : BaseType(isolate, count) { + CHECK_GT(count, 0); + const v8::HandleScope handle_scope(isolate); + const size_t size_in_bytes = + MultiplyWithOverflowCheck(sizeof(NativeT), count); + + // allocate v8 ArrayBuffer + v8::Local ab = + v8::ArrayBuffer::New(isolate, size_in_bytes); + BaseType::buffer_ = static_cast(ab->GetBackingStore()->Data()); + + // allocate v8 TypedArray + v8::Local js_array = V8T::New(ab, 0, count); + BaseType::js_array_ = v8::Global(isolate, js_array); + } + // Should only be used to extend the array. - // Should only be used on an owning array, not one created as a sub array of - // an owning `AliasedBufferBase`. void reserve(size_t new_capacity) { - DCHECK_GE(new_capacity, count_); - DCHECK_EQ(byte_offset_, 0); - const v8::HandleScope handle_scope(isolate_); + size_t count = BaseType::count_; + v8::Isolate* isolate = BaseType::isolate_; + DCHECK_GE(new_capacity, count); + const v8::HandleScope handle_scope(isolate); - const size_t old_size_in_bytes = sizeof(NativeT) * count_; + const size_t old_size_in_bytes = sizeof(NativeT) * count; const size_t new_size_in_bytes = MultiplyWithOverflowCheck(sizeof(NativeT), new_capacity); // allocate v8 new ArrayBuffer - v8::Local ab = v8::ArrayBuffer::New( - isolate_, new_size_in_bytes); + v8::Local ab = + v8::ArrayBuffer::New(isolate, new_size_in_bytes); // allocate new native buffer NativeT* new_buffer = static_cast(ab->GetBackingStore()->Data()); // copy old content - memcpy(new_buffer, buffer_, old_size_in_bytes); + memcpy(new_buffer, BaseType::buffer_, old_size_in_bytes); // allocate v8 TypedArray - v8::Local js_array = V8T::New(ab, byte_offset_, new_capacity); + v8::Local js_array = V8T::New(ab, 0, new_capacity); // move over old v8 TypedArray - js_array_ = std::move(v8::Global(isolate_, js_array)); + BaseType::js_array_ = std::move(v8::Global(isolate, js_array)); + + BaseType::buffer_ = new_buffer; + BaseType::count_ = new_capacity; + } + OwningAliasedBufferBase(const OwningAliasedBufferBase&) = delete; + OwningAliasedBufferBase& operator=(const OwningAliasedBufferBase&) = delete; + OwningAliasedBufferBase(OwningAliasedBufferBase&&) = delete; + OwningAliasedBufferBase& operator=(OwningAliasedBufferBase&&) = delete; +}; + +/** + * Create an AliasedBufferViewBase over a sub-region of another + * AliasedBufferBase. The two will share a v8::ArrayBuffer instance & + * a native buffer, but will each read/write to different sections of the + * native buffer. + * + * Note that byte_offset must by aligned by sizeof(NativeT). + */ +template +class AliasedBufferViewBase : public AliasedBufferBase { + typedef AliasedBufferBase BaseType; + + public: + AliasedBufferViewBase( + v8::Isolate* isolate, + const size_t byte_offset, + const size_t count, + const AliasedBufferBase& backing_buffer) + : BaseType(isolate, count), byte_offset_(byte_offset) { + const v8::HandleScope handle_scope(isolate); + + v8::Local ab = backing_buffer.GetArrayBuffer(); + + // validate that the byte_offset is aligned with sizeof(NativeT) + CHECK_EQ(byte_offset & (sizeof(NativeT) - 1), 0); + // validate this fits inside the backing buffer + CHECK_LE(MultiplyWithOverflowCheck(sizeof(NativeT), count), + ab->ByteLength() - byte_offset); + + BaseType::buffer_ = reinterpret_cast( + const_cast(backing_buffer.GetNativeBuffer() + byte_offset)); - buffer_ = new_buffer; - count_ = new_capacity; + v8::Local js_array = V8T::New(ab, byte_offset, count); + BaseType::js_array_ = v8::Global(isolate, js_array); } + AliasedBufferViewBase(const AliasedBufferViewBase&) = delete; + AliasedBufferViewBase& operator=(const AliasedBufferViewBase&) = delete; + AliasedBufferViewBase(AliasedBufferViewBase&&) = delete; + AliasedBufferViewBase& operator=(AliasedBufferViewBase&&) = delete; + private: - v8::Isolate* isolate_; - size_t count_; size_t byte_offset_; - NativeT* buffer_; - v8::Global js_array_; }; -typedef AliasedBufferBase AliasedInt32Array; -typedef AliasedBufferBase AliasedUint8Array; -typedef AliasedBufferBase AliasedUint32Array; -typedef AliasedBufferBase AliasedFloat64Array; -typedef AliasedBufferBase AliasedBigUint64Array; +#define ALIASED_BUFFER_TYPES(V) \ + V(uint8_t, Uint8Array) \ + V(int32_t, Int32Array) \ + V(uint32_t, Uint32Array) \ + V(double, Float64Array) \ + V(uint64_t, BigUint64Array) + +#define V(NativeT, V8T) \ + typedef OwningAliasedBufferBase OwningAliased##V8T; \ + typedef AliasedBufferViewBase Aliased##V8T##View; +ALIASED_BUFFER_TYPES(V) +#undef V } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS diff --git a/src/env-inl.h b/src/env-inl.h index cab967f10db530..1b70c8703ae635 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -100,15 +100,15 @@ inline AsyncHooks::AsyncHooks() // context during bootstrap (code that runs before entering uv_run()). async_id_fields_[AsyncHooks::kAsyncIdCounter] = 1; } -inline AliasedUint32Array& AsyncHooks::fields() { +inline OwningAliasedUint32Array& AsyncHooks::fields() { return fields_; } -inline AliasedFloat64Array& AsyncHooks::async_id_fields() { +inline OwningAliasedFloat64Array& AsyncHooks::async_id_fields() { return async_id_fields_; } -inline AliasedFloat64Array& AsyncHooks::async_ids_stack() { +inline OwningAliasedFloat64Array& AsyncHooks::async_ids_stack() { return async_ids_stack_; } @@ -241,7 +241,7 @@ inline void Environment::PopAsyncCallbackScope() { inline ImmediateInfo::ImmediateInfo(v8::Isolate* isolate) : fields_(isolate, kFieldsCount) {} -inline AliasedUint32Array& ImmediateInfo::fields() { +inline OwningAliasedUint32Array& ImmediateInfo::fields() { return fields_; } @@ -268,7 +268,7 @@ inline void ImmediateInfo::ref_count_dec(uint32_t decrement) { inline TickInfo::TickInfo(v8::Isolate* isolate) : fields_(isolate, kFieldsCount) {} -inline AliasedUint8Array& TickInfo::fields() { +inline OwningAliasedUint8Array& TickInfo::fields() { return fields_; } @@ -507,11 +507,12 @@ inline void Environment::set_abort_on_uncaught_exception(bool value) { options_->abort_on_uncaught_exception = value; } -inline AliasedUint32Array& Environment::should_abort_on_uncaught_toggle() { +inline OwningAliasedUint32Array& +Environment::should_abort_on_uncaught_toggle() { return should_abort_on_uncaught_toggle_; } -inline AliasedInt32Array& Environment::stream_base_state() { +inline OwningAliasedInt32Array& Environment::stream_base_state() { return stream_base_state_; } diff --git a/src/env.h b/src/env.h index e2dc5e866f451c..fb3d13c2189539 100644 --- a/src/env.h +++ b/src/env.h @@ -647,9 +647,9 @@ class AsyncHooks : public MemoryRetainer { kUidFieldsCount, }; - inline AliasedUint32Array& fields(); - inline AliasedFloat64Array& async_id_fields(); - inline AliasedFloat64Array& async_ids_stack(); + inline OwningAliasedUint32Array& fields(); + inline OwningAliasedFloat64Array& async_id_fields(); + inline OwningAliasedFloat64Array& async_ids_stack(); inline v8::Local execution_async_resources(); inline v8::Local provider_string(int idx); @@ -694,12 +694,12 @@ class AsyncHooks : public MemoryRetainer { friend class Environment; // So we can call the constructor. inline AsyncHooks(); // Stores the ids of the current execution context stack. - AliasedFloat64Array async_ids_stack_; + OwningAliasedFloat64Array async_ids_stack_; // Attached to a Uint32Array that tracks the number of active hooks for // each type. - AliasedUint32Array fields_; + OwningAliasedUint32Array fields_; // Attached to a Float64Array that tracks the state of async resources. - AliasedFloat64Array async_id_fields_; + OwningAliasedFloat64Array async_id_fields_; void grow_async_ids_stack(); @@ -708,7 +708,7 @@ class AsyncHooks : public MemoryRetainer { class ImmediateInfo : public MemoryRetainer { public: - inline AliasedUint32Array& fields(); + inline OwningAliasedUint32Array& fields(); inline uint32_t count() const; inline uint32_t ref_count() const; inline bool has_outstanding() const; @@ -731,12 +731,12 @@ class ImmediateInfo : public MemoryRetainer { enum Fields { kCount, kRefCount, kHasOutstanding, kFieldsCount }; - AliasedUint32Array fields_; + OwningAliasedUint32Array fields_; }; class TickInfo : public MemoryRetainer { public: - inline AliasedUint8Array& fields(); + inline OwningAliasedUint8Array& fields(); inline bool has_tick_scheduled() const; inline bool has_rejection_to_warn() const; @@ -756,7 +756,7 @@ class TickInfo : public MemoryRetainer { enum Fields { kHasTickScheduled = 0, kHasRejectionToWarn, kFieldsCount }; - AliasedUint8Array fields_; + OwningAliasedUint8Array fields_; }; class TrackingTraceStateObserver : @@ -977,9 +977,9 @@ class Environment : public MemoryRetainer { // This is a pseudo-boolean that keeps track of whether an uncaught exception // should abort the process or not if --abort-on-uncaught-exception was // passed to Node. If the flag was not passed, it is ignored. - inline AliasedUint32Array& should_abort_on_uncaught_toggle(); + inline OwningAliasedUint32Array& should_abort_on_uncaught_toggle(); - inline AliasedInt32Array& stream_base_state(); + inline OwningAliasedInt32Array& stream_base_state(); // The necessary API for async_hooks. inline double new_async_id(); @@ -1315,12 +1315,12 @@ class Environment : public MemoryRetainer { uint32_t script_id_counter_ = 0; uint32_t function_id_counter_ = 0; - AliasedUint32Array should_abort_on_uncaught_toggle_; + OwningAliasedUint32Array should_abort_on_uncaught_toggle_; int should_not_abort_scope_counter_ = 0; std::unique_ptr trace_state_observer_; - AliasedInt32Array stream_base_state_; + OwningAliasedInt32Array stream_base_state_; std::unique_ptr performance_state_; std::unordered_map performance_marks_; diff --git a/src/node_file-inl.h b/src/node_file-inl.h index d30d77301005a3..c45dd2ce617b28 100644 --- a/src/node_file-inl.h +++ b/src/node_file-inl.h @@ -231,9 +231,11 @@ FSReqBase* GetReqWrap(const v8::FunctionCallbackInfo& args, Environment* env = binding_data->env(); if (value->StrictEquals(env->fs_use_promises_symbol())) { if (use_bigint) { - return FSReqPromise::New(binding_data, use_bigint); + return FSReqPromise::New(binding_data, + use_bigint); } else { - return FSReqPromise::New(binding_data, use_bigint); + return FSReqPromise::New(binding_data, + use_bigint); } } return nullptr; diff --git a/src/node_file.h b/src/node_file.h index 1fda81361fef79..e101444fd8735c 100644 --- a/src/node_file.h +++ b/src/node_file.h @@ -20,8 +20,8 @@ class BindingData : public BaseObject { stats_field_array(env->isolate(), kFsStatsBufferLength), stats_field_bigint_array(env->isolate(), kFsStatsBufferLength) {} - AliasedFloat64Array stats_field_array; - AliasedBigUint64Array stats_field_bigint_array; + OwningAliasedFloat64Array stats_field_array; + OwningAliasedBigUint64Array stats_field_bigint_array; std::vector> file_handle_read_wrap_freelist; diff --git a/src/node_http2.cc b/src/node_http2.cc index 6637166e954267..a8689678868e38 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -49,7 +49,7 @@ namespace { const char zero_bytes_256[256] = {}; bool HasHttp2Observer(Environment* env) { - AliasedUint32Array& observers = env->performance_state()->observers; + AliasedUint32ArrayView& observers = env->performance_state()->observers; return observers[performance::NODE_PERFORMANCE_ENTRY_TYPE_HTTP2] != 0; } @@ -122,7 +122,7 @@ Http2Options::Http2Options(Http2State* http2_state, SessionType type) { nghttp2_option_set_builtin_recv_extension_type(option, NGHTTP2_ORIGIN); } - AliasedUint32Array& buffer = http2_state->options_buffer; + AliasedUint32ArrayView& buffer = http2_state->options_buffer; uint32_t flags = buffer[IDX_OPTIONS_FLAGS]; if (flags & (1 << IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE)) { @@ -208,7 +208,7 @@ Http2Options::Http2Options(Http2State* http2_state, SessionType type) { size_t Http2Settings::Init( Http2State* http2_state, nghttp2_settings_entry* entries) { - AliasedUint32Array& buffer = http2_state->settings_buffer; + AliasedUint32ArrayView& buffer = http2_state->settings_buffer; uint32_t flags = buffer[IDX_SETTINGS_COUNT]; size_t count = 0; @@ -277,7 +277,7 @@ Local Http2Settings::Pack( // Updates the shared TypedArray with the current remote or local settings for // the session. void Http2Settings::Update(Http2Session* session, get_setting fn) { - AliasedUint32Array& buffer = session->http2_state()->settings_buffer; + AliasedUint32ArrayView& buffer = session->http2_state()->settings_buffer; #define V(name) \ buffer[IDX_SETTINGS_ ## name] = \ @@ -288,7 +288,7 @@ void Http2Settings::Update(Http2Session* session, get_setting fn) { // Initializes the shared TypedArray with the default settings values. void Http2Settings::RefreshDefaults(Http2State* http2_state) { - AliasedUint32Array& buffer = http2_state->settings_buffer; + AliasedUint32ArrayView& buffer = http2_state->settings_buffer; uint32_t flags = 0; #define V(name) \ @@ -546,7 +546,7 @@ void Http2Stream::EmitStatistics() { if (!HasHttp2Observer(env)) return; HandleScope handle_scope(env->isolate()); - AliasedFloat64Array& buffer = entry->http2_state()->stream_stats_buffer; + AliasedFloat64ArrayView& buffer = entry->http2_state()->stream_stats_buffer; buffer[IDX_STREAM_STATS_ID] = entry->id(); if (entry->first_byte() != 0) { buffer[IDX_STREAM_STATS_TIMETOFIRSTBYTE] = @@ -584,7 +584,8 @@ void Http2Session::EmitStatistics() { if (!HasHttp2Observer(env)) return; HandleScope handle_scope(env->isolate()); - AliasedFloat64Array& buffer = entry->http2_state()->session_stats_buffer; + AliasedFloat64ArrayView& buffer = + entry->http2_state()->session_stats_buffer; buffer[IDX_SESSION_STATS_TYPE] = entry->type(); buffer[IDX_SESSION_STATS_PINGRTT] = entry->ping_rtt() / 1e6; buffer[IDX_SESSION_STATS_FRAMESRECEIVED] = entry->frame_count(); @@ -2396,7 +2397,8 @@ void Http2Session::RefreshState(const FunctionCallbackInfo& args) { ASSIGN_OR_RETURN_UNWRAP(&session, args.Holder()); Debug(session, "refreshing state"); - AliasedFloat64Array& buffer = session->http2_state()->session_state_buffer; + AliasedFloat64ArrayView& buffer = + session->http2_state()->session_state_buffer; nghttp2_session* s = session->session(); @@ -2658,7 +2660,7 @@ void Http2Stream::RefreshState(const FunctionCallbackInfo& args) { Debug(stream, "refreshing state"); CHECK_NOT_NULL(stream->session()); - AliasedFloat64Array& buffer = + AliasedFloat64ArrayView& buffer = stream->session()->http2_state()->stream_state_buffer; nghttp2_stream* str = stream->stream(); diff --git a/src/node_http2_state.h b/src/node_http2_state.h index 80efb40cd27589..c8435189cc0275 100644 --- a/src/node_http2_state.h +++ b/src/node_http2_state.h @@ -119,13 +119,13 @@ class Http2State : public BaseObject { root_buffer) { } - AliasedUint8Array root_buffer; - AliasedFloat64Array session_state_buffer; - AliasedFloat64Array stream_state_buffer; - AliasedFloat64Array stream_stats_buffer; - AliasedFloat64Array session_stats_buffer; - AliasedUint32Array options_buffer; - AliasedUint32Array settings_buffer; + OwningAliasedUint8Array root_buffer; + AliasedFloat64ArrayView session_state_buffer; + AliasedFloat64ArrayView stream_state_buffer; + AliasedFloat64ArrayView stream_stats_buffer; + AliasedFloat64ArrayView session_stats_buffer; + AliasedUint32ArrayView options_buffer; + AliasedUint32ArrayView settings_buffer; void MemoryInfo(MemoryTracker* tracker) const override; SET_SELF_SIZE(Http2State) diff --git a/src/node_perf.cc b/src/node_perf.cc index 4b8bf2a8a7c913..8fa1f475753fe5 100644 --- a/src/node_perf.cc +++ b/src/node_perf.cc @@ -116,7 +116,7 @@ void PerformanceEntry::Notify(Environment* env, PerformanceEntryType type, Local object) { Context::Scope scope(env->context()); - AliasedUint32Array& observers = env->performance_state()->observers; + AliasedUint32ArrayView& observers = env->performance_state()->observers; if (type != NODE_PERFORMANCE_ENTRY_TYPE_INVALID && observers[type]) { node::MakeCallback(env->isolate(), @@ -173,7 +173,7 @@ void Measure(const FunctionCallbackInfo& args) { Utf8Value name(env->isolate(), args[0]); Utf8Value startMark(env->isolate(), args[1]); - AliasedFloat64Array& milestones = env->performance_state()->milestones; + AliasedFloat64ArrayView& milestones = env->performance_state()->milestones; uint64_t startTimestamp = timeOrigin; uint64_t start = GetPerformanceMark(env, *startMark); @@ -239,7 +239,7 @@ void PerformanceGCCallback(Environment* env, HandleScope scope(env->isolate()); Local context = env->context(); - AliasedUint32Array& observers = env->performance_state()->observers; + AliasedUint32ArrayView& observers = env->performance_state()->observers; if (observers[NODE_PERFORMANCE_ENTRY_TYPE_GC]) { Local obj; if (!entry->ToObject().ToLocal(&obj)) return; @@ -361,7 +361,7 @@ void TimerFunctionCall(const FunctionCallbackInfo& args) { return; args.GetReturnValue().Set(ret.ToLocalChecked()); - AliasedUint32Array& observers = env->performance_state()->observers; + AliasedUint32ArrayView& observers = env->performance_state()->observers; if (!observers[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION]) return; @@ -392,7 +392,7 @@ void Notify(const FunctionCallbackInfo& args) { Utf8Value type(env->isolate(), args[0]); Local entry = args[1]; PerformanceEntryType entry_type = ToPerformanceEntryTypeEnum(*type); - AliasedUint32Array& observers = env->performance_state()->observers; + AliasedUint32ArrayView& observers = env->performance_state()->observers; if (entry_type != NODE_PERFORMANCE_ENTRY_TYPE_INVALID && observers[entry_type]) { USE(env->performance_entry_callback()-> diff --git a/src/node_perf_common.h b/src/node_perf_common.h index 75d266afc257e9..174fe6e47ed667 100644 --- a/src/node_perf_common.h +++ b/src/node_perf_common.h @@ -72,9 +72,9 @@ class PerformanceState { milestones[i] = -1.; } - AliasedUint8Array root; - AliasedFloat64Array milestones; - AliasedUint32Array observers; + OwningAliasedUint8Array root; + AliasedFloat64ArrayView milestones; + AliasedUint32ArrayView observers; uint64_t performance_last_gc_start_mark = 0; diff --git a/src/node_v8.cc b/src/node_v8.cc index 7174d9ae7f830b..b485078001df39 100644 --- a/src/node_v8.cc +++ b/src/node_v8.cc @@ -96,9 +96,9 @@ class BindingData : public BaseObject { heap_code_statistics_buffer(env->isolate(), kHeapCodeStatisticsPropertiesCount) {} - AliasedFloat64Array heap_statistics_buffer; - AliasedFloat64Array heap_space_statistics_buffer; - AliasedFloat64Array heap_code_statistics_buffer; + OwningAliasedFloat64Array heap_statistics_buffer; + OwningAliasedFloat64Array heap_space_statistics_buffer; + OwningAliasedFloat64Array heap_code_statistics_buffer; void MemoryInfo(MemoryTracker* tracker) const override { tracker->TrackField("heap_statistics_buffer", heap_statistics_buffer); @@ -124,7 +124,7 @@ void UpdateHeapStatisticsBuffer(const FunctionCallbackInfo& args) { BindingData* data = Unwrap(args.Data()); HeapStatistics s; args.GetIsolate()->GetHeapStatistics(&s); - AliasedFloat64Array& buffer = data->heap_statistics_buffer; + OwningAliasedFloat64Array& buffer = data->heap_statistics_buffer; #define V(index, name, _) buffer[index] = static_cast(s.name()); HEAP_STATISTICS_PROPERTIES(V) #undef V @@ -139,7 +139,7 @@ void UpdateHeapSpaceStatisticsBuffer(const FunctionCallbackInfo& args) { size_t space_index = static_cast(args[0].As()->Value()); isolate->GetHeapSpaceStatistics(&s, space_index); - AliasedFloat64Array& buffer = data->heap_space_statistics_buffer; + OwningAliasedFloat64Array& buffer = data->heap_space_statistics_buffer; #define V(index, name, _) buffer[index] = static_cast(s.name()); HEAP_SPACE_STATISTICS_PROPERTIES(V) @@ -150,7 +150,7 @@ void UpdateHeapCodeStatisticsBuffer(const FunctionCallbackInfo& args) { BindingData* data = Unwrap(args.Data()); HeapCodeStatistics s; args.GetIsolate()->GetHeapCodeAndMetadataStatistics(&s); - AliasedFloat64Array& buffer = data->heap_code_statistics_buffer; + OwningAliasedFloat64Array& buffer = data->heap_code_statistics_buffer; #define V(index, name, _) buffer[index] = static_cast(s.name()); HEAP_CODE_STATISTICS_PROPERTIES(V) diff --git a/test/abort/test_abort-aliased-buffer-overflow/binding.cc b/test/abort/test_abort-aliased-buffer-overflow/binding.cc index c3bf66061bf0ee..88b575cb8bfb55 100644 --- a/test/abort/test_abort-aliased-buffer-overflow/binding.cc +++ b/test/abort/test_abort-aliased-buffer-overflow/binding.cc @@ -10,7 +10,7 @@ void AllocateAndResizeBuffer( v8::Isolate* isolate = args.GetIsolate(); int64_t length = args[0].As()->Int64Value(); - node::AliasedBigUint64Array array{isolate, 0}; + node::OwningAliasedBigUint64Array array{isolate, 0}; array.reserve(length); assert(false); diff --git a/test/cctest/test_aliased_buffer.cc b/test/cctest/test_aliased_buffer.cc index 4dab70d0b576cb..32812ddc7786d7 100644 --- a/test/cctest/test_aliased_buffer.cc +++ b/test/cctest/test_aliased_buffer.cc @@ -10,6 +10,8 @@ #include "node_test_fixture.h" using node::AliasedBufferBase; +using node::AliasedBufferViewBase; +using node::OwningAliasedBufferBase; class AliasBufferTest : public NodeTestFixture {}; @@ -82,19 +84,13 @@ void ReadWriteTest(v8::Isolate* isolate) { v8::Context::Scope context_scope(context); const size_t size = 100; - AliasedBufferBase ab(isolate, size); + OwningAliasedBufferBase ab(isolate, size); std::vector oracle(size); CreateOracleValues(&oracle); WriteViaOperator(&ab, oracle); ReadAndValidate(isolate, context, &ab, oracle); WriteViaSetValue(&ab, oracle); - - // validate copy constructor - { - AliasedBufferBase ab2(ab); - ReadAndValidate(isolate, context, &ab2, oracle); - } ReadAndValidate(isolate, context, &ab, oracle); } @@ -116,12 +112,12 @@ void SharedBufferTest( size_t sizeInBytes_B = count_B * sizeof(NativeT_B); size_t sizeInBytes_C = count_C * sizeof(NativeT_C); - AliasedBufferBase rootBuffer( + OwningAliasedBufferBase rootBuffer( isolate, sizeInBytes_A + sizeInBytes_B + sizeInBytes_C); - AliasedBufferBase ab_A(isolate, 0, count_A, rootBuffer); - AliasedBufferBase ab_B( + AliasedBufferViewBase ab_A(isolate, 0, count_A, rootBuffer); + AliasedBufferViewBase ab_B( isolate, sizeInBytes_A, count_B, rootBuffer); - AliasedBufferBase ab_C( + AliasedBufferViewBase ab_C( isolate, sizeInBytes_A + sizeInBytes_B, count_C, rootBuffer); std::vector oracle_A(count_A); @@ -214,7 +210,7 @@ TEST_F(AliasBufferTest, OperatorOverloads) { v8::Local context = v8::Context::New(isolate_); v8::Context::Scope context_scope(context); const size_t size = 10; - AliasedBufferBase ab{isolate_, size}; + OwningAliasedBufferBase ab{isolate_, size}; EXPECT_EQ(static_cast(1), ab[0] = 1); EXPECT_EQ(static_cast(4), ab[0] += 3); @@ -227,8 +223,9 @@ TEST_F(AliasBufferTest, OperatorOverloadsRefs) { v8::HandleScope handle_scope(isolate_); v8::Local context = v8::Context::New(isolate_); v8::Context::Scope context_scope(context); - AliasedBufferBase ab{isolate_, 2}; - using Reference = AliasedBufferBase::Reference; + OwningAliasedBufferBase ab{isolate_, 2}; + using Reference = + OwningAliasedBufferBase::Reference; Reference ref = ab[0]; Reference ref_value = ab[1] = 2;