diff --git a/common.gypi b/common.gypi index 0dcf428002c4c7..f8d98fb492db42 100644 --- a/common.gypi +++ b/common.gypi @@ -36,7 +36,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.3', + 'v8_embedder_string': '-node.5', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/heap/collection-barrier.cc b/deps/v8/src/heap/collection-barrier.cc index 9486c234b0f9db..41dcf3a3b1257b 100644 --- a/deps/v8/src/heap/collection-barrier.cc +++ b/deps/v8/src/heap/collection-barrier.cc @@ -17,6 +17,11 @@ namespace v8 { namespace internal { +CollectionBarrier::CollectionBarrier(Heap* heap) + : heap_(heap), + foreground_task_runner_(V8::GetCurrentPlatform()->GetForegroundTaskRunner( + reinterpret_cast(heap->isolate()))) {} + bool CollectionBarrier::WasGCRequested() { return collection_requested_.load(); } @@ -95,7 +100,14 @@ bool CollectionBarrier::AwaitCollectionBackground(LocalHeap* local_heap) { } // The first thread needs to activate the stack guard and post the task. - if (first_thread) ActivateStackGuardAndPostTask(); + if (first_thread) { + Isolate* isolate = heap_->isolate(); + ExecutionAccess access(isolate); + isolate->stack_guard()->RequestGC(); + + foreground_task_runner_->PostTask( + std::make_unique(heap_)); + } ParkedScope scope(local_heap); base::MutexGuard guard(&mutex_); @@ -109,16 +121,6 @@ bool CollectionBarrier::AwaitCollectionBackground(LocalHeap* local_heap) { return collection_performed_; } -void CollectionBarrier::ActivateStackGuardAndPostTask() { - Isolate* isolate = heap_->isolate(); - ExecutionAccess access(isolate); - isolate->stack_guard()->RequestGC(); - - V8::GetCurrentPlatform() - ->GetForegroundTaskRunner(reinterpret_cast(isolate)) - ->PostTask(std::make_unique(heap_)); -} - void CollectionBarrier::StopTimeToCollectionTimer() { if (collection_requested_.load()) { base::MutexGuard guard(&mutex_); diff --git a/deps/v8/src/heap/collection-barrier.h b/deps/v8/src/heap/collection-barrier.h index fd894324a6fca8..6db89842594839 100644 --- a/deps/v8/src/heap/collection-barrier.h +++ b/deps/v8/src/heap/collection-barrier.h @@ -22,7 +22,7 @@ class Heap; // This class stops and resumes all background threads waiting for GC. class CollectionBarrier { public: - explicit CollectionBarrier(Heap* heap) : heap_(heap) {} + explicit CollectionBarrier(Heap* heap); // Returns true when collection was requested. bool WasGCRequested(); @@ -49,9 +49,6 @@ class CollectionBarrier { bool AwaitCollectionBackground(LocalHeap* local_heap); private: - // Activate stack guards and posting a task to perform the GC. - void ActivateStackGuardAndPostTask(); - Heap* heap_; base::Mutex mutex_; base::ConditionVariable cv_wakeup_; @@ -72,6 +69,9 @@ class CollectionBarrier { // Will be set as soon as Isolate starts tear down. bool shutdown_requested_ = false; + + // Used to post tasks on the main thread. + std::shared_ptr foreground_task_runner_; }; } // namespace internal diff --git a/deps/v8/src/heap/heap.cc b/deps/v8/src/heap/heap.cc index 90aa3360b4baa7..e4d1120f3b4654 100644 --- a/deps/v8/src/heap/heap.cc +++ b/deps/v8/src/heap/heap.cc @@ -283,7 +283,6 @@ Heap::Heap() allocation_type_for_in_place_internalizable_strings_( isolate()->OwnsStringTables() ? AllocationType::kOld : AllocationType::kSharedOld), - collection_barrier_(new CollectionBarrier(this)), marking_state_(isolate_), non_atomic_marking_state_(isolate_), atomic_marking_state_(isolate_), @@ -5431,6 +5430,8 @@ void Heap::SetUp(LocalHeap* main_thread_local_heap) { code_page_allocator = isolate_->page_allocator(); } + collection_barrier_.reset(new CollectionBarrier(this)); + // Set up memory allocator. memory_allocator_.reset( new MemoryAllocator(isolate_, code_page_allocator, MaxReserved())); diff --git a/deps/v8/src/heap/incremental-marking-job.cc b/deps/v8/src/heap/incremental-marking-job.cc index 82cc8fb0c2693b..762282183ce144 100644 --- a/deps/v8/src/heap/incremental-marking-job.cc +++ b/deps/v8/src/heap/incremental-marking-job.cc @@ -36,6 +36,11 @@ class IncrementalMarkingJob::Task : public CancelableTask { const StackState stack_state_; }; +IncrementalMarkingJob::IncrementalMarkingJob(Heap* heap) V8_NOEXCEPT + : heap_(heap), + foreground_task_runner_(V8::GetCurrentPlatform()->GetForegroundTaskRunner( + reinterpret_cast(heap->isolate()))) {} + void IncrementalMarkingJob::ScheduleTask() { base::MutexGuard guard(&mutex_); @@ -44,11 +49,8 @@ void IncrementalMarkingJob::ScheduleTask() { return; } - v8::Isolate* isolate = reinterpret_cast(heap_->isolate()); is_task_pending_ = true; - auto taskrunner = V8::GetCurrentPlatform()->GetForegroundTaskRunner(isolate); - - const auto stack_state = taskrunner->NonNestableTasksEnabled() + const auto stack_state = foreground_task_runner_->NonNestableTasksEnabled() ? StackState::kNoHeapPointers : StackState::kMayContainHeapPointers; @@ -56,10 +58,10 @@ void IncrementalMarkingJob::ScheduleTask() { scheduled_time_ = heap_->MonotonicallyIncreasingTimeInMs(); - if (taskrunner->NonNestableTasksEnabled()) { - taskrunner->PostNonNestableTask(std::move(task)); + if (foreground_task_runner_->NonNestableTasksEnabled()) { + foreground_task_runner_->PostNonNestableTask(std::move(task)); } else { - taskrunner->PostTask(std::move(task)); + foreground_task_runner_->PostTask(std::move(task)); } } diff --git a/deps/v8/src/heap/incremental-marking-job.h b/deps/v8/src/heap/incremental-marking-job.h index ca590bf1140890..a2436342ba7829 100644 --- a/deps/v8/src/heap/incremental-marking-job.h +++ b/deps/v8/src/heap/incremental-marking-job.h @@ -18,7 +18,7 @@ class Isolate; // step and posts another task until the marking is completed. class IncrementalMarkingJob final { public: - explicit IncrementalMarkingJob(Heap* heap) V8_NOEXCEPT : heap_(heap) {} + explicit IncrementalMarkingJob(Heap* heap) V8_NOEXCEPT; void ScheduleTask(); double CurrentTimeToTask() const; @@ -31,6 +31,7 @@ class IncrementalMarkingJob final { base::Mutex mutex_; double scheduled_time_ = 0.0; bool is_task_pending_ = false; + std::shared_ptr foreground_task_runner_; }; } // namespace internal } // namespace v8 diff --git a/src/node_platform.cc b/src/node_platform.cc index 74ab4a3df8f09b..1c1f5b2a3d0f31 100644 --- a/src/node_platform.cc +++ b/src/node_platform.cc @@ -451,10 +451,10 @@ void NodePlatform::DrainTasks(Isolate* isolate) { std::shared_ptr per_isolate = ForNodeIsolate(isolate); if (!per_isolate) return; - do { - // Worker tasks aren't associated with an Isolate. - worker_thread_task_runner_->BlockingDrain(); - } while (per_isolate->FlushForegroundTasksInternal()); + // Drain foreground tasks but not worker tasks as this may cause deadlocks + // and v8::Isolate::Dispose will join V8's worker tasks for that isolate. + while (per_isolate->FlushForegroundTasksInternal()) { + } } bool PerIsolatePlatformData::FlushForegroundTasksInternal() { diff --git a/test/parallel/parallel.status b/test/parallel/parallel.status index 2c105b230fae0b..363cea8f65fb14 100644 --- a/test/parallel/parallel.status +++ b/test/parallel/parallel.status @@ -32,8 +32,6 @@ test-http-server-request-timeouts-mixed: PASS,FLAKY # https://github.com/nodejs/node/pull/31178 test-crypto-dh-stateless: SKIP test-crypto-keygen: SKIP -# https://github.com/nodejs/node/issues/47297 -test-wasm-web-api: SKIP [$system==solaris] # Also applies to SmartOS # https://github.com/nodejs/node/issues/43457 diff --git a/test/wpt/status/wasm/webapi.json b/test/wpt/status/wasm/webapi.json index 3e2075655e5af2..6328e55dc18bc9 100644 --- a/test/wpt/status/wasm/webapi.json +++ b/test/wpt/status/wasm/webapi.json @@ -16,8 +16,5 @@ }, "status.any.js": { "skip": "WPTRunner does not support fetch()" - }, - "instantiateStreaming-bad-imports.any.js": { - "skip": "Flaky on ARM with V8 >= 11.2" } }