Commit 0dc6e037 authored by Shu-yu Guo's avatar Shu-yu Guo Committed by V8 LUCI CQ

[compiler] Park main thread while awaiting compile tasks

Currently a deadlock can result on heap teardown during the shared heap
verification which performs a global safepoint. The heap teardown awaits
compile tasks, while the compile helper thread is waiting on a
global safepoint.

Bug: v8:11708
Change-Id: I8328a4b142cb9045bfaf592ac4f4dd259ba0d397
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3820354
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarDominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82364}
parent 3f0c4414
......@@ -139,8 +139,12 @@ void OptimizingCompileDispatcher::FlushInputQueue() {
void OptimizingCompileDispatcher::AwaitCompileTasks() {
{
AllowGarbageCollection allow_before_parking;
ParkedScope parked_scope(isolate_->main_thread_local_isolate());
base::MutexGuard lock_guard(&ref_count_mutex_);
while (ref_count_ > 0) ref_count_zero_.Wait(&ref_count_mutex_);
while (ref_count_ > 0) {
ref_count_zero_.ParkedWait(parked_scope, &ref_count_mutex_);
}
}
#ifdef DEBUG
......@@ -152,10 +156,7 @@ void OptimizingCompileDispatcher::AwaitCompileTasks() {
void OptimizingCompileDispatcher::FlushQueues(
BlockingBehavior blocking_behavior, bool restore_function_code) {
FlushInputQueue();
if (blocking_behavior == BlockingBehavior::kBlock) {
base::MutexGuard lock_guard(&ref_count_mutex_);
while (ref_count_ > 0) ref_count_zero_.Wait(&ref_count_mutex_);
}
if (blocking_behavior == BlockingBehavior::kBlock) AwaitCompileTasks();
FlushOutputQueue(restore_function_code);
}
......
......@@ -12,6 +12,7 @@
#include "src/base/platform/mutex.h"
#include "src/common/globals.h"
#include "src/flags/flags.h"
#include "src/heap/parked-scope.h"
#include "src/utils/allocation.h"
namespace v8 {
......@@ -98,7 +99,7 @@ class V8_EXPORT_PRIVATE OptimizingCompileDispatcher {
std::atomic<int> ref_count_;
base::Mutex ref_count_mutex_;
base::ConditionVariable ref_count_zero_;
ParkingConditionVariable ref_count_zero_;
// Copy of FLAG_concurrent_recompilation_delay that will be used from the
// background thread.
......
......@@ -119,6 +119,7 @@ class V8_NODISCARD ParkedSharedMutexGuardIf final {
class V8_NODISCARD ParkingConditionVariable final
: public base::ConditionVariable {
public:
ParkingConditionVariable() = default;
ParkingConditionVariable(const ParkingConditionVariable&) = delete;
ParkingConditionVariable& operator=(const ParkingConditionVariable&) = delete;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment