Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
WebAssembly: handle and optimize wasm export → wasm import calls
https://bugs.webkit.org/show_bug.cgi?id=165282 Reviewed by Saam Barati. JSTests: * wasm/Builder.js: Add a Proxy to Builder.js, which intercepts unknown property lookups. This creates way better error messages on typos than 'undefined is not a function', which happens semi-frequently as I typo opcode names (and which one is a typo is hard to find because we chain builders). (const._isValidValue): (get target): (const._importFunctionContinuation): (const._importMemoryContinuation): (const._importTableContinuation): (const._exportFunctionContinuation): (export.default.Builder.prototype._registerSectionBuilders.const.section.in.WASM.description.section.switch.section.case.string_appeared_here.this.section): (export.default.Builder.prototype._registerSectionBuilders.this.Unknown): * wasm/LowLevelBinary.js: Add limited support for var{u}int64 (only the 32-bit values) (export.default.LowLevelBinary.prototype.varint32): (export.default.LowLevelBinary.prototype.varuint64): (export.default.LowLevelBinary.prototype.varint64): * wasm/function-tests/exceptions.js: update error message * wasm/function-tests/trap-load.js: update error message * wasm/function-tests/trap-store.js: update error message * wasm/js-api/wasm-to-wasm-bad-signature.js: Added. Test a bunch of bad wasm->wasm import signatures (const.makeImportee.signature.switch): (BadSignatureDropStartParams): * wasm/js-api/wasm-to-wasm.js: Added. Test 64-bit wasm->wasm import calls (const.callerModule): (const.calleeModule): (WasmToWasm): Source/JavaScriptCore: - Add a new JSType for WebAssemblyFunction, and use it when creating its structure. This will is used to quickly detect from wasm whether the import call is to another wasm module, or whether it's to JS. - Generate two stubs from the import stub generator: one for wasm->JS and one for wasm -> wasm. This is done at Module time. Which is called will only be known at Instance time, once we've received the import object. We want to avoid codegen at Instance time, so having both around is great. - Restore the WebAssembly global state (VM top Instance, and pinned registers) after call / call_indirect, and in the JS->wasm entry stub. - Pinned registers are now a global thing, not per-Memory, because the wasm -> wasm stubs are generated at Module time where we don't really have enough information to do the right thing (doing so would generate too much code). * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * runtime/JSType.h: add WebAssemblyFunctionType as a JSType * wasm/WasmB3IRGenerator.cpp: significantly rework how calls which could be external work, and how we save / restore global state: VM's top Instance, and pinned registers (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::getMemoryBaseAndSize): (JSC::Wasm::restoreWebAssemblyGlobalState): (JSC::Wasm::createJSToWasmWrapper): (JSC::Wasm::parseAndCompile): * wasm/WasmB3IRGenerator.h: * wasm/WasmBinding.cpp: (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToWasm): the main goal of this patch was adding this function (JSC::Wasm::exitStubGenerator): * wasm/WasmBinding.h: * wasm/WasmFormat.h: Get rid of much of the function index space: we already have all of its information elsewhere, and as-is it provides no extra efficiency. (JSC::Wasm::ModuleInformation::functionIndexSpaceSize): (JSC::Wasm::ModuleInformation::isImportedFunctionFromFunctionIndexSpace): (JSC::Wasm::ModuleInformation::signatureIndexFromFunctionIndexSpace): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::FunctionParser): * wasm/WasmMemory.cpp: Add some logging. (JSC::Wasm::Memory::dump): this was nice when debugging (JSC::Wasm::Memory::makeString): (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::~Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: don't use extra indirection, it wasn't needed. Reorder some of the fields which are looked up at runtime so they're more cache-friendly. (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::mode): (JSC::Wasm::Memory::offsetOfSize): * wasm/WasmMemoryInformation.cpp: Pinned registers are now a global thing for all of JSC, not a per-Memory thing anymore. wasm->wasm calls are more complex otherwise: they have to figure out how to bridge between the caller and callee's special-snowflake pinning. (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): (JSC::Wasm::MemoryInformation::MemoryInformation): * wasm/WasmMemoryInformation.h: * wasm/WasmModuleParser.cpp: * wasm/WasmModuleParser.h: * wasm/WasmPageCount.cpp: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. (JSC::Wasm::PageCount::dump): nice for debugging * wasm/WasmPageCount.h: * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::parseAndValidateModule): (JSC::Wasm::Plan::run): * wasm/WasmPlan.h: (JSC::Wasm::Plan::takeWasmExitStubs): * wasm/WasmSignature.cpp: (JSC::Wasm::Signature::toString): (JSC::Wasm::Signature::dump): * wasm/WasmSignature.h: * wasm/WasmValidate.cpp: (JSC::Wasm::validateFunction): * wasm/WasmValidate.h: * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::offsetOfTable): (JSC::JSWebAssemblyInstance::offsetOfImportFunctions): (JSC::JSWebAssemblyInstance::offsetOfImportFunction): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::create): (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::buffer): (JSC::JSWebAssemblyMemory::grow): * wasm/js/JSWebAssemblyMemory.h: (JSC::JSWebAssemblyMemory::memory): (JSC::JSWebAssemblyMemory::offsetOfMemory): (JSC::JSWebAssemblyMemory::offsetOfSize): * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::create): (JSC::JSWebAssemblyModule::JSWebAssemblyModule): * wasm/js/JSWebAssemblyModule.h: (JSC::JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace): (JSC::JSWebAssemblyModule::functionImportCount): * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): (JSC::WebAssemblyFunction::create): (JSC::WebAssemblyFunction::createStructure): (JSC::WebAssemblyFunction::WebAssemblyFunction): (JSC::WebAssemblyFunction::finishCreation): * wasm/js/WebAssemblyFunction.h: (JSC::WebAssemblyFunction::wasmEntrypoint): (JSC::WebAssemblyFunction::offsetOfInstance): (JSC::WebAssemblyFunction::offsetOfWasmEntryPointCode): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): always start with a dummy memory, so wasm->wasm calls don't need to null-check * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::WebAssemblyModuleConstructor::createModule): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyModuleRecord.h: Canonical link: https://commits.webkit.org/183789@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@210229 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
with
927 additions
and 298 deletions.
- +35 −0 JSTests/ChangeLog
- +51 −40 JSTests/wasm/Builder.js
- +12 −0 JSTests/wasm/LowLevelBinary.js
- +3 −3 JSTests/wasm/function-tests/exceptions.js
- +1 −1 JSTests/wasm/function-tests/trap-load.js
- +1 −1 JSTests/wasm/function-tests/trap-store.js
- +105 −0 JSTests/wasm/js-api/wasm-to-wasm-bad-signature.js
- +72 −0 JSTests/wasm/js-api/wasm-to-wasm.js
- +1 −0 Source/JavaScriptCore/CMakeLists.txt
- +125 −0 Source/JavaScriptCore/ChangeLog
- +6 −2 Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
- +0 −1 Source/JavaScriptCore/jsc.cpp
- +2 −0 Source/JavaScriptCore/runtime/JSType.h
- +136 −86 Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp
- +1 −1 Source/JavaScriptCore/wasm/WasmB3IRGenerator.h
- +61 −6 Source/JavaScriptCore/wasm/WasmBinding.cpp
- +1 −1 Source/JavaScriptCore/wasm/WasmBinding.h
- +20 −8 Source/JavaScriptCore/wasm/WasmFormat.h
- +8 −8 Source/JavaScriptCore/wasm/WasmFunctionParser.h
- +54 −3 Source/JavaScriptCore/wasm/WasmMemory.cpp
- +21 −10 Source/JavaScriptCore/wasm/WasmMemory.h
- +42 −17 Source/JavaScriptCore/wasm/WasmMemoryInformation.cpp
- +3 −6 Source/JavaScriptCore/wasm/WasmMemoryInformation.h
- +11 −16 Source/JavaScriptCore/wasm/WasmModuleParser.cpp
- +1 −1 Source/JavaScriptCore/wasm/WasmModuleParser.h
- +45 −0 Source/JavaScriptCore/wasm/WasmPageCount.cpp
- +6 −0 Source/JavaScriptCore/wasm/WasmPageCount.h
- +26 −18 Source/JavaScriptCore/wasm/WasmPlan.cpp
- +4 −10 Source/JavaScriptCore/wasm/WasmPlan.h
- +14 −4 Source/JavaScriptCore/wasm/WasmSignature.cpp
- +1 −0 Source/JavaScriptCore/wasm/WasmSignature.h
- +2 −2 Source/JavaScriptCore/wasm/WasmValidate.cpp
- +1 −1 Source/JavaScriptCore/wasm/WasmValidate.h
- +3 −6 Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.h
- +6 −6 Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.cpp
- +6 −5 Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h
- +4 −5 Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.cpp
- +6 −10 Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.h
- +6 −3 Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp
- +6 −2 Source/JavaScriptCore/wasm/js/WebAssemblyFunction.h
- +13 −7 Source/JavaScriptCore/wasm/js/WebAssemblyInstanceConstructor.cpp
- +1 −1 Source/JavaScriptCore/wasm/js/WebAssemblyMemoryConstructor.cpp
- +1 −1 Source/JavaScriptCore/wasm/js/WebAssemblyModuleConstructor.cpp
- +3 −6 Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.