WebAssembly: Implement tier up
authorkeith_miller@apple.com <keith_miller@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Apr 2017 23:55:05 +0000 (23:55 +0000)
committerkeith_miller@apple.com <keith_miller@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Apr 2017 23:55:05 +0000 (23:55 +0000)
commit5fe2e7018d6ba43b226781f45486db0e8d6498eb
treed7f32ce35ef4da5a0b7999057f994c0e054ad66c
parentc782a4773f5d84b4a0db14cb5c0ebcacda629960
WebAssembly: Implement tier up
https://bugs.webkit.org/show_bug.cgi?id=170134

Reviewed by Filip Pizlo.

JSTests:

* wasm/function-tests/trap-after-cross-instance-call.js:
* wasm/tier-up/js-to-wasm.js: Added.
(async.test):
* wasm/tier-up/wasm-to-wasm.js: Added.
(async.test):

Source/JavaScriptCore:

This patch implements tier up for wasm functions. Unlike with JS
code, wasm code needs to be able to tier up concurrently with the
running code.  Since JS code is synchronous we can always link on
the running thread, wasm, however, can run the same code on more
than one thread. In order to make patching work correctly, we need
to ensure that all patches of callsites are aligned. On ARM we get
this for free since every call is a near call. On X86 we ensure
that the 32-bit relative offset is 32-bit aligned.

This patch also modifies how Wasm::Plan works. Now Plan is a
abstract super class and there are two subclasses, which
correspond to the different tiers of our wasm engine.  The first,
Build Bytecode Quickly (BBQ) tier, roughly does what the old plan
code did before.  The new tier, Optimized Machine code Generation
(OMG), can be called at any point by BBQ code and compiles exactly
one function. Once an OMGPlan finishes it will link it's code
internally then reset the instruction cache of all running wasm
threads, via, a ThreadMessage. Once the instruction caches have
been reset all the other functions will be patched to call the new
code.

* JavaScriptCore.xcodeproj/project.pbxproj:
* assembler/AbstractMacroAssembler.h:
(JSC::AbstractMacroAssembler::ensureCacheLineSpace):
* assembler/CodeLocation.h:
(JSC::CodeLocationThreadSafeNearCall::CodeLocationThreadSafeNearCall):
* assembler/MacroAssemblerARM64.h:
(JSC::MacroAssemblerARM64::threadSafePatchableNearCall):
* assembler/MacroAssemblerX86Common.h:
(JSC::MacroAssemblerX86Common::threadSafeNearCall):
* assembler/MacroAssemblerX86_64.h:
(JSC::MacroAssemblerX86_64::threadSafePatchableNearCall):
* b3/air/AirEmitShuffle.cpp:
(JSC::B3::Air::ShufflePair::inst):
(JSC::B3::Air::ShufflePair::opcode): Deleted.
* b3/air/AirEmitShuffle.h:
* jsc.cpp:
(functionTestWasmModuleFunctions):
* runtime/JSLock.cpp:
(JSC::JSLock::didAcquireLock):
* runtime/Options.h:
* wasm/WasmB3IRGenerator.cpp:
(JSC::Wasm::B3IRGenerator::materializeWasmContext):
(JSC::Wasm::B3IRGenerator::B3IRGenerator):
(JSC::Wasm::B3IRGenerator::constant):
(JSC::Wasm::B3IRGenerator::emitTierUpCheck):
(JSC::Wasm::B3IRGenerator::addLoop):
(JSC::Wasm::B3IRGenerator::addTopLevel):
(JSC::Wasm::B3IRGenerator::addBlock):
(JSC::Wasm::createJSToWasmWrapper):
(JSC::Wasm::parseAndCompile):
* wasm/WasmB3IRGenerator.h:
* wasm/WasmBBQPlan.cpp: Copied from Source/JavaScriptCore/wasm/WasmPlan.cpp.
(JSC::Wasm::BBQPlan::BBQPlan):
(JSC::Wasm::BBQPlan::stateString):
(JSC::Wasm::BBQPlan::moveToState):
(JSC::Wasm::BBQPlan::parseAndValidateModule):
(JSC::Wasm::BBQPlan::prepare):
(JSC::Wasm::BBQPlan::ThreadCountHolder::ThreadCountHolder):
(JSC::Wasm::BBQPlan::ThreadCountHolder::~ThreadCountHolder):
(JSC::Wasm::BBQPlan::compileFunctions):
(JSC::Wasm::BBQPlan::complete):
(JSC::Wasm::BBQPlan::work):
* wasm/WasmBBQPlan.h: Copied from Source/JavaScriptCore/wasm/WasmPlan.h.
* wasm/WasmBBQPlanInlines.h: Copied from Source/JavaScriptCore/wasm/WasmPlanInlines.h.
(JSC::Wasm::BBQPlan::initializeCallees):
* wasm/WasmBinding.cpp:
(JSC::Wasm::wasmToWasm):
* wasm/WasmCallee.h:
(JSC::Wasm::Callee::entrypoint):
* wasm/WasmCodeBlock.cpp:
(JSC::Wasm::CodeBlock::CodeBlock):
* wasm/WasmCodeBlock.h:
(JSC::Wasm::CodeBlock::jsEntrypointCalleeFromFunctionIndexSpace):
(JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace):
(JSC::Wasm::CodeBlock::wasmEntrypointLoadLocationFromFunctionIndexSpace):
(JSC::Wasm::CodeBlock::tierUpCount):
(JSC::Wasm::CodeBlock::mode):
* wasm/WasmFormat.h:
(JSC::Wasm::CallableFunction::CallableFunction):
(JSC::Wasm::CallableFunction::offsetOfWasmEntrypointLoadLocation):
* wasm/WasmMachineThreads.cpp: Copied from Source/JavaScriptCore/wasm/WasmPlanInlines.h.
(JSC::Wasm::wasmThreads):
(JSC::Wasm::startTrackingCurrentThread):
(JSC::Wasm::resetInstructionCacheOnAllThreads):
* wasm/WasmMachineThreads.h: Copied from Source/JavaScriptCore/wasm/WasmCallee.h.
* wasm/WasmModule.cpp:
(JSC::Wasm::makeValidationResult):
(JSC::Wasm::makeValidationCallback):
(JSC::Wasm::Module::validateSync):
(JSC::Wasm::Module::validateAsync):
* wasm/WasmModule.h:
(JSC::Wasm::Module::codeBlockFor):
* wasm/WasmOMGPlan.cpp: Added.
(JSC::Wasm::OMGPlan::OMGPlan):
(JSC::Wasm::OMGPlan::work):
(JSC::Wasm::runOMGPlanForIndex):
* wasm/WasmOMGPlan.h: Copied from Source/JavaScriptCore/wasm/WasmPlanInlines.h.
* wasm/WasmPlan.cpp:
(JSC::Wasm::Plan::Plan):
(JSC::Wasm::Plan::runCompletionTasks):
(JSC::Wasm::Plan::addCompletionTask):
(JSC::Wasm::Plan::waitForCompletion):
(JSC::Wasm::Plan::tryRemoveVMAndCancelIfLast):
(JSC::Wasm::Plan::fail):
(JSC::Wasm::Plan::stateString): Deleted.
(JSC::Wasm::Plan::moveToState): Deleted.
(JSC::Wasm::Plan::parseAndValidateModule): Deleted.
(JSC::Wasm::Plan::prepare): Deleted.
(JSC::Wasm::Plan::ThreadCountHolder::ThreadCountHolder): Deleted.
(JSC::Wasm::Plan::ThreadCountHolder::~ThreadCountHolder): Deleted.
(JSC::Wasm::Plan::compileFunctions): Deleted.
(JSC::Wasm::Plan::complete): Deleted.
* wasm/WasmPlan.h:
(JSC::Wasm::Plan::exports): Deleted.
(JSC::Wasm::Plan::internalFunctionCount): Deleted.
(JSC::Wasm::Plan::takeModuleInformation): Deleted.
(JSC::Wasm::Plan::takeCallLinkInfos): Deleted.
(JSC::Wasm::Plan::takeWasmToWasmExitStubs): Deleted.
(JSC::Wasm::Plan::hasWork): Deleted.
(JSC::Wasm::Plan::hasBeenPrepared): Deleted.
* wasm/WasmTierUpCount.h: Renamed from Source/JavaScriptCore/wasm/WasmPlanInlines.h.
(JSC::Wasm::TierUpCount::TierUpCount):
(JSC::Wasm::TierUpCount::loopDecrement):
(JSC::Wasm::TierUpCount::functionEntryDecrement):
(JSC::Wasm::TierUpCount::shouldStartTierUp):
(JSC::Wasm::TierUpCount::count):
* wasm/WasmWorklist.cpp:
* wasm/WasmWorklist.h:
(JSC::Wasm::Worklist::nextTicket):
* wasm/js/JSWebAssemblyCodeBlock.cpp:
* wasm/js/JSWebAssemblyCodeBlock.h:
(JSC::JSWebAssemblyCodeBlock::wasmEntrypointLoadLocationFromFunctionIndexSpace):
(JSC::JSWebAssemblyCodeBlock::wasmToJsCallStubForImport):
(JSC::JSWebAssemblyCodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): Deleted.
* wasm/js/JSWebAssemblyTable.cpp:
(JSC::JSWebAssemblyTable::setFunction):
* wasm/js/WebAssemblyFunction.cpp:
(JSC::WebAssemblyFunction::create):
(JSC::WebAssemblyFunction::WebAssemblyFunction):
* wasm/js/WebAssemblyFunction.h:
(JSC::WebAssemblyFunction::signatureIndex):
(JSC::WebAssemblyFunction::wasmEntrypointLoadLocation):
(JSC::WebAssemblyFunction::callableFunction):
(JSC::WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation):
(JSC::WebAssemblyFunction::wasmEntrypoint): Deleted.
(JSC::WebAssemblyFunction::offsetOfWasmEntrypoint): Deleted.
* wasm/js/WebAssemblyModuleRecord.cpp:
(JSC::WebAssemblyModuleRecord::link):
(JSC::WebAssemblyModuleRecord::evaluate):
* wasm/js/WebAssemblyPrototype.cpp:
(JSC::webAssemblyValidateFunc):
* wasm/js/WebAssemblyWrapperFunction.cpp:
(JSC::WebAssemblyWrapperFunction::WebAssemblyWrapperFunction):
(JSC::WebAssemblyWrapperFunction::create):
* wasm/js/WebAssemblyWrapperFunction.h:
(JSC::WebAssemblyWrapperFunction::signatureIndex):
(JSC::WebAssemblyWrapperFunction::wasmEntrypointLoadLocation):
(JSC::WebAssemblyWrapperFunction::callableFunction):
(JSC::WebAssemblyWrapperFunction::wasmEntrypoint): Deleted.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@215843 268f45cc-cd09-0410-ab3c-d52691b4dbfc
44 files changed:
JSTests/ChangeLog
JSTests/wasm/function-tests/trap-after-cross-instance-call.js
JSTests/wasm/tier-up/js-to-wasm.js [new file with mode: 0644]
JSTests/wasm/tier-up/wasm-to-wasm.js [new file with mode: 0644]
Source/JavaScriptCore/CMakeLists.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/assembler/MacroAssemblerARM64.h
Source/JavaScriptCore/assembler/MacroAssemblerX86_64.h
Source/JavaScriptCore/b3/air/AirEmitShuffle.cpp
Source/JavaScriptCore/b3/air/AirEmitShuffle.h
Source/JavaScriptCore/jsc.cpp
Source/JavaScriptCore/runtime/JSLock.cpp
Source/JavaScriptCore/runtime/Options.h
Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp
Source/JavaScriptCore/wasm/WasmB3IRGenerator.h
Source/JavaScriptCore/wasm/WasmBBQPlan.cpp [new file with mode: 0644]
Source/JavaScriptCore/wasm/WasmBBQPlan.h [new file with mode: 0644]
Source/JavaScriptCore/wasm/WasmBBQPlanInlines.h [moved from Source/JavaScriptCore/wasm/WasmPlanInlines.h with 96% similarity]
Source/JavaScriptCore/wasm/WasmBinding.cpp
Source/JavaScriptCore/wasm/WasmCallee.h
Source/JavaScriptCore/wasm/WasmCodeBlock.cpp
Source/JavaScriptCore/wasm/WasmCodeBlock.h
Source/JavaScriptCore/wasm/WasmFormat.h
Source/JavaScriptCore/wasm/WasmMachineThreads.cpp [new file with mode: 0644]
Source/JavaScriptCore/wasm/WasmMachineThreads.h [new file with mode: 0644]
Source/JavaScriptCore/wasm/WasmModule.cpp
Source/JavaScriptCore/wasm/WasmModule.h
Source/JavaScriptCore/wasm/WasmOMGPlan.cpp [new file with mode: 0644]
Source/JavaScriptCore/wasm/WasmOMGPlan.h [new file with mode: 0644]
Source/JavaScriptCore/wasm/WasmPlan.cpp
Source/JavaScriptCore/wasm/WasmPlan.h
Source/JavaScriptCore/wasm/WasmTierUpCount.h [new file with mode: 0644]
Source/JavaScriptCore/wasm/WasmWorklist.cpp
Source/JavaScriptCore/wasm/WasmWorklist.h
Source/JavaScriptCore/wasm/js/JSWebAssemblyCodeBlock.cpp
Source/JavaScriptCore/wasm/js/JSWebAssemblyCodeBlock.h
Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyFunction.h
Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyWrapperFunction.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyWrapperFunction.h