Skip to content

Commit 10c761d

Browse files
mi-acV8-internal LUCI CQ
authored andcommitted
Add a code generator to force OSR
Test cases that use OSR currently only do this through --jit-fuzzing triggering OSR in loops, often leading to brittle repros like the referenced bug. This creates a typical pattern in a code generator making use of the %OptimizeOsr() runtime function. Bug: 490353576 Change-Id: Id09459d8f7ba26a1b0eaec7e438de555b22fc7b5 Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/9087056 Reviewed-by: Matthias Liedtke <mliedtke@google.com> Commit-Queue: Michael Achenbach <machenbach@google.com>
1 parent f0f491a commit 10c761d

5 files changed

Lines changed: 32 additions & 0 deletions

File tree

Sources/Fuzzilli/Profiles/V8CommonProfile.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,34 @@ public let ForceTurboFanCompilationGenerator = forceCompilationGenerator(
148148
public let ForceMaglevCompilationGenerator = forceCompilationGenerator(
149149
"ForceMaglevCompilationGenerator", optimizeName: "OptimizeMaglevOnNextCall")
150150

151+
// Create a loop and force OSR in one of the iterations.
152+
public let ForceOsrGenerator = CodeGenerator("ForceOsrGenerator", [
153+
GeneratorStub(
154+
"ForceOsrBeginGenerator",
155+
inContext: .single(.javascript),
156+
provides: [.javascript]
157+
) { b in
158+
let numIterations = Int.random(in: 2...50)
159+
let loopVar = b.emit(BeginRepeatLoop(iterations: numIterations)).innerOutput
160+
let condition = b.compare(
161+
loopVar, with: b.loadInt(Int64.random(in: 0..<Int64(numIterations))),
162+
using: .equal)
163+
b.buildIf(condition) {
164+
if probability(0.8) {
165+
b.eval("%OptimizeOsr()");
166+
} else {
167+
b.eval("%OptimizeOsr(%@)", with: [b.loadInt(1)]);
168+
}
169+
}
170+
},
171+
GeneratorStub(
172+
"ForceOsrEndGenerator",
173+
inContext: .single([.javascript])
174+
) { b in
175+
b.emit(EndRepeatLoop())
176+
},
177+
])
178+
151179
public let TurbofanVerifyTypeGenerator = CodeGenerator("TurbofanVerifyTypeGenerator", inputs: .one) { b, v in
152180
b.eval("%VerifyType(%@)", with: [v])
153181
}

Sources/Fuzzilli/Profiles/V8DumplingProfile.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ let v8DumplingProfile = Profile(
126126
(ForceJITCompilationThroughLoopGenerator, 5),
127127
(ForceTurboFanCompilationGenerator, 5),
128128
(ForceMaglevCompilationGenerator, 5),
129+
(ForceOsrGenerator, 5),
129130
(TurbofanVerifyTypeGenerator, 10),
130131

131132
(V8GcGenerator, 10),

Sources/Fuzzilli/Profiles/V8HoleFuzzingProfile.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ let v8HoleFuzzingProfile = Profile(
7171
(ForceJITCompilationThroughLoopGenerator, 5),
7272
(ForceTurboFanCompilationGenerator, 5),
7373
(ForceMaglevCompilationGenerator, 5),
74+
(ForceOsrGenerator, 5),
7475
(V8GcGenerator, 10),
7576
(HoleLeakGenerator, 25),
7677
],

Sources/Fuzzilli/Profiles/V8Profile.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public let v8Profile = Profile(
6060
(ForceJITCompilationThroughLoopGenerator, 5),
6161
(ForceTurboFanCompilationGenerator, 5),
6262
(ForceMaglevCompilationGenerator, 5),
63+
(ForceOsrGenerator, 5),
6364
(TurbofanVerifyTypeGenerator, 10),
6465

6566
(WorkerGenerator, 10),

Sources/Fuzzilli/Profiles/V8SandboxProfile.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ let v8SandboxProfile = Profile(
522522
(ForceJITCompilationThroughLoopGenerator, 5),
523523
(ForceTurboFanCompilationGenerator, 5),
524524
(ForceMaglevCompilationGenerator, 5),
525+
(ForceOsrGenerator, 5),
525526
(V8GcGenerator, 10),
526527
(WasmStructGenerator, 5),
527528
(WasmArrayGenerator, 5),

0 commit comments

Comments
 (0)