Closed Bug 1925105 Opened 2 years ago Closed 3 months ago

Missing interpreter frames in profiles of resumed async functions (interpreter and baseline interpreter)

Categories

(Core :: JavaScript Engine, defect, P2)

defect

Tracking

()

RESOLVED FIXED
156 Branch
Tracking Status
firefox156 --- fixed

People

(Reporter: mstange, Assigned: jandem)

References

(Blocks 1 open bug)

Details

(Whiteboard: [sp3])

Attachments

(1 file, 1 external file, 1 obsolete file)

For profiling with native profilers such as samply or perf, Spidermonkey supports entering "stub" functions for the C++ interpreter and the Baseline interpreter. However, it seems that when resuming an async functions, we sometimes don't enter these stubs.
Example profile: https://share.firefox.dev/3UfMbPV

This makes it hard to account the correct sample count to these async functions. It also makes it hard to get an accurate sense of the async/await overhead tracked in bug 1924185.

Markus, can you name which frames we are supposed to look at in the flame graph?

Flags: needinfo?(mstange.moz)
Blocks: speedometer3
Severity: -- → S3
Priority: -- → P2
Whiteboard: [js-perf-next]

The callees of the Baseline: AsyncFunctionNext frame are the frames that are missing JS function names.

I'll try to get a reduced testcase.

Flags: needinfo?(mstange.moz)
Flags: needinfo?(mstange.moz)
Whiteboard: [js-perf-next] → [js-perf-next][sp3]
Whiteboard: [js-perf-next][sp3] → [sp3]
Attached file testcase (obsolete) —

samply profile of this testcase: https://share.firefox.dev/428alAq

The profile is missing the frame for myAsyncFunction(). It's unclear from the profile what is calling foo() and bar().

This profile was collected with samply record -r 4000 PERF_SPEW_DIR=. IONPERF=func MOZ_DISABLE_CONTENT_SANDBOX=1 JIT_OPTION_enableICFramePointers=true JIT_OPTION_onlyInlineSelfHosted=true JIT_OPTION_emitInterpreterEntryTrampoline=true python3 ./mach run on macOS.

Flags: needinfo?(mstange.moz)
Attached file better testcase —

Actually the previous testcase wasn't good because it was calling foo() and bar() with await.

Here's a testcase with regular calls from myAsyncFunction() to foo() and to bar(). There's no interpreter trampoline frame for myAsyncFunction() in the profile: https://share.firefox.dev/3RGLBsL

Attachment #9478187 - Attachment is obsolete: true

I took a quick look at this. It's a non-trivial fix.

To resume a generator / async function, we call into self-hosted code (GeneratorNext for generators, AsyncFunctionNext for async functions). Those functions contain a call to the resumeGenerator intrinsic, which the parser turns into JSOp::Resume. The effect of JSOp::Resume is to set up the stack frame for the function being resumed, and then jump to the right place in the code. This plays out in different ways depending on the tier of the result, but the key fact for every tier is that we never actually call the resumed function. We always set up a fake stack frame manually. This means that we can't reuse our existing interpreter entry trampolines, which call the wrapped function.

Instead, we would have to generate a second set of resume trampolines, or at least add an additional path in the trampoline for async functions / generators that would resume the function instead of calling it. Then we could make the resume code call into those trampolines.

We should revisit this after we finish landing patches for bug 1317690 (supporting generators in Ion). Resuming a generator has been rewritten to be more like a regular call; we might be able to make the trampolines work with relatively small changes.

Depends on: 1317690

It's possible this has been fixed already; in bug 2058411 part 13 we had to add resume-support to the interpreter-entry trampoline.

We may still need to call MaybeEnterInterpreterTrampoline for the JSOp::Resume case in the C++ interpreter (only used for plain generators now), but otherwise it might just work?

I tested this and it looks fixed but I'll post a patch for the sync-generator issue from comment 7.

After the generator-resume rewrite in bug 2058411, we now support interpreter-entry
trampolines (for profiling Nightly builds).

The only place still missing support for this was the JSOp::Resume code in the
C++ interpreter. This patch adds code for that similar to what we do for
JSOp::Call etc.

This code is covered by the resume-interpreter-entry-trampoline.js jit-test.

Assignee: nobody → jdemooij
Status: NEW → ASSIGNED
Assignee: nobody → jdemooij
Status: NEW → ASSIGNED
Pushed by jdemooij@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/2fcc4cf798cb https://hg.mozilla.org/integration/autoland/rev/6d9fd038678c Use interpreter-entry trampoline for JSOp::Resume in the C++ interpreter. r=spidermonkey-reviewers,mgaudet
Status: ASSIGNED → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Target Milestone: --- → 156 Branch
QA Whiteboard: [qa-triage-done-c157/b156]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: