commit | bf01be2a66d7ab349140a846f33fa0f4835783ef | [log] [tgz] |
---|---|---|
author | tzagallo@apple.com <tzagallo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc> | Thu Oct 31 22:32:52 2019 +0000 |
committer | tzagallo@apple.com <tzagallo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc> | Thu Oct 31 22:32:52 2019 +0000 |
tree | ebbbb65b40797d11cff1b21cd7fc93b0fa4cf3ec | |
parent | b58d805d8a81452374a0e5d3a9e4b504914c66dd [diff] |
[WebAssembly] Create a Wasm interpreter https://bugs.webkit.org/show_bug.cgi?id=194257 <rdar://problem/44186794> Reviewed by Saam Barati. Source/JavaScriptCore: Add an interpreter tier to WebAssembly which reuses the LLInt infrastructure. The interpreter currently tiers up straight to OMG and can OSR enter at the prologue and from loops. The initial implementation of the interpreter is very naive, but despite the lack of optimizations it still shows a 2x improvement on the WebAssembly subtests in JetStream2 and 2x improvement on the PSPDFKit benchmark. It reduces "compilation" times by ~3x and it's neutral on throughput. The interpreter follows the same calling conventions as the BBQ/OMG, this means that: - We have to allocate locals for all argument registers and write all arguments registers to the stack in the prologue. - Calls have to allocate space for at least as many arguments as the number of argument registers. Before each call, all argument registers must be loaded from the stack, and after we return from the call, all registers must be stored back to the stack, in case they contain return values. We carefully layout the stack so that the arguments that would already have to be passed in the stack end up in the right place. The stack layout for calls is: [ gprs ][ fprs ][ optional stack arguments ][ callee frame ] ^ sp - The return opcode has to load all registers from the stack, since they might need to contain results of the function. - The calling convention requires that the callee should store itself in the callee slot of the call frame, which is impossible in the interpreter, since the code we execute is the same for all callees. In order to work around that, we generate an entry thunk to the wasm interpreter for each function. All this thunk does is store the callee in the call frame and tail call the interpreter. * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/BytecodeDumper.cpp: (JSC::BytecodeDumper<Block>::constantName const): (JSC::BytecodeDumper<Block>::dumpValue): (JSC::BytecodeDumper<Block>::dumpBytecode): (JSC::CodeBlockBytecodeDumper<Block>::vm const): (JSC::CodeBlockBytecodeDumper<Block>::identifier const): (JSC::CodeBlockBytecodeDumper<Block>::dumpIdentifiers): (JSC::CodeBlockBytecodeDumper<Block>::dumpConstants): (JSC::CodeBlockBytecodeDumper<Block>::dumpExceptionHandlers): (JSC::CodeBlockBytecodeDumper<Block>::dumpSwitchJumpTables): (JSC::CodeBlockBytecodeDumper<Block>::dumpStringSwitchJumpTables): (JSC::CodeBlockBytecodeDumper<Block>::dumpBlock): * bytecode/BytecodeDumper.h: (JSC::BytecodeDumper::dumpValue): (JSC::BytecodeDumper::BytecodeDumper): * bytecode/BytecodeGeneratorification.cpp: (JSC::performGeneratorification): * bytecode/BytecodeList.rb: * bytecode/CodeBlock.cpp: (JSC::CodeBlock::dumpBytecode): * bytecode/Fits.h: * bytecode/Instruction.h: (JSC::BaseInstruction::BaseInstruction): (JSC::BaseInstruction::Impl::opcodeID const): (JSC::BaseInstruction::opcodeID const): (JSC::BaseInstruction::name const): (JSC::BaseInstruction::isWide16 const): (JSC::BaseInstruction::isWide32 const): (JSC::BaseInstruction::hasMetadata const): (JSC::BaseInstruction::sizeShiftAmount const): (JSC::BaseInstruction::size const): (JSC::BaseInstruction::is const): (JSC::BaseInstruction::as const): (JSC::BaseInstruction::cast): (JSC::BaseInstruction::cast const): (JSC::BaseInstruction::wide16 const): (JSC::BaseInstruction::wide32 const): * bytecode/InstructionStream.h: (JSC::InstructionStream::iterator::operator+=): (JSC::InstructionStream::iterator::operator++): (JSC::InstructionStreamWriter::iterator::operator+=): (JSC::InstructionStreamWriter::iterator::operator++): * bytecode/Opcode.cpp: * bytecode/Opcode.h: * bytecode/PreciseJumpTargetsInlines.h: * bytecode/UnlinkedCodeBlock.h: * bytecode/VirtualRegister.cpp: (JSC::VirtualRegister::VirtualRegister): * bytecode/VirtualRegister.h: * bytecompiler/BytecodeGenerator.cpp: (JSC::GenericLabel<JSGeneratorTraits>::setLocation): (JSC::BytecodeGenerator::BytecodeGenerator): * bytecompiler/BytecodeGenerator.h: * bytecompiler/BytecodeGeneratorBase.h: Added. * bytecompiler/BytecodeGeneratorBaseInlines.h: Added. (JSC::shrinkToFit): (JSC::BytecodeGeneratorBase<Traits>::BytecodeGeneratorBase): (JSC::BytecodeGeneratorBase<Traits>::newLabel): (JSC::BytecodeGeneratorBase<Traits>::newEmittedLabel): (JSC::BytecodeGeneratorBase<Traits>::reclaimFreeRegisters): (JSC::BytecodeGeneratorBase<Traits>::emitLabel): (JSC::BytecodeGeneratorBase<Traits>::recordOpcode): (JSC::BytecodeGeneratorBase<Traits>::alignWideOpcode16): (JSC::BytecodeGeneratorBase<Traits>::alignWideOpcode32): (JSC::BytecodeGeneratorBase<Traits>::write): (JSC::BytecodeGeneratorBase<Traits>::newRegister): (JSC::BytecodeGeneratorBase<Traits>::newTemporary): (JSC::BytecodeGeneratorBase<Traits>::addVar): (JSC::BytecodeGeneratorBase<Traits>::allocateCalleeSaveSpace): * bytecompiler/Label.h: (JSC::GenericBoundLabel::GenericBoundLabel): (JSC::GenericBoundLabel::target): (JSC::GenericBoundLabel::saveTarget): (JSC::GenericBoundLabel::commitTarget): * dfg/DFGByteCodeParser.cpp: * dfg/DFGCapabilities.cpp: (JSC::DFG::capabilityLevel): * dfg/DFGOperations.cpp: * generator/Argument.rb: * generator/DSL.rb: * generator/GeneratedFile.rb: * generator/Opcode.rb: * generator/Options.rb: * generator/Section.rb: * generator/Wasm.rb: Added. * interpreter/Register.h: * interpreter/RegisterInlines.h: (JSC::Register::operator=): * jit/JITArithmetic.cpp: * jit/JITOpcodes.cpp: * llint/LLIntData.cpp: (JSC::LLInt::initialize): * llint/LLIntData.h: (JSC::LLInt::wasmExceptionInstructions): * llint/LLIntOfflineAsmConfig.h: * llint/LLIntOffsetsExtractor.cpp: * llint/LLIntSlowPaths.cpp: * llint/LLIntThunks.cpp: (JSC::LLInt::generateThunkWithJumpTo): (JSC::LLInt::wasmFunctionEntryThunk): * llint/LLIntThunks.h: * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * llint/WebAssembly.asm: Added. * offlineasm/arm64.rb: * offlineasm/instructions.rb: * offlineasm/parser.rb: * offlineasm/registers.rb: * offlineasm/transform.rb: * offlineasm/x86.rb: * parser/Nodes.h: * runtime/Error.cpp: (JSC::FindFirstCallerFrameWithCodeblockFunctor::operator() const): * runtime/ErrorInstance.cpp: (JSC::ErrorInstance::finishCreation): * runtime/Options.cpp: (JSC::overrideDefaults): * runtime/OptionsList.h: * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::recordJITFrame): (JSC::FrameWalker::resetAtMachineFrame): * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::isControlTypeIf): (JSC::Wasm::AirIRGenerator::emitLoopTierUpCheck): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::isControlTypeIf): * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::prepareImpl): (JSC::Wasm::BBQPlan::work): (JSC::Wasm::BBQPlan::compileFunction): (JSC::Wasm::BBQPlan::didCompleteCompilation): (JSC::Wasm::BBQPlan::initializeCallees): * wasm/WasmBBQPlan.h: * wasm/WasmBBQPlanInlines.h: Removed. * wasm/WasmCallee.cpp: (JSC::Wasm::Callee::Callee): (JSC::Wasm::Callee::dump const): (JSC::Wasm::JITCallee::JITCallee): (JSC::Wasm::LLIntCallee::setEntrypoint): (JSC::Wasm::LLIntCallee::entrypoint const): (JSC::Wasm::LLIntCallee::calleeSaveRegisters): (JSC::Wasm:: const): * wasm/WasmCallee.h: (JSC::Wasm::Callee::setOSREntryCallee): (JSC::Wasm::JITCallee::wasmToWasmCallsites): (JSC::Wasm::JITCallee:: const): * wasm/WasmCallingConvention.h: * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::CodeBlock): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmBBQCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmToWasmExitStub): * wasm/WasmCompilationMode.cpp: (JSC::Wasm::makeString): * wasm/WasmCompilationMode.h: * wasm/WasmEmbedder.h: * wasm/WasmEntryPlan.cpp: Added. (JSC::Wasm::EntryPlan::EntryPlan): (JSC::Wasm::EntryPlan::stateString): (JSC::Wasm::EntryPlan::moveToState): (JSC::Wasm::EntryPlan::didReceiveFunctionData): (JSC::Wasm::EntryPlan::parseAndValidateModule): (JSC::Wasm::EntryPlan::prepare): (JSC::Wasm::EntryPlan::ThreadCountHolder::ThreadCountHolder): (JSC::Wasm::EntryPlan::ThreadCountHolder::~ThreadCountHolder): (JSC::Wasm::EntryPlan::complete): (JSC::Wasm::EntryPlan::compileFunctions): (JSC::Wasm::EntryPlan::work): * wasm/WasmEntryPlan.h: Copied from Source/JavaScriptCore/wasm/WasmBBQPlan.h. (JSC::Wasm::EntryPlan::parseAndValidateModule): (JSC::Wasm::EntryPlan::exports const): (JSC::Wasm::EntryPlan::internalFunctionCount const): (JSC::Wasm::EntryPlan::takeModuleInformation): (JSC::Wasm::EntryPlan::takeWasmToWasmExitStubs): (JSC::Wasm::EntryPlan::takeWasmToWasmCallsites): (JSC::Wasm::EntryPlan::hasBeenPrepared const): (JSC::Wasm::EntryPlan::tryReserveCapacity): * wasm/WasmFunctionCodeBlock.cpp: Added. (JSC::Wasm::FunctionCodeBlock::setInstructions): (JSC::Wasm::FunctionCodeBlock::dumpBytecode): (JSC::Wasm::FunctionCodeBlock::addOutOfLineJumpTarget): (JSC::Wasm::FunctionCodeBlock::outOfLineJumpOffset): (JSC::Wasm::FunctionCodeBlock::outOfLineJumpTarget): (JSC::Wasm::FunctionCodeBlock::addSignature): (JSC::Wasm::FunctionCodeBlock::signature const): (JSC::Wasm::FunctionCodeBlock::addJumpTable): (JSC::Wasm::FunctionCodeBlock::jumpTable const const): (JSC::Wasm::FunctionCodeBlock::numberOfJumpTables const): * wasm/WasmFunctionCodeBlock.h: Added. (JSC::Wasm::FunctionCodeBlock::FunctionCodeBlock): (JSC::Wasm::FunctionCodeBlock::getConstant const): (JSC::Wasm::FunctionCodeBlock::functionIndex const): (JSC::Wasm::FunctionCodeBlock::addJumpTarget): (JSC::Wasm::FunctionCodeBlock::numberOfJumpTargets): (JSC::Wasm::FunctionCodeBlock::lastJumpTarget): (JSC::Wasm::FunctionCodeBlock::outOfLineJumpOffset): (JSC::Wasm::FunctionCodeBlock::bytecodeOffset): (JSC::Wasm::FunctionCodeBlock::tierUpCounter): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parseExpression): (JSC::Wasm::FunctionParser<Context>::parseUnreachableExpression): * wasm/WasmInstance.h: * wasm/WasmLLIntGenerator.cpp: Added. (JSC::Wasm::LLIntGenerator::ControlType::ControlType): (JSC::Wasm::LLIntGenerator::ControlType::loop): (JSC::Wasm::LLIntGenerator::ControlType::topLevel): (JSC::Wasm::LLIntGenerator::ControlType::block): (JSC::Wasm::LLIntGenerator::ControlType::if_): (JSC::Wasm::LLIntGenerator::ControlType::targetLabelForBranch const): (JSC::Wasm::LLIntGenerator::fail const): (JSC::Wasm::LLIntGenerator::unifyValuesWithBlock): (JSC::Wasm::LLIntGenerator::emptyExpression): (JSC::Wasm::LLIntGenerator::createStack): (JSC::Wasm::LLIntGenerator::isControlTypeIf): (JSC::Wasm::LLIntGenerator::addEndToUnreachable): (JSC::Wasm::LLIntGenerator::setParser): (JSC::Wasm::LLIntGenerator::dump): (JSC::Wasm::LLIntGenerator::virtualRegisterForLocal): (JSC::Wasm::LLIntGenerator::tmpsForSignature): (JSC::Wasm::LLIntGenerator::jsNullConstant): (JSC::Wasm::LLIntGenerator::isConstant): (JSC::Wasm::parseAndCompileBytecode): (JSC::Wasm::LLIntGenerator::LLIntGenerator): (JSC::Wasm::LLIntGenerator::finalize): (JSC::Wasm::LLIntGenerator::callInformationFor): (JSC::Wasm::LLIntGenerator::addArguments): (JSC::Wasm::LLIntGenerator::addLocal): (JSC::Wasm::LLIntGenerator::addConstant): (JSC::Wasm::LLIntGenerator::getLocal): (JSC::Wasm::LLIntGenerator::setLocal): (JSC::Wasm::LLIntGenerator::getGlobal): (JSC::Wasm::LLIntGenerator::setGlobal): (JSC::Wasm::LLIntGenerator::addLoop): (JSC::Wasm::LLIntGenerator::addTopLevel): (JSC::Wasm::LLIntGenerator::addBlock): (JSC::Wasm::LLIntGenerator::addIf): (JSC::Wasm::LLIntGenerator::addElse): (JSC::Wasm::LLIntGenerator::addElseToUnreachable): (JSC::Wasm::LLIntGenerator::addReturn): (JSC::Wasm::LLIntGenerator::addBranch): (JSC::Wasm::LLIntGenerator::addSwitch): (JSC::Wasm::LLIntGenerator::endBlock): (JSC::Wasm::LLIntGenerator::addCall): (JSC::Wasm::LLIntGenerator::addCallIndirect): (JSC::Wasm::LLIntGenerator::addRefIsNull): (JSC::Wasm::LLIntGenerator::addRefFunc): (JSC::Wasm::LLIntGenerator::addTableGet): (JSC::Wasm::LLIntGenerator::addTableSet): (JSC::Wasm::LLIntGenerator::addTableSize): (JSC::Wasm::LLIntGenerator::addTableGrow): (JSC::Wasm::LLIntGenerator::addTableFill): (JSC::Wasm::LLIntGenerator::addUnreachable): (JSC::Wasm::LLIntGenerator::addCurrentMemory): (JSC::Wasm::LLIntGenerator::addGrowMemory): (JSC::Wasm::LLIntGenerator::addSelect): (JSC::Wasm::LLIntGenerator::load): (JSC::Wasm::LLIntGenerator::store): (JSC::GenericLabel<Wasm::GeneratorTraits>::setLocation): * wasm/WasmLLIntGenerator.h: Copied from Source/JavaScriptCore/wasm/WasmCompilationMode.h. * wasm/WasmLLIntPlan.cpp: Added. (JSC::Wasm::LLIntPlan::prepareImpl): (JSC::Wasm::LLIntPlan::compileFunction): (JSC::Wasm::LLIntPlan::didCompleteCompilation): (JSC::Wasm::LLIntPlan::initializeCallees): * wasm/WasmLLIntPlan.h: Copied from Source/JavaScriptCore/wasm/WasmOMGForOSREntryPlan.h. * wasm/WasmLLIntTierUpCounter.cpp: Copied from Source/JavaScriptCore/wasm/WasmCompilationMode.cpp. (JSC::Wasm::LLIntTierUpCounter::addOSREntryDataForLoop): (JSC::Wasm::LLIntTierUpCounter::osrEntryDataForLoop const const): * wasm/WasmLLIntTierUpCounter.h: Copied from Source/JavaScriptCore/wasm/WasmOMGForOSREntryPlan.h. (JSC::Wasm::LLIntTierUpCounter::LLIntTierUpCounter): (JSC::Wasm::LLIntTierUpCounter::optimizeAfterWarmUp): (JSC::Wasm::LLIntTierUpCounter::checkIfOptimizationThresholdReached): (JSC::Wasm::LLIntTierUpCounter::optimizeSoon): * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationResult): (JSC::Wasm::makeValidationCallback): (JSC::Wasm::Module::validateSync): (JSC::Wasm::Module::validateAsync): * wasm/WasmOMGForOSREntryPlan.cpp: (JSC::Wasm::OMGForOSREntryPlan::OMGForOSREntryPlan): (JSC::Wasm::OMGForOSREntryPlan::work): * wasm/WasmOMGForOSREntryPlan.h: * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::work): * wasm/WasmSlowPaths.cpp: Added. (JSC::LLInt::jitCompileAndSetHeuristics): (JSC::LLInt::WASM_SLOW_PATH_DECL): (JSC::LLInt::doWasmCall): (JSC::LLInt::doWasmCallIndirect): (JSC::LLInt::slow_path_wasm_throw_exception): (JSC::LLInt::slow_path_wasm_popcount): (JSC::LLInt::slow_path_wasm_popcountll): * wasm/WasmSlowPaths.h: Added. * wasm/WasmTable.cpp: (JSC::Wasm::FuncRefTable::function const): (JSC::Wasm::FuncRefTable::instance const): * wasm/WasmTable.h: * wasm/WasmTierUpCount.h: * wasm/WasmValidate.cpp: (JSC::Wasm::Validate::isControlTypeIf): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::WebAssemblyFunction::calleeSaves const): Tools: Add a mode that runs WebAssembly tests without the LLInt (i.e. only Air) and update the no-air mode to also disable the LLInt tier. * Scripts/run-jsc-stress-tests: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@251886 268f45cc-cd09-0410-ab3c-d52691b4dbfc
WebKit is a cross-platform web browser engine. On iOS and macOS, it powers Safari, Mail, iBooks, and many other applications.
Visit WebKit Feature Status page to see which Web API has been implemented, in development, or under consideration.
On macOS, download Safari Technology Preview to test the latest version of WebKit. On Linux, download Epiphany Technology Preview. On Windows, you'll have to build it yourself.
Once your bug is filed, you will receive email when it is updated at each stage in the bug life cycle. After the bug is considered fixed, you may be asked to download the latest nightly and confirm that the fix works for you.
On Windows, follow the instructions on our website.
Run the following command to clone WebKit's Git SVN repository:
git clone git://git.webkit.org/WebKit.git WebKit
or
git clone https://git.webkit.org/git/WebKit.git WebKit
If you want to be able to commit changes to the repository, or just want to check out branches that aren’t contained in WebKit.git, you will need track WebKit's Subversion repository. You can run the following command to configure this and other options of the new Git clone for WebKit development.
Tools/Scripts/webkit-patch setup-git-clone
For information about this, and other aspects of using Git with WebKit, read the wiki page.
If you don‘t want to use Git, run the following command to check out WebKit’s Subversion repository:
svn checkout https://svn.webkit.org/repository/webkit/trunk WebKit
Install Xcode and its command line tools if you haven't done so already:
xcode-select --install
Run the following command to build a debug build with debugging symbols and assertions:
Tools/Scripts/build-webkit --debug
For performance testing, and other purposes, use --release
instead.
You can open WebKit.xcworkspace
to build and debug WebKit within Xcode.
If you don't use a custom build location in Xcode preferences, you have to update the workspace settings to use WebKitBuild
directory. In menu bar, choose File > Workspace Settings, then click the Advanced button, select “Custom”, “Relative to Workspace”, and enter WebKitBuild
for both Products and Intermediates.
The first time after you install a new Xcode, you will need to run the following command to enable Xcode to build command line tools for iOS Simulator:
sudo Tools/Scripts/configure-xcode-for-ios-development
Without this step, you will see the error message: “target specifies product type ‘com.apple.product-type.tool’, but there’s no such product type for the ‘iphonesimulator’ platform.
” when building target JSCLLIntOffsetsExtractor
of project JavaScriptCore
.
Run the following command to build a debug build with debugging symbols and assertions for iOS:
Tools/Scripts/build-webkit --debug --ios-simulator
For production builds:
cmake -DPORT=GTK -DCMAKE_BUILD_TYPE=RelWithDebInfo -GNinja ninja sudo ninja install
For development builds:
Tools/gtk/install-dependencies Tools/Scripts/update-webkitgtk-libs Tools/Scripts/build-webkit --gtk --debug
For more information on building WebKitGTK+, see the wiki page.
For production builds:
cmake -DPORT=WPE -DCMAKE_BUILD_TYPE=RelWithDebInfo -GNinja ninja sudo ninja install
For development builds:
Tools/wpe/install-dependencies Tools/Scripts/update-webkitwpe-libs Tools/Scripts/build-webkit --wpe --debug
For building WebKit on Windows, see the wiki page.
Run the following command to launch Safari with your local build of WebKit:
Tools/Scripts/run-safari --debug
The run-safari
script sets the DYLD_FRAMEWORK_PATH
environment variable to point to your build products, and then launches /Applications/Safari.app
. DYLD_FRAMEWORK_PATH
tells the system loader to prefer your build products over the frameworks installed in /System/Library/Frameworks
.
To run other applications with your local build of WebKit, run the following command:
Tools/Scripts/run-webkit-app <application-path>
Run the following command to launch iOS simulator with your local build of WebKit:
run-safari --debug --ios-simulator
In both cases, if you have built release builds instead, use --release
instead of --debug
.
If you have a development build, you can use the run-minibrowser script, e.g.:
run-minibrowser --debug --wpe
Pass one of --gtk
, --jsc-only
, or --wpe
to indicate the port to use.
Congratulations! You’re up and running. Now you can begin coding in WebKit and contribute your fixes and new features to the project. For details on submitting your code to the project, read Contributing Code.