Ignore:
Timestamp:
Mar 24, 2017, 4:25:16 PM (8 years ago)
Author:
[email protected]
Message:

WebAssembly: store state in TLS instead of on VM
https://bugs.webkit.org/show_bug.cgi?id=169611

Reviewed by Filip Pizlo.

Source/JavaScriptCore:

Using thread-local storage instead of VM makes code more position
independent. We used to store the WebAssembly top Instance (the
latest one in the call stack) on VM, now we instead store it in
TLS. This top Instance is used to access a bunch of state such as
Memory location, size, table (for call_indirect), etc.

Instead of calling it "top", which is confusing, we now just call
it WasmContext.

Making the code PIC means future patches will be able to
postMessage and structured clone into IDB without having to
recompile the code. This wasn't possible before because we
hard-coded the address of VM at compilation time. That doesn't
work between workers, and doesn't work across reloads (which IDB
is intended to do).

It'll also potentially make code faster once we start tuning
what's in TLS, what's in which of the 4 free slots, and what's in
pinned registers. I'm leaving this tuning for later because
there's lower lying fruit for us to pick.

  • CMakeLists.txt:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • assembler/AbstractMacroAssembler.h:
  • assembler/AllowMacroScratchRegisterUsageIf.h: Copied from assembler/AllowMacroScratchRegisterUsage.h.

(JSC::AllowMacroScratchRegisterUsageIf::AllowMacroScratchRegisterUsageIf):
(JSC::AllowMacroScratchRegisterUsageIf::~AllowMacroScratchRegisterUsageIf):

  • assembler/MacroAssembler.h:

(JSC::MacroAssembler::storeToTLSPtr): we previously didn't have
the code required to store to TLS, only to load

  • assembler/MacroAssemblerARM64.h:

(JSC::MacroAssemblerARM64::loadFromTLSPtrNeedsMacroScratchRegister):
(JSC::MacroAssemblerARM64::storeToTLS32):
(JSC::MacroAssemblerARM64::storeToTLS64):
(JSC::MacroAssemblerARM64::storeToTLSPtrNeedsMacroScratchRegister):

  • assembler/MacroAssemblerX86Common.h:

(JSC::MacroAssemblerX86Common::loadFromTLSPtrNeedsMacroScratchRegister):
(JSC::MacroAssemblerX86Common::storeToTLS32):
(JSC::MacroAssemblerX86Common::storeToTLSPtrNeedsMacroScratchRegister):

  • assembler/MacroAssemblerX86_64.h:

(JSC::MacroAssemblerX86_64::loadFromTLS64): was loading 32-bit instead of 64-bit
(JSC::MacroAssemblerX86_64::storeToTLS64):

  • assembler/X86Assembler.h:

(JSC::X86Assembler::movl_rm):
(JSC::X86Assembler::movq_rm):

  • b3/testb3.cpp:

(JSC::B3::testFastTLSLoad):
(JSC::B3::testFastTLSStore):
(JSC::B3::run):

  • jit/AssemblyHelpers.h:

(JSC::AssemblyHelpers::loadWasmContext):
(JSC::AssemblyHelpers::storeWasmContext):
(JSC::AssemblyHelpers::loadWasmContextNeedsMacroScratchRegister):
(JSC::AssemblyHelpers::storeWasmContextNeedsMacroScratchRegister):

  • jit/Repatch.cpp:

(JSC::webAssemblyOwner):

  • jit/ThunkGenerators.cpp:

(JSC::throwExceptionFromWasmThunkGenerator):

  • runtime/Options.h:
  • runtime/VM.cpp:

(JSC::VM::VM):

  • runtime/VM.h:
  • wasm/WasmB3IRGenerator.cpp:

(JSC::Wasm::loadWasmContext):
(JSC::Wasm::storeWasmContext):
(JSC::Wasm::B3IRGenerator::B3IRGenerator):
(JSC::Wasm::getMemoryBaseAndSize):
(JSC::Wasm::restoreWebAssemblyGlobalState):
(JSC::Wasm::createJSToWasmWrapper):
(JSC::Wasm::parseAndCompile):

  • wasm/WasmBinding.cpp:

(JSC::Wasm::materializeImportJSCell):
(JSC::Wasm::wasmToJs):
(JSC::Wasm::wasmToWasm):

  • wasm/WasmContext.cpp: Added.

(JSC::loadWasmContext):
(JSC::storeWasmContext):

  • wasm/WasmContext.h: Added. Replaces "top" JSWebAssemblyInstance.
  • wasm/js/WebAssemblyFunction.cpp:

(JSC::callWebAssemblyFunction):

  • wasm/js/WebAssemblyInstanceConstructor.h:

Source/WTF:

  • wtf/FastTLS.h: reserve one key for WebAssembly, delete a bunch

of dead code which clang couldn't compile (it's valid GCC assembly
which LLVM dislikes).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/assembler/MacroAssemblerARM64.h

    r213753 r214384  
    36013601#if ENABLE(FAST_TLS_JIT)
    36023602    // This will use scratch registers if the offset is not legal.
    3603    
     3603
    36043604    void loadFromTLS32(uint32_t offset, RegisterID dst)
    36053605    {
     
    36143614        and64(TrustedImm32(~7), dst);
    36153615        load64(Address(dst, offset), dst);
     3616    }
     3617
     3618    static bool loadFromTLSPtrNeedsMacroScratchRegister()
     3619    {
     3620        return true;
     3621    }
     3622
     3623    void storeToTLS32(RegisterID src, uint32_t offset)
     3624    {
     3625        RegisterID tmp = getCachedDataTempRegisterIDAndInvalidate();
     3626        ASSERT(src != tmp);
     3627        m_assembler.mrs_TPIDRRO_EL0(tmp);
     3628        and64(TrustedImm32(~7), tmp);
     3629        store32(src, Address(tmp, offset));
     3630    }
     3631   
     3632    void storeToTLS64(RegisterID src, uint32_t offset)
     3633    {
     3634        RegisterID tmp = getCachedDataTempRegisterIDAndInvalidate();
     3635        ASSERT(src != tmp);
     3636        m_assembler.mrs_TPIDRRO_EL0(tmp);
     3637        and64(TrustedImm32(~7), tmp);
     3638        store64(src, Address(tmp, offset));
     3639    }
     3640
     3641    static bool storeToTLSPtrNeedsMacroScratchRegister()
     3642    {
     3643        return true;
    36163644    }
    36173645#endif // ENABLE(FAST_TLS_JIT)
Note: See TracChangeset for help on using the changeset viewer.