Closed Bug 2060131 Opened 5 days ago Closed 3 days ago

Support JSOp::Resume in Warp

Categories

(Core :: JavaScript Engine: JIT, task)

task

Tracking

()

RESOLVED FIXED
155 Branch
Tracking Status
firefox155 --- fixed

People

(Reporter: jandem, Assigned: jandem)

References

(Blocks 1 open bug)

Details

Attachments

(10 files)

48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review

Bug 2058411 changed generator-resume to be callee-driven and JSOp::Resume is now similar to a function call. This means we can now support it in WarpBuilder. This lets us Ion-compile + inline the self-hosted GeneratorNext function.

This is just the resumer side; Ion-compiling the generator/async function itself is more complicated and is the bigger win, but this is also a small improvement: the micro-benchmark below improves from 1838 ms to 1604 ms on my machine.

function* gen() {
  for (var i = 0; i < 100_000_000; i++) {
    yield 1;
  }
}
function f() {
  var res = 0;
  var t = Date.now();
  for (var x of gen()) {
    res += x;
  }
  print(Date.now() - t);
  print(res);
}
f();

This adds a fourth slot to ResumeFrameArgs for the generator's resume index.
The resumer is now responsible for reading the generator's resume index slot and
marking the generator as running (this clobbers the generator's resume index slot).

Initially this was required for part 4, but I've since changed that path to no longer
allow executing arbitrary JS through the interrupt handler. However having the resume
index in ResumeFrameArgs also simplifies the Ion implementation later on and will be
more efficient in some cases, so I've kept it.

The next patch will use this to restore registers in emitIsDebuggeeCheck only if
we actually called into C++.

We were doing this as part of JSOp::AfterYield, but that's too late when we
add an overrecursion check to the resume prologue.

Setting the flag in the prologue makes this consistent with both the C++ interpreter's
resume code and Baseline's non-resume prologue.

This is more consistent with the normal (non-resume) prologue. Currently all
generator-resumes go through GeneratorNext and it has an overrecursion check,
but when Ion can inline that function and compile generators, the generator's
own overrecursion check becomes more important.

Unlike the normal overrecursion check in the prologue, this one does not handle
interrupts. Supporting interrupts while we're in the middle of resuming a generator
frame is complicated considering Debugger interactions.

GeneratorNext now has a bytecode length of ~115, less than smallFunctionMaxBytecodeLength (140).
This ensures we can inline it once WarpBuilder can compile JSOp::Resume.

The GeneratorSetClosed intrinsic was only called in the catch-blocks, after
checking !GeneratorObjectIsClosed. Move that if-statement into the intrinsic to
avoid the extra call and branch.

Now that JSOp::Resume is very similar to a call, we can Ion-compile and inline
the self-hosted GeneratorNext function. (GeneratorThrow and GeneratorReturn
can also be Ion-compiled now but they're less performance-sensitive.)

This will avoid a redundant unbox in Ion.

This is required to get good performance for Ion-compiled GeneratorNext.

BaselineFrame::trace and InterpreterFrame::trace clear the locals that aren't live
at the frame's pc. Nothing between restoring these slots and setting the pc can GC,
so assert this to prevent a (future) footgun.

This was an issue for an earlier prototype based on a different approach. It caused
JetStream to fail intermittently.

Pushed by jdemooij@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/44ccd2a4fcf1 https://hg.mozilla.org/integration/autoland/rev/f8944199b9e5 part 1 - Pass the generator resume index in the ResumeFrameArgs. r=iain https://github.com/mozilla-firefox/firefox/commit/5eedf93248d8 https://hg.mozilla.org/integration/autoland/rev/4256d4d5e006 part 2 - Add emitAfterCall argument to emitIsDebuggeeCheck. r=iain https://github.com/mozilla-firefox/firefox/commit/9879a2d1ab80 https://hg.mozilla.org/integration/autoland/rev/8b06c0d9e6a0 part 3 - Set the frame's debuggee flag in Baseline's generator resume prologue. r=iain https://github.com/mozilla-firefox/firefox/commit/8efdfae70717 https://hg.mozilla.org/integration/autoland/rev/c008707e2e86 part 4 - Add an overrecursion check to the generator resume prologue. r=iain https://github.com/mozilla-firefox/firefox/commit/13a058f8307e https://hg.mozilla.org/integration/autoland/rev/c8c48b313662 part 5 - Shrink GeneratorNext so that it can be inlined later. r=iain https://github.com/mozilla-firefox/firefox/commit/52b3c9699cea https://hg.mozilla.org/integration/autoland/rev/0b3651bc33f5 part 6 - Support JSOp::Resume in WarpBuilder. r=iain https://github.com/mozilla-firefox/firefox/commit/1d7c81028b30 https://hg.mozilla.org/integration/autoland/rev/676585a0fe2f part 7 - Rename CallIsSuspendedGeneratorResult op to IsSuspendedGeneratorResult. r=iain https://github.com/mozilla-firefox/firefox/commit/f10aa7bbbdd6 https://hg.mozilla.org/integration/autoland/rev/3b44c81dae61 part 8 - Make IsSuspendedGeneratorResult take an object operand. r=iain https://github.com/mozilla-firefox/firefox/commit/cd88ae08d75f https://hg.mozilla.org/integration/autoland/rev/10f0f7db2d8a part 9 - Transpile IsSuspendedGeneratorResult. r=iain https://github.com/mozilla-firefox/firefox/commit/9c6d75198bd3 https://hg.mozilla.org/integration/autoland/rev/ce8346d5a287 part 10 - Assert resuming generator stack slots are only traced at the resume point. r=iain
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: