diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-09-21 00:42:31 +0300 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-09-25 07:35:40 +0300 |
commit | 7899a96e66a2f9bb836ca80d8264954848633a3d (patch) | |
tree | d53d1b85aa621e6e4a518599f1eed4b4860bed25 /src/env.cc | |
parent | 355f2ad466dc155cae233e3990d19b094dd72b46 (diff) |
worker: keep allocators for transferred SAB instances alive longer
Keep the `ArrayBuffer::Allocator` behind a `SharedArrayBuffer` instance
alive for at least as long as the receiving Isolate lives, if the
`SharedArrayBuffer` instance isn’t already destroyed through GC.
This is to work around the fact that V8 7.9 started refactoring
how backing stores for `SharedArrayBuffer` instances work, changing
the timing of the call that releases the backing store to be
during Isolate disposal.
The flag added to the test is optional but helps verify that the
backing store is actually free’d at the end of the test and does not
leak memory.
Fixes: https://github.com/nodejs/node-v8/issues/115
PR-URL: https://github.com/nodejs/node/pull/29637
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src/env.cc')
-rw-r--r-- | src/env.cc | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/env.cc b/src/env.cc index 257bf78519f..2400785ea82 100644 --- a/src/env.cc +++ b/src/env.cc @@ -1036,6 +1036,21 @@ char* Environment::Reallocate(char* data, size_t old_size, size_t size) { return new_data; } +void Environment::AddArrayBufferAllocatorToKeepAliveUntilIsolateDispose( + std::shared_ptr<v8::ArrayBuffer::Allocator> allocator) { + if (keep_alive_allocators_ == nullptr) { + MultiIsolatePlatform* platform = isolate_data()->platform(); + CHECK_NOT_NULL(platform); + + keep_alive_allocators_ = new ArrayBufferAllocatorList(); + platform->AddIsolateFinishedCallback(isolate(), [](void* data) { + delete static_cast<ArrayBufferAllocatorList*>(data); + }, static_cast<void*>(keep_alive_allocators_)); + } + + keep_alive_allocators_->insert(allocator); +} + void AsyncRequest::Install(Environment* env, void* data, uv_async_cb target) { CHECK_NULL(async_); env_ = env; |