RESOLVED FIXED 212825
Make FAST_JIT_PERMISSIONS check in LinkBuffer::copyCompactAndLinkCode a runtime check
https://bugs.webkit.org/show_bug.cgi?id=212825
Summary Make FAST_JIT_PERMISSIONS check in LinkBuffer::copyCompactAndLinkCode a runti...
Michael Saboff
Reported 2020-06-05 08:37:08 PDT
There are some ARM64 devices that have runtime support for APRR, but the current way we link in copyCompactAndLinkCode() causes us to use a side buffer to link the code before copying the results to the JIT memory. By making the FAST_JIT_PERMISSION paths runtime selected, we can eliminate the allocation of the buffer and the subsequent copying out of the buffer. This is a follow to https://bugs.webkit.org/show_bug.cgi?id=212765.
Attachments
Patch (7.99 KB, patch)
2020-06-05 08:54 PDT, Michael Saboff
no flags
Patch with speculative build fixes (8.03 KB, patch)
2020-06-05 09:30 PDT, Michael Saboff
no flags
Patch (8.51 KB, patch)
2020-06-05 11:08 PDT, Michael Saboff
no flags
Patch with suggested changes (7.99 KB, patch)
2020-06-05 12:48 PDT, Michael Saboff
saam: review+
Patch for Landing (9.72 KB, patch)
2020-06-05 17:42 PDT, Michael Saboff
no flags
Michael Saboff
Comment 1 2020-06-05 08:39:01 PDT
Michael Saboff
Comment 2 2020-06-05 08:54:02 PDT
Michael Saboff
Comment 3 2020-06-05 09:30:05 PDT
Created attachment 401161 [details] Patch with speculative build fixes
Michael Saboff
Comment 4 2020-06-05 11:08:16 PDT
Created attachment 401176 [details] Patch More changes to make the code statically compiled where appropriate. This should fix the ARMv7 build.
Saam Barati
Comment 5 2020-06-05 11:11:38 PDT
Comment on attachment 401176 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=401176&action=review > Source/JavaScriptCore/assembler/LinkBuffer.cpp:282 > + IF_FAST_JIT_PERMISSIONS(os_thread_self_restrict_rwx_to_rw()); why not just use a normal if statement here? Doesn't feel like canonical webkit style. I think if (useFastJITPermissions()) is much easier to parse and read than macros as control flow. > Source/JavaScriptCore/assembler/LinkBuffer.cpp:371 > + IF_FAST_JIT_PERMISSIONS_ELSE(MacroAssembler::link<memcpy>(jumpsToLink[i], outData + jumpsToLink[i].from(), location, target), \ > + MacroAssembler::link<performJITMemcpy>(jumpsToLink[i], outData + jumpsToLink[i].from(), location, target)); same comment
Michael Saboff
Comment 6 2020-06-05 12:48:55 PDT
Created attachment 401188 [details] Patch with suggested changes (In reply to Saam Barati from comment #5) > Comment on attachment 401176 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=401176&action=review > > > Source/JavaScriptCore/assembler/LinkBuffer.cpp:282 > > + IF_FAST_JIT_PERMISSIONS(os_thread_self_restrict_rwx_to_rw()); > > why not just use a normal if statement here? Doesn't feel like canonical > webkit style. > > I think > if (useFastJITPermissions()) > is much easier to parse and read than macros as control flow. > > > Source/JavaScriptCore/assembler/LinkBuffer.cpp:371 > > + IF_FAST_JIT_PERMISSIONS_ELSE(MacroAssembler::link<memcpy>(jumpsToLink[i], outData + jumpsToLink[i].from(), location, target), \ > > + MacroAssembler::link<performJITMemcpy>(jumpsToLink[i], outData + jumpsToLink[i].from(), location, target)); > > same comment Here's a patch with the suggested changes.
Sam Weinig
Comment 7 2020-06-05 14:24:19 PDT
Comment on attachment 401188 [details] Patch with suggested changes View in context: https://bugs.webkit.org/attachment.cgi?id=401188&action=review > Source/JavaScriptCore/assembler/LinkBuffer.cpp:137 > +ALWAYS_INLINE bool useFastJITPermissions() > +{ > +#if ENABLE(FAST_JIT_PERMISSIONS) && !ENABLE(SEPARATED_WX_HEAP) > + return true; > +#elif ENABLE(FAST_JIT_PERMISSIONS) > + return g_jscConfig.useFastPermisionsJITCopy; > +#else > + return false; > +#endif > +} If you moved this to ExecutableAllocator.h, you could use useFastJITPermissions() to slightly simplify performJITMemcpy as well (remove one #if/endif ENABLE(SEPARATED_WX_HEAP)). > Source/JavaScriptCore/assembler/LinkBuffer.cpp:268 > + os_thread_self_restrict_rwx_to_rw(); Is this still in an #ifdef that is Darwin specific? Or are we just getting away with this because we only build branch compaction on Darwin systems?
Saam Barati
Comment 8 2020-06-05 14:30:23 PDT
Comment on attachment 401188 [details] Patch with suggested changes View in context: https://bugs.webkit.org/attachment.cgi?id=401188&action=review r=me > Source/JavaScriptCore/ChangeLog:8 > + Made the FAST_JIT_PERMISSIONS code to be runtime conditional. "code to be" => maybe something a bit more specific: "code when linking to be" > Source/JavaScriptCore/ChangeLog:16 > + Broke out the "verify hash" conditionally compiled code with a file local > + ENABLE_VERIFY_JIT_HASH macro for readability. this is nicer > Source/JavaScriptCore/assembler/LinkBuffer.cpp:250 > +#if ENABLE(VERIFY_JIT_HASH) can we assert that useFastJITPermissions() is true alternatively, just return true from that function #if ENABLE(VERIFY_JIT_HASH)
Saam Barati
Comment 9 2020-06-05 14:31:02 PDT
Comment on attachment 401188 [details] Patch with suggested changes View in context: https://bugs.webkit.org/attachment.cgi?id=401188&action=review >> Source/JavaScriptCore/ChangeLog:8 >> + Made the FAST_JIT_PERMISSIONS code to be runtime conditional. > > "code to be" => maybe something a bit more specific: "code when linking to be" or maybe even more specific, say something about the side buffer vs malloc buffer.
Michael Saboff
Comment 10 2020-06-05 15:39:00 PDT
(In reply to Sam Weinig from comment #7) > Comment on attachment 401188 [details] > Patch with suggested changes > > View in context: > https://bugs.webkit.org/attachment.cgi?id=401188&action=review > > > Source/JavaScriptCore/assembler/LinkBuffer.cpp:137 > > +ALWAYS_INLINE bool useFastJITPermissions() > > +{ > > +#if ENABLE(FAST_JIT_PERMISSIONS) && !ENABLE(SEPARATED_WX_HEAP) > > + return true; > > +#elif ENABLE(FAST_JIT_PERMISSIONS) > > + return g_jscConfig.useFastPermisionsJITCopy; > > +#else > > + return false; > > +#endif > > +} > > If you moved this to ExecutableAllocator.h, you could use > useFastJITPermissions() to slightly simplify performJITMemcpy as well > (remove one #if/endif ENABLE(SEPARATED_WX_HEAP)). Let me look into that. > > Source/JavaScriptCore/assembler/LinkBuffer.cpp:268 > > + os_thread_self_restrict_rwx_to_rw(); > > Is this still in an #ifdef that is Darwin specific? Or are we just getting > away with this because we only build branch compaction on Darwin systems? Yes it is. I posted this patch to see if ALWAYS_LINE could get the other compilers / SDKs to work, but it wasn't successful.
Saam Barati
Comment 11 2020-06-05 15:58:24 PDT
r=me still with old Macro control flow version, after talking with Michael, compiling in the control flow is leading to build annoyance
Michael Saboff
Comment 12 2020-06-05 17:42:49 PDT
Created attachment 401220 [details] Patch for Landing > > Source/JavaScriptCore/assembler/LinkBuffer.cpp:137 > > +ALWAYS_INLINE bool useFastJITPermissions() > > +{ > > +#if ENABLE(FAST_JIT_PERMISSIONS) && !ENABLE(SEPARATED_WX_HEAP) > > + return true; > > +#elif ENABLE(FAST_JIT_PERMISSIONS) > > + return g_jscConfig.useFastPermisionsJITCopy; > > +#else > > + return false; > > +#endif > > +} > > If you moved this to ExecutableAllocator.h, you could use > useFastJITPermissions() to slightly simplify performJITMemcpy as well > (remove one #if/endif ENABLE(SEPARATED_WX_HEAP)). Done. > > Source/JavaScriptCore/assembler/LinkBuffer.cpp:250 > > +#if ENABLE(VERIFY_JIT_HASH) > > can we assert that useFastJITPermissions() is true > > alternatively, just return true from that function #if > ENABLE(VERIFY_JIT_HASH) Although these sections of code were part of the same "#if CPU(ARM64E) && ENABLE(FAST_JIT_PERMISSIONS)" sections, this is actually independent of FAST_JIT_PERMISSIONS. You'll see elsewhere (AssemblerBuffer.h ~183) that the assembly hash code is simply #if CPU(ARM64E). I have adjusted the setting of ENABLE_VERIFY_JIT_HASH accordingly.
Michael Saboff
Comment 13 2020-06-05 21:25:06 PDT
Note You need to log in before you can comment on or make changes to this bug.