Skip to content

Commit 82dbe6e

Browse files
GeorgNeismibrunin
authored andcommitted
[Backport] Security bug 1211215
Cherry-pick of patch originally reviewed on https://chromium-review.googlesource.com/c/v8/v8/+/2940899: Merged: Squashed multiple commits. Merged: Disable left-trimming when optimizing compile jobs exist Revision: ac0605a1a486b8d074f116cc365de9d2b6d7c9e5 Merged: [heap] Don't assume that optimizing-compile-dispatcher exists Revision: 022b312d55e75935cfa99cca7729ae2d3f795bd0 BUG=chromium:1211215,chromium:1215514 NOTRY=true NOPRESUBMIT=true NOTREECHECKS=true [email protected] Change-Id: I3b3a37d64402ea464c8e653517928522a1c5e0da Reviewed-by: Dominik Inführ <[email protected]> Commit-Queue: Georg Neis <[email protected]> Cr-Commit-Position: refs/branch-heads/9.1@{#67} Cr-Branched-From: 0e4ac64a8cf298b14034a22f9fe7b085d2cb238d-refs/heads/9.1.269@{#1} Cr-Branched-From: f565e72d5ba88daae35a59d0f978643e2343e912-refs/heads/master@{#73847} Reviewed-by: Michal Klocek <[email protected]>
1 parent 63aa707 commit 82dbe6e

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

chromium/v8/src/compiler-dispatcher/optimizing-compile-dispatcher.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class OptimizingCompileDispatcher::CompileTask : public CancelableTask {
4747
worker_thread_runtime_call_stats_(
4848
isolate->counters()->worker_thread_runtime_call_stats()),
4949
dispatcher_(dispatcher) {
50-
base::MutexGuard lock_guard(&dispatcher_->ref_count_mutex_);
5150
++dispatcher_->ref_count_;
5251
}
5352

@@ -95,12 +94,7 @@ class OptimizingCompileDispatcher::CompileTask : public CancelableTask {
9594
};
9695

9796
OptimizingCompileDispatcher::~OptimizingCompileDispatcher() {
98-
#ifdef DEBUG
99-
{
100-
base::MutexGuard lock_guard(&ref_count_mutex_);
101-
DCHECK_EQ(0, ref_count_);
102-
}
103-
#endif
97+
DCHECK_EQ(0, ref_count_);
10498
DCHECK_EQ(0, input_queue_length_);
10599
DeleteArray(input_queue_);
106100
}
@@ -227,6 +221,14 @@ void OptimizingCompileDispatcher::InstallOptimizedFunctions() {
227221
}
228222
}
229223

224+
bool OptimizingCompileDispatcher::HasJobs() {
225+
DCHECK_EQ(ThreadId::Current(), isolate_->thread_id());
226+
// Note: This relies on {output_queue_} being mutated by a background thread
227+
// only when {ref_count_} is not zero. Also, {ref_count_} is never incremented
228+
// by a background thread.
229+
return !(ref_count_ == 0 && output_queue_.empty());
230+
}
231+
230232
void OptimizingCompileDispatcher::QueueForOptimization(
231233
OptimizedCompilationJob* job) {
232234
DCHECK(IsQueueAvailable());

chromium/v8/src/compiler-dispatcher/optimizing-compile-dispatcher.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class V8_EXPORT_PRIVATE OptimizingCompileDispatcher {
5252

5353
static bool Enabled() { return FLAG_concurrent_recompilation; }
5454

55+
// This method must be called on the main thread.
56+
bool HasJobs();
57+
5558
private:
5659
class CompileTask;
5760

@@ -87,7 +90,7 @@ class V8_EXPORT_PRIVATE OptimizingCompileDispatcher {
8790

8891
int blocked_jobs_;
8992

90-
int ref_count_;
93+
std::atomic<int> ref_count_;
9194
base::Mutex ref_count_mutex_;
9295
base::ConditionVariable ref_count_zero_;
9396

chromium/v8/src/heap/heap.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "src/codegen/compilation-cache.h"
2323
#include "src/common/assert-scope.h"
2424
#include "src/common/globals.h"
25+
#include "src/compiler-dispatcher/optimizing-compile-dispatcher.h"
2526
#include "src/debug/debug.h"
2627
#include "src/deoptimizer/deoptimizer.h"
2728
#include "src/execution/isolate-utils-inl.h"
@@ -3036,6 +3037,12 @@ bool Heap::CanMoveObjectStart(HeapObject object) {
30363037

30373038
if (IsLargeObject(object)) return false;
30383039

3040+
// Compilation jobs may have references to the object.
3041+
if (isolate()->concurrent_recompilation_enabled() &&
3042+
isolate()->optimizing_compile_dispatcher()->HasJobs()) {
3043+
return false;
3044+
}
3045+
30393046
// We can move the object start if the page was already swept.
30403047
return Page::FromHeapObject(object)->SweepingDone();
30413048
}

0 commit comments

Comments
 (0)