Closed Bug 1765346 Opened 4 years ago Closed 1 year ago

Consider removing alignas(8) from JS::Value

Categories

(Core :: JavaScript Engine, task, P3)

task

Tracking

()

RESOLVED FIXED
141 Branch
Tracking Status
firefox141 --- fixed

People

(Reporter: jandem, Assigned: jandem)

References

(Blocks 2 open bugs)

Details

Attachments

(3 files)

We can't pass JS::Value by value as function argument due to its alignas(8). It's not clear to me if/why we still need this. Value contains just a uint64_t asBits_ field nowadays.

If I remove the alignas, things seem to work fine. We need some JIT codegen changes for 32-bit platforms where Map/Set entries are a bit smaller now, but that's easy to fix.

My understanding of this alignas is the requirement that JS::Value hold double value which are read/written as double and some architecture cause a SIGBUS when the memory is not properly aligned. (ARM?)

Good point, but alignof(Value) would still be 8 on 32-bit ARM due to its uint64_t member.

There could be an issue with the ARM simulator because it has LDRD/STRD alignment assertions and compiles for x86-32 where the alignment is 4. It does pass all jit-tests for me though.

Unaligned FP loads are dicey on some ARM systems depending on the code the C++ compiler generates. Generally these days it seems that the kernel will patch up for you if you have an unaligned integer access, if the CPU traps, but for FP accesses you must generate the correct unaligned-friendly instruction to avoid the trap.

NI myself to try changing this and if nothing comes up after a few months we can start changing const Value& arguments to Value.

Flags: needinfo?(jdemooij)

Some Clang versions had bugs when passing types that use alignas as argument
to a function, so our static analysis currently doesn't allow this. This meant
that JS::Value had to be passed as const-ref (const Value&) instead.

JS::Value has a uint64_t field and this ensures the alignment will be 8 on most
platforms also without the alignas. The main exception is 32-bit x86 where Value
can now be 4-byte aligned in C++ code.

This patch fixes two places to avoid static_assert failures in the JIT backend on x86.

Assignee: nobody → jdemooij
Status: NEW → ASSIGNED

This just converts a few places for now.

Flags: needinfo?(jdemooij)
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 141 Branch

Also delete the part about JSVAL_* operations because these were removed a long
time ago (bug 952650 for example).

Blocks: 1972305

A patch has been attached on this bug, which was already closed. Filing a separate bug will ensure better tracking. If this was not by mistake and further action is needed, please alert the appropriate party. (Or: if the patch doesn't change behavior -- e.g. landing a test case, or fixing a typo -- then feel free to disregard this message)

QA Whiteboard: [qa-triage-done-c142/b141]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: