diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-12-13 22:32:44 +0300 |
---|---|---|
committer | Gabriel Schulhof <gabriel.schulhof@intel.com> | 2019-12-14 06:17:05 +0300 |
commit | d06efafe6b5885e14441409a21eab810cdae754b (patch) | |
tree | a32d97e4313fb30dc333b94541807586333a7fad /src/node_v8.cc | |
parent | d502b83cbdde7ecc7efb3c87503817617d7aacd1 (diff) |
src: explicitly allocate backing stores for v8 stat buffers
This fixes flaky tests that crashed because the allocations ended
up at positions of previously allocated `ArrayBuffer`s that were
still in the backing store table. In particular, there was a race
condition window between destroying a Worker thread’s `Environment`
and destroying its `Isolate` in which the underlying memory was
already released but the `ArrayBuffer` was still existent, meaning
that new memory could be allocated at the address of the previous
`ArrayBuffer`.
Refs: https://github.com/nodejs/node/pull/30782
PR-URL: https://github.com/nodejs/node/pull/30946
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'src/node_v8.cc')
-rw-r--r-- | src/node_v8.cc | 47 |
1 files changed, 8 insertions, 39 deletions
diff --git a/src/node_v8.cc b/src/node_v8.cc index 1f4ef0e35f5..d1fb3666d1a 100644 --- a/src/node_v8.cc +++ b/src/node_v8.cc @@ -158,23 +158,12 @@ void Initialize(Local<Object> target, "updateHeapStatisticsArrayBuffer", UpdateHeapStatisticsArrayBuffer); - env->set_heap_statistics_buffer(new double[kHeapStatisticsPropertiesCount]); - const size_t heap_statistics_buffer_byte_length = sizeof(*env->heap_statistics_buffer()) * kHeapStatisticsPropertiesCount; - std::unique_ptr<BackingStore> heap_statistics_backing = - ArrayBuffer::NewBackingStore(env->heap_statistics_buffer(), - heap_statistics_buffer_byte_length, - [](void*, size_t, void*){}, - nullptr); Local<ArrayBuffer> heap_statistics_ab = - ArrayBuffer::New(env->isolate(), - std::move(heap_statistics_backing)); - // TODO(thangktran): drop this check when V8 is pumped to 8.0 . - if (!heap_statistics_ab->IsExternal()) - heap_statistics_ab->Externalize( - heap_statistics_ab->GetBackingStore()); + ArrayBuffer::New(env->isolate(), heap_statistics_buffer_byte_length); + env->set_heap_statistics_buffer(heap_statistics_ab->GetBackingStore()); target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "heapStatisticsArrayBuffer"), @@ -193,25 +182,15 @@ void Initialize(Local<Object> target, "updateHeapCodeStatisticsArrayBuffer", UpdateHeapCodeStatisticsArrayBuffer); - env->set_heap_code_statistics_buffer( - new double[kHeapCodeStatisticsPropertiesCount]); - const size_t heap_code_statistics_buffer_byte_length = sizeof(*env->heap_code_statistics_buffer()) * kHeapCodeStatisticsPropertiesCount; - std::unique_ptr<BackingStore> heap_code_statistics_backing = - ArrayBuffer::NewBackingStore(env->heap_code_statistics_buffer(), - heap_code_statistics_buffer_byte_length, - [](void*, size_t, void*){}, - nullptr); Local<ArrayBuffer> heap_code_statistics_ab = ArrayBuffer::New(env->isolate(), - std::move(heap_code_statistics_backing)); - // TODO(thangktran): drop this check when V8 is pumped to 8.0 . - if (!heap_code_statistics_ab->IsExternal()) - heap_code_statistics_ab->Externalize( - heap_code_statistics_ab->GetBackingStore()); + heap_code_statistics_buffer_byte_length); + env->set_heap_code_statistics_buffer( + heap_code_statistics_ab->GetBackingStore()); target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "heapCodeStatisticsArrayBuffer"), @@ -257,26 +236,16 @@ void Initialize(Local<Object> target, "updateHeapSpaceStatisticsArrayBuffer", UpdateHeapSpaceStatisticsBuffer); - env->set_heap_space_statistics_buffer( - new double[kHeapSpaceStatisticsPropertiesCount * number_of_heap_spaces]); - const size_t heap_space_statistics_buffer_byte_length = sizeof(*env->heap_space_statistics_buffer()) * kHeapSpaceStatisticsPropertiesCount * number_of_heap_spaces; - std::unique_ptr<BackingStore> heap_space_statistics_backing = - ArrayBuffer::NewBackingStore(env->heap_space_statistics_buffer(), - heap_space_statistics_buffer_byte_length, - [](void*, size_t, void*){}, - nullptr); Local<ArrayBuffer> heap_space_statistics_ab = ArrayBuffer::New(env->isolate(), - std::move(heap_space_statistics_backing)); - // TODO(thangktran): drop this check when V8 is pumped to 8.0 . - if (!heap_space_statistics_ab->IsExternal()) - heap_space_statistics_ab->Externalize( - heap_space_statistics_ab->GetBackingStore()); + heap_space_statistics_buffer_byte_length); + env->set_heap_space_statistics_buffer( + heap_space_statistics_ab->GetBackingStore()); target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "heapSpaceStatisticsArrayBuffer"), |