[go: up one dir, main page]

Page MenuHomePhabricator

Bug 1894937 - Trace JitCode weak refs via new JitCode::weakDataRelocTable r=jonco
Needs RevisionPublic

Authored by bthrall on Feb 18 2026, 5:54 PM.
Tags
None
Referenced Files
F84360326: D283930.1792206607.diff
Fri, Oct 16, 3:10 AM
F84360325: D283930.1792206606.diff
Fri, Oct 16, 3:10 AM
Unknown Object (File)
Thu, Oct 15, 5:58 PM
Unknown Object (File)
Thu, Oct 15, 5:58 PM
Unknown Object (File)
Tue, Oct 13, 6:34 PM
Unknown Object (File)
Tue, Oct 13, 6:34 PM
Unknown Object (File)
Tue, Oct 13, 7:34 AM
Unknown Object (File)
Sat, Oct 10, 12:33 PM

Details

Reviewers
jonco
jandem
Bugzilla Bug ID
1894937
Merge Conflict Status
Landing merges cleanly into the target branch
Merges cleanly when merged against target branch tip 72fa9c388cbb, starting from 00a4d527cdb9, with 1 parent revision(s) applied first.
Last checked Fri, Oct 16, 7:42 PM
Diff 1395315, based on 00a4d527cdb9
Summary

We need to update the weak pointers that are baked into IC code.

moveValue will need to propagate weakness for GuardHasGetterSetter ICs.

Diff Detail

Repository
rFIREFOXAUTOLAND firefox-autoland
Branch
HEAD

Event Timeline

bthrall created this revision.
phab-bot changed the visibility from "Custom Policy" to "Public (No Login Required)".Feb 18 2026, 5:54 PM
phab-bot changed the edit policy from "Custom Policy" to "Restricted Project (Project)".
phab-bot removed a project: secure-revision.

Code analysis found 12 defects in diff 1207421:

  • 6 defects found by clang-format
  • 6 defects found by clang-format (Mozlint)
WARNING: Found 12 defects (warning level) that can be dismissed.

You can run this analysis locally with:

  • ./mach lint --warnings --outgoing
  • ./mach clang-format -p js/src/jit/IonCacheIRCompiler.cpp js/src/jit/x86-shared/Assembler-x86-shared.cpp js/src/jit/x86-shared/Assembler-x86-shared.h js/src/jit/shared/Assembler-shared.h js/src/jit/JitcodeMap.cpp js/src/jit/JitCode.h

For your convenience, here is a patch that fixes all the clang-format defects (use it in your repository with hg import or git apply -p0).


If you see a problem in this automated review, please report it here.

You can view these defects in the Diff Detail section of Phabricator diff 1207421.

bthrall updated this revision to Diff 1308016.
bthrall retitled this revision from WIP: Bug 1894937 - Add JitCode::weakDataRelocTable to WIP: Bug 1894937 - Trace JitCode weak refs via new JitCode::weakDataRelocTable.
bthrall edited the summary of this revision. (Show Details)
bthrall updated this revision to Diff 1320260.
bthrall retitled this revision from WIP: Bug 1894937 - Trace JitCode weak refs via new JitCode::weakDataRelocTable to Bug 1894937 - Trace JitCode weak refs via new JitCode::weakDataRelocTable r=jonco.
bthrall added a reviewer: jonco.

Looks good but see comments about TraceWeakEdge / TraceOrClearWeakEdge which applies everywhere. Sorry I changed this underneath you!

js/src/gc/Marking.cpp
3256

To be consistent with TraceWeakEdge this should use |true| for null edges.

3267

These functions have been changed recently to split TraceWeakEdge and TraceOrClearWeakEdge. I think that this one should have 'OrClear' in the name since you are expecting it to clear the dead edge.

js/src/jit/arm/Assembler-arm.cpp
742

super nit: you could static_cast this to gc::Cell* and you wouldn't need to reinterpret_cast below.

js/src/jit/arm64/Assembler-arm64.cpp
618

How often does this happen? TraceManuallyBarrieredWeakEdge doesn't clear the edge any more. This will need an 'OrClear' version.

bthrall marked 4 inline comments as done.
js/src/jit/arm64/Assembler-arm64.cpp
618

It primarily comes from CacheIRCompiler::emitGuardHasGetterSetter(), but can also come from CacheIRCompiler::emitCheckWeakValueResultForFixedSlot() and emitCheckWeakValueResultForDynamicSlot().

IonCacheIRCompiler::emitUncheckedLoadWeakObjectResult() (as patched by D308631) also could create weak Value relocations, but it doesn't seem to be used.

jonco added a reviewer: jandem. jonco added 1 blocking reviewer(s): jonco.

Thanks for the updates.

I'm happy with the GC changes. Jan should look at the JIT changes though.

This makes sense but some nits and a design question below.

js/src/jit/Ion.cpp
851–853

Do you know what this does for weak pointers to GC cells that are dead? Do weak Shape* pointers in JIT code become nullptr? I think the safest option would be to use this only for Ion IC stubs, similar to the Baseline stubs, and not for the transpiler.

js/src/jit/riscv64/Assembler-riscv64.cpp
141

Nit: weakDataRelocations_.length()

js/src/jit/x86-shared/Assembler-x86-shared.cpp
109–110

This is very similar to TraceDataRelocations, except for the Trace*Edge call. I think it would be simpler to add a bool weak argument and then call the strong vs weak Trace*Edge based on that. The extra branch is fine and predictable for the CPU.

jandem requested changes to this revision.Jul 31 2026, 3:43 PM

(Changing status so I see updates..)

This revision now requires changes to proceed.Jul 31 2026, 3:43 PM
bthrall updated this revision to Diff 1395315.
bthrall marked 2 inline comments as done.

(Reviewing Diff 1395315)
The relocation-table plumbing looks mechanically consistent across back-ends. The main risk is semantic: clearing a weak immediate leaves runnable JIT code with a null or substituted constant, and nothing invalidates or unlinks that code. That needs to be fixed before any users of weak relocations land.


Please use / reactions on inline comments to provide feedback. This will have a significant impact on the quality of future reviews.
js/src/jit/Ion.cpp
687

When a weak relocation gets cleared, nothing invalidates, unlinks or discards the JitCode. TraceDataRelocations returns void, and traceWeakChildren / IonIC::traceWeak / IonScript::traceWeak / BaselineScript::traceWeak ignore the outcome. The code stays live and keeps running with nullptr baked in (or UndefinedValue() for punboxed Values). A guard that compares a Value operand against the cleared immediate now matches undefined, which is a wrong-behaviour bug. Make the trace routines report whether anything was cleared, and use that to unlink the IC stub or invalidate the Ion/Baseline script.

js/src/jit/arm64/Assembler-arm64.h
609

assertNoGCThings() checks weakDataRelocations_ only on x86/x64. Add MOZ_ASSERT(weakDataRelocations_.length() == 0) to assertNoGCThings() on ARM, ARM64, MIPS, LoongArch64 and RISC-V64 too. Otherwise a weak GC pointer emitted into code that must not contain GC things goes unnoticed on those platforms.

js/src/jit/x86-shared/Assembler-x86-shared.cpp
87

Several new lines break the clang-format style. Examples: static_cast<gc::Cell *> / reinterpret_cast<gc::Cell **> (the existing code used gc::Cell*), if (weak){ in Assembler-arm.cpp, the leading || in Assembler-arm64.h's oom(), and many signatures and bytesNeeded() bodies longer than 80 columns. Run ./mach clang-format on the patch.

js/src/jit/x86/MacroAssembler-x86.cpp
964

On nunbox32 (x86 and ARM), only the payload is recorded as a weak relocation. The tag is emitted as a plain Imm32. Clearing the weak edge zeroes the payload but keeps the GC-thing tag (e.g. JSVAL_TAG_OBJECT), so the generated code builds an object/string Value with a null payload, which is invalid. On punbox64 the same clear gives UndefinedValue(), so the platforms also disagree. Fix this so a cleared weak Value turns into a consistent, valid Value on every platform, or forbid weak moveValue on nunbox until the code is guaranteed to be discarded. The same applies to MacroAssembler-arm.cpp.

jandem requested changes to this revision.Tue, Oct 13, 8:10 AM

This is mostly ready but we should call JitCode::traceWeakChildren only for Ion IC code. I think the bot is technically correct that we should check the return value of this call somehow, but for Ion ICs we can probably get away with this because we check the return value of TraceWeakCacheIRStub instead?

js/src/jit/Ion.cpp
852

Here and for the BaselineScript version, we should instead release-assert there are no weak pointers in the JitCode, because handling this properly will require more work (checking the return value, if it's false invalidate the script or something).

The BaselineIC version here should also assert there are no weak pointers in the JitCode.

js/src/jit/arm64/Assembler-arm64.h
609

This seems valid.

This revision now requires changes to proceed.Tue, Oct 13, 8:10 AM
This revision now requires review to proceed.Tue, Oct 13, 8:22 AM

Rather than passing | bool weak | what do you think about adding an enum (e.g. PtrKind::Strong/Weak)?

Rather than passing | bool weak | what do you think about adding an enum (e.g. PtrKind::Strong/Weak)?

Another option is to add ImmWeakGCPtr that derives from ImmGCPtr and passes the bool weak = true flag to the base constructor.

jandem requested changes to this revision.Fri, Oct 16, 11:34 AM

(Changing the status again, looks like it was lost with Jon's review)

This revision now requires changes to proceed.Fri, Oct 16, 11:34 AM