Closed Bug 1969435 Opened 11 months ago Closed 9 months ago

Remove GC things from JitcodeGlobalEntry

Categories

(Core :: JavaScript Engine, task, P3)

task

Tracking

()

RESOLVED FIXED
143 Branch
Tracking Status
firefox143 --- fixed

People

(Reporter: canova, Assigned: canova)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

This is an idea Iain had after we talked about the profiler/SM issues. Right now, JitcodeGlobalEntry holds direct references to GC-managed objects like JSScript*, and those get accessed from the profiler's sampling thread. That’s a problem because compacting GC can move things around, and we risk crashes like the one in bug 1833295, where the sampling thread tries to dereference a pointer that's in the middle of being moved.

There’s another issue too: since entries hold on to things like scripts and their realms, they can end up keeping memory alive longer than needed, especially if profiler samples are still referencing them. That can lead to shutdown crashes and memory retention.

To fix this, we should remove all GC references from JitcodeGlobalEntry. The first step is to delete the unused callStackAtAddr variant, which already relies on accessing the script. That patch is approved. Next, we can store the realmId directly in the entry at creation time so we don’t need to touch the script or realm later. After that, removing the JSScript* becomes a straightforward cleanup.

Lastly, we should make the JitCode pointer permanently weak. Instead of keeping it alive in markIteratively, we should move that logic to traceWeak, and decide whether to drop the entry or defer cleanup based on profiler state. With these changes, we avoid touching GC-managed memory off-thread and hopefully eliminate a whole class of lifetime bugs and crashes.

Currently this is blocked by bug 1963824. There is an approved patch but we can't land it due to conflicts. I might rebase and land it if we don't hear from our contributor by the next week.

Severity: -- → N/A
Priority: -- → P3

Hey Iain, bug 1963824 is landed now, so hopefully there is no blocker left for this! Do you have some time to look at it? Thanks!

Flags: needinfo?(iireland)

I took a quick look at this yesterday. The patch to storeOne obstacle that we hadn't spotted earlier is this code in JSJitProfilingFrameIterator::tryInitWithTable, which uses the script pointer in the baseline/ion entries to filter out certain cases where the lastProfilingCallSite may not be reliable. I don't know the tryInitWithTable code very well, so I'll have to do a bit of investigation to figure out whether it's okay to stop filtering, or whether we should find a way to keep filtering without keeping scripts alive.

Flags: needinfo?(iireland)

Putting up my WIP patches before going on leave. They are green on try, but I otherwise haven't tested them.

In the action plan in this doc, these patches cover parts 2-3 of the first task, and part 1 of the second task. I think this should unblock Nazim's work on JS source code in profiles. The one missing piece on my end is part 4 of the first task, which will also prevent dead JitCode from being kept alive.

Assignee: nobody → canaltinova
Status: NEW → ASSIGNED
Attachment #9497437 - Attachment description: WIP: Bug 1969435: Store realmID directly in JitcodeGlobalEntry → Bug 1969435: Store realmID directly in JitcodeGlobalEntry
Attachment #9497438 - Attachment description: WIP: Bug 1969435: Store ScriptSourceAndExtent in IonEntry/BaselineEntry instead of JSScript → Bug 1969435: Store ScriptSourceAndExtent in IonEntry/BaselineEntry instead of JSScript
Status: ASSIGNED → RESOLVED
Closed: 9 months ago
Resolution: --- → FIXED
Target Milestone: --- → 143 Branch
QA Whiteboard: [qa-triage-done-c144/b143]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: