Export js::jit::AtomicOperations from the engine
Categories
(Core :: JavaScript Engine, defect, P3)
Tracking
()
People
(Reporter: lth, Unassigned)
References
(Blocks 1 open bug)
Details
Reporter | ||
Comment 1•9 years ago
|
||
Reporter | ||
Comment 2•9 years ago
|
||
Reporter | ||
Updated•8 years ago
|
Reporter | ||
Updated•7 years ago
|
Comment 4•6 years ago
|
||
Reporter | ||
Updated•6 years ago
|
Reporter | ||
Comment 5•6 years ago
|
||
Safe-for-races functions are now available in the JIT (landed with bug 1394420). We now need to:
- export them from the engine
- use them in the DOM when appropriate
The "when appropriate" bit is important. The safe-for-races functions are generally slower than raw libc functions, this is especially true for memcpy / memmove. Performance-sensitive code that works on shared memory may wish to special-case the unshared path for this reason.
Comment 6•6 years ago
|
||
Are these functions also defined in the relevant specifications so DOM specifications can chose which to use?
Reporter | ||
Comment 7•6 years ago
|
||
What "relevant specifications"? (These are in any case strictly internal, they provide compatibility between C++ code and jitted code and they avoid undefined behavior in C++ operations on shared memory.)
Comment 8•6 years ago
|
||
Also, do I interpret your comments elsewhere correctly that this does not necessarily block bug 1477743, but would be good to fix quickly nonetheless? What kind of thing should we not do before this is fixed?
Reporter | ||
Comment 9•6 years ago
|
||
With PGO there's a minor risk that the C++ compiler will recognize that DOM code triggers undefined behavior if it operates on shared memory and then "optimizes" code accordingly. I don't think this is a big risk but it's hard to know for sure. There's a slightly larger risk that we'll run into TSAN error reports since TSAN, too, looks for UB resulting from races. If SAB is enabled by default then presumably any TSAN runs we do will be run with SAB enabled, and if DOM uses straight C++ to access memory racily then TSAN may complain.
I don't think this should block re-enabling SAB but it's something we need to address. The JS engine is, or will shortly be, clean wrt to this issue, so it's just DOM.
Comment 10•6 years ago
|
||
Is there any chance of identifying C++11/C11 atomic operations that are equivalent to loadSafeWhenRacy() and storeSafeWhenRacy()? Since Rust atomics have C11 atomic semantics, documenting racy-but-safe SAB access in terms of C++11/C11 atomics would enable efficient access from C++ and Rust without having to go through function pointers on a per-byte basis.
Reporter | ||
Comment 11•6 years ago
|
||
(In reply to Henri Sivonen (:hsivonen) from comment #10)
Is there any chance of identifying C++11/C11 atomic operations that are equivalent to loadSafeWhenRacy() and storeSafeWhenRacy()?
No. We had this initially and this is how the "portable" fallback layer for tier-3 platforms works, but from all the reading I've done this steps into UB pretty quickly because the C++ atomics assume race-free programs. Also, since they assume race-free programs the C++ compiler optimizes them in various ways, omitting fences when DRF lets that be assumed etc, the gcc docs are explicit about that. This would violate the JS/wasm memory model; that memory model allows for optimization of atomics, but probably with different semantics than C++.
(The portable layer is in jit/shared/AtomicOperations-feeling-lucky-{gcc,msvc}.{h,cpp}.)
Since Rust atomics have C11 atomic semantics, documenting racy-but-safe SAB access in terms of C++11/C11 atomics would enable efficient access from C++ and Rust without having to go through function pointers on a per-byte basis.
Yes it would, but I don't think this works.
Updated•2 years ago
|
Description
•