haikuwebkit/Source/JavaScriptCore/wasm/WasmInstance.h

245 lines
11 KiB
C
Raw Permalink Normal View History

WebAssembly: no VM / JS version of everything but Instance https://bugs.webkit.org/show_bug.cgi?id=177473 Reviewed by Filip Pizlo, Saam Barati. JSTests: - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. * wasm/js-api/memory-grow.js: (assertEq): * wasm/js-api/table.js: (assert.throws): Source/JavaScriptCore: This change entails cleaning up and splitting a bunch of code which we had intertwined between C++ classes which represent JS objects, and pure C++ implementation objects. This specific change goes most of the way towards allowing JSC's WebAssembly to work without VM / JS, up to but excluding JSWebAssemblyInstance (there's Wasm::Instance, but it's not *the* thing yet). Because of this we still have a few FIXME identifying places that need to change. A follow-up change will go the rest of the way. I went about this change in the simplest way possible: grep the JavaScriptCore/wasm directory for "JS[^C_]" as well as "VM" and exclude the /js/ sub-directory (which contains the JS implementation of WebAssembly). None of this change removes the need for a JIT entitlement to be able to use WebAssembly. We don't have an interpreter, the process therefore still needs to be allowed to JIT to use these pure-C++ APIs. Interesting things to note: - Remove VM from Plan and associated places. It can just live as a capture in the callback lambda if it's needed. - Wasm::Memory shouldn't require a VM. It was only used to ask the GC to collect. We now instead pass two lambdas at construction time for this purpose: one to notify of memory pressure, and the other to ask for syncrhonous memory reclamation. This allows whoever creates the memory to dictate how to react to both these cases, and for a JS embedding that's to call the GC (async or sync, respectively). - Move grow logic from JSWebAssemblyMemory to Wasm::Memory::grow. Use Expected there, with an enum class for failure types. - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. - When generating the grow_memory opcode, no need to get the VM. Instead, reach directly for Wasm::Memory and grow it. - JSWebAssemblyMemory::grow can now always throw on failure, because it's only ever called from JS (not from grow_memory as before). - Wasm::Memory now takes a callback for successful growth. This allows JS wrappers to register themselves when growth succeeds without Wasm::Memory knowning anything about JS. It'll also allow creating a list of callbacks for when we add thread support (we'll want to notify many wrappers, all under a lock). - Wasm::Memory is now back to being the source of truth about address / size, used directly by generated code instead of JSWebAssemblyMemory. - Move wasmToJS from the general WasmBinding header to its own header under wasm/js. It's only used by wasm/js/JSWebAssemblyCodeBlock.cpp, and uses VM, and therefore isn't general WebAssembly. - Make Wasm::Context an actual type (just a struct holding a JSWebAssemlyInstance for now) instead of an alias for that. Notably this doesn't add anything to the Context and doesn't change what actually gets passed around in JIT code (fast TLS or registers) because these changes potentially impact performance. The entire purpose of this change is to allow passing Wasm::Context around without having to know about VM. Since VM contains a Wasm::Context the JS embedding is effectively the same, but with this setup a non-JS embedding is much better off. - Move JSWebAssembly into the JS folder. - OMGPlan: use Wasm::CodeBlock directly instead of JSWebAssemblyCodeBlock. - wasm->JS stubs are now on the instance's tail as raw pointers, instead of being on JSWebAssemblyCodeBlock, and are now called wasm->Embedder stubs. The owned reference is still on JSWebAssemblyCodeBlock, and is still called wasm->JS stub. This move means that the embedder must, after creating a Wasm::CodeBlock, somehow create the stubs to call back into the embedder. This removes an indirection in the generated code because the B3 IR generator now reaches into the instance instead of JSWebAssemblyCodeBlock. - Move more CodeBlock things. Compilation completion is now marked by its own atomic<bool> flag instead of a nullptr plan: that required using a lock, and was causing a deadlock in stack-trace.js because before my changes JSWebAssemblyCodeBlock did its own completion checking separately from Wasm::CodeBlock, without getting the lock. Now that everything points to Wasm::CodeBlock and there's no cached completion marker, the lock was being acquired in a sanity-check assertion. - Embedder -> Wasm wrappers are now generated through a function that's passed in at compilation time, instead of being hard-coded as a JS -> Wasm wrapper. - WasmMemory doens't need to know about fault handling thunks. Only the IR generator should know, and should make sure that the exception throwing thunk is generated if any memory is present (note: with signal handling not all of them generate an exception check). - Make exception throwing pluggable: instead of having a hard-coded JS-specific lambda we now have a regular C++ function being called from JIT code when a WebAssembly exception is thrown. This allows any embedder to get called as they wish. For now a process can only have a single of these functions (i.e. only one embedder per process) because the trap handler is a singleton. That can be fixed in in #177475. - Create WasmEmbedder.h where all embedder plugging will live. - Split up JSWebAssemblyTable into Wasm::Table which is refcounted. JSWebAssemblyTable now only contains the JS functions in the table, and Wasm::Table is what's used by the JIT code to lookup where to call and do the instance check (for context switch). Note that this creates an extra allocation for all the instances in Wasm::Table, and in exchange removes an indirection in JIT code because the instance used to be obtained off of the JS function. Also note that it's the embedder than keeps the instances alive, not Wasm::Table (which holds a dumb pointer to the instance), because doing otherwise would cause reference cycles. - Add WasmInstance. It doesn't do much for now, owns globals. - JSWebAssembly instance now doesn't just contain the imported functions as JSObjects, it also has the corresponding import's instance and wasm entrypoint. This triples the space allocated per instance's imported function, but there shouldn't be that many imports. This has two upsides: it creates smaller and faster code, and makes is easier to disassociate embedder-specific things from embedder-neutral things. The small / faster win is in two places: B3 IR generator only needs offsetOfImportFunction for the call opcode (when the called index is an import) to know whether the import is wasm->wasm or wasm->embedder (this isn't known at compile-time because it's dependent on the import object), this is now done by seeing if that import function has an associated target instance (only wasm->wasm does); the other place is wasmBinding which uses offsetOfImportFunction to figure out the wasm->wasm target instance, and then gets WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation to do a tail call. The disassociation comes because the target instance can be Wasm::Instance once we change what the Context is, and WasmEntrypointLoadLocation is already embedder-independent. As a next step I can move this tail allocation from JSWebAssemblyInstance to Wasm::Instance, and leave importFunction in as an opaque pointer which is embedder-specific, and in JS will remain WriteBarrier<JSObject>. - Rename VMEntryFrame to EntryFrame, and in many places pass a pointer to it around instead of VM. This is a first step in allowing entry frames which aren't stored on VM, but which are instead stored in an embedder-specific location. That change won't really affect JS except through code churn, but will allow WebAssembly to use some machinery in a generic manner without having a VM. * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * debugger/Debugger.cpp: (JSC::Debugger::stepOutOfFunction): (JSC::Debugger::returnEvent): (JSC::Debugger::unwindEvent): (JSC::Debugger::didExecuteProgram): * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::compileExceptionHandlers): * dfg/DFGOSREntry.cpp: (JSC::DFG::prepareOSREntry): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::compileOSRExit): (JSC::DFG::OSRExit::compileExit): * dfg/DFGThunks.cpp: (JSC::DFG::osrEntryThunkGenerator): * ftl/FTLCompile.cpp: (JSC::FTL::compile): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::lower): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): (JSC::CallFrame::callerFrame): (JSC::CallFrame::unsafeCallerFrame): * interpreter/CallFrame.h: (JSC::ExecState::callerFrame const): (JSC::ExecState::callerFrameOrEntryFrame const): (JSC::ExecState::unsafeCallerFrameOrEntryFrame const): * interpreter/FrameTracers.h: (JSC::NativeCallFrameTracer::NativeCallFrameTracer): (JSC::NativeCallFrameTracerWithRestore::NativeCallFrameTracerWithRestore): (JSC::NativeCallFrameTracerWithRestore::~NativeCallFrameTracerWithRestore): * interpreter/Interpreter.cpp: (JSC::UnwindFunctor::operator() const): (JSC::UnwindFunctor::copyCalleeSavesToEntryFrameCalleeSavesBuffer const): (JSC::Interpreter::unwind): * interpreter/StackVisitor.cpp: (JSC::StackVisitor::StackVisitor): (JSC::StackVisitor::gotoNextFrame): (JSC::StackVisitor::readNonInlinedFrame): (JSC::StackVisitor::Frame::dump const): * interpreter/StackVisitor.h: (JSC::StackVisitor::Frame::callerIsEntryFrame const): * interpreter/VMEntryRecord.h: (JSC::VMEntryRecord::prevTopEntryFrame): (JSC::VMEntryRecord::unsafePrevTopEntryFrame): (JSC::EntryFrame::vmEntryRecordOffset): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::restoreCalleeSavesFromEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::loadWasmContextInstance): (JSC::AssemblyHelpers::storeWasmContextInstance): (JSC::AssemblyHelpers::loadWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::storeWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBufferImpl): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::copyCalleeSavesToVMEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer): * jit/JIT.cpp: (JSC::JIT::emitEnterOptimizationCheck): (JSC::JIT::privateCompileExceptionHandlers): * jit/JITExceptions.cpp: (JSC::genericUnwind): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): (JSC::JIT::emitSlow_op_loop_hint): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): * jit/JITOperations.cpp: * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::nativeForGenerator): * jsc.cpp: (functionDumpCallFrame): * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LLIntThunks.cpp: (JSC::vmEntryRecord): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/Options.cpp: (JSC::recomputeDependentOptions): * runtime/Options.h: * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::FrameWalker): (JSC::FrameWalker::advanceToParentFrame): (JSC::SamplingProfiler::processUnverifiedStackTraces): * runtime/ThrowScope.cpp: (JSC::ThrowScope::~ThrowScope): * runtime/VM.cpp: (JSC::VM::VM): (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::topEntryFrameOffset): * runtime/VMTraps.cpp: (JSC::isSaneFrame): (JSC::VMTraps::tryInstallTrapBreakpoints): (JSC::VMTraps::invalidateCodeBlocksOnStack): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWasmContextInstance): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::parseAndCompile): * wasm/WasmB3IRGenerator.h: * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::BBQPlan): (JSC::Wasm::BBQPlan::compileFunctions): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBBQPlanInlines.h: (JSC::Wasm::BBQPlan::initializeCallees): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmBinding.h: * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::create): (JSC::Wasm::CodeBlock::CodeBlock): (JSC::Wasm::CodeBlock::compileAsync): (JSC::Wasm::CodeBlock::setCompilationFinished): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::offsetOfImportStubs): (JSC::Wasm::CodeBlock::allocationSize): (JSC::Wasm::CodeBlock::importWasmToEmbedderStub): (JSC::Wasm::CodeBlock::offsetOfImportWasmToEmbedderStub): (JSC::Wasm::CodeBlock::wasmToJSCallStubForImport): (JSC::Wasm::CodeBlock::compilationFinished): (JSC::Wasm::CodeBlock::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): * wasm/WasmContext.cpp: (JSC::Wasm::Context::useFastTLS): (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: Copied from Source/JavaScriptCore/wasm/WasmContext.h. * wasm/WasmFaultSignalHandler.cpp: * wasm/WasmFaultSignalHandler.h: * wasm/WasmFormat.h: * wasm/WasmInstance.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::~Instance): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: Added. (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::module): (JSC::Wasm::Instance::codeBlock): (JSC::Wasm::Instance::memory): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::loadF32Global const): (JSC::Wasm::Instance::loadF64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::offsetOfCachedStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::~Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::offsetOfSize): * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationCallback): (JSC::Wasm::Module::validateSync): (JSC::Wasm::Module::validateAsync): (JSC::Wasm::Module::getOrCreateCodeBlock): (JSC::Wasm::Module::compileSync): (JSC::Wasm::Module::compileAsync): * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseTableHelper): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::OMGPlan): (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::isValid const): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::runCompletionTasks): (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmPlan.h: (JSC::Wasm::Plan::dontFinalize): * wasm/WasmSignature.cpp: * wasm/WasmSignature.h: * wasm/WasmTable.cpp: Added. (JSC::Wasm::Table::create): (JSC::Wasm::Table::~Table): (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h. (JSC::Wasm::Table::maximum const): (JSC::Wasm::Table::size const): (JSC::Wasm::Table::offsetOfSize): (JSC::Wasm::Table::offsetOfFunctions): (JSC::Wasm::Table::offsetOfInstances): (JSC::Wasm::Table::isValidSize): * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): (JSC::Wasm::Thunks::setThrowWasmException): (JSC::Wasm::Thunks::throwWasmException): * wasm/WasmThunks.h: * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::stopAllPlansForContext): * wasm/WasmWorklist.h: * wasm/js/JSToWasm.cpp: Added. (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/JSWebAssembly.cpp: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.cpp. * wasm/js/JSWebAssembly.h: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.h. * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::create): (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::context const): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::webAssemblyToJSCallee): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::offsetOfTail): (JSC::JSWebAssemblyInstance::importFunctionInfo): (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): (JSC::JSWebAssemblyInstance::offsetOfImportFunction): (JSC::JSWebAssemblyInstance::importFunction): (JSC::JSWebAssemblyInstance::internalMemory): (JSC::JSWebAssemblyInstance::wasmCodeBlock const): (JSC::JSWebAssemblyInstance::offsetOfWasmTable): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::offsetOfGlobals): (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): (JSC::JSWebAssemblyInstance::cachedStackLimit const): (JSC::JSWebAssemblyInstance::setCachedStackLimit): (JSC::JSWebAssemblyInstance::wasmMemory): (JSC::JSWebAssemblyInstance::wasmModule): (JSC::JSWebAssemblyInstance::allocationSize): (JSC::JSWebAssemblyInstance::module const): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::create): (JSC::JSWebAssemblyMemory::adopt): (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::moduleInformation const): (JSC::JSWebAssemblyModule::exportSymbolTable const): (JSC::JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace const): (JSC::JSWebAssemblyModule::callee const): (JSC::JSWebAssemblyModule::codeBlock): (JSC::JSWebAssemblyModule::module): * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::create): (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::visitChildren): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::getFunction): (JSC::JSWebAssemblyTable::clearFunction): (JSC::JSWebAssemblyTable::setFunction): * wasm/js/JSWebAssemblyTable.h: (JSC::JSWebAssemblyTable::isValidSize): (JSC::JSWebAssemblyTable::maximum const): (JSC::JSWebAssemblyTable::size const): (JSC::JSWebAssemblyTable::table): * wasm/js/WasmToJS.cpp: Copied from Source/JavaScriptCore/wasm/WasmBinding.cpp. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): (JSC::WebAssemblyModuleConstructor::createModule): * wasm/js/WebAssemblyModuleConstructor.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::webAssemblyCompileFunc): (JSC::instantiate): (JSC::compileAndInstantiate): (JSC::webAssemblyValidateFunc): * wasm/js/WebAssemblyTableConstructor.cpp: (JSC::constructJSWebAssemblyTable): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Source/WebCore: * ForwardingHeaders/wasm/WasmModule.h: Added. This used to be included in JSWebAssemblyModule.h. * bindings/js/SerializedScriptValue.cpp: Update postMessage code according to C++ API changes. Canonical link: https://commits.webkit.org/194750@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223738 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-20 02:23:29 +00:00
/*
PoisonedWriteBarrier https://bugs.webkit.org/show_bug.cgi?id=181599 <rdar://problem/36474351> Reviewed by Mark Lam. Source/JavaScriptCore: Allow poisoning of WriteBarrier objects, and use this for WebAssembly because it is perf-neutral, at least on WasmBench on my MBP. If it indeed is perf-neutral according to the bots, start using it in more performance-sensitive places. * heap/HandleTypes.h: * heap/SlotVisitor.h: * heap/SlotVisitorInlines.h: (JSC::SlotVisitor::append): (JSC::SlotVisitor::appendHidden): * runtime/JSCJSValue.h: * runtime/JSCPoison.h: * runtime/Structure.h: * runtime/StructureInlines.h: (JSC::Structure::setPrototypeWithoutTransition): (JSC::Structure::setGlobalObject): (JSC::Structure::setPreviousID): * runtime/WriteBarrier.h: (JSC::WriteBarrierBase::copyFrom): (JSC::WriteBarrierBase::get const): (JSC::WriteBarrierBase::operator* const): (JSC::WriteBarrierBase::operator-> const): (JSC::WriteBarrierBase::clear): (JSC::WriteBarrierBase::slot): (JSC::WriteBarrierBase::operator bool const): (JSC::WriteBarrierBase::setWithoutWriteBarrier): (JSC::WriteBarrierBase::unvalidatedGet const): (JSC::operator==): * runtime/WriteBarrierInlines.h: (JSC::Traits>::set): (JSC::Traits>::setMayBeNull): (JSC::Traits>::setEarlyValue): (JSC::DumbValueTraits<Unknown>>::set): * wasm/WasmInstance.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::offsetOfPoisonedCallee): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::clearFunction): * wasm/js/JSWebAssemblyTable.h: * wasm/js/WasmToJS.cpp: (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): * wasm/js/WebAssemblyFunctionBase.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyModuleRecord.h: * wasm/js/WebAssemblyToJSCallee.h: * wasm/js/WebAssemblyWrapperFunction.h: Source/WTF: Supporting changes needed to allow poisoning of WriteBarrier objects. * WTF.xcodeproj/project.pbxproj: * wtf/DumbPtrTraits.h: * wtf/DumbValueTraits.h: Copied from Source/WTF/wtf/DumbPtrTraits.h. (WTF::DumbValueTraits::exchange): (WTF::DumbValueTraits::swap): (WTF::DumbValueTraits::unwrap): * wtf/Forward.h: * wtf/Poisoned.h: (WTF::ConstExprPoisonedValueTraits::exchange): (WTF::ConstExprPoisonedValueTraits::swap): (WTF::ConstExprPoisonedValueTraits::unwrap): Canonical link: https://commits.webkit.org/197477@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226920 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-01-12 23:47:58 +00:00
* Copyright (C) 2017-2018 Apple Inc. All rights reserved.
WebAssembly: no VM / JS version of everything but Instance https://bugs.webkit.org/show_bug.cgi?id=177473 Reviewed by Filip Pizlo, Saam Barati. JSTests: - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. * wasm/js-api/memory-grow.js: (assertEq): * wasm/js-api/table.js: (assert.throws): Source/JavaScriptCore: This change entails cleaning up and splitting a bunch of code which we had intertwined between C++ classes which represent JS objects, and pure C++ implementation objects. This specific change goes most of the way towards allowing JSC's WebAssembly to work without VM / JS, up to but excluding JSWebAssemblyInstance (there's Wasm::Instance, but it's not *the* thing yet). Because of this we still have a few FIXME identifying places that need to change. A follow-up change will go the rest of the way. I went about this change in the simplest way possible: grep the JavaScriptCore/wasm directory for "JS[^C_]" as well as "VM" and exclude the /js/ sub-directory (which contains the JS implementation of WebAssembly). None of this change removes the need for a JIT entitlement to be able to use WebAssembly. We don't have an interpreter, the process therefore still needs to be allowed to JIT to use these pure-C++ APIs. Interesting things to note: - Remove VM from Plan and associated places. It can just live as a capture in the callback lambda if it's needed. - Wasm::Memory shouldn't require a VM. It was only used to ask the GC to collect. We now instead pass two lambdas at construction time for this purpose: one to notify of memory pressure, and the other to ask for syncrhonous memory reclamation. This allows whoever creates the memory to dictate how to react to both these cases, and for a JS embedding that's to call the GC (async or sync, respectively). - Move grow logic from JSWebAssemblyMemory to Wasm::Memory::grow. Use Expected there, with an enum class for failure types. - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. - When generating the grow_memory opcode, no need to get the VM. Instead, reach directly for Wasm::Memory and grow it. - JSWebAssemblyMemory::grow can now always throw on failure, because it's only ever called from JS (not from grow_memory as before). - Wasm::Memory now takes a callback for successful growth. This allows JS wrappers to register themselves when growth succeeds without Wasm::Memory knowning anything about JS. It'll also allow creating a list of callbacks for when we add thread support (we'll want to notify many wrappers, all under a lock). - Wasm::Memory is now back to being the source of truth about address / size, used directly by generated code instead of JSWebAssemblyMemory. - Move wasmToJS from the general WasmBinding header to its own header under wasm/js. It's only used by wasm/js/JSWebAssemblyCodeBlock.cpp, and uses VM, and therefore isn't general WebAssembly. - Make Wasm::Context an actual type (just a struct holding a JSWebAssemlyInstance for now) instead of an alias for that. Notably this doesn't add anything to the Context and doesn't change what actually gets passed around in JIT code (fast TLS or registers) because these changes potentially impact performance. The entire purpose of this change is to allow passing Wasm::Context around without having to know about VM. Since VM contains a Wasm::Context the JS embedding is effectively the same, but with this setup a non-JS embedding is much better off. - Move JSWebAssembly into the JS folder. - OMGPlan: use Wasm::CodeBlock directly instead of JSWebAssemblyCodeBlock. - wasm->JS stubs are now on the instance's tail as raw pointers, instead of being on JSWebAssemblyCodeBlock, and are now called wasm->Embedder stubs. The owned reference is still on JSWebAssemblyCodeBlock, and is still called wasm->JS stub. This move means that the embedder must, after creating a Wasm::CodeBlock, somehow create the stubs to call back into the embedder. This removes an indirection in the generated code because the B3 IR generator now reaches into the instance instead of JSWebAssemblyCodeBlock. - Move more CodeBlock things. Compilation completion is now marked by its own atomic<bool> flag instead of a nullptr plan: that required using a lock, and was causing a deadlock in stack-trace.js because before my changes JSWebAssemblyCodeBlock did its own completion checking separately from Wasm::CodeBlock, without getting the lock. Now that everything points to Wasm::CodeBlock and there's no cached completion marker, the lock was being acquired in a sanity-check assertion. - Embedder -> Wasm wrappers are now generated through a function that's passed in at compilation time, instead of being hard-coded as a JS -> Wasm wrapper. - WasmMemory doens't need to know about fault handling thunks. Only the IR generator should know, and should make sure that the exception throwing thunk is generated if any memory is present (note: with signal handling not all of them generate an exception check). - Make exception throwing pluggable: instead of having a hard-coded JS-specific lambda we now have a regular C++ function being called from JIT code when a WebAssembly exception is thrown. This allows any embedder to get called as they wish. For now a process can only have a single of these functions (i.e. only one embedder per process) because the trap handler is a singleton. That can be fixed in in #177475. - Create WasmEmbedder.h where all embedder plugging will live. - Split up JSWebAssemblyTable into Wasm::Table which is refcounted. JSWebAssemblyTable now only contains the JS functions in the table, and Wasm::Table is what's used by the JIT code to lookup where to call and do the instance check (for context switch). Note that this creates an extra allocation for all the instances in Wasm::Table, and in exchange removes an indirection in JIT code because the instance used to be obtained off of the JS function. Also note that it's the embedder than keeps the instances alive, not Wasm::Table (which holds a dumb pointer to the instance), because doing otherwise would cause reference cycles. - Add WasmInstance. It doesn't do much for now, owns globals. - JSWebAssembly instance now doesn't just contain the imported functions as JSObjects, it also has the corresponding import's instance and wasm entrypoint. This triples the space allocated per instance's imported function, but there shouldn't be that many imports. This has two upsides: it creates smaller and faster code, and makes is easier to disassociate embedder-specific things from embedder-neutral things. The small / faster win is in two places: B3 IR generator only needs offsetOfImportFunction for the call opcode (when the called index is an import) to know whether the import is wasm->wasm or wasm->embedder (this isn't known at compile-time because it's dependent on the import object), this is now done by seeing if that import function has an associated target instance (only wasm->wasm does); the other place is wasmBinding which uses offsetOfImportFunction to figure out the wasm->wasm target instance, and then gets WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation to do a tail call. The disassociation comes because the target instance can be Wasm::Instance once we change what the Context is, and WasmEntrypointLoadLocation is already embedder-independent. As a next step I can move this tail allocation from JSWebAssemblyInstance to Wasm::Instance, and leave importFunction in as an opaque pointer which is embedder-specific, and in JS will remain WriteBarrier<JSObject>. - Rename VMEntryFrame to EntryFrame, and in many places pass a pointer to it around instead of VM. This is a first step in allowing entry frames which aren't stored on VM, but which are instead stored in an embedder-specific location. That change won't really affect JS except through code churn, but will allow WebAssembly to use some machinery in a generic manner without having a VM. * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * debugger/Debugger.cpp: (JSC::Debugger::stepOutOfFunction): (JSC::Debugger::returnEvent): (JSC::Debugger::unwindEvent): (JSC::Debugger::didExecuteProgram): * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::compileExceptionHandlers): * dfg/DFGOSREntry.cpp: (JSC::DFG::prepareOSREntry): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::compileOSRExit): (JSC::DFG::OSRExit::compileExit): * dfg/DFGThunks.cpp: (JSC::DFG::osrEntryThunkGenerator): * ftl/FTLCompile.cpp: (JSC::FTL::compile): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::lower): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): (JSC::CallFrame::callerFrame): (JSC::CallFrame::unsafeCallerFrame): * interpreter/CallFrame.h: (JSC::ExecState::callerFrame const): (JSC::ExecState::callerFrameOrEntryFrame const): (JSC::ExecState::unsafeCallerFrameOrEntryFrame const): * interpreter/FrameTracers.h: (JSC::NativeCallFrameTracer::NativeCallFrameTracer): (JSC::NativeCallFrameTracerWithRestore::NativeCallFrameTracerWithRestore): (JSC::NativeCallFrameTracerWithRestore::~NativeCallFrameTracerWithRestore): * interpreter/Interpreter.cpp: (JSC::UnwindFunctor::operator() const): (JSC::UnwindFunctor::copyCalleeSavesToEntryFrameCalleeSavesBuffer const): (JSC::Interpreter::unwind): * interpreter/StackVisitor.cpp: (JSC::StackVisitor::StackVisitor): (JSC::StackVisitor::gotoNextFrame): (JSC::StackVisitor::readNonInlinedFrame): (JSC::StackVisitor::Frame::dump const): * interpreter/StackVisitor.h: (JSC::StackVisitor::Frame::callerIsEntryFrame const): * interpreter/VMEntryRecord.h: (JSC::VMEntryRecord::prevTopEntryFrame): (JSC::VMEntryRecord::unsafePrevTopEntryFrame): (JSC::EntryFrame::vmEntryRecordOffset): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::restoreCalleeSavesFromEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::loadWasmContextInstance): (JSC::AssemblyHelpers::storeWasmContextInstance): (JSC::AssemblyHelpers::loadWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::storeWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBufferImpl): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::copyCalleeSavesToVMEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer): * jit/JIT.cpp: (JSC::JIT::emitEnterOptimizationCheck): (JSC::JIT::privateCompileExceptionHandlers): * jit/JITExceptions.cpp: (JSC::genericUnwind): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): (JSC::JIT::emitSlow_op_loop_hint): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): * jit/JITOperations.cpp: * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::nativeForGenerator): * jsc.cpp: (functionDumpCallFrame): * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LLIntThunks.cpp: (JSC::vmEntryRecord): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/Options.cpp: (JSC::recomputeDependentOptions): * runtime/Options.h: * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::FrameWalker): (JSC::FrameWalker::advanceToParentFrame): (JSC::SamplingProfiler::processUnverifiedStackTraces): * runtime/ThrowScope.cpp: (JSC::ThrowScope::~ThrowScope): * runtime/VM.cpp: (JSC::VM::VM): (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::topEntryFrameOffset): * runtime/VMTraps.cpp: (JSC::isSaneFrame): (JSC::VMTraps::tryInstallTrapBreakpoints): (JSC::VMTraps::invalidateCodeBlocksOnStack): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWasmContextInstance): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::parseAndCompile): * wasm/WasmB3IRGenerator.h: * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::BBQPlan): (JSC::Wasm::BBQPlan::compileFunctions): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBBQPlanInlines.h: (JSC::Wasm::BBQPlan::initializeCallees): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmBinding.h: * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::create): (JSC::Wasm::CodeBlock::CodeBlock): (JSC::Wasm::CodeBlock::compileAsync): (JSC::Wasm::CodeBlock::setCompilationFinished): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::offsetOfImportStubs): (JSC::Wasm::CodeBlock::allocationSize): (JSC::Wasm::CodeBlock::importWasmToEmbedderStub): (JSC::Wasm::CodeBlock::offsetOfImportWasmToEmbedderStub): (JSC::Wasm::CodeBlock::wasmToJSCallStubForImport): (JSC::Wasm::CodeBlock::compilationFinished): (JSC::Wasm::CodeBlock::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): * wasm/WasmContext.cpp: (JSC::Wasm::Context::useFastTLS): (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: Copied from Source/JavaScriptCore/wasm/WasmContext.h. * wasm/WasmFaultSignalHandler.cpp: * wasm/WasmFaultSignalHandler.h: * wasm/WasmFormat.h: * wasm/WasmInstance.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::~Instance): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: Added. (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::module): (JSC::Wasm::Instance::codeBlock): (JSC::Wasm::Instance::memory): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::loadF32Global const): (JSC::Wasm::Instance::loadF64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::offsetOfCachedStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::~Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::offsetOfSize): * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationCallback): (JSC::Wasm::Module::validateSync): (JSC::Wasm::Module::validateAsync): (JSC::Wasm::Module::getOrCreateCodeBlock): (JSC::Wasm::Module::compileSync): (JSC::Wasm::Module::compileAsync): * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseTableHelper): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::OMGPlan): (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::isValid const): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::runCompletionTasks): (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmPlan.h: (JSC::Wasm::Plan::dontFinalize): * wasm/WasmSignature.cpp: * wasm/WasmSignature.h: * wasm/WasmTable.cpp: Added. (JSC::Wasm::Table::create): (JSC::Wasm::Table::~Table): (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h. (JSC::Wasm::Table::maximum const): (JSC::Wasm::Table::size const): (JSC::Wasm::Table::offsetOfSize): (JSC::Wasm::Table::offsetOfFunctions): (JSC::Wasm::Table::offsetOfInstances): (JSC::Wasm::Table::isValidSize): * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): (JSC::Wasm::Thunks::setThrowWasmException): (JSC::Wasm::Thunks::throwWasmException): * wasm/WasmThunks.h: * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::stopAllPlansForContext): * wasm/WasmWorklist.h: * wasm/js/JSToWasm.cpp: Added. (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/JSWebAssembly.cpp: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.cpp. * wasm/js/JSWebAssembly.h: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.h. * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::create): (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::context const): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::webAssemblyToJSCallee): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::offsetOfTail): (JSC::JSWebAssemblyInstance::importFunctionInfo): (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): (JSC::JSWebAssemblyInstance::offsetOfImportFunction): (JSC::JSWebAssemblyInstance::importFunction): (JSC::JSWebAssemblyInstance::internalMemory): (JSC::JSWebAssemblyInstance::wasmCodeBlock const): (JSC::JSWebAssemblyInstance::offsetOfWasmTable): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::offsetOfGlobals): (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): (JSC::JSWebAssemblyInstance::cachedStackLimit const): (JSC::JSWebAssemblyInstance::setCachedStackLimit): (JSC::JSWebAssemblyInstance::wasmMemory): (JSC::JSWebAssemblyInstance::wasmModule): (JSC::JSWebAssemblyInstance::allocationSize): (JSC::JSWebAssemblyInstance::module const): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::create): (JSC::JSWebAssemblyMemory::adopt): (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::moduleInformation const): (JSC::JSWebAssemblyModule::exportSymbolTable const): (JSC::JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace const): (JSC::JSWebAssemblyModule::callee const): (JSC::JSWebAssemblyModule::codeBlock): (JSC::JSWebAssemblyModule::module): * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::create): (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::visitChildren): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::getFunction): (JSC::JSWebAssemblyTable::clearFunction): (JSC::JSWebAssemblyTable::setFunction): * wasm/js/JSWebAssemblyTable.h: (JSC::JSWebAssemblyTable::isValidSize): (JSC::JSWebAssemblyTable::maximum const): (JSC::JSWebAssemblyTable::size const): (JSC::JSWebAssemblyTable::table): * wasm/js/WasmToJS.cpp: Copied from Source/JavaScriptCore/wasm/WasmBinding.cpp. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): (JSC::WebAssemblyModuleConstructor::createModule): * wasm/js/WebAssemblyModuleConstructor.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::webAssemblyCompileFunc): (JSC::instantiate): (JSC::compileAndInstantiate): (JSC::webAssemblyValidateFunc): * wasm/js/WebAssemblyTableConstructor.cpp: (JSC::constructJSWebAssemblyTable): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Source/WebCore: * ForwardingHeaders/wasm/WasmModule.h: Added. This used to be included in JSWebAssemblyModule.h. * bindings/js/SerializedScriptValue.cpp: Update postMessage code according to C++ API changes. Canonical link: https://commits.webkit.org/194750@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223738 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-20 02:23:29 +00:00
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#if ENABLE(WEBASSEMBLY)
#include "WasmFormat.h"
Adopt the new WebAssembly.Global system https://bugs.webkit.org/show_bug.cgi?id=186552 Reviewed by Keith Miller. JSTests: 1. Update spec-harness to accept newer tests. And we update several tests that does not work with the old harness. 2. Add WebAssembly.Global tests. * wasm/js-api/global-error.js: (assert.throws.new.WebAssembly.Module.bin): (new.WebAssembly.Module): (assert.throws): * wasm/js-api/global-external-init-from-import.js: * wasm/js-api/globals-export.js: * wasm/modules/js-wasm-global-namespace.js: (assert.throws): * wasm/modules/js-wasm-global.js: (assert.throws): * wasm/modules/wasm-import-wasm-export-i64-error.js: * wasm/references/anyref_globals.js: * wasm/references/func_ref.js: (assert.eq.instance.exports.fix): * wasm/spec-harness.js: (getGlobal): (let.console.log): * wasm/spec-harness/sync_index.js: Renamed from JSTests/wasm/spec-harness/index.js. (reinitializeRegistry.let.handler.get return): (module): * wasm/spec-tests/call.wast.js: * wasm/spec-tests/exports.wast.js: * wasm/spec-tests/globals.wast.js: * wasm/spec-tests/if.wast.js: * wasm/spec-tests/imports.wast.js: * wasm/spec-tests/linking.wast.js: * wasm/spec-tests/memory.wast.js: * wasm/stress/immutable-globals.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.assert.eq.instance.exports.getI32): (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.assert.eq): * wasm/stress/mutable-globals-cross.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.const.instance1): (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.const.instance2): * wasm/stress/mutable-globals.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.instance.exports.setI32AsI64): LayoutTests/imported/w3c: * web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any-expected.txt: * web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/constructor.any-expected.txt: * web-platform-tests/wasm/jsapi/global/constructor.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/toString.any-expected.txt: * web-platform-tests/wasm/jsapi/global/toString.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/value-set.any-expected.txt: * web-platform-tests/wasm/jsapi/global/value-set.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/valueOf.any-expected.txt: * web-platform-tests/wasm/jsapi/global/valueOf.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor.any-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/interface.any-expected.txt: * web-platform-tests/wasm/jsapi/interface.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/module/exports.any-expected.txt: * web-platform-tests/wasm/jsapi/module/exports.any.worker-expected.txt: Source/JavaScriptCore: This patch adds WebAssembly.Global implementation. It is already included in the Wasm spec (this means, it is not in staging right now: it was stage-4, and included in the spec). WebAssembly.Global is a wrapper object around "global" binding. This object can hold "immutable" and "mutable" global binding, and we can access Wasm globals through this object. Furthermore, we can share mutable global binding through this object across WebAssembly modules. To implement it efficiently, this patch introduces BindingMode to Wasm globals. If the mode is EmbeddedInInstance, we continue using the current existing mechanism. If the mode is Portable, we store a pointer to actual value in Wasm globals array in Wasm::Instance, so that we can access it through one additional dereference. And we mark all immutable globals as EmbeddedInInstance. If the binding is immutable, internally we do not need to have one binding. We can just continue using the current mechanism since users cannot observe whether immutable bindings' storage is shared or not. If the global is mutable, and it is exported outside of the module, we use Portable mode. So, all the previously used wasm global bindings are EmbeddedInInstance. Only newly added "mutable" "exported" bindings are Portable and requires one additional dereference. To access portable bindings efficiently, we add new Wasm bytecodes, `get_global_portable_binding`, `set_global_portable_binding`, and `set_global_ref_portable_binding`. This patch improves WPT wasm coverage significantly. * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/BytecodeList.rb: * heap/HeapCell.cpp: (JSC::keepAlive): (JSC::HeapCell::use const): Deleted. * heap/HeapCell.h: (JSC::keepAlive): (JSC::HeapCell::use const): * llint/WebAssembly.asm: * runtime/JSGlobalObject.cpp: * runtime/JSGlobalObject.h: * runtime/VM.cpp: (JSC::VM::VM): * runtime/VM.h: * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::getGlobal): (JSC::Wasm::AirIRGenerator::setGlobal): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::getGlobal): (JSC::Wasm::B3IRGenerator::setGlobal): * wasm/WasmFormat.h: * wasm/WasmGlobal.cpp: Added. (JSC::Wasm::Global::get const): (JSC::Wasm::Global::set): (JSC::Wasm::Global::visitAggregate): * wasm/WasmGlobal.h: Added. * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::linkGlobal): * wasm/WasmInstance.h: (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::globalsToBinding): (JSC::Wasm::Instance::getGlobalBinding): * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::getGlobal): (JSC::Wasm::LLIntGenerator::setGlobal): * wasm/WasmModuleInformation.h: * wasm/WasmOperations.cpp: (JSC::Wasm::operationWasmWriteBarrierSlowPath): * wasm/WasmOperations.h: * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseImport): (JSC::Wasm::SectionParser::parseGlobal): (JSC::Wasm::SectionParser::parseExport): (JSC::Wasm::SectionParser::parseInitExpr): (JSC::Wasm::SectionParser::parseGlobalType): * wasm/WasmSectionParser.h: * wasm/WasmSlowPaths.cpp: (JSC::LLInt::WASM_SLOW_PATH_DECL): * wasm/WasmSlowPaths.h: * wasm/WasmValidate.cpp: (JSC::Wasm::Validate::setGlobal): * wasm/js/JSWebAssembly.cpp: * wasm/js/JSWebAssemblyGlobal.cpp: Added. (JSC::JSWebAssemblyGlobal::create): (JSC::JSWebAssemblyGlobal::createStructure): (JSC::JSWebAssemblyGlobal::JSWebAssemblyGlobal): (JSC::JSWebAssemblyGlobal::finishCreation): (JSC::JSWebAssemblyGlobal::destroy): (JSC::JSWebAssemblyGlobal::visitChildren): * wasm/js/JSWebAssemblyGlobal.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/JSWebAssemblyInstance.h: * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::destroy): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.h: * wasm/js/WebAssemblyGlobalConstructor.cpp: Added. (JSC::constructJSWebAssemblyGlobal): (JSC::callJSWebAssemblyGlobal): (JSC::WebAssemblyGlobalConstructor::create): (JSC::WebAssemblyGlobalConstructor::createStructure): (JSC::WebAssemblyGlobalConstructor::finishCreation): (JSC::WebAssemblyGlobalConstructor::WebAssemblyGlobalConstructor): * wasm/js/WebAssemblyGlobalConstructor.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/WebAssemblyGlobalPrototype.cpp: Added. (JSC::getGlobal): (JSC::webAssemblyGlobalProtoFuncValueOf): (JSC::webAssemblyGlobalProtoGetterFuncValue): (JSC::webAssemblyGlobalProtoSetterFuncValue): (JSC::WebAssemblyGlobalPrototype::create): (JSC::WebAssemblyGlobalPrototype::createStructure): (JSC::WebAssemblyGlobalPrototype::finishCreation): (JSC::WebAssemblyGlobalPrototype::WebAssemblyGlobalPrototype): * wasm/js/WebAssemblyGlobalPrototype.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): Canonical link: https://commits.webkit.org/218038@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@253074 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-12-04 01:36:56 +00:00
#include "WasmGlobal.h"
WebAssembly: no VM / JS version of everything but Instance https://bugs.webkit.org/show_bug.cgi?id=177473 Reviewed by Filip Pizlo, Saam Barati. JSTests: - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. * wasm/js-api/memory-grow.js: (assertEq): * wasm/js-api/table.js: (assert.throws): Source/JavaScriptCore: This change entails cleaning up and splitting a bunch of code which we had intertwined between C++ classes which represent JS objects, and pure C++ implementation objects. This specific change goes most of the way towards allowing JSC's WebAssembly to work without VM / JS, up to but excluding JSWebAssemblyInstance (there's Wasm::Instance, but it's not *the* thing yet). Because of this we still have a few FIXME identifying places that need to change. A follow-up change will go the rest of the way. I went about this change in the simplest way possible: grep the JavaScriptCore/wasm directory for "JS[^C_]" as well as "VM" and exclude the /js/ sub-directory (which contains the JS implementation of WebAssembly). None of this change removes the need for a JIT entitlement to be able to use WebAssembly. We don't have an interpreter, the process therefore still needs to be allowed to JIT to use these pure-C++ APIs. Interesting things to note: - Remove VM from Plan and associated places. It can just live as a capture in the callback lambda if it's needed. - Wasm::Memory shouldn't require a VM. It was only used to ask the GC to collect. We now instead pass two lambdas at construction time for this purpose: one to notify of memory pressure, and the other to ask for syncrhonous memory reclamation. This allows whoever creates the memory to dictate how to react to both these cases, and for a JS embedding that's to call the GC (async or sync, respectively). - Move grow logic from JSWebAssemblyMemory to Wasm::Memory::grow. Use Expected there, with an enum class for failure types. - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. - When generating the grow_memory opcode, no need to get the VM. Instead, reach directly for Wasm::Memory and grow it. - JSWebAssemblyMemory::grow can now always throw on failure, because it's only ever called from JS (not from grow_memory as before). - Wasm::Memory now takes a callback for successful growth. This allows JS wrappers to register themselves when growth succeeds without Wasm::Memory knowning anything about JS. It'll also allow creating a list of callbacks for when we add thread support (we'll want to notify many wrappers, all under a lock). - Wasm::Memory is now back to being the source of truth about address / size, used directly by generated code instead of JSWebAssemblyMemory. - Move wasmToJS from the general WasmBinding header to its own header under wasm/js. It's only used by wasm/js/JSWebAssemblyCodeBlock.cpp, and uses VM, and therefore isn't general WebAssembly. - Make Wasm::Context an actual type (just a struct holding a JSWebAssemlyInstance for now) instead of an alias for that. Notably this doesn't add anything to the Context and doesn't change what actually gets passed around in JIT code (fast TLS or registers) because these changes potentially impact performance. The entire purpose of this change is to allow passing Wasm::Context around without having to know about VM. Since VM contains a Wasm::Context the JS embedding is effectively the same, but with this setup a non-JS embedding is much better off. - Move JSWebAssembly into the JS folder. - OMGPlan: use Wasm::CodeBlock directly instead of JSWebAssemblyCodeBlock. - wasm->JS stubs are now on the instance's tail as raw pointers, instead of being on JSWebAssemblyCodeBlock, and are now called wasm->Embedder stubs. The owned reference is still on JSWebAssemblyCodeBlock, and is still called wasm->JS stub. This move means that the embedder must, after creating a Wasm::CodeBlock, somehow create the stubs to call back into the embedder. This removes an indirection in the generated code because the B3 IR generator now reaches into the instance instead of JSWebAssemblyCodeBlock. - Move more CodeBlock things. Compilation completion is now marked by its own atomic<bool> flag instead of a nullptr plan: that required using a lock, and was causing a deadlock in stack-trace.js because before my changes JSWebAssemblyCodeBlock did its own completion checking separately from Wasm::CodeBlock, without getting the lock. Now that everything points to Wasm::CodeBlock and there's no cached completion marker, the lock was being acquired in a sanity-check assertion. - Embedder -> Wasm wrappers are now generated through a function that's passed in at compilation time, instead of being hard-coded as a JS -> Wasm wrapper. - WasmMemory doens't need to know about fault handling thunks. Only the IR generator should know, and should make sure that the exception throwing thunk is generated if any memory is present (note: with signal handling not all of them generate an exception check). - Make exception throwing pluggable: instead of having a hard-coded JS-specific lambda we now have a regular C++ function being called from JIT code when a WebAssembly exception is thrown. This allows any embedder to get called as they wish. For now a process can only have a single of these functions (i.e. only one embedder per process) because the trap handler is a singleton. That can be fixed in in #177475. - Create WasmEmbedder.h where all embedder plugging will live. - Split up JSWebAssemblyTable into Wasm::Table which is refcounted. JSWebAssemblyTable now only contains the JS functions in the table, and Wasm::Table is what's used by the JIT code to lookup where to call and do the instance check (for context switch). Note that this creates an extra allocation for all the instances in Wasm::Table, and in exchange removes an indirection in JIT code because the instance used to be obtained off of the JS function. Also note that it's the embedder than keeps the instances alive, not Wasm::Table (which holds a dumb pointer to the instance), because doing otherwise would cause reference cycles. - Add WasmInstance. It doesn't do much for now, owns globals. - JSWebAssembly instance now doesn't just contain the imported functions as JSObjects, it also has the corresponding import's instance and wasm entrypoint. This triples the space allocated per instance's imported function, but there shouldn't be that many imports. This has two upsides: it creates smaller and faster code, and makes is easier to disassociate embedder-specific things from embedder-neutral things. The small / faster win is in two places: B3 IR generator only needs offsetOfImportFunction for the call opcode (when the called index is an import) to know whether the import is wasm->wasm or wasm->embedder (this isn't known at compile-time because it's dependent on the import object), this is now done by seeing if that import function has an associated target instance (only wasm->wasm does); the other place is wasmBinding which uses offsetOfImportFunction to figure out the wasm->wasm target instance, and then gets WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation to do a tail call. The disassociation comes because the target instance can be Wasm::Instance once we change what the Context is, and WasmEntrypointLoadLocation is already embedder-independent. As a next step I can move this tail allocation from JSWebAssemblyInstance to Wasm::Instance, and leave importFunction in as an opaque pointer which is embedder-specific, and in JS will remain WriteBarrier<JSObject>. - Rename VMEntryFrame to EntryFrame, and in many places pass a pointer to it around instead of VM. This is a first step in allowing entry frames which aren't stored on VM, but which are instead stored in an embedder-specific location. That change won't really affect JS except through code churn, but will allow WebAssembly to use some machinery in a generic manner without having a VM. * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * debugger/Debugger.cpp: (JSC::Debugger::stepOutOfFunction): (JSC::Debugger::returnEvent): (JSC::Debugger::unwindEvent): (JSC::Debugger::didExecuteProgram): * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::compileExceptionHandlers): * dfg/DFGOSREntry.cpp: (JSC::DFG::prepareOSREntry): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::compileOSRExit): (JSC::DFG::OSRExit::compileExit): * dfg/DFGThunks.cpp: (JSC::DFG::osrEntryThunkGenerator): * ftl/FTLCompile.cpp: (JSC::FTL::compile): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::lower): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): (JSC::CallFrame::callerFrame): (JSC::CallFrame::unsafeCallerFrame): * interpreter/CallFrame.h: (JSC::ExecState::callerFrame const): (JSC::ExecState::callerFrameOrEntryFrame const): (JSC::ExecState::unsafeCallerFrameOrEntryFrame const): * interpreter/FrameTracers.h: (JSC::NativeCallFrameTracer::NativeCallFrameTracer): (JSC::NativeCallFrameTracerWithRestore::NativeCallFrameTracerWithRestore): (JSC::NativeCallFrameTracerWithRestore::~NativeCallFrameTracerWithRestore): * interpreter/Interpreter.cpp: (JSC::UnwindFunctor::operator() const): (JSC::UnwindFunctor::copyCalleeSavesToEntryFrameCalleeSavesBuffer const): (JSC::Interpreter::unwind): * interpreter/StackVisitor.cpp: (JSC::StackVisitor::StackVisitor): (JSC::StackVisitor::gotoNextFrame): (JSC::StackVisitor::readNonInlinedFrame): (JSC::StackVisitor::Frame::dump const): * interpreter/StackVisitor.h: (JSC::StackVisitor::Frame::callerIsEntryFrame const): * interpreter/VMEntryRecord.h: (JSC::VMEntryRecord::prevTopEntryFrame): (JSC::VMEntryRecord::unsafePrevTopEntryFrame): (JSC::EntryFrame::vmEntryRecordOffset): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::restoreCalleeSavesFromEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::loadWasmContextInstance): (JSC::AssemblyHelpers::storeWasmContextInstance): (JSC::AssemblyHelpers::loadWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::storeWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBufferImpl): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::copyCalleeSavesToVMEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer): * jit/JIT.cpp: (JSC::JIT::emitEnterOptimizationCheck): (JSC::JIT::privateCompileExceptionHandlers): * jit/JITExceptions.cpp: (JSC::genericUnwind): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): (JSC::JIT::emitSlow_op_loop_hint): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): * jit/JITOperations.cpp: * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::nativeForGenerator): * jsc.cpp: (functionDumpCallFrame): * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LLIntThunks.cpp: (JSC::vmEntryRecord): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/Options.cpp: (JSC::recomputeDependentOptions): * runtime/Options.h: * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::FrameWalker): (JSC::FrameWalker::advanceToParentFrame): (JSC::SamplingProfiler::processUnverifiedStackTraces): * runtime/ThrowScope.cpp: (JSC::ThrowScope::~ThrowScope): * runtime/VM.cpp: (JSC::VM::VM): (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::topEntryFrameOffset): * runtime/VMTraps.cpp: (JSC::isSaneFrame): (JSC::VMTraps::tryInstallTrapBreakpoints): (JSC::VMTraps::invalidateCodeBlocksOnStack): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWasmContextInstance): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::parseAndCompile): * wasm/WasmB3IRGenerator.h: * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::BBQPlan): (JSC::Wasm::BBQPlan::compileFunctions): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBBQPlanInlines.h: (JSC::Wasm::BBQPlan::initializeCallees): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmBinding.h: * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::create): (JSC::Wasm::CodeBlock::CodeBlock): (JSC::Wasm::CodeBlock::compileAsync): (JSC::Wasm::CodeBlock::setCompilationFinished): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::offsetOfImportStubs): (JSC::Wasm::CodeBlock::allocationSize): (JSC::Wasm::CodeBlock::importWasmToEmbedderStub): (JSC::Wasm::CodeBlock::offsetOfImportWasmToEmbedderStub): (JSC::Wasm::CodeBlock::wasmToJSCallStubForImport): (JSC::Wasm::CodeBlock::compilationFinished): (JSC::Wasm::CodeBlock::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): * wasm/WasmContext.cpp: (JSC::Wasm::Context::useFastTLS): (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: Copied from Source/JavaScriptCore/wasm/WasmContext.h. * wasm/WasmFaultSignalHandler.cpp: * wasm/WasmFaultSignalHandler.h: * wasm/WasmFormat.h: * wasm/WasmInstance.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::~Instance): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: Added. (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::module): (JSC::Wasm::Instance::codeBlock): (JSC::Wasm::Instance::memory): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::loadF32Global const): (JSC::Wasm::Instance::loadF64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::offsetOfCachedStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::~Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::offsetOfSize): * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationCallback): (JSC::Wasm::Module::validateSync): (JSC::Wasm::Module::validateAsync): (JSC::Wasm::Module::getOrCreateCodeBlock): (JSC::Wasm::Module::compileSync): (JSC::Wasm::Module::compileAsync): * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseTableHelper): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::OMGPlan): (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::isValid const): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::runCompletionTasks): (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmPlan.h: (JSC::Wasm::Plan::dontFinalize): * wasm/WasmSignature.cpp: * wasm/WasmSignature.h: * wasm/WasmTable.cpp: Added. (JSC::Wasm::Table::create): (JSC::Wasm::Table::~Table): (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h. (JSC::Wasm::Table::maximum const): (JSC::Wasm::Table::size const): (JSC::Wasm::Table::offsetOfSize): (JSC::Wasm::Table::offsetOfFunctions): (JSC::Wasm::Table::offsetOfInstances): (JSC::Wasm::Table::isValidSize): * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): (JSC::Wasm::Thunks::setThrowWasmException): (JSC::Wasm::Thunks::throwWasmException): * wasm/WasmThunks.h: * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::stopAllPlansForContext): * wasm/WasmWorklist.h: * wasm/js/JSToWasm.cpp: Added. (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/JSWebAssembly.cpp: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.cpp. * wasm/js/JSWebAssembly.h: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.h. * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::create): (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::context const): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::webAssemblyToJSCallee): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::offsetOfTail): (JSC::JSWebAssemblyInstance::importFunctionInfo): (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): (JSC::JSWebAssemblyInstance::offsetOfImportFunction): (JSC::JSWebAssemblyInstance::importFunction): (JSC::JSWebAssemblyInstance::internalMemory): (JSC::JSWebAssemblyInstance::wasmCodeBlock const): (JSC::JSWebAssemblyInstance::offsetOfWasmTable): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::offsetOfGlobals): (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): (JSC::JSWebAssemblyInstance::cachedStackLimit const): (JSC::JSWebAssemblyInstance::setCachedStackLimit): (JSC::JSWebAssemblyInstance::wasmMemory): (JSC::JSWebAssemblyInstance::wasmModule): (JSC::JSWebAssemblyInstance::allocationSize): (JSC::JSWebAssemblyInstance::module const): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::create): (JSC::JSWebAssemblyMemory::adopt): (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::moduleInformation const): (JSC::JSWebAssemblyModule::exportSymbolTable const): (JSC::JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace const): (JSC::JSWebAssemblyModule::callee const): (JSC::JSWebAssemblyModule::codeBlock): (JSC::JSWebAssemblyModule::module): * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::create): (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::visitChildren): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::getFunction): (JSC::JSWebAssemblyTable::clearFunction): (JSC::JSWebAssemblyTable::setFunction): * wasm/js/JSWebAssemblyTable.h: (JSC::JSWebAssemblyTable::isValidSize): (JSC::JSWebAssemblyTable::maximum const): (JSC::JSWebAssemblyTable::size const): (JSC::JSWebAssemblyTable::table): * wasm/js/WasmToJS.cpp: Copied from Source/JavaScriptCore/wasm/WasmBinding.cpp. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): (JSC::WebAssemblyModuleConstructor::createModule): * wasm/js/WebAssemblyModuleConstructor.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::webAssemblyCompileFunc): (JSC::instantiate): (JSC::compileAndInstantiate): (JSC::webAssemblyValidateFunc): * wasm/js/WebAssemblyTableConstructor.cpp: (JSC::constructJSWebAssemblyTable): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Source/WebCore: * ForwardingHeaders/wasm/WasmModule.h: Added. This used to be included in JSWebAssemblyModule.h. * bindings/js/SerializedScriptValue.cpp: Update postMessage code according to C++ API changes. Canonical link: https://commits.webkit.org/194750@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223738 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-20 02:23:29 +00:00
#include "WasmMemory.h"
#include "WasmModule.h"
#include "WasmTable.h"
[WASM-References] Support Anyref in globals https://bugs.webkit.org/show_bug.cgi?id=198102 Reviewed by Saam Barati. JSTests: Add test for anyrefs in globals, as well as adding a new RefNull initExpr for Builder. * wasm/Builder.js: (export.default.Builder.prototype._registerSectionBuilders.const.section.in.WASM.description.section.switch.section.case.string_appeared_here.this.section): * wasm/Builder_WebAssemblyBinary.js: (const.putInitExpr): * wasm/references/anyref_globals.js: Added. (GetGlobal.0.End.End.WebAssembly): (5.doGCSet): (doGCTest): (doGCSet.doGCTest.let.count.0.doBarrierSet): Source/JavaScriptCore: Support anyref for globals, imports and exports. This adds code in B3 and Air to emit a write barrier on the JSWebAssemblyWrapper whenever an anyref global is set. This also fixes a small bug in emitCCall for air where it adds code to the wrong block. * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::emitCCall): (JSC::Wasm::AirIRGenerator::moveOpForValueType): (JSC::Wasm::AirIRGenerator::setGlobal): (JSC::Wasm::AirIRGenerator::emitWriteBarrierForJSWrapper): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::setGlobal): (JSC::Wasm::B3IRGenerator::emitWriteBarrierForJSWrapper): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::setGlobal): * wasm/WasmInstance.h: (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::shouldMarkGlobal): (JSC::Wasm::Instance::numGlobals const): * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseInitExpr): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): Canonical link: https://commits.webkit.org/212290@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245765 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-25 00:51:21 +00:00
#include "WriteBarrier.h"
#include <wtf/BitVector.h>
WebAssembly: no VM / JS version of everything but Instance https://bugs.webkit.org/show_bug.cgi?id=177473 Reviewed by Filip Pizlo, Saam Barati. JSTests: - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. * wasm/js-api/memory-grow.js: (assertEq): * wasm/js-api/table.js: (assert.throws): Source/JavaScriptCore: This change entails cleaning up and splitting a bunch of code which we had intertwined between C++ classes which represent JS objects, and pure C++ implementation objects. This specific change goes most of the way towards allowing JSC's WebAssembly to work without VM / JS, up to but excluding JSWebAssemblyInstance (there's Wasm::Instance, but it's not *the* thing yet). Because of this we still have a few FIXME identifying places that need to change. A follow-up change will go the rest of the way. I went about this change in the simplest way possible: grep the JavaScriptCore/wasm directory for "JS[^C_]" as well as "VM" and exclude the /js/ sub-directory (which contains the JS implementation of WebAssembly). None of this change removes the need for a JIT entitlement to be able to use WebAssembly. We don't have an interpreter, the process therefore still needs to be allowed to JIT to use these pure-C++ APIs. Interesting things to note: - Remove VM from Plan and associated places. It can just live as a capture in the callback lambda if it's needed. - Wasm::Memory shouldn't require a VM. It was only used to ask the GC to collect. We now instead pass two lambdas at construction time for this purpose: one to notify of memory pressure, and the other to ask for syncrhonous memory reclamation. This allows whoever creates the memory to dictate how to react to both these cases, and for a JS embedding that's to call the GC (async or sync, respectively). - Move grow logic from JSWebAssemblyMemory to Wasm::Memory::grow. Use Expected there, with an enum class for failure types. - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. - When generating the grow_memory opcode, no need to get the VM. Instead, reach directly for Wasm::Memory and grow it. - JSWebAssemblyMemory::grow can now always throw on failure, because it's only ever called from JS (not from grow_memory as before). - Wasm::Memory now takes a callback for successful growth. This allows JS wrappers to register themselves when growth succeeds without Wasm::Memory knowning anything about JS. It'll also allow creating a list of callbacks for when we add thread support (we'll want to notify many wrappers, all under a lock). - Wasm::Memory is now back to being the source of truth about address / size, used directly by generated code instead of JSWebAssemblyMemory. - Move wasmToJS from the general WasmBinding header to its own header under wasm/js. It's only used by wasm/js/JSWebAssemblyCodeBlock.cpp, and uses VM, and therefore isn't general WebAssembly. - Make Wasm::Context an actual type (just a struct holding a JSWebAssemlyInstance for now) instead of an alias for that. Notably this doesn't add anything to the Context and doesn't change what actually gets passed around in JIT code (fast TLS or registers) because these changes potentially impact performance. The entire purpose of this change is to allow passing Wasm::Context around without having to know about VM. Since VM contains a Wasm::Context the JS embedding is effectively the same, but with this setup a non-JS embedding is much better off. - Move JSWebAssembly into the JS folder. - OMGPlan: use Wasm::CodeBlock directly instead of JSWebAssemblyCodeBlock. - wasm->JS stubs are now on the instance's tail as raw pointers, instead of being on JSWebAssemblyCodeBlock, and are now called wasm->Embedder stubs. The owned reference is still on JSWebAssemblyCodeBlock, and is still called wasm->JS stub. This move means that the embedder must, after creating a Wasm::CodeBlock, somehow create the stubs to call back into the embedder. This removes an indirection in the generated code because the B3 IR generator now reaches into the instance instead of JSWebAssemblyCodeBlock. - Move more CodeBlock things. Compilation completion is now marked by its own atomic<bool> flag instead of a nullptr plan: that required using a lock, and was causing a deadlock in stack-trace.js because before my changes JSWebAssemblyCodeBlock did its own completion checking separately from Wasm::CodeBlock, without getting the lock. Now that everything points to Wasm::CodeBlock and there's no cached completion marker, the lock was being acquired in a sanity-check assertion. - Embedder -> Wasm wrappers are now generated through a function that's passed in at compilation time, instead of being hard-coded as a JS -> Wasm wrapper. - WasmMemory doens't need to know about fault handling thunks. Only the IR generator should know, and should make sure that the exception throwing thunk is generated if any memory is present (note: with signal handling not all of them generate an exception check). - Make exception throwing pluggable: instead of having a hard-coded JS-specific lambda we now have a regular C++ function being called from JIT code when a WebAssembly exception is thrown. This allows any embedder to get called as they wish. For now a process can only have a single of these functions (i.e. only one embedder per process) because the trap handler is a singleton. That can be fixed in in #177475. - Create WasmEmbedder.h where all embedder plugging will live. - Split up JSWebAssemblyTable into Wasm::Table which is refcounted. JSWebAssemblyTable now only contains the JS functions in the table, and Wasm::Table is what's used by the JIT code to lookup where to call and do the instance check (for context switch). Note that this creates an extra allocation for all the instances in Wasm::Table, and in exchange removes an indirection in JIT code because the instance used to be obtained off of the JS function. Also note that it's the embedder than keeps the instances alive, not Wasm::Table (which holds a dumb pointer to the instance), because doing otherwise would cause reference cycles. - Add WasmInstance. It doesn't do much for now, owns globals. - JSWebAssembly instance now doesn't just contain the imported functions as JSObjects, it also has the corresponding import's instance and wasm entrypoint. This triples the space allocated per instance's imported function, but there shouldn't be that many imports. This has two upsides: it creates smaller and faster code, and makes is easier to disassociate embedder-specific things from embedder-neutral things. The small / faster win is in two places: B3 IR generator only needs offsetOfImportFunction for the call opcode (when the called index is an import) to know whether the import is wasm->wasm or wasm->embedder (this isn't known at compile-time because it's dependent on the import object), this is now done by seeing if that import function has an associated target instance (only wasm->wasm does); the other place is wasmBinding which uses offsetOfImportFunction to figure out the wasm->wasm target instance, and then gets WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation to do a tail call. The disassociation comes because the target instance can be Wasm::Instance once we change what the Context is, and WasmEntrypointLoadLocation is already embedder-independent. As a next step I can move this tail allocation from JSWebAssemblyInstance to Wasm::Instance, and leave importFunction in as an opaque pointer which is embedder-specific, and in JS will remain WriteBarrier<JSObject>. - Rename VMEntryFrame to EntryFrame, and in many places pass a pointer to it around instead of VM. This is a first step in allowing entry frames which aren't stored on VM, but which are instead stored in an embedder-specific location. That change won't really affect JS except through code churn, but will allow WebAssembly to use some machinery in a generic manner without having a VM. * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * debugger/Debugger.cpp: (JSC::Debugger::stepOutOfFunction): (JSC::Debugger::returnEvent): (JSC::Debugger::unwindEvent): (JSC::Debugger::didExecuteProgram): * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::compileExceptionHandlers): * dfg/DFGOSREntry.cpp: (JSC::DFG::prepareOSREntry): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::compileOSRExit): (JSC::DFG::OSRExit::compileExit): * dfg/DFGThunks.cpp: (JSC::DFG::osrEntryThunkGenerator): * ftl/FTLCompile.cpp: (JSC::FTL::compile): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::lower): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): (JSC::CallFrame::callerFrame): (JSC::CallFrame::unsafeCallerFrame): * interpreter/CallFrame.h: (JSC::ExecState::callerFrame const): (JSC::ExecState::callerFrameOrEntryFrame const): (JSC::ExecState::unsafeCallerFrameOrEntryFrame const): * interpreter/FrameTracers.h: (JSC::NativeCallFrameTracer::NativeCallFrameTracer): (JSC::NativeCallFrameTracerWithRestore::NativeCallFrameTracerWithRestore): (JSC::NativeCallFrameTracerWithRestore::~NativeCallFrameTracerWithRestore): * interpreter/Interpreter.cpp: (JSC::UnwindFunctor::operator() const): (JSC::UnwindFunctor::copyCalleeSavesToEntryFrameCalleeSavesBuffer const): (JSC::Interpreter::unwind): * interpreter/StackVisitor.cpp: (JSC::StackVisitor::StackVisitor): (JSC::StackVisitor::gotoNextFrame): (JSC::StackVisitor::readNonInlinedFrame): (JSC::StackVisitor::Frame::dump const): * interpreter/StackVisitor.h: (JSC::StackVisitor::Frame::callerIsEntryFrame const): * interpreter/VMEntryRecord.h: (JSC::VMEntryRecord::prevTopEntryFrame): (JSC::VMEntryRecord::unsafePrevTopEntryFrame): (JSC::EntryFrame::vmEntryRecordOffset): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::restoreCalleeSavesFromEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::loadWasmContextInstance): (JSC::AssemblyHelpers::storeWasmContextInstance): (JSC::AssemblyHelpers::loadWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::storeWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBufferImpl): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::copyCalleeSavesToVMEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer): * jit/JIT.cpp: (JSC::JIT::emitEnterOptimizationCheck): (JSC::JIT::privateCompileExceptionHandlers): * jit/JITExceptions.cpp: (JSC::genericUnwind): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): (JSC::JIT::emitSlow_op_loop_hint): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): * jit/JITOperations.cpp: * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::nativeForGenerator): * jsc.cpp: (functionDumpCallFrame): * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LLIntThunks.cpp: (JSC::vmEntryRecord): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/Options.cpp: (JSC::recomputeDependentOptions): * runtime/Options.h: * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::FrameWalker): (JSC::FrameWalker::advanceToParentFrame): (JSC::SamplingProfiler::processUnverifiedStackTraces): * runtime/ThrowScope.cpp: (JSC::ThrowScope::~ThrowScope): * runtime/VM.cpp: (JSC::VM::VM): (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::topEntryFrameOffset): * runtime/VMTraps.cpp: (JSC::isSaneFrame): (JSC::VMTraps::tryInstallTrapBreakpoints): (JSC::VMTraps::invalidateCodeBlocksOnStack): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWasmContextInstance): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::parseAndCompile): * wasm/WasmB3IRGenerator.h: * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::BBQPlan): (JSC::Wasm::BBQPlan::compileFunctions): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBBQPlanInlines.h: (JSC::Wasm::BBQPlan::initializeCallees): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmBinding.h: * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::create): (JSC::Wasm::CodeBlock::CodeBlock): (JSC::Wasm::CodeBlock::compileAsync): (JSC::Wasm::CodeBlock::setCompilationFinished): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::offsetOfImportStubs): (JSC::Wasm::CodeBlock::allocationSize): (JSC::Wasm::CodeBlock::importWasmToEmbedderStub): (JSC::Wasm::CodeBlock::offsetOfImportWasmToEmbedderStub): (JSC::Wasm::CodeBlock::wasmToJSCallStubForImport): (JSC::Wasm::CodeBlock::compilationFinished): (JSC::Wasm::CodeBlock::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): * wasm/WasmContext.cpp: (JSC::Wasm::Context::useFastTLS): (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: Copied from Source/JavaScriptCore/wasm/WasmContext.h. * wasm/WasmFaultSignalHandler.cpp: * wasm/WasmFaultSignalHandler.h: * wasm/WasmFormat.h: * wasm/WasmInstance.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::~Instance): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: Added. (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::module): (JSC::Wasm::Instance::codeBlock): (JSC::Wasm::Instance::memory): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::loadF32Global const): (JSC::Wasm::Instance::loadF64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::offsetOfCachedStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::~Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::offsetOfSize): * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationCallback): (JSC::Wasm::Module::validateSync): (JSC::Wasm::Module::validateAsync): (JSC::Wasm::Module::getOrCreateCodeBlock): (JSC::Wasm::Module::compileSync): (JSC::Wasm::Module::compileAsync): * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseTableHelper): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::OMGPlan): (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::isValid const): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::runCompletionTasks): (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmPlan.h: (JSC::Wasm::Plan::dontFinalize): * wasm/WasmSignature.cpp: * wasm/WasmSignature.h: * wasm/WasmTable.cpp: Added. (JSC::Wasm::Table::create): (JSC::Wasm::Table::~Table): (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h. (JSC::Wasm::Table::maximum const): (JSC::Wasm::Table::size const): (JSC::Wasm::Table::offsetOfSize): (JSC::Wasm::Table::offsetOfFunctions): (JSC::Wasm::Table::offsetOfInstances): (JSC::Wasm::Table::isValidSize): * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): (JSC::Wasm::Thunks::setThrowWasmException): (JSC::Wasm::Thunks::throwWasmException): * wasm/WasmThunks.h: * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::stopAllPlansForContext): * wasm/WasmWorklist.h: * wasm/js/JSToWasm.cpp: Added. (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/JSWebAssembly.cpp: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.cpp. * wasm/js/JSWebAssembly.h: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.h. * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::create): (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::context const): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::webAssemblyToJSCallee): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::offsetOfTail): (JSC::JSWebAssemblyInstance::importFunctionInfo): (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): (JSC::JSWebAssemblyInstance::offsetOfImportFunction): (JSC::JSWebAssemblyInstance::importFunction): (JSC::JSWebAssemblyInstance::internalMemory): (JSC::JSWebAssemblyInstance::wasmCodeBlock const): (JSC::JSWebAssemblyInstance::offsetOfWasmTable): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::offsetOfGlobals): (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): (JSC::JSWebAssemblyInstance::cachedStackLimit const): (JSC::JSWebAssemblyInstance::setCachedStackLimit): (JSC::JSWebAssemblyInstance::wasmMemory): (JSC::JSWebAssemblyInstance::wasmModule): (JSC::JSWebAssemblyInstance::allocationSize): (JSC::JSWebAssemblyInstance::module const): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::create): (JSC::JSWebAssemblyMemory::adopt): (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::moduleInformation const): (JSC::JSWebAssemblyModule::exportSymbolTable const): (JSC::JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace const): (JSC::JSWebAssemblyModule::callee const): (JSC::JSWebAssemblyModule::codeBlock): (JSC::JSWebAssemblyModule::module): * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::create): (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::visitChildren): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::getFunction): (JSC::JSWebAssemblyTable::clearFunction): (JSC::JSWebAssemblyTable::setFunction): * wasm/js/JSWebAssemblyTable.h: (JSC::JSWebAssemblyTable::isValidSize): (JSC::JSWebAssemblyTable::maximum const): (JSC::JSWebAssemblyTable::size const): (JSC::JSWebAssemblyTable::table): * wasm/js/WasmToJS.cpp: Copied from Source/JavaScriptCore/wasm/WasmBinding.cpp. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): (JSC::WebAssemblyModuleConstructor::createModule): * wasm/js/WebAssemblyModuleConstructor.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::webAssemblyCompileFunc): (JSC::instantiate): (JSC::compileAndInstantiate): (JSC::webAssemblyValidateFunc): * wasm/js/WebAssemblyTableConstructor.cpp: (JSC::constructJSWebAssemblyTable): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Source/WebCore: * ForwardingHeaders/wasm/WasmModule.h: Added. This used to be included in JSWebAssemblyModule.h. * bindings/js/SerializedScriptValue.cpp: Update postMessage code according to C++ API changes. Canonical link: https://commits.webkit.org/194750@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223738 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-20 02:23:29 +00:00
#include <wtf/RefPtr.h>
#include <wtf/ThreadSafeRefCounted.h>
Add support for the Wasm multi-value proposal https://bugs.webkit.org/show_bug.cgi?id=202250 Reviewed by Saam Barati. JSTests: This patch adds a new way to run stress tests via the .wat text format. By attaching an asm.js compiled version of the wabt tool we can easily create wat files programatically and convert them into a wasm blob to compile. To make this easy there is a wabt-wrapper.js module file that exports two useful functions that correspond to WebAssembly.compile and WebAssembly.instantiate. * wasm.yaml: * wasm/function-tests/if-no-else-non-void.js: * wasm/js-api/web-assembly-instantiate.js: (assert.asyncTest.async.test): (assert.asyncTest): * wasm/libwabt.js: Added. (WabtModule): (set get if): * wasm/references/func_ref.js: * wasm/references/validation.js: (assert.throws): * wasm/spec-harness/index.js: * wasm/spec-tests/block.wast.js: * wasm/spec-tests/br.wast.js: * wasm/spec-tests/br_if.wast.js: * wasm/spec-tests/call.wast.js: * wasm/spec-tests/call_indirect.wast.js: * wasm/spec-tests/func.wast.js: * wasm/spec-tests/if.wast.js: * wasm/spec-tests/loop.wast.js: * wasm/spec-tests/type.wast.js: * wasm/stress/js-wasm-call-many-return-types-on-stack-no-args.js: Added. (buildWat): * wasm/stress/js-wasm-js-varying-arities.js: Added. (paramForwarder): * wasm/stress/wasm-js-call-many-return-types-on-stack-no-args.js: Added. (buildWat): * wasm/stress/wasm-js-multi-value-exception-in-iterator.js: Added. (buildWat.throwError): (buildWat.throwErrorInIterator): (buildWat.tooManyValues): (buildWat.tooFewValues): (buildWat): * wasm/stress/wasm-wasm-call-indirect-many-return-types-on-stack.js: Added. (buildWat): * wasm/stress/wasm-wasm-call-many-return-types-on-stack-no-args.js: Added. (buildWat): * wasm/wabt-wrapper.js: Added. (export.compile): * wasm/wast-tests/br-if-at-end-of-block.wasm: Added. * wasm/wast-tests/br-if-at-end-of-block.wast: Added. * wasm/wast-tests/harness.js: (async.runWasmFile): * wasm/wast-tests/single-param-loop-signature.wasm: Added. * wasm/wast-tests/single-param-loop-signature.wast: Added. Source/JavaScriptCore: The wasm multi-value proposal makes two major changes to the spec. The first is that functions may now return more than one value across calls. When calling to/from JS, if there is more than one return type we return/receive a JSArray/Iterable, respectively. In the Wasm calls JS case, if the iteratable object does not vend the exact number of objects expected by the signature an error is thrown. The second major change in the multi-value proposal allows blocks to have any signature type. This works in a backwards compatible way by exploiting the fact that the old value-type thunk signatures (where the block takes no arguments and returns just the value type i.e. [] -> [type]) were always encoded as a negative number. If a block has a function signature, it is encoded as a positive index into the type section. When a block has a function signature type then the values from the enclosing stack are popped off that stack and added to the new block's stack. In the case of a br/br_if to a Loop block the "argument" values should be on the brancher's stack. The biggest change in this patch is stripping down the WasmCallingConventions file into one simpler API that just tells you where the each argument should be located. It also now handles adding or subtracting sizeof(CallerFrameAndPC) depending on whether you are caller or callee. Additionally, when computing locations for the callee it returns a B3::ValueRep that has the offsetFromFP rather than offsetFromSP. Since the code has been cleaned up I tried to also reduce code duplication in the various stubs for wasm code. This patch also removes the Air specific calling convention code and moves that logic into the Air IR generator. Since blocks can now have arbitrary signatures the control entries now use a const signature* rather than just the return type. Additionally, what used to be the result phi is now the phis for all the results for non-loop blocks and the arguments for a loop block. Due to the control flow restrictions of wasm conveniently we don't have to worry about generating non-optimal SSA, thus we can just use phis directly rather than using a variable. Lastly, to help clean up some code in the IR generators new helper methods were added to create call Patchpoints. These helpers do most of the boiler-plate initialization. * JavaScriptCore.xcodeproj/project.pbxproj: * assembler/AbstractMacroAssembler.h: (JSC::AbstractMacroAssembler::ImplicitAddress::ImplicitAddress): * assembler/LinkBuffer.cpp: (JSC::shouldDumpDisassemblyFor): * assembler/LinkBuffer.h: * assembler/MacroAssemblerARM64.h: (JSC::MacroAssemblerARM64::callOperation): * assembler/MacroAssemblerX86_64.h: (JSC::MacroAssemblerX86_64::callOperation): * b3/B3LowerToAir.cpp: * b3/B3PatchpointSpecial.cpp: (JSC::B3::PatchpointSpecial::forEachArg): (JSC::B3::PatchpointSpecial::isValid): (JSC::B3::PatchpointSpecial::admitsStack): (JSC::B3::PatchpointSpecial::generate): * b3/B3Procedure.h: (JSC::B3::Procedure::resultCount const): (JSC::B3::Procedure::typeAtOffset const): (JSC::B3::Procedure::returnCount const): Deleted. * b3/B3StackmapGenerationParams.cpp: (JSC::B3::StackmapGenerationParams::code const): * b3/B3StackmapGenerationParams.h: * b3/B3ValueRep.h: * b3/air/AirHelpers.h: Added. (JSC::B3::Air::moveForType): (JSC::B3::Air::relaxedMoveForType): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::store64FromReg): (JSC::AssemblyHelpers::store32FromReg): (JSC::AssemblyHelpers::load64ToReg): (JSC::AssemblyHelpers::load32ToReg): * runtime/JSCConfig.h: * runtime/OptionsList.h: * tools/JSDollarVM.cpp: * tools/VMInspector.cpp: (JSC::VMInspector::dumpValue): * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::ConstrainedTmp::operator bool const): (JSC::Wasm::TypedTmp::dump const): (JSC::Wasm::AirIRGenerator::ControlData::ControlData): (JSC::Wasm::AirIRGenerator::ControlData::dump const): (JSC::Wasm::AirIRGenerator::ControlData::blockType const): (JSC::Wasm::AirIRGenerator::ControlData::signature const): (JSC::Wasm::AirIRGenerator::ControlData::targetBlockForBranch): (JSC::Wasm::AirIRGenerator::ControlData::convertIfToBlock): (JSC::Wasm::AirIRGenerator::addEndToUnreachable): (JSC::Wasm::AirIRGenerator::emitCallPatchpoint): (JSC::Wasm::AirIRGenerator::validateInst): (JSC::Wasm::AirIRGenerator::tmpsForSignature): (JSC::Wasm::AirIRGenerator::emitPatchpoint): (JSC::Wasm::AirIRGenerator::AirIRGenerator): (JSC::Wasm::AirIRGenerator::toB3ResultType): (JSC::Wasm::AirIRGenerator::addBottom): (JSC::Wasm::AirIRGenerator::emitLoopTierUpCheck): (JSC::Wasm::AirIRGenerator::addTopLevel): (JSC::Wasm::AirIRGenerator::addLoop): (JSC::Wasm::AirIRGenerator::addBlock): (JSC::Wasm::AirIRGenerator::addIf): (JSC::Wasm::AirIRGenerator::addElse): (JSC::Wasm::AirIRGenerator::addElseToUnreachable): (JSC::Wasm::AirIRGenerator::addReturn): (JSC::Wasm::AirIRGenerator::addBranch): (JSC::Wasm::AirIRGenerator::addSwitch): (JSC::Wasm::AirIRGenerator::endBlock): (JSC::Wasm::AirIRGenerator::addCall): (JSC::Wasm::AirIRGenerator::addCallIndirect): (JSC::Wasm::dumpExpressionStack): (JSC::Wasm::AirIRGenerator::dump): (JSC::Wasm::AirIRGenerator::addOp<OpType::I64TruncUF64>): (JSC::Wasm::AirIRGenerator::addOp<OpType::I64TruncUF32>): (JSC::Wasm::AirIRGenerator::ControlData::type const): Deleted. (JSC::Wasm::AirIRGenerator::ControlData::hasNonVoidSignature const): Deleted. (JSC::Wasm::AirIRGenerator::ControlData::resultForBranch const): Deleted. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::ControlData::ControlData): (JSC::Wasm::B3IRGenerator::ControlData::dump const): (JSC::Wasm::B3IRGenerator::ControlData::blockType const): (JSC::Wasm::B3IRGenerator::ControlData::hasNonVoidresult const): (JSC::Wasm::B3IRGenerator::ControlData::targetBlockForBranch): (JSC::Wasm::B3IRGenerator::ControlData::convertIfToBlock): (JSC::Wasm::B3IRGenerator::addEndToUnreachable): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::framePointer): (JSC::Wasm::B3IRGenerator::toB3ResultType): (JSC::Wasm::B3IRGenerator::addArguments): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addLoop): (JSC::Wasm::B3IRGenerator::addTopLevel): (JSC::Wasm::B3IRGenerator::addBlock): (JSC::Wasm::B3IRGenerator::addIf): (JSC::Wasm::B3IRGenerator::addElse): (JSC::Wasm::B3IRGenerator::addElseToUnreachable): (JSC::Wasm::B3IRGenerator::addReturn): (JSC::Wasm::B3IRGenerator::addBranch): (JSC::Wasm::B3IRGenerator::addSwitch): (JSC::Wasm::B3IRGenerator::endBlock): (JSC::Wasm::B3IRGenerator::createCallPatchpoint): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::B3IRGenerator::ControlData::type const): Deleted. (JSC::Wasm::B3IRGenerator::ControlData::hasNonVoidSignature const): Deleted. (JSC::Wasm::B3IRGenerator::ControlData::resultForBranch const): Deleted. (JSC::Wasm::B3IRGenerator::createStack): Deleted. * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::didReceiveFunctionData): (JSC::Wasm::BBQPlan::parseAndValidateModule): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmCallingConvention.cpp: (JSC::Wasm::jsCallingConvention): (JSC::Wasm::wasmCallingConvention): (JSC::Wasm::jscCallingConvention): Deleted. (JSC::Wasm::jscCallingConventionAir): Deleted. (JSC::Wasm::wasmCallingConventionAir): Deleted. * wasm/WasmCallingConvention.h: (JSC::Wasm::CallInformation::CallInformation): (JSC::Wasm::CallInformation::computeResultsOffsetList): (JSC::Wasm::WasmCallingConvention::WasmCallingConvention): (JSC::Wasm::WasmCallingConvention::marshallLocationImpl const): (JSC::Wasm::WasmCallingConvention::marshallLocation const): (JSC::Wasm::WasmCallingConvention::callInformationFor const): (JSC::Wasm::JSCallingConvention::JSCallingConvention): (JSC::Wasm::JSCallingConvention::marshallLocationImpl const): (JSC::Wasm::JSCallingConvention::marshallLocation const): (JSC::Wasm::JSCallingConvention::callInformationFor const): (JSC::Wasm::CallingConvention::CallingConvention): Deleted. (JSC::Wasm::CallingConvention::marshallArgumentImpl const): Deleted. (JSC::Wasm::CallingConvention::marshallArgument const): Deleted. (JSC::Wasm::CallingConvention::headerSizeInBytes): Deleted. (JSC::Wasm::CallingConvention::setupFrameInPrologue const): Deleted. (JSC::Wasm::CallingConvention::loadArguments const): Deleted. (JSC::Wasm::CallingConvention::setupCall const): Deleted. (JSC::Wasm::CallingConventionAir::CallingConventionAir): Deleted. (JSC::Wasm::CallingConventionAir::prologueScratch const): Deleted. (JSC::Wasm::CallingConventionAir::marshallArgumentImpl const): Deleted. (JSC::Wasm::CallingConventionAir::marshallArgument const): Deleted. (JSC::Wasm::CallingConventionAir::headerSizeInBytes): Deleted. (JSC::Wasm::CallingConventionAir::loadArguments const): Deleted. (JSC::Wasm::CallingConventionAir::setupCall const): Deleted. (JSC::Wasm::nextJSCOffset): Deleted. * wasm/WasmFormat.h: * wasm/WasmFunctionParser.h: (JSC::Wasm::splitStack): (JSC::Wasm::FunctionParser::signature const): (JSC::Wasm::FunctionParser<Context>::FunctionParser): (JSC::Wasm::FunctionParser<Context>::parseBody): (JSC::Wasm::FunctionParser<Context>::parseExpression): (JSC::Wasm::FunctionParser<Context>::parseUnreachableExpression): * wasm/WasmInstance.h: * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::getPinnedRegisters): * wasm/WasmOMGForOSREntryPlan.cpp: (JSC::Wasm::OMGForOSREntryPlan::work): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::work): * wasm/WasmParser.h: (JSC::Wasm::FailureHelper::makeString): (JSC::Wasm::Parser<SuccessType>::Parser): (JSC::Wasm::Parser<SuccessType>::peekInt7): (JSC::Wasm::Parser<SuccessType>::parseBlockSignature): (JSC::Wasm::Parser<SuccessType>::parseValueType): (JSC::Wasm::Parser<SuccessType>::parseResultType): Deleted. * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseType): (JSC::Wasm::SectionParser::parseStart): * wasm/WasmSectionParser.h: * wasm/WasmSignature.cpp: (JSC::Wasm::Signature::toString const): (JSC::Wasm::Signature::dump const): (JSC::Wasm::computeHash): (JSC::Wasm::Signature::hash const): (JSC::Wasm::Signature::tryCreate): (JSC::Wasm::SignatureInformation::SignatureInformation): (JSC::Wasm::ParameterTypes::hash): (JSC::Wasm::ParameterTypes::equal): (JSC::Wasm::ParameterTypes::translate): (JSC::Wasm::SignatureInformation::signatureFor): (JSC::Wasm::SignatureInformation::adopt): Deleted. * wasm/WasmSignature.h: (JSC::Wasm::Signature::Signature): (JSC::Wasm::Signature::allocatedSize): (JSC::Wasm::Signature::returnCount const): (JSC::Wasm::Signature::returnType const): (JSC::Wasm::Signature::returnsVoid const): (JSC::Wasm::Signature::argument const): (JSC::Wasm::Signature::operator== const): (JSC::Wasm::Signature::getReturnType): (JSC::Wasm::Signature::getArgument): (JSC::Wasm::SignatureHash::SignatureHash): (JSC::Wasm::SignatureHash::equal): (JSC::Wasm::SignatureInformation::thunkFor const): (JSC::Wasm::Signature::returnType): Deleted. (JSC::Wasm::Signature::argument): Deleted. * wasm/WasmStreamingParser.cpp: (JSC::Wasm::StreamingParser::parseCodeSectionSize): (JSC::Wasm::StreamingParser::parseFunctionPayload): (JSC::Wasm::StreamingParser::parseSectionPayload): * wasm/WasmStreamingParser.h: (JSC::Wasm::StreamingParserClient::didReceiveSectionData): (JSC::Wasm::StreamingParser::reportError): (JSC::Wasm::StreamingParserClient::didReceiveFunctionData): Deleted. * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::throwStackOverflowFromWasmThunkGenerator): (JSC::Wasm::triggerOMGEntryTierUpThunkGenerator): * wasm/WasmValidate.cpp: (JSC::Wasm::Validate::ControlData::ControlData): (JSC::Wasm::Validate::ControlData::dump const): (JSC::Wasm::Validate::ControlData::blockType const): (JSC::Wasm::Validate::ControlData::signature const): (JSC::Wasm::Validate::ControlData::branchTargetArity const): (JSC::Wasm::Validate::ControlData::branchTargetType const): (JSC::Wasm::Validate::fail const): (JSC::Wasm::Validate::addTableGet): (JSC::Wasm::Validate::addTableGrow): (JSC::Wasm::Validate::addTableFill): (JSC::Wasm::Validate::addRefIsNull): (JSC::Wasm::Validate::addTopLevel): (JSC::Wasm::splitStack): (JSC::Wasm::Validate::addBlock): (JSC::Wasm::Validate::addLoop): (JSC::Wasm::Validate::addIf): (JSC::Wasm::Validate::addElseToUnreachable): (JSC::Wasm::Validate::addReturn): (JSC::Wasm::Validate::checkBranchTarget): (JSC::Wasm::Validate::addSwitch): (JSC::Wasm::Validate::addGrowMemory): (JSC::Wasm::Validate::addEndToUnreachable): (JSC::Wasm::Validate::addCall): (JSC::Wasm::Validate::addCallIndirect): (JSC::Wasm::Validate::unify): (JSC::Wasm::Validate::ControlData::hasNonVoidSignature const): Deleted. (JSC::Wasm::Validate::ControlData::type const): Deleted. (JSC::Wasm::Validate::ControlData::branchTargetSignature const): Deleted. * wasm/generateWasmOpsHeader.py: * wasm/js/JSToWasm.cpp: (JSC::Wasm::boxWasmResult): (JSC::Wasm::allocateResultsArray): (JSC::Wasm::marshallJSResult): (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/WasmToJS.cpp: (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): * wasm/js/WasmToJS.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): (JSC::WebAssemblyFunction::useTagRegisters const): (JSC::WebAssemblyFunction::jsCallEntrypointSlow): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): Tools: * Scripts/run-jsc-stress-tests: Canonical link: https://commits.webkit.org/215930@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@250559 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-10-01 16:38:26 +00:00
namespace JSC {
[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: Canonical link: https://commits.webkit.org/217068@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@251886 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-10-31 22:32:52 +00:00
class LLIntOffsetsExtractor;
Add support for the Wasm multi-value proposal https://bugs.webkit.org/show_bug.cgi?id=202250 Reviewed by Saam Barati. JSTests: This patch adds a new way to run stress tests via the .wat text format. By attaching an asm.js compiled version of the wabt tool we can easily create wat files programatically and convert them into a wasm blob to compile. To make this easy there is a wabt-wrapper.js module file that exports two useful functions that correspond to WebAssembly.compile and WebAssembly.instantiate. * wasm.yaml: * wasm/function-tests/if-no-else-non-void.js: * wasm/js-api/web-assembly-instantiate.js: (assert.asyncTest.async.test): (assert.asyncTest): * wasm/libwabt.js: Added. (WabtModule): (set get if): * wasm/references/func_ref.js: * wasm/references/validation.js: (assert.throws): * wasm/spec-harness/index.js: * wasm/spec-tests/block.wast.js: * wasm/spec-tests/br.wast.js: * wasm/spec-tests/br_if.wast.js: * wasm/spec-tests/call.wast.js: * wasm/spec-tests/call_indirect.wast.js: * wasm/spec-tests/func.wast.js: * wasm/spec-tests/if.wast.js: * wasm/spec-tests/loop.wast.js: * wasm/spec-tests/type.wast.js: * wasm/stress/js-wasm-call-many-return-types-on-stack-no-args.js: Added. (buildWat): * wasm/stress/js-wasm-js-varying-arities.js: Added. (paramForwarder): * wasm/stress/wasm-js-call-many-return-types-on-stack-no-args.js: Added. (buildWat): * wasm/stress/wasm-js-multi-value-exception-in-iterator.js: Added. (buildWat.throwError): (buildWat.throwErrorInIterator): (buildWat.tooManyValues): (buildWat.tooFewValues): (buildWat): * wasm/stress/wasm-wasm-call-indirect-many-return-types-on-stack.js: Added. (buildWat): * wasm/stress/wasm-wasm-call-many-return-types-on-stack-no-args.js: Added. (buildWat): * wasm/wabt-wrapper.js: Added. (export.compile): * wasm/wast-tests/br-if-at-end-of-block.wasm: Added. * wasm/wast-tests/br-if-at-end-of-block.wast: Added. * wasm/wast-tests/harness.js: (async.runWasmFile): * wasm/wast-tests/single-param-loop-signature.wasm: Added. * wasm/wast-tests/single-param-loop-signature.wast: Added. Source/JavaScriptCore: The wasm multi-value proposal makes two major changes to the spec. The first is that functions may now return more than one value across calls. When calling to/from JS, if there is more than one return type we return/receive a JSArray/Iterable, respectively. In the Wasm calls JS case, if the iteratable object does not vend the exact number of objects expected by the signature an error is thrown. The second major change in the multi-value proposal allows blocks to have any signature type. This works in a backwards compatible way by exploiting the fact that the old value-type thunk signatures (where the block takes no arguments and returns just the value type i.e. [] -> [type]) were always encoded as a negative number. If a block has a function signature, it is encoded as a positive index into the type section. When a block has a function signature type then the values from the enclosing stack are popped off that stack and added to the new block's stack. In the case of a br/br_if to a Loop block the "argument" values should be on the brancher's stack. The biggest change in this patch is stripping down the WasmCallingConventions file into one simpler API that just tells you where the each argument should be located. It also now handles adding or subtracting sizeof(CallerFrameAndPC) depending on whether you are caller or callee. Additionally, when computing locations for the callee it returns a B3::ValueRep that has the offsetFromFP rather than offsetFromSP. Since the code has been cleaned up I tried to also reduce code duplication in the various stubs for wasm code. This patch also removes the Air specific calling convention code and moves that logic into the Air IR generator. Since blocks can now have arbitrary signatures the control entries now use a const signature* rather than just the return type. Additionally, what used to be the result phi is now the phis for all the results for non-loop blocks and the arguments for a loop block. Due to the control flow restrictions of wasm conveniently we don't have to worry about generating non-optimal SSA, thus we can just use phis directly rather than using a variable. Lastly, to help clean up some code in the IR generators new helper methods were added to create call Patchpoints. These helpers do most of the boiler-plate initialization. * JavaScriptCore.xcodeproj/project.pbxproj: * assembler/AbstractMacroAssembler.h: (JSC::AbstractMacroAssembler::ImplicitAddress::ImplicitAddress): * assembler/LinkBuffer.cpp: (JSC::shouldDumpDisassemblyFor): * assembler/LinkBuffer.h: * assembler/MacroAssemblerARM64.h: (JSC::MacroAssemblerARM64::callOperation): * assembler/MacroAssemblerX86_64.h: (JSC::MacroAssemblerX86_64::callOperation): * b3/B3LowerToAir.cpp: * b3/B3PatchpointSpecial.cpp: (JSC::B3::PatchpointSpecial::forEachArg): (JSC::B3::PatchpointSpecial::isValid): (JSC::B3::PatchpointSpecial::admitsStack): (JSC::B3::PatchpointSpecial::generate): * b3/B3Procedure.h: (JSC::B3::Procedure::resultCount const): (JSC::B3::Procedure::typeAtOffset const): (JSC::B3::Procedure::returnCount const): Deleted. * b3/B3StackmapGenerationParams.cpp: (JSC::B3::StackmapGenerationParams::code const): * b3/B3StackmapGenerationParams.h: * b3/B3ValueRep.h: * b3/air/AirHelpers.h: Added. (JSC::B3::Air::moveForType): (JSC::B3::Air::relaxedMoveForType): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::store64FromReg): (JSC::AssemblyHelpers::store32FromReg): (JSC::AssemblyHelpers::load64ToReg): (JSC::AssemblyHelpers::load32ToReg): * runtime/JSCConfig.h: * runtime/OptionsList.h: * tools/JSDollarVM.cpp: * tools/VMInspector.cpp: (JSC::VMInspector::dumpValue): * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::ConstrainedTmp::operator bool const): (JSC::Wasm::TypedTmp::dump const): (JSC::Wasm::AirIRGenerator::ControlData::ControlData): (JSC::Wasm::AirIRGenerator::ControlData::dump const): (JSC::Wasm::AirIRGenerator::ControlData::blockType const): (JSC::Wasm::AirIRGenerator::ControlData::signature const): (JSC::Wasm::AirIRGenerator::ControlData::targetBlockForBranch): (JSC::Wasm::AirIRGenerator::ControlData::convertIfToBlock): (JSC::Wasm::AirIRGenerator::addEndToUnreachable): (JSC::Wasm::AirIRGenerator::emitCallPatchpoint): (JSC::Wasm::AirIRGenerator::validateInst): (JSC::Wasm::AirIRGenerator::tmpsForSignature): (JSC::Wasm::AirIRGenerator::emitPatchpoint): (JSC::Wasm::AirIRGenerator::AirIRGenerator): (JSC::Wasm::AirIRGenerator::toB3ResultType): (JSC::Wasm::AirIRGenerator::addBottom): (JSC::Wasm::AirIRGenerator::emitLoopTierUpCheck): (JSC::Wasm::AirIRGenerator::addTopLevel): (JSC::Wasm::AirIRGenerator::addLoop): (JSC::Wasm::AirIRGenerator::addBlock): (JSC::Wasm::AirIRGenerator::addIf): (JSC::Wasm::AirIRGenerator::addElse): (JSC::Wasm::AirIRGenerator::addElseToUnreachable): (JSC::Wasm::AirIRGenerator::addReturn): (JSC::Wasm::AirIRGenerator::addBranch): (JSC::Wasm::AirIRGenerator::addSwitch): (JSC::Wasm::AirIRGenerator::endBlock): (JSC::Wasm::AirIRGenerator::addCall): (JSC::Wasm::AirIRGenerator::addCallIndirect): (JSC::Wasm::dumpExpressionStack): (JSC::Wasm::AirIRGenerator::dump): (JSC::Wasm::AirIRGenerator::addOp<OpType::I64TruncUF64>): (JSC::Wasm::AirIRGenerator::addOp<OpType::I64TruncUF32>): (JSC::Wasm::AirIRGenerator::ControlData::type const): Deleted. (JSC::Wasm::AirIRGenerator::ControlData::hasNonVoidSignature const): Deleted. (JSC::Wasm::AirIRGenerator::ControlData::resultForBranch const): Deleted. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::ControlData::ControlData): (JSC::Wasm::B3IRGenerator::ControlData::dump const): (JSC::Wasm::B3IRGenerator::ControlData::blockType const): (JSC::Wasm::B3IRGenerator::ControlData::hasNonVoidresult const): (JSC::Wasm::B3IRGenerator::ControlData::targetBlockForBranch): (JSC::Wasm::B3IRGenerator::ControlData::convertIfToBlock): (JSC::Wasm::B3IRGenerator::addEndToUnreachable): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::framePointer): (JSC::Wasm::B3IRGenerator::toB3ResultType): (JSC::Wasm::B3IRGenerator::addArguments): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addLoop): (JSC::Wasm::B3IRGenerator::addTopLevel): (JSC::Wasm::B3IRGenerator::addBlock): (JSC::Wasm::B3IRGenerator::addIf): (JSC::Wasm::B3IRGenerator::addElse): (JSC::Wasm::B3IRGenerator::addElseToUnreachable): (JSC::Wasm::B3IRGenerator::addReturn): (JSC::Wasm::B3IRGenerator::addBranch): (JSC::Wasm::B3IRGenerator::addSwitch): (JSC::Wasm::B3IRGenerator::endBlock): (JSC::Wasm::B3IRGenerator::createCallPatchpoint): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::B3IRGenerator::ControlData::type const): Deleted. (JSC::Wasm::B3IRGenerator::ControlData::hasNonVoidSignature const): Deleted. (JSC::Wasm::B3IRGenerator::ControlData::resultForBranch const): Deleted. (JSC::Wasm::B3IRGenerator::createStack): Deleted. * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::didReceiveFunctionData): (JSC::Wasm::BBQPlan::parseAndValidateModule): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmCallingConvention.cpp: (JSC::Wasm::jsCallingConvention): (JSC::Wasm::wasmCallingConvention): (JSC::Wasm::jscCallingConvention): Deleted. (JSC::Wasm::jscCallingConventionAir): Deleted. (JSC::Wasm::wasmCallingConventionAir): Deleted. * wasm/WasmCallingConvention.h: (JSC::Wasm::CallInformation::CallInformation): (JSC::Wasm::CallInformation::computeResultsOffsetList): (JSC::Wasm::WasmCallingConvention::WasmCallingConvention): (JSC::Wasm::WasmCallingConvention::marshallLocationImpl const): (JSC::Wasm::WasmCallingConvention::marshallLocation const): (JSC::Wasm::WasmCallingConvention::callInformationFor const): (JSC::Wasm::JSCallingConvention::JSCallingConvention): (JSC::Wasm::JSCallingConvention::marshallLocationImpl const): (JSC::Wasm::JSCallingConvention::marshallLocation const): (JSC::Wasm::JSCallingConvention::callInformationFor const): (JSC::Wasm::CallingConvention::CallingConvention): Deleted. (JSC::Wasm::CallingConvention::marshallArgumentImpl const): Deleted. (JSC::Wasm::CallingConvention::marshallArgument const): Deleted. (JSC::Wasm::CallingConvention::headerSizeInBytes): Deleted. (JSC::Wasm::CallingConvention::setupFrameInPrologue const): Deleted. (JSC::Wasm::CallingConvention::loadArguments const): Deleted. (JSC::Wasm::CallingConvention::setupCall const): Deleted. (JSC::Wasm::CallingConventionAir::CallingConventionAir): Deleted. (JSC::Wasm::CallingConventionAir::prologueScratch const): Deleted. (JSC::Wasm::CallingConventionAir::marshallArgumentImpl const): Deleted. (JSC::Wasm::CallingConventionAir::marshallArgument const): Deleted. (JSC::Wasm::CallingConventionAir::headerSizeInBytes): Deleted. (JSC::Wasm::CallingConventionAir::loadArguments const): Deleted. (JSC::Wasm::CallingConventionAir::setupCall const): Deleted. (JSC::Wasm::nextJSCOffset): Deleted. * wasm/WasmFormat.h: * wasm/WasmFunctionParser.h: (JSC::Wasm::splitStack): (JSC::Wasm::FunctionParser::signature const): (JSC::Wasm::FunctionParser<Context>::FunctionParser): (JSC::Wasm::FunctionParser<Context>::parseBody): (JSC::Wasm::FunctionParser<Context>::parseExpression): (JSC::Wasm::FunctionParser<Context>::parseUnreachableExpression): * wasm/WasmInstance.h: * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::getPinnedRegisters): * wasm/WasmOMGForOSREntryPlan.cpp: (JSC::Wasm::OMGForOSREntryPlan::work): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::work): * wasm/WasmParser.h: (JSC::Wasm::FailureHelper::makeString): (JSC::Wasm::Parser<SuccessType>::Parser): (JSC::Wasm::Parser<SuccessType>::peekInt7): (JSC::Wasm::Parser<SuccessType>::parseBlockSignature): (JSC::Wasm::Parser<SuccessType>::parseValueType): (JSC::Wasm::Parser<SuccessType>::parseResultType): Deleted. * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseType): (JSC::Wasm::SectionParser::parseStart): * wasm/WasmSectionParser.h: * wasm/WasmSignature.cpp: (JSC::Wasm::Signature::toString const): (JSC::Wasm::Signature::dump const): (JSC::Wasm::computeHash): (JSC::Wasm::Signature::hash const): (JSC::Wasm::Signature::tryCreate): (JSC::Wasm::SignatureInformation::SignatureInformation): (JSC::Wasm::ParameterTypes::hash): (JSC::Wasm::ParameterTypes::equal): (JSC::Wasm::ParameterTypes::translate): (JSC::Wasm::SignatureInformation::signatureFor): (JSC::Wasm::SignatureInformation::adopt): Deleted. * wasm/WasmSignature.h: (JSC::Wasm::Signature::Signature): (JSC::Wasm::Signature::allocatedSize): (JSC::Wasm::Signature::returnCount const): (JSC::Wasm::Signature::returnType const): (JSC::Wasm::Signature::returnsVoid const): (JSC::Wasm::Signature::argument const): (JSC::Wasm::Signature::operator== const): (JSC::Wasm::Signature::getReturnType): (JSC::Wasm::Signature::getArgument): (JSC::Wasm::SignatureHash::SignatureHash): (JSC::Wasm::SignatureHash::equal): (JSC::Wasm::SignatureInformation::thunkFor const): (JSC::Wasm::Signature::returnType): Deleted. (JSC::Wasm::Signature::argument): Deleted. * wasm/WasmStreamingParser.cpp: (JSC::Wasm::StreamingParser::parseCodeSectionSize): (JSC::Wasm::StreamingParser::parseFunctionPayload): (JSC::Wasm::StreamingParser::parseSectionPayload): * wasm/WasmStreamingParser.h: (JSC::Wasm::StreamingParserClient::didReceiveSectionData): (JSC::Wasm::StreamingParser::reportError): (JSC::Wasm::StreamingParserClient::didReceiveFunctionData): Deleted. * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::throwStackOverflowFromWasmThunkGenerator): (JSC::Wasm::triggerOMGEntryTierUpThunkGenerator): * wasm/WasmValidate.cpp: (JSC::Wasm::Validate::ControlData::ControlData): (JSC::Wasm::Validate::ControlData::dump const): (JSC::Wasm::Validate::ControlData::blockType const): (JSC::Wasm::Validate::ControlData::signature const): (JSC::Wasm::Validate::ControlData::branchTargetArity const): (JSC::Wasm::Validate::ControlData::branchTargetType const): (JSC::Wasm::Validate::fail const): (JSC::Wasm::Validate::addTableGet): (JSC::Wasm::Validate::addTableGrow): (JSC::Wasm::Validate::addTableFill): (JSC::Wasm::Validate::addRefIsNull): (JSC::Wasm::Validate::addTopLevel): (JSC::Wasm::splitStack): (JSC::Wasm::Validate::addBlock): (JSC::Wasm::Validate::addLoop): (JSC::Wasm::Validate::addIf): (JSC::Wasm::Validate::addElseToUnreachable): (JSC::Wasm::Validate::addReturn): (JSC::Wasm::Validate::checkBranchTarget): (JSC::Wasm::Validate::addSwitch): (JSC::Wasm::Validate::addGrowMemory): (JSC::Wasm::Validate::addEndToUnreachable): (JSC::Wasm::Validate::addCall): (JSC::Wasm::Validate::addCallIndirect): (JSC::Wasm::Validate::unify): (JSC::Wasm::Validate::ControlData::hasNonVoidSignature const): Deleted. (JSC::Wasm::Validate::ControlData::type const): Deleted. (JSC::Wasm::Validate::ControlData::branchTargetSignature const): Deleted. * wasm/generateWasmOpsHeader.py: * wasm/js/JSToWasm.cpp: (JSC::Wasm::boxWasmResult): (JSC::Wasm::allocateResultsArray): (JSC::Wasm::marshallJSResult): (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/WasmToJS.cpp: (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): * wasm/js/WasmToJS.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): (JSC::WebAssemblyFunction::useTagRegisters const): (JSC::WebAssemblyFunction::jsCallEntrypointSlow): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): Tools: * Scripts/run-jsc-stress-tests: Canonical link: https://commits.webkit.org/215930@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@250559 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-10-01 16:38:26 +00:00
class JSWebAssemblyInstance;
namespace Wasm {
WebAssembly: no VM / JS version of everything but Instance https://bugs.webkit.org/show_bug.cgi?id=177473 Reviewed by Filip Pizlo, Saam Barati. JSTests: - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. * wasm/js-api/memory-grow.js: (assertEq): * wasm/js-api/table.js: (assert.throws): Source/JavaScriptCore: This change entails cleaning up and splitting a bunch of code which we had intertwined between C++ classes which represent JS objects, and pure C++ implementation objects. This specific change goes most of the way towards allowing JSC's WebAssembly to work without VM / JS, up to but excluding JSWebAssemblyInstance (there's Wasm::Instance, but it's not *the* thing yet). Because of this we still have a few FIXME identifying places that need to change. A follow-up change will go the rest of the way. I went about this change in the simplest way possible: grep the JavaScriptCore/wasm directory for "JS[^C_]" as well as "VM" and exclude the /js/ sub-directory (which contains the JS implementation of WebAssembly). None of this change removes the need for a JIT entitlement to be able to use WebAssembly. We don't have an interpreter, the process therefore still needs to be allowed to JIT to use these pure-C++ APIs. Interesting things to note: - Remove VM from Plan and associated places. It can just live as a capture in the callback lambda if it's needed. - Wasm::Memory shouldn't require a VM. It was only used to ask the GC to collect. We now instead pass two lambdas at construction time for this purpose: one to notify of memory pressure, and the other to ask for syncrhonous memory reclamation. This allows whoever creates the memory to dictate how to react to both these cases, and for a JS embedding that's to call the GC (async or sync, respectively). - Move grow logic from JSWebAssemblyMemory to Wasm::Memory::grow. Use Expected there, with an enum class for failure types. - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. - When generating the grow_memory opcode, no need to get the VM. Instead, reach directly for Wasm::Memory and grow it. - JSWebAssemblyMemory::grow can now always throw on failure, because it's only ever called from JS (not from grow_memory as before). - Wasm::Memory now takes a callback for successful growth. This allows JS wrappers to register themselves when growth succeeds without Wasm::Memory knowning anything about JS. It'll also allow creating a list of callbacks for when we add thread support (we'll want to notify many wrappers, all under a lock). - Wasm::Memory is now back to being the source of truth about address / size, used directly by generated code instead of JSWebAssemblyMemory. - Move wasmToJS from the general WasmBinding header to its own header under wasm/js. It's only used by wasm/js/JSWebAssemblyCodeBlock.cpp, and uses VM, and therefore isn't general WebAssembly. - Make Wasm::Context an actual type (just a struct holding a JSWebAssemlyInstance for now) instead of an alias for that. Notably this doesn't add anything to the Context and doesn't change what actually gets passed around in JIT code (fast TLS or registers) because these changes potentially impact performance. The entire purpose of this change is to allow passing Wasm::Context around without having to know about VM. Since VM contains a Wasm::Context the JS embedding is effectively the same, but with this setup a non-JS embedding is much better off. - Move JSWebAssembly into the JS folder. - OMGPlan: use Wasm::CodeBlock directly instead of JSWebAssemblyCodeBlock. - wasm->JS stubs are now on the instance's tail as raw pointers, instead of being on JSWebAssemblyCodeBlock, and are now called wasm->Embedder stubs. The owned reference is still on JSWebAssemblyCodeBlock, and is still called wasm->JS stub. This move means that the embedder must, after creating a Wasm::CodeBlock, somehow create the stubs to call back into the embedder. This removes an indirection in the generated code because the B3 IR generator now reaches into the instance instead of JSWebAssemblyCodeBlock. - Move more CodeBlock things. Compilation completion is now marked by its own atomic<bool> flag instead of a nullptr plan: that required using a lock, and was causing a deadlock in stack-trace.js because before my changes JSWebAssemblyCodeBlock did its own completion checking separately from Wasm::CodeBlock, without getting the lock. Now that everything points to Wasm::CodeBlock and there's no cached completion marker, the lock was being acquired in a sanity-check assertion. - Embedder -> Wasm wrappers are now generated through a function that's passed in at compilation time, instead of being hard-coded as a JS -> Wasm wrapper. - WasmMemory doens't need to know about fault handling thunks. Only the IR generator should know, and should make sure that the exception throwing thunk is generated if any memory is present (note: with signal handling not all of them generate an exception check). - Make exception throwing pluggable: instead of having a hard-coded JS-specific lambda we now have a regular C++ function being called from JIT code when a WebAssembly exception is thrown. This allows any embedder to get called as they wish. For now a process can only have a single of these functions (i.e. only one embedder per process) because the trap handler is a singleton. That can be fixed in in #177475. - Create WasmEmbedder.h where all embedder plugging will live. - Split up JSWebAssemblyTable into Wasm::Table which is refcounted. JSWebAssemblyTable now only contains the JS functions in the table, and Wasm::Table is what's used by the JIT code to lookup where to call and do the instance check (for context switch). Note that this creates an extra allocation for all the instances in Wasm::Table, and in exchange removes an indirection in JIT code because the instance used to be obtained off of the JS function. Also note that it's the embedder than keeps the instances alive, not Wasm::Table (which holds a dumb pointer to the instance), because doing otherwise would cause reference cycles. - Add WasmInstance. It doesn't do much for now, owns globals. - JSWebAssembly instance now doesn't just contain the imported functions as JSObjects, it also has the corresponding import's instance and wasm entrypoint. This triples the space allocated per instance's imported function, but there shouldn't be that many imports. This has two upsides: it creates smaller and faster code, and makes is easier to disassociate embedder-specific things from embedder-neutral things. The small / faster win is in two places: B3 IR generator only needs offsetOfImportFunction for the call opcode (when the called index is an import) to know whether the import is wasm->wasm or wasm->embedder (this isn't known at compile-time because it's dependent on the import object), this is now done by seeing if that import function has an associated target instance (only wasm->wasm does); the other place is wasmBinding which uses offsetOfImportFunction to figure out the wasm->wasm target instance, and then gets WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation to do a tail call. The disassociation comes because the target instance can be Wasm::Instance once we change what the Context is, and WasmEntrypointLoadLocation is already embedder-independent. As a next step I can move this tail allocation from JSWebAssemblyInstance to Wasm::Instance, and leave importFunction in as an opaque pointer which is embedder-specific, and in JS will remain WriteBarrier<JSObject>. - Rename VMEntryFrame to EntryFrame, and in many places pass a pointer to it around instead of VM. This is a first step in allowing entry frames which aren't stored on VM, but which are instead stored in an embedder-specific location. That change won't really affect JS except through code churn, but will allow WebAssembly to use some machinery in a generic manner without having a VM. * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * debugger/Debugger.cpp: (JSC::Debugger::stepOutOfFunction): (JSC::Debugger::returnEvent): (JSC::Debugger::unwindEvent): (JSC::Debugger::didExecuteProgram): * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::compileExceptionHandlers): * dfg/DFGOSREntry.cpp: (JSC::DFG::prepareOSREntry): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::compileOSRExit): (JSC::DFG::OSRExit::compileExit): * dfg/DFGThunks.cpp: (JSC::DFG::osrEntryThunkGenerator): * ftl/FTLCompile.cpp: (JSC::FTL::compile): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::lower): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): (JSC::CallFrame::callerFrame): (JSC::CallFrame::unsafeCallerFrame): * interpreter/CallFrame.h: (JSC::ExecState::callerFrame const): (JSC::ExecState::callerFrameOrEntryFrame const): (JSC::ExecState::unsafeCallerFrameOrEntryFrame const): * interpreter/FrameTracers.h: (JSC::NativeCallFrameTracer::NativeCallFrameTracer): (JSC::NativeCallFrameTracerWithRestore::NativeCallFrameTracerWithRestore): (JSC::NativeCallFrameTracerWithRestore::~NativeCallFrameTracerWithRestore): * interpreter/Interpreter.cpp: (JSC::UnwindFunctor::operator() const): (JSC::UnwindFunctor::copyCalleeSavesToEntryFrameCalleeSavesBuffer const): (JSC::Interpreter::unwind): * interpreter/StackVisitor.cpp: (JSC::StackVisitor::StackVisitor): (JSC::StackVisitor::gotoNextFrame): (JSC::StackVisitor::readNonInlinedFrame): (JSC::StackVisitor::Frame::dump const): * interpreter/StackVisitor.h: (JSC::StackVisitor::Frame::callerIsEntryFrame const): * interpreter/VMEntryRecord.h: (JSC::VMEntryRecord::prevTopEntryFrame): (JSC::VMEntryRecord::unsafePrevTopEntryFrame): (JSC::EntryFrame::vmEntryRecordOffset): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::restoreCalleeSavesFromEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::loadWasmContextInstance): (JSC::AssemblyHelpers::storeWasmContextInstance): (JSC::AssemblyHelpers::loadWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::storeWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBufferImpl): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::copyCalleeSavesToVMEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer): * jit/JIT.cpp: (JSC::JIT::emitEnterOptimizationCheck): (JSC::JIT::privateCompileExceptionHandlers): * jit/JITExceptions.cpp: (JSC::genericUnwind): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): (JSC::JIT::emitSlow_op_loop_hint): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): * jit/JITOperations.cpp: * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::nativeForGenerator): * jsc.cpp: (functionDumpCallFrame): * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LLIntThunks.cpp: (JSC::vmEntryRecord): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/Options.cpp: (JSC::recomputeDependentOptions): * runtime/Options.h: * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::FrameWalker): (JSC::FrameWalker::advanceToParentFrame): (JSC::SamplingProfiler::processUnverifiedStackTraces): * runtime/ThrowScope.cpp: (JSC::ThrowScope::~ThrowScope): * runtime/VM.cpp: (JSC::VM::VM): (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::topEntryFrameOffset): * runtime/VMTraps.cpp: (JSC::isSaneFrame): (JSC::VMTraps::tryInstallTrapBreakpoints): (JSC::VMTraps::invalidateCodeBlocksOnStack): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWasmContextInstance): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::parseAndCompile): * wasm/WasmB3IRGenerator.h: * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::BBQPlan): (JSC::Wasm::BBQPlan::compileFunctions): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBBQPlanInlines.h: (JSC::Wasm::BBQPlan::initializeCallees): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmBinding.h: * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::create): (JSC::Wasm::CodeBlock::CodeBlock): (JSC::Wasm::CodeBlock::compileAsync): (JSC::Wasm::CodeBlock::setCompilationFinished): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::offsetOfImportStubs): (JSC::Wasm::CodeBlock::allocationSize): (JSC::Wasm::CodeBlock::importWasmToEmbedderStub): (JSC::Wasm::CodeBlock::offsetOfImportWasmToEmbedderStub): (JSC::Wasm::CodeBlock::wasmToJSCallStubForImport): (JSC::Wasm::CodeBlock::compilationFinished): (JSC::Wasm::CodeBlock::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): * wasm/WasmContext.cpp: (JSC::Wasm::Context::useFastTLS): (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: Copied from Source/JavaScriptCore/wasm/WasmContext.h. * wasm/WasmFaultSignalHandler.cpp: * wasm/WasmFaultSignalHandler.h: * wasm/WasmFormat.h: * wasm/WasmInstance.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::~Instance): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: Added. (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::module): (JSC::Wasm::Instance::codeBlock): (JSC::Wasm::Instance::memory): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::loadF32Global const): (JSC::Wasm::Instance::loadF64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::offsetOfCachedStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::~Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::offsetOfSize): * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationCallback): (JSC::Wasm::Module::validateSync): (JSC::Wasm::Module::validateAsync): (JSC::Wasm::Module::getOrCreateCodeBlock): (JSC::Wasm::Module::compileSync): (JSC::Wasm::Module::compileAsync): * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseTableHelper): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::OMGPlan): (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::isValid const): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::runCompletionTasks): (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmPlan.h: (JSC::Wasm::Plan::dontFinalize): * wasm/WasmSignature.cpp: * wasm/WasmSignature.h: * wasm/WasmTable.cpp: Added. (JSC::Wasm::Table::create): (JSC::Wasm::Table::~Table): (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h. (JSC::Wasm::Table::maximum const): (JSC::Wasm::Table::size const): (JSC::Wasm::Table::offsetOfSize): (JSC::Wasm::Table::offsetOfFunctions): (JSC::Wasm::Table::offsetOfInstances): (JSC::Wasm::Table::isValidSize): * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): (JSC::Wasm::Thunks::setThrowWasmException): (JSC::Wasm::Thunks::throwWasmException): * wasm/WasmThunks.h: * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::stopAllPlansForContext): * wasm/WasmWorklist.h: * wasm/js/JSToWasm.cpp: Added. (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/JSWebAssembly.cpp: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.cpp. * wasm/js/JSWebAssembly.h: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.h. * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::create): (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::context const): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::webAssemblyToJSCallee): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::offsetOfTail): (JSC::JSWebAssemblyInstance::importFunctionInfo): (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): (JSC::JSWebAssemblyInstance::offsetOfImportFunction): (JSC::JSWebAssemblyInstance::importFunction): (JSC::JSWebAssemblyInstance::internalMemory): (JSC::JSWebAssemblyInstance::wasmCodeBlock const): (JSC::JSWebAssemblyInstance::offsetOfWasmTable): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::offsetOfGlobals): (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): (JSC::JSWebAssemblyInstance::cachedStackLimit const): (JSC::JSWebAssemblyInstance::setCachedStackLimit): (JSC::JSWebAssemblyInstance::wasmMemory): (JSC::JSWebAssemblyInstance::wasmModule): (JSC::JSWebAssemblyInstance::allocationSize): (JSC::JSWebAssemblyInstance::module const): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::create): (JSC::JSWebAssemblyMemory::adopt): (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::moduleInformation const): (JSC::JSWebAssemblyModule::exportSymbolTable const): (JSC::JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace const): (JSC::JSWebAssemblyModule::callee const): (JSC::JSWebAssemblyModule::codeBlock): (JSC::JSWebAssemblyModule::module): * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::create): (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::visitChildren): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::getFunction): (JSC::JSWebAssemblyTable::clearFunction): (JSC::JSWebAssemblyTable::setFunction): * wasm/js/JSWebAssemblyTable.h: (JSC::JSWebAssemblyTable::isValidSize): (JSC::JSWebAssemblyTable::maximum const): (JSC::JSWebAssemblyTable::size const): (JSC::JSWebAssemblyTable::table): * wasm/js/WasmToJS.cpp: Copied from Source/JavaScriptCore/wasm/WasmBinding.cpp. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): (JSC::WebAssemblyModuleConstructor::createModule): * wasm/js/WebAssemblyModuleConstructor.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::webAssemblyCompileFunc): (JSC::instantiate): (JSC::compileAndInstantiate): (JSC::webAssemblyValidateFunc): * wasm/js/WebAssemblyTableConstructor.cpp: (JSC::constructJSWebAssemblyTable): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Source/WebCore: * ForwardingHeaders/wasm/WasmModule.h: Added. This used to be included in JSWebAssemblyModule.h. * bindings/js/SerializedScriptValue.cpp: Update postMessage code according to C++ API changes. Canonical link: https://commits.webkit.org/194750@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223738 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-20 02:23:29 +00:00
WebAssembly: no VM / JS version of our implementation https://bugs.webkit.org/show_bug.cgi?id=177472 Reviewed by Michael Saboff. This patch removes all appearances of "JS" and "VM" in the wasm directory. These now only appear in the wasm/js directory, which is only used in a JS embedding of wasm. It should therefore now be possible to create non-JS embeddings of wasm through JSC, though it'll still require: - Mild codegen for wasm<->embedder calls; - A strategy for trap handling (no need for full unwind! Could kill). - Creation of the Wasm::* objects. - Calling convention handling to call the embedder. - Handling of multiple embedders (see #177475, this is optional). Most of the patch consists in renaming JSWebAssemblyInstance to Instance, and removing temporary copies which I'd added to make this specific patch very simple. * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): this one place which needs to know about who "owns" the Wasm::Instance. In a JS embedding it's the JSWebAssemblyInstance. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::getGlobal): (JSC::Wasm::B3IRGenerator::setGlobal): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmContext.cpp: (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: add an "owner", the Wasm::Context, move the "tail" import information from JSWebAssemblyInstance over to here. (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::owner const): (JSC::Wasm::Instance::offsetOfOwner): (JSC::Wasm::Instance::context const): (JSC::Wasm::Instance::setMemory): (JSC::Wasm::Instance::setTable): (JSC::Wasm::Instance::offsetOfMemory): (JSC::Wasm::Instance::offsetOfGlobals): (JSC::Wasm::Instance::offsetOfTable): (JSC::Wasm::Instance::offsetOfTail): (JSC::Wasm::Instance::numImportFunctions const): (JSC::Wasm::Instance::importFunctionInfo): (JSC::Wasm::Instance::offsetOfTargetInstance): (JSC::Wasm::Instance::offsetOfWasmEntrypoint): (JSC::Wasm::Instance::offsetOfWasmToEmbedderStubExecutableAddress): (JSC::Wasm::Instance::offsetOfImportFunction): (JSC::Wasm::Instance::importFunction): (JSC::Wasm::Instance::allocationSize): (JSC::Wasm::Instance::create): Deleted. * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmTable.cpp: (JSC::Wasm::Table::Table): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyInstance.cpp: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): The embedder decides what the import function is. Here we must properly placement-new it to what we've elected (and initialize it later). (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::moduleNamespaceObject): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::setTable): (JSC::JSWebAssemblyInstance::offsetOfInstance): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::context const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTail): Deleted. (): Deleted. (JSC::JSWebAssemblyInstance::importFunctionInfo): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmToEmbedderStubExecutableAddress): Deleted. (JSC::JSWebAssemblyInstance::offsetOfImportFunction): Deleted. (JSC::JSWebAssemblyInstance::importFunction): Deleted. (JSC::JSWebAssemblyInstance::internalMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmCodeBlock const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmTable): Deleted. (JSC::JSWebAssemblyInstance::offsetOfGlobals): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTopEntryFramePointer): Deleted. (JSC::JSWebAssemblyInstance::cachedStackLimit const): Deleted. (JSC::JSWebAssemblyInstance::setCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::wasmMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmModule): Deleted. (JSC::JSWebAssemblyInstance::allocationSize): Deleted. * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::setFunction): * wasm/js/WasmToJS.cpp: One extra indirection to find the JSWebAssemblyInstance. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::instantiate): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Canonical link: https://commits.webkit.org/195012@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224020 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-26 15:33:55 +00:00
struct Context;
[WASM-References] Add support for Funcref in parameters and return types https://bugs.webkit.org/show_bug.cgi?id=198157 Reviewed by Yusuke Suzuki. JSTests: * wasm/Builder.js: (export.default.Builder.prototype._registerSectionBuilders.const.section.in.WASM.description.section.switch.section.case.string_appeared_here.this.section): * wasm/references/anyref_globals.js: * wasm/references/func_ref.js: Added. (fullGC.gc.makeExportedFunction): (makeExportedIdent): (makeAnyfuncIdent): (fun): (assert.eq.instance.exports.fix.fun): (assert.eq.instance.exports.fix): (string_appeared_here.End.End.Function.End.Code.End.WebAssembly.imp.ref): (string_appeared_here.End.End.Function.End.Code.End.WebAssembly): (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly.fun): (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly.assert.throws): (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly): (assert.throws): (assert.throws.doTest): (let.importedFun.of): (makeAnyfuncIdent.fun): * wasm/references/validation.js: (assert.throws): * wasm/wasm.json: Source/JavaScriptCore: Add support for funcref in parameters, globals, and in table.get/set. When converting a JSValue to a funcref (nee anyfunc), we first make sure it is an exported wasm function or null. We also add support for Ref.func. Anywhere a Ref.func is used, (statically) we construct a JS wrapper for it so that we never need to construct JSValues when handling references. This should make threads easier to implement. Finally, we add some missing bounds checks for table.get/set. * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::tmpForType): (JSC::Wasm::AirIRGenerator::moveOpForValueType): (JSC::Wasm::AirIRGenerator::AirIRGenerator): (JSC::Wasm::AirIRGenerator::addLocal): (JSC::Wasm::AirIRGenerator::addConstant): (JSC::Wasm::AirIRGenerator::addRefFunc): (JSC::Wasm::AirIRGenerator::addTableSet): (JSC::Wasm::AirIRGenerator::setGlobal): (JSC::Wasm::AirIRGenerator::addReturn): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::addLocal): (JSC::Wasm::B3IRGenerator::addTableSet): (JSC::Wasm::B3IRGenerator::addRefFunc): (JSC::Wasm::B3IRGenerator::setGlobal): * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::compileFunctions): * wasm/WasmCallingConvention.h: (JSC::Wasm::CallingConventionAir::marshallArgument const): (JSC::Wasm::CallingConventionAir::setupCall const): * wasm/WasmExceptionType.h: * wasm/WasmFormat.h: (JSC::Wasm::isValueType): (JSC::Wasm::isSubtype): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parseExpression): (JSC::Wasm::FunctionParser<Context>::parseUnreachableExpression): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::getFunctionWrapper const): (JSC::Wasm::Instance::setFunctionWrapper): * wasm/WasmInstance.h: * wasm/WasmModuleInformation.h: (JSC::Wasm::ModuleInformation::referencedFunctions const): (JSC::Wasm::ModuleInformation::addReferencedFunction const): * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseGlobal): (JSC::Wasm::SectionParser::parseInitExpr): * wasm/WasmValidate.cpp: (JSC::Wasm::Validate::addTableGet): (JSC::Wasm::Validate::addTableSet): (JSC::Wasm::Validate::addRefIsNull): (JSC::Wasm::Validate::addRefFunc): (JSC::Wasm::Validate::setLocal): (JSC::Wasm::Validate::addCall): (JSC::Wasm::Validate::addCallIndirect): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyHelpers.h: (JSC::isWebAssemblyHostFunction): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/JSWebAssemblyRuntimeError.cpp: (JSC::createJSWebAssemblyRuntimeError): * wasm/js/JSWebAssemblyRuntimeError.h: * wasm/js/WasmToJS.cpp: (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): (JSC::Wasm::emitWasmToJSException): * wasm/js/WasmToJS.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): (JSC::WebAssemblyFunction::jsCallEntrypointSlow): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): * wasm/wasm.json: Canonical link: https://commits.webkit.org/212896@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@246504 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-06-17 18:44:18 +00:00
class Instance;
Add base class to get WeakPtrFactory member and avoid some boilerplate code https://bugs.webkit.org/show_bug.cgi?id=186407 Reviewed by Brent Fulgham. Source/JavaScriptCore: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * wasm/WasmInstance.h: * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::registerInstance): Source/WebCore: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * Modules/credentialmanagement/CredentialsMessenger.h: * Modules/credentialmanagement/NavigatorCredentials.cpp: (WebCore::NavigatorCredentials::credentials): * Modules/encryptedmedia/CDM.cpp: (WebCore::CDM::doSupportedConfigurationStep): (WebCore::CDM::getConsentStatus): * Modules/encryptedmedia/CDM.h: * Modules/encryptedmedia/MediaKeySession.cpp: (WebCore::MediaKeySession::generateRequest): (WebCore::MediaKeySession::load): (WebCore::MediaKeySession::update): (WebCore::MediaKeySession::close): (WebCore::MediaKeySession::remove): * Modules/encryptedmedia/MediaKeySession.h: * Modules/encryptedmedia/MediaKeys.cpp: (WebCore::MediaKeys::createSession): * Modules/encryptedmedia/MediaKeys.h: * Modules/gamepad/GamepadManager.cpp: (WebCore::GamepadManager::platformGamepadDisconnected): (WebCore::GamepadManager::makeGamepadVisible): * Modules/mediastream/MediaDevices.cpp: (WebCore::MediaDevices::MediaDevices): * Modules/mediastream/MediaDevices.h: * Modules/mediastream/MediaStreamTrack.cpp: (WebCore::MediaStreamTrack::applyConstraints): * Modules/mediastream/MediaStreamTrack.h: * Modules/webauthn/cocoa/LocalAuthenticator.h: * Modules/webauthn/cocoa/LocalAuthenticator.mm: (WebCore::LocalAuthenticator::makeCredential): * accessibility/AccessibilityRenderObject.h: * accessibility/AccessibilitySVGRoot.cpp: (WebCore::AccessibilitySVGRoot::setParent): * crypto/SubtleCrypto.cpp: (WebCore::SubtleCrypto::encrypt): (WebCore::SubtleCrypto::decrypt): (WebCore::SubtleCrypto::sign): (WebCore::SubtleCrypto::verify): (WebCore::SubtleCrypto::digest): (WebCore::SubtleCrypto::generateKey): (WebCore::SubtleCrypto::deriveKey): (WebCore::SubtleCrypto::deriveBits): (WebCore::SubtleCrypto::importKey): (WebCore::SubtleCrypto::exportKey): (WebCore::SubtleCrypto::wrapKey): (WebCore::SubtleCrypto::unwrapKey): * crypto/SubtleCrypto.h: * css/CSSFontFace.cpp: (WebCore::CSSFontFace::CSSFontFace): (WebCore::CSSFontFace::wrapper): (WebCore::CSSFontFace::setWrapper): * css/DeprecatedCSSOMValue.h: * css/FontFace.cpp: * css/FontFace.h: * css/MediaQueryEvaluator.cpp: (WebCore::MediaQueryEvaluator::MediaQueryEvaluator): * css/StyleSheetContents.h: * css/parser/CSSDeferredParser.cpp: (WebCore::CSSDeferredParser::CSSDeferredParser): * dom/DataTransferItemList.cpp: (WebCore::DataTransferItemList::add): (WebCore::DataTransferItemList::ensureItems const): (WebCore::DataTransferItemList::didSetStringData): * dom/DataTransferItemList.h: * dom/Document.cpp: (WebCore::Document::postTask): (WebCore::Document::hasStorageAccess): (WebCore::Document::requestStorageAccess): * dom/Document.h: (WebCore::Document::setContextDocument): * dom/MessagePort.h: * html/HTMLImageElement.cpp: (WebCore::HTMLImageElement::setPictureElement): * html/HTMLInputElement.h: * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::mediaPlayerCreateResourceLoader): * html/HTMLMediaElement.h: * html/HTMLPictureElement.h: * html/parser/HTMLResourcePreloader.h: * layout/layouttree/LayoutBox.h: (WebCore::Layout::Box::style const): * loader/FormState.h: * loader/LinkLoader.cpp: (WebCore::LinkLoader::preconnectIfNeeded): * loader/LinkLoader.h: * loader/LinkPreloadResourceClients.cpp: (WebCore::LinkPreloadResourceClient::LinkPreloadResourceClient): * loader/MediaResourceLoader.cpp: (WebCore::MediaResourceLoader::MediaResourceLoader): * loader/MediaResourceLoader.h: * page/DOMWindow.h: * page/EventHandler.cpp: (WebCore::widgetForElement): (WebCore::EventHandler::updateLastScrollbarUnderMouse): * platform/GenericTaskQueue.cpp: (WebCore::TaskDispatcher<Timer>::postTask): * platform/GenericTaskQueue.h: (WebCore::GenericTaskQueue::enqueueTask): (WebCore::GenericTaskQueue::cancelAllTasks): * platform/ScrollView.h: * platform/ScrollableArea.h: * platform/Scrollbar.h: * platform/Widget.cpp: (WebCore::Widget::setParent): * platform/Widget.h: * platform/audio/gstreamer/AudioFileReaderGStreamer.cpp: (WebCore::AudioFileReader::decodeAudioForBusCreation): * platform/audio/mac/AudioHardwareListenerMac.cpp: (WebCore::AudioHardwareListenerMac::AudioHardwareListenerMac): * platform/audio/mac/AudioHardwareListenerMac.h: * platform/encryptedmedia/clearkey/CDMClearKey.cpp: (WebCore::CDMInstanceClearKey::requestLicense): (WebCore::CDMInstanceClearKey::updateLicense): (WebCore::CDMInstanceClearKey::loadSession): (WebCore::CDMInstanceClearKey::closeSession): (WebCore::CDMInstanceClearKey::removeSessionData): * platform/encryptedmedia/clearkey/CDMClearKey.h: * platform/graphics/FontCascade.h: * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp: (WebCore::MediaPlayerPrivateAVFoundation::scheduleMainThreadNotification): (WebCore::MediaPlayerPrivateAVFoundation::dispatchNotification): * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h: * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.h: * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm: (WebCore::CDMInstanceFairPlayStreamingAVFObjC::didProvideRequest): * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.h: * platform/graphics/avfoundation/objc/CDMSessionAVFoundationObjC.mm: (WebCore::CDMSessionAVFoundationObjC::CDMSessionAVFoundationObjC): * platform/graphics/avfoundation/objc/CDMSessionAVStreamSession.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::createVideoLayer): (WebCore::MediaPlayerPrivateAVFoundationObjC::checkPlayability): (WebCore::MediaPlayerPrivateAVFoundationObjC::beginLoadingMetadata): (WebCore::MediaPlayerPrivateAVFoundationObjC::seekToTime): (WebCore::MediaPlayerPrivateAVFoundationObjC::createSession): (WebCore::MediaPlayerPrivateAVFoundationObjC::setShouldPlayToPlaybackTarget): (-[WebCoreAVFMovieObserver observeValueForKeyPath:ofObject:change:context:]): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::requestNotificationWhenReadyForVideoData): (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::scheduleDeferredTask): * platform/graphics/cv/TextureCacheCV.h: * platform/graphics/cv/TextureCacheCV.mm: (WebCore::TextureCacheCV::textureFromImage): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::notifyPlayerOfVideo): (WebCore::MediaPlayerPrivateGStreamer::notifyPlayerOfAudio): (WebCore::MediaPlayerPrivateGStreamer::handleMessage): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h: * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp: (WebCore::MediaPlayerPrivateGStreamerBase::handleSyncMessage): (WebCore::MediaPlayerPrivateGStreamerBase::initializationDataEncountered): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h: * platform/graphics/gstreamer/mse/AppendPipeline.cpp: (WebCore::AppendPipeline::connectDemuxerSrcPadToAppsink): * platform/graphics/mac/DisplayRefreshMonitorMac.cpp: (WebCore::DisplayRefreshMonitorMac::displayLinkFired): * platform/graphics/mac/DisplayRefreshMonitorMac.h: * platform/graphics/texmap/TextureMapperLayer.cpp: (WebCore::TextureMapperLayer::setMaskLayer): (WebCore::TextureMapperLayer::setReplicaLayer): * platform/graphics/texmap/TextureMapperLayer.h: * platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp: (WebCore::MediaPlayerPrivateMediaFoundation::endCreatedMediaSource): (WebCore::MediaPlayerPrivateMediaFoundation::endGetEvent): (WebCore::MediaPlayerPrivateMediaFoundation::CustomVideoPresenter::processInputNotify): * platform/graphics/win/MediaPlayerPrivateMediaFoundation.h: * platform/ios/RemoteCommandListenerIOS.h: * platform/ios/RemoteCommandListenerIOS.mm: (WebCore::RemoteCommandListenerIOS::RemoteCommandListenerIOS): * platform/mac/RemoteCommandListenerMac.h: * platform/mac/RemoteCommandListenerMac.mm: (WebCore::RemoteCommandListenerMac::RemoteCommandListenerMac): * platform/mediastream/MediaStreamPrivate.cpp: (WebCore::MediaStreamPrivate::scheduleDeferredTask): * platform/mediastream/MediaStreamPrivate.h: * platform/mediastream/RealtimeMediaSource.cpp: (WebCore::RealtimeMediaSource::scheduleDeferredTask): * platform/mediastream/RealtimeMediaSource.h: * platform/mediastream/mac/ScreenDisplayCaptureSourceMac.h: * platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm: (WebCore::ScreenDisplayCaptureSourceMac::createDisplayStream): * platform/vr/VRPlatformDisplay.h: * platform/vr/openvr/VRPlatformManagerOpenVR.cpp: (WebCore::VRPlatformManagerOpenVR::getVRDisplays): * rendering/FloatingObjects.h: (WebCore::FloatingObject::setOriginatingLine): * rendering/RenderObject.h: * rendering/RootInlineBox.cpp: * rendering/RootInlineBox.h: * svg/SVGPathElement.h: * svg/SVGPathSegWithContext.h: (WebCore::SVGPathSegWithContext::SVGPathSegWithContext): (WebCore::SVGPathSegWithContext::setContextAndRole): * svg/SVGTransformList.h: * svg/properties/SVGAnimatedListPropertyTearOff.h: (WebCore::SVGAnimatedListPropertyTearOff::baseVal): (WebCore::SVGAnimatedListPropertyTearOff::animVal): * svg/properties/SVGAnimatedPathSegListPropertyTearOff.h: * svg/properties/SVGAnimatedPropertyTearOff.h: * svg/properties/SVGAnimatedTransformListPropertyTearOff.h: * svg/properties/SVGListProperty.h: (WebCore::SVGListProperty::initializeValuesAndWrappers): (WebCore::SVGListProperty::getItemValuesAndWrappers): (WebCore::SVGListProperty::insertItemBeforeValuesAndWrappers): (WebCore::SVGListProperty::replaceItemValuesAndWrappers): (WebCore::SVGListProperty::appendItemValuesAndWrappers): * svg/properties/SVGMatrixTearOff.h: * svg/properties/SVGPropertyTearOff.h: * testing/MockCDMFactory.cpp: (WebCore::MockCDMFactory::createCDM): (WebCore::MockCDM::createInstance): * testing/MockCDMFactory.h: * workers/service/ExtendableEvent.h: * workers/service/FetchEvent.cpp: (WebCore::FetchEvent::respondWith): * workers/service/server/SWServer.h: * xml/DOMParser.cpp: (WebCore::DOMParser::DOMParser): Source/WebCore/PAL: 186407_CanMakeWeakPtr * pal/system/mac/SystemSleepListenerMac.h: * pal/system/mac/SystemSleepListenerMac.mm: (PAL::SystemSleepListenerMac::SystemSleepListenerMac): Source/WebKit: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * NetworkProcess/NetworkLoadChecker.h: * NetworkProcess/NetworkProcess.cpp: (WebKit::NetworkProcess::canAuthenticateAgainstProtectionSpace): * NetworkProcess/PreconnectTask.h: * NetworkProcess/cache/CacheStorageEngine.h: * Shared/Authentication/AuthenticationManager.h: * UIProcess/API/APIAttachment.cpp: (API::Attachment::Attachment): * UIProcess/ApplePay/WebPaymentCoordinatorProxy.cpp: (WebKit::WebPaymentCoordinatorProxy::canMakePaymentsWithActiveCard): (WebKit::WebPaymentCoordinatorProxy::openPaymentSetup): * UIProcess/ApplePay/WebPaymentCoordinatorProxy.h: * UIProcess/ApplePay/mac/WebPaymentCoordinatorProxyMac.mm: (WebKit::WebPaymentCoordinatorProxy::platformShowPaymentUI): * UIProcess/ApplicationStateTracker.h: * UIProcess/ApplicationStateTracker.mm: (WebKit::ApplicationStateTracker::ApplicationStateTracker): * UIProcess/Cocoa/ViewGestureController.cpp: (WebKit::ViewGestureController::setAlternateBackForwardListSourcePage): * UIProcess/Cocoa/WebViewImpl.h: * UIProcess/Cocoa/WebViewImpl.mm: (WebKit::WebViewImpl::updateWindowAndViewFrames): (WebKit::WebViewImpl::setTopContentInset): (WebKit::WebViewImpl::viewDidMoveToWindow): (WebKit::WebViewImpl::prepareForMoveToWindow): (WebKit::WebViewImpl::validateUserInterfaceItem): (WebKit::WebViewImpl::requestCandidatesForSelectionIfNeeded): (WebKit::WebViewImpl::interpretKeyEvent): (WebKit::WebViewImpl::firstRectForCharacterRange): (WebKit::WebViewImpl::performKeyEquivalent): (WebKit::WebViewImpl::keyUp): (WebKit::WebViewImpl::keyDown): * UIProcess/CredentialManagement/WebCredentialsMessengerProxy.cpp: (WebKit::WebCredentialsMessengerProxy::makeCredential): (WebKit::WebCredentialsMessengerProxy::getAssertion): * UIProcess/CredentialManagement/WebCredentialsMessengerProxy.h: * UIProcess/Downloads/DownloadProxy.cpp: (WebKit::DownloadProxy::setOriginatingPage): * UIProcess/Launcher/ProcessLauncher.h: * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::ProcessLauncher::launchProcess): * UIProcess/ProcessAssertion.h: * UIProcess/WebPageProxy.h: * UIProcess/WebsiteData/WebsiteDataStore.h: * UIProcess/gtk/WaylandCompositor.cpp: (WebKit::WaylandCompositor::Surface::attachBuffer): * UIProcess/gtk/WaylandCompositor.h: * UIProcess/ios/ProcessAssertionIOS.mm: (WebKit::ProcessAssertion::ProcessAssertion): * UIProcess/mac/DisplayLink.cpp: (WebKit::DisplayLink::displayLinkCallback): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDisplayRefreshMonitor.mm: (WebKit::RemoteLayerTreeDisplayRefreshMonitor::RemoteLayerTreeDisplayRefreshMonitor): * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.h: Source/WebKitLegacy/mac: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * WebCoreSupport/WebEditorClient.h: * WebCoreSupport/WebEditorClient.mm: (WebEditorClient::requestCandidatesForSelection): Source/WTF: Add CanMakeWeakPtr base class to get WeakPtrFactory member and its getter, in order to avoid some boilerplate code in every class needing a WeakPtrFactory. This also gets rid of old-style createWeakPtr() methods in favor of the newer makeWeakPtr(). * wtf/WeakPtr.h: (WTF::CanMakeWeakPtr::weakPtrFactory const): (WTF::CanMakeWeakPtr::weakPtrFactory): Canonical link: https://commits.webkit.org/201784@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232613 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-06-08 03:56:04 +00:00
class Instance : public ThreadSafeRefCounted<Instance>, public CanMakeWeakPtr<Instance> {
[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: Canonical link: https://commits.webkit.org/217068@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@251886 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-10-31 22:32:52 +00:00
friend LLIntOffsetsExtractor;
WebAssembly: no VM / JS version of everything but Instance https://bugs.webkit.org/show_bug.cgi?id=177473 Reviewed by Filip Pizlo, Saam Barati. JSTests: - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. * wasm/js-api/memory-grow.js: (assertEq): * wasm/js-api/table.js: (assert.throws): Source/JavaScriptCore: This change entails cleaning up and splitting a bunch of code which we had intertwined between C++ classes which represent JS objects, and pure C++ implementation objects. This specific change goes most of the way towards allowing JSC's WebAssembly to work without VM / JS, up to but excluding JSWebAssemblyInstance (there's Wasm::Instance, but it's not *the* thing yet). Because of this we still have a few FIXME identifying places that need to change. A follow-up change will go the rest of the way. I went about this change in the simplest way possible: grep the JavaScriptCore/wasm directory for "JS[^C_]" as well as "VM" and exclude the /js/ sub-directory (which contains the JS implementation of WebAssembly). None of this change removes the need for a JIT entitlement to be able to use WebAssembly. We don't have an interpreter, the process therefore still needs to be allowed to JIT to use these pure-C++ APIs. Interesting things to note: - Remove VM from Plan and associated places. It can just live as a capture in the callback lambda if it's needed. - Wasm::Memory shouldn't require a VM. It was only used to ask the GC to collect. We now instead pass two lambdas at construction time for this purpose: one to notify of memory pressure, and the other to ask for syncrhonous memory reclamation. This allows whoever creates the memory to dictate how to react to both these cases, and for a JS embedding that's to call the GC (async or sync, respectively). - Move grow logic from JSWebAssemblyMemory to Wasm::Memory::grow. Use Expected there, with an enum class for failure types. - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. - When generating the grow_memory opcode, no need to get the VM. Instead, reach directly for Wasm::Memory and grow it. - JSWebAssemblyMemory::grow can now always throw on failure, because it's only ever called from JS (not from grow_memory as before). - Wasm::Memory now takes a callback for successful growth. This allows JS wrappers to register themselves when growth succeeds without Wasm::Memory knowning anything about JS. It'll also allow creating a list of callbacks for when we add thread support (we'll want to notify many wrappers, all under a lock). - Wasm::Memory is now back to being the source of truth about address / size, used directly by generated code instead of JSWebAssemblyMemory. - Move wasmToJS from the general WasmBinding header to its own header under wasm/js. It's only used by wasm/js/JSWebAssemblyCodeBlock.cpp, and uses VM, and therefore isn't general WebAssembly. - Make Wasm::Context an actual type (just a struct holding a JSWebAssemlyInstance for now) instead of an alias for that. Notably this doesn't add anything to the Context and doesn't change what actually gets passed around in JIT code (fast TLS or registers) because these changes potentially impact performance. The entire purpose of this change is to allow passing Wasm::Context around without having to know about VM. Since VM contains a Wasm::Context the JS embedding is effectively the same, but with this setup a non-JS embedding is much better off. - Move JSWebAssembly into the JS folder. - OMGPlan: use Wasm::CodeBlock directly instead of JSWebAssemblyCodeBlock. - wasm->JS stubs are now on the instance's tail as raw pointers, instead of being on JSWebAssemblyCodeBlock, and are now called wasm->Embedder stubs. The owned reference is still on JSWebAssemblyCodeBlock, and is still called wasm->JS stub. This move means that the embedder must, after creating a Wasm::CodeBlock, somehow create the stubs to call back into the embedder. This removes an indirection in the generated code because the B3 IR generator now reaches into the instance instead of JSWebAssemblyCodeBlock. - Move more CodeBlock things. Compilation completion is now marked by its own atomic<bool> flag instead of a nullptr plan: that required using a lock, and was causing a deadlock in stack-trace.js because before my changes JSWebAssemblyCodeBlock did its own completion checking separately from Wasm::CodeBlock, without getting the lock. Now that everything points to Wasm::CodeBlock and there's no cached completion marker, the lock was being acquired in a sanity-check assertion. - Embedder -> Wasm wrappers are now generated through a function that's passed in at compilation time, instead of being hard-coded as a JS -> Wasm wrapper. - WasmMemory doens't need to know about fault handling thunks. Only the IR generator should know, and should make sure that the exception throwing thunk is generated if any memory is present (note: with signal handling not all of them generate an exception check). - Make exception throwing pluggable: instead of having a hard-coded JS-specific lambda we now have a regular C++ function being called from JIT code when a WebAssembly exception is thrown. This allows any embedder to get called as they wish. For now a process can only have a single of these functions (i.e. only one embedder per process) because the trap handler is a singleton. That can be fixed in in #177475. - Create WasmEmbedder.h where all embedder plugging will live. - Split up JSWebAssemblyTable into Wasm::Table which is refcounted. JSWebAssemblyTable now only contains the JS functions in the table, and Wasm::Table is what's used by the JIT code to lookup where to call and do the instance check (for context switch). Note that this creates an extra allocation for all the instances in Wasm::Table, and in exchange removes an indirection in JIT code because the instance used to be obtained off of the JS function. Also note that it's the embedder than keeps the instances alive, not Wasm::Table (which holds a dumb pointer to the instance), because doing otherwise would cause reference cycles. - Add WasmInstance. It doesn't do much for now, owns globals. - JSWebAssembly instance now doesn't just contain the imported functions as JSObjects, it also has the corresponding import's instance and wasm entrypoint. This triples the space allocated per instance's imported function, but there shouldn't be that many imports. This has two upsides: it creates smaller and faster code, and makes is easier to disassociate embedder-specific things from embedder-neutral things. The small / faster win is in two places: B3 IR generator only needs offsetOfImportFunction for the call opcode (when the called index is an import) to know whether the import is wasm->wasm or wasm->embedder (this isn't known at compile-time because it's dependent on the import object), this is now done by seeing if that import function has an associated target instance (only wasm->wasm does); the other place is wasmBinding which uses offsetOfImportFunction to figure out the wasm->wasm target instance, and then gets WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation to do a tail call. The disassociation comes because the target instance can be Wasm::Instance once we change what the Context is, and WasmEntrypointLoadLocation is already embedder-independent. As a next step I can move this tail allocation from JSWebAssemblyInstance to Wasm::Instance, and leave importFunction in as an opaque pointer which is embedder-specific, and in JS will remain WriteBarrier<JSObject>. - Rename VMEntryFrame to EntryFrame, and in many places pass a pointer to it around instead of VM. This is a first step in allowing entry frames which aren't stored on VM, but which are instead stored in an embedder-specific location. That change won't really affect JS except through code churn, but will allow WebAssembly to use some machinery in a generic manner without having a VM. * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * debugger/Debugger.cpp: (JSC::Debugger::stepOutOfFunction): (JSC::Debugger::returnEvent): (JSC::Debugger::unwindEvent): (JSC::Debugger::didExecuteProgram): * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::compileExceptionHandlers): * dfg/DFGOSREntry.cpp: (JSC::DFG::prepareOSREntry): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::compileOSRExit): (JSC::DFG::OSRExit::compileExit): * dfg/DFGThunks.cpp: (JSC::DFG::osrEntryThunkGenerator): * ftl/FTLCompile.cpp: (JSC::FTL::compile): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::lower): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): (JSC::CallFrame::callerFrame): (JSC::CallFrame::unsafeCallerFrame): * interpreter/CallFrame.h: (JSC::ExecState::callerFrame const): (JSC::ExecState::callerFrameOrEntryFrame const): (JSC::ExecState::unsafeCallerFrameOrEntryFrame const): * interpreter/FrameTracers.h: (JSC::NativeCallFrameTracer::NativeCallFrameTracer): (JSC::NativeCallFrameTracerWithRestore::NativeCallFrameTracerWithRestore): (JSC::NativeCallFrameTracerWithRestore::~NativeCallFrameTracerWithRestore): * interpreter/Interpreter.cpp: (JSC::UnwindFunctor::operator() const): (JSC::UnwindFunctor::copyCalleeSavesToEntryFrameCalleeSavesBuffer const): (JSC::Interpreter::unwind): * interpreter/StackVisitor.cpp: (JSC::StackVisitor::StackVisitor): (JSC::StackVisitor::gotoNextFrame): (JSC::StackVisitor::readNonInlinedFrame): (JSC::StackVisitor::Frame::dump const): * interpreter/StackVisitor.h: (JSC::StackVisitor::Frame::callerIsEntryFrame const): * interpreter/VMEntryRecord.h: (JSC::VMEntryRecord::prevTopEntryFrame): (JSC::VMEntryRecord::unsafePrevTopEntryFrame): (JSC::EntryFrame::vmEntryRecordOffset): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::restoreCalleeSavesFromEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::loadWasmContextInstance): (JSC::AssemblyHelpers::storeWasmContextInstance): (JSC::AssemblyHelpers::loadWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::storeWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBufferImpl): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::copyCalleeSavesToVMEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer): * jit/JIT.cpp: (JSC::JIT::emitEnterOptimizationCheck): (JSC::JIT::privateCompileExceptionHandlers): * jit/JITExceptions.cpp: (JSC::genericUnwind): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): (JSC::JIT::emitSlow_op_loop_hint): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): * jit/JITOperations.cpp: * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::nativeForGenerator): * jsc.cpp: (functionDumpCallFrame): * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LLIntThunks.cpp: (JSC::vmEntryRecord): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/Options.cpp: (JSC::recomputeDependentOptions): * runtime/Options.h: * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::FrameWalker): (JSC::FrameWalker::advanceToParentFrame): (JSC::SamplingProfiler::processUnverifiedStackTraces): * runtime/ThrowScope.cpp: (JSC::ThrowScope::~ThrowScope): * runtime/VM.cpp: (JSC::VM::VM): (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::topEntryFrameOffset): * runtime/VMTraps.cpp: (JSC::isSaneFrame): (JSC::VMTraps::tryInstallTrapBreakpoints): (JSC::VMTraps::invalidateCodeBlocksOnStack): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWasmContextInstance): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::parseAndCompile): * wasm/WasmB3IRGenerator.h: * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::BBQPlan): (JSC::Wasm::BBQPlan::compileFunctions): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBBQPlanInlines.h: (JSC::Wasm::BBQPlan::initializeCallees): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmBinding.h: * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::create): (JSC::Wasm::CodeBlock::CodeBlock): (JSC::Wasm::CodeBlock::compileAsync): (JSC::Wasm::CodeBlock::setCompilationFinished): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::offsetOfImportStubs): (JSC::Wasm::CodeBlock::allocationSize): (JSC::Wasm::CodeBlock::importWasmToEmbedderStub): (JSC::Wasm::CodeBlock::offsetOfImportWasmToEmbedderStub): (JSC::Wasm::CodeBlock::wasmToJSCallStubForImport): (JSC::Wasm::CodeBlock::compilationFinished): (JSC::Wasm::CodeBlock::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): * wasm/WasmContext.cpp: (JSC::Wasm::Context::useFastTLS): (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: Copied from Source/JavaScriptCore/wasm/WasmContext.h. * wasm/WasmFaultSignalHandler.cpp: * wasm/WasmFaultSignalHandler.h: * wasm/WasmFormat.h: * wasm/WasmInstance.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::~Instance): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: Added. (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::module): (JSC::Wasm::Instance::codeBlock): (JSC::Wasm::Instance::memory): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::loadF32Global const): (JSC::Wasm::Instance::loadF64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::offsetOfCachedStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::~Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::offsetOfSize): * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationCallback): (JSC::Wasm::Module::validateSync): (JSC::Wasm::Module::validateAsync): (JSC::Wasm::Module::getOrCreateCodeBlock): (JSC::Wasm::Module::compileSync): (JSC::Wasm::Module::compileAsync): * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseTableHelper): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::OMGPlan): (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::isValid const): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::runCompletionTasks): (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmPlan.h: (JSC::Wasm::Plan::dontFinalize): * wasm/WasmSignature.cpp: * wasm/WasmSignature.h: * wasm/WasmTable.cpp: Added. (JSC::Wasm::Table::create): (JSC::Wasm::Table::~Table): (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h. (JSC::Wasm::Table::maximum const): (JSC::Wasm::Table::size const): (JSC::Wasm::Table::offsetOfSize): (JSC::Wasm::Table::offsetOfFunctions): (JSC::Wasm::Table::offsetOfInstances): (JSC::Wasm::Table::isValidSize): * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): (JSC::Wasm::Thunks::setThrowWasmException): (JSC::Wasm::Thunks::throwWasmException): * wasm/WasmThunks.h: * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::stopAllPlansForContext): * wasm/WasmWorklist.h: * wasm/js/JSToWasm.cpp: Added. (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/JSWebAssembly.cpp: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.cpp. * wasm/js/JSWebAssembly.h: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.h. * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::create): (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::context const): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::webAssemblyToJSCallee): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::offsetOfTail): (JSC::JSWebAssemblyInstance::importFunctionInfo): (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): (JSC::JSWebAssemblyInstance::offsetOfImportFunction): (JSC::JSWebAssemblyInstance::importFunction): (JSC::JSWebAssemblyInstance::internalMemory): (JSC::JSWebAssemblyInstance::wasmCodeBlock const): (JSC::JSWebAssemblyInstance::offsetOfWasmTable): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::offsetOfGlobals): (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): (JSC::JSWebAssemblyInstance::cachedStackLimit const): (JSC::JSWebAssemblyInstance::setCachedStackLimit): (JSC::JSWebAssemblyInstance::wasmMemory): (JSC::JSWebAssemblyInstance::wasmModule): (JSC::JSWebAssemblyInstance::allocationSize): (JSC::JSWebAssemblyInstance::module const): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::create): (JSC::JSWebAssemblyMemory::adopt): (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::moduleInformation const): (JSC::JSWebAssemblyModule::exportSymbolTable const): (JSC::JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace const): (JSC::JSWebAssemblyModule::callee const): (JSC::JSWebAssemblyModule::codeBlock): (JSC::JSWebAssemblyModule::module): * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::create): (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::visitChildren): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::getFunction): (JSC::JSWebAssemblyTable::clearFunction): (JSC::JSWebAssemblyTable::setFunction): * wasm/js/JSWebAssemblyTable.h: (JSC::JSWebAssemblyTable::isValidSize): (JSC::JSWebAssemblyTable::maximum const): (JSC::JSWebAssemblyTable::size const): (JSC::JSWebAssemblyTable::table): * wasm/js/WasmToJS.cpp: Copied from Source/JavaScriptCore/wasm/WasmBinding.cpp. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): (JSC::WebAssemblyModuleConstructor::createModule): * wasm/js/WebAssemblyModuleConstructor.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::webAssemblyCompileFunc): (JSC::instantiate): (JSC::compileAndInstantiate): (JSC::webAssemblyValidateFunc): * wasm/js/WebAssemblyTableConstructor.cpp: (JSC::constructJSWebAssemblyTable): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Source/WebCore: * ForwardingHeaders/wasm/WasmModule.h: Added. This used to be included in JSWebAssemblyModule.h. * bindings/js/SerializedScriptValue.cpp: Update postMessage code according to C++ API changes. Canonical link: https://commits.webkit.org/194750@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223738 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-20 02:23:29 +00:00
public:
We need to set topCallFrame when calling Wasm::Memory::grow from the JIT https://bugs.webkit.org/show_bug.cgi?id=179639 <rdar://problem/35513018> Reviewed by JF Bastien. JSTests: * wasm/function-tests/grow-memory-cause-gc.js: Added. (escape): (i.func): Source/JavaScriptCore: Calling Wasm::Memory::grow from the JIT may cause us to GC. When we GC, we will walk the stack for ShadowChicken (and maybe other things). We weren't updating topCallFrame when calling grow from the Wasm JIT. This would cause the GC to use stale topCallFrame bits in VM, often leading to crashes. This patch fixes this bug by giving Wasm::Instance a lambda that is called when we need to store the topCallFrame. Users of Wasm::Instance can provide a function to do this action. Currently, JSWebAssemblyInstance passes in a lambda that stores to VM.topCallFrame. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::addGrowMemory): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): * wasm/WasmInstance.h: (JSC::Wasm::Instance::storeTopCallFrame): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: * wasm/js/WasmToJS.cpp: (JSC::Wasm::wasmToJSException): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyPrototype.cpp: (JSC::instantiate): Canonical link: https://commits.webkit.org/195695@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224810 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-14 09:05:33 +00:00
using StoreTopCallFrameCallback = WTF::Function<void(void*)>;
[WASM-References] Add support for Funcref in parameters and return types https://bugs.webkit.org/show_bug.cgi?id=198157 Reviewed by Yusuke Suzuki. JSTests: * wasm/Builder.js: (export.default.Builder.prototype._registerSectionBuilders.const.section.in.WASM.description.section.switch.section.case.string_appeared_here.this.section): * wasm/references/anyref_globals.js: * wasm/references/func_ref.js: Added. (fullGC.gc.makeExportedFunction): (makeExportedIdent): (makeAnyfuncIdent): (fun): (assert.eq.instance.exports.fix.fun): (assert.eq.instance.exports.fix): (string_appeared_here.End.End.Function.End.Code.End.WebAssembly.imp.ref): (string_appeared_here.End.End.Function.End.Code.End.WebAssembly): (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly.fun): (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly.assert.throws): (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly): (assert.throws): (assert.throws.doTest): (let.importedFun.of): (makeAnyfuncIdent.fun): * wasm/references/validation.js: (assert.throws): * wasm/wasm.json: Source/JavaScriptCore: Add support for funcref in parameters, globals, and in table.get/set. When converting a JSValue to a funcref (nee anyfunc), we first make sure it is an exported wasm function or null. We also add support for Ref.func. Anywhere a Ref.func is used, (statically) we construct a JS wrapper for it so that we never need to construct JSValues when handling references. This should make threads easier to implement. Finally, we add some missing bounds checks for table.get/set. * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::tmpForType): (JSC::Wasm::AirIRGenerator::moveOpForValueType): (JSC::Wasm::AirIRGenerator::AirIRGenerator): (JSC::Wasm::AirIRGenerator::addLocal): (JSC::Wasm::AirIRGenerator::addConstant): (JSC::Wasm::AirIRGenerator::addRefFunc): (JSC::Wasm::AirIRGenerator::addTableSet): (JSC::Wasm::AirIRGenerator::setGlobal): (JSC::Wasm::AirIRGenerator::addReturn): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::addLocal): (JSC::Wasm::B3IRGenerator::addTableSet): (JSC::Wasm::B3IRGenerator::addRefFunc): (JSC::Wasm::B3IRGenerator::setGlobal): * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::compileFunctions): * wasm/WasmCallingConvention.h: (JSC::Wasm::CallingConventionAir::marshallArgument const): (JSC::Wasm::CallingConventionAir::setupCall const): * wasm/WasmExceptionType.h: * wasm/WasmFormat.h: (JSC::Wasm::isValueType): (JSC::Wasm::isSubtype): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parseExpression): (JSC::Wasm::FunctionParser<Context>::parseUnreachableExpression): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::getFunctionWrapper const): (JSC::Wasm::Instance::setFunctionWrapper): * wasm/WasmInstance.h: * wasm/WasmModuleInformation.h: (JSC::Wasm::ModuleInformation::referencedFunctions const): (JSC::Wasm::ModuleInformation::addReferencedFunction const): * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseGlobal): (JSC::Wasm::SectionParser::parseInitExpr): * wasm/WasmValidate.cpp: (JSC::Wasm::Validate::addTableGet): (JSC::Wasm::Validate::addTableSet): (JSC::Wasm::Validate::addRefIsNull): (JSC::Wasm::Validate::addRefFunc): (JSC::Wasm::Validate::setLocal): (JSC::Wasm::Validate::addCall): (JSC::Wasm::Validate::addCallIndirect): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyHelpers.h: (JSC::isWebAssemblyHostFunction): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/JSWebAssemblyRuntimeError.cpp: (JSC::createJSWebAssemblyRuntimeError): * wasm/js/JSWebAssemblyRuntimeError.h: * wasm/js/WasmToJS.cpp: (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): (JSC::Wasm::emitWasmToJSException): * wasm/js/WasmToJS.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): (JSC::WebAssemblyFunction::jsCallEntrypointSlow): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): * wasm/wasm.json: Canonical link: https://commits.webkit.org/212896@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@246504 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-06-17 18:44:18 +00:00
using FunctionWrapperMap = HashMap<uint32_t, WriteBarrier<Unknown>, IntHash<uint32_t>, WTF::UnsignedWithZeroKeyHashTraits<uint32_t>>;
We need to set topCallFrame when calling Wasm::Memory::grow from the JIT https://bugs.webkit.org/show_bug.cgi?id=179639 <rdar://problem/35513018> Reviewed by JF Bastien. JSTests: * wasm/function-tests/grow-memory-cause-gc.js: Added. (escape): (i.func): Source/JavaScriptCore: Calling Wasm::Memory::grow from the JIT may cause us to GC. When we GC, we will walk the stack for ShadowChicken (and maybe other things). We weren't updating topCallFrame when calling grow from the Wasm JIT. This would cause the GC to use stale topCallFrame bits in VM, often leading to crashes. This patch fixes this bug by giving Wasm::Instance a lambda that is called when we need to store the topCallFrame. Users of Wasm::Instance can provide a function to do this action. Currently, JSWebAssemblyInstance passes in a lambda that stores to VM.topCallFrame. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::addGrowMemory): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): * wasm/WasmInstance.h: (JSC::Wasm::Instance::storeTopCallFrame): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: * wasm/js/WasmToJS.cpp: (JSC::Wasm::wasmToJSException): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyPrototype.cpp: (JSC::instantiate): Canonical link: https://commits.webkit.org/195695@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224810 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-14 09:05:33 +00:00
WebAssembly: restore cached stack limit after out-call https://bugs.webkit.org/show_bug.cgi?id=179106 <rdar://problem/35337525> Reviewed by Saam Barati. JSTests: * wasm/function-tests/double-instance.js: Added. (const.imp.boom): (const.imp.get callAnother): Source/JavaScriptCore: We cache the stack limit on the Instance so that we can do fast stack checks where required. In regular usage the stack limit never changes because we always run on the same thread, but in rare cases an API user can totally migrate which thread (and therefore stack) is used for execution between WebAssembly traces. For that reason we set the cached stack limit to UINTPTR_MAX on the outgoing Instance when transitioning back into a different Instance. We usually restore the cached stack limit in Context::store, but this wasn't called on all code paths. We had a bug where an Instance calling into itself indirectly would therefore fail to restore its cached stack limit properly. This patch therefore restores the cached stack limit after direct calls which could be to imports (both wasm->wasm and wasm->embedder). We have to do all of them because we have no way of knowing what imports will do (they're known at instantiation time, not compilation time, and different instances can have different imports). To make this efficient we also add a pointer to the canonical location of the stack limit (i.e. the extra indirection we're trying to save by caching the stack limit on the Instance in the first place). This is potentially a small perf hit on imported direct calls. It's hard to say what the performance cost will be because we haven't seen much code in the wild which does this. We're adding two dependent loads and a store of the loaded value, which is unlikely to get used soon after. It's more code, but on an out-of-order processor it doesn't contribute to the critical path. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): * wasm/WasmInstance.h: (JSC::Wasm::Instance::offsetOfPointerToActualStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::create): * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): Canonical link: https://commits.webkit.org/196260@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225411 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-01 21:58:36 +00:00
static Ref<Instance> create(Context*, Ref<Module>&&, EntryFrame** pointerToTopEntryFrame, void** pointerToActualStackLimit, StoreTopCallFrameCallback&&);
WebAssembly: no VM / JS version of everything but Instance https://bugs.webkit.org/show_bug.cgi?id=177473 Reviewed by Filip Pizlo, Saam Barati. JSTests: - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. * wasm/js-api/memory-grow.js: (assertEq): * wasm/js-api/table.js: (assert.throws): Source/JavaScriptCore: This change entails cleaning up and splitting a bunch of code which we had intertwined between C++ classes which represent JS objects, and pure C++ implementation objects. This specific change goes most of the way towards allowing JSC's WebAssembly to work without VM / JS, up to but excluding JSWebAssemblyInstance (there's Wasm::Instance, but it's not *the* thing yet). Because of this we still have a few FIXME identifying places that need to change. A follow-up change will go the rest of the way. I went about this change in the simplest way possible: grep the JavaScriptCore/wasm directory for "JS[^C_]" as well as "VM" and exclude the /js/ sub-directory (which contains the JS implementation of WebAssembly). None of this change removes the need for a JIT entitlement to be able to use WebAssembly. We don't have an interpreter, the process therefore still needs to be allowed to JIT to use these pure-C++ APIs. Interesting things to note: - Remove VM from Plan and associated places. It can just live as a capture in the callback lambda if it's needed. - Wasm::Memory shouldn't require a VM. It was only used to ask the GC to collect. We now instead pass two lambdas at construction time for this purpose: one to notify of memory pressure, and the other to ask for syncrhonous memory reclamation. This allows whoever creates the memory to dictate how to react to both these cases, and for a JS embedding that's to call the GC (async or sync, respectively). - Move grow logic from JSWebAssemblyMemory to Wasm::Memory::grow. Use Expected there, with an enum class for failure types. - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. - When generating the grow_memory opcode, no need to get the VM. Instead, reach directly for Wasm::Memory and grow it. - JSWebAssemblyMemory::grow can now always throw on failure, because it's only ever called from JS (not from grow_memory as before). - Wasm::Memory now takes a callback for successful growth. This allows JS wrappers to register themselves when growth succeeds without Wasm::Memory knowning anything about JS. It'll also allow creating a list of callbacks for when we add thread support (we'll want to notify many wrappers, all under a lock). - Wasm::Memory is now back to being the source of truth about address / size, used directly by generated code instead of JSWebAssemblyMemory. - Move wasmToJS from the general WasmBinding header to its own header under wasm/js. It's only used by wasm/js/JSWebAssemblyCodeBlock.cpp, and uses VM, and therefore isn't general WebAssembly. - Make Wasm::Context an actual type (just a struct holding a JSWebAssemlyInstance for now) instead of an alias for that. Notably this doesn't add anything to the Context and doesn't change what actually gets passed around in JIT code (fast TLS or registers) because these changes potentially impact performance. The entire purpose of this change is to allow passing Wasm::Context around without having to know about VM. Since VM contains a Wasm::Context the JS embedding is effectively the same, but with this setup a non-JS embedding is much better off. - Move JSWebAssembly into the JS folder. - OMGPlan: use Wasm::CodeBlock directly instead of JSWebAssemblyCodeBlock. - wasm->JS stubs are now on the instance's tail as raw pointers, instead of being on JSWebAssemblyCodeBlock, and are now called wasm->Embedder stubs. The owned reference is still on JSWebAssemblyCodeBlock, and is still called wasm->JS stub. This move means that the embedder must, after creating a Wasm::CodeBlock, somehow create the stubs to call back into the embedder. This removes an indirection in the generated code because the B3 IR generator now reaches into the instance instead of JSWebAssemblyCodeBlock. - Move more CodeBlock things. Compilation completion is now marked by its own atomic<bool> flag instead of a nullptr plan: that required using a lock, and was causing a deadlock in stack-trace.js because before my changes JSWebAssemblyCodeBlock did its own completion checking separately from Wasm::CodeBlock, without getting the lock. Now that everything points to Wasm::CodeBlock and there's no cached completion marker, the lock was being acquired in a sanity-check assertion. - Embedder -> Wasm wrappers are now generated through a function that's passed in at compilation time, instead of being hard-coded as a JS -> Wasm wrapper. - WasmMemory doens't need to know about fault handling thunks. Only the IR generator should know, and should make sure that the exception throwing thunk is generated if any memory is present (note: with signal handling not all of them generate an exception check). - Make exception throwing pluggable: instead of having a hard-coded JS-specific lambda we now have a regular C++ function being called from JIT code when a WebAssembly exception is thrown. This allows any embedder to get called as they wish. For now a process can only have a single of these functions (i.e. only one embedder per process) because the trap handler is a singleton. That can be fixed in in #177475. - Create WasmEmbedder.h where all embedder plugging will live. - Split up JSWebAssemblyTable into Wasm::Table which is refcounted. JSWebAssemblyTable now only contains the JS functions in the table, and Wasm::Table is what's used by the JIT code to lookup where to call and do the instance check (for context switch). Note that this creates an extra allocation for all the instances in Wasm::Table, and in exchange removes an indirection in JIT code because the instance used to be obtained off of the JS function. Also note that it's the embedder than keeps the instances alive, not Wasm::Table (which holds a dumb pointer to the instance), because doing otherwise would cause reference cycles. - Add WasmInstance. It doesn't do much for now, owns globals. - JSWebAssembly instance now doesn't just contain the imported functions as JSObjects, it also has the corresponding import's instance and wasm entrypoint. This triples the space allocated per instance's imported function, but there shouldn't be that many imports. This has two upsides: it creates smaller and faster code, and makes is easier to disassociate embedder-specific things from embedder-neutral things. The small / faster win is in two places: B3 IR generator only needs offsetOfImportFunction for the call opcode (when the called index is an import) to know whether the import is wasm->wasm or wasm->embedder (this isn't known at compile-time because it's dependent on the import object), this is now done by seeing if that import function has an associated target instance (only wasm->wasm does); the other place is wasmBinding which uses offsetOfImportFunction to figure out the wasm->wasm target instance, and then gets WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation to do a tail call. The disassociation comes because the target instance can be Wasm::Instance once we change what the Context is, and WasmEntrypointLoadLocation is already embedder-independent. As a next step I can move this tail allocation from JSWebAssemblyInstance to Wasm::Instance, and leave importFunction in as an opaque pointer which is embedder-specific, and in JS will remain WriteBarrier<JSObject>. - Rename VMEntryFrame to EntryFrame, and in many places pass a pointer to it around instead of VM. This is a first step in allowing entry frames which aren't stored on VM, but which are instead stored in an embedder-specific location. That change won't really affect JS except through code churn, but will allow WebAssembly to use some machinery in a generic manner without having a VM. * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * debugger/Debugger.cpp: (JSC::Debugger::stepOutOfFunction): (JSC::Debugger::returnEvent): (JSC::Debugger::unwindEvent): (JSC::Debugger::didExecuteProgram): * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::compileExceptionHandlers): * dfg/DFGOSREntry.cpp: (JSC::DFG::prepareOSREntry): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::compileOSRExit): (JSC::DFG::OSRExit::compileExit): * dfg/DFGThunks.cpp: (JSC::DFG::osrEntryThunkGenerator): * ftl/FTLCompile.cpp: (JSC::FTL::compile): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::lower): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): (JSC::CallFrame::callerFrame): (JSC::CallFrame::unsafeCallerFrame): * interpreter/CallFrame.h: (JSC::ExecState::callerFrame const): (JSC::ExecState::callerFrameOrEntryFrame const): (JSC::ExecState::unsafeCallerFrameOrEntryFrame const): * interpreter/FrameTracers.h: (JSC::NativeCallFrameTracer::NativeCallFrameTracer): (JSC::NativeCallFrameTracerWithRestore::NativeCallFrameTracerWithRestore): (JSC::NativeCallFrameTracerWithRestore::~NativeCallFrameTracerWithRestore): * interpreter/Interpreter.cpp: (JSC::UnwindFunctor::operator() const): (JSC::UnwindFunctor::copyCalleeSavesToEntryFrameCalleeSavesBuffer const): (JSC::Interpreter::unwind): * interpreter/StackVisitor.cpp: (JSC::StackVisitor::StackVisitor): (JSC::StackVisitor::gotoNextFrame): (JSC::StackVisitor::readNonInlinedFrame): (JSC::StackVisitor::Frame::dump const): * interpreter/StackVisitor.h: (JSC::StackVisitor::Frame::callerIsEntryFrame const): * interpreter/VMEntryRecord.h: (JSC::VMEntryRecord::prevTopEntryFrame): (JSC::VMEntryRecord::unsafePrevTopEntryFrame): (JSC::EntryFrame::vmEntryRecordOffset): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::restoreCalleeSavesFromEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::loadWasmContextInstance): (JSC::AssemblyHelpers::storeWasmContextInstance): (JSC::AssemblyHelpers::loadWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::storeWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBufferImpl): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::copyCalleeSavesToVMEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer): * jit/JIT.cpp: (JSC::JIT::emitEnterOptimizationCheck): (JSC::JIT::privateCompileExceptionHandlers): * jit/JITExceptions.cpp: (JSC::genericUnwind): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): (JSC::JIT::emitSlow_op_loop_hint): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): * jit/JITOperations.cpp: * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::nativeForGenerator): * jsc.cpp: (functionDumpCallFrame): * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LLIntThunks.cpp: (JSC::vmEntryRecord): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/Options.cpp: (JSC::recomputeDependentOptions): * runtime/Options.h: * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::FrameWalker): (JSC::FrameWalker::advanceToParentFrame): (JSC::SamplingProfiler::processUnverifiedStackTraces): * runtime/ThrowScope.cpp: (JSC::ThrowScope::~ThrowScope): * runtime/VM.cpp: (JSC::VM::VM): (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::topEntryFrameOffset): * runtime/VMTraps.cpp: (JSC::isSaneFrame): (JSC::VMTraps::tryInstallTrapBreakpoints): (JSC::VMTraps::invalidateCodeBlocksOnStack): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWasmContextInstance): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::parseAndCompile): * wasm/WasmB3IRGenerator.h: * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::BBQPlan): (JSC::Wasm::BBQPlan::compileFunctions): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBBQPlanInlines.h: (JSC::Wasm::BBQPlan::initializeCallees): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmBinding.h: * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::create): (JSC::Wasm::CodeBlock::CodeBlock): (JSC::Wasm::CodeBlock::compileAsync): (JSC::Wasm::CodeBlock::setCompilationFinished): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::offsetOfImportStubs): (JSC::Wasm::CodeBlock::allocationSize): (JSC::Wasm::CodeBlock::importWasmToEmbedderStub): (JSC::Wasm::CodeBlock::offsetOfImportWasmToEmbedderStub): (JSC::Wasm::CodeBlock::wasmToJSCallStubForImport): (JSC::Wasm::CodeBlock::compilationFinished): (JSC::Wasm::CodeBlock::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): * wasm/WasmContext.cpp: (JSC::Wasm::Context::useFastTLS): (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: Copied from Source/JavaScriptCore/wasm/WasmContext.h. * wasm/WasmFaultSignalHandler.cpp: * wasm/WasmFaultSignalHandler.h: * wasm/WasmFormat.h: * wasm/WasmInstance.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::~Instance): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: Added. (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::module): (JSC::Wasm::Instance::codeBlock): (JSC::Wasm::Instance::memory): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::loadF32Global const): (JSC::Wasm::Instance::loadF64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::offsetOfCachedStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::~Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::offsetOfSize): * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationCallback): (JSC::Wasm::Module::validateSync): (JSC::Wasm::Module::validateAsync): (JSC::Wasm::Module::getOrCreateCodeBlock): (JSC::Wasm::Module::compileSync): (JSC::Wasm::Module::compileAsync): * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseTableHelper): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::OMGPlan): (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::isValid const): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::runCompletionTasks): (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmPlan.h: (JSC::Wasm::Plan::dontFinalize): * wasm/WasmSignature.cpp: * wasm/WasmSignature.h: * wasm/WasmTable.cpp: Added. (JSC::Wasm::Table::create): (JSC::Wasm::Table::~Table): (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h. (JSC::Wasm::Table::maximum const): (JSC::Wasm::Table::size const): (JSC::Wasm::Table::offsetOfSize): (JSC::Wasm::Table::offsetOfFunctions): (JSC::Wasm::Table::offsetOfInstances): (JSC::Wasm::Table::isValidSize): * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): (JSC::Wasm::Thunks::setThrowWasmException): (JSC::Wasm::Thunks::throwWasmException): * wasm/WasmThunks.h: * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::stopAllPlansForContext): * wasm/WasmWorklist.h: * wasm/js/JSToWasm.cpp: Added. (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/JSWebAssembly.cpp: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.cpp. * wasm/js/JSWebAssembly.h: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.h. * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::create): (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::context const): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::webAssemblyToJSCallee): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::offsetOfTail): (JSC::JSWebAssemblyInstance::importFunctionInfo): (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): (JSC::JSWebAssemblyInstance::offsetOfImportFunction): (JSC::JSWebAssemblyInstance::importFunction): (JSC::JSWebAssemblyInstance::internalMemory): (JSC::JSWebAssemblyInstance::wasmCodeBlock const): (JSC::JSWebAssemblyInstance::offsetOfWasmTable): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::offsetOfGlobals): (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): (JSC::JSWebAssemblyInstance::cachedStackLimit const): (JSC::JSWebAssemblyInstance::setCachedStackLimit): (JSC::JSWebAssemblyInstance::wasmMemory): (JSC::JSWebAssemblyInstance::wasmModule): (JSC::JSWebAssemblyInstance::allocationSize): (JSC::JSWebAssemblyInstance::module const): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::create): (JSC::JSWebAssemblyMemory::adopt): (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::moduleInformation const): (JSC::JSWebAssemblyModule::exportSymbolTable const): (JSC::JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace const): (JSC::JSWebAssemblyModule::callee const): (JSC::JSWebAssemblyModule::codeBlock): (JSC::JSWebAssemblyModule::module): * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::create): (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::visitChildren): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::getFunction): (JSC::JSWebAssemblyTable::clearFunction): (JSC::JSWebAssemblyTable::setFunction): * wasm/js/JSWebAssemblyTable.h: (JSC::JSWebAssemblyTable::isValidSize): (JSC::JSWebAssemblyTable::maximum const): (JSC::JSWebAssemblyTable::size const): (JSC::JSWebAssemblyTable::table): * wasm/js/WasmToJS.cpp: Copied from Source/JavaScriptCore/wasm/WasmBinding.cpp. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): (JSC::WebAssemblyModuleConstructor::createModule): * wasm/js/WebAssemblyModuleConstructor.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::webAssemblyCompileFunc): (JSC::instantiate): (JSC::compileAndInstantiate): (JSC::webAssemblyValidateFunc): * wasm/js/WebAssemblyTableConstructor.cpp: (JSC::constructJSWebAssemblyTable): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Source/WebCore: * ForwardingHeaders/wasm/WasmModule.h: Added. This used to be included in JSWebAssemblyModule.h. * bindings/js/SerializedScriptValue.cpp: Update postMessage code according to C++ API changes. Canonical link: https://commits.webkit.org/194750@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223738 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-20 02:23:29 +00:00
WebAssembly: no VM / JS version of our implementation https://bugs.webkit.org/show_bug.cgi?id=177472 Reviewed by Michael Saboff. This patch removes all appearances of "JS" and "VM" in the wasm directory. These now only appear in the wasm/js directory, which is only used in a JS embedding of wasm. It should therefore now be possible to create non-JS embeddings of wasm through JSC, though it'll still require: - Mild codegen for wasm<->embedder calls; - A strategy for trap handling (no need for full unwind! Could kill). - Creation of the Wasm::* objects. - Calling convention handling to call the embedder. - Handling of multiple embedders (see #177475, this is optional). Most of the patch consists in renaming JSWebAssemblyInstance to Instance, and removing temporary copies which I'd added to make this specific patch very simple. * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): this one place which needs to know about who "owns" the Wasm::Instance. In a JS embedding it's the JSWebAssemblyInstance. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::getGlobal): (JSC::Wasm::B3IRGenerator::setGlobal): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmContext.cpp: (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: add an "owner", the Wasm::Context, move the "tail" import information from JSWebAssemblyInstance over to here. (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::owner const): (JSC::Wasm::Instance::offsetOfOwner): (JSC::Wasm::Instance::context const): (JSC::Wasm::Instance::setMemory): (JSC::Wasm::Instance::setTable): (JSC::Wasm::Instance::offsetOfMemory): (JSC::Wasm::Instance::offsetOfGlobals): (JSC::Wasm::Instance::offsetOfTable): (JSC::Wasm::Instance::offsetOfTail): (JSC::Wasm::Instance::numImportFunctions const): (JSC::Wasm::Instance::importFunctionInfo): (JSC::Wasm::Instance::offsetOfTargetInstance): (JSC::Wasm::Instance::offsetOfWasmEntrypoint): (JSC::Wasm::Instance::offsetOfWasmToEmbedderStubExecutableAddress): (JSC::Wasm::Instance::offsetOfImportFunction): (JSC::Wasm::Instance::importFunction): (JSC::Wasm::Instance::allocationSize): (JSC::Wasm::Instance::create): Deleted. * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmTable.cpp: (JSC::Wasm::Table::Table): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyInstance.cpp: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): The embedder decides what the import function is. Here we must properly placement-new it to what we've elected (and initialize it later). (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::moduleNamespaceObject): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::setTable): (JSC::JSWebAssemblyInstance::offsetOfInstance): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::context const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTail): Deleted. (): Deleted. (JSC::JSWebAssemblyInstance::importFunctionInfo): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmToEmbedderStubExecutableAddress): Deleted. (JSC::JSWebAssemblyInstance::offsetOfImportFunction): Deleted. (JSC::JSWebAssemblyInstance::importFunction): Deleted. (JSC::JSWebAssemblyInstance::internalMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmCodeBlock const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmTable): Deleted. (JSC::JSWebAssemblyInstance::offsetOfGlobals): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTopEntryFramePointer): Deleted. (JSC::JSWebAssemblyInstance::cachedStackLimit const): Deleted. (JSC::JSWebAssemblyInstance::setCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::wasmMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmModule): Deleted. (JSC::JSWebAssemblyInstance::allocationSize): Deleted. * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::setFunction): * wasm/js/WasmToJS.cpp: One extra indirection to find the JSWebAssemblyInstance. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::instantiate): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Canonical link: https://commits.webkit.org/195012@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224020 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-26 15:33:55 +00:00
void finalizeCreation(void* owner, Ref<CodeBlock>&& codeBlock)
WebAssembly: no VM / JS version of everything but Instance https://bugs.webkit.org/show_bug.cgi?id=177473 Reviewed by Filip Pizlo, Saam Barati. JSTests: - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. * wasm/js-api/memory-grow.js: (assertEq): * wasm/js-api/table.js: (assert.throws): Source/JavaScriptCore: This change entails cleaning up and splitting a bunch of code which we had intertwined between C++ classes which represent JS objects, and pure C++ implementation objects. This specific change goes most of the way towards allowing JSC's WebAssembly to work without VM / JS, up to but excluding JSWebAssemblyInstance (there's Wasm::Instance, but it's not *the* thing yet). Because of this we still have a few FIXME identifying places that need to change. A follow-up change will go the rest of the way. I went about this change in the simplest way possible: grep the JavaScriptCore/wasm directory for "JS[^C_]" as well as "VM" and exclude the /js/ sub-directory (which contains the JS implementation of WebAssembly). None of this change removes the need for a JIT entitlement to be able to use WebAssembly. We don't have an interpreter, the process therefore still needs to be allowed to JIT to use these pure-C++ APIs. Interesting things to note: - Remove VM from Plan and associated places. It can just live as a capture in the callback lambda if it's needed. - Wasm::Memory shouldn't require a VM. It was only used to ask the GC to collect. We now instead pass two lambdas at construction time for this purpose: one to notify of memory pressure, and the other to ask for syncrhonous memory reclamation. This allows whoever creates the memory to dictate how to react to both these cases, and for a JS embedding that's to call the GC (async or sync, respectively). - Move grow logic from JSWebAssemblyMemory to Wasm::Memory::grow. Use Expected there, with an enum class for failure types. - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. - When generating the grow_memory opcode, no need to get the VM. Instead, reach directly for Wasm::Memory and grow it. - JSWebAssemblyMemory::grow can now always throw on failure, because it's only ever called from JS (not from grow_memory as before). - Wasm::Memory now takes a callback for successful growth. This allows JS wrappers to register themselves when growth succeeds without Wasm::Memory knowning anything about JS. It'll also allow creating a list of callbacks for when we add thread support (we'll want to notify many wrappers, all under a lock). - Wasm::Memory is now back to being the source of truth about address / size, used directly by generated code instead of JSWebAssemblyMemory. - Move wasmToJS from the general WasmBinding header to its own header under wasm/js. It's only used by wasm/js/JSWebAssemblyCodeBlock.cpp, and uses VM, and therefore isn't general WebAssembly. - Make Wasm::Context an actual type (just a struct holding a JSWebAssemlyInstance for now) instead of an alias for that. Notably this doesn't add anything to the Context and doesn't change what actually gets passed around in JIT code (fast TLS or registers) because these changes potentially impact performance. The entire purpose of this change is to allow passing Wasm::Context around without having to know about VM. Since VM contains a Wasm::Context the JS embedding is effectively the same, but with this setup a non-JS embedding is much better off. - Move JSWebAssembly into the JS folder. - OMGPlan: use Wasm::CodeBlock directly instead of JSWebAssemblyCodeBlock. - wasm->JS stubs are now on the instance's tail as raw pointers, instead of being on JSWebAssemblyCodeBlock, and are now called wasm->Embedder stubs. The owned reference is still on JSWebAssemblyCodeBlock, and is still called wasm->JS stub. This move means that the embedder must, after creating a Wasm::CodeBlock, somehow create the stubs to call back into the embedder. This removes an indirection in the generated code because the B3 IR generator now reaches into the instance instead of JSWebAssemblyCodeBlock. - Move more CodeBlock things. Compilation completion is now marked by its own atomic<bool> flag instead of a nullptr plan: that required using a lock, and was causing a deadlock in stack-trace.js because before my changes JSWebAssemblyCodeBlock did its own completion checking separately from Wasm::CodeBlock, without getting the lock. Now that everything points to Wasm::CodeBlock and there's no cached completion marker, the lock was being acquired in a sanity-check assertion. - Embedder -> Wasm wrappers are now generated through a function that's passed in at compilation time, instead of being hard-coded as a JS -> Wasm wrapper. - WasmMemory doens't need to know about fault handling thunks. Only the IR generator should know, and should make sure that the exception throwing thunk is generated if any memory is present (note: with signal handling not all of them generate an exception check). - Make exception throwing pluggable: instead of having a hard-coded JS-specific lambda we now have a regular C++ function being called from JIT code when a WebAssembly exception is thrown. This allows any embedder to get called as they wish. For now a process can only have a single of these functions (i.e. only one embedder per process) because the trap handler is a singleton. That can be fixed in in #177475. - Create WasmEmbedder.h where all embedder plugging will live. - Split up JSWebAssemblyTable into Wasm::Table which is refcounted. JSWebAssemblyTable now only contains the JS functions in the table, and Wasm::Table is what's used by the JIT code to lookup where to call and do the instance check (for context switch). Note that this creates an extra allocation for all the instances in Wasm::Table, and in exchange removes an indirection in JIT code because the instance used to be obtained off of the JS function. Also note that it's the embedder than keeps the instances alive, not Wasm::Table (which holds a dumb pointer to the instance), because doing otherwise would cause reference cycles. - Add WasmInstance. It doesn't do much for now, owns globals. - JSWebAssembly instance now doesn't just contain the imported functions as JSObjects, it also has the corresponding import's instance and wasm entrypoint. This triples the space allocated per instance's imported function, but there shouldn't be that many imports. This has two upsides: it creates smaller and faster code, and makes is easier to disassociate embedder-specific things from embedder-neutral things. The small / faster win is in two places: B3 IR generator only needs offsetOfImportFunction for the call opcode (when the called index is an import) to know whether the import is wasm->wasm or wasm->embedder (this isn't known at compile-time because it's dependent on the import object), this is now done by seeing if that import function has an associated target instance (only wasm->wasm does); the other place is wasmBinding which uses offsetOfImportFunction to figure out the wasm->wasm target instance, and then gets WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation to do a tail call. The disassociation comes because the target instance can be Wasm::Instance once we change what the Context is, and WasmEntrypointLoadLocation is already embedder-independent. As a next step I can move this tail allocation from JSWebAssemblyInstance to Wasm::Instance, and leave importFunction in as an opaque pointer which is embedder-specific, and in JS will remain WriteBarrier<JSObject>. - Rename VMEntryFrame to EntryFrame, and in many places pass a pointer to it around instead of VM. This is a first step in allowing entry frames which aren't stored on VM, but which are instead stored in an embedder-specific location. That change won't really affect JS except through code churn, but will allow WebAssembly to use some machinery in a generic manner without having a VM. * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * debugger/Debugger.cpp: (JSC::Debugger::stepOutOfFunction): (JSC::Debugger::returnEvent): (JSC::Debugger::unwindEvent): (JSC::Debugger::didExecuteProgram): * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::compileExceptionHandlers): * dfg/DFGOSREntry.cpp: (JSC::DFG::prepareOSREntry): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::compileOSRExit): (JSC::DFG::OSRExit::compileExit): * dfg/DFGThunks.cpp: (JSC::DFG::osrEntryThunkGenerator): * ftl/FTLCompile.cpp: (JSC::FTL::compile): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::lower): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): (JSC::CallFrame::callerFrame): (JSC::CallFrame::unsafeCallerFrame): * interpreter/CallFrame.h: (JSC::ExecState::callerFrame const): (JSC::ExecState::callerFrameOrEntryFrame const): (JSC::ExecState::unsafeCallerFrameOrEntryFrame const): * interpreter/FrameTracers.h: (JSC::NativeCallFrameTracer::NativeCallFrameTracer): (JSC::NativeCallFrameTracerWithRestore::NativeCallFrameTracerWithRestore): (JSC::NativeCallFrameTracerWithRestore::~NativeCallFrameTracerWithRestore): * interpreter/Interpreter.cpp: (JSC::UnwindFunctor::operator() const): (JSC::UnwindFunctor::copyCalleeSavesToEntryFrameCalleeSavesBuffer const): (JSC::Interpreter::unwind): * interpreter/StackVisitor.cpp: (JSC::StackVisitor::StackVisitor): (JSC::StackVisitor::gotoNextFrame): (JSC::StackVisitor::readNonInlinedFrame): (JSC::StackVisitor::Frame::dump const): * interpreter/StackVisitor.h: (JSC::StackVisitor::Frame::callerIsEntryFrame const): * interpreter/VMEntryRecord.h: (JSC::VMEntryRecord::prevTopEntryFrame): (JSC::VMEntryRecord::unsafePrevTopEntryFrame): (JSC::EntryFrame::vmEntryRecordOffset): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::restoreCalleeSavesFromEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::loadWasmContextInstance): (JSC::AssemblyHelpers::storeWasmContextInstance): (JSC::AssemblyHelpers::loadWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::storeWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBufferImpl): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::copyCalleeSavesToVMEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer): * jit/JIT.cpp: (JSC::JIT::emitEnterOptimizationCheck): (JSC::JIT::privateCompileExceptionHandlers): * jit/JITExceptions.cpp: (JSC::genericUnwind): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): (JSC::JIT::emitSlow_op_loop_hint): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): * jit/JITOperations.cpp: * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::nativeForGenerator): * jsc.cpp: (functionDumpCallFrame): * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LLIntThunks.cpp: (JSC::vmEntryRecord): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/Options.cpp: (JSC::recomputeDependentOptions): * runtime/Options.h: * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::FrameWalker): (JSC::FrameWalker::advanceToParentFrame): (JSC::SamplingProfiler::processUnverifiedStackTraces): * runtime/ThrowScope.cpp: (JSC::ThrowScope::~ThrowScope): * runtime/VM.cpp: (JSC::VM::VM): (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::topEntryFrameOffset): * runtime/VMTraps.cpp: (JSC::isSaneFrame): (JSC::VMTraps::tryInstallTrapBreakpoints): (JSC::VMTraps::invalidateCodeBlocksOnStack): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWasmContextInstance): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::parseAndCompile): * wasm/WasmB3IRGenerator.h: * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::BBQPlan): (JSC::Wasm::BBQPlan::compileFunctions): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBBQPlanInlines.h: (JSC::Wasm::BBQPlan::initializeCallees): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmBinding.h: * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::create): (JSC::Wasm::CodeBlock::CodeBlock): (JSC::Wasm::CodeBlock::compileAsync): (JSC::Wasm::CodeBlock::setCompilationFinished): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::offsetOfImportStubs): (JSC::Wasm::CodeBlock::allocationSize): (JSC::Wasm::CodeBlock::importWasmToEmbedderStub): (JSC::Wasm::CodeBlock::offsetOfImportWasmToEmbedderStub): (JSC::Wasm::CodeBlock::wasmToJSCallStubForImport): (JSC::Wasm::CodeBlock::compilationFinished): (JSC::Wasm::CodeBlock::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): * wasm/WasmContext.cpp: (JSC::Wasm::Context::useFastTLS): (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: Copied from Source/JavaScriptCore/wasm/WasmContext.h. * wasm/WasmFaultSignalHandler.cpp: * wasm/WasmFaultSignalHandler.h: * wasm/WasmFormat.h: * wasm/WasmInstance.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::~Instance): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: Added. (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::module): (JSC::Wasm::Instance::codeBlock): (JSC::Wasm::Instance::memory): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::loadF32Global const): (JSC::Wasm::Instance::loadF64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::offsetOfCachedStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::~Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::offsetOfSize): * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationCallback): (JSC::Wasm::Module::validateSync): (JSC::Wasm::Module::validateAsync): (JSC::Wasm::Module::getOrCreateCodeBlock): (JSC::Wasm::Module::compileSync): (JSC::Wasm::Module::compileAsync): * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseTableHelper): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::OMGPlan): (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::isValid const): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::runCompletionTasks): (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmPlan.h: (JSC::Wasm::Plan::dontFinalize): * wasm/WasmSignature.cpp: * wasm/WasmSignature.h: * wasm/WasmTable.cpp: Added. (JSC::Wasm::Table::create): (JSC::Wasm::Table::~Table): (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h. (JSC::Wasm::Table::maximum const): (JSC::Wasm::Table::size const): (JSC::Wasm::Table::offsetOfSize): (JSC::Wasm::Table::offsetOfFunctions): (JSC::Wasm::Table::offsetOfInstances): (JSC::Wasm::Table::isValidSize): * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): (JSC::Wasm::Thunks::setThrowWasmException): (JSC::Wasm::Thunks::throwWasmException): * wasm/WasmThunks.h: * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::stopAllPlansForContext): * wasm/WasmWorklist.h: * wasm/js/JSToWasm.cpp: Added. (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/JSWebAssembly.cpp: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.cpp. * wasm/js/JSWebAssembly.h: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.h. * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::create): (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::context const): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::webAssemblyToJSCallee): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::offsetOfTail): (JSC::JSWebAssemblyInstance::importFunctionInfo): (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): (JSC::JSWebAssemblyInstance::offsetOfImportFunction): (JSC::JSWebAssemblyInstance::importFunction): (JSC::JSWebAssemblyInstance::internalMemory): (JSC::JSWebAssemblyInstance::wasmCodeBlock const): (JSC::JSWebAssemblyInstance::offsetOfWasmTable): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::offsetOfGlobals): (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): (JSC::JSWebAssemblyInstance::cachedStackLimit const): (JSC::JSWebAssemblyInstance::setCachedStackLimit): (JSC::JSWebAssemblyInstance::wasmMemory): (JSC::JSWebAssemblyInstance::wasmModule): (JSC::JSWebAssemblyInstance::allocationSize): (JSC::JSWebAssemblyInstance::module const): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::create): (JSC::JSWebAssemblyMemory::adopt): (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::moduleInformation const): (JSC::JSWebAssemblyModule::exportSymbolTable const): (JSC::JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace const): (JSC::JSWebAssemblyModule::callee const): (JSC::JSWebAssemblyModule::codeBlock): (JSC::JSWebAssemblyModule::module): * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::create): (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::visitChildren): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::getFunction): (JSC::JSWebAssemblyTable::clearFunction): (JSC::JSWebAssemblyTable::setFunction): * wasm/js/JSWebAssemblyTable.h: (JSC::JSWebAssemblyTable::isValidSize): (JSC::JSWebAssemblyTable::maximum const): (JSC::JSWebAssemblyTable::size const): (JSC::JSWebAssemblyTable::table): * wasm/js/WasmToJS.cpp: Copied from Source/JavaScriptCore/wasm/WasmBinding.cpp. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): (JSC::WebAssemblyModuleConstructor::createModule): * wasm/js/WebAssemblyModuleConstructor.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::webAssemblyCompileFunc): (JSC::instantiate): (JSC::compileAndInstantiate): (JSC::webAssemblyValidateFunc): * wasm/js/WebAssemblyTableConstructor.cpp: (JSC::constructJSWebAssemblyTable): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Source/WebCore: * ForwardingHeaders/wasm/WasmModule.h: Added. This used to be included in JSWebAssemblyModule.h. * bindings/js/SerializedScriptValue.cpp: Update postMessage code according to C++ API changes. Canonical link: https://commits.webkit.org/194750@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223738 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-20 02:23:29 +00:00
{
WebAssembly: no VM / JS version of our implementation https://bugs.webkit.org/show_bug.cgi?id=177472 Reviewed by Michael Saboff. This patch removes all appearances of "JS" and "VM" in the wasm directory. These now only appear in the wasm/js directory, which is only used in a JS embedding of wasm. It should therefore now be possible to create non-JS embeddings of wasm through JSC, though it'll still require: - Mild codegen for wasm<->embedder calls; - A strategy for trap handling (no need for full unwind! Could kill). - Creation of the Wasm::* objects. - Calling convention handling to call the embedder. - Handling of multiple embedders (see #177475, this is optional). Most of the patch consists in renaming JSWebAssemblyInstance to Instance, and removing temporary copies which I'd added to make this specific patch very simple. * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): this one place which needs to know about who "owns" the Wasm::Instance. In a JS embedding it's the JSWebAssemblyInstance. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::getGlobal): (JSC::Wasm::B3IRGenerator::setGlobal): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmContext.cpp: (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: add an "owner", the Wasm::Context, move the "tail" import information from JSWebAssemblyInstance over to here. (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::owner const): (JSC::Wasm::Instance::offsetOfOwner): (JSC::Wasm::Instance::context const): (JSC::Wasm::Instance::setMemory): (JSC::Wasm::Instance::setTable): (JSC::Wasm::Instance::offsetOfMemory): (JSC::Wasm::Instance::offsetOfGlobals): (JSC::Wasm::Instance::offsetOfTable): (JSC::Wasm::Instance::offsetOfTail): (JSC::Wasm::Instance::numImportFunctions const): (JSC::Wasm::Instance::importFunctionInfo): (JSC::Wasm::Instance::offsetOfTargetInstance): (JSC::Wasm::Instance::offsetOfWasmEntrypoint): (JSC::Wasm::Instance::offsetOfWasmToEmbedderStubExecutableAddress): (JSC::Wasm::Instance::offsetOfImportFunction): (JSC::Wasm::Instance::importFunction): (JSC::Wasm::Instance::allocationSize): (JSC::Wasm::Instance::create): Deleted. * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmTable.cpp: (JSC::Wasm::Table::Table): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyInstance.cpp: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): The embedder decides what the import function is. Here we must properly placement-new it to what we've elected (and initialize it later). (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::moduleNamespaceObject): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::setTable): (JSC::JSWebAssemblyInstance::offsetOfInstance): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::context const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTail): Deleted. (): Deleted. (JSC::JSWebAssemblyInstance::importFunctionInfo): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmToEmbedderStubExecutableAddress): Deleted. (JSC::JSWebAssemblyInstance::offsetOfImportFunction): Deleted. (JSC::JSWebAssemblyInstance::importFunction): Deleted. (JSC::JSWebAssemblyInstance::internalMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmCodeBlock const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmTable): Deleted. (JSC::JSWebAssemblyInstance::offsetOfGlobals): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTopEntryFramePointer): Deleted. (JSC::JSWebAssemblyInstance::cachedStackLimit const): Deleted. (JSC::JSWebAssemblyInstance::setCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::wasmMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmModule): Deleted. (JSC::JSWebAssemblyInstance::allocationSize): Deleted. * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::setFunction): * wasm/js/WasmToJS.cpp: One extra indirection to find the JSWebAssemblyInstance. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::instantiate): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Canonical link: https://commits.webkit.org/195012@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224020 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-26 15:33:55 +00:00
m_owner = owner;
WebAssembly: no VM / JS version of everything but Instance https://bugs.webkit.org/show_bug.cgi?id=177473 Reviewed by Filip Pizlo, Saam Barati. JSTests: - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. * wasm/js-api/memory-grow.js: (assertEq): * wasm/js-api/table.js: (assert.throws): Source/JavaScriptCore: This change entails cleaning up and splitting a bunch of code which we had intertwined between C++ classes which represent JS objects, and pure C++ implementation objects. This specific change goes most of the way towards allowing JSC's WebAssembly to work without VM / JS, up to but excluding JSWebAssemblyInstance (there's Wasm::Instance, but it's not *the* thing yet). Because of this we still have a few FIXME identifying places that need to change. A follow-up change will go the rest of the way. I went about this change in the simplest way possible: grep the JavaScriptCore/wasm directory for "JS[^C_]" as well as "VM" and exclude the /js/ sub-directory (which contains the JS implementation of WebAssembly). None of this change removes the need for a JIT entitlement to be able to use WebAssembly. We don't have an interpreter, the process therefore still needs to be allowed to JIT to use these pure-C++ APIs. Interesting things to note: - Remove VM from Plan and associated places. It can just live as a capture in the callback lambda if it's needed. - Wasm::Memory shouldn't require a VM. It was only used to ask the GC to collect. We now instead pass two lambdas at construction time for this purpose: one to notify of memory pressure, and the other to ask for syncrhonous memory reclamation. This allows whoever creates the memory to dictate how to react to both these cases, and for a JS embedding that's to call the GC (async or sync, respectively). - Move grow logic from JSWebAssemblyMemory to Wasm::Memory::grow. Use Expected there, with an enum class for failure types. - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. - When generating the grow_memory opcode, no need to get the VM. Instead, reach directly for Wasm::Memory and grow it. - JSWebAssemblyMemory::grow can now always throw on failure, because it's only ever called from JS (not from grow_memory as before). - Wasm::Memory now takes a callback for successful growth. This allows JS wrappers to register themselves when growth succeeds without Wasm::Memory knowning anything about JS. It'll also allow creating a list of callbacks for when we add thread support (we'll want to notify many wrappers, all under a lock). - Wasm::Memory is now back to being the source of truth about address / size, used directly by generated code instead of JSWebAssemblyMemory. - Move wasmToJS from the general WasmBinding header to its own header under wasm/js. It's only used by wasm/js/JSWebAssemblyCodeBlock.cpp, and uses VM, and therefore isn't general WebAssembly. - Make Wasm::Context an actual type (just a struct holding a JSWebAssemlyInstance for now) instead of an alias for that. Notably this doesn't add anything to the Context and doesn't change what actually gets passed around in JIT code (fast TLS or registers) because these changes potentially impact performance. The entire purpose of this change is to allow passing Wasm::Context around without having to know about VM. Since VM contains a Wasm::Context the JS embedding is effectively the same, but with this setup a non-JS embedding is much better off. - Move JSWebAssembly into the JS folder. - OMGPlan: use Wasm::CodeBlock directly instead of JSWebAssemblyCodeBlock. - wasm->JS stubs are now on the instance's tail as raw pointers, instead of being on JSWebAssemblyCodeBlock, and are now called wasm->Embedder stubs. The owned reference is still on JSWebAssemblyCodeBlock, and is still called wasm->JS stub. This move means that the embedder must, after creating a Wasm::CodeBlock, somehow create the stubs to call back into the embedder. This removes an indirection in the generated code because the B3 IR generator now reaches into the instance instead of JSWebAssemblyCodeBlock. - Move more CodeBlock things. Compilation completion is now marked by its own atomic<bool> flag instead of a nullptr plan: that required using a lock, and was causing a deadlock in stack-trace.js because before my changes JSWebAssemblyCodeBlock did its own completion checking separately from Wasm::CodeBlock, without getting the lock. Now that everything points to Wasm::CodeBlock and there's no cached completion marker, the lock was being acquired in a sanity-check assertion. - Embedder -> Wasm wrappers are now generated through a function that's passed in at compilation time, instead of being hard-coded as a JS -> Wasm wrapper. - WasmMemory doens't need to know about fault handling thunks. Only the IR generator should know, and should make sure that the exception throwing thunk is generated if any memory is present (note: with signal handling not all of them generate an exception check). - Make exception throwing pluggable: instead of having a hard-coded JS-specific lambda we now have a regular C++ function being called from JIT code when a WebAssembly exception is thrown. This allows any embedder to get called as they wish. For now a process can only have a single of these functions (i.e. only one embedder per process) because the trap handler is a singleton. That can be fixed in in #177475. - Create WasmEmbedder.h where all embedder plugging will live. - Split up JSWebAssemblyTable into Wasm::Table which is refcounted. JSWebAssemblyTable now only contains the JS functions in the table, and Wasm::Table is what's used by the JIT code to lookup where to call and do the instance check (for context switch). Note that this creates an extra allocation for all the instances in Wasm::Table, and in exchange removes an indirection in JIT code because the instance used to be obtained off of the JS function. Also note that it's the embedder than keeps the instances alive, not Wasm::Table (which holds a dumb pointer to the instance), because doing otherwise would cause reference cycles. - Add WasmInstance. It doesn't do much for now, owns globals. - JSWebAssembly instance now doesn't just contain the imported functions as JSObjects, it also has the corresponding import's instance and wasm entrypoint. This triples the space allocated per instance's imported function, but there shouldn't be that many imports. This has two upsides: it creates smaller and faster code, and makes is easier to disassociate embedder-specific things from embedder-neutral things. The small / faster win is in two places: B3 IR generator only needs offsetOfImportFunction for the call opcode (when the called index is an import) to know whether the import is wasm->wasm or wasm->embedder (this isn't known at compile-time because it's dependent on the import object), this is now done by seeing if that import function has an associated target instance (only wasm->wasm does); the other place is wasmBinding which uses offsetOfImportFunction to figure out the wasm->wasm target instance, and then gets WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation to do a tail call. The disassociation comes because the target instance can be Wasm::Instance once we change what the Context is, and WasmEntrypointLoadLocation is already embedder-independent. As a next step I can move this tail allocation from JSWebAssemblyInstance to Wasm::Instance, and leave importFunction in as an opaque pointer which is embedder-specific, and in JS will remain WriteBarrier<JSObject>. - Rename VMEntryFrame to EntryFrame, and in many places pass a pointer to it around instead of VM. This is a first step in allowing entry frames which aren't stored on VM, but which are instead stored in an embedder-specific location. That change won't really affect JS except through code churn, but will allow WebAssembly to use some machinery in a generic manner without having a VM. * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * debugger/Debugger.cpp: (JSC::Debugger::stepOutOfFunction): (JSC::Debugger::returnEvent): (JSC::Debugger::unwindEvent): (JSC::Debugger::didExecuteProgram): * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::compileExceptionHandlers): * dfg/DFGOSREntry.cpp: (JSC::DFG::prepareOSREntry): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::compileOSRExit): (JSC::DFG::OSRExit::compileExit): * dfg/DFGThunks.cpp: (JSC::DFG::osrEntryThunkGenerator): * ftl/FTLCompile.cpp: (JSC::FTL::compile): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::lower): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): (JSC::CallFrame::callerFrame): (JSC::CallFrame::unsafeCallerFrame): * interpreter/CallFrame.h: (JSC::ExecState::callerFrame const): (JSC::ExecState::callerFrameOrEntryFrame const): (JSC::ExecState::unsafeCallerFrameOrEntryFrame const): * interpreter/FrameTracers.h: (JSC::NativeCallFrameTracer::NativeCallFrameTracer): (JSC::NativeCallFrameTracerWithRestore::NativeCallFrameTracerWithRestore): (JSC::NativeCallFrameTracerWithRestore::~NativeCallFrameTracerWithRestore): * interpreter/Interpreter.cpp: (JSC::UnwindFunctor::operator() const): (JSC::UnwindFunctor::copyCalleeSavesToEntryFrameCalleeSavesBuffer const): (JSC::Interpreter::unwind): * interpreter/StackVisitor.cpp: (JSC::StackVisitor::StackVisitor): (JSC::StackVisitor::gotoNextFrame): (JSC::StackVisitor::readNonInlinedFrame): (JSC::StackVisitor::Frame::dump const): * interpreter/StackVisitor.h: (JSC::StackVisitor::Frame::callerIsEntryFrame const): * interpreter/VMEntryRecord.h: (JSC::VMEntryRecord::prevTopEntryFrame): (JSC::VMEntryRecord::unsafePrevTopEntryFrame): (JSC::EntryFrame::vmEntryRecordOffset): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::restoreCalleeSavesFromEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::loadWasmContextInstance): (JSC::AssemblyHelpers::storeWasmContextInstance): (JSC::AssemblyHelpers::loadWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::storeWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBufferImpl): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::copyCalleeSavesToVMEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer): * jit/JIT.cpp: (JSC::JIT::emitEnterOptimizationCheck): (JSC::JIT::privateCompileExceptionHandlers): * jit/JITExceptions.cpp: (JSC::genericUnwind): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): (JSC::JIT::emitSlow_op_loop_hint): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): * jit/JITOperations.cpp: * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::nativeForGenerator): * jsc.cpp: (functionDumpCallFrame): * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LLIntThunks.cpp: (JSC::vmEntryRecord): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/Options.cpp: (JSC::recomputeDependentOptions): * runtime/Options.h: * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::FrameWalker): (JSC::FrameWalker::advanceToParentFrame): (JSC::SamplingProfiler::processUnverifiedStackTraces): * runtime/ThrowScope.cpp: (JSC::ThrowScope::~ThrowScope): * runtime/VM.cpp: (JSC::VM::VM): (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::topEntryFrameOffset): * runtime/VMTraps.cpp: (JSC::isSaneFrame): (JSC::VMTraps::tryInstallTrapBreakpoints): (JSC::VMTraps::invalidateCodeBlocksOnStack): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWasmContextInstance): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::parseAndCompile): * wasm/WasmB3IRGenerator.h: * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::BBQPlan): (JSC::Wasm::BBQPlan::compileFunctions): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBBQPlanInlines.h: (JSC::Wasm::BBQPlan::initializeCallees): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmBinding.h: * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::create): (JSC::Wasm::CodeBlock::CodeBlock): (JSC::Wasm::CodeBlock::compileAsync): (JSC::Wasm::CodeBlock::setCompilationFinished): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::offsetOfImportStubs): (JSC::Wasm::CodeBlock::allocationSize): (JSC::Wasm::CodeBlock::importWasmToEmbedderStub): (JSC::Wasm::CodeBlock::offsetOfImportWasmToEmbedderStub): (JSC::Wasm::CodeBlock::wasmToJSCallStubForImport): (JSC::Wasm::CodeBlock::compilationFinished): (JSC::Wasm::CodeBlock::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): * wasm/WasmContext.cpp: (JSC::Wasm::Context::useFastTLS): (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: Copied from Source/JavaScriptCore/wasm/WasmContext.h. * wasm/WasmFaultSignalHandler.cpp: * wasm/WasmFaultSignalHandler.h: * wasm/WasmFormat.h: * wasm/WasmInstance.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::~Instance): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: Added. (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::module): (JSC::Wasm::Instance::codeBlock): (JSC::Wasm::Instance::memory): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::loadF32Global const): (JSC::Wasm::Instance::loadF64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::offsetOfCachedStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::~Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::offsetOfSize): * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationCallback): (JSC::Wasm::Module::validateSync): (JSC::Wasm::Module::validateAsync): (JSC::Wasm::Module::getOrCreateCodeBlock): (JSC::Wasm::Module::compileSync): (JSC::Wasm::Module::compileAsync): * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseTableHelper): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::OMGPlan): (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::isValid const): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::runCompletionTasks): (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmPlan.h: (JSC::Wasm::Plan::dontFinalize): * wasm/WasmSignature.cpp: * wasm/WasmSignature.h: * wasm/WasmTable.cpp: Added. (JSC::Wasm::Table::create): (JSC::Wasm::Table::~Table): (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h. (JSC::Wasm::Table::maximum const): (JSC::Wasm::Table::size const): (JSC::Wasm::Table::offsetOfSize): (JSC::Wasm::Table::offsetOfFunctions): (JSC::Wasm::Table::offsetOfInstances): (JSC::Wasm::Table::isValidSize): * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): (JSC::Wasm::Thunks::setThrowWasmException): (JSC::Wasm::Thunks::throwWasmException): * wasm/WasmThunks.h: * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::stopAllPlansForContext): * wasm/WasmWorklist.h: * wasm/js/JSToWasm.cpp: Added. (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/JSWebAssembly.cpp: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.cpp. * wasm/js/JSWebAssembly.h: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.h. * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::create): (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::context const): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::webAssemblyToJSCallee): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::offsetOfTail): (JSC::JSWebAssemblyInstance::importFunctionInfo): (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): (JSC::JSWebAssemblyInstance::offsetOfImportFunction): (JSC::JSWebAssemblyInstance::importFunction): (JSC::JSWebAssemblyInstance::internalMemory): (JSC::JSWebAssemblyInstance::wasmCodeBlock const): (JSC::JSWebAssemblyInstance::offsetOfWasmTable): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::offsetOfGlobals): (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): (JSC::JSWebAssemblyInstance::cachedStackLimit const): (JSC::JSWebAssemblyInstance::setCachedStackLimit): (JSC::JSWebAssemblyInstance::wasmMemory): (JSC::JSWebAssemblyInstance::wasmModule): (JSC::JSWebAssemblyInstance::allocationSize): (JSC::JSWebAssemblyInstance::module const): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::create): (JSC::JSWebAssemblyMemory::adopt): (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::moduleInformation const): (JSC::JSWebAssemblyModule::exportSymbolTable const): (JSC::JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace const): (JSC::JSWebAssemblyModule::callee const): (JSC::JSWebAssemblyModule::codeBlock): (JSC::JSWebAssemblyModule::module): * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::create): (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::visitChildren): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::getFunction): (JSC::JSWebAssemblyTable::clearFunction): (JSC::JSWebAssemblyTable::setFunction): * wasm/js/JSWebAssemblyTable.h: (JSC::JSWebAssemblyTable::isValidSize): (JSC::JSWebAssemblyTable::maximum const): (JSC::JSWebAssemblyTable::size const): (JSC::JSWebAssemblyTable::table): * wasm/js/WasmToJS.cpp: Copied from Source/JavaScriptCore/wasm/WasmBinding.cpp. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): (JSC::WebAssemblyModuleConstructor::createModule): * wasm/js/WebAssemblyModuleConstructor.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::webAssemblyCompileFunc): (JSC::instantiate): (JSC::compileAndInstantiate): (JSC::webAssemblyValidateFunc): * wasm/js/WebAssemblyTableConstructor.cpp: (JSC::constructJSWebAssemblyTable): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Source/WebCore: * ForwardingHeaders/wasm/WasmModule.h: Added. This used to be included in JSWebAssemblyModule.h. * bindings/js/SerializedScriptValue.cpp: Update postMessage code according to C++ API changes. Canonical link: https://commits.webkit.org/194750@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223738 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-20 02:23:29 +00:00
m_codeBlock = WTFMove(codeBlock);
}
JS_EXPORT_PRIVATE ~Instance();
WebAssembly: no VM / JS version of our implementation https://bugs.webkit.org/show_bug.cgi?id=177472 Reviewed by Michael Saboff. This patch removes all appearances of "JS" and "VM" in the wasm directory. These now only appear in the wasm/js directory, which is only used in a JS embedding of wasm. It should therefore now be possible to create non-JS embeddings of wasm through JSC, though it'll still require: - Mild codegen for wasm<->embedder calls; - A strategy for trap handling (no need for full unwind! Could kill). - Creation of the Wasm::* objects. - Calling convention handling to call the embedder. - Handling of multiple embedders (see #177475, this is optional). Most of the patch consists in renaming JSWebAssemblyInstance to Instance, and removing temporary copies which I'd added to make this specific patch very simple. * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): this one place which needs to know about who "owns" the Wasm::Instance. In a JS embedding it's the JSWebAssemblyInstance. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::getGlobal): (JSC::Wasm::B3IRGenerator::setGlobal): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmContext.cpp: (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: add an "owner", the Wasm::Context, move the "tail" import information from JSWebAssemblyInstance over to here. (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::owner const): (JSC::Wasm::Instance::offsetOfOwner): (JSC::Wasm::Instance::context const): (JSC::Wasm::Instance::setMemory): (JSC::Wasm::Instance::setTable): (JSC::Wasm::Instance::offsetOfMemory): (JSC::Wasm::Instance::offsetOfGlobals): (JSC::Wasm::Instance::offsetOfTable): (JSC::Wasm::Instance::offsetOfTail): (JSC::Wasm::Instance::numImportFunctions const): (JSC::Wasm::Instance::importFunctionInfo): (JSC::Wasm::Instance::offsetOfTargetInstance): (JSC::Wasm::Instance::offsetOfWasmEntrypoint): (JSC::Wasm::Instance::offsetOfWasmToEmbedderStubExecutableAddress): (JSC::Wasm::Instance::offsetOfImportFunction): (JSC::Wasm::Instance::importFunction): (JSC::Wasm::Instance::allocationSize): (JSC::Wasm::Instance::create): Deleted. * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmTable.cpp: (JSC::Wasm::Table::Table): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyInstance.cpp: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): The embedder decides what the import function is. Here we must properly placement-new it to what we've elected (and initialize it later). (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::moduleNamespaceObject): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::setTable): (JSC::JSWebAssemblyInstance::offsetOfInstance): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::context const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTail): Deleted. (): Deleted. (JSC::JSWebAssemblyInstance::importFunctionInfo): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmToEmbedderStubExecutableAddress): Deleted. (JSC::JSWebAssemblyInstance::offsetOfImportFunction): Deleted. (JSC::JSWebAssemblyInstance::importFunction): Deleted. (JSC::JSWebAssemblyInstance::internalMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmCodeBlock const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmTable): Deleted. (JSC::JSWebAssemblyInstance::offsetOfGlobals): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTopEntryFramePointer): Deleted. (JSC::JSWebAssemblyInstance::cachedStackLimit const): Deleted. (JSC::JSWebAssemblyInstance::setCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::wasmMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmModule): Deleted. (JSC::JSWebAssemblyInstance::allocationSize): Deleted. * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::setFunction): * wasm/js/WasmToJS.cpp: One extra indirection to find the JSWebAssemblyInstance. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::instantiate): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Canonical link: https://commits.webkit.org/195012@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224020 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-26 15:33:55 +00:00
template<typename T> T* owner() const { return reinterpret_cast<T*>(m_owner); }
static ptrdiff_t offsetOfOwner() { return OBJECT_OFFSETOF(Instance, m_owner); }
WebAssembly: no VM / JS version of everything but Instance https://bugs.webkit.org/show_bug.cgi?id=177473 Reviewed by Filip Pizlo, Saam Barati. JSTests: - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. * wasm/js-api/memory-grow.js: (assertEq): * wasm/js-api/table.js: (assert.throws): Source/JavaScriptCore: This change entails cleaning up and splitting a bunch of code which we had intertwined between C++ classes which represent JS objects, and pure C++ implementation objects. This specific change goes most of the way towards allowing JSC's WebAssembly to work without VM / JS, up to but excluding JSWebAssemblyInstance (there's Wasm::Instance, but it's not *the* thing yet). Because of this we still have a few FIXME identifying places that need to change. A follow-up change will go the rest of the way. I went about this change in the simplest way possible: grep the JavaScriptCore/wasm directory for "JS[^C_]" as well as "VM" and exclude the /js/ sub-directory (which contains the JS implementation of WebAssembly). None of this change removes the need for a JIT entitlement to be able to use WebAssembly. We don't have an interpreter, the process therefore still needs to be allowed to JIT to use these pure-C++ APIs. Interesting things to note: - Remove VM from Plan and associated places. It can just live as a capture in the callback lambda if it's needed. - Wasm::Memory shouldn't require a VM. It was only used to ask the GC to collect. We now instead pass two lambdas at construction time for this purpose: one to notify of memory pressure, and the other to ask for syncrhonous memory reclamation. This allows whoever creates the memory to dictate how to react to both these cases, and for a JS embedding that's to call the GC (async or sync, respectively). - Move grow logic from JSWebAssemblyMemory to Wasm::Memory::grow. Use Expected there, with an enum class for failure types. - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. - When generating the grow_memory opcode, no need to get the VM. Instead, reach directly for Wasm::Memory and grow it. - JSWebAssemblyMemory::grow can now always throw on failure, because it's only ever called from JS (not from grow_memory as before). - Wasm::Memory now takes a callback for successful growth. This allows JS wrappers to register themselves when growth succeeds without Wasm::Memory knowning anything about JS. It'll also allow creating a list of callbacks for when we add thread support (we'll want to notify many wrappers, all under a lock). - Wasm::Memory is now back to being the source of truth about address / size, used directly by generated code instead of JSWebAssemblyMemory. - Move wasmToJS from the general WasmBinding header to its own header under wasm/js. It's only used by wasm/js/JSWebAssemblyCodeBlock.cpp, and uses VM, and therefore isn't general WebAssembly. - Make Wasm::Context an actual type (just a struct holding a JSWebAssemlyInstance for now) instead of an alias for that. Notably this doesn't add anything to the Context and doesn't change what actually gets passed around in JIT code (fast TLS or registers) because these changes potentially impact performance. The entire purpose of this change is to allow passing Wasm::Context around without having to know about VM. Since VM contains a Wasm::Context the JS embedding is effectively the same, but with this setup a non-JS embedding is much better off. - Move JSWebAssembly into the JS folder. - OMGPlan: use Wasm::CodeBlock directly instead of JSWebAssemblyCodeBlock. - wasm->JS stubs are now on the instance's tail as raw pointers, instead of being on JSWebAssemblyCodeBlock, and are now called wasm->Embedder stubs. The owned reference is still on JSWebAssemblyCodeBlock, and is still called wasm->JS stub. This move means that the embedder must, after creating a Wasm::CodeBlock, somehow create the stubs to call back into the embedder. This removes an indirection in the generated code because the B3 IR generator now reaches into the instance instead of JSWebAssemblyCodeBlock. - Move more CodeBlock things. Compilation completion is now marked by its own atomic<bool> flag instead of a nullptr plan: that required using a lock, and was causing a deadlock in stack-trace.js because before my changes JSWebAssemblyCodeBlock did its own completion checking separately from Wasm::CodeBlock, without getting the lock. Now that everything points to Wasm::CodeBlock and there's no cached completion marker, the lock was being acquired in a sanity-check assertion. - Embedder -> Wasm wrappers are now generated through a function that's passed in at compilation time, instead of being hard-coded as a JS -> Wasm wrapper. - WasmMemory doens't need to know about fault handling thunks. Only the IR generator should know, and should make sure that the exception throwing thunk is generated if any memory is present (note: with signal handling not all of them generate an exception check). - Make exception throwing pluggable: instead of having a hard-coded JS-specific lambda we now have a regular C++ function being called from JIT code when a WebAssembly exception is thrown. This allows any embedder to get called as they wish. For now a process can only have a single of these functions (i.e. only one embedder per process) because the trap handler is a singleton. That can be fixed in in #177475. - Create WasmEmbedder.h where all embedder plugging will live. - Split up JSWebAssemblyTable into Wasm::Table which is refcounted. JSWebAssemblyTable now only contains the JS functions in the table, and Wasm::Table is what's used by the JIT code to lookup where to call and do the instance check (for context switch). Note that this creates an extra allocation for all the instances in Wasm::Table, and in exchange removes an indirection in JIT code because the instance used to be obtained off of the JS function. Also note that it's the embedder than keeps the instances alive, not Wasm::Table (which holds a dumb pointer to the instance), because doing otherwise would cause reference cycles. - Add WasmInstance. It doesn't do much for now, owns globals. - JSWebAssembly instance now doesn't just contain the imported functions as JSObjects, it also has the corresponding import's instance and wasm entrypoint. This triples the space allocated per instance's imported function, but there shouldn't be that many imports. This has two upsides: it creates smaller and faster code, and makes is easier to disassociate embedder-specific things from embedder-neutral things. The small / faster win is in two places: B3 IR generator only needs offsetOfImportFunction for the call opcode (when the called index is an import) to know whether the import is wasm->wasm or wasm->embedder (this isn't known at compile-time because it's dependent on the import object), this is now done by seeing if that import function has an associated target instance (only wasm->wasm does); the other place is wasmBinding which uses offsetOfImportFunction to figure out the wasm->wasm target instance, and then gets WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation to do a tail call. The disassociation comes because the target instance can be Wasm::Instance once we change what the Context is, and WasmEntrypointLoadLocation is already embedder-independent. As a next step I can move this tail allocation from JSWebAssemblyInstance to Wasm::Instance, and leave importFunction in as an opaque pointer which is embedder-specific, and in JS will remain WriteBarrier<JSObject>. - Rename VMEntryFrame to EntryFrame, and in many places pass a pointer to it around instead of VM. This is a first step in allowing entry frames which aren't stored on VM, but which are instead stored in an embedder-specific location. That change won't really affect JS except through code churn, but will allow WebAssembly to use some machinery in a generic manner without having a VM. * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * debugger/Debugger.cpp: (JSC::Debugger::stepOutOfFunction): (JSC::Debugger::returnEvent): (JSC::Debugger::unwindEvent): (JSC::Debugger::didExecuteProgram): * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::compileExceptionHandlers): * dfg/DFGOSREntry.cpp: (JSC::DFG::prepareOSREntry): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::compileOSRExit): (JSC::DFG::OSRExit::compileExit): * dfg/DFGThunks.cpp: (JSC::DFG::osrEntryThunkGenerator): * ftl/FTLCompile.cpp: (JSC::FTL::compile): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::lower): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): (JSC::CallFrame::callerFrame): (JSC::CallFrame::unsafeCallerFrame): * interpreter/CallFrame.h: (JSC::ExecState::callerFrame const): (JSC::ExecState::callerFrameOrEntryFrame const): (JSC::ExecState::unsafeCallerFrameOrEntryFrame const): * interpreter/FrameTracers.h: (JSC::NativeCallFrameTracer::NativeCallFrameTracer): (JSC::NativeCallFrameTracerWithRestore::NativeCallFrameTracerWithRestore): (JSC::NativeCallFrameTracerWithRestore::~NativeCallFrameTracerWithRestore): * interpreter/Interpreter.cpp: (JSC::UnwindFunctor::operator() const): (JSC::UnwindFunctor::copyCalleeSavesToEntryFrameCalleeSavesBuffer const): (JSC::Interpreter::unwind): * interpreter/StackVisitor.cpp: (JSC::StackVisitor::StackVisitor): (JSC::StackVisitor::gotoNextFrame): (JSC::StackVisitor::readNonInlinedFrame): (JSC::StackVisitor::Frame::dump const): * interpreter/StackVisitor.h: (JSC::StackVisitor::Frame::callerIsEntryFrame const): * interpreter/VMEntryRecord.h: (JSC::VMEntryRecord::prevTopEntryFrame): (JSC::VMEntryRecord::unsafePrevTopEntryFrame): (JSC::EntryFrame::vmEntryRecordOffset): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::restoreCalleeSavesFromEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::loadWasmContextInstance): (JSC::AssemblyHelpers::storeWasmContextInstance): (JSC::AssemblyHelpers::loadWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::storeWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBufferImpl): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::copyCalleeSavesToVMEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer): * jit/JIT.cpp: (JSC::JIT::emitEnterOptimizationCheck): (JSC::JIT::privateCompileExceptionHandlers): * jit/JITExceptions.cpp: (JSC::genericUnwind): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): (JSC::JIT::emitSlow_op_loop_hint): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): * jit/JITOperations.cpp: * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::nativeForGenerator): * jsc.cpp: (functionDumpCallFrame): * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LLIntThunks.cpp: (JSC::vmEntryRecord): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/Options.cpp: (JSC::recomputeDependentOptions): * runtime/Options.h: * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::FrameWalker): (JSC::FrameWalker::advanceToParentFrame): (JSC::SamplingProfiler::processUnverifiedStackTraces): * runtime/ThrowScope.cpp: (JSC::ThrowScope::~ThrowScope): * runtime/VM.cpp: (JSC::VM::VM): (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::topEntryFrameOffset): * runtime/VMTraps.cpp: (JSC::isSaneFrame): (JSC::VMTraps::tryInstallTrapBreakpoints): (JSC::VMTraps::invalidateCodeBlocksOnStack): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWasmContextInstance): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::parseAndCompile): * wasm/WasmB3IRGenerator.h: * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::BBQPlan): (JSC::Wasm::BBQPlan::compileFunctions): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBBQPlanInlines.h: (JSC::Wasm::BBQPlan::initializeCallees): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmBinding.h: * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::create): (JSC::Wasm::CodeBlock::CodeBlock): (JSC::Wasm::CodeBlock::compileAsync): (JSC::Wasm::CodeBlock::setCompilationFinished): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::offsetOfImportStubs): (JSC::Wasm::CodeBlock::allocationSize): (JSC::Wasm::CodeBlock::importWasmToEmbedderStub): (JSC::Wasm::CodeBlock::offsetOfImportWasmToEmbedderStub): (JSC::Wasm::CodeBlock::wasmToJSCallStubForImport): (JSC::Wasm::CodeBlock::compilationFinished): (JSC::Wasm::CodeBlock::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): * wasm/WasmContext.cpp: (JSC::Wasm::Context::useFastTLS): (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: Copied from Source/JavaScriptCore/wasm/WasmContext.h. * wasm/WasmFaultSignalHandler.cpp: * wasm/WasmFaultSignalHandler.h: * wasm/WasmFormat.h: * wasm/WasmInstance.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::~Instance): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: Added. (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::module): (JSC::Wasm::Instance::codeBlock): (JSC::Wasm::Instance::memory): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::loadF32Global const): (JSC::Wasm::Instance::loadF64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::offsetOfCachedStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::~Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::offsetOfSize): * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationCallback): (JSC::Wasm::Module::validateSync): (JSC::Wasm::Module::validateAsync): (JSC::Wasm::Module::getOrCreateCodeBlock): (JSC::Wasm::Module::compileSync): (JSC::Wasm::Module::compileAsync): * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseTableHelper): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::OMGPlan): (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::isValid const): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::runCompletionTasks): (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmPlan.h: (JSC::Wasm::Plan::dontFinalize): * wasm/WasmSignature.cpp: * wasm/WasmSignature.h: * wasm/WasmTable.cpp: Added. (JSC::Wasm::Table::create): (JSC::Wasm::Table::~Table): (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h. (JSC::Wasm::Table::maximum const): (JSC::Wasm::Table::size const): (JSC::Wasm::Table::offsetOfSize): (JSC::Wasm::Table::offsetOfFunctions): (JSC::Wasm::Table::offsetOfInstances): (JSC::Wasm::Table::isValidSize): * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): (JSC::Wasm::Thunks::setThrowWasmException): (JSC::Wasm::Thunks::throwWasmException): * wasm/WasmThunks.h: * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::stopAllPlansForContext): * wasm/WasmWorklist.h: * wasm/js/JSToWasm.cpp: Added. (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/JSWebAssembly.cpp: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.cpp. * wasm/js/JSWebAssembly.h: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.h. * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::create): (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::context const): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::webAssemblyToJSCallee): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::offsetOfTail): (JSC::JSWebAssemblyInstance::importFunctionInfo): (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): (JSC::JSWebAssemblyInstance::offsetOfImportFunction): (JSC::JSWebAssemblyInstance::importFunction): (JSC::JSWebAssemblyInstance::internalMemory): (JSC::JSWebAssemblyInstance::wasmCodeBlock const): (JSC::JSWebAssemblyInstance::offsetOfWasmTable): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::offsetOfGlobals): (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): (JSC::JSWebAssemblyInstance::cachedStackLimit const): (JSC::JSWebAssemblyInstance::setCachedStackLimit): (JSC::JSWebAssemblyInstance::wasmMemory): (JSC::JSWebAssemblyInstance::wasmModule): (JSC::JSWebAssemblyInstance::allocationSize): (JSC::JSWebAssemblyInstance::module const): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::create): (JSC::JSWebAssemblyMemory::adopt): (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::moduleInformation const): (JSC::JSWebAssemblyModule::exportSymbolTable const): (JSC::JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace const): (JSC::JSWebAssemblyModule::callee const): (JSC::JSWebAssemblyModule::codeBlock): (JSC::JSWebAssemblyModule::module): * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::create): (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::visitChildren): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::getFunction): (JSC::JSWebAssemblyTable::clearFunction): (JSC::JSWebAssemblyTable::setFunction): * wasm/js/JSWebAssemblyTable.h: (JSC::JSWebAssemblyTable::isValidSize): (JSC::JSWebAssemblyTable::maximum const): (JSC::JSWebAssemblyTable::size const): (JSC::JSWebAssemblyTable::table): * wasm/js/WasmToJS.cpp: Copied from Source/JavaScriptCore/wasm/WasmBinding.cpp. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): (JSC::WebAssemblyModuleConstructor::createModule): * wasm/js/WebAssemblyModuleConstructor.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::webAssemblyCompileFunc): (JSC::instantiate): (JSC::compileAndInstantiate): (JSC::webAssemblyValidateFunc): * wasm/js/WebAssemblyTableConstructor.cpp: (JSC::constructJSWebAssemblyTable): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Source/WebCore: * ForwardingHeaders/wasm/WasmModule.h: Added. This used to be included in JSWebAssemblyModule.h. * bindings/js/SerializedScriptValue.cpp: Update postMessage code according to C++ API changes. Canonical link: https://commits.webkit.org/194750@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223738 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-20 02:23:29 +00:00
size_t extraMemoryAllocated() const;
WebAssembly: no VM / JS version of our implementation https://bugs.webkit.org/show_bug.cgi?id=177472 Reviewed by Michael Saboff. This patch removes all appearances of "JS" and "VM" in the wasm directory. These now only appear in the wasm/js directory, which is only used in a JS embedding of wasm. It should therefore now be possible to create non-JS embeddings of wasm through JSC, though it'll still require: - Mild codegen for wasm<->embedder calls; - A strategy for trap handling (no need for full unwind! Could kill). - Creation of the Wasm::* objects. - Calling convention handling to call the embedder. - Handling of multiple embedders (see #177475, this is optional). Most of the patch consists in renaming JSWebAssemblyInstance to Instance, and removing temporary copies which I'd added to make this specific patch very simple. * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): this one place which needs to know about who "owns" the Wasm::Instance. In a JS embedding it's the JSWebAssemblyInstance. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::getGlobal): (JSC::Wasm::B3IRGenerator::setGlobal): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmContext.cpp: (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: add an "owner", the Wasm::Context, move the "tail" import information from JSWebAssemblyInstance over to here. (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::owner const): (JSC::Wasm::Instance::offsetOfOwner): (JSC::Wasm::Instance::context const): (JSC::Wasm::Instance::setMemory): (JSC::Wasm::Instance::setTable): (JSC::Wasm::Instance::offsetOfMemory): (JSC::Wasm::Instance::offsetOfGlobals): (JSC::Wasm::Instance::offsetOfTable): (JSC::Wasm::Instance::offsetOfTail): (JSC::Wasm::Instance::numImportFunctions const): (JSC::Wasm::Instance::importFunctionInfo): (JSC::Wasm::Instance::offsetOfTargetInstance): (JSC::Wasm::Instance::offsetOfWasmEntrypoint): (JSC::Wasm::Instance::offsetOfWasmToEmbedderStubExecutableAddress): (JSC::Wasm::Instance::offsetOfImportFunction): (JSC::Wasm::Instance::importFunction): (JSC::Wasm::Instance::allocationSize): (JSC::Wasm::Instance::create): Deleted. * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmTable.cpp: (JSC::Wasm::Table::Table): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyInstance.cpp: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): The embedder decides what the import function is. Here we must properly placement-new it to what we've elected (and initialize it later). (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::moduleNamespaceObject): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::setTable): (JSC::JSWebAssemblyInstance::offsetOfInstance): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::context const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTail): Deleted. (): Deleted. (JSC::JSWebAssemblyInstance::importFunctionInfo): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmToEmbedderStubExecutableAddress): Deleted. (JSC::JSWebAssemblyInstance::offsetOfImportFunction): Deleted. (JSC::JSWebAssemblyInstance::importFunction): Deleted. (JSC::JSWebAssemblyInstance::internalMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmCodeBlock const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmTable): Deleted. (JSC::JSWebAssemblyInstance::offsetOfGlobals): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTopEntryFramePointer): Deleted. (JSC::JSWebAssemblyInstance::cachedStackLimit const): Deleted. (JSC::JSWebAssemblyInstance::setCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::wasmMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmModule): Deleted. (JSC::JSWebAssemblyInstance::allocationSize): Deleted. * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::setFunction): * wasm/js/WasmToJS.cpp: One extra indirection to find the JSWebAssemblyInstance. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::instantiate): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Canonical link: https://commits.webkit.org/195012@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224020 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-26 15:33:55 +00:00
Wasm::Context* context() const { return m_context; }
WebAssembly: no VM / JS version of everything but Instance https://bugs.webkit.org/show_bug.cgi?id=177473 Reviewed by Filip Pizlo, Saam Barati. JSTests: - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. * wasm/js-api/memory-grow.js: (assertEq): * wasm/js-api/table.js: (assert.throws): Source/JavaScriptCore: This change entails cleaning up and splitting a bunch of code which we had intertwined between C++ classes which represent JS objects, and pure C++ implementation objects. This specific change goes most of the way towards allowing JSC's WebAssembly to work without VM / JS, up to but excluding JSWebAssemblyInstance (there's Wasm::Instance, but it's not *the* thing yet). Because of this we still have a few FIXME identifying places that need to change. A follow-up change will go the rest of the way. I went about this change in the simplest way possible: grep the JavaScriptCore/wasm directory for "JS[^C_]" as well as "VM" and exclude the /js/ sub-directory (which contains the JS implementation of WebAssembly). None of this change removes the need for a JIT entitlement to be able to use WebAssembly. We don't have an interpreter, the process therefore still needs to be allowed to JIT to use these pure-C++ APIs. Interesting things to note: - Remove VM from Plan and associated places. It can just live as a capture in the callback lambda if it's needed. - Wasm::Memory shouldn't require a VM. It was only used to ask the GC to collect. We now instead pass two lambdas at construction time for this purpose: one to notify of memory pressure, and the other to ask for syncrhonous memory reclamation. This allows whoever creates the memory to dictate how to react to both these cases, and for a JS embedding that's to call the GC (async or sync, respectively). - Move grow logic from JSWebAssemblyMemory to Wasm::Memory::grow. Use Expected there, with an enum class for failure types. - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. - When generating the grow_memory opcode, no need to get the VM. Instead, reach directly for Wasm::Memory and grow it. - JSWebAssemblyMemory::grow can now always throw on failure, because it's only ever called from JS (not from grow_memory as before). - Wasm::Memory now takes a callback for successful growth. This allows JS wrappers to register themselves when growth succeeds without Wasm::Memory knowning anything about JS. It'll also allow creating a list of callbacks for when we add thread support (we'll want to notify many wrappers, all under a lock). - Wasm::Memory is now back to being the source of truth about address / size, used directly by generated code instead of JSWebAssemblyMemory. - Move wasmToJS from the general WasmBinding header to its own header under wasm/js. It's only used by wasm/js/JSWebAssemblyCodeBlock.cpp, and uses VM, and therefore isn't general WebAssembly. - Make Wasm::Context an actual type (just a struct holding a JSWebAssemlyInstance for now) instead of an alias for that. Notably this doesn't add anything to the Context and doesn't change what actually gets passed around in JIT code (fast TLS or registers) because these changes potentially impact performance. The entire purpose of this change is to allow passing Wasm::Context around without having to know about VM. Since VM contains a Wasm::Context the JS embedding is effectively the same, but with this setup a non-JS embedding is much better off. - Move JSWebAssembly into the JS folder. - OMGPlan: use Wasm::CodeBlock directly instead of JSWebAssemblyCodeBlock. - wasm->JS stubs are now on the instance's tail as raw pointers, instead of being on JSWebAssemblyCodeBlock, and are now called wasm->Embedder stubs. The owned reference is still on JSWebAssemblyCodeBlock, and is still called wasm->JS stub. This move means that the embedder must, after creating a Wasm::CodeBlock, somehow create the stubs to call back into the embedder. This removes an indirection in the generated code because the B3 IR generator now reaches into the instance instead of JSWebAssemblyCodeBlock. - Move more CodeBlock things. Compilation completion is now marked by its own atomic<bool> flag instead of a nullptr plan: that required using a lock, and was causing a deadlock in stack-trace.js because before my changes JSWebAssemblyCodeBlock did its own completion checking separately from Wasm::CodeBlock, without getting the lock. Now that everything points to Wasm::CodeBlock and there's no cached completion marker, the lock was being acquired in a sanity-check assertion. - Embedder -> Wasm wrappers are now generated through a function that's passed in at compilation time, instead of being hard-coded as a JS -> Wasm wrapper. - WasmMemory doens't need to know about fault handling thunks. Only the IR generator should know, and should make sure that the exception throwing thunk is generated if any memory is present (note: with signal handling not all of them generate an exception check). - Make exception throwing pluggable: instead of having a hard-coded JS-specific lambda we now have a regular C++ function being called from JIT code when a WebAssembly exception is thrown. This allows any embedder to get called as they wish. For now a process can only have a single of these functions (i.e. only one embedder per process) because the trap handler is a singleton. That can be fixed in in #177475. - Create WasmEmbedder.h where all embedder plugging will live. - Split up JSWebAssemblyTable into Wasm::Table which is refcounted. JSWebAssemblyTable now only contains the JS functions in the table, and Wasm::Table is what's used by the JIT code to lookup where to call and do the instance check (for context switch). Note that this creates an extra allocation for all the instances in Wasm::Table, and in exchange removes an indirection in JIT code because the instance used to be obtained off of the JS function. Also note that it's the embedder than keeps the instances alive, not Wasm::Table (which holds a dumb pointer to the instance), because doing otherwise would cause reference cycles. - Add WasmInstance. It doesn't do much for now, owns globals. - JSWebAssembly instance now doesn't just contain the imported functions as JSObjects, it also has the corresponding import's instance and wasm entrypoint. This triples the space allocated per instance's imported function, but there shouldn't be that many imports. This has two upsides: it creates smaller and faster code, and makes is easier to disassociate embedder-specific things from embedder-neutral things. The small / faster win is in two places: B3 IR generator only needs offsetOfImportFunction for the call opcode (when the called index is an import) to know whether the import is wasm->wasm or wasm->embedder (this isn't known at compile-time because it's dependent on the import object), this is now done by seeing if that import function has an associated target instance (only wasm->wasm does); the other place is wasmBinding which uses offsetOfImportFunction to figure out the wasm->wasm target instance, and then gets WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation to do a tail call. The disassociation comes because the target instance can be Wasm::Instance once we change what the Context is, and WasmEntrypointLoadLocation is already embedder-independent. As a next step I can move this tail allocation from JSWebAssemblyInstance to Wasm::Instance, and leave importFunction in as an opaque pointer which is embedder-specific, and in JS will remain WriteBarrier<JSObject>. - Rename VMEntryFrame to EntryFrame, and in many places pass a pointer to it around instead of VM. This is a first step in allowing entry frames which aren't stored on VM, but which are instead stored in an embedder-specific location. That change won't really affect JS except through code churn, but will allow WebAssembly to use some machinery in a generic manner without having a VM. * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * debugger/Debugger.cpp: (JSC::Debugger::stepOutOfFunction): (JSC::Debugger::returnEvent): (JSC::Debugger::unwindEvent): (JSC::Debugger::didExecuteProgram): * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::compileExceptionHandlers): * dfg/DFGOSREntry.cpp: (JSC::DFG::prepareOSREntry): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::compileOSRExit): (JSC::DFG::OSRExit::compileExit): * dfg/DFGThunks.cpp: (JSC::DFG::osrEntryThunkGenerator): * ftl/FTLCompile.cpp: (JSC::FTL::compile): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::lower): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): (JSC::CallFrame::callerFrame): (JSC::CallFrame::unsafeCallerFrame): * interpreter/CallFrame.h: (JSC::ExecState::callerFrame const): (JSC::ExecState::callerFrameOrEntryFrame const): (JSC::ExecState::unsafeCallerFrameOrEntryFrame const): * interpreter/FrameTracers.h: (JSC::NativeCallFrameTracer::NativeCallFrameTracer): (JSC::NativeCallFrameTracerWithRestore::NativeCallFrameTracerWithRestore): (JSC::NativeCallFrameTracerWithRestore::~NativeCallFrameTracerWithRestore): * interpreter/Interpreter.cpp: (JSC::UnwindFunctor::operator() const): (JSC::UnwindFunctor::copyCalleeSavesToEntryFrameCalleeSavesBuffer const): (JSC::Interpreter::unwind): * interpreter/StackVisitor.cpp: (JSC::StackVisitor::StackVisitor): (JSC::StackVisitor::gotoNextFrame): (JSC::StackVisitor::readNonInlinedFrame): (JSC::StackVisitor::Frame::dump const): * interpreter/StackVisitor.h: (JSC::StackVisitor::Frame::callerIsEntryFrame const): * interpreter/VMEntryRecord.h: (JSC::VMEntryRecord::prevTopEntryFrame): (JSC::VMEntryRecord::unsafePrevTopEntryFrame): (JSC::EntryFrame::vmEntryRecordOffset): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::restoreCalleeSavesFromEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::loadWasmContextInstance): (JSC::AssemblyHelpers::storeWasmContextInstance): (JSC::AssemblyHelpers::loadWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::storeWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBufferImpl): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::copyCalleeSavesToVMEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer): * jit/JIT.cpp: (JSC::JIT::emitEnterOptimizationCheck): (JSC::JIT::privateCompileExceptionHandlers): * jit/JITExceptions.cpp: (JSC::genericUnwind): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): (JSC::JIT::emitSlow_op_loop_hint): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): * jit/JITOperations.cpp: * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::nativeForGenerator): * jsc.cpp: (functionDumpCallFrame): * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LLIntThunks.cpp: (JSC::vmEntryRecord): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/Options.cpp: (JSC::recomputeDependentOptions): * runtime/Options.h: * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::FrameWalker): (JSC::FrameWalker::advanceToParentFrame): (JSC::SamplingProfiler::processUnverifiedStackTraces): * runtime/ThrowScope.cpp: (JSC::ThrowScope::~ThrowScope): * runtime/VM.cpp: (JSC::VM::VM): (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::topEntryFrameOffset): * runtime/VMTraps.cpp: (JSC::isSaneFrame): (JSC::VMTraps::tryInstallTrapBreakpoints): (JSC::VMTraps::invalidateCodeBlocksOnStack): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWasmContextInstance): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::parseAndCompile): * wasm/WasmB3IRGenerator.h: * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::BBQPlan): (JSC::Wasm::BBQPlan::compileFunctions): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBBQPlanInlines.h: (JSC::Wasm::BBQPlan::initializeCallees): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmBinding.h: * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::create): (JSC::Wasm::CodeBlock::CodeBlock): (JSC::Wasm::CodeBlock::compileAsync): (JSC::Wasm::CodeBlock::setCompilationFinished): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::offsetOfImportStubs): (JSC::Wasm::CodeBlock::allocationSize): (JSC::Wasm::CodeBlock::importWasmToEmbedderStub): (JSC::Wasm::CodeBlock::offsetOfImportWasmToEmbedderStub): (JSC::Wasm::CodeBlock::wasmToJSCallStubForImport): (JSC::Wasm::CodeBlock::compilationFinished): (JSC::Wasm::CodeBlock::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): * wasm/WasmContext.cpp: (JSC::Wasm::Context::useFastTLS): (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: Copied from Source/JavaScriptCore/wasm/WasmContext.h. * wasm/WasmFaultSignalHandler.cpp: * wasm/WasmFaultSignalHandler.h: * wasm/WasmFormat.h: * wasm/WasmInstance.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::~Instance): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: Added. (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::module): (JSC::Wasm::Instance::codeBlock): (JSC::Wasm::Instance::memory): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::loadF32Global const): (JSC::Wasm::Instance::loadF64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::offsetOfCachedStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::~Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::offsetOfSize): * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationCallback): (JSC::Wasm::Module::validateSync): (JSC::Wasm::Module::validateAsync): (JSC::Wasm::Module::getOrCreateCodeBlock): (JSC::Wasm::Module::compileSync): (JSC::Wasm::Module::compileAsync): * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseTableHelper): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::OMGPlan): (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::isValid const): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::runCompletionTasks): (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmPlan.h: (JSC::Wasm::Plan::dontFinalize): * wasm/WasmSignature.cpp: * wasm/WasmSignature.h: * wasm/WasmTable.cpp: Added. (JSC::Wasm::Table::create): (JSC::Wasm::Table::~Table): (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h. (JSC::Wasm::Table::maximum const): (JSC::Wasm::Table::size const): (JSC::Wasm::Table::offsetOfSize): (JSC::Wasm::Table::offsetOfFunctions): (JSC::Wasm::Table::offsetOfInstances): (JSC::Wasm::Table::isValidSize): * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): (JSC::Wasm::Thunks::setThrowWasmException): (JSC::Wasm::Thunks::throwWasmException): * wasm/WasmThunks.h: * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::stopAllPlansForContext): * wasm/WasmWorklist.h: * wasm/js/JSToWasm.cpp: Added. (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/JSWebAssembly.cpp: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.cpp. * wasm/js/JSWebAssembly.h: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.h. * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::create): (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::context const): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::webAssemblyToJSCallee): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::offsetOfTail): (JSC::JSWebAssemblyInstance::importFunctionInfo): (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): (JSC::JSWebAssemblyInstance::offsetOfImportFunction): (JSC::JSWebAssemblyInstance::importFunction): (JSC::JSWebAssemblyInstance::internalMemory): (JSC::JSWebAssemblyInstance::wasmCodeBlock const): (JSC::JSWebAssemblyInstance::offsetOfWasmTable): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::offsetOfGlobals): (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): (JSC::JSWebAssemblyInstance::cachedStackLimit const): (JSC::JSWebAssemblyInstance::setCachedStackLimit): (JSC::JSWebAssemblyInstance::wasmMemory): (JSC::JSWebAssemblyInstance::wasmModule): (JSC::JSWebAssemblyInstance::allocationSize): (JSC::JSWebAssemblyInstance::module const): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::create): (JSC::JSWebAssemblyMemory::adopt): (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::moduleInformation const): (JSC::JSWebAssemblyModule::exportSymbolTable const): (JSC::JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace const): (JSC::JSWebAssemblyModule::callee const): (JSC::JSWebAssemblyModule::codeBlock): (JSC::JSWebAssemblyModule::module): * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::create): (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::visitChildren): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::getFunction): (JSC::JSWebAssemblyTable::clearFunction): (JSC::JSWebAssemblyTable::setFunction): * wasm/js/JSWebAssemblyTable.h: (JSC::JSWebAssemblyTable::isValidSize): (JSC::JSWebAssemblyTable::maximum const): (JSC::JSWebAssemblyTable::size const): (JSC::JSWebAssemblyTable::table): * wasm/js/WasmToJS.cpp: Copied from Source/JavaScriptCore/wasm/WasmBinding.cpp. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): (JSC::WebAssemblyModuleConstructor::createModule): * wasm/js/WebAssemblyModuleConstructor.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::webAssemblyCompileFunc): (JSC::instantiate): (JSC::compileAndInstantiate): (JSC::webAssemblyValidateFunc): * wasm/js/WebAssemblyTableConstructor.cpp: (JSC::constructJSWebAssemblyTable): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Source/WebCore: * ForwardingHeaders/wasm/WasmModule.h: Added. This used to be included in JSWebAssemblyModule.h. * bindings/js/SerializedScriptValue.cpp: Update postMessage code according to C++ API changes. Canonical link: https://commits.webkit.org/194750@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223738 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-20 02:23:29 +00:00
Module& module() { return m_module.get(); }
CodeBlock* codeBlock() { return m_codeBlock.get(); }
Memory* memory() { return m_memory.get(); }
[WASM-References] Add support for multiple tables https://bugs.webkit.org/show_bug.cgi?id=198760 Reviewed by Saam Barati. JSTests: * wasm/Builder.js: * wasm/js-api/call-indirect.js: (const.oneTable): (const.multiTable): (multiTable): (multiTable.Polyphic2Import): (multiTable.VirtualImport): (const.wasmModuleWhichImportJS): Deleted. (const.makeTable): Deleted. (): Deleted. (Polyphic2Import): Deleted. (VirtualImport): Deleted. * wasm/js-api/table.js: (new.WebAssembly.Module): (assert.throws): (assertBadTableImport): (assert.truthy): (assert.throws.new.WebAssembly.Module.builder.WebAssembly): Deleted. * wasm/references/anyref_table.js: * wasm/references/anyref_table_import.js: (makeImport): (string_appeared_here.fullGC.assert.eq.1.exports.get_tbl.makeImport): (string_appeared_here.fullGC.assert.eq.1.exports.get_tbl): * wasm/references/multitable.js: Added. (assert.throws.1.exports.set_tbl0): (assert.throws): (assert.eq): * wasm/references/validation.js: (assert.throws.new.WebAssembly.Module.bin): (assert.throws): * wasm/spec-tests/imports.wast.js: * wasm/wasm.json: * wasm/Builder.js: * wasm/js-api/call-indirect.js: (const.oneTable): (const.multiTable): (multiTable): (multiTable.Polyphic2Import): (multiTable.VirtualImport): (const.wasmModuleWhichImportJS): Deleted. (const.makeTable): Deleted. (): Deleted. (Polyphic2Import): Deleted. (VirtualImport): Deleted. * wasm/js-api/table.js: (new.WebAssembly.Module): (assert.throws): (assertBadTableImport): (assert.truthy): (assert.throws.new.WebAssembly.Module.builder.WebAssembly): Deleted. * wasm/references/anyref_table.js: * wasm/references/anyref_table_import.js: (makeImport): (string_appeared_here.fullGC.assert.eq.1.exports.get_tbl.makeImport): (string_appeared_here.fullGC.assert.eq.1.exports.get_tbl): * wasm/references/func_ref.js: (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly.fun): Deleted. (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly.assert.throws): Deleted. (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly): Deleted. * wasm/references/multitable.js: Added. (assert.throws.1.exports.set_tbl0): (assert.throws): (assert.eq): (string_appeared_here.tableInsanity): (I32Const.0.GetLocal.0.TableSet.1.End.End.WebAssembly.): (I32Const.0.GetLocal.0.TableSet.1.End.End.WebAssembly): * wasm/references/validation.js: (assert.throws.new.WebAssembly.Module.bin): (assert.throws): * wasm/spec-tests/imports.wast.js: * wasm/wasm.json: Source/JavaScriptCore: Support multiple wasm tables. We turn tableInformation into a tables array, and update all of the existing users to give a table index. The array of Tables in Wasm::Instance is hung off the tail to make it easier to use from jit code. * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::AirIRGenerator): (JSC::Wasm::AirIRGenerator::addTableGet): (JSC::Wasm::AirIRGenerator::addTableSet): (JSC::Wasm::AirIRGenerator::addCallIndirect): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::addTableGet): (JSC::Wasm::B3IRGenerator::addTableSet): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmExceptionType.h: * wasm/WasmFormat.h: (JSC::Wasm::Element::Element): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parseExpression): (JSC::Wasm::FunctionParser<Context>::parseUnreachableExpression): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::extraMemoryAllocated const): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::setTable): * wasm/WasmInstance.h: (JSC::Wasm::Instance::updateCachedMemory): (JSC::Wasm::Instance::offsetOfGlobals): (JSC::Wasm::Instance::offsetOfTablePtr): (JSC::Wasm::Instance::allocationSize): (JSC::Wasm::Instance::table): Deleted. (JSC::Wasm::Instance::setTable): Deleted. (JSC::Wasm::Instance::offsetOfTable): Deleted. * wasm/WasmModuleInformation.h: (JSC::Wasm::ModuleInformation::tableCount const): * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseImport): (JSC::Wasm::SectionParser::parseTableHelper): (JSC::Wasm::SectionParser::parseTable): (JSC::Wasm::SectionParser::parseElement): * wasm/WasmTable.h: (JSC::Wasm::Table::owner const): * wasm/WasmValidate.cpp: (JSC::Wasm::Validate::addTableGet): (JSC::Wasm::Validate::addTableSet): (JSC::Wasm::Validate::addCallIndirect): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/JSWebAssemblyInstance.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/wasm.json: Canonical link: https://commits.webkit.org/212963@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@246571 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-06-18 22:01:02 +00:00
Table* table(unsigned);
void setTable(unsigned, Ref<Table>&&);
[WASM-References] Add table.init https://bugs.webkit.org/show_bug.cgi?id=219297 Patch by Dmitry Bezhetskov <dbezhetskov@igalia.com> on 2020-12-11 Reviewed by Yusuke Suzuki. JSTests: Added reference types spec tests for element section, table.init and elem.drop: https://github.com/WebAssembly/reference-types/blob/master/test/core/elem.wast, https://github.com/WebAssembly/reference-types/blob/master/test/core/table_init.wast. Added tests for checking table instructions immediates when they are unreachable. * wasm.yaml: * wasm/references-spec-tests/elem.wast.js: Added. * wasm/references-spec-tests/ref_is_null.js: Removed. * wasm/references-spec-tests/ref_is_null.wast.js: Added. * wasm/references-spec-tests/ref_null.js: Removed. * wasm/references-spec-tests/ref_null.wast.js: Added. * wasm/references-spec-tests/table_copy.wast.js: Renamed from JSTests/wasm/references-spec-tests/table_copy.js. * wasm/references-spec-tests/table_init.wast.js: Added. * wasm/spec-harness/wasm-constants.js: (hostref): * wasm/wasm.json: Source/JavaScriptCore: Add support for table.init, elem.drop and new element section from reference-type proposal: https://webassembly.github.io/reference-types/core/syntax/instructions.html#table-instructions, https://webassembly.github.io/reference-types/core/syntax/modules.html#element-segments. All in one patch because all this stuff are very coupled and ref-types spec tests require each other to run the its tests, so not to write hand-crafted tests this is in one PR. * bytecode/BytecodeList.rb: * llint/WebAssembly.asm: * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::addTableInit): (JSC::Wasm::AirIRGenerator::addElemDrop): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::addTableInit): (JSC::Wasm::B3IRGenerator::addElemDrop): * wasm/WasmFormat.h: (JSC::Wasm::Element::Element): (JSC::Wasm::Element::length const): (JSC::Wasm::Element::isPassive const): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parseExpression): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::elemDrop): (JSC::Wasm::Instance::elem const): (JSC::Wasm::Instance::initElementSegment): (JSC::Wasm::Instance::tableInit): * wasm/WasmInstance.h: (JSC::Wasm::Instance::isImportFunction const): * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::addTableInit): (JSC::Wasm::LLIntGenerator::addElemDrop): * wasm/WasmModuleInformation.h: (JSC::Wasm::ModuleInformation::elementCount const): * wasm/WasmOperations.cpp: (JSC::Wasm::JSC_DEFINE_JIT_OPERATION): * wasm/WasmOperations.h: * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseElement): (JSC::Wasm::SectionParser::parseElementSegmentVectorOfExpressions): (JSC::Wasm::SectionParser::parseElementSegmentVectorOfIndexes): (JSC::Wasm::SectionParser::parseFuncIndexFromRefExpForElementSection): Deleted. (JSC::Wasm::SectionParser::parseFuncIndexForElementSection): Deleted. * wasm/WasmSectionParser.h: * wasm/WasmSlowPaths.cpp: (JSC::LLInt::WASM_SLOW_PATH_DECL): * wasm/WasmSlowPaths.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::evaluate): * wasm/wasm.json: Tools: Support ref-types spec tests. * Scripts/run-jsc-stress-tests: Canonical link: https://commits.webkit.org/232352@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@270689 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-12-11 19:04:22 +00:00
const Element* elementAt(unsigned) const;
void initElementSegment(uint32_t tableIndex, const Element& segment, uint32_t dstOffset, uint32_t srcOffset, uint32_t length);
bool isImportFunction(uint32_t functionIndex) const
{
return functionIndex < m_codeBlock->functionImportCount();
}
void tableInit(uint32_t dstOffset, uint32_t srcOffset, uint32_t length, uint32_t elementIndex, uint32_t tableIndex);
WebAssembly: cache memory address / size on instance https://bugs.webkit.org/show_bug.cgi?id=177305 Reviewed by JF Bastien. JSTests: * wasm/function-tests/memory-reuse.js: Added. (createWasmInstance): (doCheckTrap): (doMemoryGrow): (doCheck): (checkWasmInstancesWithSharedMemory): Source/JavaScriptCore: Cache memory address/size in wasm:Instance to avoid load wasm:Memory object during access to memory and memory size property in JiT * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmInstance.h: (JSC::Wasm::Instance::cachedMemory const): (JSC::Wasm::Instance::cachedMemorySize const): (JSC::Wasm::Instance::createWeakPtr): (JSC::Wasm::Instance::setMemory): (JSC::Wasm::Instance::updateCachedMemory): (JSC::Wasm::Instance::offsetOfCachedMemory): (JSC::Wasm::Instance::offsetOfCachedMemorySize): (JSC::Wasm::Instance::offsetOfCachedIndexingMask): (JSC::Wasm::Instance::allocationSize): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::grow): (JSC::Wasm::Memory::registerInstance): * wasm/WasmMemory.h: (JSC::Wasm::Memory::indexingMask): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::evaluate): Canonical link: https://commits.webkit.org/198823@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@228966 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-02-23 23:16:59 +00:00
[WASM-References] Add support for table.copy https://bugs.webkit.org/show_bug.cgi?id=219427 Patch by Dmitry Bezhetskov <dbezhetskov@igalia.com> on 2020-12-07 Reviewed by Yusuke Suzuki. Add support for table.copy from reference types proposal: https://webassembly.github.io/reference-types/core/syntax/instructions.html#table-instructions. JSTests: Add the tests from above spec. * wasm/references-spec-tests/table_copy.js: Added. (hostref): (is_hostref): (is_funcref): (eq_ref): (let.handler.get target): (register): (module): (instance): (call): (get instance): (exports): (run): (assert_malformed): (assert_invalid): (assert_unlinkable): (assert_uninstantiable): (assert_trap): (try.f): (catch): (assert_exhaustion): (assert_return): (assert_return_canonical_nan): (assert_return_arithmetic_nan): (assert_return_ref): (assert_return_func): * wasm/references/element_parsing.js: * wasm/wasm.json: Source/JavaScriptCore: The table.copy instruction accepts three stack arguments (destination offset, source offset, length) and two immediates for table indexes and copies items from one wasm table to another. * bytecode/BytecodeList.rb: * llint/WebAssembly.asm: * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::addTableFill): (JSC::Wasm::AirIRGenerator::addTableCopy): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::addTableFill): (JSC::Wasm::B3IRGenerator::addTableCopy): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parseExpression): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::tableCopy): * wasm/WasmInstance.h: * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::addTableCopy): * wasm/WasmOperations.cpp: (JSC::Wasm::isSumOverflow): (JSC::Wasm::JSC_DEFINE_JIT_OPERATION): * wasm/WasmOperations.h: * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseElement): * wasm/WasmSlowPaths.cpp: (JSC::LLInt::WASM_SLOW_PATH_DECL): * wasm/WasmSlowPaths.h: * wasm/WasmTable.cpp: (JSC::Wasm::Table::copy): (JSC::Wasm::FuncRefTable::copyFunction): * wasm/WasmTable.h: * wasm/wasm.json: Canonical link: https://commits.webkit.org/232200@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@270524 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-12-07 22:26:48 +00:00
void tableCopy(uint32_t dstOffset, uint32_t srcOffset, uint32_t length, uint32_t dstTableIndex, uint32_t srcTableIndex);
[WASM-References] Add table.init https://bugs.webkit.org/show_bug.cgi?id=219297 Patch by Dmitry Bezhetskov <dbezhetskov@igalia.com> on 2020-12-11 Reviewed by Yusuke Suzuki. JSTests: Added reference types spec tests for element section, table.init and elem.drop: https://github.com/WebAssembly/reference-types/blob/master/test/core/elem.wast, https://github.com/WebAssembly/reference-types/blob/master/test/core/table_init.wast. Added tests for checking table instructions immediates when they are unreachable. * wasm.yaml: * wasm/references-spec-tests/elem.wast.js: Added. * wasm/references-spec-tests/ref_is_null.js: Removed. * wasm/references-spec-tests/ref_is_null.wast.js: Added. * wasm/references-spec-tests/ref_null.js: Removed. * wasm/references-spec-tests/ref_null.wast.js: Added. * wasm/references-spec-tests/table_copy.wast.js: Renamed from JSTests/wasm/references-spec-tests/table_copy.js. * wasm/references-spec-tests/table_init.wast.js: Added. * wasm/spec-harness/wasm-constants.js: (hostref): * wasm/wasm.json: Source/JavaScriptCore: Add support for table.init, elem.drop and new element section from reference-type proposal: https://webassembly.github.io/reference-types/core/syntax/instructions.html#table-instructions, https://webassembly.github.io/reference-types/core/syntax/modules.html#element-segments. All in one patch because all this stuff are very coupled and ref-types spec tests require each other to run the its tests, so not to write hand-crafted tests this is in one PR. * bytecode/BytecodeList.rb: * llint/WebAssembly.asm: * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::addTableInit): (JSC::Wasm::AirIRGenerator::addElemDrop): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::addTableInit): (JSC::Wasm::B3IRGenerator::addElemDrop): * wasm/WasmFormat.h: (JSC::Wasm::Element::Element): (JSC::Wasm::Element::length const): (JSC::Wasm::Element::isPassive const): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parseExpression): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::elemDrop): (JSC::Wasm::Instance::elem const): (JSC::Wasm::Instance::initElementSegment): (JSC::Wasm::Instance::tableInit): * wasm/WasmInstance.h: (JSC::Wasm::Instance::isImportFunction const): * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::addTableInit): (JSC::Wasm::LLIntGenerator::addElemDrop): * wasm/WasmModuleInformation.h: (JSC::Wasm::ModuleInformation::elementCount const): * wasm/WasmOperations.cpp: (JSC::Wasm::JSC_DEFINE_JIT_OPERATION): * wasm/WasmOperations.h: * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseElement): (JSC::Wasm::SectionParser::parseElementSegmentVectorOfExpressions): (JSC::Wasm::SectionParser::parseElementSegmentVectorOfIndexes): (JSC::Wasm::SectionParser::parseFuncIndexFromRefExpForElementSection): Deleted. (JSC::Wasm::SectionParser::parseFuncIndexForElementSection): Deleted. * wasm/WasmSectionParser.h: * wasm/WasmSlowPaths.cpp: (JSC::LLInt::WASM_SLOW_PATH_DECL): * wasm/WasmSlowPaths.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::evaluate): * wasm/wasm.json: Tools: Support ref-types spec tests. * Scripts/run-jsc-stress-tests: Canonical link: https://commits.webkit.org/232352@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@270689 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-12-11 19:04:22 +00:00
void elemDrop(uint32_t elementIndex);
[WASM-References] Add support for memory.copy, memory.init and data.drop https://bugs.webkit.org/show_bug.cgi?id=219943 Patch by Dmitry Bezhetskov <dbezhetskov@igalia.com> on 2020-12-17 Reviewed by Yusuke Suzuki. JSTests: Added ref-types spec tests for memory.copy, memory.init and data.drop: https://github.com/WebAssembly/reference-types/tree/master/test/core. Renamed table_instructions_parse_unreachable test into just parse_unreachable to prevent confusion. * wasm.yaml: * wasm/references-spec-tests/memory_copy.wast.js: Added. * wasm/references-spec-tests/memory_init.wast.js: Added. * wasm/references/memory_copy.js: Added. (async test): * wasm/references/memory_copy_shared.js: Added. (async test): * wasm/references/parse_unreachable.js: Renamed from JSTests/wasm/references/table_instructions_parse_unreachable.js. (invalidMemoryCopyUnreachable): (invalidMemoryInitUnreachable): (invalidDataDropUnreachable): * wasm/wasm.json: Source/JavaScriptCore: Add support for memory.copy [dstAddress, srcAddress, length] -> [] that copies one memory segment to another memory segment. The memory.copy calls C memcpy function to utilize all possible optimization for copy. This instruction speedup copying data segments in wasm because without it we need to use a lot load/store instructions with loops in wasm. Add support for memory.init data_segment_index [dstAddress, srcAddress, length] -> [] that copies data from a passive data segment into a memory segment. This instruction is the same as memory.copy but for read-only data segments. It also utilize C memcpy under the hood. Add support for data.drop data_segment_index [] -> [] that resize given data segment to zero. Data.drop makes redundant data segment and prevents usage of it in the next. BTW, it is just a hint for the host runtime so we don't have to change data segment. Add support for Data count section. This section just stores the number of data segments. We need this to validate memory.init instruction's data index because Code section comes before Data section. These instructions are needed to support reference types proposal and bulk proposal. * bytecode/BytecodeList.rb: * llint/WebAssembly.asm: * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::addMemoryCopy): (JSC::Wasm::AirIRGenerator::addMemoryInit): (JSC::Wasm::AirIRGenerator::addDataDrop): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::addMemoryInit): (JSC::Wasm::B3IRGenerator::addMemoryCopy): (JSC::Wasm::B3IRGenerator::addDataDrop): * wasm/WasmFormat.cpp: (JSC::Wasm::Segment::create): * wasm/WasmFormat.h: (JSC::Wasm::Segment::isActive const): (JSC::Wasm::Segment::isPassive const): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parseDataSegmentIndex): (JSC::Wasm::FunctionParser<Context>::parseMemoryCopyImmediates): (JSC::Wasm::FunctionParser<Context>::parseMemoryInitImmediates): (JSC::Wasm::FunctionParser<Context>::parseExpression): (JSC::Wasm::FunctionParser<Context>::parseUnreachableExpression): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::memoryInit): (JSC::Wasm::Instance::dataDrop): * wasm/WasmInstance.h: * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::addMemoryInit): (JSC::Wasm::LLIntGenerator::addDataDrop): (JSC::Wasm::LLIntGenerator::addMemoryCopy): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::copy): (JSC::Wasm::Memory::init): * wasm/WasmMemory.h: * wasm/WasmModuleInformation.h: (JSC::Wasm::ModuleInformation::dataSegmentsCount const): * wasm/WasmOperations.cpp: (JSC::Wasm::JSC_DEFINE_JIT_OPERATION): * wasm/WasmOperations.h: * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseElement): (JSC::Wasm::SectionParser::parseI32InitExpr): (JSC::Wasm::SectionParser::parseI32InitExprForElementSection): (JSC::Wasm::SectionParser::parseI32InitExprForDataSection): (JSC::Wasm::SectionParser::parseDataSegmentCoreSpec): (JSC::Wasm::SectionParser::parseDataSegmentReferenceTypesSpec): (JSC::Wasm::SectionParser::parseGlobalType): (JSC::Wasm::SectionParser::parseData): (JSC::Wasm::SectionParser::parseDataCount): * wasm/WasmSectionParser.h: * wasm/WasmSections.h: (JSC::Wasm::validateOrder): * wasm/WasmSlowPaths.cpp: (JSC::LLInt::WASM_SLOW_PATH_DECL): * wasm/WasmSlowPaths.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::evaluate): * wasm/wasm.json: Canonical link: https://commits.webkit.org/232571@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@270948 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-12-17 22:25:20 +00:00
bool memoryInit(uint32_t dstAddress, uint32_t srcAddress, uint32_t length, uint32_t dataSegmentIndex);
void dataDrop(uint32_t dataSegmentIndex);
Unreviewed, relanding r269940 https://bugs.webkit.org/show_bug.cgi?id=219076 JSTests: * wasm/function-tests/trap-load-shared.js: Added. (wasmFrameCountFromError): * wasm/function-tests/trap-store-shared.js: Added. * wasm/js-api/test_memory.js: (binaryShouldNotParse): * wasm/stress/shared-memory-errors.js: Added. (assert.throws): * wasm/stress/shared-wasm-memory-buffer.js: Added. LayoutTests/imported/w3c: * web-platform-tests/html/webappapis/scripting/processing-model-2/integration-with-the-javascript-agent-formalism/requires-success.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/memory/constructor-shared.tentative.any-expected.txt: * web-platform-tests/wasm/jsapi/memory/constructor-shared.tentative.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/memory/constructor.any-expected.txt: * web-platform-tests/wasm/jsapi/memory/constructor.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/memory/grow.any-expected.txt: * web-platform-tests/wasm/jsapi/memory/grow.any.worker-expected.txt: * web-platform-tests/webaudio/the-audio-api/the-audiobuffer-interface/audiobuffer-copy-channel-expected.txt: Source/JavaScriptCore: ARM64E clang optimizer is broken and optimizing forever if Wasm::MemoryHandle::memory() is inlined. Putting NEVER_INLINE onto this function for now (unfortunate). * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * llint/LLIntPCRanges.h: (JSC::LLInt::isWasmLLIntPC): * llint/LowLevelInterpreter.asm: * llint/WebAssembly.asm: * runtime/JSArrayBuffer.h: (JSC::JSArrayBuffer::toWrappedAllowShared): * runtime/JSArrayBufferView.h: * runtime/JSArrayBufferViewInlines.h: (JSC::JSArrayBufferView::toWrappedAllowShared): * runtime/JSGenericTypedArrayView.h: (JSC::JSGenericTypedArrayView<Adaptor>::toWrappedAllowShared): * runtime/Options.cpp: (JSC::overrideDefaults): (JSC::Options::initialize): * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::AirIRGenerator): (JSC::Wasm::AirIRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::AirIRGenerator::addCurrentMemory): (JSC::Wasm::AirIRGenerator::emitCheckAndPreparePointer): (JSC::Wasm::AirIRGenerator::addCall): (JSC::Wasm::AirIRGenerator::addCallIndirect): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::emitCheckAndPreparePointer): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmFaultSignalHandler.cpp: (JSC::Wasm::trapHandler): (JSC::Wasm::enableFastMemory): (JSC::Wasm::prepareFastMemory): * wasm/WasmInstance.h: (JSC::Wasm::Instance::cachedMemory const): (JSC::Wasm::Instance::cachedBoundsCheckingSize const): (JSC::Wasm::Instance::updateCachedMemory): (JSC::Wasm::Instance::offsetOfCachedBoundsCheckingSize): (JSC::Wasm::Instance::cachedMemorySize const): Deleted. (JSC::Wasm::Instance::offsetOfCachedMemorySize): Deleted. * wasm/WasmMemory.cpp: (JSC::Wasm::MemoryHandle::MemoryHandle): (JSC::Wasm::MemoryHandle::~MemoryHandle): (JSC::Wasm::MemoryHandle::memory const): (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::tryCreate): (JSC::Wasm::Memory::addressIsInGrowableOrFastMemory): (JSC::Wasm::Memory::growShared): (JSC::Wasm::Memory::grow): (JSC::Wasm::Memory::dump const): (JSC::Wasm::Memory::~Memory): Deleted. (JSC::Wasm::Memory::addressIsInActiveFastMemory): Deleted. * wasm/WasmMemory.h: (JSC::Wasm::Memory::addressIsInGrowableOrFastMemory): (JSC::Wasm::Memory::operator bool const): Deleted. (JSC::Wasm::Memory::memory const): Deleted. (JSC::Wasm::Memory::size const): Deleted. (JSC::Wasm::Memory::sizeInPages const): Deleted. (JSC::Wasm::Memory::initial const): Deleted. (JSC::Wasm::Memory::maximum const): Deleted. (JSC::Wasm::Memory::mode const): Deleted. (JSC::Wasm::Memory::check): Deleted. (JSC::Wasm::Memory::offsetOfMemory): Deleted. (JSC::Wasm::Memory::offsetOfSize): Deleted. (JSC::Wasm::Memory::addressIsInActiveFastMemory): Deleted. * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::tryCreate): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::buffer): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::WebAssemblyFunction::jsCallEntrypointSlow): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::evaluate): Source/WebCore: Tests: js/dom/webassembly-memory-normal-fail.html js/dom/webassembly-memory-shared-basic.html js/dom/webassembly-memory-shared-fail.html storage/indexeddb/shared-memory-structured-clone.html * Headers.cmake: * Modules/indexeddb/server/IDBSerializationContext.cpp: (WebCore::IDBServer::IDBSerializationContext::initializeVM): * WebCore.xcodeproj/project.pbxproj: * bindings/IDLTypes.h: * bindings/js/CommonVM.cpp: (WebCore::commonVMSlow): * bindings/js/JSDOMConvertBufferSource.h: (WebCore::Detail::BufferSourceConverter::convert): (WebCore::Converter<IDLArrayBuffer>::convert): (WebCore::Converter<IDLDataView>::convert): (WebCore::Converter<IDLInt8Array>::convert): (WebCore::Converter<IDLInt16Array>::convert): (WebCore::Converter<IDLInt32Array>::convert): (WebCore::Converter<IDLUint8Array>::convert): (WebCore::Converter<IDLUint16Array>::convert): (WebCore::Converter<IDLUint32Array>::convert): (WebCore::Converter<IDLUint8ClampedArray>::convert): (WebCore::Converter<IDLFloat32Array>::convert): (WebCore::Converter<IDLFloat64Array>::convert): (WebCore::Converter<IDLArrayBufferView>::convert): (WebCore::Converter<IDLAllowSharedAdaptor<T>>::convert): * bindings/js/JSDOMConvertUnion.h: * bindings/js/SerializedScriptValue.cpp: (WebCore::CloneSerializer::serialize): (WebCore::CloneSerializer::CloneSerializer): (WebCore::CloneSerializer::dumpIfTerminal): (WebCore::CloneDeserializer::deserialize): (WebCore::CloneDeserializer::CloneDeserializer): (WebCore::CloneDeserializer::readTerminal): (WebCore::SerializedScriptValue::SerializedScriptValue): (WebCore::SerializedScriptValue::computeMemoryCost const): (WebCore::SerializedScriptValue::create): (WebCore::SerializedScriptValue::deserialize): * bindings/js/SerializedScriptValue.h: * bindings/js/WebCoreJSClientData.cpp: (WebCore::JSVMClientData::initNormalWorld): * bindings/js/WebCoreJSClientData.h: * bindings/js/WebCoreTypedArrayController.cpp: (WebCore::WebCoreTypedArrayController::WebCoreTypedArrayController): (WebCore::WebCoreTypedArrayController::isAtomicsWaitAllowedOnCurrentThread): * bindings/js/WebCoreTypedArrayController.h: * bindings/scripts/CodeGeneratorJS.pm: (IsAnnotatedType): (GetAnnotatedIDLType): * bindings/scripts/IDLAttributes.json: * bindings/scripts/test/JS/JSTestObj.cpp: (WebCore::JSTestObjDOMConstructor::construct): (WebCore::jsTestObjPrototypeFunction_encodeIntoBody): (WebCore::JSC_DEFINE_HOST_FUNCTION): * bindings/scripts/test/TestObj.idl: * dom/TextDecoder.idl: * dom/TextDecoderStreamDecoder.idl: * dom/TextEncoder.idl: * workers/DedicatedWorkerGlobalScope.cpp: (WebCore::DedicatedWorkerGlobalScope::DedicatedWorkerGlobalScope): * workers/WorkerGlobalScope.cpp: (WebCore::WorkerGlobalScope::WorkerGlobalScope): * workers/WorkerGlobalScope.h: * workers/WorkerOrWorkletGlobalScope.cpp: (WebCore::WorkerOrWorkletGlobalScope::WorkerOrWorkletGlobalScope): * workers/WorkerOrWorkletGlobalScope.h: * workers/WorkerOrWorkletScriptController.cpp: (WebCore::WorkerOrWorkletScriptController::WorkerOrWorkletScriptController): * workers/WorkerOrWorkletScriptController.h: * workers/WorkerThreadType.h: Added. * workers/service/ServiceWorkerGlobalScope.cpp: (WebCore::ServiceWorkerGlobalScope::ServiceWorkerGlobalScope): * worklets/WorkletGlobalScope.cpp: (WebCore::WorkletGlobalScope::WorkletGlobalScope): Source/WTF: * wtf/PlatformEnable.h: LayoutTests: * js/dom/resources/webassembly-memory-normal-fail-worker.js: Added. * js/dom/resources/webassembly-memory-shared-worker.js: Added. (onmessage): * js/dom/webassembly-memory-normal-fail-expected.txt: Added. * js/dom/webassembly-memory-normal-fail.html: Added. * js/dom/webassembly-memory-shared-basic-expected.txt: Added. * js/dom/webassembly-memory-shared-basic.html: Added. * js/dom/webassembly-memory-shared-fail-expected.txt: Added. * js/dom/webassembly-memory-shared-fail.html: Added. * platform/win/TestExpectations: * storage/indexeddb/resources/shared-memory-structured-clone.js: Added. (prepareDatabase): (async startTests): (testSharedWebAssemblyMemory): * storage/indexeddb/shared-memory-structured-clone-expected.txt: Added. * storage/indexeddb/shared-memory-structured-clone.html: Added. Canonical link: https://commits.webkit.org/231721@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@269974 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-11-18 20:22:16 +00:00
void* cachedMemory() const { return m_cachedMemory.getMayBeNull(cachedBoundsCheckingSize()); }
size_t cachedBoundsCheckingSize() const { return m_cachedBoundsCheckingSize; }
WebAssembly: cache memory address / size on instance https://bugs.webkit.org/show_bug.cgi?id=177305 Reviewed by JF Bastien. JSTests: * wasm/function-tests/memory-reuse.js: Added. (createWasmInstance): (doCheckTrap): (doMemoryGrow): (doCheck): (checkWasmInstancesWithSharedMemory): Source/JavaScriptCore: Cache memory address/size in wasm:Instance to avoid load wasm:Memory object during access to memory and memory size property in JiT * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmInstance.h: (JSC::Wasm::Instance::cachedMemory const): (JSC::Wasm::Instance::cachedMemorySize const): (JSC::Wasm::Instance::createWeakPtr): (JSC::Wasm::Instance::setMemory): (JSC::Wasm::Instance::updateCachedMemory): (JSC::Wasm::Instance::offsetOfCachedMemory): (JSC::Wasm::Instance::offsetOfCachedMemorySize): (JSC::Wasm::Instance::offsetOfCachedIndexingMask): (JSC::Wasm::Instance::allocationSize): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::grow): (JSC::Wasm::Memory::registerInstance): * wasm/WasmMemory.h: (JSC::Wasm::Memory::indexingMask): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::evaluate): Canonical link: https://commits.webkit.org/198823@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@228966 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-02-23 23:16:59 +00:00
void setMemory(Ref<Memory>&& memory)
{
m_memory = WTFMove(memory);
m_memory.get()->registerInstance(this);
updateCachedMemory();
}
void updateCachedMemory()
{
if (m_memory != nullptr) {
Unreviewed, relanding r269940 https://bugs.webkit.org/show_bug.cgi?id=219076 JSTests: * wasm/function-tests/trap-load-shared.js: Added. (wasmFrameCountFromError): * wasm/function-tests/trap-store-shared.js: Added. * wasm/js-api/test_memory.js: (binaryShouldNotParse): * wasm/stress/shared-memory-errors.js: Added. (assert.throws): * wasm/stress/shared-wasm-memory-buffer.js: Added. LayoutTests/imported/w3c: * web-platform-tests/html/webappapis/scripting/processing-model-2/integration-with-the-javascript-agent-formalism/requires-success.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/memory/constructor-shared.tentative.any-expected.txt: * web-platform-tests/wasm/jsapi/memory/constructor-shared.tentative.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/memory/constructor.any-expected.txt: * web-platform-tests/wasm/jsapi/memory/constructor.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/memory/grow.any-expected.txt: * web-platform-tests/wasm/jsapi/memory/grow.any.worker-expected.txt: * web-platform-tests/webaudio/the-audio-api/the-audiobuffer-interface/audiobuffer-copy-channel-expected.txt: Source/JavaScriptCore: ARM64E clang optimizer is broken and optimizing forever if Wasm::MemoryHandle::memory() is inlined. Putting NEVER_INLINE onto this function for now (unfortunate). * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * llint/LLIntPCRanges.h: (JSC::LLInt::isWasmLLIntPC): * llint/LowLevelInterpreter.asm: * llint/WebAssembly.asm: * runtime/JSArrayBuffer.h: (JSC::JSArrayBuffer::toWrappedAllowShared): * runtime/JSArrayBufferView.h: * runtime/JSArrayBufferViewInlines.h: (JSC::JSArrayBufferView::toWrappedAllowShared): * runtime/JSGenericTypedArrayView.h: (JSC::JSGenericTypedArrayView<Adaptor>::toWrappedAllowShared): * runtime/Options.cpp: (JSC::overrideDefaults): (JSC::Options::initialize): * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::AirIRGenerator): (JSC::Wasm::AirIRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::AirIRGenerator::addCurrentMemory): (JSC::Wasm::AirIRGenerator::emitCheckAndPreparePointer): (JSC::Wasm::AirIRGenerator::addCall): (JSC::Wasm::AirIRGenerator::addCallIndirect): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::emitCheckAndPreparePointer): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmFaultSignalHandler.cpp: (JSC::Wasm::trapHandler): (JSC::Wasm::enableFastMemory): (JSC::Wasm::prepareFastMemory): * wasm/WasmInstance.h: (JSC::Wasm::Instance::cachedMemory const): (JSC::Wasm::Instance::cachedBoundsCheckingSize const): (JSC::Wasm::Instance::updateCachedMemory): (JSC::Wasm::Instance::offsetOfCachedBoundsCheckingSize): (JSC::Wasm::Instance::cachedMemorySize const): Deleted. (JSC::Wasm::Instance::offsetOfCachedMemorySize): Deleted. * wasm/WasmMemory.cpp: (JSC::Wasm::MemoryHandle::MemoryHandle): (JSC::Wasm::MemoryHandle::~MemoryHandle): (JSC::Wasm::MemoryHandle::memory const): (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::tryCreate): (JSC::Wasm::Memory::addressIsInGrowableOrFastMemory): (JSC::Wasm::Memory::growShared): (JSC::Wasm::Memory::grow): (JSC::Wasm::Memory::dump const): (JSC::Wasm::Memory::~Memory): Deleted. (JSC::Wasm::Memory::addressIsInActiveFastMemory): Deleted. * wasm/WasmMemory.h: (JSC::Wasm::Memory::addressIsInGrowableOrFastMemory): (JSC::Wasm::Memory::operator bool const): Deleted. (JSC::Wasm::Memory::memory const): Deleted. (JSC::Wasm::Memory::size const): Deleted. (JSC::Wasm::Memory::sizeInPages const): Deleted. (JSC::Wasm::Memory::initial const): Deleted. (JSC::Wasm::Memory::maximum const): Deleted. (JSC::Wasm::Memory::mode const): Deleted. (JSC::Wasm::Memory::check): Deleted. (JSC::Wasm::Memory::offsetOfMemory): Deleted. (JSC::Wasm::Memory::offsetOfSize): Deleted. (JSC::Wasm::Memory::addressIsInActiveFastMemory): Deleted. * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::tryCreate): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::buffer): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::WebAssemblyFunction::jsCallEntrypointSlow): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::evaluate): Source/WebCore: Tests: js/dom/webassembly-memory-normal-fail.html js/dom/webassembly-memory-shared-basic.html js/dom/webassembly-memory-shared-fail.html storage/indexeddb/shared-memory-structured-clone.html * Headers.cmake: * Modules/indexeddb/server/IDBSerializationContext.cpp: (WebCore::IDBServer::IDBSerializationContext::initializeVM): * WebCore.xcodeproj/project.pbxproj: * bindings/IDLTypes.h: * bindings/js/CommonVM.cpp: (WebCore::commonVMSlow): * bindings/js/JSDOMConvertBufferSource.h: (WebCore::Detail::BufferSourceConverter::convert): (WebCore::Converter<IDLArrayBuffer>::convert): (WebCore::Converter<IDLDataView>::convert): (WebCore::Converter<IDLInt8Array>::convert): (WebCore::Converter<IDLInt16Array>::convert): (WebCore::Converter<IDLInt32Array>::convert): (WebCore::Converter<IDLUint8Array>::convert): (WebCore::Converter<IDLUint16Array>::convert): (WebCore::Converter<IDLUint32Array>::convert): (WebCore::Converter<IDLUint8ClampedArray>::convert): (WebCore::Converter<IDLFloat32Array>::convert): (WebCore::Converter<IDLFloat64Array>::convert): (WebCore::Converter<IDLArrayBufferView>::convert): (WebCore::Converter<IDLAllowSharedAdaptor<T>>::convert): * bindings/js/JSDOMConvertUnion.h: * bindings/js/SerializedScriptValue.cpp: (WebCore::CloneSerializer::serialize): (WebCore::CloneSerializer::CloneSerializer): (WebCore::CloneSerializer::dumpIfTerminal): (WebCore::CloneDeserializer::deserialize): (WebCore::CloneDeserializer::CloneDeserializer): (WebCore::CloneDeserializer::readTerminal): (WebCore::SerializedScriptValue::SerializedScriptValue): (WebCore::SerializedScriptValue::computeMemoryCost const): (WebCore::SerializedScriptValue::create): (WebCore::SerializedScriptValue::deserialize): * bindings/js/SerializedScriptValue.h: * bindings/js/WebCoreJSClientData.cpp: (WebCore::JSVMClientData::initNormalWorld): * bindings/js/WebCoreJSClientData.h: * bindings/js/WebCoreTypedArrayController.cpp: (WebCore::WebCoreTypedArrayController::WebCoreTypedArrayController): (WebCore::WebCoreTypedArrayController::isAtomicsWaitAllowedOnCurrentThread): * bindings/js/WebCoreTypedArrayController.h: * bindings/scripts/CodeGeneratorJS.pm: (IsAnnotatedType): (GetAnnotatedIDLType): * bindings/scripts/IDLAttributes.json: * bindings/scripts/test/JS/JSTestObj.cpp: (WebCore::JSTestObjDOMConstructor::construct): (WebCore::jsTestObjPrototypeFunction_encodeIntoBody): (WebCore::JSC_DEFINE_HOST_FUNCTION): * bindings/scripts/test/TestObj.idl: * dom/TextDecoder.idl: * dom/TextDecoderStreamDecoder.idl: * dom/TextEncoder.idl: * workers/DedicatedWorkerGlobalScope.cpp: (WebCore::DedicatedWorkerGlobalScope::DedicatedWorkerGlobalScope): * workers/WorkerGlobalScope.cpp: (WebCore::WorkerGlobalScope::WorkerGlobalScope): * workers/WorkerGlobalScope.h: * workers/WorkerOrWorkletGlobalScope.cpp: (WebCore::WorkerOrWorkletGlobalScope::WorkerOrWorkletGlobalScope): * workers/WorkerOrWorkletGlobalScope.h: * workers/WorkerOrWorkletScriptController.cpp: (WebCore::WorkerOrWorkletScriptController::WorkerOrWorkletScriptController): * workers/WorkerOrWorkletScriptController.h: * workers/WorkerThreadType.h: Added. * workers/service/ServiceWorkerGlobalScope.cpp: (WebCore::ServiceWorkerGlobalScope::ServiceWorkerGlobalScope): * worklets/WorkletGlobalScope.cpp: (WebCore::WorkletGlobalScope::WorkletGlobalScope): Source/WTF: * wtf/PlatformEnable.h: LayoutTests: * js/dom/resources/webassembly-memory-normal-fail-worker.js: Added. * js/dom/resources/webassembly-memory-shared-worker.js: Added. (onmessage): * js/dom/webassembly-memory-normal-fail-expected.txt: Added. * js/dom/webassembly-memory-normal-fail.html: Added. * js/dom/webassembly-memory-shared-basic-expected.txt: Added. * js/dom/webassembly-memory-shared-basic.html: Added. * js/dom/webassembly-memory-shared-fail-expected.txt: Added. * js/dom/webassembly-memory-shared-fail.html: Added. * platform/win/TestExpectations: * storage/indexeddb/resources/shared-memory-structured-clone.js: Added. (prepareDatabase): (async startTests): (testSharedWebAssemblyMemory): * storage/indexeddb/shared-memory-structured-clone-expected.txt: Added. * storage/indexeddb/shared-memory-structured-clone.html: Added. Canonical link: https://commits.webkit.org/231721@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@269974 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-11-18 20:22:16 +00:00
m_cachedMemory = CagedPtr<Gigacage::Primitive, void, tagCagedPtr>(memory()->memory(), memory()->boundsCheckingSize());
m_cachedBoundsCheckingSize = memory()->boundsCheckingSize();
JSTests: [JSC] WasmMemory caging should care about nullptr https://bugs.webkit.org/show_bug.cgi?id=224268 <rdar://problem/74654838> Reviewed by Mark Lam. * wasm/stress/4g-memory-cage.js: Added. (async test): * wasm/stress/more-than-4g-offset-access-oom.js: Added. (async test): * wasm/stress/null-memory-cage-explicit.js: Added. (async test): * wasm/stress/null-memory-cage.js: Added. (async test): Source/JavaScriptCore: [JSC] WasmMemory caging should care about nullptr https://bugs.webkit.org/show_bug.cgi?id=224268 <rdar://problem/74654838> Reviewed by Mark Lam. 1. Fix Wasm::MemoryHandle::boundsCheckingSize. We should just return m_mappedCapacity here since UINT32_MAX is not 4GB. This checking size can include redzone for fast-memory, but this is OK: bounds-check pass in LLInt (in upper tiers, we do not use bounds-check for fast-memory), and access to redzone, then fault occurs and signal handler can make it error since signal handler is checking whether the access is within Memory::fastMappedBytes which includes redzone. 2. Fix caging of wasm memory-base pointer in LLInt. We should use pointer sized length since it can be larger than 4GB. And we should handle nullptr case correctly: Wasm::MemoryHandle's memory can be nullptr when mapped size is zero. caging needs to handle this case as we do in CagedPtr::getMayBeNull. * assembler/MacroAssemblerARM64E.h: (JSC::MacroAssemblerARM64E::untagArrayPtrLength32): * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::cageTypedArrayStorage): * llint/LowLevelInterpreter64.asm: * llint/WebAssembly.asm: * offlineasm/arm64e.rb: * offlineasm/ast.rb: * offlineasm/instructions.rb: * runtime/CagedBarrierPtr.h: (JSC::CagedBarrierPtr::CagedBarrierPtr): (JSC::CagedBarrierPtr::set): (JSC::CagedBarrierPtr::get const): (JSC::CagedBarrierPtr::getMayBeNull const): (JSC::CagedBarrierPtr::at const): (JSC::CagedBarrierPtr::setWithoutBarrier): * wasm/WasmInstance.h: (JSC::Wasm::Instance::updateCachedMemory): * wasm/WasmMemory.cpp: (JSC::Wasm::MemoryHandle::MemoryHandle): * wasm/WasmMemory.h: Source/WTF: [JSC] WasmMemory caging should care nullptr https://bugs.webkit.org/show_bug.cgi?id=224268 <rdar://problem/74654838> Reviewed by Mark Lam. Accept size_t since Wasm::Memory's length can be larger than 4GB. * wtf/CagedPtr.h: (WTF::CagedPtr::CagedPtr): (WTF::CagedPtr::get const): (WTF::CagedPtr::getMayBeNull const): (WTF::CagedPtr::at const): (WTF::CagedPtr::recage): * wtf/CagedUniquePtr.h: (WTF::CagedUniquePtr::CagedUniquePtr): (WTF::CagedUniquePtr::create): (WTF::CagedUniquePtr::tryCreate): Canonical link: https://commits.webkit.org/236242@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@275597 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-04-07 09:28:49 +00:00
ASSERT(memory()->memory() == cachedMemory());
WebAssembly: cache memory address / size on instance https://bugs.webkit.org/show_bug.cgi?id=177305 Reviewed by JF Bastien. JSTests: * wasm/function-tests/memory-reuse.js: Added. (createWasmInstance): (doCheckTrap): (doMemoryGrow): (doCheck): (checkWasmInstancesWithSharedMemory): Source/JavaScriptCore: Cache memory address/size in wasm:Instance to avoid load wasm:Memory object during access to memory and memory size property in JiT * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmInstance.h: (JSC::Wasm::Instance::cachedMemory const): (JSC::Wasm::Instance::cachedMemorySize const): (JSC::Wasm::Instance::createWeakPtr): (JSC::Wasm::Instance::setMemory): (JSC::Wasm::Instance::updateCachedMemory): (JSC::Wasm::Instance::offsetOfCachedMemory): (JSC::Wasm::Instance::offsetOfCachedMemorySize): (JSC::Wasm::Instance::offsetOfCachedIndexingMask): (JSC::Wasm::Instance::allocationSize): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::grow): (JSC::Wasm::Memory::registerInstance): * wasm/WasmMemory.h: (JSC::Wasm::Memory::indexingMask): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::evaluate): Canonical link: https://commits.webkit.org/198823@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@228966 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-02-23 23:16:59 +00:00
}
}
WebAssembly: no VM / JS version of everything but Instance https://bugs.webkit.org/show_bug.cgi?id=177473 Reviewed by Filip Pizlo, Saam Barati. JSTests: - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. * wasm/js-api/memory-grow.js: (assertEq): * wasm/js-api/table.js: (assert.throws): Source/JavaScriptCore: This change entails cleaning up and splitting a bunch of code which we had intertwined between C++ classes which represent JS objects, and pure C++ implementation objects. This specific change goes most of the way towards allowing JSC's WebAssembly to work without VM / JS, up to but excluding JSWebAssemblyInstance (there's Wasm::Instance, but it's not *the* thing yet). Because of this we still have a few FIXME identifying places that need to change. A follow-up change will go the rest of the way. I went about this change in the simplest way possible: grep the JavaScriptCore/wasm directory for "JS[^C_]" as well as "VM" and exclude the /js/ sub-directory (which contains the JS implementation of WebAssembly). None of this change removes the need for a JIT entitlement to be able to use WebAssembly. We don't have an interpreter, the process therefore still needs to be allowed to JIT to use these pure-C++ APIs. Interesting things to note: - Remove VM from Plan and associated places. It can just live as a capture in the callback lambda if it's needed. - Wasm::Memory shouldn't require a VM. It was only used to ask the GC to collect. We now instead pass two lambdas at construction time for this purpose: one to notify of memory pressure, and the other to ask for syncrhonous memory reclamation. This allows whoever creates the memory to dictate how to react to both these cases, and for a JS embedding that's to call the GC (async or sync, respectively). - Move grow logic from JSWebAssemblyMemory to Wasm::Memory::grow. Use Expected there, with an enum class for failure types. - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. - When generating the grow_memory opcode, no need to get the VM. Instead, reach directly for Wasm::Memory and grow it. - JSWebAssemblyMemory::grow can now always throw on failure, because it's only ever called from JS (not from grow_memory as before). - Wasm::Memory now takes a callback for successful growth. This allows JS wrappers to register themselves when growth succeeds without Wasm::Memory knowning anything about JS. It'll also allow creating a list of callbacks for when we add thread support (we'll want to notify many wrappers, all under a lock). - Wasm::Memory is now back to being the source of truth about address / size, used directly by generated code instead of JSWebAssemblyMemory. - Move wasmToJS from the general WasmBinding header to its own header under wasm/js. It's only used by wasm/js/JSWebAssemblyCodeBlock.cpp, and uses VM, and therefore isn't general WebAssembly. - Make Wasm::Context an actual type (just a struct holding a JSWebAssemlyInstance for now) instead of an alias for that. Notably this doesn't add anything to the Context and doesn't change what actually gets passed around in JIT code (fast TLS or registers) because these changes potentially impact performance. The entire purpose of this change is to allow passing Wasm::Context around without having to know about VM. Since VM contains a Wasm::Context the JS embedding is effectively the same, but with this setup a non-JS embedding is much better off. - Move JSWebAssembly into the JS folder. - OMGPlan: use Wasm::CodeBlock directly instead of JSWebAssemblyCodeBlock. - wasm->JS stubs are now on the instance's tail as raw pointers, instead of being on JSWebAssemblyCodeBlock, and are now called wasm->Embedder stubs. The owned reference is still on JSWebAssemblyCodeBlock, and is still called wasm->JS stub. This move means that the embedder must, after creating a Wasm::CodeBlock, somehow create the stubs to call back into the embedder. This removes an indirection in the generated code because the B3 IR generator now reaches into the instance instead of JSWebAssemblyCodeBlock. - Move more CodeBlock things. Compilation completion is now marked by its own atomic<bool> flag instead of a nullptr plan: that required using a lock, and was causing a deadlock in stack-trace.js because before my changes JSWebAssemblyCodeBlock did its own completion checking separately from Wasm::CodeBlock, without getting the lock. Now that everything points to Wasm::CodeBlock and there's no cached completion marker, the lock was being acquired in a sanity-check assertion. - Embedder -> Wasm wrappers are now generated through a function that's passed in at compilation time, instead of being hard-coded as a JS -> Wasm wrapper. - WasmMemory doens't need to know about fault handling thunks. Only the IR generator should know, and should make sure that the exception throwing thunk is generated if any memory is present (note: with signal handling not all of them generate an exception check). - Make exception throwing pluggable: instead of having a hard-coded JS-specific lambda we now have a regular C++ function being called from JIT code when a WebAssembly exception is thrown. This allows any embedder to get called as they wish. For now a process can only have a single of these functions (i.e. only one embedder per process) because the trap handler is a singleton. That can be fixed in in #177475. - Create WasmEmbedder.h where all embedder plugging will live. - Split up JSWebAssemblyTable into Wasm::Table which is refcounted. JSWebAssemblyTable now only contains the JS functions in the table, and Wasm::Table is what's used by the JIT code to lookup where to call and do the instance check (for context switch). Note that this creates an extra allocation for all the instances in Wasm::Table, and in exchange removes an indirection in JIT code because the instance used to be obtained off of the JS function. Also note that it's the embedder than keeps the instances alive, not Wasm::Table (which holds a dumb pointer to the instance), because doing otherwise would cause reference cycles. - Add WasmInstance. It doesn't do much for now, owns globals. - JSWebAssembly instance now doesn't just contain the imported functions as JSObjects, it also has the corresponding import's instance and wasm entrypoint. This triples the space allocated per instance's imported function, but there shouldn't be that many imports. This has two upsides: it creates smaller and faster code, and makes is easier to disassociate embedder-specific things from embedder-neutral things. The small / faster win is in two places: B3 IR generator only needs offsetOfImportFunction for the call opcode (when the called index is an import) to know whether the import is wasm->wasm or wasm->embedder (this isn't known at compile-time because it's dependent on the import object), this is now done by seeing if that import function has an associated target instance (only wasm->wasm does); the other place is wasmBinding which uses offsetOfImportFunction to figure out the wasm->wasm target instance, and then gets WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation to do a tail call. The disassociation comes because the target instance can be Wasm::Instance once we change what the Context is, and WasmEntrypointLoadLocation is already embedder-independent. As a next step I can move this tail allocation from JSWebAssemblyInstance to Wasm::Instance, and leave importFunction in as an opaque pointer which is embedder-specific, and in JS will remain WriteBarrier<JSObject>. - Rename VMEntryFrame to EntryFrame, and in many places pass a pointer to it around instead of VM. This is a first step in allowing entry frames which aren't stored on VM, but which are instead stored in an embedder-specific location. That change won't really affect JS except through code churn, but will allow WebAssembly to use some machinery in a generic manner without having a VM. * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * debugger/Debugger.cpp: (JSC::Debugger::stepOutOfFunction): (JSC::Debugger::returnEvent): (JSC::Debugger::unwindEvent): (JSC::Debugger::didExecuteProgram): * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::compileExceptionHandlers): * dfg/DFGOSREntry.cpp: (JSC::DFG::prepareOSREntry): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::compileOSRExit): (JSC::DFG::OSRExit::compileExit): * dfg/DFGThunks.cpp: (JSC::DFG::osrEntryThunkGenerator): * ftl/FTLCompile.cpp: (JSC::FTL::compile): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::lower): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): (JSC::CallFrame::callerFrame): (JSC::CallFrame::unsafeCallerFrame): * interpreter/CallFrame.h: (JSC::ExecState::callerFrame const): (JSC::ExecState::callerFrameOrEntryFrame const): (JSC::ExecState::unsafeCallerFrameOrEntryFrame const): * interpreter/FrameTracers.h: (JSC::NativeCallFrameTracer::NativeCallFrameTracer): (JSC::NativeCallFrameTracerWithRestore::NativeCallFrameTracerWithRestore): (JSC::NativeCallFrameTracerWithRestore::~NativeCallFrameTracerWithRestore): * interpreter/Interpreter.cpp: (JSC::UnwindFunctor::operator() const): (JSC::UnwindFunctor::copyCalleeSavesToEntryFrameCalleeSavesBuffer const): (JSC::Interpreter::unwind): * interpreter/StackVisitor.cpp: (JSC::StackVisitor::StackVisitor): (JSC::StackVisitor::gotoNextFrame): (JSC::StackVisitor::readNonInlinedFrame): (JSC::StackVisitor::Frame::dump const): * interpreter/StackVisitor.h: (JSC::StackVisitor::Frame::callerIsEntryFrame const): * interpreter/VMEntryRecord.h: (JSC::VMEntryRecord::prevTopEntryFrame): (JSC::VMEntryRecord::unsafePrevTopEntryFrame): (JSC::EntryFrame::vmEntryRecordOffset): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::restoreCalleeSavesFromEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::loadWasmContextInstance): (JSC::AssemblyHelpers::storeWasmContextInstance): (JSC::AssemblyHelpers::loadWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::storeWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBufferImpl): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::copyCalleeSavesToVMEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer): * jit/JIT.cpp: (JSC::JIT::emitEnterOptimizationCheck): (JSC::JIT::privateCompileExceptionHandlers): * jit/JITExceptions.cpp: (JSC::genericUnwind): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): (JSC::JIT::emitSlow_op_loop_hint): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): * jit/JITOperations.cpp: * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::nativeForGenerator): * jsc.cpp: (functionDumpCallFrame): * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LLIntThunks.cpp: (JSC::vmEntryRecord): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/Options.cpp: (JSC::recomputeDependentOptions): * runtime/Options.h: * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::FrameWalker): (JSC::FrameWalker::advanceToParentFrame): (JSC::SamplingProfiler::processUnverifiedStackTraces): * runtime/ThrowScope.cpp: (JSC::ThrowScope::~ThrowScope): * runtime/VM.cpp: (JSC::VM::VM): (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::topEntryFrameOffset): * runtime/VMTraps.cpp: (JSC::isSaneFrame): (JSC::VMTraps::tryInstallTrapBreakpoints): (JSC::VMTraps::invalidateCodeBlocksOnStack): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWasmContextInstance): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::parseAndCompile): * wasm/WasmB3IRGenerator.h: * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::BBQPlan): (JSC::Wasm::BBQPlan::compileFunctions): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBBQPlanInlines.h: (JSC::Wasm::BBQPlan::initializeCallees): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmBinding.h: * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::create): (JSC::Wasm::CodeBlock::CodeBlock): (JSC::Wasm::CodeBlock::compileAsync): (JSC::Wasm::CodeBlock::setCompilationFinished): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::offsetOfImportStubs): (JSC::Wasm::CodeBlock::allocationSize): (JSC::Wasm::CodeBlock::importWasmToEmbedderStub): (JSC::Wasm::CodeBlock::offsetOfImportWasmToEmbedderStub): (JSC::Wasm::CodeBlock::wasmToJSCallStubForImport): (JSC::Wasm::CodeBlock::compilationFinished): (JSC::Wasm::CodeBlock::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): * wasm/WasmContext.cpp: (JSC::Wasm::Context::useFastTLS): (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: Copied from Source/JavaScriptCore/wasm/WasmContext.h. * wasm/WasmFaultSignalHandler.cpp: * wasm/WasmFaultSignalHandler.h: * wasm/WasmFormat.h: * wasm/WasmInstance.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::~Instance): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: Added. (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::module): (JSC::Wasm::Instance::codeBlock): (JSC::Wasm::Instance::memory): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::loadF32Global const): (JSC::Wasm::Instance::loadF64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::offsetOfCachedStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::~Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::offsetOfSize): * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationCallback): (JSC::Wasm::Module::validateSync): (JSC::Wasm::Module::validateAsync): (JSC::Wasm::Module::getOrCreateCodeBlock): (JSC::Wasm::Module::compileSync): (JSC::Wasm::Module::compileAsync): * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseTableHelper): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::OMGPlan): (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::isValid const): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::runCompletionTasks): (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmPlan.h: (JSC::Wasm::Plan::dontFinalize): * wasm/WasmSignature.cpp: * wasm/WasmSignature.h: * wasm/WasmTable.cpp: Added. (JSC::Wasm::Table::create): (JSC::Wasm::Table::~Table): (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h. (JSC::Wasm::Table::maximum const): (JSC::Wasm::Table::size const): (JSC::Wasm::Table::offsetOfSize): (JSC::Wasm::Table::offsetOfFunctions): (JSC::Wasm::Table::offsetOfInstances): (JSC::Wasm::Table::isValidSize): * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): (JSC::Wasm::Thunks::setThrowWasmException): (JSC::Wasm::Thunks::throwWasmException): * wasm/WasmThunks.h: * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::stopAllPlansForContext): * wasm/WasmWorklist.h: * wasm/js/JSToWasm.cpp: Added. (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/JSWebAssembly.cpp: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.cpp. * wasm/js/JSWebAssembly.h: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.h. * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::create): (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::context const): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::webAssemblyToJSCallee): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::offsetOfTail): (JSC::JSWebAssemblyInstance::importFunctionInfo): (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): (JSC::JSWebAssemblyInstance::offsetOfImportFunction): (JSC::JSWebAssemblyInstance::importFunction): (JSC::JSWebAssemblyInstance::internalMemory): (JSC::JSWebAssemblyInstance::wasmCodeBlock const): (JSC::JSWebAssemblyInstance::offsetOfWasmTable): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::offsetOfGlobals): (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): (JSC::JSWebAssemblyInstance::cachedStackLimit const): (JSC::JSWebAssemblyInstance::setCachedStackLimit): (JSC::JSWebAssemblyInstance::wasmMemory): (JSC::JSWebAssemblyInstance::wasmModule): (JSC::JSWebAssemblyInstance::allocationSize): (JSC::JSWebAssemblyInstance::module const): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::create): (JSC::JSWebAssemblyMemory::adopt): (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::moduleInformation const): (JSC::JSWebAssemblyModule::exportSymbolTable const): (JSC::JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace const): (JSC::JSWebAssemblyModule::callee const): (JSC::JSWebAssemblyModule::codeBlock): (JSC::JSWebAssemblyModule::module): * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::create): (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::visitChildren): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::getFunction): (JSC::JSWebAssemblyTable::clearFunction): (JSC::JSWebAssemblyTable::setFunction): * wasm/js/JSWebAssemblyTable.h: (JSC::JSWebAssemblyTable::isValidSize): (JSC::JSWebAssemblyTable::maximum const): (JSC::JSWebAssemblyTable::size const): (JSC::JSWebAssemblyTable::table): * wasm/js/WasmToJS.cpp: Copied from Source/JavaScriptCore/wasm/WasmBinding.cpp. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): (JSC::WebAssemblyModuleConstructor::createModule): * wasm/js/WebAssemblyModuleConstructor.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::webAssemblyCompileFunc): (JSC::instantiate): (JSC::compileAndInstantiate): (JSC::webAssemblyValidateFunc): * wasm/js/WebAssemblyTableConstructor.cpp: (JSC::constructJSWebAssemblyTable): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Source/WebCore: * ForwardingHeaders/wasm/WasmModule.h: Added. This used to be included in JSWebAssemblyModule.h. * bindings/js/SerializedScriptValue.cpp: Update postMessage code according to C++ API changes. Canonical link: https://commits.webkit.org/194750@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223738 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-20 02:23:29 +00:00
Adopt the new WebAssembly.Global system https://bugs.webkit.org/show_bug.cgi?id=186552 Reviewed by Keith Miller. JSTests: 1. Update spec-harness to accept newer tests. And we update several tests that does not work with the old harness. 2. Add WebAssembly.Global tests. * wasm/js-api/global-error.js: (assert.throws.new.WebAssembly.Module.bin): (new.WebAssembly.Module): (assert.throws): * wasm/js-api/global-external-init-from-import.js: * wasm/js-api/globals-export.js: * wasm/modules/js-wasm-global-namespace.js: (assert.throws): * wasm/modules/js-wasm-global.js: (assert.throws): * wasm/modules/wasm-import-wasm-export-i64-error.js: * wasm/references/anyref_globals.js: * wasm/references/func_ref.js: (assert.eq.instance.exports.fix): * wasm/spec-harness.js: (getGlobal): (let.console.log): * wasm/spec-harness/sync_index.js: Renamed from JSTests/wasm/spec-harness/index.js. (reinitializeRegistry.let.handler.get return): (module): * wasm/spec-tests/call.wast.js: * wasm/spec-tests/exports.wast.js: * wasm/spec-tests/globals.wast.js: * wasm/spec-tests/if.wast.js: * wasm/spec-tests/imports.wast.js: * wasm/spec-tests/linking.wast.js: * wasm/spec-tests/memory.wast.js: * wasm/stress/immutable-globals.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.assert.eq.instance.exports.getI32): (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.assert.eq): * wasm/stress/mutable-globals-cross.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.const.instance1): (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.const.instance2): * wasm/stress/mutable-globals.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.instance.exports.setI32AsI64): LayoutTests/imported/w3c: * web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any-expected.txt: * web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/constructor.any-expected.txt: * web-platform-tests/wasm/jsapi/global/constructor.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/toString.any-expected.txt: * web-platform-tests/wasm/jsapi/global/toString.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/value-set.any-expected.txt: * web-platform-tests/wasm/jsapi/global/value-set.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/valueOf.any-expected.txt: * web-platform-tests/wasm/jsapi/global/valueOf.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor.any-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/interface.any-expected.txt: * web-platform-tests/wasm/jsapi/interface.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/module/exports.any-expected.txt: * web-platform-tests/wasm/jsapi/module/exports.any.worker-expected.txt: Source/JavaScriptCore: This patch adds WebAssembly.Global implementation. It is already included in the Wasm spec (this means, it is not in staging right now: it was stage-4, and included in the spec). WebAssembly.Global is a wrapper object around "global" binding. This object can hold "immutable" and "mutable" global binding, and we can access Wasm globals through this object. Furthermore, we can share mutable global binding through this object across WebAssembly modules. To implement it efficiently, this patch introduces BindingMode to Wasm globals. If the mode is EmbeddedInInstance, we continue using the current existing mechanism. If the mode is Portable, we store a pointer to actual value in Wasm globals array in Wasm::Instance, so that we can access it through one additional dereference. And we mark all immutable globals as EmbeddedInInstance. If the binding is immutable, internally we do not need to have one binding. We can just continue using the current mechanism since users cannot observe whether immutable bindings' storage is shared or not. If the global is mutable, and it is exported outside of the module, we use Portable mode. So, all the previously used wasm global bindings are EmbeddedInInstance. Only newly added "mutable" "exported" bindings are Portable and requires one additional dereference. To access portable bindings efficiently, we add new Wasm bytecodes, `get_global_portable_binding`, `set_global_portable_binding`, and `set_global_ref_portable_binding`. This patch improves WPT wasm coverage significantly. * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/BytecodeList.rb: * heap/HeapCell.cpp: (JSC::keepAlive): (JSC::HeapCell::use const): Deleted. * heap/HeapCell.h: (JSC::keepAlive): (JSC::HeapCell::use const): * llint/WebAssembly.asm: * runtime/JSGlobalObject.cpp: * runtime/JSGlobalObject.h: * runtime/VM.cpp: (JSC::VM::VM): * runtime/VM.h: * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::getGlobal): (JSC::Wasm::AirIRGenerator::setGlobal): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::getGlobal): (JSC::Wasm::B3IRGenerator::setGlobal): * wasm/WasmFormat.h: * wasm/WasmGlobal.cpp: Added. (JSC::Wasm::Global::get const): (JSC::Wasm::Global::set): (JSC::Wasm::Global::visitAggregate): * wasm/WasmGlobal.h: Added. * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::linkGlobal): * wasm/WasmInstance.h: (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::globalsToBinding): (JSC::Wasm::Instance::getGlobalBinding): * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::getGlobal): (JSC::Wasm::LLIntGenerator::setGlobal): * wasm/WasmModuleInformation.h: * wasm/WasmOperations.cpp: (JSC::Wasm::operationWasmWriteBarrierSlowPath): * wasm/WasmOperations.h: * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseImport): (JSC::Wasm::SectionParser::parseGlobal): (JSC::Wasm::SectionParser::parseExport): (JSC::Wasm::SectionParser::parseInitExpr): (JSC::Wasm::SectionParser::parseGlobalType): * wasm/WasmSectionParser.h: * wasm/WasmSlowPaths.cpp: (JSC::LLInt::WASM_SLOW_PATH_DECL): * wasm/WasmSlowPaths.h: * wasm/WasmValidate.cpp: (JSC::Wasm::Validate::setGlobal): * wasm/js/JSWebAssembly.cpp: * wasm/js/JSWebAssemblyGlobal.cpp: Added. (JSC::JSWebAssemblyGlobal::create): (JSC::JSWebAssemblyGlobal::createStructure): (JSC::JSWebAssemblyGlobal::JSWebAssemblyGlobal): (JSC::JSWebAssemblyGlobal::finishCreation): (JSC::JSWebAssemblyGlobal::destroy): (JSC::JSWebAssemblyGlobal::visitChildren): * wasm/js/JSWebAssemblyGlobal.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/JSWebAssemblyInstance.h: * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::destroy): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.h: * wasm/js/WebAssemblyGlobalConstructor.cpp: Added. (JSC::constructJSWebAssemblyGlobal): (JSC::callJSWebAssemblyGlobal): (JSC::WebAssemblyGlobalConstructor::create): (JSC::WebAssemblyGlobalConstructor::createStructure): (JSC::WebAssemblyGlobalConstructor::finishCreation): (JSC::WebAssemblyGlobalConstructor::WebAssemblyGlobalConstructor): * wasm/js/WebAssemblyGlobalConstructor.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/WebAssemblyGlobalPrototype.cpp: Added. (JSC::getGlobal): (JSC::webAssemblyGlobalProtoFuncValueOf): (JSC::webAssemblyGlobalProtoGetterFuncValue): (JSC::webAssemblyGlobalProtoSetterFuncValue): (JSC::WebAssemblyGlobalPrototype::create): (JSC::WebAssemblyGlobalPrototype::createStructure): (JSC::WebAssemblyGlobalPrototype::finishCreation): (JSC::WebAssemblyGlobalPrototype::WebAssemblyGlobalPrototype): * wasm/js/WebAssemblyGlobalPrototype.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): Canonical link: https://commits.webkit.org/218038@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@253074 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-12-04 01:36:56 +00:00
int32_t loadI32Global(unsigned i) const
{
Global::Value* slot = m_globals.get() + i;
if (m_globalsToBinding.get(i)) {
slot = slot->m_pointer;
if (!slot)
return 0;
}
return slot->m_primitive;
}
int64_t loadI64Global(unsigned i) const
{
Global::Value* slot = m_globals.get() + i;
if (m_globalsToBinding.get(i)) {
slot = slot->m_pointer;
if (!slot)
return 0;
}
return slot->m_primitive;
}
WebAssembly: no VM / JS version of everything but Instance https://bugs.webkit.org/show_bug.cgi?id=177473 Reviewed by Filip Pizlo, Saam Barati. JSTests: - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. * wasm/js-api/memory-grow.js: (assertEq): * wasm/js-api/table.js: (assert.throws): Source/JavaScriptCore: This change entails cleaning up and splitting a bunch of code which we had intertwined between C++ classes which represent JS objects, and pure C++ implementation objects. This specific change goes most of the way towards allowing JSC's WebAssembly to work without VM / JS, up to but excluding JSWebAssemblyInstance (there's Wasm::Instance, but it's not *the* thing yet). Because of this we still have a few FIXME identifying places that need to change. A follow-up change will go the rest of the way. I went about this change in the simplest way possible: grep the JavaScriptCore/wasm directory for "JS[^C_]" as well as "VM" and exclude the /js/ sub-directory (which contains the JS implementation of WebAssembly). None of this change removes the need for a JIT entitlement to be able to use WebAssembly. We don't have an interpreter, the process therefore still needs to be allowed to JIT to use these pure-C++ APIs. Interesting things to note: - Remove VM from Plan and associated places. It can just live as a capture in the callback lambda if it's needed. - Wasm::Memory shouldn't require a VM. It was only used to ask the GC to collect. We now instead pass two lambdas at construction time for this purpose: one to notify of memory pressure, and the other to ask for syncrhonous memory reclamation. This allows whoever creates the memory to dictate how to react to both these cases, and for a JS embedding that's to call the GC (async or sync, respectively). - Move grow logic from JSWebAssemblyMemory to Wasm::Memory::grow. Use Expected there, with an enum class for failure types. - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. - When generating the grow_memory opcode, no need to get the VM. Instead, reach directly for Wasm::Memory and grow it. - JSWebAssemblyMemory::grow can now always throw on failure, because it's only ever called from JS (not from grow_memory as before). - Wasm::Memory now takes a callback for successful growth. This allows JS wrappers to register themselves when growth succeeds without Wasm::Memory knowning anything about JS. It'll also allow creating a list of callbacks for when we add thread support (we'll want to notify many wrappers, all under a lock). - Wasm::Memory is now back to being the source of truth about address / size, used directly by generated code instead of JSWebAssemblyMemory. - Move wasmToJS from the general WasmBinding header to its own header under wasm/js. It's only used by wasm/js/JSWebAssemblyCodeBlock.cpp, and uses VM, and therefore isn't general WebAssembly. - Make Wasm::Context an actual type (just a struct holding a JSWebAssemlyInstance for now) instead of an alias for that. Notably this doesn't add anything to the Context and doesn't change what actually gets passed around in JIT code (fast TLS or registers) because these changes potentially impact performance. The entire purpose of this change is to allow passing Wasm::Context around without having to know about VM. Since VM contains a Wasm::Context the JS embedding is effectively the same, but with this setup a non-JS embedding is much better off. - Move JSWebAssembly into the JS folder. - OMGPlan: use Wasm::CodeBlock directly instead of JSWebAssemblyCodeBlock. - wasm->JS stubs are now on the instance's tail as raw pointers, instead of being on JSWebAssemblyCodeBlock, and are now called wasm->Embedder stubs. The owned reference is still on JSWebAssemblyCodeBlock, and is still called wasm->JS stub. This move means that the embedder must, after creating a Wasm::CodeBlock, somehow create the stubs to call back into the embedder. This removes an indirection in the generated code because the B3 IR generator now reaches into the instance instead of JSWebAssemblyCodeBlock. - Move more CodeBlock things. Compilation completion is now marked by its own atomic<bool> flag instead of a nullptr plan: that required using a lock, and was causing a deadlock in stack-trace.js because before my changes JSWebAssemblyCodeBlock did its own completion checking separately from Wasm::CodeBlock, without getting the lock. Now that everything points to Wasm::CodeBlock and there's no cached completion marker, the lock was being acquired in a sanity-check assertion. - Embedder -> Wasm wrappers are now generated through a function that's passed in at compilation time, instead of being hard-coded as a JS -> Wasm wrapper. - WasmMemory doens't need to know about fault handling thunks. Only the IR generator should know, and should make sure that the exception throwing thunk is generated if any memory is present (note: with signal handling not all of them generate an exception check). - Make exception throwing pluggable: instead of having a hard-coded JS-specific lambda we now have a regular C++ function being called from JIT code when a WebAssembly exception is thrown. This allows any embedder to get called as they wish. For now a process can only have a single of these functions (i.e. only one embedder per process) because the trap handler is a singleton. That can be fixed in in #177475. - Create WasmEmbedder.h where all embedder plugging will live. - Split up JSWebAssemblyTable into Wasm::Table which is refcounted. JSWebAssemblyTable now only contains the JS functions in the table, and Wasm::Table is what's used by the JIT code to lookup where to call and do the instance check (for context switch). Note that this creates an extra allocation for all the instances in Wasm::Table, and in exchange removes an indirection in JIT code because the instance used to be obtained off of the JS function. Also note that it's the embedder than keeps the instances alive, not Wasm::Table (which holds a dumb pointer to the instance), because doing otherwise would cause reference cycles. - Add WasmInstance. It doesn't do much for now, owns globals. - JSWebAssembly instance now doesn't just contain the imported functions as JSObjects, it also has the corresponding import's instance and wasm entrypoint. This triples the space allocated per instance's imported function, but there shouldn't be that many imports. This has two upsides: it creates smaller and faster code, and makes is easier to disassociate embedder-specific things from embedder-neutral things. The small / faster win is in two places: B3 IR generator only needs offsetOfImportFunction for the call opcode (when the called index is an import) to know whether the import is wasm->wasm or wasm->embedder (this isn't known at compile-time because it's dependent on the import object), this is now done by seeing if that import function has an associated target instance (only wasm->wasm does); the other place is wasmBinding which uses offsetOfImportFunction to figure out the wasm->wasm target instance, and then gets WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation to do a tail call. The disassociation comes because the target instance can be Wasm::Instance once we change what the Context is, and WasmEntrypointLoadLocation is already embedder-independent. As a next step I can move this tail allocation from JSWebAssemblyInstance to Wasm::Instance, and leave importFunction in as an opaque pointer which is embedder-specific, and in JS will remain WriteBarrier<JSObject>. - Rename VMEntryFrame to EntryFrame, and in many places pass a pointer to it around instead of VM. This is a first step in allowing entry frames which aren't stored on VM, but which are instead stored in an embedder-specific location. That change won't really affect JS except through code churn, but will allow WebAssembly to use some machinery in a generic manner without having a VM. * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * debugger/Debugger.cpp: (JSC::Debugger::stepOutOfFunction): (JSC::Debugger::returnEvent): (JSC::Debugger::unwindEvent): (JSC::Debugger::didExecuteProgram): * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::compileExceptionHandlers): * dfg/DFGOSREntry.cpp: (JSC::DFG::prepareOSREntry): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::compileOSRExit): (JSC::DFG::OSRExit::compileExit): * dfg/DFGThunks.cpp: (JSC::DFG::osrEntryThunkGenerator): * ftl/FTLCompile.cpp: (JSC::FTL::compile): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::lower): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): (JSC::CallFrame::callerFrame): (JSC::CallFrame::unsafeCallerFrame): * interpreter/CallFrame.h: (JSC::ExecState::callerFrame const): (JSC::ExecState::callerFrameOrEntryFrame const): (JSC::ExecState::unsafeCallerFrameOrEntryFrame const): * interpreter/FrameTracers.h: (JSC::NativeCallFrameTracer::NativeCallFrameTracer): (JSC::NativeCallFrameTracerWithRestore::NativeCallFrameTracerWithRestore): (JSC::NativeCallFrameTracerWithRestore::~NativeCallFrameTracerWithRestore): * interpreter/Interpreter.cpp: (JSC::UnwindFunctor::operator() const): (JSC::UnwindFunctor::copyCalleeSavesToEntryFrameCalleeSavesBuffer const): (JSC::Interpreter::unwind): * interpreter/StackVisitor.cpp: (JSC::StackVisitor::StackVisitor): (JSC::StackVisitor::gotoNextFrame): (JSC::StackVisitor::readNonInlinedFrame): (JSC::StackVisitor::Frame::dump const): * interpreter/StackVisitor.h: (JSC::StackVisitor::Frame::callerIsEntryFrame const): * interpreter/VMEntryRecord.h: (JSC::VMEntryRecord::prevTopEntryFrame): (JSC::VMEntryRecord::unsafePrevTopEntryFrame): (JSC::EntryFrame::vmEntryRecordOffset): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::restoreCalleeSavesFromEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::loadWasmContextInstance): (JSC::AssemblyHelpers::storeWasmContextInstance): (JSC::AssemblyHelpers::loadWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::storeWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBufferImpl): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::copyCalleeSavesToVMEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer): * jit/JIT.cpp: (JSC::JIT::emitEnterOptimizationCheck): (JSC::JIT::privateCompileExceptionHandlers): * jit/JITExceptions.cpp: (JSC::genericUnwind): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): (JSC::JIT::emitSlow_op_loop_hint): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): * jit/JITOperations.cpp: * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::nativeForGenerator): * jsc.cpp: (functionDumpCallFrame): * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LLIntThunks.cpp: (JSC::vmEntryRecord): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/Options.cpp: (JSC::recomputeDependentOptions): * runtime/Options.h: * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::FrameWalker): (JSC::FrameWalker::advanceToParentFrame): (JSC::SamplingProfiler::processUnverifiedStackTraces): * runtime/ThrowScope.cpp: (JSC::ThrowScope::~ThrowScope): * runtime/VM.cpp: (JSC::VM::VM): (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::topEntryFrameOffset): * runtime/VMTraps.cpp: (JSC::isSaneFrame): (JSC::VMTraps::tryInstallTrapBreakpoints): (JSC::VMTraps::invalidateCodeBlocksOnStack): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWasmContextInstance): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::parseAndCompile): * wasm/WasmB3IRGenerator.h: * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::BBQPlan): (JSC::Wasm::BBQPlan::compileFunctions): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBBQPlanInlines.h: (JSC::Wasm::BBQPlan::initializeCallees): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmBinding.h: * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::create): (JSC::Wasm::CodeBlock::CodeBlock): (JSC::Wasm::CodeBlock::compileAsync): (JSC::Wasm::CodeBlock::setCompilationFinished): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::offsetOfImportStubs): (JSC::Wasm::CodeBlock::allocationSize): (JSC::Wasm::CodeBlock::importWasmToEmbedderStub): (JSC::Wasm::CodeBlock::offsetOfImportWasmToEmbedderStub): (JSC::Wasm::CodeBlock::wasmToJSCallStubForImport): (JSC::Wasm::CodeBlock::compilationFinished): (JSC::Wasm::CodeBlock::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): * wasm/WasmContext.cpp: (JSC::Wasm::Context::useFastTLS): (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: Copied from Source/JavaScriptCore/wasm/WasmContext.h. * wasm/WasmFaultSignalHandler.cpp: * wasm/WasmFaultSignalHandler.h: * wasm/WasmFormat.h: * wasm/WasmInstance.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::~Instance): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: Added. (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::module): (JSC::Wasm::Instance::codeBlock): (JSC::Wasm::Instance::memory): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::loadF32Global const): (JSC::Wasm::Instance::loadF64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::offsetOfCachedStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::~Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::offsetOfSize): * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationCallback): (JSC::Wasm::Module::validateSync): (JSC::Wasm::Module::validateAsync): (JSC::Wasm::Module::getOrCreateCodeBlock): (JSC::Wasm::Module::compileSync): (JSC::Wasm::Module::compileAsync): * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseTableHelper): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::OMGPlan): (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::isValid const): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::runCompletionTasks): (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmPlan.h: (JSC::Wasm::Plan::dontFinalize): * wasm/WasmSignature.cpp: * wasm/WasmSignature.h: * wasm/WasmTable.cpp: Added. (JSC::Wasm::Table::create): (JSC::Wasm::Table::~Table): (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h. (JSC::Wasm::Table::maximum const): (JSC::Wasm::Table::size const): (JSC::Wasm::Table::offsetOfSize): (JSC::Wasm::Table::offsetOfFunctions): (JSC::Wasm::Table::offsetOfInstances): (JSC::Wasm::Table::isValidSize): * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): (JSC::Wasm::Thunks::setThrowWasmException): (JSC::Wasm::Thunks::throwWasmException): * wasm/WasmThunks.h: * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::stopAllPlansForContext): * wasm/WasmWorklist.h: * wasm/js/JSToWasm.cpp: Added. (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/JSWebAssembly.cpp: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.cpp. * wasm/js/JSWebAssembly.h: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.h. * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::create): (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::context const): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::webAssemblyToJSCallee): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::offsetOfTail): (JSC::JSWebAssemblyInstance::importFunctionInfo): (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): (JSC::JSWebAssemblyInstance::offsetOfImportFunction): (JSC::JSWebAssemblyInstance::importFunction): (JSC::JSWebAssemblyInstance::internalMemory): (JSC::JSWebAssemblyInstance::wasmCodeBlock const): (JSC::JSWebAssemblyInstance::offsetOfWasmTable): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::offsetOfGlobals): (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): (JSC::JSWebAssemblyInstance::cachedStackLimit const): (JSC::JSWebAssemblyInstance::setCachedStackLimit): (JSC::JSWebAssemblyInstance::wasmMemory): (JSC::JSWebAssemblyInstance::wasmModule): (JSC::JSWebAssemblyInstance::allocationSize): (JSC::JSWebAssemblyInstance::module const): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::create): (JSC::JSWebAssemblyMemory::adopt): (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::moduleInformation const): (JSC::JSWebAssemblyModule::exportSymbolTable const): (JSC::JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace const): (JSC::JSWebAssemblyModule::callee const): (JSC::JSWebAssemblyModule::codeBlock): (JSC::JSWebAssemblyModule::module): * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::create): (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::visitChildren): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::getFunction): (JSC::JSWebAssemblyTable::clearFunction): (JSC::JSWebAssemblyTable::setFunction): * wasm/js/JSWebAssemblyTable.h: (JSC::JSWebAssemblyTable::isValidSize): (JSC::JSWebAssemblyTable::maximum const): (JSC::JSWebAssemblyTable::size const): (JSC::JSWebAssemblyTable::table): * wasm/js/WasmToJS.cpp: Copied from Source/JavaScriptCore/wasm/WasmBinding.cpp. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): (JSC::WebAssemblyModuleConstructor::createModule): * wasm/js/WebAssemblyModuleConstructor.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::webAssemblyCompileFunc): (JSC::instantiate): (JSC::compileAndInstantiate): (JSC::webAssemblyValidateFunc): * wasm/js/WebAssemblyTableConstructor.cpp: (JSC::constructJSWebAssemblyTable): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Source/WebCore: * ForwardingHeaders/wasm/WasmModule.h: Added. This used to be included in JSWebAssemblyModule.h. * bindings/js/SerializedScriptValue.cpp: Update postMessage code according to C++ API changes. Canonical link: https://commits.webkit.org/194750@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223738 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-20 02:23:29 +00:00
float loadF32Global(unsigned i) const { return bitwise_cast<float>(loadI32Global(i)); }
double loadF64Global(unsigned i) const { return bitwise_cast<double>(loadI64Global(i)); }
Adopt the new WebAssembly.Global system https://bugs.webkit.org/show_bug.cgi?id=186552 Reviewed by Keith Miller. JSTests: 1. Update spec-harness to accept newer tests. And we update several tests that does not work with the old harness. 2. Add WebAssembly.Global tests. * wasm/js-api/global-error.js: (assert.throws.new.WebAssembly.Module.bin): (new.WebAssembly.Module): (assert.throws): * wasm/js-api/global-external-init-from-import.js: * wasm/js-api/globals-export.js: * wasm/modules/js-wasm-global-namespace.js: (assert.throws): * wasm/modules/js-wasm-global.js: (assert.throws): * wasm/modules/wasm-import-wasm-export-i64-error.js: * wasm/references/anyref_globals.js: * wasm/references/func_ref.js: (assert.eq.instance.exports.fix): * wasm/spec-harness.js: (getGlobal): (let.console.log): * wasm/spec-harness/sync_index.js: Renamed from JSTests/wasm/spec-harness/index.js. (reinitializeRegistry.let.handler.get return): (module): * wasm/spec-tests/call.wast.js: * wasm/spec-tests/exports.wast.js: * wasm/spec-tests/globals.wast.js: * wasm/spec-tests/if.wast.js: * wasm/spec-tests/imports.wast.js: * wasm/spec-tests/linking.wast.js: * wasm/spec-tests/memory.wast.js: * wasm/stress/immutable-globals.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.assert.eq.instance.exports.getI32): (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.assert.eq): * wasm/stress/mutable-globals-cross.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.const.instance1): (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.const.instance2): * wasm/stress/mutable-globals.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.instance.exports.setI32AsI64): LayoutTests/imported/w3c: * web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any-expected.txt: * web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/constructor.any-expected.txt: * web-platform-tests/wasm/jsapi/global/constructor.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/toString.any-expected.txt: * web-platform-tests/wasm/jsapi/global/toString.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/value-set.any-expected.txt: * web-platform-tests/wasm/jsapi/global/value-set.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/valueOf.any-expected.txt: * web-platform-tests/wasm/jsapi/global/valueOf.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor.any-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/interface.any-expected.txt: * web-platform-tests/wasm/jsapi/interface.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/module/exports.any-expected.txt: * web-platform-tests/wasm/jsapi/module/exports.any.worker-expected.txt: Source/JavaScriptCore: This patch adds WebAssembly.Global implementation. It is already included in the Wasm spec (this means, it is not in staging right now: it was stage-4, and included in the spec). WebAssembly.Global is a wrapper object around "global" binding. This object can hold "immutable" and "mutable" global binding, and we can access Wasm globals through this object. Furthermore, we can share mutable global binding through this object across WebAssembly modules. To implement it efficiently, this patch introduces BindingMode to Wasm globals. If the mode is EmbeddedInInstance, we continue using the current existing mechanism. If the mode is Portable, we store a pointer to actual value in Wasm globals array in Wasm::Instance, so that we can access it through one additional dereference. And we mark all immutable globals as EmbeddedInInstance. If the binding is immutable, internally we do not need to have one binding. We can just continue using the current mechanism since users cannot observe whether immutable bindings' storage is shared or not. If the global is mutable, and it is exported outside of the module, we use Portable mode. So, all the previously used wasm global bindings are EmbeddedInInstance. Only newly added "mutable" "exported" bindings are Portable and requires one additional dereference. To access portable bindings efficiently, we add new Wasm bytecodes, `get_global_portable_binding`, `set_global_portable_binding`, and `set_global_ref_portable_binding`. This patch improves WPT wasm coverage significantly. * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/BytecodeList.rb: * heap/HeapCell.cpp: (JSC::keepAlive): (JSC::HeapCell::use const): Deleted. * heap/HeapCell.h: (JSC::keepAlive): (JSC::HeapCell::use const): * llint/WebAssembly.asm: * runtime/JSGlobalObject.cpp: * runtime/JSGlobalObject.h: * runtime/VM.cpp: (JSC::VM::VM): * runtime/VM.h: * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::getGlobal): (JSC::Wasm::AirIRGenerator::setGlobal): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::getGlobal): (JSC::Wasm::B3IRGenerator::setGlobal): * wasm/WasmFormat.h: * wasm/WasmGlobal.cpp: Added. (JSC::Wasm::Global::get const): (JSC::Wasm::Global::set): (JSC::Wasm::Global::visitAggregate): * wasm/WasmGlobal.h: Added. * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::linkGlobal): * wasm/WasmInstance.h: (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::globalsToBinding): (JSC::Wasm::Instance::getGlobalBinding): * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::getGlobal): (JSC::Wasm::LLIntGenerator::setGlobal): * wasm/WasmModuleInformation.h: * wasm/WasmOperations.cpp: (JSC::Wasm::operationWasmWriteBarrierSlowPath): * wasm/WasmOperations.h: * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseImport): (JSC::Wasm::SectionParser::parseGlobal): (JSC::Wasm::SectionParser::parseExport): (JSC::Wasm::SectionParser::parseInitExpr): (JSC::Wasm::SectionParser::parseGlobalType): * wasm/WasmSectionParser.h: * wasm/WasmSlowPaths.cpp: (JSC::LLInt::WASM_SLOW_PATH_DECL): * wasm/WasmSlowPaths.h: * wasm/WasmValidate.cpp: (JSC::Wasm::Validate::setGlobal): * wasm/js/JSWebAssembly.cpp: * wasm/js/JSWebAssemblyGlobal.cpp: Added. (JSC::JSWebAssemblyGlobal::create): (JSC::JSWebAssemblyGlobal::createStructure): (JSC::JSWebAssemblyGlobal::JSWebAssemblyGlobal): (JSC::JSWebAssemblyGlobal::finishCreation): (JSC::JSWebAssemblyGlobal::destroy): (JSC::JSWebAssemblyGlobal::visitChildren): * wasm/js/JSWebAssemblyGlobal.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/JSWebAssemblyInstance.h: * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::destroy): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.h: * wasm/js/WebAssemblyGlobalConstructor.cpp: Added. (JSC::constructJSWebAssemblyGlobal): (JSC::callJSWebAssemblyGlobal): (JSC::WebAssemblyGlobalConstructor::create): (JSC::WebAssemblyGlobalConstructor::createStructure): (JSC::WebAssemblyGlobalConstructor::finishCreation): (JSC::WebAssemblyGlobalConstructor::WebAssemblyGlobalConstructor): * wasm/js/WebAssemblyGlobalConstructor.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/WebAssemblyGlobalPrototype.cpp: Added. (JSC::getGlobal): (JSC::webAssemblyGlobalProtoFuncValueOf): (JSC::webAssemblyGlobalProtoGetterFuncValue): (JSC::webAssemblyGlobalProtoSetterFuncValue): (JSC::WebAssemblyGlobalPrototype::create): (JSC::WebAssemblyGlobalPrototype::createStructure): (JSC::WebAssemblyGlobalPrototype::finishCreation): (JSC::WebAssemblyGlobalPrototype::WebAssemblyGlobalPrototype): * wasm/js/WebAssemblyGlobalPrototype.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): Canonical link: https://commits.webkit.org/218038@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@253074 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-12-04 01:36:56 +00:00
void setGlobal(unsigned i, int64_t bits)
{
Global::Value* slot = m_globals.get() + i;
if (m_globalsToBinding.get(i)) {
slot = slot->m_pointer;
if (!slot)
return;
}
slot->m_primitive = bits;
}
[WASM-References] Support Anyref in globals https://bugs.webkit.org/show_bug.cgi?id=198102 Reviewed by Saam Barati. JSTests: Add test for anyrefs in globals, as well as adding a new RefNull initExpr for Builder. * wasm/Builder.js: (export.default.Builder.prototype._registerSectionBuilders.const.section.in.WASM.description.section.switch.section.case.string_appeared_here.this.section): * wasm/Builder_WebAssemblyBinary.js: (const.putInitExpr): * wasm/references/anyref_globals.js: Added. (GetGlobal.0.End.End.WebAssembly): (5.doGCSet): (doGCTest): (doGCSet.doGCTest.let.count.0.doBarrierSet): Source/JavaScriptCore: Support anyref for globals, imports and exports. This adds code in B3 and Air to emit a write barrier on the JSWebAssemblyWrapper whenever an anyref global is set. This also fixes a small bug in emitCCall for air where it adds code to the wrong block. * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::emitCCall): (JSC::Wasm::AirIRGenerator::moveOpForValueType): (JSC::Wasm::AirIRGenerator::setGlobal): (JSC::Wasm::AirIRGenerator::emitWriteBarrierForJSWrapper): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::setGlobal): (JSC::Wasm::B3IRGenerator::emitWriteBarrierForJSWrapper): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::setGlobal): * wasm/WasmInstance.h: (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::shouldMarkGlobal): (JSC::Wasm::Instance::numGlobals const): * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseInitExpr): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): Canonical link: https://commits.webkit.org/212290@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245765 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-25 00:51:21 +00:00
void setGlobal(unsigned, JSValue);
Adopt the new WebAssembly.Global system https://bugs.webkit.org/show_bug.cgi?id=186552 Reviewed by Keith Miller. JSTests: 1. Update spec-harness to accept newer tests. And we update several tests that does not work with the old harness. 2. Add WebAssembly.Global tests. * wasm/js-api/global-error.js: (assert.throws.new.WebAssembly.Module.bin): (new.WebAssembly.Module): (assert.throws): * wasm/js-api/global-external-init-from-import.js: * wasm/js-api/globals-export.js: * wasm/modules/js-wasm-global-namespace.js: (assert.throws): * wasm/modules/js-wasm-global.js: (assert.throws): * wasm/modules/wasm-import-wasm-export-i64-error.js: * wasm/references/anyref_globals.js: * wasm/references/func_ref.js: (assert.eq.instance.exports.fix): * wasm/spec-harness.js: (getGlobal): (let.console.log): * wasm/spec-harness/sync_index.js: Renamed from JSTests/wasm/spec-harness/index.js. (reinitializeRegistry.let.handler.get return): (module): * wasm/spec-tests/call.wast.js: * wasm/spec-tests/exports.wast.js: * wasm/spec-tests/globals.wast.js: * wasm/spec-tests/if.wast.js: * wasm/spec-tests/imports.wast.js: * wasm/spec-tests/linking.wast.js: * wasm/spec-tests/memory.wast.js: * wasm/stress/immutable-globals.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.assert.eq.instance.exports.getI32): (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.assert.eq): * wasm/stress/mutable-globals-cross.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.const.instance1): (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.const.instance2): * wasm/stress/mutable-globals.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.instance.exports.setI32AsI64): LayoutTests/imported/w3c: * web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any-expected.txt: * web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/constructor.any-expected.txt: * web-platform-tests/wasm/jsapi/global/constructor.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/toString.any-expected.txt: * web-platform-tests/wasm/jsapi/global/toString.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/value-set.any-expected.txt: * web-platform-tests/wasm/jsapi/global/value-set.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/valueOf.any-expected.txt: * web-platform-tests/wasm/jsapi/global/valueOf.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor.any-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/interface.any-expected.txt: * web-platform-tests/wasm/jsapi/interface.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/module/exports.any-expected.txt: * web-platform-tests/wasm/jsapi/module/exports.any.worker-expected.txt: Source/JavaScriptCore: This patch adds WebAssembly.Global implementation. It is already included in the Wasm spec (this means, it is not in staging right now: it was stage-4, and included in the spec). WebAssembly.Global is a wrapper object around "global" binding. This object can hold "immutable" and "mutable" global binding, and we can access Wasm globals through this object. Furthermore, we can share mutable global binding through this object across WebAssembly modules. To implement it efficiently, this patch introduces BindingMode to Wasm globals. If the mode is EmbeddedInInstance, we continue using the current existing mechanism. If the mode is Portable, we store a pointer to actual value in Wasm globals array in Wasm::Instance, so that we can access it through one additional dereference. And we mark all immutable globals as EmbeddedInInstance. If the binding is immutable, internally we do not need to have one binding. We can just continue using the current mechanism since users cannot observe whether immutable bindings' storage is shared or not. If the global is mutable, and it is exported outside of the module, we use Portable mode. So, all the previously used wasm global bindings are EmbeddedInInstance. Only newly added "mutable" "exported" bindings are Portable and requires one additional dereference. To access portable bindings efficiently, we add new Wasm bytecodes, `get_global_portable_binding`, `set_global_portable_binding`, and `set_global_ref_portable_binding`. This patch improves WPT wasm coverage significantly. * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/BytecodeList.rb: * heap/HeapCell.cpp: (JSC::keepAlive): (JSC::HeapCell::use const): Deleted. * heap/HeapCell.h: (JSC::keepAlive): (JSC::HeapCell::use const): * llint/WebAssembly.asm: * runtime/JSGlobalObject.cpp: * runtime/JSGlobalObject.h: * runtime/VM.cpp: (JSC::VM::VM): * runtime/VM.h: * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::getGlobal): (JSC::Wasm::AirIRGenerator::setGlobal): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::getGlobal): (JSC::Wasm::B3IRGenerator::setGlobal): * wasm/WasmFormat.h: * wasm/WasmGlobal.cpp: Added. (JSC::Wasm::Global::get const): (JSC::Wasm::Global::set): (JSC::Wasm::Global::visitAggregate): * wasm/WasmGlobal.h: Added. * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::linkGlobal): * wasm/WasmInstance.h: (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::globalsToBinding): (JSC::Wasm::Instance::getGlobalBinding): * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::getGlobal): (JSC::Wasm::LLIntGenerator::setGlobal): * wasm/WasmModuleInformation.h: * wasm/WasmOperations.cpp: (JSC::Wasm::operationWasmWriteBarrierSlowPath): * wasm/WasmOperations.h: * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseImport): (JSC::Wasm::SectionParser::parseGlobal): (JSC::Wasm::SectionParser::parseExport): (JSC::Wasm::SectionParser::parseInitExpr): (JSC::Wasm::SectionParser::parseGlobalType): * wasm/WasmSectionParser.h: * wasm/WasmSlowPaths.cpp: (JSC::LLInt::WASM_SLOW_PATH_DECL): * wasm/WasmSlowPaths.h: * wasm/WasmValidate.cpp: (JSC::Wasm::Validate::setGlobal): * wasm/js/JSWebAssembly.cpp: * wasm/js/JSWebAssemblyGlobal.cpp: Added. (JSC::JSWebAssemblyGlobal::create): (JSC::JSWebAssemblyGlobal::createStructure): (JSC::JSWebAssemblyGlobal::JSWebAssemblyGlobal): (JSC::JSWebAssemblyGlobal::finishCreation): (JSC::JSWebAssemblyGlobal::destroy): (JSC::JSWebAssemblyGlobal::visitChildren): * wasm/js/JSWebAssemblyGlobal.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/JSWebAssemblyInstance.h: * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::destroy): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.h: * wasm/js/WebAssemblyGlobalConstructor.cpp: Added. (JSC::constructJSWebAssemblyGlobal): (JSC::callJSWebAssemblyGlobal): (JSC::WebAssemblyGlobalConstructor::create): (JSC::WebAssemblyGlobalConstructor::createStructure): (JSC::WebAssemblyGlobalConstructor::finishCreation): (JSC::WebAssemblyGlobalConstructor::WebAssemblyGlobalConstructor): * wasm/js/WebAssemblyGlobalConstructor.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/WebAssemblyGlobalPrototype.cpp: Added. (JSC::getGlobal): (JSC::webAssemblyGlobalProtoFuncValueOf): (JSC::webAssemblyGlobalProtoGetterFuncValue): (JSC::webAssemblyGlobalProtoSetterFuncValue): (JSC::WebAssemblyGlobalPrototype::create): (JSC::WebAssemblyGlobalPrototype::createStructure): (JSC::WebAssemblyGlobalPrototype::finishCreation): (JSC::WebAssemblyGlobalPrototype::WebAssemblyGlobalPrototype): * wasm/js/WebAssemblyGlobalPrototype.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): Canonical link: https://commits.webkit.org/218038@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@253074 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-12-04 01:36:56 +00:00
void linkGlobal(unsigned, Ref<Global>&&);
[WASM-References] Support Anyref in globals https://bugs.webkit.org/show_bug.cgi?id=198102 Reviewed by Saam Barati. JSTests: Add test for anyrefs in globals, as well as adding a new RefNull initExpr for Builder. * wasm/Builder.js: (export.default.Builder.prototype._registerSectionBuilders.const.section.in.WASM.description.section.switch.section.case.string_appeared_here.this.section): * wasm/Builder_WebAssemblyBinary.js: (const.putInitExpr): * wasm/references/anyref_globals.js: Added. (GetGlobal.0.End.End.WebAssembly): (5.doGCSet): (doGCTest): (doGCSet.doGCTest.let.count.0.doBarrierSet): Source/JavaScriptCore: Support anyref for globals, imports and exports. This adds code in B3 and Air to emit a write barrier on the JSWebAssemblyWrapper whenever an anyref global is set. This also fixes a small bug in emitCCall for air where it adds code to the wrong block. * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::emitCCall): (JSC::Wasm::AirIRGenerator::moveOpForValueType): (JSC::Wasm::AirIRGenerator::setGlobal): (JSC::Wasm::AirIRGenerator::emitWriteBarrierForJSWrapper): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::setGlobal): (JSC::Wasm::B3IRGenerator::emitWriteBarrierForJSWrapper): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::setGlobal): * wasm/WasmInstance.h: (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::shouldMarkGlobal): (JSC::Wasm::Instance::numGlobals const): * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseInitExpr): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): Canonical link: https://commits.webkit.org/212290@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245765 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-25 00:51:21 +00:00
const BitVector& globalsToMark() { return m_globalsToMark; }
Adopt the new WebAssembly.Global system https://bugs.webkit.org/show_bug.cgi?id=186552 Reviewed by Keith Miller. JSTests: 1. Update spec-harness to accept newer tests. And we update several tests that does not work with the old harness. 2. Add WebAssembly.Global tests. * wasm/js-api/global-error.js: (assert.throws.new.WebAssembly.Module.bin): (new.WebAssembly.Module): (assert.throws): * wasm/js-api/global-external-init-from-import.js: * wasm/js-api/globals-export.js: * wasm/modules/js-wasm-global-namespace.js: (assert.throws): * wasm/modules/js-wasm-global.js: (assert.throws): * wasm/modules/wasm-import-wasm-export-i64-error.js: * wasm/references/anyref_globals.js: * wasm/references/func_ref.js: (assert.eq.instance.exports.fix): * wasm/spec-harness.js: (getGlobal): (let.console.log): * wasm/spec-harness/sync_index.js: Renamed from JSTests/wasm/spec-harness/index.js. (reinitializeRegistry.let.handler.get return): (module): * wasm/spec-tests/call.wast.js: * wasm/spec-tests/exports.wast.js: * wasm/spec-tests/globals.wast.js: * wasm/spec-tests/if.wast.js: * wasm/spec-tests/imports.wast.js: * wasm/spec-tests/linking.wast.js: * wasm/spec-tests/memory.wast.js: * wasm/stress/immutable-globals.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.assert.eq.instance.exports.getI32): (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.assert.eq): * wasm/stress/mutable-globals-cross.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.const.instance1): (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.const.instance2): * wasm/stress/mutable-globals.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.instance.exports.setI32AsI64): LayoutTests/imported/w3c: * web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any-expected.txt: * web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/constructor.any-expected.txt: * web-platform-tests/wasm/jsapi/global/constructor.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/toString.any-expected.txt: * web-platform-tests/wasm/jsapi/global/toString.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/value-set.any-expected.txt: * web-platform-tests/wasm/jsapi/global/value-set.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/valueOf.any-expected.txt: * web-platform-tests/wasm/jsapi/global/valueOf.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor.any-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/interface.any-expected.txt: * web-platform-tests/wasm/jsapi/interface.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/module/exports.any-expected.txt: * web-platform-tests/wasm/jsapi/module/exports.any.worker-expected.txt: Source/JavaScriptCore: This patch adds WebAssembly.Global implementation. It is already included in the Wasm spec (this means, it is not in staging right now: it was stage-4, and included in the spec). WebAssembly.Global is a wrapper object around "global" binding. This object can hold "immutable" and "mutable" global binding, and we can access Wasm globals through this object. Furthermore, we can share mutable global binding through this object across WebAssembly modules. To implement it efficiently, this patch introduces BindingMode to Wasm globals. If the mode is EmbeddedInInstance, we continue using the current existing mechanism. If the mode is Portable, we store a pointer to actual value in Wasm globals array in Wasm::Instance, so that we can access it through one additional dereference. And we mark all immutable globals as EmbeddedInInstance. If the binding is immutable, internally we do not need to have one binding. We can just continue using the current mechanism since users cannot observe whether immutable bindings' storage is shared or not. If the global is mutable, and it is exported outside of the module, we use Portable mode. So, all the previously used wasm global bindings are EmbeddedInInstance. Only newly added "mutable" "exported" bindings are Portable and requires one additional dereference. To access portable bindings efficiently, we add new Wasm bytecodes, `get_global_portable_binding`, `set_global_portable_binding`, and `set_global_ref_portable_binding`. This patch improves WPT wasm coverage significantly. * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/BytecodeList.rb: * heap/HeapCell.cpp: (JSC::keepAlive): (JSC::HeapCell::use const): Deleted. * heap/HeapCell.h: (JSC::keepAlive): (JSC::HeapCell::use const): * llint/WebAssembly.asm: * runtime/JSGlobalObject.cpp: * runtime/JSGlobalObject.h: * runtime/VM.cpp: (JSC::VM::VM): * runtime/VM.h: * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::getGlobal): (JSC::Wasm::AirIRGenerator::setGlobal): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::getGlobal): (JSC::Wasm::B3IRGenerator::setGlobal): * wasm/WasmFormat.h: * wasm/WasmGlobal.cpp: Added. (JSC::Wasm::Global::get const): (JSC::Wasm::Global::set): (JSC::Wasm::Global::visitAggregate): * wasm/WasmGlobal.h: Added. * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::linkGlobal): * wasm/WasmInstance.h: (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::globalsToBinding): (JSC::Wasm::Instance::getGlobalBinding): * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::getGlobal): (JSC::Wasm::LLIntGenerator::setGlobal): * wasm/WasmModuleInformation.h: * wasm/WasmOperations.cpp: (JSC::Wasm::operationWasmWriteBarrierSlowPath): * wasm/WasmOperations.h: * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseImport): (JSC::Wasm::SectionParser::parseGlobal): (JSC::Wasm::SectionParser::parseExport): (JSC::Wasm::SectionParser::parseInitExpr): (JSC::Wasm::SectionParser::parseGlobalType): * wasm/WasmSectionParser.h: * wasm/WasmSlowPaths.cpp: (JSC::LLInt::WASM_SLOW_PATH_DECL): * wasm/WasmSlowPaths.h: * wasm/WasmValidate.cpp: (JSC::Wasm::Validate::setGlobal): * wasm/js/JSWebAssembly.cpp: * wasm/js/JSWebAssemblyGlobal.cpp: Added. (JSC::JSWebAssemblyGlobal::create): (JSC::JSWebAssemblyGlobal::createStructure): (JSC::JSWebAssemblyGlobal::JSWebAssemblyGlobal): (JSC::JSWebAssemblyGlobal::finishCreation): (JSC::JSWebAssemblyGlobal::destroy): (JSC::JSWebAssemblyGlobal::visitChildren): * wasm/js/JSWebAssemblyGlobal.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/JSWebAssemblyInstance.h: * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::destroy): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.h: * wasm/js/WebAssemblyGlobalConstructor.cpp: Added. (JSC::constructJSWebAssemblyGlobal): (JSC::callJSWebAssemblyGlobal): (JSC::WebAssemblyGlobalConstructor::create): (JSC::WebAssemblyGlobalConstructor::createStructure): (JSC::WebAssemblyGlobalConstructor::finishCreation): (JSC::WebAssemblyGlobalConstructor::WebAssemblyGlobalConstructor): * wasm/js/WebAssemblyGlobalConstructor.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/WebAssemblyGlobalPrototype.cpp: Added. (JSC::getGlobal): (JSC::webAssemblyGlobalProtoFuncValueOf): (JSC::webAssemblyGlobalProtoGetterFuncValue): (JSC::webAssemblyGlobalProtoSetterFuncValue): (JSC::WebAssemblyGlobalPrototype::create): (JSC::WebAssemblyGlobalPrototype::createStructure): (JSC::WebAssemblyGlobalPrototype::finishCreation): (JSC::WebAssemblyGlobalPrototype::WebAssemblyGlobalPrototype): * wasm/js/WebAssemblyGlobalPrototype.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): Canonical link: https://commits.webkit.org/218038@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@253074 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-12-04 01:36:56 +00:00
const BitVector& globalsToBinding() { return m_globalsToBinding; }
[WASM-References] Add support for Funcref in parameters and return types https://bugs.webkit.org/show_bug.cgi?id=198157 Reviewed by Yusuke Suzuki. JSTests: * wasm/Builder.js: (export.default.Builder.prototype._registerSectionBuilders.const.section.in.WASM.description.section.switch.section.case.string_appeared_here.this.section): * wasm/references/anyref_globals.js: * wasm/references/func_ref.js: Added. (fullGC.gc.makeExportedFunction): (makeExportedIdent): (makeAnyfuncIdent): (fun): (assert.eq.instance.exports.fix.fun): (assert.eq.instance.exports.fix): (string_appeared_here.End.End.Function.End.Code.End.WebAssembly.imp.ref): (string_appeared_here.End.End.Function.End.Code.End.WebAssembly): (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly.fun): (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly.assert.throws): (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly): (assert.throws): (assert.throws.doTest): (let.importedFun.of): (makeAnyfuncIdent.fun): * wasm/references/validation.js: (assert.throws): * wasm/wasm.json: Source/JavaScriptCore: Add support for funcref in parameters, globals, and in table.get/set. When converting a JSValue to a funcref (nee anyfunc), we first make sure it is an exported wasm function or null. We also add support for Ref.func. Anywhere a Ref.func is used, (statically) we construct a JS wrapper for it so that we never need to construct JSValues when handling references. This should make threads easier to implement. Finally, we add some missing bounds checks for table.get/set. * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::tmpForType): (JSC::Wasm::AirIRGenerator::moveOpForValueType): (JSC::Wasm::AirIRGenerator::AirIRGenerator): (JSC::Wasm::AirIRGenerator::addLocal): (JSC::Wasm::AirIRGenerator::addConstant): (JSC::Wasm::AirIRGenerator::addRefFunc): (JSC::Wasm::AirIRGenerator::addTableSet): (JSC::Wasm::AirIRGenerator::setGlobal): (JSC::Wasm::AirIRGenerator::addReturn): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::addLocal): (JSC::Wasm::B3IRGenerator::addTableSet): (JSC::Wasm::B3IRGenerator::addRefFunc): (JSC::Wasm::B3IRGenerator::setGlobal): * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::compileFunctions): * wasm/WasmCallingConvention.h: (JSC::Wasm::CallingConventionAir::marshallArgument const): (JSC::Wasm::CallingConventionAir::setupCall const): * wasm/WasmExceptionType.h: * wasm/WasmFormat.h: (JSC::Wasm::isValueType): (JSC::Wasm::isSubtype): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parseExpression): (JSC::Wasm::FunctionParser<Context>::parseUnreachableExpression): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::getFunctionWrapper const): (JSC::Wasm::Instance::setFunctionWrapper): * wasm/WasmInstance.h: * wasm/WasmModuleInformation.h: (JSC::Wasm::ModuleInformation::referencedFunctions const): (JSC::Wasm::ModuleInformation::addReferencedFunction const): * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseGlobal): (JSC::Wasm::SectionParser::parseInitExpr): * wasm/WasmValidate.cpp: (JSC::Wasm::Validate::addTableGet): (JSC::Wasm::Validate::addTableSet): (JSC::Wasm::Validate::addRefIsNull): (JSC::Wasm::Validate::addRefFunc): (JSC::Wasm::Validate::setLocal): (JSC::Wasm::Validate::addCall): (JSC::Wasm::Validate::addCallIndirect): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyHelpers.h: (JSC::isWebAssemblyHostFunction): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/JSWebAssemblyRuntimeError.cpp: (JSC::createJSWebAssemblyRuntimeError): * wasm/js/JSWebAssemblyRuntimeError.h: * wasm/js/WasmToJS.cpp: (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): (JSC::Wasm::emitWasmToJSException): * wasm/js/WasmToJS.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): (JSC::WebAssemblyFunction::jsCallEntrypointSlow): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): * wasm/wasm.json: Canonical link: https://commits.webkit.org/212896@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@246504 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-06-17 18:44:18 +00:00
JSValue getFunctionWrapper(unsigned) const;
typename FunctionWrapperMap::ValuesConstIteratorRange functionWrappers() const { return m_functionWrappers.values(); }
void setFunctionWrapper(unsigned, JSValue);
WebAssembly: no VM / JS version of everything but Instance https://bugs.webkit.org/show_bug.cgi?id=177473 Reviewed by Filip Pizlo, Saam Barati. JSTests: - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. * wasm/js-api/memory-grow.js: (assertEq): * wasm/js-api/table.js: (assert.throws): Source/JavaScriptCore: This change entails cleaning up and splitting a bunch of code which we had intertwined between C++ classes which represent JS objects, and pure C++ implementation objects. This specific change goes most of the way towards allowing JSC's WebAssembly to work without VM / JS, up to but excluding JSWebAssemblyInstance (there's Wasm::Instance, but it's not *the* thing yet). Because of this we still have a few FIXME identifying places that need to change. A follow-up change will go the rest of the way. I went about this change in the simplest way possible: grep the JavaScriptCore/wasm directory for "JS[^C_]" as well as "VM" and exclude the /js/ sub-directory (which contains the JS implementation of WebAssembly). None of this change removes the need for a JIT entitlement to be able to use WebAssembly. We don't have an interpreter, the process therefore still needs to be allowed to JIT to use these pure-C++ APIs. Interesting things to note: - Remove VM from Plan and associated places. It can just live as a capture in the callback lambda if it's needed. - Wasm::Memory shouldn't require a VM. It was only used to ask the GC to collect. We now instead pass two lambdas at construction time for this purpose: one to notify of memory pressure, and the other to ask for syncrhonous memory reclamation. This allows whoever creates the memory to dictate how to react to both these cases, and for a JS embedding that's to call the GC (async or sync, respectively). - Move grow logic from JSWebAssemblyMemory to Wasm::Memory::grow. Use Expected there, with an enum class for failure types. - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. - When generating the grow_memory opcode, no need to get the VM. Instead, reach directly for Wasm::Memory and grow it. - JSWebAssemblyMemory::grow can now always throw on failure, because it's only ever called from JS (not from grow_memory as before). - Wasm::Memory now takes a callback for successful growth. This allows JS wrappers to register themselves when growth succeeds without Wasm::Memory knowning anything about JS. It'll also allow creating a list of callbacks for when we add thread support (we'll want to notify many wrappers, all under a lock). - Wasm::Memory is now back to being the source of truth about address / size, used directly by generated code instead of JSWebAssemblyMemory. - Move wasmToJS from the general WasmBinding header to its own header under wasm/js. It's only used by wasm/js/JSWebAssemblyCodeBlock.cpp, and uses VM, and therefore isn't general WebAssembly. - Make Wasm::Context an actual type (just a struct holding a JSWebAssemlyInstance for now) instead of an alias for that. Notably this doesn't add anything to the Context and doesn't change what actually gets passed around in JIT code (fast TLS or registers) because these changes potentially impact performance. The entire purpose of this change is to allow passing Wasm::Context around without having to know about VM. Since VM contains a Wasm::Context the JS embedding is effectively the same, but with this setup a non-JS embedding is much better off. - Move JSWebAssembly into the JS folder. - OMGPlan: use Wasm::CodeBlock directly instead of JSWebAssemblyCodeBlock. - wasm->JS stubs are now on the instance's tail as raw pointers, instead of being on JSWebAssemblyCodeBlock, and are now called wasm->Embedder stubs. The owned reference is still on JSWebAssemblyCodeBlock, and is still called wasm->JS stub. This move means that the embedder must, after creating a Wasm::CodeBlock, somehow create the stubs to call back into the embedder. This removes an indirection in the generated code because the B3 IR generator now reaches into the instance instead of JSWebAssemblyCodeBlock. - Move more CodeBlock things. Compilation completion is now marked by its own atomic<bool> flag instead of a nullptr plan: that required using a lock, and was causing a deadlock in stack-trace.js because before my changes JSWebAssemblyCodeBlock did its own completion checking separately from Wasm::CodeBlock, without getting the lock. Now that everything points to Wasm::CodeBlock and there's no cached completion marker, the lock was being acquired in a sanity-check assertion. - Embedder -> Wasm wrappers are now generated through a function that's passed in at compilation time, instead of being hard-coded as a JS -> Wasm wrapper. - WasmMemory doens't need to know about fault handling thunks. Only the IR generator should know, and should make sure that the exception throwing thunk is generated if any memory is present (note: with signal handling not all of them generate an exception check). - Make exception throwing pluggable: instead of having a hard-coded JS-specific lambda we now have a regular C++ function being called from JIT code when a WebAssembly exception is thrown. This allows any embedder to get called as they wish. For now a process can only have a single of these functions (i.e. only one embedder per process) because the trap handler is a singleton. That can be fixed in in #177475. - Create WasmEmbedder.h where all embedder plugging will live. - Split up JSWebAssemblyTable into Wasm::Table which is refcounted. JSWebAssemblyTable now only contains the JS functions in the table, and Wasm::Table is what's used by the JIT code to lookup where to call and do the instance check (for context switch). Note that this creates an extra allocation for all the instances in Wasm::Table, and in exchange removes an indirection in JIT code because the instance used to be obtained off of the JS function. Also note that it's the embedder than keeps the instances alive, not Wasm::Table (which holds a dumb pointer to the instance), because doing otherwise would cause reference cycles. - Add WasmInstance. It doesn't do much for now, owns globals. - JSWebAssembly instance now doesn't just contain the imported functions as JSObjects, it also has the corresponding import's instance and wasm entrypoint. This triples the space allocated per instance's imported function, but there shouldn't be that many imports. This has two upsides: it creates smaller and faster code, and makes is easier to disassociate embedder-specific things from embedder-neutral things. The small / faster win is in two places: B3 IR generator only needs offsetOfImportFunction for the call opcode (when the called index is an import) to know whether the import is wasm->wasm or wasm->embedder (this isn't known at compile-time because it's dependent on the import object), this is now done by seeing if that import function has an associated target instance (only wasm->wasm does); the other place is wasmBinding which uses offsetOfImportFunction to figure out the wasm->wasm target instance, and then gets WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation to do a tail call. The disassociation comes because the target instance can be Wasm::Instance once we change what the Context is, and WasmEntrypointLoadLocation is already embedder-independent. As a next step I can move this tail allocation from JSWebAssemblyInstance to Wasm::Instance, and leave importFunction in as an opaque pointer which is embedder-specific, and in JS will remain WriteBarrier<JSObject>. - Rename VMEntryFrame to EntryFrame, and in many places pass a pointer to it around instead of VM. This is a first step in allowing entry frames which aren't stored on VM, but which are instead stored in an embedder-specific location. That change won't really affect JS except through code churn, but will allow WebAssembly to use some machinery in a generic manner without having a VM. * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * debugger/Debugger.cpp: (JSC::Debugger::stepOutOfFunction): (JSC::Debugger::returnEvent): (JSC::Debugger::unwindEvent): (JSC::Debugger::didExecuteProgram): * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::compileExceptionHandlers): * dfg/DFGOSREntry.cpp: (JSC::DFG::prepareOSREntry): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::compileOSRExit): (JSC::DFG::OSRExit::compileExit): * dfg/DFGThunks.cpp: (JSC::DFG::osrEntryThunkGenerator): * ftl/FTLCompile.cpp: (JSC::FTL::compile): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::lower): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): (JSC::CallFrame::callerFrame): (JSC::CallFrame::unsafeCallerFrame): * interpreter/CallFrame.h: (JSC::ExecState::callerFrame const): (JSC::ExecState::callerFrameOrEntryFrame const): (JSC::ExecState::unsafeCallerFrameOrEntryFrame const): * interpreter/FrameTracers.h: (JSC::NativeCallFrameTracer::NativeCallFrameTracer): (JSC::NativeCallFrameTracerWithRestore::NativeCallFrameTracerWithRestore): (JSC::NativeCallFrameTracerWithRestore::~NativeCallFrameTracerWithRestore): * interpreter/Interpreter.cpp: (JSC::UnwindFunctor::operator() const): (JSC::UnwindFunctor::copyCalleeSavesToEntryFrameCalleeSavesBuffer const): (JSC::Interpreter::unwind): * interpreter/StackVisitor.cpp: (JSC::StackVisitor::StackVisitor): (JSC::StackVisitor::gotoNextFrame): (JSC::StackVisitor::readNonInlinedFrame): (JSC::StackVisitor::Frame::dump const): * interpreter/StackVisitor.h: (JSC::StackVisitor::Frame::callerIsEntryFrame const): * interpreter/VMEntryRecord.h: (JSC::VMEntryRecord::prevTopEntryFrame): (JSC::VMEntryRecord::unsafePrevTopEntryFrame): (JSC::EntryFrame::vmEntryRecordOffset): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::restoreCalleeSavesFromEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::loadWasmContextInstance): (JSC::AssemblyHelpers::storeWasmContextInstance): (JSC::AssemblyHelpers::loadWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::storeWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBufferImpl): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::copyCalleeSavesToVMEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer): * jit/JIT.cpp: (JSC::JIT::emitEnterOptimizationCheck): (JSC::JIT::privateCompileExceptionHandlers): * jit/JITExceptions.cpp: (JSC::genericUnwind): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): (JSC::JIT::emitSlow_op_loop_hint): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): * jit/JITOperations.cpp: * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::nativeForGenerator): * jsc.cpp: (functionDumpCallFrame): * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LLIntThunks.cpp: (JSC::vmEntryRecord): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/Options.cpp: (JSC::recomputeDependentOptions): * runtime/Options.h: * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::FrameWalker): (JSC::FrameWalker::advanceToParentFrame): (JSC::SamplingProfiler::processUnverifiedStackTraces): * runtime/ThrowScope.cpp: (JSC::ThrowScope::~ThrowScope): * runtime/VM.cpp: (JSC::VM::VM): (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::topEntryFrameOffset): * runtime/VMTraps.cpp: (JSC::isSaneFrame): (JSC::VMTraps::tryInstallTrapBreakpoints): (JSC::VMTraps::invalidateCodeBlocksOnStack): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWasmContextInstance): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::parseAndCompile): * wasm/WasmB3IRGenerator.h: * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::BBQPlan): (JSC::Wasm::BBQPlan::compileFunctions): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBBQPlanInlines.h: (JSC::Wasm::BBQPlan::initializeCallees): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmBinding.h: * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::create): (JSC::Wasm::CodeBlock::CodeBlock): (JSC::Wasm::CodeBlock::compileAsync): (JSC::Wasm::CodeBlock::setCompilationFinished): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::offsetOfImportStubs): (JSC::Wasm::CodeBlock::allocationSize): (JSC::Wasm::CodeBlock::importWasmToEmbedderStub): (JSC::Wasm::CodeBlock::offsetOfImportWasmToEmbedderStub): (JSC::Wasm::CodeBlock::wasmToJSCallStubForImport): (JSC::Wasm::CodeBlock::compilationFinished): (JSC::Wasm::CodeBlock::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): * wasm/WasmContext.cpp: (JSC::Wasm::Context::useFastTLS): (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: Copied from Source/JavaScriptCore/wasm/WasmContext.h. * wasm/WasmFaultSignalHandler.cpp: * wasm/WasmFaultSignalHandler.h: * wasm/WasmFormat.h: * wasm/WasmInstance.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::~Instance): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: Added. (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::module): (JSC::Wasm::Instance::codeBlock): (JSC::Wasm::Instance::memory): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::loadF32Global const): (JSC::Wasm::Instance::loadF64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::offsetOfCachedStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::~Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::offsetOfSize): * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationCallback): (JSC::Wasm::Module::validateSync): (JSC::Wasm::Module::validateAsync): (JSC::Wasm::Module::getOrCreateCodeBlock): (JSC::Wasm::Module::compileSync): (JSC::Wasm::Module::compileAsync): * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseTableHelper): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::OMGPlan): (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::isValid const): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::runCompletionTasks): (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmPlan.h: (JSC::Wasm::Plan::dontFinalize): * wasm/WasmSignature.cpp: * wasm/WasmSignature.h: * wasm/WasmTable.cpp: Added. (JSC::Wasm::Table::create): (JSC::Wasm::Table::~Table): (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h. (JSC::Wasm::Table::maximum const): (JSC::Wasm::Table::size const): (JSC::Wasm::Table::offsetOfSize): (JSC::Wasm::Table::offsetOfFunctions): (JSC::Wasm::Table::offsetOfInstances): (JSC::Wasm::Table::isValidSize): * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): (JSC::Wasm::Thunks::setThrowWasmException): (JSC::Wasm::Thunks::throwWasmException): * wasm/WasmThunks.h: * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::stopAllPlansForContext): * wasm/WasmWorklist.h: * wasm/js/JSToWasm.cpp: Added. (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/JSWebAssembly.cpp: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.cpp. * wasm/js/JSWebAssembly.h: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.h. * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::create): (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::context const): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::webAssemblyToJSCallee): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::offsetOfTail): (JSC::JSWebAssemblyInstance::importFunctionInfo): (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): (JSC::JSWebAssemblyInstance::offsetOfImportFunction): (JSC::JSWebAssemblyInstance::importFunction): (JSC::JSWebAssemblyInstance::internalMemory): (JSC::JSWebAssemblyInstance::wasmCodeBlock const): (JSC::JSWebAssemblyInstance::offsetOfWasmTable): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::offsetOfGlobals): (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): (JSC::JSWebAssemblyInstance::cachedStackLimit const): (JSC::JSWebAssemblyInstance::setCachedStackLimit): (JSC::JSWebAssemblyInstance::wasmMemory): (JSC::JSWebAssemblyInstance::wasmModule): (JSC::JSWebAssemblyInstance::allocationSize): (JSC::JSWebAssemblyInstance::module const): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::create): (JSC::JSWebAssemblyMemory::adopt): (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::moduleInformation const): (JSC::JSWebAssemblyModule::exportSymbolTable const): (JSC::JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace const): (JSC::JSWebAssemblyModule::callee const): (JSC::JSWebAssemblyModule::codeBlock): (JSC::JSWebAssemblyModule::module): * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::create): (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::visitChildren): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::getFunction): (JSC::JSWebAssemblyTable::clearFunction): (JSC::JSWebAssemblyTable::setFunction): * wasm/js/JSWebAssemblyTable.h: (JSC::JSWebAssemblyTable::isValidSize): (JSC::JSWebAssemblyTable::maximum const): (JSC::JSWebAssemblyTable::size const): (JSC::JSWebAssemblyTable::table): * wasm/js/WasmToJS.cpp: Copied from Source/JavaScriptCore/wasm/WasmBinding.cpp. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): (JSC::WebAssemblyModuleConstructor::createModule): * wasm/js/WebAssemblyModuleConstructor.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::webAssemblyCompileFunc): (JSC::instantiate): (JSC::compileAndInstantiate): (JSC::webAssemblyValidateFunc): * wasm/js/WebAssemblyTableConstructor.cpp: (JSC::constructJSWebAssemblyTable): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Source/WebCore: * ForwardingHeaders/wasm/WasmModule.h: Added. This used to be included in JSWebAssemblyModule.h. * bindings/js/SerializedScriptValue.cpp: Update postMessage code according to C++ API changes. Canonical link: https://commits.webkit.org/194750@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223738 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-20 02:23:29 +00:00
Adopt the new WebAssembly.Global system https://bugs.webkit.org/show_bug.cgi?id=186552 Reviewed by Keith Miller. JSTests: 1. Update spec-harness to accept newer tests. And we update several tests that does not work with the old harness. 2. Add WebAssembly.Global tests. * wasm/js-api/global-error.js: (assert.throws.new.WebAssembly.Module.bin): (new.WebAssembly.Module): (assert.throws): * wasm/js-api/global-external-init-from-import.js: * wasm/js-api/globals-export.js: * wasm/modules/js-wasm-global-namespace.js: (assert.throws): * wasm/modules/js-wasm-global.js: (assert.throws): * wasm/modules/wasm-import-wasm-export-i64-error.js: * wasm/references/anyref_globals.js: * wasm/references/func_ref.js: (assert.eq.instance.exports.fix): * wasm/spec-harness.js: (getGlobal): (let.console.log): * wasm/spec-harness/sync_index.js: Renamed from JSTests/wasm/spec-harness/index.js. (reinitializeRegistry.let.handler.get return): (module): * wasm/spec-tests/call.wast.js: * wasm/spec-tests/exports.wast.js: * wasm/spec-tests/globals.wast.js: * wasm/spec-tests/if.wast.js: * wasm/spec-tests/imports.wast.js: * wasm/spec-tests/linking.wast.js: * wasm/spec-tests/memory.wast.js: * wasm/stress/immutable-globals.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.assert.eq.instance.exports.getI32): (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.assert.eq): * wasm/stress/mutable-globals-cross.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.const.instance1): (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.const.instance2): * wasm/stress/mutable-globals.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.instance.exports.setI32AsI64): LayoutTests/imported/w3c: * web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any-expected.txt: * web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/constructor.any-expected.txt: * web-platform-tests/wasm/jsapi/global/constructor.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/toString.any-expected.txt: * web-platform-tests/wasm/jsapi/global/toString.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/value-set.any-expected.txt: * web-platform-tests/wasm/jsapi/global/value-set.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/valueOf.any-expected.txt: * web-platform-tests/wasm/jsapi/global/valueOf.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor.any-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/interface.any-expected.txt: * web-platform-tests/wasm/jsapi/interface.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/module/exports.any-expected.txt: * web-platform-tests/wasm/jsapi/module/exports.any.worker-expected.txt: Source/JavaScriptCore: This patch adds WebAssembly.Global implementation. It is already included in the Wasm spec (this means, it is not in staging right now: it was stage-4, and included in the spec). WebAssembly.Global is a wrapper object around "global" binding. This object can hold "immutable" and "mutable" global binding, and we can access Wasm globals through this object. Furthermore, we can share mutable global binding through this object across WebAssembly modules. To implement it efficiently, this patch introduces BindingMode to Wasm globals. If the mode is EmbeddedInInstance, we continue using the current existing mechanism. If the mode is Portable, we store a pointer to actual value in Wasm globals array in Wasm::Instance, so that we can access it through one additional dereference. And we mark all immutable globals as EmbeddedInInstance. If the binding is immutable, internally we do not need to have one binding. We can just continue using the current mechanism since users cannot observe whether immutable bindings' storage is shared or not. If the global is mutable, and it is exported outside of the module, we use Portable mode. So, all the previously used wasm global bindings are EmbeddedInInstance. Only newly added "mutable" "exported" bindings are Portable and requires one additional dereference. To access portable bindings efficiently, we add new Wasm bytecodes, `get_global_portable_binding`, `set_global_portable_binding`, and `set_global_ref_portable_binding`. This patch improves WPT wasm coverage significantly. * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/BytecodeList.rb: * heap/HeapCell.cpp: (JSC::keepAlive): (JSC::HeapCell::use const): Deleted. * heap/HeapCell.h: (JSC::keepAlive): (JSC::HeapCell::use const): * llint/WebAssembly.asm: * runtime/JSGlobalObject.cpp: * runtime/JSGlobalObject.h: * runtime/VM.cpp: (JSC::VM::VM): * runtime/VM.h: * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::getGlobal): (JSC::Wasm::AirIRGenerator::setGlobal): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::getGlobal): (JSC::Wasm::B3IRGenerator::setGlobal): * wasm/WasmFormat.h: * wasm/WasmGlobal.cpp: Added. (JSC::Wasm::Global::get const): (JSC::Wasm::Global::set): (JSC::Wasm::Global::visitAggregate): * wasm/WasmGlobal.h: Added. * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::linkGlobal): * wasm/WasmInstance.h: (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::globalsToBinding): (JSC::Wasm::Instance::getGlobalBinding): * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::getGlobal): (JSC::Wasm::LLIntGenerator::setGlobal): * wasm/WasmModuleInformation.h: * wasm/WasmOperations.cpp: (JSC::Wasm::operationWasmWriteBarrierSlowPath): * wasm/WasmOperations.h: * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseImport): (JSC::Wasm::SectionParser::parseGlobal): (JSC::Wasm::SectionParser::parseExport): (JSC::Wasm::SectionParser::parseInitExpr): (JSC::Wasm::SectionParser::parseGlobalType): * wasm/WasmSectionParser.h: * wasm/WasmSlowPaths.cpp: (JSC::LLInt::WASM_SLOW_PATH_DECL): * wasm/WasmSlowPaths.h: * wasm/WasmValidate.cpp: (JSC::Wasm::Validate::setGlobal): * wasm/js/JSWebAssembly.cpp: * wasm/js/JSWebAssemblyGlobal.cpp: Added. (JSC::JSWebAssemblyGlobal::create): (JSC::JSWebAssemblyGlobal::createStructure): (JSC::JSWebAssemblyGlobal::JSWebAssemblyGlobal): (JSC::JSWebAssemblyGlobal::finishCreation): (JSC::JSWebAssemblyGlobal::destroy): (JSC::JSWebAssemblyGlobal::visitChildren): * wasm/js/JSWebAssemblyGlobal.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/JSWebAssemblyInstance.h: * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::destroy): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.h: * wasm/js/WebAssemblyGlobalConstructor.cpp: Added. (JSC::constructJSWebAssemblyGlobal): (JSC::callJSWebAssemblyGlobal): (JSC::WebAssemblyGlobalConstructor::create): (JSC::WebAssemblyGlobalConstructor::createStructure): (JSC::WebAssemblyGlobalConstructor::finishCreation): (JSC::WebAssemblyGlobalConstructor::WebAssemblyGlobalConstructor): * wasm/js/WebAssemblyGlobalConstructor.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/WebAssemblyGlobalPrototype.cpp: Added. (JSC::getGlobal): (JSC::webAssemblyGlobalProtoFuncValueOf): (JSC::webAssemblyGlobalProtoGetterFuncValue): (JSC::webAssemblyGlobalProtoSetterFuncValue): (JSC::WebAssemblyGlobalPrototype::create): (JSC::WebAssemblyGlobalPrototype::createStructure): (JSC::WebAssemblyGlobalPrototype::finishCreation): (JSC::WebAssemblyGlobalPrototype::WebAssemblyGlobalPrototype): * wasm/js/WebAssemblyGlobalPrototype.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): Canonical link: https://commits.webkit.org/218038@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@253074 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-12-04 01:36:56 +00:00
Wasm::Global* getGlobalBinding(unsigned i)
{
ASSERT(m_globalsToBinding.get(i));
Wasm::Global::Value* pointer = m_globals.get()[i].m_pointer;
if (!pointer)
return nullptr;
return &Wasm::Global::fromBinding(*pointer);
}
WebAssembly: no VM / JS version of our implementation https://bugs.webkit.org/show_bug.cgi?id=177472 Reviewed by Michael Saboff. This patch removes all appearances of "JS" and "VM" in the wasm directory. These now only appear in the wasm/js directory, which is only used in a JS embedding of wasm. It should therefore now be possible to create non-JS embeddings of wasm through JSC, though it'll still require: - Mild codegen for wasm<->embedder calls; - A strategy for trap handling (no need for full unwind! Could kill). - Creation of the Wasm::* objects. - Calling convention handling to call the embedder. - Handling of multiple embedders (see #177475, this is optional). Most of the patch consists in renaming JSWebAssemblyInstance to Instance, and removing temporary copies which I'd added to make this specific patch very simple. * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): this one place which needs to know about who "owns" the Wasm::Instance. In a JS embedding it's the JSWebAssemblyInstance. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::getGlobal): (JSC::Wasm::B3IRGenerator::setGlobal): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmContext.cpp: (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: add an "owner", the Wasm::Context, move the "tail" import information from JSWebAssemblyInstance over to here. (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::owner const): (JSC::Wasm::Instance::offsetOfOwner): (JSC::Wasm::Instance::context const): (JSC::Wasm::Instance::setMemory): (JSC::Wasm::Instance::setTable): (JSC::Wasm::Instance::offsetOfMemory): (JSC::Wasm::Instance::offsetOfGlobals): (JSC::Wasm::Instance::offsetOfTable): (JSC::Wasm::Instance::offsetOfTail): (JSC::Wasm::Instance::numImportFunctions const): (JSC::Wasm::Instance::importFunctionInfo): (JSC::Wasm::Instance::offsetOfTargetInstance): (JSC::Wasm::Instance::offsetOfWasmEntrypoint): (JSC::Wasm::Instance::offsetOfWasmToEmbedderStubExecutableAddress): (JSC::Wasm::Instance::offsetOfImportFunction): (JSC::Wasm::Instance::importFunction): (JSC::Wasm::Instance::allocationSize): (JSC::Wasm::Instance::create): Deleted. * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmTable.cpp: (JSC::Wasm::Table::Table): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyInstance.cpp: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): The embedder decides what the import function is. Here we must properly placement-new it to what we've elected (and initialize it later). (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::moduleNamespaceObject): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::setTable): (JSC::JSWebAssemblyInstance::offsetOfInstance): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::context const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTail): Deleted. (): Deleted. (JSC::JSWebAssemblyInstance::importFunctionInfo): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmToEmbedderStubExecutableAddress): Deleted. (JSC::JSWebAssemblyInstance::offsetOfImportFunction): Deleted. (JSC::JSWebAssemblyInstance::importFunction): Deleted. (JSC::JSWebAssemblyInstance::internalMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmCodeBlock const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmTable): Deleted. (JSC::JSWebAssemblyInstance::offsetOfGlobals): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTopEntryFramePointer): Deleted. (JSC::JSWebAssemblyInstance::cachedStackLimit const): Deleted. (JSC::JSWebAssemblyInstance::setCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::wasmMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmModule): Deleted. (JSC::JSWebAssemblyInstance::allocationSize): Deleted. * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::setFunction): * wasm/js/WasmToJS.cpp: One extra indirection to find the JSWebAssemblyInstance. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::instantiate): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Canonical link: https://commits.webkit.org/195012@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224020 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-26 15:33:55 +00:00
static ptrdiff_t offsetOfMemory() { return OBJECT_OFFSETOF(Instance, m_memory); }
static ptrdiff_t offsetOfGlobals() { return OBJECT_OFFSETOF(Instance, m_globals); }
WebAssembly: cache memory address / size on instance https://bugs.webkit.org/show_bug.cgi?id=177305 Reviewed by JF Bastien. JSTests: * wasm/function-tests/memory-reuse.js: Added. (createWasmInstance): (doCheckTrap): (doMemoryGrow): (doCheck): (checkWasmInstancesWithSharedMemory): Source/JavaScriptCore: Cache memory address/size in wasm:Instance to avoid load wasm:Memory object during access to memory and memory size property in JiT * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmInstance.h: (JSC::Wasm::Instance::cachedMemory const): (JSC::Wasm::Instance::cachedMemorySize const): (JSC::Wasm::Instance::createWeakPtr): (JSC::Wasm::Instance::setMemory): (JSC::Wasm::Instance::updateCachedMemory): (JSC::Wasm::Instance::offsetOfCachedMemory): (JSC::Wasm::Instance::offsetOfCachedMemorySize): (JSC::Wasm::Instance::offsetOfCachedIndexingMask): (JSC::Wasm::Instance::allocationSize): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::grow): (JSC::Wasm::Memory::registerInstance): * wasm/WasmMemory.h: (JSC::Wasm::Memory::indexingMask): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::evaluate): Canonical link: https://commits.webkit.org/198823@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@228966 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-02-23 23:16:59 +00:00
static ptrdiff_t offsetOfCachedMemory() { return OBJECT_OFFSETOF(Instance, m_cachedMemory); }
Unreviewed, relanding r269940 https://bugs.webkit.org/show_bug.cgi?id=219076 JSTests: * wasm/function-tests/trap-load-shared.js: Added. (wasmFrameCountFromError): * wasm/function-tests/trap-store-shared.js: Added. * wasm/js-api/test_memory.js: (binaryShouldNotParse): * wasm/stress/shared-memory-errors.js: Added. (assert.throws): * wasm/stress/shared-wasm-memory-buffer.js: Added. LayoutTests/imported/w3c: * web-platform-tests/html/webappapis/scripting/processing-model-2/integration-with-the-javascript-agent-formalism/requires-success.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/memory/constructor-shared.tentative.any-expected.txt: * web-platform-tests/wasm/jsapi/memory/constructor-shared.tentative.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/memory/constructor.any-expected.txt: * web-platform-tests/wasm/jsapi/memory/constructor.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/memory/grow.any-expected.txt: * web-platform-tests/wasm/jsapi/memory/grow.any.worker-expected.txt: * web-platform-tests/webaudio/the-audio-api/the-audiobuffer-interface/audiobuffer-copy-channel-expected.txt: Source/JavaScriptCore: ARM64E clang optimizer is broken and optimizing forever if Wasm::MemoryHandle::memory() is inlined. Putting NEVER_INLINE onto this function for now (unfortunate). * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * llint/LLIntPCRanges.h: (JSC::LLInt::isWasmLLIntPC): * llint/LowLevelInterpreter.asm: * llint/WebAssembly.asm: * runtime/JSArrayBuffer.h: (JSC::JSArrayBuffer::toWrappedAllowShared): * runtime/JSArrayBufferView.h: * runtime/JSArrayBufferViewInlines.h: (JSC::JSArrayBufferView::toWrappedAllowShared): * runtime/JSGenericTypedArrayView.h: (JSC::JSGenericTypedArrayView<Adaptor>::toWrappedAllowShared): * runtime/Options.cpp: (JSC::overrideDefaults): (JSC::Options::initialize): * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::AirIRGenerator): (JSC::Wasm::AirIRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::AirIRGenerator::addCurrentMemory): (JSC::Wasm::AirIRGenerator::emitCheckAndPreparePointer): (JSC::Wasm::AirIRGenerator::addCall): (JSC::Wasm::AirIRGenerator::addCallIndirect): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::emitCheckAndPreparePointer): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmFaultSignalHandler.cpp: (JSC::Wasm::trapHandler): (JSC::Wasm::enableFastMemory): (JSC::Wasm::prepareFastMemory): * wasm/WasmInstance.h: (JSC::Wasm::Instance::cachedMemory const): (JSC::Wasm::Instance::cachedBoundsCheckingSize const): (JSC::Wasm::Instance::updateCachedMemory): (JSC::Wasm::Instance::offsetOfCachedBoundsCheckingSize): (JSC::Wasm::Instance::cachedMemorySize const): Deleted. (JSC::Wasm::Instance::offsetOfCachedMemorySize): Deleted. * wasm/WasmMemory.cpp: (JSC::Wasm::MemoryHandle::MemoryHandle): (JSC::Wasm::MemoryHandle::~MemoryHandle): (JSC::Wasm::MemoryHandle::memory const): (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::tryCreate): (JSC::Wasm::Memory::addressIsInGrowableOrFastMemory): (JSC::Wasm::Memory::growShared): (JSC::Wasm::Memory::grow): (JSC::Wasm::Memory::dump const): (JSC::Wasm::Memory::~Memory): Deleted. (JSC::Wasm::Memory::addressIsInActiveFastMemory): Deleted. * wasm/WasmMemory.h: (JSC::Wasm::Memory::addressIsInGrowableOrFastMemory): (JSC::Wasm::Memory::operator bool const): Deleted. (JSC::Wasm::Memory::memory const): Deleted. (JSC::Wasm::Memory::size const): Deleted. (JSC::Wasm::Memory::sizeInPages const): Deleted. (JSC::Wasm::Memory::initial const): Deleted. (JSC::Wasm::Memory::maximum const): Deleted. (JSC::Wasm::Memory::mode const): Deleted. (JSC::Wasm::Memory::check): Deleted. (JSC::Wasm::Memory::offsetOfMemory): Deleted. (JSC::Wasm::Memory::offsetOfSize): Deleted. (JSC::Wasm::Memory::addressIsInActiveFastMemory): Deleted. * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::tryCreate): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::buffer): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::WebAssemblyFunction::jsCallEntrypointSlow): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::evaluate): Source/WebCore: Tests: js/dom/webassembly-memory-normal-fail.html js/dom/webassembly-memory-shared-basic.html js/dom/webassembly-memory-shared-fail.html storage/indexeddb/shared-memory-structured-clone.html * Headers.cmake: * Modules/indexeddb/server/IDBSerializationContext.cpp: (WebCore::IDBServer::IDBSerializationContext::initializeVM): * WebCore.xcodeproj/project.pbxproj: * bindings/IDLTypes.h: * bindings/js/CommonVM.cpp: (WebCore::commonVMSlow): * bindings/js/JSDOMConvertBufferSource.h: (WebCore::Detail::BufferSourceConverter::convert): (WebCore::Converter<IDLArrayBuffer>::convert): (WebCore::Converter<IDLDataView>::convert): (WebCore::Converter<IDLInt8Array>::convert): (WebCore::Converter<IDLInt16Array>::convert): (WebCore::Converter<IDLInt32Array>::convert): (WebCore::Converter<IDLUint8Array>::convert): (WebCore::Converter<IDLUint16Array>::convert): (WebCore::Converter<IDLUint32Array>::convert): (WebCore::Converter<IDLUint8ClampedArray>::convert): (WebCore::Converter<IDLFloat32Array>::convert): (WebCore::Converter<IDLFloat64Array>::convert): (WebCore::Converter<IDLArrayBufferView>::convert): (WebCore::Converter<IDLAllowSharedAdaptor<T>>::convert): * bindings/js/JSDOMConvertUnion.h: * bindings/js/SerializedScriptValue.cpp: (WebCore::CloneSerializer::serialize): (WebCore::CloneSerializer::CloneSerializer): (WebCore::CloneSerializer::dumpIfTerminal): (WebCore::CloneDeserializer::deserialize): (WebCore::CloneDeserializer::CloneDeserializer): (WebCore::CloneDeserializer::readTerminal): (WebCore::SerializedScriptValue::SerializedScriptValue): (WebCore::SerializedScriptValue::computeMemoryCost const): (WebCore::SerializedScriptValue::create): (WebCore::SerializedScriptValue::deserialize): * bindings/js/SerializedScriptValue.h: * bindings/js/WebCoreJSClientData.cpp: (WebCore::JSVMClientData::initNormalWorld): * bindings/js/WebCoreJSClientData.h: * bindings/js/WebCoreTypedArrayController.cpp: (WebCore::WebCoreTypedArrayController::WebCoreTypedArrayController): (WebCore::WebCoreTypedArrayController::isAtomicsWaitAllowedOnCurrentThread): * bindings/js/WebCoreTypedArrayController.h: * bindings/scripts/CodeGeneratorJS.pm: (IsAnnotatedType): (GetAnnotatedIDLType): * bindings/scripts/IDLAttributes.json: * bindings/scripts/test/JS/JSTestObj.cpp: (WebCore::JSTestObjDOMConstructor::construct): (WebCore::jsTestObjPrototypeFunction_encodeIntoBody): (WebCore::JSC_DEFINE_HOST_FUNCTION): * bindings/scripts/test/TestObj.idl: * dom/TextDecoder.idl: * dom/TextDecoderStreamDecoder.idl: * dom/TextEncoder.idl: * workers/DedicatedWorkerGlobalScope.cpp: (WebCore::DedicatedWorkerGlobalScope::DedicatedWorkerGlobalScope): * workers/WorkerGlobalScope.cpp: (WebCore::WorkerGlobalScope::WorkerGlobalScope): * workers/WorkerGlobalScope.h: * workers/WorkerOrWorkletGlobalScope.cpp: (WebCore::WorkerOrWorkletGlobalScope::WorkerOrWorkletGlobalScope): * workers/WorkerOrWorkletGlobalScope.h: * workers/WorkerOrWorkletScriptController.cpp: (WebCore::WorkerOrWorkletScriptController::WorkerOrWorkletScriptController): * workers/WorkerOrWorkletScriptController.h: * workers/WorkerThreadType.h: Added. * workers/service/ServiceWorkerGlobalScope.cpp: (WebCore::ServiceWorkerGlobalScope::ServiceWorkerGlobalScope): * worklets/WorkletGlobalScope.cpp: (WebCore::WorkletGlobalScope::WorkletGlobalScope): Source/WTF: * wtf/PlatformEnable.h: LayoutTests: * js/dom/resources/webassembly-memory-normal-fail-worker.js: Added. * js/dom/resources/webassembly-memory-shared-worker.js: Added. (onmessage): * js/dom/webassembly-memory-normal-fail-expected.txt: Added. * js/dom/webassembly-memory-normal-fail.html: Added. * js/dom/webassembly-memory-shared-basic-expected.txt: Added. * js/dom/webassembly-memory-shared-basic.html: Added. * js/dom/webassembly-memory-shared-fail-expected.txt: Added. * js/dom/webassembly-memory-shared-fail.html: Added. * platform/win/TestExpectations: * storage/indexeddb/resources/shared-memory-structured-clone.js: Added. (prepareDatabase): (async startTests): (testSharedWebAssemblyMemory): * storage/indexeddb/shared-memory-structured-clone-expected.txt: Added. * storage/indexeddb/shared-memory-structured-clone.html: Added. Canonical link: https://commits.webkit.org/231721@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@269974 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-11-18 20:22:16 +00:00
static ptrdiff_t offsetOfCachedBoundsCheckingSize() { return OBJECT_OFFSETOF(Instance, m_cachedBoundsCheckingSize); }
WebAssembly: restore cached stack limit after out-call https://bugs.webkit.org/show_bug.cgi?id=179106 <rdar://problem/35337525> Reviewed by Saam Barati. JSTests: * wasm/function-tests/double-instance.js: Added. (const.imp.boom): (const.imp.get callAnother): Source/JavaScriptCore: We cache the stack limit on the Instance so that we can do fast stack checks where required. In regular usage the stack limit never changes because we always run on the same thread, but in rare cases an API user can totally migrate which thread (and therefore stack) is used for execution between WebAssembly traces. For that reason we set the cached stack limit to UINTPTR_MAX on the outgoing Instance when transitioning back into a different Instance. We usually restore the cached stack limit in Context::store, but this wasn't called on all code paths. We had a bug where an Instance calling into itself indirectly would therefore fail to restore its cached stack limit properly. This patch therefore restores the cached stack limit after direct calls which could be to imports (both wasm->wasm and wasm->embedder). We have to do all of them because we have no way of knowing what imports will do (they're known at instantiation time, not compilation time, and different instances can have different imports). To make this efficient we also add a pointer to the canonical location of the stack limit (i.e. the extra indirection we're trying to save by caching the stack limit on the Instance in the first place). This is potentially a small perf hit on imported direct calls. It's hard to say what the performance cost will be because we haven't seen much code in the wild which does this. We're adding two dependent loads and a store of the loaded value, which is unlikely to get used soon after. It's more code, but on an out-of-order processor it doesn't contribute to the critical path. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): * wasm/WasmInstance.h: (JSC::Wasm::Instance::offsetOfPointerToActualStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::create): * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): Canonical link: https://commits.webkit.org/196260@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225411 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-01 21:58:36 +00:00
static ptrdiff_t offsetOfPointerToTopEntryFrame() { return OBJECT_OFFSETOF(Instance, m_pointerToTopEntryFrame); }
WebAssembly: restore cached stack limit after out-call https://bugs.webkit.org/show_bug.cgi?id=179106 <rdar://problem/35337525> Reviewed by Saam Barati. JSTests: * wasm/function-tests/double-instance.js: Added. (const.imp.boom): (const.imp.get callAnother): Source/JavaScriptCore: We cache the stack limit on the Instance so that we can do fast stack checks where required. In regular usage the stack limit never changes because we always run on the same thread, but in rare cases an API user can totally migrate which thread (and therefore stack) is used for execution between WebAssembly traces. For that reason we set the cached stack limit to UINTPTR_MAX on the outgoing Instance when transitioning back into a different Instance. We usually restore the cached stack limit in Context::store, but this wasn't called on all code paths. We had a bug where an Instance calling into itself indirectly would therefore fail to restore its cached stack limit properly. This patch therefore restores the cached stack limit after direct calls which could be to imports (both wasm->wasm and wasm->embedder). We have to do all of them because we have no way of knowing what imports will do (they're known at instantiation time, not compilation time, and different instances can have different imports). To make this efficient we also add a pointer to the canonical location of the stack limit (i.e. the extra indirection we're trying to save by caching the stack limit on the Instance in the first place). This is potentially a small perf hit on imported direct calls. It's hard to say what the performance cost will be because we haven't seen much code in the wild which does this. We're adding two dependent loads and a store of the loaded value, which is unlikely to get used soon after. It's more code, but on an out-of-order processor it doesn't contribute to the critical path. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): * wasm/WasmInstance.h: (JSC::Wasm::Instance::offsetOfPointerToActualStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::create): * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): Canonical link: https://commits.webkit.org/196260@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225411 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-01 21:58:36 +00:00
static ptrdiff_t offsetOfPointerToActualStackLimit() { return OBJECT_OFFSETOF(Instance, m_pointerToActualStackLimit); }
WebAssembly: no VM / JS version of everything but Instance https://bugs.webkit.org/show_bug.cgi?id=177473 Reviewed by Filip Pizlo, Saam Barati. JSTests: - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. * wasm/js-api/memory-grow.js: (assertEq): * wasm/js-api/table.js: (assert.throws): Source/JavaScriptCore: This change entails cleaning up and splitting a bunch of code which we had intertwined between C++ classes which represent JS objects, and pure C++ implementation objects. This specific change goes most of the way towards allowing JSC's WebAssembly to work without VM / JS, up to but excluding JSWebAssemblyInstance (there's Wasm::Instance, but it's not *the* thing yet). Because of this we still have a few FIXME identifying places that need to change. A follow-up change will go the rest of the way. I went about this change in the simplest way possible: grep the JavaScriptCore/wasm directory for "JS[^C_]" as well as "VM" and exclude the /js/ sub-directory (which contains the JS implementation of WebAssembly). None of this change removes the need for a JIT entitlement to be able to use WebAssembly. We don't have an interpreter, the process therefore still needs to be allowed to JIT to use these pure-C++ APIs. Interesting things to note: - Remove VM from Plan and associated places. It can just live as a capture in the callback lambda if it's needed. - Wasm::Memory shouldn't require a VM. It was only used to ask the GC to collect. We now instead pass two lambdas at construction time for this purpose: one to notify of memory pressure, and the other to ask for syncrhonous memory reclamation. This allows whoever creates the memory to dictate how to react to both these cases, and for a JS embedding that's to call the GC (async or sync, respectively). - Move grow logic from JSWebAssemblyMemory to Wasm::Memory::grow. Use Expected there, with an enum class for failure types. - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. - When generating the grow_memory opcode, no need to get the VM. Instead, reach directly for Wasm::Memory and grow it. - JSWebAssemblyMemory::grow can now always throw on failure, because it's only ever called from JS (not from grow_memory as before). - Wasm::Memory now takes a callback for successful growth. This allows JS wrappers to register themselves when growth succeeds without Wasm::Memory knowning anything about JS. It'll also allow creating a list of callbacks for when we add thread support (we'll want to notify many wrappers, all under a lock). - Wasm::Memory is now back to being the source of truth about address / size, used directly by generated code instead of JSWebAssemblyMemory. - Move wasmToJS from the general WasmBinding header to its own header under wasm/js. It's only used by wasm/js/JSWebAssemblyCodeBlock.cpp, and uses VM, and therefore isn't general WebAssembly. - Make Wasm::Context an actual type (just a struct holding a JSWebAssemlyInstance for now) instead of an alias for that. Notably this doesn't add anything to the Context and doesn't change what actually gets passed around in JIT code (fast TLS or registers) because these changes potentially impact performance. The entire purpose of this change is to allow passing Wasm::Context around without having to know about VM. Since VM contains a Wasm::Context the JS embedding is effectively the same, but with this setup a non-JS embedding is much better off. - Move JSWebAssembly into the JS folder. - OMGPlan: use Wasm::CodeBlock directly instead of JSWebAssemblyCodeBlock. - wasm->JS stubs are now on the instance's tail as raw pointers, instead of being on JSWebAssemblyCodeBlock, and are now called wasm->Embedder stubs. The owned reference is still on JSWebAssemblyCodeBlock, and is still called wasm->JS stub. This move means that the embedder must, after creating a Wasm::CodeBlock, somehow create the stubs to call back into the embedder. This removes an indirection in the generated code because the B3 IR generator now reaches into the instance instead of JSWebAssemblyCodeBlock. - Move more CodeBlock things. Compilation completion is now marked by its own atomic<bool> flag instead of a nullptr plan: that required using a lock, and was causing a deadlock in stack-trace.js because before my changes JSWebAssemblyCodeBlock did its own completion checking separately from Wasm::CodeBlock, without getting the lock. Now that everything points to Wasm::CodeBlock and there's no cached completion marker, the lock was being acquired in a sanity-check assertion. - Embedder -> Wasm wrappers are now generated through a function that's passed in at compilation time, instead of being hard-coded as a JS -> Wasm wrapper. - WasmMemory doens't need to know about fault handling thunks. Only the IR generator should know, and should make sure that the exception throwing thunk is generated if any memory is present (note: with signal handling not all of them generate an exception check). - Make exception throwing pluggable: instead of having a hard-coded JS-specific lambda we now have a regular C++ function being called from JIT code when a WebAssembly exception is thrown. This allows any embedder to get called as they wish. For now a process can only have a single of these functions (i.e. only one embedder per process) because the trap handler is a singleton. That can be fixed in in #177475. - Create WasmEmbedder.h where all embedder plugging will live. - Split up JSWebAssemblyTable into Wasm::Table which is refcounted. JSWebAssemblyTable now only contains the JS functions in the table, and Wasm::Table is what's used by the JIT code to lookup where to call and do the instance check (for context switch). Note that this creates an extra allocation for all the instances in Wasm::Table, and in exchange removes an indirection in JIT code because the instance used to be obtained off of the JS function. Also note that it's the embedder than keeps the instances alive, not Wasm::Table (which holds a dumb pointer to the instance), because doing otherwise would cause reference cycles. - Add WasmInstance. It doesn't do much for now, owns globals. - JSWebAssembly instance now doesn't just contain the imported functions as JSObjects, it also has the corresponding import's instance and wasm entrypoint. This triples the space allocated per instance's imported function, but there shouldn't be that many imports. This has two upsides: it creates smaller and faster code, and makes is easier to disassociate embedder-specific things from embedder-neutral things. The small / faster win is in two places: B3 IR generator only needs offsetOfImportFunction for the call opcode (when the called index is an import) to know whether the import is wasm->wasm or wasm->embedder (this isn't known at compile-time because it's dependent on the import object), this is now done by seeing if that import function has an associated target instance (only wasm->wasm does); the other place is wasmBinding which uses offsetOfImportFunction to figure out the wasm->wasm target instance, and then gets WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation to do a tail call. The disassociation comes because the target instance can be Wasm::Instance once we change what the Context is, and WasmEntrypointLoadLocation is already embedder-independent. As a next step I can move this tail allocation from JSWebAssemblyInstance to Wasm::Instance, and leave importFunction in as an opaque pointer which is embedder-specific, and in JS will remain WriteBarrier<JSObject>. - Rename VMEntryFrame to EntryFrame, and in many places pass a pointer to it around instead of VM. This is a first step in allowing entry frames which aren't stored on VM, but which are instead stored in an embedder-specific location. That change won't really affect JS except through code churn, but will allow WebAssembly to use some machinery in a generic manner without having a VM. * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * debugger/Debugger.cpp: (JSC::Debugger::stepOutOfFunction): (JSC::Debugger::returnEvent): (JSC::Debugger::unwindEvent): (JSC::Debugger::didExecuteProgram): * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::compileExceptionHandlers): * dfg/DFGOSREntry.cpp: (JSC::DFG::prepareOSREntry): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::compileOSRExit): (JSC::DFG::OSRExit::compileExit): * dfg/DFGThunks.cpp: (JSC::DFG::osrEntryThunkGenerator): * ftl/FTLCompile.cpp: (JSC::FTL::compile): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::lower): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): (JSC::CallFrame::callerFrame): (JSC::CallFrame::unsafeCallerFrame): * interpreter/CallFrame.h: (JSC::ExecState::callerFrame const): (JSC::ExecState::callerFrameOrEntryFrame const): (JSC::ExecState::unsafeCallerFrameOrEntryFrame const): * interpreter/FrameTracers.h: (JSC::NativeCallFrameTracer::NativeCallFrameTracer): (JSC::NativeCallFrameTracerWithRestore::NativeCallFrameTracerWithRestore): (JSC::NativeCallFrameTracerWithRestore::~NativeCallFrameTracerWithRestore): * interpreter/Interpreter.cpp: (JSC::UnwindFunctor::operator() const): (JSC::UnwindFunctor::copyCalleeSavesToEntryFrameCalleeSavesBuffer const): (JSC::Interpreter::unwind): * interpreter/StackVisitor.cpp: (JSC::StackVisitor::StackVisitor): (JSC::StackVisitor::gotoNextFrame): (JSC::StackVisitor::readNonInlinedFrame): (JSC::StackVisitor::Frame::dump const): * interpreter/StackVisitor.h: (JSC::StackVisitor::Frame::callerIsEntryFrame const): * interpreter/VMEntryRecord.h: (JSC::VMEntryRecord::prevTopEntryFrame): (JSC::VMEntryRecord::unsafePrevTopEntryFrame): (JSC::EntryFrame::vmEntryRecordOffset): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::restoreCalleeSavesFromEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::loadWasmContextInstance): (JSC::AssemblyHelpers::storeWasmContextInstance): (JSC::AssemblyHelpers::loadWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::storeWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBufferImpl): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::copyCalleeSavesToVMEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer): * jit/JIT.cpp: (JSC::JIT::emitEnterOptimizationCheck): (JSC::JIT::privateCompileExceptionHandlers): * jit/JITExceptions.cpp: (JSC::genericUnwind): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): (JSC::JIT::emitSlow_op_loop_hint): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): * jit/JITOperations.cpp: * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::nativeForGenerator): * jsc.cpp: (functionDumpCallFrame): * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LLIntThunks.cpp: (JSC::vmEntryRecord): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/Options.cpp: (JSC::recomputeDependentOptions): * runtime/Options.h: * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::FrameWalker): (JSC::FrameWalker::advanceToParentFrame): (JSC::SamplingProfiler::processUnverifiedStackTraces): * runtime/ThrowScope.cpp: (JSC::ThrowScope::~ThrowScope): * runtime/VM.cpp: (JSC::VM::VM): (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::topEntryFrameOffset): * runtime/VMTraps.cpp: (JSC::isSaneFrame): (JSC::VMTraps::tryInstallTrapBreakpoints): (JSC::VMTraps::invalidateCodeBlocksOnStack): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWasmContextInstance): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::parseAndCompile): * wasm/WasmB3IRGenerator.h: * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::BBQPlan): (JSC::Wasm::BBQPlan::compileFunctions): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBBQPlanInlines.h: (JSC::Wasm::BBQPlan::initializeCallees): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmBinding.h: * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::create): (JSC::Wasm::CodeBlock::CodeBlock): (JSC::Wasm::CodeBlock::compileAsync): (JSC::Wasm::CodeBlock::setCompilationFinished): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::offsetOfImportStubs): (JSC::Wasm::CodeBlock::allocationSize): (JSC::Wasm::CodeBlock::importWasmToEmbedderStub): (JSC::Wasm::CodeBlock::offsetOfImportWasmToEmbedderStub): (JSC::Wasm::CodeBlock::wasmToJSCallStubForImport): (JSC::Wasm::CodeBlock::compilationFinished): (JSC::Wasm::CodeBlock::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): * wasm/WasmContext.cpp: (JSC::Wasm::Context::useFastTLS): (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: Copied from Source/JavaScriptCore/wasm/WasmContext.h. * wasm/WasmFaultSignalHandler.cpp: * wasm/WasmFaultSignalHandler.h: * wasm/WasmFormat.h: * wasm/WasmInstance.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::~Instance): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: Added. (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::module): (JSC::Wasm::Instance::codeBlock): (JSC::Wasm::Instance::memory): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::loadF32Global const): (JSC::Wasm::Instance::loadF64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::offsetOfCachedStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::~Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::offsetOfSize): * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationCallback): (JSC::Wasm::Module::validateSync): (JSC::Wasm::Module::validateAsync): (JSC::Wasm::Module::getOrCreateCodeBlock): (JSC::Wasm::Module::compileSync): (JSC::Wasm::Module::compileAsync): * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseTableHelper): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::OMGPlan): (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::isValid const): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::runCompletionTasks): (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmPlan.h: (JSC::Wasm::Plan::dontFinalize): * wasm/WasmSignature.cpp: * wasm/WasmSignature.h: * wasm/WasmTable.cpp: Added. (JSC::Wasm::Table::create): (JSC::Wasm::Table::~Table): (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h. (JSC::Wasm::Table::maximum const): (JSC::Wasm::Table::size const): (JSC::Wasm::Table::offsetOfSize): (JSC::Wasm::Table::offsetOfFunctions): (JSC::Wasm::Table::offsetOfInstances): (JSC::Wasm::Table::isValidSize): * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): (JSC::Wasm::Thunks::setThrowWasmException): (JSC::Wasm::Thunks::throwWasmException): * wasm/WasmThunks.h: * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::stopAllPlansForContext): * wasm/WasmWorklist.h: * wasm/js/JSToWasm.cpp: Added. (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/JSWebAssembly.cpp: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.cpp. * wasm/js/JSWebAssembly.h: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.h. * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::create): (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::context const): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::webAssemblyToJSCallee): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::offsetOfTail): (JSC::JSWebAssemblyInstance::importFunctionInfo): (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): (JSC::JSWebAssemblyInstance::offsetOfImportFunction): (JSC::JSWebAssemblyInstance::importFunction): (JSC::JSWebAssemblyInstance::internalMemory): (JSC::JSWebAssemblyInstance::wasmCodeBlock const): (JSC::JSWebAssemblyInstance::offsetOfWasmTable): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::offsetOfGlobals): (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): (JSC::JSWebAssemblyInstance::cachedStackLimit const): (JSC::JSWebAssemblyInstance::setCachedStackLimit): (JSC::JSWebAssemblyInstance::wasmMemory): (JSC::JSWebAssemblyInstance::wasmModule): (JSC::JSWebAssemblyInstance::allocationSize): (JSC::JSWebAssemblyInstance::module const): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::create): (JSC::JSWebAssemblyMemory::adopt): (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::moduleInformation const): (JSC::JSWebAssemblyModule::exportSymbolTable const): (JSC::JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace const): (JSC::JSWebAssemblyModule::callee const): (JSC::JSWebAssemblyModule::codeBlock): (JSC::JSWebAssemblyModule::module): * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::create): (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::visitChildren): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::getFunction): (JSC::JSWebAssemblyTable::clearFunction): (JSC::JSWebAssemblyTable::setFunction): * wasm/js/JSWebAssemblyTable.h: (JSC::JSWebAssemblyTable::isValidSize): (JSC::JSWebAssemblyTable::maximum const): (JSC::JSWebAssemblyTable::size const): (JSC::JSWebAssemblyTable::table): * wasm/js/WasmToJS.cpp: Copied from Source/JavaScriptCore/wasm/WasmBinding.cpp. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): (JSC::WebAssemblyModuleConstructor::createModule): * wasm/js/WebAssemblyModuleConstructor.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::webAssemblyCompileFunc): (JSC::instantiate): (JSC::compileAndInstantiate): (JSC::webAssemblyValidateFunc): * wasm/js/WebAssemblyTableConstructor.cpp: (JSC::constructJSWebAssemblyTable): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Source/WebCore: * ForwardingHeaders/wasm/WasmModule.h: Added. This used to be included in JSWebAssemblyModule.h. * bindings/js/SerializedScriptValue.cpp: Update postMessage code according to C++ API changes. Canonical link: https://commits.webkit.org/194750@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223738 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-20 02:23:29 +00:00
static ptrdiff_t offsetOfCachedStackLimit() { return OBJECT_OFFSETOF(Instance, m_cachedStackLimit); }
WebAssembly: restore cached stack limit after out-call https://bugs.webkit.org/show_bug.cgi?id=179106 <rdar://problem/35337525> Reviewed by Saam Barati. JSTests: * wasm/function-tests/double-instance.js: Added. (const.imp.boom): (const.imp.get callAnother): Source/JavaScriptCore: We cache the stack limit on the Instance so that we can do fast stack checks where required. In regular usage the stack limit never changes because we always run on the same thread, but in rare cases an API user can totally migrate which thread (and therefore stack) is used for execution between WebAssembly traces. For that reason we set the cached stack limit to UINTPTR_MAX on the outgoing Instance when transitioning back into a different Instance. We usually restore the cached stack limit in Context::store, but this wasn't called on all code paths. We had a bug where an Instance calling into itself indirectly would therefore fail to restore its cached stack limit properly. This patch therefore restores the cached stack limit after direct calls which could be to imports (both wasm->wasm and wasm->embedder). We have to do all of them because we have no way of knowing what imports will do (they're known at instantiation time, not compilation time, and different instances can have different imports). To make this efficient we also add a pointer to the canonical location of the stack limit (i.e. the extra indirection we're trying to save by caching the stack limit on the Instance in the first place). This is potentially a small perf hit on imported direct calls. It's hard to say what the performance cost will be because we haven't seen much code in the wild which does this. We're adding two dependent loads and a store of the loaded value, which is unlikely to get used soon after. It's more code, but on an out-of-order processor it doesn't contribute to the critical path. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): * wasm/WasmInstance.h: (JSC::Wasm::Instance::offsetOfPointerToActualStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::create): * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): Canonical link: https://commits.webkit.org/196260@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225411 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-01 21:58:36 +00:00
void* cachedStackLimit() const
{
ASSERT(*m_pointerToActualStackLimit == m_cachedStackLimit);
return m_cachedStackLimit;
}
void setCachedStackLimit(void* limit)
{
ASSERT(*m_pointerToActualStackLimit == limit || bitwise_cast<void*>(std::numeric_limits<uintptr_t>::max()) == limit);
m_cachedStackLimit = limit;
}
WebAssembly: no VM / JS version of everything but Instance https://bugs.webkit.org/show_bug.cgi?id=177473 Reviewed by Filip Pizlo, Saam Barati. JSTests: - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. * wasm/js-api/memory-grow.js: (assertEq): * wasm/js-api/table.js: (assert.throws): Source/JavaScriptCore: This change entails cleaning up and splitting a bunch of code which we had intertwined between C++ classes which represent JS objects, and pure C++ implementation objects. This specific change goes most of the way towards allowing JSC's WebAssembly to work without VM / JS, up to but excluding JSWebAssemblyInstance (there's Wasm::Instance, but it's not *the* thing yet). Because of this we still have a few FIXME identifying places that need to change. A follow-up change will go the rest of the way. I went about this change in the simplest way possible: grep the JavaScriptCore/wasm directory for "JS[^C_]" as well as "VM" and exclude the /js/ sub-directory (which contains the JS implementation of WebAssembly). None of this change removes the need for a JIT entitlement to be able to use WebAssembly. We don't have an interpreter, the process therefore still needs to be allowed to JIT to use these pure-C++ APIs. Interesting things to note: - Remove VM from Plan and associated places. It can just live as a capture in the callback lambda if it's needed. - Wasm::Memory shouldn't require a VM. It was only used to ask the GC to collect. We now instead pass two lambdas at construction time for this purpose: one to notify of memory pressure, and the other to ask for syncrhonous memory reclamation. This allows whoever creates the memory to dictate how to react to both these cases, and for a JS embedding that's to call the GC (async or sync, respectively). - Move grow logic from JSWebAssemblyMemory to Wasm::Memory::grow. Use Expected there, with an enum class for failure types. - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. - When generating the grow_memory opcode, no need to get the VM. Instead, reach directly for Wasm::Memory and grow it. - JSWebAssemblyMemory::grow can now always throw on failure, because it's only ever called from JS (not from grow_memory as before). - Wasm::Memory now takes a callback for successful growth. This allows JS wrappers to register themselves when growth succeeds without Wasm::Memory knowning anything about JS. It'll also allow creating a list of callbacks for when we add thread support (we'll want to notify many wrappers, all under a lock). - Wasm::Memory is now back to being the source of truth about address / size, used directly by generated code instead of JSWebAssemblyMemory. - Move wasmToJS from the general WasmBinding header to its own header under wasm/js. It's only used by wasm/js/JSWebAssemblyCodeBlock.cpp, and uses VM, and therefore isn't general WebAssembly. - Make Wasm::Context an actual type (just a struct holding a JSWebAssemlyInstance for now) instead of an alias for that. Notably this doesn't add anything to the Context and doesn't change what actually gets passed around in JIT code (fast TLS or registers) because these changes potentially impact performance. The entire purpose of this change is to allow passing Wasm::Context around without having to know about VM. Since VM contains a Wasm::Context the JS embedding is effectively the same, but with this setup a non-JS embedding is much better off. - Move JSWebAssembly into the JS folder. - OMGPlan: use Wasm::CodeBlock directly instead of JSWebAssemblyCodeBlock. - wasm->JS stubs are now on the instance's tail as raw pointers, instead of being on JSWebAssemblyCodeBlock, and are now called wasm->Embedder stubs. The owned reference is still on JSWebAssemblyCodeBlock, and is still called wasm->JS stub. This move means that the embedder must, after creating a Wasm::CodeBlock, somehow create the stubs to call back into the embedder. This removes an indirection in the generated code because the B3 IR generator now reaches into the instance instead of JSWebAssemblyCodeBlock. - Move more CodeBlock things. Compilation completion is now marked by its own atomic<bool> flag instead of a nullptr plan: that required using a lock, and was causing a deadlock in stack-trace.js because before my changes JSWebAssemblyCodeBlock did its own completion checking separately from Wasm::CodeBlock, without getting the lock. Now that everything points to Wasm::CodeBlock and there's no cached completion marker, the lock was being acquired in a sanity-check assertion. - Embedder -> Wasm wrappers are now generated through a function that's passed in at compilation time, instead of being hard-coded as a JS -> Wasm wrapper. - WasmMemory doens't need to know about fault handling thunks. Only the IR generator should know, and should make sure that the exception throwing thunk is generated if any memory is present (note: with signal handling not all of them generate an exception check). - Make exception throwing pluggable: instead of having a hard-coded JS-specific lambda we now have a regular C++ function being called from JIT code when a WebAssembly exception is thrown. This allows any embedder to get called as they wish. For now a process can only have a single of these functions (i.e. only one embedder per process) because the trap handler is a singleton. That can be fixed in in #177475. - Create WasmEmbedder.h where all embedder plugging will live. - Split up JSWebAssemblyTable into Wasm::Table which is refcounted. JSWebAssemblyTable now only contains the JS functions in the table, and Wasm::Table is what's used by the JIT code to lookup where to call and do the instance check (for context switch). Note that this creates an extra allocation for all the instances in Wasm::Table, and in exchange removes an indirection in JIT code because the instance used to be obtained off of the JS function. Also note that it's the embedder than keeps the instances alive, not Wasm::Table (which holds a dumb pointer to the instance), because doing otherwise would cause reference cycles. - Add WasmInstance. It doesn't do much for now, owns globals. - JSWebAssembly instance now doesn't just contain the imported functions as JSObjects, it also has the corresponding import's instance and wasm entrypoint. This triples the space allocated per instance's imported function, but there shouldn't be that many imports. This has two upsides: it creates smaller and faster code, and makes is easier to disassociate embedder-specific things from embedder-neutral things. The small / faster win is in two places: B3 IR generator only needs offsetOfImportFunction for the call opcode (when the called index is an import) to know whether the import is wasm->wasm or wasm->embedder (this isn't known at compile-time because it's dependent on the import object), this is now done by seeing if that import function has an associated target instance (only wasm->wasm does); the other place is wasmBinding which uses offsetOfImportFunction to figure out the wasm->wasm target instance, and then gets WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation to do a tail call. The disassociation comes because the target instance can be Wasm::Instance once we change what the Context is, and WasmEntrypointLoadLocation is already embedder-independent. As a next step I can move this tail allocation from JSWebAssemblyInstance to Wasm::Instance, and leave importFunction in as an opaque pointer which is embedder-specific, and in JS will remain WriteBarrier<JSObject>. - Rename VMEntryFrame to EntryFrame, and in many places pass a pointer to it around instead of VM. This is a first step in allowing entry frames which aren't stored on VM, but which are instead stored in an embedder-specific location. That change won't really affect JS except through code churn, but will allow WebAssembly to use some machinery in a generic manner without having a VM. * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * debugger/Debugger.cpp: (JSC::Debugger::stepOutOfFunction): (JSC::Debugger::returnEvent): (JSC::Debugger::unwindEvent): (JSC::Debugger::didExecuteProgram): * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::compileExceptionHandlers): * dfg/DFGOSREntry.cpp: (JSC::DFG::prepareOSREntry): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::compileOSRExit): (JSC::DFG::OSRExit::compileExit): * dfg/DFGThunks.cpp: (JSC::DFG::osrEntryThunkGenerator): * ftl/FTLCompile.cpp: (JSC::FTL::compile): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::lower): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): (JSC::CallFrame::callerFrame): (JSC::CallFrame::unsafeCallerFrame): * interpreter/CallFrame.h: (JSC::ExecState::callerFrame const): (JSC::ExecState::callerFrameOrEntryFrame const): (JSC::ExecState::unsafeCallerFrameOrEntryFrame const): * interpreter/FrameTracers.h: (JSC::NativeCallFrameTracer::NativeCallFrameTracer): (JSC::NativeCallFrameTracerWithRestore::NativeCallFrameTracerWithRestore): (JSC::NativeCallFrameTracerWithRestore::~NativeCallFrameTracerWithRestore): * interpreter/Interpreter.cpp: (JSC::UnwindFunctor::operator() const): (JSC::UnwindFunctor::copyCalleeSavesToEntryFrameCalleeSavesBuffer const): (JSC::Interpreter::unwind): * interpreter/StackVisitor.cpp: (JSC::StackVisitor::StackVisitor): (JSC::StackVisitor::gotoNextFrame): (JSC::StackVisitor::readNonInlinedFrame): (JSC::StackVisitor::Frame::dump const): * interpreter/StackVisitor.h: (JSC::StackVisitor::Frame::callerIsEntryFrame const): * interpreter/VMEntryRecord.h: (JSC::VMEntryRecord::prevTopEntryFrame): (JSC::VMEntryRecord::unsafePrevTopEntryFrame): (JSC::EntryFrame::vmEntryRecordOffset): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::restoreCalleeSavesFromEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::loadWasmContextInstance): (JSC::AssemblyHelpers::storeWasmContextInstance): (JSC::AssemblyHelpers::loadWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::storeWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBufferImpl): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::copyCalleeSavesToVMEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer): * jit/JIT.cpp: (JSC::JIT::emitEnterOptimizationCheck): (JSC::JIT::privateCompileExceptionHandlers): * jit/JITExceptions.cpp: (JSC::genericUnwind): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): (JSC::JIT::emitSlow_op_loop_hint): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): * jit/JITOperations.cpp: * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::nativeForGenerator): * jsc.cpp: (functionDumpCallFrame): * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LLIntThunks.cpp: (JSC::vmEntryRecord): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/Options.cpp: (JSC::recomputeDependentOptions): * runtime/Options.h: * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::FrameWalker): (JSC::FrameWalker::advanceToParentFrame): (JSC::SamplingProfiler::processUnverifiedStackTraces): * runtime/ThrowScope.cpp: (JSC::ThrowScope::~ThrowScope): * runtime/VM.cpp: (JSC::VM::VM): (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::topEntryFrameOffset): * runtime/VMTraps.cpp: (JSC::isSaneFrame): (JSC::VMTraps::tryInstallTrapBreakpoints): (JSC::VMTraps::invalidateCodeBlocksOnStack): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWasmContextInstance): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::parseAndCompile): * wasm/WasmB3IRGenerator.h: * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::BBQPlan): (JSC::Wasm::BBQPlan::compileFunctions): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBBQPlanInlines.h: (JSC::Wasm::BBQPlan::initializeCallees): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmBinding.h: * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::create): (JSC::Wasm::CodeBlock::CodeBlock): (JSC::Wasm::CodeBlock::compileAsync): (JSC::Wasm::CodeBlock::setCompilationFinished): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::offsetOfImportStubs): (JSC::Wasm::CodeBlock::allocationSize): (JSC::Wasm::CodeBlock::importWasmToEmbedderStub): (JSC::Wasm::CodeBlock::offsetOfImportWasmToEmbedderStub): (JSC::Wasm::CodeBlock::wasmToJSCallStubForImport): (JSC::Wasm::CodeBlock::compilationFinished): (JSC::Wasm::CodeBlock::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): * wasm/WasmContext.cpp: (JSC::Wasm::Context::useFastTLS): (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: Copied from Source/JavaScriptCore/wasm/WasmContext.h. * wasm/WasmFaultSignalHandler.cpp: * wasm/WasmFaultSignalHandler.h: * wasm/WasmFormat.h: * wasm/WasmInstance.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::~Instance): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: Added. (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::module): (JSC::Wasm::Instance::codeBlock): (JSC::Wasm::Instance::memory): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::loadF32Global const): (JSC::Wasm::Instance::loadF64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::offsetOfCachedStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::~Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::offsetOfSize): * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationCallback): (JSC::Wasm::Module::validateSync): (JSC::Wasm::Module::validateAsync): (JSC::Wasm::Module::getOrCreateCodeBlock): (JSC::Wasm::Module::compileSync): (JSC::Wasm::Module::compileAsync): * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseTableHelper): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::OMGPlan): (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::isValid const): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::runCompletionTasks): (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmPlan.h: (JSC::Wasm::Plan::dontFinalize): * wasm/WasmSignature.cpp: * wasm/WasmSignature.h: * wasm/WasmTable.cpp: Added. (JSC::Wasm::Table::create): (JSC::Wasm::Table::~Table): (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h. (JSC::Wasm::Table::maximum const): (JSC::Wasm::Table::size const): (JSC::Wasm::Table::offsetOfSize): (JSC::Wasm::Table::offsetOfFunctions): (JSC::Wasm::Table::offsetOfInstances): (JSC::Wasm::Table::isValidSize): * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): (JSC::Wasm::Thunks::setThrowWasmException): (JSC::Wasm::Thunks::throwWasmException): * wasm/WasmThunks.h: * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::stopAllPlansForContext): * wasm/WasmWorklist.h: * wasm/js/JSToWasm.cpp: Added. (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/JSWebAssembly.cpp: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.cpp. * wasm/js/JSWebAssembly.h: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.h. * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::create): (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::context const): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::webAssemblyToJSCallee): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::offsetOfTail): (JSC::JSWebAssemblyInstance::importFunctionInfo): (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): (JSC::JSWebAssemblyInstance::offsetOfImportFunction): (JSC::JSWebAssemblyInstance::importFunction): (JSC::JSWebAssemblyInstance::internalMemory): (JSC::JSWebAssemblyInstance::wasmCodeBlock const): (JSC::JSWebAssemblyInstance::offsetOfWasmTable): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::offsetOfGlobals): (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): (JSC::JSWebAssemblyInstance::cachedStackLimit const): (JSC::JSWebAssemblyInstance::setCachedStackLimit): (JSC::JSWebAssemblyInstance::wasmMemory): (JSC::JSWebAssemblyInstance::wasmModule): (JSC::JSWebAssemblyInstance::allocationSize): (JSC::JSWebAssemblyInstance::module const): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::create): (JSC::JSWebAssemblyMemory::adopt): (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::moduleInformation const): (JSC::JSWebAssemblyModule::exportSymbolTable const): (JSC::JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace const): (JSC::JSWebAssemblyModule::callee const): (JSC::JSWebAssemblyModule::codeBlock): (JSC::JSWebAssemblyModule::module): * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::create): (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::visitChildren): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::getFunction): (JSC::JSWebAssemblyTable::clearFunction): (JSC::JSWebAssemblyTable::setFunction): * wasm/js/JSWebAssemblyTable.h: (JSC::JSWebAssemblyTable::isValidSize): (JSC::JSWebAssemblyTable::maximum const): (JSC::JSWebAssemblyTable::size const): (JSC::JSWebAssemblyTable::table): * wasm/js/WasmToJS.cpp: Copied from Source/JavaScriptCore/wasm/WasmBinding.cpp. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): (JSC::WebAssemblyModuleConstructor::createModule): * wasm/js/WebAssemblyModuleConstructor.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::webAssemblyCompileFunc): (JSC::instantiate): (JSC::compileAndInstantiate): (JSC::webAssemblyValidateFunc): * wasm/js/WebAssemblyTableConstructor.cpp: (JSC::constructJSWebAssemblyTable): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Source/WebCore: * ForwardingHeaders/wasm/WasmModule.h: Added. This used to be included in JSWebAssemblyModule.h. * bindings/js/SerializedScriptValue.cpp: Update postMessage code according to C++ API changes. Canonical link: https://commits.webkit.org/194750@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223738 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-20 02:23:29 +00:00
WebAssembly: no VM / JS version of our implementation https://bugs.webkit.org/show_bug.cgi?id=177472 Reviewed by Michael Saboff. This patch removes all appearances of "JS" and "VM" in the wasm directory. These now only appear in the wasm/js directory, which is only used in a JS embedding of wasm. It should therefore now be possible to create non-JS embeddings of wasm through JSC, though it'll still require: - Mild codegen for wasm<->embedder calls; - A strategy for trap handling (no need for full unwind! Could kill). - Creation of the Wasm::* objects. - Calling convention handling to call the embedder. - Handling of multiple embedders (see #177475, this is optional). Most of the patch consists in renaming JSWebAssemblyInstance to Instance, and removing temporary copies which I'd added to make this specific patch very simple. * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): this one place which needs to know about who "owns" the Wasm::Instance. In a JS embedding it's the JSWebAssemblyInstance. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::getGlobal): (JSC::Wasm::B3IRGenerator::setGlobal): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmContext.cpp: (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: add an "owner", the Wasm::Context, move the "tail" import information from JSWebAssemblyInstance over to here. (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::owner const): (JSC::Wasm::Instance::offsetOfOwner): (JSC::Wasm::Instance::context const): (JSC::Wasm::Instance::setMemory): (JSC::Wasm::Instance::setTable): (JSC::Wasm::Instance::offsetOfMemory): (JSC::Wasm::Instance::offsetOfGlobals): (JSC::Wasm::Instance::offsetOfTable): (JSC::Wasm::Instance::offsetOfTail): (JSC::Wasm::Instance::numImportFunctions const): (JSC::Wasm::Instance::importFunctionInfo): (JSC::Wasm::Instance::offsetOfTargetInstance): (JSC::Wasm::Instance::offsetOfWasmEntrypoint): (JSC::Wasm::Instance::offsetOfWasmToEmbedderStubExecutableAddress): (JSC::Wasm::Instance::offsetOfImportFunction): (JSC::Wasm::Instance::importFunction): (JSC::Wasm::Instance::allocationSize): (JSC::Wasm::Instance::create): Deleted. * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmTable.cpp: (JSC::Wasm::Table::Table): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyInstance.cpp: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): The embedder decides what the import function is. Here we must properly placement-new it to what we've elected (and initialize it later). (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::moduleNamespaceObject): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::setTable): (JSC::JSWebAssemblyInstance::offsetOfInstance): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::context const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTail): Deleted. (): Deleted. (JSC::JSWebAssemblyInstance::importFunctionInfo): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmToEmbedderStubExecutableAddress): Deleted. (JSC::JSWebAssemblyInstance::offsetOfImportFunction): Deleted. (JSC::JSWebAssemblyInstance::importFunction): Deleted. (JSC::JSWebAssemblyInstance::internalMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmCodeBlock const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmTable): Deleted. (JSC::JSWebAssemblyInstance::offsetOfGlobals): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTopEntryFramePointer): Deleted. (JSC::JSWebAssemblyInstance::cachedStackLimit const): Deleted. (JSC::JSWebAssemblyInstance::setCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::wasmMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmModule): Deleted. (JSC::JSWebAssemblyInstance::allocationSize): Deleted. * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::setFunction): * wasm/js/WasmToJS.cpp: One extra indirection to find the JSWebAssemblyInstance. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::instantiate): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Canonical link: https://commits.webkit.org/195012@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224020 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-26 15:33:55 +00:00
// Tail accessors.
[WASM-References] Add support for multiple tables https://bugs.webkit.org/show_bug.cgi?id=198760 Reviewed by Saam Barati. JSTests: * wasm/Builder.js: * wasm/js-api/call-indirect.js: (const.oneTable): (const.multiTable): (multiTable): (multiTable.Polyphic2Import): (multiTable.VirtualImport): (const.wasmModuleWhichImportJS): Deleted. (const.makeTable): Deleted. (): Deleted. (Polyphic2Import): Deleted. (VirtualImport): Deleted. * wasm/js-api/table.js: (new.WebAssembly.Module): (assert.throws): (assertBadTableImport): (assert.truthy): (assert.throws.new.WebAssembly.Module.builder.WebAssembly): Deleted. * wasm/references/anyref_table.js: * wasm/references/anyref_table_import.js: (makeImport): (string_appeared_here.fullGC.assert.eq.1.exports.get_tbl.makeImport): (string_appeared_here.fullGC.assert.eq.1.exports.get_tbl): * wasm/references/multitable.js: Added. (assert.throws.1.exports.set_tbl0): (assert.throws): (assert.eq): * wasm/references/validation.js: (assert.throws.new.WebAssembly.Module.bin): (assert.throws): * wasm/spec-tests/imports.wast.js: * wasm/wasm.json: * wasm/Builder.js: * wasm/js-api/call-indirect.js: (const.oneTable): (const.multiTable): (multiTable): (multiTable.Polyphic2Import): (multiTable.VirtualImport): (const.wasmModuleWhichImportJS): Deleted. (const.makeTable): Deleted. (): Deleted. (Polyphic2Import): Deleted. (VirtualImport): Deleted. * wasm/js-api/table.js: (new.WebAssembly.Module): (assert.throws): (assertBadTableImport): (assert.truthy): (assert.throws.new.WebAssembly.Module.builder.WebAssembly): Deleted. * wasm/references/anyref_table.js: * wasm/references/anyref_table_import.js: (makeImport): (string_appeared_here.fullGC.assert.eq.1.exports.get_tbl.makeImport): (string_appeared_here.fullGC.assert.eq.1.exports.get_tbl): * wasm/references/func_ref.js: (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly.fun): Deleted. (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly.assert.throws): Deleted. (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly): Deleted. * wasm/references/multitable.js: Added. (assert.throws.1.exports.set_tbl0): (assert.throws): (assert.eq): (string_appeared_here.tableInsanity): (I32Const.0.GetLocal.0.TableSet.1.End.End.WebAssembly.): (I32Const.0.GetLocal.0.TableSet.1.End.End.WebAssembly): * wasm/references/validation.js: (assert.throws.new.WebAssembly.Module.bin): (assert.throws): * wasm/spec-tests/imports.wast.js: * wasm/wasm.json: Source/JavaScriptCore: Support multiple wasm tables. We turn tableInformation into a tables array, and update all of the existing users to give a table index. The array of Tables in Wasm::Instance is hung off the tail to make it easier to use from jit code. * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::AirIRGenerator): (JSC::Wasm::AirIRGenerator::addTableGet): (JSC::Wasm::AirIRGenerator::addTableSet): (JSC::Wasm::AirIRGenerator::addCallIndirect): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::addTableGet): (JSC::Wasm::B3IRGenerator::addTableSet): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmExceptionType.h: * wasm/WasmFormat.h: (JSC::Wasm::Element::Element): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parseExpression): (JSC::Wasm::FunctionParser<Context>::parseUnreachableExpression): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::extraMemoryAllocated const): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::setTable): * wasm/WasmInstance.h: (JSC::Wasm::Instance::updateCachedMemory): (JSC::Wasm::Instance::offsetOfGlobals): (JSC::Wasm::Instance::offsetOfTablePtr): (JSC::Wasm::Instance::allocationSize): (JSC::Wasm::Instance::table): Deleted. (JSC::Wasm::Instance::setTable): Deleted. (JSC::Wasm::Instance::offsetOfTable): Deleted. * wasm/WasmModuleInformation.h: (JSC::Wasm::ModuleInformation::tableCount const): * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseImport): (JSC::Wasm::SectionParser::parseTableHelper): (JSC::Wasm::SectionParser::parseTable): (JSC::Wasm::SectionParser::parseElement): * wasm/WasmTable.h: (JSC::Wasm::Table::owner const): * wasm/WasmValidate.cpp: (JSC::Wasm::Validate::addTableGet): (JSC::Wasm::Validate::addTableSet): (JSC::Wasm::Validate::addCallIndirect): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/JSWebAssemblyInstance.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/wasm.json: Canonical link: https://commits.webkit.org/212963@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@246571 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-06-18 22:01:02 +00:00
static constexpr size_t offsetOfTail() { return WTF::roundUpToMultipleOf<sizeof(uint64_t)>(sizeof(Instance)); }
WebAssembly: no VM / JS version of our implementation https://bugs.webkit.org/show_bug.cgi?id=177472 Reviewed by Michael Saboff. This patch removes all appearances of "JS" and "VM" in the wasm directory. These now only appear in the wasm/js directory, which is only used in a JS embedding of wasm. It should therefore now be possible to create non-JS embeddings of wasm through JSC, though it'll still require: - Mild codegen for wasm<->embedder calls; - A strategy for trap handling (no need for full unwind! Could kill). - Creation of the Wasm::* objects. - Calling convention handling to call the embedder. - Handling of multiple embedders (see #177475, this is optional). Most of the patch consists in renaming JSWebAssemblyInstance to Instance, and removing temporary copies which I'd added to make this specific patch very simple. * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): this one place which needs to know about who "owns" the Wasm::Instance. In a JS embedding it's the JSWebAssemblyInstance. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::getGlobal): (JSC::Wasm::B3IRGenerator::setGlobal): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmContext.cpp: (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: add an "owner", the Wasm::Context, move the "tail" import information from JSWebAssemblyInstance over to here. (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::owner const): (JSC::Wasm::Instance::offsetOfOwner): (JSC::Wasm::Instance::context const): (JSC::Wasm::Instance::setMemory): (JSC::Wasm::Instance::setTable): (JSC::Wasm::Instance::offsetOfMemory): (JSC::Wasm::Instance::offsetOfGlobals): (JSC::Wasm::Instance::offsetOfTable): (JSC::Wasm::Instance::offsetOfTail): (JSC::Wasm::Instance::numImportFunctions const): (JSC::Wasm::Instance::importFunctionInfo): (JSC::Wasm::Instance::offsetOfTargetInstance): (JSC::Wasm::Instance::offsetOfWasmEntrypoint): (JSC::Wasm::Instance::offsetOfWasmToEmbedderStubExecutableAddress): (JSC::Wasm::Instance::offsetOfImportFunction): (JSC::Wasm::Instance::importFunction): (JSC::Wasm::Instance::allocationSize): (JSC::Wasm::Instance::create): Deleted. * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmTable.cpp: (JSC::Wasm::Table::Table): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyInstance.cpp: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): The embedder decides what the import function is. Here we must properly placement-new it to what we've elected (and initialize it later). (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::moduleNamespaceObject): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::setTable): (JSC::JSWebAssemblyInstance::offsetOfInstance): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::context const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTail): Deleted. (): Deleted. (JSC::JSWebAssemblyInstance::importFunctionInfo): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmToEmbedderStubExecutableAddress): Deleted. (JSC::JSWebAssemblyInstance::offsetOfImportFunction): Deleted. (JSC::JSWebAssemblyInstance::importFunction): Deleted. (JSC::JSWebAssemblyInstance::internalMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmCodeBlock const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmTable): Deleted. (JSC::JSWebAssemblyInstance::offsetOfGlobals): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTopEntryFramePointer): Deleted. (JSC::JSWebAssemblyInstance::cachedStackLimit const): Deleted. (JSC::JSWebAssemblyInstance::setCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::wasmMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmModule): Deleted. (JSC::JSWebAssemblyInstance::allocationSize): Deleted. * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::setFunction): * wasm/js/WasmToJS.cpp: One extra indirection to find the JSWebAssemblyInstance. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::instantiate): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Canonical link: https://commits.webkit.org/195012@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224020 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-26 15:33:55 +00:00
struct ImportFunctionInfo {
// Target instance and entrypoint are only set for wasm->wasm calls, and are otherwise nullptr. The embedder-specific logic occurs through import function.
Instance* targetInstance { nullptr };
Use MacroAssemblerCodePtr in Wasm code for code pointers instead of void*. https://bugs.webkit.org/show_bug.cgi?id=184163 <rdar://problem/39020397> Reviewed by JF Bastien. With the use of MacroAssemblerCodePtr, we now get poisoning for Wasm code pointers. Also renamed some structs, methods, and variable names to be more accurate. Previously, there is some confusion between a code pointer and the address of a code pointer (sometimes referred to in the code as a "LoadLocation"). We now name the LoadLocation variables appropriately to distinguish them from code pointers. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::CodeBlock): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::entrypointLoadLocationFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointLoadLocationFromFunctionIndexSpace): Deleted. * wasm/WasmFormat.h: (JSC::Wasm::WasmToWasmImportableFunction::WasmToWasmImportableFunction): (JSC::Wasm::WasmToWasmImportableFunction::offsetOfEntrypointLoadLocation): (JSC::Wasm::CallableFunction::CallableFunction): Deleted. (JSC::Wasm::CallableFunction::offsetOfWasmEntrypointLoadLocation): Deleted. * wasm/WasmInstance.h: (JSC::Wasm::Instance::offsetOfWasmEntrypointLoadLocation): (JSC::Wasm::Instance::offsetOfWasmToEmbedderStub): (JSC::Wasm::Instance::offsetOfWasmEntrypoint): Deleted. (JSC::Wasm::Instance::offsetOfWasmToEmbedderStubExecutableAddress): Deleted. * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::work): * wasm/WasmTable.cpp: (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: (JSC::Wasm::Table::offsetOfFunctions): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::setFunction): * wasm/js/WebAssemblyFunction.cpp: (JSC::WebAssemblyFunction::create): (JSC::WebAssemblyFunction::WebAssemblyFunction): * wasm/js/WebAssemblyFunction.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::WebAssemblyWrapperFunction): (JSC::WebAssemblyWrapperFunction::create): * wasm/js/WebAssemblyWrapperFunction.h: Canonical link: https://commits.webkit.org/199724@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230096 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-03-30 05:04:44 +00:00
WasmToWasmImportableFunction::LoadLocation wasmEntrypointLoadLocation { nullptr };
Templatize CodePtr/Refs/FunctionPtrs with PtrTags. https://bugs.webkit.org/show_bug.cgi?id=184702 <rdar://problem/35391681> Reviewed by Filip Pizlo and Saam Barati. Source/JavaScriptCore: 1. Templatized MacroAssemblerCodePtr/Ref, FunctionPtr, and CodeLocation variants to take a PtrTag template argument. 2. Replaced some uses of raw pointers with the equivalent CodePtr / FunctionPtr. * assembler/AbstractMacroAssembler.h: (JSC::AbstractMacroAssembler::differenceBetweenCodePtr): (JSC::AbstractMacroAssembler::linkJump): (JSC::AbstractMacroAssembler::linkPointer): (JSC::AbstractMacroAssembler::getLinkerAddress): (JSC::AbstractMacroAssembler::repatchJump): (JSC::AbstractMacroAssembler::repatchJumpToNop): (JSC::AbstractMacroAssembler::repatchNearCall): (JSC::AbstractMacroAssembler::repatchCompact): (JSC::AbstractMacroAssembler::repatchInt32): (JSC::AbstractMacroAssembler::repatchPointer): (JSC::AbstractMacroAssembler::readPointer): (JSC::AbstractMacroAssembler::replaceWithLoad): (JSC::AbstractMacroAssembler::replaceWithAddressComputation): * assembler/CodeLocation.h: (JSC::CodeLocationCommon:: const): (JSC::CodeLocationCommon::CodeLocationCommon): (JSC::CodeLocationInstruction::CodeLocationInstruction): (JSC::CodeLocationLabel::CodeLocationLabel): (JSC::CodeLocationLabel::retagged): (JSC::CodeLocationLabel:: const): (JSC::CodeLocationJump::CodeLocationJump): (JSC::CodeLocationJump::retagged): (JSC::CodeLocationCall::CodeLocationCall): (JSC::CodeLocationCall::retagged): (JSC::CodeLocationNearCall::CodeLocationNearCall): (JSC::CodeLocationDataLabel32::CodeLocationDataLabel32): (JSC::CodeLocationDataLabelCompact::CodeLocationDataLabelCompact): (JSC::CodeLocationDataLabelPtr::CodeLocationDataLabelPtr): (JSC::CodeLocationConvertibleLoad::CodeLocationConvertibleLoad): (JSC::CodeLocationCommon<tag>::instructionAtOffset): (JSC::CodeLocationCommon<tag>::labelAtOffset): (JSC::CodeLocationCommon<tag>::jumpAtOffset): (JSC::CodeLocationCommon<tag>::callAtOffset): (JSC::CodeLocationCommon<tag>::nearCallAtOffset): (JSC::CodeLocationCommon<tag>::dataLabelPtrAtOffset): (JSC::CodeLocationCommon<tag>::dataLabel32AtOffset): (JSC::CodeLocationCommon<tag>::dataLabelCompactAtOffset): (JSC::CodeLocationCommon<tag>::convertibleLoadAtOffset): (JSC::CodeLocationCommon::instructionAtOffset): Deleted. (JSC::CodeLocationCommon::labelAtOffset): Deleted. (JSC::CodeLocationCommon::jumpAtOffset): Deleted. (JSC::CodeLocationCommon::callAtOffset): Deleted. (JSC::CodeLocationCommon::nearCallAtOffset): Deleted. (JSC::CodeLocationCommon::dataLabelPtrAtOffset): Deleted. (JSC::CodeLocationCommon::dataLabel32AtOffset): Deleted. (JSC::CodeLocationCommon::dataLabelCompactAtOffset): Deleted. (JSC::CodeLocationCommon::convertibleLoadAtOffset): Deleted. * assembler/LinkBuffer.cpp: (JSC::LinkBuffer::finalizeCodeWithoutDisassemblyImpl): (JSC::LinkBuffer::finalizeCodeWithDisassemblyImpl): (JSC::LinkBuffer::finalizeCodeWithoutDisassembly): Deleted. (JSC::LinkBuffer::finalizeCodeWithDisassembly): Deleted. * assembler/LinkBuffer.h: (JSC::LinkBuffer::link): (JSC::LinkBuffer::patch): (JSC::LinkBuffer::entrypoint): (JSC::LinkBuffer::locationOf): (JSC::LinkBuffer::locationOfNearCall): (JSC::LinkBuffer::finalizeCodeWithoutDisassembly): (JSC::LinkBuffer::finalizeCodeWithDisassembly): (JSC::LinkBuffer::trampolineAt): * assembler/MacroAssemblerARM.h: (JSC::MacroAssemblerARM::readCallTarget): (JSC::MacroAssemblerARM::replaceWithJump): (JSC::MacroAssemblerARM::startOfPatchableBranch32WithPatchOnAddress): (JSC::MacroAssemblerARM::startOfPatchableBranchPtrWithPatchOnAddress): (JSC::MacroAssemblerARM::startOfBranchPtrWithPatchOnRegister): (JSC::MacroAssemblerARM::revertJumpReplacementToBranchPtrWithPatch): (JSC::MacroAssemblerARM::revertJumpReplacementToPatchableBranch32WithPatch): (JSC::MacroAssemblerARM::revertJumpReplacementToPatchableBranchPtrWithPatch): (JSC::MacroAssemblerARM::repatchCall): (JSC::MacroAssemblerARM::linkCall): * assembler/MacroAssemblerARM64.h: (JSC::MacroAssemblerARM64::readCallTarget): (JSC::MacroAssemblerARM64::replaceWithVMHalt): (JSC::MacroAssemblerARM64::replaceWithJump): (JSC::MacroAssemblerARM64::startOfBranchPtrWithPatchOnRegister): (JSC::MacroAssemblerARM64::startOfPatchableBranchPtrWithPatchOnAddress): (JSC::MacroAssemblerARM64::startOfPatchableBranch32WithPatchOnAddress): (JSC::MacroAssemblerARM64::revertJumpReplacementToBranchPtrWithPatch): (JSC::MacroAssemblerARM64::revertJumpReplacementToPatchableBranchPtrWithPatch): (JSC::MacroAssemblerARM64::revertJumpReplacementToPatchableBranch32WithPatch): (JSC::MacroAssemblerARM64::repatchCall): (JSC::MacroAssemblerARM64::linkCall): * assembler/MacroAssemblerARMv7.h: (JSC::MacroAssemblerARMv7::replaceWithJump): (JSC::MacroAssemblerARMv7::readCallTarget): (JSC::MacroAssemblerARMv7::startOfBranchPtrWithPatchOnRegister): (JSC::MacroAssemblerARMv7::revertJumpReplacementToBranchPtrWithPatch): (JSC::MacroAssemblerARMv7::startOfPatchableBranchPtrWithPatchOnAddress): (JSC::MacroAssemblerARMv7::startOfPatchableBranch32WithPatchOnAddress): (JSC::MacroAssemblerARMv7::revertJumpReplacementToPatchableBranchPtrWithPatch): (JSC::MacroAssemblerARMv7::revertJumpReplacementToPatchableBranch32WithPatch): (JSC::MacroAssemblerARMv7::repatchCall): (JSC::MacroAssemblerARMv7::linkCall): * assembler/MacroAssemblerCodeRef.cpp: (JSC::MacroAssemblerCodePtrBase::dumpWithName): (JSC::MacroAssemblerCodeRefBase::tryToDisassemble): (JSC::MacroAssemblerCodeRefBase::disassembly): (JSC::MacroAssemblerCodePtr::createLLIntCodePtr): Deleted. (JSC::MacroAssemblerCodePtr::dumpWithName const): Deleted. (JSC::MacroAssemblerCodePtr::dump const): Deleted. (JSC::MacroAssemblerCodeRef::createLLIntCodeRef): Deleted. (JSC::MacroAssemblerCodeRef::tryToDisassemble const): Deleted. (JSC::MacroAssemblerCodeRef::disassembly const): Deleted. (JSC::MacroAssemblerCodeRef::dump const): Deleted. * assembler/MacroAssemblerCodeRef.h: (JSC::FunctionPtr::FunctionPtr): (JSC::FunctionPtr::retagged const): (JSC::FunctionPtr::retaggedExecutableAddress const): (JSC::FunctionPtr::operator== const): (JSC::FunctionPtr::operator!= const): (JSC::ReturnAddressPtr::ReturnAddressPtr): (JSC::MacroAssemblerCodePtr::MacroAssemblerCodePtr): (JSC::MacroAssemblerCodePtr::createFromExecutableAddress): (JSC::MacroAssemblerCodePtr::retagged const): (JSC::MacroAssemblerCodePtr:: const): (JSC::MacroAssemblerCodePtr::dumpWithName const): (JSC::MacroAssemblerCodePtr::dump const): (JSC::MacroAssemblerCodePtrHash::hash): (JSC::MacroAssemblerCodePtrHash::equal): (JSC::MacroAssemblerCodeRef::MacroAssemblerCodeRef): (JSC::MacroAssemblerCodeRef::createSelfManagedCodeRef): (JSC::MacroAssemblerCodeRef::code const): (JSC::MacroAssemblerCodeRef::retaggedCode const): (JSC::MacroAssemblerCodeRef::retagged const): (JSC::MacroAssemblerCodeRef::tryToDisassemble const): (JSC::MacroAssemblerCodeRef::disassembly const): (JSC::MacroAssemblerCodeRef::dump const): (JSC::FunctionPtr<tag>::FunctionPtr): * assembler/MacroAssemblerMIPS.h: (JSC::MacroAssemblerMIPS::readCallTarget): (JSC::MacroAssemblerMIPS::replaceWithJump): (JSC::MacroAssemblerMIPS::startOfPatchableBranch32WithPatchOnAddress): (JSC::MacroAssemblerMIPS::startOfBranchPtrWithPatchOnRegister): (JSC::MacroAssemblerMIPS::revertJumpReplacementToBranchPtrWithPatch): (JSC::MacroAssemblerMIPS::startOfPatchableBranchPtrWithPatchOnAddress): (JSC::MacroAssemblerMIPS::revertJumpReplacementToPatchableBranch32WithPatch): (JSC::MacroAssemblerMIPS::revertJumpReplacementToPatchableBranchPtrWithPatch): (JSC::MacroAssemblerMIPS::repatchCall): (JSC::MacroAssemblerMIPS::linkCall): * assembler/MacroAssemblerX86.h: (JSC::MacroAssemblerX86::readCallTarget): (JSC::MacroAssemblerX86::startOfBranchPtrWithPatchOnRegister): (JSC::MacroAssemblerX86::startOfPatchableBranchPtrWithPatchOnAddress): (JSC::MacroAssemblerX86::startOfPatchableBranch32WithPatchOnAddress): (JSC::MacroAssemblerX86::revertJumpReplacementToBranchPtrWithPatch): (JSC::MacroAssemblerX86::revertJumpReplacementToPatchableBranchPtrWithPatch): (JSC::MacroAssemblerX86::revertJumpReplacementToPatchableBranch32WithPatch): (JSC::MacroAssemblerX86::repatchCall): (JSC::MacroAssemblerX86::linkCall): * assembler/MacroAssemblerX86Common.h: (JSC::MacroAssemblerX86Common::repatchCompact): (JSC::MacroAssemblerX86Common::replaceWithVMHalt): (JSC::MacroAssemblerX86Common::replaceWithJump): * assembler/MacroAssemblerX86_64.h: (JSC::MacroAssemblerX86_64::readCallTarget): (JSC::MacroAssemblerX86_64::startOfBranchPtrWithPatchOnRegister): (JSC::MacroAssemblerX86_64::startOfBranch32WithPatchOnRegister): (JSC::MacroAssemblerX86_64::startOfPatchableBranchPtrWithPatchOnAddress): (JSC::MacroAssemblerX86_64::startOfPatchableBranch32WithPatchOnAddress): (JSC::MacroAssemblerX86_64::revertJumpReplacementToPatchableBranchPtrWithPatch): (JSC::MacroAssemblerX86_64::revertJumpReplacementToPatchableBranch32WithPatch): (JSC::MacroAssemblerX86_64::revertJumpReplacementToBranchPtrWithPatch): (JSC::MacroAssemblerX86_64::repatchCall): (JSC::MacroAssemblerX86_64::linkCall): * assembler/testmasm.cpp: (JSC::compile): (JSC::invoke): (JSC::testProbeModifiesProgramCounter): * b3/B3Compilation.cpp: (JSC::B3::Compilation::Compilation): * b3/B3Compilation.h: (JSC::B3::Compilation::code const): (JSC::B3::Compilation::codeRef const): * b3/B3Compile.cpp: (JSC::B3::compile): * b3/B3LowerMacros.cpp: * b3/air/AirDisassembler.cpp: (JSC::B3::Air::Disassembler::dump): * b3/air/testair.cpp: * b3/testb3.cpp: (JSC::B3::invoke): (JSC::B3::testInterpreter): (JSC::B3::testEntrySwitchSimple): (JSC::B3::testEntrySwitchNoEntrySwitch): (JSC::B3::testEntrySwitchWithCommonPaths): (JSC::B3::testEntrySwitchWithCommonPathsAndNonTrivialEntrypoint): (JSC::B3::testEntrySwitchLoop): * bytecode/AccessCase.cpp: (JSC::AccessCase::generateImpl): * bytecode/AccessCaseSnippetParams.cpp: (JSC::SlowPathCallGeneratorWithArguments::generateImpl): * bytecode/ByValInfo.h: (JSC::ByValInfo::ByValInfo): * bytecode/CallLinkInfo.cpp: (JSC::CallLinkInfo::callReturnLocation): (JSC::CallLinkInfo::patchableJump): (JSC::CallLinkInfo::hotPathBegin): (JSC::CallLinkInfo::slowPathStart): * bytecode/CallLinkInfo.h: (JSC::CallLinkInfo::setCallLocations): (JSC::CallLinkInfo::hotPathOther): * bytecode/CodeBlock.cpp: (JSC::CodeBlock::finishCreation): * bytecode/GetByIdStatus.cpp: (JSC::GetByIdStatus::computeForStubInfoWithoutExitSiteFeedback): * bytecode/GetByIdVariant.cpp: (JSC::GetByIdVariant::GetByIdVariant): (JSC::GetByIdVariant::dumpInContext const): * bytecode/GetByIdVariant.h: (JSC::GetByIdVariant::customAccessorGetter const): * bytecode/GetterSetterAccessCase.cpp: (JSC::GetterSetterAccessCase::create): (JSC::GetterSetterAccessCase::GetterSetterAccessCase): (JSC::GetterSetterAccessCase::dumpImpl const): * bytecode/GetterSetterAccessCase.h: (JSC::GetterSetterAccessCase::customAccessor const): (): Deleted. * bytecode/HandlerInfo.h: (JSC::HandlerInfo::initialize): * bytecode/InlineAccess.cpp: (JSC::linkCodeInline): (JSC::InlineAccess::rewireStubAsJump): * bytecode/InlineAccess.h: * bytecode/JumpTable.h: (JSC::StringJumpTable::ctiForValue): (JSC::SimpleJumpTable::ctiForValue): * bytecode/LLIntCallLinkInfo.h: (JSC::LLIntCallLinkInfo::unlink): * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): (JSC::PolymorphicAccess::regenerate): * bytecode/PolymorphicAccess.h: (JSC::AccessGenerationResult::AccessGenerationResult): (JSC::AccessGenerationResult::code const): * bytecode/StructureStubInfo.h: (JSC::StructureStubInfo::slowPathCallLocation): (JSC::StructureStubInfo::doneLocation): (JSC::StructureStubInfo::slowPathStartLocation): (JSC::StructureStubInfo::patchableJumpForIn): * dfg/DFGCommonData.h: (JSC::DFG::CommonData::appendCatchEntrypoint): * dfg/DFGDisassembler.cpp: (JSC::DFG::Disassembler::dumpDisassembly): * dfg/DFGDriver.h: * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::linkOSRExits): (JSC::DFG::JITCompiler::compileExceptionHandlers): (JSC::DFG::JITCompiler::link): (JSC::DFG::JITCompiler::compileFunction): (JSC::DFG::JITCompiler::noticeCatchEntrypoint): * dfg/DFGJITCompiler.h: (JSC::DFG::CallLinkRecord::CallLinkRecord): (JSC::DFG::JITCompiler::appendCall): (JSC::DFG::JITCompiler::JSCallRecord::JSCallRecord): (JSC::DFG::JITCompiler::JSDirectCallRecord::JSDirectCallRecord): (JSC::DFG::JITCompiler::JSDirectTailCallRecord::JSDirectTailCallRecord): * dfg/DFGJITFinalizer.cpp: (JSC::DFG::JITFinalizer::JITFinalizer): (JSC::DFG::JITFinalizer::finalize): (JSC::DFG::JITFinalizer::finalizeFunction): * dfg/DFGJITFinalizer.h: * dfg/DFGJumpReplacement.h: (JSC::DFG::JumpReplacement::JumpReplacement): * dfg/DFGNode.h: * dfg/DFGOSREntry.cpp: (JSC::DFG::prepareOSREntry): (JSC::DFG::prepareCatchOSREntry): * dfg/DFGOSREntry.h: (JSC::DFG::prepareOSREntry): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::executeOSRExit): (JSC::DFG::reifyInlinedCallFrames): (JSC::DFG::adjustAndJumpToTarget): (JSC::DFG::OSRExit::codeLocationForRepatch const): (JSC::DFG::OSRExit::emitRestoreArguments): (JSC::DFG::OSRExit::compileOSRExit): * dfg/DFGOSRExit.h: * dfg/DFGOSRExitCompilerCommon.cpp: (JSC::DFG::handleExitCounts): (JSC::DFG::reifyInlinedCallFrames): (JSC::DFG::osrWriteBarrier): (JSC::DFG::adjustAndJumpToTarget): * dfg/DFGOperations.cpp: * dfg/DFGSlowPathGenerator.h: (JSC::DFG::CallResultAndArgumentsSlowPathGenerator::CallResultAndArgumentsSlowPathGenerator): (JSC::DFG::CallResultAndArgumentsSlowPathGenerator::unpackAndGenerate): (JSC::DFG::slowPathCall): * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileMathIC): (JSC::DFG::SpeculativeJIT::compileCallDOM): (JSC::DFG::SpeculativeJIT::compileCallDOMGetter): (JSC::DFG::SpeculativeJIT::emitSwitchIntJump): (JSC::DFG::SpeculativeJIT::emitSwitchImm): (JSC::DFG::SpeculativeJIT::emitSwitchStringOnString): (JSC::DFG::SpeculativeJIT::compileHasIndexedProperty): (JSC::DFG::SpeculativeJIT::compileGetDirectPname): (JSC::DFG::SpeculativeJIT::cachedPutById): * dfg/DFGSpeculativeJIT.h: (JSC::DFG::SpeculativeJIT::callOperation): (JSC::DFG::SpeculativeJIT::appendCall): (JSC::DFG::SpeculativeJIT::appendCallWithCallFrameRollbackOnException): (JSC::DFG::SpeculativeJIT::appendCallWithCallFrameRollbackOnExceptionSetResult): (JSC::DFG::SpeculativeJIT::appendCallSetResult): * dfg/DFGSpeculativeJIT64.cpp: (JSC::DFG::SpeculativeJIT::cachedGetById): (JSC::DFG::SpeculativeJIT::cachedGetByIdWithThis): (JSC::DFG::SpeculativeJIT::compile): * dfg/DFGThunks.cpp: (JSC::DFG::osrExitThunkGenerator): (JSC::DFG::osrExitGenerationThunkGenerator): (JSC::DFG::osrEntryThunkGenerator): * dfg/DFGThunks.h: * disassembler/ARM64Disassembler.cpp: (JSC::tryToDisassemble): * disassembler/ARMv7Disassembler.cpp: (JSC::tryToDisassemble): * disassembler/Disassembler.cpp: (JSC::disassemble): (JSC::disassembleAsynchronously): * disassembler/Disassembler.h: (JSC::tryToDisassemble): * disassembler/UDis86Disassembler.cpp: (JSC::tryToDisassembleWithUDis86): * disassembler/UDis86Disassembler.h: (JSC::tryToDisassembleWithUDis86): * disassembler/X86Disassembler.cpp: (JSC::tryToDisassemble): * ftl/FTLCompile.cpp: (JSC::FTL::compile): * ftl/FTLExceptionTarget.cpp: (JSC::FTL::ExceptionTarget::label): (JSC::FTL::ExceptionTarget::jumps): * ftl/FTLExceptionTarget.h: * ftl/FTLGeneratedFunction.h: * ftl/FTLJITCode.cpp: (JSC::FTL::JITCode::initializeB3Code): (JSC::FTL::JITCode::initializeAddressForCall): (JSC::FTL::JITCode::initializeArityCheckEntrypoint): (JSC::FTL::JITCode::addressForCall): (JSC::FTL::JITCode::executableAddressAtOffset): * ftl/FTLJITCode.h: (JSC::FTL::JITCode::b3Code const): * ftl/FTLJITFinalizer.cpp: (JSC::FTL::JITFinalizer::finalizeCommon): * ftl/FTLLazySlowPath.cpp: (JSC::FTL::LazySlowPath::initialize): (JSC::FTL::LazySlowPath::generate): * ftl/FTLLazySlowPath.h: (JSC::FTL::LazySlowPath::patchableJump const): (JSC::FTL::LazySlowPath::done const): (JSC::FTL::LazySlowPath::stub const): * ftl/FTLLazySlowPathCall.h: (JSC::FTL::createLazyCallGenerator): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::lower): (JSC::FTL::DFG::LowerDFGToB3::compileCallOrConstruct): (JSC::FTL::DFG::LowerDFGToB3::compileDirectCallOrConstruct): (JSC::FTL::DFG::LowerDFGToB3::compileTailCall): (JSC::FTL::DFG::LowerDFGToB3::compileCallOrConstructVarargsSpread): (JSC::FTL::DFG::LowerDFGToB3::compileCallOrConstructVarargs): (JSC::FTL::DFG::LowerDFGToB3::compileCallEval): (JSC::FTL::DFG::LowerDFGToB3::compileInvalidationPoint): (JSC::FTL::DFG::LowerDFGToB3::compileIn): (JSC::FTL::DFG::LowerDFGToB3::compileCheckSubClass): (JSC::FTL::DFG::LowerDFGToB3::compileCallDOM): (JSC::FTL::DFG::LowerDFGToB3::compileCallDOMGetter): (JSC::FTL::DFG::LowerDFGToB3::lazySlowPath): * ftl/FTLOSRExit.cpp: (JSC::FTL::OSRExit::codeLocationForRepatch const): * ftl/FTLOSRExit.h: * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): (JSC::FTL::compileFTLOSRExit): * ftl/FTLOSRExitHandle.cpp: (JSC::FTL::OSRExitHandle::emitExitThunk): * ftl/FTLOperations.cpp: (JSC::FTL::compileFTLLazySlowPath): * ftl/FTLPatchpointExceptionHandle.cpp: (JSC::FTL::PatchpointExceptionHandle::scheduleExitCreationForUnwind): * ftl/FTLSlowPathCall.cpp: (JSC::FTL::SlowPathCallContext::keyWithTarget const): (JSC::FTL::SlowPathCallContext::makeCall): * ftl/FTLSlowPathCall.h: (JSC::FTL::callOperation): * ftl/FTLSlowPathCallKey.cpp: (JSC::FTL::SlowPathCallKey::dump const): * ftl/FTLSlowPathCallKey.h: (JSC::FTL::SlowPathCallKey::SlowPathCallKey): (JSC::FTL::SlowPathCallKey::callTarget const): (JSC::FTL::SlowPathCallKey::withCallTarget): (JSC::FTL::SlowPathCallKey::hash const): (JSC::FTL::SlowPathCallKey::callPtrTag const): Deleted. * ftl/FTLState.cpp: (JSC::FTL::State::State): * ftl/FTLThunks.cpp: (JSC::FTL::genericGenerationThunkGenerator): (JSC::FTL::osrExitGenerationThunkGenerator): (JSC::FTL::lazySlowPathGenerationThunkGenerator): (JSC::FTL::slowPathCallThunkGenerator): * ftl/FTLThunks.h: (JSC::FTL::generateIfNecessary): (JSC::FTL::keyForThunk): (JSC::FTL::Thunks::getSlowPathCallThunk): (JSC::FTL::Thunks::keyForSlowPathCallThunk): * interpreter/InterpreterInlines.h: (JSC::Interpreter::getOpcodeID): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::callExceptionFuzz): (JSC::AssemblyHelpers::emitDumbVirtualCall): (JSC::AssemblyHelpers::debugCall): * jit/CCallHelpers.cpp: (JSC::CCallHelpers::ensureShadowChickenPacket): * jit/ExecutableAllocator.cpp: (JSC::FixedVMPoolExecutableAllocator::initializeSeparatedWXHeaps): (JSC::FixedVMPoolExecutableAllocator::jitWriteThunkGenerator): * jit/ExecutableAllocator.h: (JSC::performJITMemcpy): * jit/GCAwareJITStubRoutine.cpp: (JSC::GCAwareJITStubRoutine::GCAwareJITStubRoutine): (JSC::MarkingGCAwareJITStubRoutine::MarkingGCAwareJITStubRoutine): (JSC::GCAwareJITStubRoutineWithExceptionHandler::GCAwareJITStubRoutineWithExceptionHandler): (JSC::createJITStubRoutine): * jit/GCAwareJITStubRoutine.h: (JSC::createJITStubRoutine): * jit/JIT.cpp: (JSC::ctiPatchCallByReturnAddress): (JSC::JIT::compileWithoutLinking): (JSC::JIT::link): (JSC::JIT::privateCompileExceptionHandlers): * jit/JIT.h: (JSC::CallRecord::CallRecord): * jit/JITArithmetic.cpp: (JSC::JIT::emitMathICFast): (JSC::JIT::emitMathICSlow): * jit/JITCall.cpp: (JSC::JIT::compileOpCallSlowCase): * jit/JITCall32_64.cpp: (JSC::JIT::compileOpCallSlowCase): * jit/JITCode.cpp: (JSC::JITCodeWithCodeRef::JITCodeWithCodeRef): (JSC::JITCodeWithCodeRef::executableAddressAtOffset): (JSC::DirectJITCode::DirectJITCode): (JSC::DirectJITCode::initializeCodeRef): (JSC::DirectJITCode::addressForCall): (JSC::NativeJITCode::NativeJITCode): (JSC::NativeJITCode::initializeCodeRef): (JSC::NativeJITCode::addressForCall): * jit/JITCode.h: * jit/JITCodeMap.h: (JSC::JITCodeMap::Entry::Entry): (JSC::JITCodeMap::Entry::codeLocation): (JSC::JITCodeMap::append): (JSC::JITCodeMap::find const): * jit/JITDisassembler.cpp: (JSC::JITDisassembler::dumpDisassembly): * jit/JITExceptions.cpp: (JSC::genericUnwind): * jit/JITInlineCacheGenerator.cpp: (JSC::JITByIdGenerator::finalize): * jit/JITInlines.h: (JSC::JIT::emitNakedCall): (JSC::JIT::emitNakedTailCall): (JSC::JIT::appendCallWithExceptionCheck): (JSC::JIT::appendCallWithExceptionCheckAndSlowPathReturnType): (JSC::JIT::appendCallWithCallFrameRollbackOnException): (JSC::JIT::appendCallWithExceptionCheckSetJSValueResult): (JSC::JIT::appendCallWithExceptionCheckSetJSValueResultWithProfile): * jit/JITMathIC.h: (JSC::isProfileEmpty): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_catch): (JSC::JIT::emit_op_switch_imm): (JSC::JIT::emit_op_switch_char): (JSC::JIT::emit_op_switch_string): (JSC::JIT::privateCompileHasIndexedProperty): (JSC::JIT::emitSlow_op_has_indexed_property): * jit/JITOpcodes32_64.cpp: (JSC::JIT::privateCompileHasIndexedProperty): * jit/JITOperations.cpp: (JSC::getByVal): * jit/JITPropertyAccess.cpp: (JSC::JIT::stringGetByValStubGenerator): (JSC::JIT::emitGetByValWithCachedId): (JSC::JIT::emitSlow_op_get_by_val): (JSC::JIT::emitPutByValWithCachedId): (JSC::JIT::emitSlow_op_put_by_val): (JSC::JIT::emitSlow_op_try_get_by_id): (JSC::JIT::emitSlow_op_get_by_id_direct): (JSC::JIT::emitSlow_op_get_by_id): (JSC::JIT::emitSlow_op_get_by_id_with_this): (JSC::JIT::emitSlow_op_put_by_id): (JSC::JIT::privateCompileGetByVal): (JSC::JIT::privateCompileGetByValWithCachedId): (JSC::JIT::privateCompilePutByVal): (JSC::JIT::privateCompilePutByValWithCachedId): * jit/JITPropertyAccess32_64.cpp: (JSC::JIT::stringGetByValStubGenerator): (JSC::JIT::emitSlow_op_get_by_val): (JSC::JIT::emitSlow_op_put_by_val): * jit/JITStubRoutine.h: (JSC::JITStubRoutine::JITStubRoutine): (JSC::JITStubRoutine::createSelfManagedRoutine): (JSC::JITStubRoutine::code const): (JSC::JITStubRoutine::asCodePtr): * jit/JITThunks.cpp: (JSC::JITThunks::ctiNativeCall): (JSC::JITThunks::ctiNativeConstruct): (JSC::JITThunks::ctiNativeTailCall): (JSC::JITThunks::ctiNativeTailCallWithoutSavedTags): (JSC::JITThunks::ctiInternalFunctionCall): (JSC::JITThunks::ctiInternalFunctionConstruct): (JSC::JITThunks::ctiStub): (JSC::JITThunks::existingCTIStub): (JSC::JITThunks::hostFunctionStub): * jit/JITThunks.h: * jit/PCToCodeOriginMap.cpp: (JSC::PCToCodeOriginMap::PCToCodeOriginMap): * jit/PCToCodeOriginMap.h: * jit/PolymorphicCallStubRoutine.cpp: (JSC::PolymorphicCallStubRoutine::PolymorphicCallStubRoutine): * jit/PolymorphicCallStubRoutine.h: * jit/Repatch.cpp: (JSC::readPutICCallTarget): (JSC::ftlThunkAwareRepatchCall): (JSC::appropriateOptimizingGetByIdFunction): (JSC::appropriateGetByIdFunction): (JSC::tryCacheGetByID): (JSC::repatchGetByID): (JSC::tryCachePutByID): (JSC::repatchPutByID): (JSC::tryCacheIn): (JSC::repatchIn): (JSC::linkSlowFor): (JSC::linkFor): (JSC::linkDirectFor): (JSC::revertCall): (JSC::unlinkFor): (JSC::linkVirtualFor): (JSC::linkPolymorphicCall): (JSC::resetGetByID): (JSC::resetPutByID): * jit/Repatch.h: * jit/SlowPathCall.h: (JSC::JITSlowPathCall::call): * jit/SpecializedThunkJIT.h: (JSC::SpecializedThunkJIT::finalize): (JSC::SpecializedThunkJIT::callDoubleToDouble): (JSC::SpecializedThunkJIT::callDoubleToDoublePreservingReturn): * jit/ThunkGenerator.h: * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::slowPathFor): (JSC::linkCallThunkGenerator): (JSC::linkPolymorphicCallThunkGenerator): (JSC::virtualThunkFor): (JSC::nativeForGenerator): (JSC::nativeCallGenerator): (JSC::nativeTailCallGenerator): (JSC::nativeTailCallWithoutSavedTagsGenerator): (JSC::nativeConstructGenerator): (JSC::internalFunctionCallGenerator): (JSC::internalFunctionConstructGenerator): (JSC::arityFixupGenerator): (JSC::unreachableGenerator): (JSC::charCodeAtThunkGenerator): (JSC::charAtThunkGenerator): (JSC::fromCharCodeThunkGenerator): (JSC::clz32ThunkGenerator): (JSC::sqrtThunkGenerator): (JSC::floorThunkGenerator): (JSC::ceilThunkGenerator): (JSC::truncThunkGenerator): (JSC::roundThunkGenerator): (JSC::expThunkGenerator): (JSC::logThunkGenerator): (JSC::absThunkGenerator): (JSC::imulThunkGenerator): (JSC::randomThunkGenerator): (JSC::boundThisNoArgsFunctionCallGenerator): * jit/ThunkGenerators.h: * llint/LLIntData.cpp: (JSC::LLInt::initialize): * llint/LLIntData.h: (JSC::LLInt::getExecutableAddress): (JSC::LLInt::getCodePtr): (JSC::LLInt::getCodeRef): (JSC::LLInt::getCodeFunctionPtr): * llint/LLIntEntrypoint.cpp: (JSC::LLInt::setFunctionEntrypoint): (JSC::LLInt::setEvalEntrypoint): (JSC::LLInt::setProgramEntrypoint): (JSC::LLInt::setModuleProgramEntrypoint): * llint/LLIntExceptions.cpp: (JSC::LLInt::callToThrow): * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): (JSC::LLInt::setUpCall): * llint/LLIntThunks.cpp: (JSC::vmEntryToWasm): (JSC::LLInt::generateThunkWithJumpTo): (JSC::LLInt::functionForCallEntryThunkGenerator): (JSC::LLInt::functionForConstructEntryThunkGenerator): (JSC::LLInt::functionForCallArityCheckThunkGenerator): (JSC::LLInt::functionForConstructArityCheckThunkGenerator): (JSC::LLInt::evalEntryThunkGenerator): (JSC::LLInt::programEntryThunkGenerator): (JSC::LLInt::moduleProgramEntryThunkGenerator): * llint/LLIntThunks.h: * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * profiler/ProfilerCompilation.cpp: (JSC::Profiler::Compilation::addOSRExitSite): * profiler/ProfilerCompilation.h: * profiler/ProfilerOSRExitSite.cpp: (JSC::Profiler::OSRExitSite::toJS const): * profiler/ProfilerOSRExitSite.h: (JSC::Profiler::OSRExitSite::OSRExitSite): (JSC::Profiler::OSRExitSite::codeAddress const): (JSC::Profiler::OSRExitSite:: const): Deleted. * runtime/ExecutableBase.cpp: (JSC::ExecutableBase::clearCode): * runtime/ExecutableBase.h: (JSC::ExecutableBase::entrypointFor): * runtime/NativeExecutable.cpp: (JSC::NativeExecutable::finishCreation): * runtime/NativeFunction.h: (JSC::TaggedNativeFunction::TaggedNativeFunction): (JSC::TaggedNativeFunction::operator NativeFunction): * runtime/PtrTag.h: (JSC::tagCodePtr): (JSC::untagCodePtr): (JSC::retagCodePtr): (JSC::tagCFunctionPtr): (JSC::untagCFunctionPtr): (JSC::nextPtrTagID): Deleted. * runtime/PutPropertySlot.h: (JSC::PutPropertySlot::PutPropertySlot): (JSC::PutPropertySlot::setCustomValue): (JSC::PutPropertySlot::setCustomAccessor): (JSC::PutPropertySlot::customSetter const): * runtime/ScriptExecutable.cpp: (JSC::ScriptExecutable::installCode): * runtime/VM.cpp: (JSC::VM::getHostFunction): (JSC::VM::getCTIInternalFunctionTrampolineFor): * runtime/VM.h: (JSC::VM::getCTIStub): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::emitExceptionCheck): (JSC::Wasm::B3IRGenerator::emitTierUpCheck): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::prepare): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmBinding.h: * wasm/WasmCallee.h: (JSC::Wasm::Callee::entrypoint const): * wasm/WasmCallingConvention.h: (JSC::Wasm::CallingConvention::setupFrameInPrologue const): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::entrypointLoadLocationFromFunctionIndexSpace): * wasm/WasmFaultSignalHandler.cpp: (JSC::Wasm::trapHandler): * wasm/WasmFormat.h: * wasm/WasmInstance.h: * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::work): * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::throwStackOverflowFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): (JSC::Wasm::Thunks::stub): (JSC::Wasm::Thunks::existingStub): * wasm/WasmThunks.h: * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/WasmToJS.cpp: (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): * wasm/js/WasmToJS.h: * wasm/js/WebAssemblyFunction.h: * yarr/YarrJIT.cpp: (JSC::Yarr::YarrGenerator::loadFromFrameAndJump): (JSC::Yarr::YarrGenerator::BacktrackingState::linkDataLabels): (JSC::Yarr::YarrGenerator::compile): * yarr/YarrJIT.h: (JSC::Yarr::YarrCodeBlock::set8BitCode): (JSC::Yarr::YarrCodeBlock::set16BitCode): (JSC::Yarr::YarrCodeBlock::set8BitCodeMatchOnly): (JSC::Yarr::YarrCodeBlock::set16BitCodeMatchOnly): (JSC::Yarr::YarrCodeBlock::execute): (JSC::Yarr::YarrCodeBlock::clear): Source/WebCore: No new tests. This is covered by existing tests. * WebCore.xcodeproj/project.pbxproj: * css/ElementRuleCollector.cpp: (WebCore::ElementRuleCollector::ruleMatches): * cssjit/CSSPtrTag.h: Added. * cssjit/CompiledSelector.h: * cssjit/FunctionCall.h: (WebCore::FunctionCall::FunctionCall): (WebCore::FunctionCall::setFunctionAddress): (WebCore::FunctionCall::prepareAndCall): * cssjit/SelectorCompiler.cpp: (WebCore::SelectorCompiler::compileSelector): (WebCore::SelectorCompiler::SelectorFragment::appendUnoptimizedPseudoClassWithContext): (WebCore::SelectorCompiler::addPseudoClassType): (WebCore::SelectorCompiler::SelectorCodeGenerator::compile): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementAttributeFunctionCallValueMatching): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementFunctionCallTest): (WebCore::SelectorCompiler::SelectorCodeGenerator::generateContextFunctionCallTest): * cssjit/SelectorCompiler.h: (WebCore::SelectorCompiler::ruleCollectorSimpleSelectorCheckerFunction): (WebCore::SelectorCompiler::querySelectorSimpleSelectorCheckerFunction): (WebCore::SelectorCompiler::ruleCollectorSelectorCheckerFunctionWithCheckingContext): (WebCore::SelectorCompiler::querySelectorSelectorCheckerFunctionWithCheckingContext): * dom/SelectorQuery.cpp: (WebCore::SelectorDataList::executeCompiledSingleMultiSelectorData const): (WebCore::SelectorDataList::execute const): * dom/SelectorQuery.h: Canonical link: https://commits.webkit.org/200234@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230748 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-04-18 03:31:09 +00:00
MacroAssemblerCodePtr<WasmEntryPtrTag> wasmToEmbedderStub;
Remove poisons in JSCPoison and uses of them. https://bugs.webkit.org/show_bug.cgi?id=195082 Reviewed by Yusuke Suzuki. Also removed unused poisoning code in WriteBarrier, AssemblyHelpers, DFG::SpeculativeJIT, FTLLowerDFGToB3, and FTL::Output. * API/JSAPIWrapperObject.h: (JSC::JSAPIWrapperObject::wrappedObject): * API/JSCallbackFunction.h: * API/JSCallbackObject.h: * API/glib/JSAPIWrapperGlobalObject.h: * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/AccessCase.cpp: (JSC::AccessCase::generateWithGuard): * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compileGetByValOnScopedArguments): (JSC::DFG::SpeculativeJIT::compileGetArrayLength): (JSC::DFG::SpeculativeJIT::compileNewFunctionCommon): (JSC::DFG::SpeculativeJIT::compileGetExecutable): (JSC::DFG::SpeculativeJIT::compileCreateThis): * dfg/DFGSpeculativeJIT.h: (JSC::DFG::SpeculativeJIT::TrustedImmPtr::weakPoisonedPointer): Deleted. * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::compileGetExecutable): (JSC::FTL::DFG::LowerDFGToB3::compileGetArrayLength): (JSC::FTL::DFG::LowerDFGToB3::compileGetByVal): (JSC::FTL::DFG::LowerDFGToB3::compileNewFunction): (JSC::FTL::DFG::LowerDFGToB3::weakPointer): (JSC::FTL::DFG::LowerDFGToB3::dynamicPoison): Deleted. (JSC::FTL::DFG::LowerDFGToB3::dynamicPoisonOnLoadedType): Deleted. (JSC::FTL::DFG::LowerDFGToB3::dynamicPoisonOnType): Deleted. (JSC::FTL::DFG::LowerDFGToB3::weakPoisonedPointer): Deleted. * ftl/FTLOutput.h: (JSC::FTL::Output::weakPoisonedPointer): Deleted. * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::emitDynamicPoison): Deleted. (JSC::AssemblyHelpers::emitDynamicPoisonOnLoadedType): Deleted. (JSC::AssemblyHelpers::emitDynamicPoisonOnType): Deleted. * jit/AssemblyHelpers.h: * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_create_this): * jit/JITPropertyAccess.cpp: (JSC::JIT::emitScopedArgumentsGetByVal): * jit/Repatch.cpp: (JSC::linkPolymorphicCall): * jit/ThunkGenerators.cpp: (JSC::virtualThunkFor): (JSC::nativeForGenerator): (JSC::boundThisNoArgsFunctionCallGenerator): * parser/UnlinkedSourceCode.h: * runtime/ArrayPrototype.h: * runtime/CustomGetterSetter.h: (JSC::CustomGetterSetter::getter const): (JSC::CustomGetterSetter::setter const): * runtime/InitializeThreading.cpp: (JSC::initializeThreading): * runtime/InternalFunction.cpp: (JSC::InternalFunction::getCallData): (JSC::InternalFunction::getConstructData): * runtime/InternalFunction.h: (JSC::InternalFunction::nativeFunctionFor): * runtime/JSArrayBuffer.h: * runtime/JSBoundFunction.h: * runtime/JSCPoison.cpp: Removed. * runtime/JSCPoison.h: Removed. * runtime/JSFunction.h: * runtime/JSGlobalObject.h: * runtime/JSScriptFetchParameters.h: * runtime/JSScriptFetcher.h: * runtime/JSString.h: * runtime/NativeExecutable.cpp: (JSC::NativeExecutable::hashFor const): * runtime/NativeExecutable.h: * runtime/Options.h: * runtime/ScopedArguments.h: * runtime/Structure.cpp: (JSC::StructureTransitionTable::setSingleTransition): * runtime/StructureTransitionTable.h: (JSC::StructureTransitionTable::map const): (JSC::StructureTransitionTable::weakImpl const): (JSC::StructureTransitionTable::setMap): * runtime/WriteBarrier.h: * wasm/WasmB3IRGenerator.cpp: * wasm/WasmInstance.h: * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/JSWebAssemblyInstance.h: * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::clearFunction): * wasm/js/JSWebAssemblyTable.h: * wasm/js/WasmToJS.cpp: (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): * wasm/js/WebAssemblyFunctionBase.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyModuleRecord.h: * wasm/js/WebAssemblyToJSCallee.h: * wasm/js/WebAssemblyWrapperFunction.h: Canonical link: https://commits.webkit.org/209443@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242123 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-02-27 05:43:34 +00:00
void* importFunction { nullptr }; // In a JS embedding, this is a WriteBarrier<JSObject>.
WebAssembly: no VM / JS version of our implementation https://bugs.webkit.org/show_bug.cgi?id=177472 Reviewed by Michael Saboff. This patch removes all appearances of "JS" and "VM" in the wasm directory. These now only appear in the wasm/js directory, which is only used in a JS embedding of wasm. It should therefore now be possible to create non-JS embeddings of wasm through JSC, though it'll still require: - Mild codegen for wasm<->embedder calls; - A strategy for trap handling (no need for full unwind! Could kill). - Creation of the Wasm::* objects. - Calling convention handling to call the embedder. - Handling of multiple embedders (see #177475, this is optional). Most of the patch consists in renaming JSWebAssemblyInstance to Instance, and removing temporary copies which I'd added to make this specific patch very simple. * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): this one place which needs to know about who "owns" the Wasm::Instance. In a JS embedding it's the JSWebAssemblyInstance. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::getGlobal): (JSC::Wasm::B3IRGenerator::setGlobal): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmContext.cpp: (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: add an "owner", the Wasm::Context, move the "tail" import information from JSWebAssemblyInstance over to here. (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::owner const): (JSC::Wasm::Instance::offsetOfOwner): (JSC::Wasm::Instance::context const): (JSC::Wasm::Instance::setMemory): (JSC::Wasm::Instance::setTable): (JSC::Wasm::Instance::offsetOfMemory): (JSC::Wasm::Instance::offsetOfGlobals): (JSC::Wasm::Instance::offsetOfTable): (JSC::Wasm::Instance::offsetOfTail): (JSC::Wasm::Instance::numImportFunctions const): (JSC::Wasm::Instance::importFunctionInfo): (JSC::Wasm::Instance::offsetOfTargetInstance): (JSC::Wasm::Instance::offsetOfWasmEntrypoint): (JSC::Wasm::Instance::offsetOfWasmToEmbedderStubExecutableAddress): (JSC::Wasm::Instance::offsetOfImportFunction): (JSC::Wasm::Instance::importFunction): (JSC::Wasm::Instance::allocationSize): (JSC::Wasm::Instance::create): Deleted. * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmTable.cpp: (JSC::Wasm::Table::Table): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyInstance.cpp: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): The embedder decides what the import function is. Here we must properly placement-new it to what we've elected (and initialize it later). (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::moduleNamespaceObject): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::setTable): (JSC::JSWebAssemblyInstance::offsetOfInstance): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::context const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTail): Deleted. (): Deleted. (JSC::JSWebAssemblyInstance::importFunctionInfo): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmToEmbedderStubExecutableAddress): Deleted. (JSC::JSWebAssemblyInstance::offsetOfImportFunction): Deleted. (JSC::JSWebAssemblyInstance::importFunction): Deleted. (JSC::JSWebAssemblyInstance::internalMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmCodeBlock const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmTable): Deleted. (JSC::JSWebAssemblyInstance::offsetOfGlobals): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTopEntryFramePointer): Deleted. (JSC::JSWebAssemblyInstance::cachedStackLimit const): Deleted. (JSC::JSWebAssemblyInstance::setCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::wasmMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmModule): Deleted. (JSC::JSWebAssemblyInstance::allocationSize): Deleted. * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::setFunction): * wasm/js/WasmToJS.cpp: One extra indirection to find the JSWebAssemblyInstance. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::instantiate): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Canonical link: https://commits.webkit.org/195012@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224020 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-26 15:33:55 +00:00
};
unsigned numImportFunctions() const { return m_numImportFunctions; }
ImportFunctionInfo* importFunctionInfo(size_t importFunctionNum)
{
RELEASE_ASSERT(importFunctionNum < m_numImportFunctions);
return &bitwise_cast<ImportFunctionInfo*>(bitwise_cast<char*>(this) + offsetOfTail())[importFunctionNum];
}
static size_t offsetOfTargetInstance(size_t importFunctionNum) { return offsetOfTail() + importFunctionNum * sizeof(ImportFunctionInfo) + OBJECT_OFFSETOF(ImportFunctionInfo, targetInstance); }
Use MacroAssemblerCodePtr in Wasm code for code pointers instead of void*. https://bugs.webkit.org/show_bug.cgi?id=184163 <rdar://problem/39020397> Reviewed by JF Bastien. With the use of MacroAssemblerCodePtr, we now get poisoning for Wasm code pointers. Also renamed some structs, methods, and variable names to be more accurate. Previously, there is some confusion between a code pointer and the address of a code pointer (sometimes referred to in the code as a "LoadLocation"). We now name the LoadLocation variables appropriately to distinguish them from code pointers. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::CodeBlock): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::entrypointLoadLocationFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointLoadLocationFromFunctionIndexSpace): Deleted. * wasm/WasmFormat.h: (JSC::Wasm::WasmToWasmImportableFunction::WasmToWasmImportableFunction): (JSC::Wasm::WasmToWasmImportableFunction::offsetOfEntrypointLoadLocation): (JSC::Wasm::CallableFunction::CallableFunction): Deleted. (JSC::Wasm::CallableFunction::offsetOfWasmEntrypointLoadLocation): Deleted. * wasm/WasmInstance.h: (JSC::Wasm::Instance::offsetOfWasmEntrypointLoadLocation): (JSC::Wasm::Instance::offsetOfWasmToEmbedderStub): (JSC::Wasm::Instance::offsetOfWasmEntrypoint): Deleted. (JSC::Wasm::Instance::offsetOfWasmToEmbedderStubExecutableAddress): Deleted. * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::work): * wasm/WasmTable.cpp: (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: (JSC::Wasm::Table::offsetOfFunctions): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::setFunction): * wasm/js/WebAssemblyFunction.cpp: (JSC::WebAssemblyFunction::create): (JSC::WebAssemblyFunction::WebAssemblyFunction): * wasm/js/WebAssemblyFunction.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::WebAssemblyWrapperFunction): (JSC::WebAssemblyWrapperFunction::create): * wasm/js/WebAssemblyWrapperFunction.h: Canonical link: https://commits.webkit.org/199724@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230096 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-03-30 05:04:44 +00:00
static size_t offsetOfWasmEntrypointLoadLocation(size_t importFunctionNum) { return offsetOfTail() + importFunctionNum * sizeof(ImportFunctionInfo) + OBJECT_OFFSETOF(ImportFunctionInfo, wasmEntrypointLoadLocation); }
static size_t offsetOfWasmToEmbedderStub(size_t importFunctionNum) { return offsetOfTail() + importFunctionNum * sizeof(ImportFunctionInfo) + OBJECT_OFFSETOF(ImportFunctionInfo, wasmToEmbedderStub); }
WebAssembly: no VM / JS version of our implementation https://bugs.webkit.org/show_bug.cgi?id=177472 Reviewed by Michael Saboff. This patch removes all appearances of "JS" and "VM" in the wasm directory. These now only appear in the wasm/js directory, which is only used in a JS embedding of wasm. It should therefore now be possible to create non-JS embeddings of wasm through JSC, though it'll still require: - Mild codegen for wasm<->embedder calls; - A strategy for trap handling (no need for full unwind! Could kill). - Creation of the Wasm::* objects. - Calling convention handling to call the embedder. - Handling of multiple embedders (see #177475, this is optional). Most of the patch consists in renaming JSWebAssemblyInstance to Instance, and removing temporary copies which I'd added to make this specific patch very simple. * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): this one place which needs to know about who "owns" the Wasm::Instance. In a JS embedding it's the JSWebAssemblyInstance. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::getGlobal): (JSC::Wasm::B3IRGenerator::setGlobal): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmContext.cpp: (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: add an "owner", the Wasm::Context, move the "tail" import information from JSWebAssemblyInstance over to here. (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::owner const): (JSC::Wasm::Instance::offsetOfOwner): (JSC::Wasm::Instance::context const): (JSC::Wasm::Instance::setMemory): (JSC::Wasm::Instance::setTable): (JSC::Wasm::Instance::offsetOfMemory): (JSC::Wasm::Instance::offsetOfGlobals): (JSC::Wasm::Instance::offsetOfTable): (JSC::Wasm::Instance::offsetOfTail): (JSC::Wasm::Instance::numImportFunctions const): (JSC::Wasm::Instance::importFunctionInfo): (JSC::Wasm::Instance::offsetOfTargetInstance): (JSC::Wasm::Instance::offsetOfWasmEntrypoint): (JSC::Wasm::Instance::offsetOfWasmToEmbedderStubExecutableAddress): (JSC::Wasm::Instance::offsetOfImportFunction): (JSC::Wasm::Instance::importFunction): (JSC::Wasm::Instance::allocationSize): (JSC::Wasm::Instance::create): Deleted. * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmTable.cpp: (JSC::Wasm::Table::Table): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyInstance.cpp: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): The embedder decides what the import function is. Here we must properly placement-new it to what we've elected (and initialize it later). (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::moduleNamespaceObject): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::setTable): (JSC::JSWebAssemblyInstance::offsetOfInstance): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::context const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTail): Deleted. (): Deleted. (JSC::JSWebAssemblyInstance::importFunctionInfo): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmToEmbedderStubExecutableAddress): Deleted. (JSC::JSWebAssemblyInstance::offsetOfImportFunction): Deleted. (JSC::JSWebAssemblyInstance::importFunction): Deleted. (JSC::JSWebAssemblyInstance::internalMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmCodeBlock const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmTable): Deleted. (JSC::JSWebAssemblyInstance::offsetOfGlobals): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTopEntryFramePointer): Deleted. (JSC::JSWebAssemblyInstance::cachedStackLimit const): Deleted. (JSC::JSWebAssemblyInstance::setCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::wasmMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmModule): Deleted. (JSC::JSWebAssemblyInstance::allocationSize): Deleted. * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::setFunction): * wasm/js/WasmToJS.cpp: One extra indirection to find the JSWebAssemblyInstance. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::instantiate): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Canonical link: https://commits.webkit.org/195012@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224020 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-26 15:33:55 +00:00
static size_t offsetOfImportFunction(size_t importFunctionNum) { return offsetOfTail() + importFunctionNum * sizeof(ImportFunctionInfo) + OBJECT_OFFSETOF(ImportFunctionInfo, importFunction); }
template<typename T> T* importFunction(unsigned importFunctionNum) { return reinterpret_cast<T*>(&importFunctionInfo(importFunctionNum)->importFunction); }
WebAssembly: no VM / JS version of everything but Instance https://bugs.webkit.org/show_bug.cgi?id=177473 Reviewed by Filip Pizlo, Saam Barati. JSTests: - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. * wasm/js-api/memory-grow.js: (assertEq): * wasm/js-api/table.js: (assert.throws): Source/JavaScriptCore: This change entails cleaning up and splitting a bunch of code which we had intertwined between C++ classes which represent JS objects, and pure C++ implementation objects. This specific change goes most of the way towards allowing JSC's WebAssembly to work without VM / JS, up to but excluding JSWebAssemblyInstance (there's Wasm::Instance, but it's not *the* thing yet). Because of this we still have a few FIXME identifying places that need to change. A follow-up change will go the rest of the way. I went about this change in the simplest way possible: grep the JavaScriptCore/wasm directory for "JS[^C_]" as well as "VM" and exclude the /js/ sub-directory (which contains the JS implementation of WebAssembly). None of this change removes the need for a JIT entitlement to be able to use WebAssembly. We don't have an interpreter, the process therefore still needs to be allowed to JIT to use these pure-C++ APIs. Interesting things to note: - Remove VM from Plan and associated places. It can just live as a capture in the callback lambda if it's needed. - Wasm::Memory shouldn't require a VM. It was only used to ask the GC to collect. We now instead pass two lambdas at construction time for this purpose: one to notify of memory pressure, and the other to ask for syncrhonous memory reclamation. This allows whoever creates the memory to dictate how to react to both these cases, and for a JS embedding that's to call the GC (async or sync, respectively). - Move grow logic from JSWebAssemblyMemory to Wasm::Memory::grow. Use Expected there, with an enum class for failure types. - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. - When generating the grow_memory opcode, no need to get the VM. Instead, reach directly for Wasm::Memory and grow it. - JSWebAssemblyMemory::grow can now always throw on failure, because it's only ever called from JS (not from grow_memory as before). - Wasm::Memory now takes a callback for successful growth. This allows JS wrappers to register themselves when growth succeeds without Wasm::Memory knowning anything about JS. It'll also allow creating a list of callbacks for when we add thread support (we'll want to notify many wrappers, all under a lock). - Wasm::Memory is now back to being the source of truth about address / size, used directly by generated code instead of JSWebAssemblyMemory. - Move wasmToJS from the general WasmBinding header to its own header under wasm/js. It's only used by wasm/js/JSWebAssemblyCodeBlock.cpp, and uses VM, and therefore isn't general WebAssembly. - Make Wasm::Context an actual type (just a struct holding a JSWebAssemlyInstance for now) instead of an alias for that. Notably this doesn't add anything to the Context and doesn't change what actually gets passed around in JIT code (fast TLS or registers) because these changes potentially impact performance. The entire purpose of this change is to allow passing Wasm::Context around without having to know about VM. Since VM contains a Wasm::Context the JS embedding is effectively the same, but with this setup a non-JS embedding is much better off. - Move JSWebAssembly into the JS folder. - OMGPlan: use Wasm::CodeBlock directly instead of JSWebAssemblyCodeBlock. - wasm->JS stubs are now on the instance's tail as raw pointers, instead of being on JSWebAssemblyCodeBlock, and are now called wasm->Embedder stubs. The owned reference is still on JSWebAssemblyCodeBlock, and is still called wasm->JS stub. This move means that the embedder must, after creating a Wasm::CodeBlock, somehow create the stubs to call back into the embedder. This removes an indirection in the generated code because the B3 IR generator now reaches into the instance instead of JSWebAssemblyCodeBlock. - Move more CodeBlock things. Compilation completion is now marked by its own atomic<bool> flag instead of a nullptr plan: that required using a lock, and was causing a deadlock in stack-trace.js because before my changes JSWebAssemblyCodeBlock did its own completion checking separately from Wasm::CodeBlock, without getting the lock. Now that everything points to Wasm::CodeBlock and there's no cached completion marker, the lock was being acquired in a sanity-check assertion. - Embedder -> Wasm wrappers are now generated through a function that's passed in at compilation time, instead of being hard-coded as a JS -> Wasm wrapper. - WasmMemory doens't need to know about fault handling thunks. Only the IR generator should know, and should make sure that the exception throwing thunk is generated if any memory is present (note: with signal handling not all of them generate an exception check). - Make exception throwing pluggable: instead of having a hard-coded JS-specific lambda we now have a regular C++ function being called from JIT code when a WebAssembly exception is thrown. This allows any embedder to get called as they wish. For now a process can only have a single of these functions (i.e. only one embedder per process) because the trap handler is a singleton. That can be fixed in in #177475. - Create WasmEmbedder.h where all embedder plugging will live. - Split up JSWebAssemblyTable into Wasm::Table which is refcounted. JSWebAssemblyTable now only contains the JS functions in the table, and Wasm::Table is what's used by the JIT code to lookup where to call and do the instance check (for context switch). Note that this creates an extra allocation for all the instances in Wasm::Table, and in exchange removes an indirection in JIT code because the instance used to be obtained off of the JS function. Also note that it's the embedder than keeps the instances alive, not Wasm::Table (which holds a dumb pointer to the instance), because doing otherwise would cause reference cycles. - Add WasmInstance. It doesn't do much for now, owns globals. - JSWebAssembly instance now doesn't just contain the imported functions as JSObjects, it also has the corresponding import's instance and wasm entrypoint. This triples the space allocated per instance's imported function, but there shouldn't be that many imports. This has two upsides: it creates smaller and faster code, and makes is easier to disassociate embedder-specific things from embedder-neutral things. The small / faster win is in two places: B3 IR generator only needs offsetOfImportFunction for the call opcode (when the called index is an import) to know whether the import is wasm->wasm or wasm->embedder (this isn't known at compile-time because it's dependent on the import object), this is now done by seeing if that import function has an associated target instance (only wasm->wasm does); the other place is wasmBinding which uses offsetOfImportFunction to figure out the wasm->wasm target instance, and then gets WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation to do a tail call. The disassociation comes because the target instance can be Wasm::Instance once we change what the Context is, and WasmEntrypointLoadLocation is already embedder-independent. As a next step I can move this tail allocation from JSWebAssemblyInstance to Wasm::Instance, and leave importFunction in as an opaque pointer which is embedder-specific, and in JS will remain WriteBarrier<JSObject>. - Rename VMEntryFrame to EntryFrame, and in many places pass a pointer to it around instead of VM. This is a first step in allowing entry frames which aren't stored on VM, but which are instead stored in an embedder-specific location. That change won't really affect JS except through code churn, but will allow WebAssembly to use some machinery in a generic manner without having a VM. * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * debugger/Debugger.cpp: (JSC::Debugger::stepOutOfFunction): (JSC::Debugger::returnEvent): (JSC::Debugger::unwindEvent): (JSC::Debugger::didExecuteProgram): * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::compileExceptionHandlers): * dfg/DFGOSREntry.cpp: (JSC::DFG::prepareOSREntry): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::compileOSRExit): (JSC::DFG::OSRExit::compileExit): * dfg/DFGThunks.cpp: (JSC::DFG::osrEntryThunkGenerator): * ftl/FTLCompile.cpp: (JSC::FTL::compile): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::lower): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): (JSC::CallFrame::callerFrame): (JSC::CallFrame::unsafeCallerFrame): * interpreter/CallFrame.h: (JSC::ExecState::callerFrame const): (JSC::ExecState::callerFrameOrEntryFrame const): (JSC::ExecState::unsafeCallerFrameOrEntryFrame const): * interpreter/FrameTracers.h: (JSC::NativeCallFrameTracer::NativeCallFrameTracer): (JSC::NativeCallFrameTracerWithRestore::NativeCallFrameTracerWithRestore): (JSC::NativeCallFrameTracerWithRestore::~NativeCallFrameTracerWithRestore): * interpreter/Interpreter.cpp: (JSC::UnwindFunctor::operator() const): (JSC::UnwindFunctor::copyCalleeSavesToEntryFrameCalleeSavesBuffer const): (JSC::Interpreter::unwind): * interpreter/StackVisitor.cpp: (JSC::StackVisitor::StackVisitor): (JSC::StackVisitor::gotoNextFrame): (JSC::StackVisitor::readNonInlinedFrame): (JSC::StackVisitor::Frame::dump const): * interpreter/StackVisitor.h: (JSC::StackVisitor::Frame::callerIsEntryFrame const): * interpreter/VMEntryRecord.h: (JSC::VMEntryRecord::prevTopEntryFrame): (JSC::VMEntryRecord::unsafePrevTopEntryFrame): (JSC::EntryFrame::vmEntryRecordOffset): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::restoreCalleeSavesFromEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::loadWasmContextInstance): (JSC::AssemblyHelpers::storeWasmContextInstance): (JSC::AssemblyHelpers::loadWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::storeWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBufferImpl): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::copyCalleeSavesToVMEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer): * jit/JIT.cpp: (JSC::JIT::emitEnterOptimizationCheck): (JSC::JIT::privateCompileExceptionHandlers): * jit/JITExceptions.cpp: (JSC::genericUnwind): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): (JSC::JIT::emitSlow_op_loop_hint): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): * jit/JITOperations.cpp: * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::nativeForGenerator): * jsc.cpp: (functionDumpCallFrame): * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LLIntThunks.cpp: (JSC::vmEntryRecord): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/Options.cpp: (JSC::recomputeDependentOptions): * runtime/Options.h: * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::FrameWalker): (JSC::FrameWalker::advanceToParentFrame): (JSC::SamplingProfiler::processUnverifiedStackTraces): * runtime/ThrowScope.cpp: (JSC::ThrowScope::~ThrowScope): * runtime/VM.cpp: (JSC::VM::VM): (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::topEntryFrameOffset): * runtime/VMTraps.cpp: (JSC::isSaneFrame): (JSC::VMTraps::tryInstallTrapBreakpoints): (JSC::VMTraps::invalidateCodeBlocksOnStack): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWasmContextInstance): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::parseAndCompile): * wasm/WasmB3IRGenerator.h: * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::BBQPlan): (JSC::Wasm::BBQPlan::compileFunctions): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBBQPlanInlines.h: (JSC::Wasm::BBQPlan::initializeCallees): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmBinding.h: * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::create): (JSC::Wasm::CodeBlock::CodeBlock): (JSC::Wasm::CodeBlock::compileAsync): (JSC::Wasm::CodeBlock::setCompilationFinished): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::offsetOfImportStubs): (JSC::Wasm::CodeBlock::allocationSize): (JSC::Wasm::CodeBlock::importWasmToEmbedderStub): (JSC::Wasm::CodeBlock::offsetOfImportWasmToEmbedderStub): (JSC::Wasm::CodeBlock::wasmToJSCallStubForImport): (JSC::Wasm::CodeBlock::compilationFinished): (JSC::Wasm::CodeBlock::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): * wasm/WasmContext.cpp: (JSC::Wasm::Context::useFastTLS): (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: Copied from Source/JavaScriptCore/wasm/WasmContext.h. * wasm/WasmFaultSignalHandler.cpp: * wasm/WasmFaultSignalHandler.h: * wasm/WasmFormat.h: * wasm/WasmInstance.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::~Instance): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: Added. (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::module): (JSC::Wasm::Instance::codeBlock): (JSC::Wasm::Instance::memory): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::loadF32Global const): (JSC::Wasm::Instance::loadF64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::offsetOfCachedStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::~Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::offsetOfSize): * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationCallback): (JSC::Wasm::Module::validateSync): (JSC::Wasm::Module::validateAsync): (JSC::Wasm::Module::getOrCreateCodeBlock): (JSC::Wasm::Module::compileSync): (JSC::Wasm::Module::compileAsync): * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseTableHelper): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::OMGPlan): (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::isValid const): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::runCompletionTasks): (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmPlan.h: (JSC::Wasm::Plan::dontFinalize): * wasm/WasmSignature.cpp: * wasm/WasmSignature.h: * wasm/WasmTable.cpp: Added. (JSC::Wasm::Table::create): (JSC::Wasm::Table::~Table): (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h. (JSC::Wasm::Table::maximum const): (JSC::Wasm::Table::size const): (JSC::Wasm::Table::offsetOfSize): (JSC::Wasm::Table::offsetOfFunctions): (JSC::Wasm::Table::offsetOfInstances): (JSC::Wasm::Table::isValidSize): * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): (JSC::Wasm::Thunks::setThrowWasmException): (JSC::Wasm::Thunks::throwWasmException): * wasm/WasmThunks.h: * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::stopAllPlansForContext): * wasm/WasmWorklist.h: * wasm/js/JSToWasm.cpp: Added. (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/JSWebAssembly.cpp: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.cpp. * wasm/js/JSWebAssembly.h: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.h. * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::create): (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::context const): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::webAssemblyToJSCallee): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::offsetOfTail): (JSC::JSWebAssemblyInstance::importFunctionInfo): (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): (JSC::JSWebAssemblyInstance::offsetOfImportFunction): (JSC::JSWebAssemblyInstance::importFunction): (JSC::JSWebAssemblyInstance::internalMemory): (JSC::JSWebAssemblyInstance::wasmCodeBlock const): (JSC::JSWebAssemblyInstance::offsetOfWasmTable): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::offsetOfGlobals): (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): (JSC::JSWebAssemblyInstance::cachedStackLimit const): (JSC::JSWebAssemblyInstance::setCachedStackLimit): (JSC::JSWebAssemblyInstance::wasmMemory): (JSC::JSWebAssemblyInstance::wasmModule): (JSC::JSWebAssemblyInstance::allocationSize): (JSC::JSWebAssemblyInstance::module const): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::create): (JSC::JSWebAssemblyMemory::adopt): (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::moduleInformation const): (JSC::JSWebAssemblyModule::exportSymbolTable const): (JSC::JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace const): (JSC::JSWebAssemblyModule::callee const): (JSC::JSWebAssemblyModule::codeBlock): (JSC::JSWebAssemblyModule::module): * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::create): (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::visitChildren): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::getFunction): (JSC::JSWebAssemblyTable::clearFunction): (JSC::JSWebAssemblyTable::setFunction): * wasm/js/JSWebAssemblyTable.h: (JSC::JSWebAssemblyTable::isValidSize): (JSC::JSWebAssemblyTable::maximum const): (JSC::JSWebAssemblyTable::size const): (JSC::JSWebAssemblyTable::table): * wasm/js/WasmToJS.cpp: Copied from Source/JavaScriptCore/wasm/WasmBinding.cpp. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): (JSC::WebAssemblyModuleConstructor::createModule): * wasm/js/WebAssemblyModuleConstructor.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::webAssemblyCompileFunc): (JSC::instantiate): (JSC::compileAndInstantiate): (JSC::webAssemblyValidateFunc): * wasm/js/WebAssemblyTableConstructor.cpp: (JSC::constructJSWebAssemblyTable): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Source/WebCore: * ForwardingHeaders/wasm/WasmModule.h: Added. This used to be included in JSWebAssemblyModule.h. * bindings/js/SerializedScriptValue.cpp: Update postMessage code according to C++ API changes. Canonical link: https://commits.webkit.org/194750@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223738 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-20 02:23:29 +00:00
[WASM-References] Add support for multiple tables https://bugs.webkit.org/show_bug.cgi?id=198760 Reviewed by Saam Barati. JSTests: * wasm/Builder.js: * wasm/js-api/call-indirect.js: (const.oneTable): (const.multiTable): (multiTable): (multiTable.Polyphic2Import): (multiTable.VirtualImport): (const.wasmModuleWhichImportJS): Deleted. (const.makeTable): Deleted. (): Deleted. (Polyphic2Import): Deleted. (VirtualImport): Deleted. * wasm/js-api/table.js: (new.WebAssembly.Module): (assert.throws): (assertBadTableImport): (assert.truthy): (assert.throws.new.WebAssembly.Module.builder.WebAssembly): Deleted. * wasm/references/anyref_table.js: * wasm/references/anyref_table_import.js: (makeImport): (string_appeared_here.fullGC.assert.eq.1.exports.get_tbl.makeImport): (string_appeared_here.fullGC.assert.eq.1.exports.get_tbl): * wasm/references/multitable.js: Added. (assert.throws.1.exports.set_tbl0): (assert.throws): (assert.eq): * wasm/references/validation.js: (assert.throws.new.WebAssembly.Module.bin): (assert.throws): * wasm/spec-tests/imports.wast.js: * wasm/wasm.json: * wasm/Builder.js: * wasm/js-api/call-indirect.js: (const.oneTable): (const.multiTable): (multiTable): (multiTable.Polyphic2Import): (multiTable.VirtualImport): (const.wasmModuleWhichImportJS): Deleted. (const.makeTable): Deleted. (): Deleted. (Polyphic2Import): Deleted. (VirtualImport): Deleted. * wasm/js-api/table.js: (new.WebAssembly.Module): (assert.throws): (assertBadTableImport): (assert.truthy): (assert.throws.new.WebAssembly.Module.builder.WebAssembly): Deleted. * wasm/references/anyref_table.js: * wasm/references/anyref_table_import.js: (makeImport): (string_appeared_here.fullGC.assert.eq.1.exports.get_tbl.makeImport): (string_appeared_here.fullGC.assert.eq.1.exports.get_tbl): * wasm/references/func_ref.js: (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly.fun): Deleted. (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly.assert.throws): Deleted. (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly): Deleted. * wasm/references/multitable.js: Added. (assert.throws.1.exports.set_tbl0): (assert.throws): (assert.eq): (string_appeared_here.tableInsanity): (I32Const.0.GetLocal.0.TableSet.1.End.End.WebAssembly.): (I32Const.0.GetLocal.0.TableSet.1.End.End.WebAssembly): * wasm/references/validation.js: (assert.throws.new.WebAssembly.Module.bin): (assert.throws): * wasm/spec-tests/imports.wast.js: * wasm/wasm.json: Source/JavaScriptCore: Support multiple wasm tables. We turn tableInformation into a tables array, and update all of the existing users to give a table index. The array of Tables in Wasm::Instance is hung off the tail to make it easier to use from jit code. * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::AirIRGenerator): (JSC::Wasm::AirIRGenerator::addTableGet): (JSC::Wasm::AirIRGenerator::addTableSet): (JSC::Wasm::AirIRGenerator::addCallIndirect): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::addTableGet): (JSC::Wasm::B3IRGenerator::addTableSet): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmExceptionType.h: * wasm/WasmFormat.h: (JSC::Wasm::Element::Element): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parseExpression): (JSC::Wasm::FunctionParser<Context>::parseUnreachableExpression): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::extraMemoryAllocated const): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::setTable): * wasm/WasmInstance.h: (JSC::Wasm::Instance::updateCachedMemory): (JSC::Wasm::Instance::offsetOfGlobals): (JSC::Wasm::Instance::offsetOfTablePtr): (JSC::Wasm::Instance::allocationSize): (JSC::Wasm::Instance::table): Deleted. (JSC::Wasm::Instance::setTable): Deleted. (JSC::Wasm::Instance::offsetOfTable): Deleted. * wasm/WasmModuleInformation.h: (JSC::Wasm::ModuleInformation::tableCount const): * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseImport): (JSC::Wasm::SectionParser::parseTableHelper): (JSC::Wasm::SectionParser::parseTable): (JSC::Wasm::SectionParser::parseElement): * wasm/WasmTable.h: (JSC::Wasm::Table::owner const): * wasm/WasmValidate.cpp: (JSC::Wasm::Validate::addTableGet): (JSC::Wasm::Validate::addTableSet): (JSC::Wasm::Validate::addCallIndirect): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/JSWebAssemblyInstance.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/wasm.json: Canonical link: https://commits.webkit.org/212963@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@246571 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-06-18 22:01:02 +00:00
static_assert(sizeof(ImportFunctionInfo) == WTF::roundUpToMultipleOf<sizeof(uint64_t)>(sizeof(ImportFunctionInfo)), "We rely on this for the alignment to be correct");
static constexpr size_t offsetOfTablePtr(unsigned numImportFunctions, unsigned i) { return offsetOfTail() + sizeof(ImportFunctionInfo) * numImportFunctions + sizeof(Table*) * i; }
We need to set topCallFrame when calling Wasm::Memory::grow from the JIT https://bugs.webkit.org/show_bug.cgi?id=179639 <rdar://problem/35513018> Reviewed by JF Bastien. JSTests: * wasm/function-tests/grow-memory-cause-gc.js: Added. (escape): (i.func): Source/JavaScriptCore: Calling Wasm::Memory::grow from the JIT may cause us to GC. When we GC, we will walk the stack for ShadowChicken (and maybe other things). We weren't updating topCallFrame when calling grow from the Wasm JIT. This would cause the GC to use stale topCallFrame bits in VM, often leading to crashes. This patch fixes this bug by giving Wasm::Instance a lambda that is called when we need to store the topCallFrame. Users of Wasm::Instance can provide a function to do this action. Currently, JSWebAssemblyInstance passes in a lambda that stores to VM.topCallFrame. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::addGrowMemory): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): * wasm/WasmInstance.h: (JSC::Wasm::Instance::storeTopCallFrame): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: * wasm/js/WasmToJS.cpp: (JSC::Wasm::wasmToJSException): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyPrototype.cpp: (JSC::instantiate): Canonical link: https://commits.webkit.org/195695@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224810 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-14 09:05:33 +00:00
void storeTopCallFrame(void* callFrame)
{
m_storeTopCallFrame(callFrame);
}
WebAssembly: no VM / JS version of everything but Instance https://bugs.webkit.org/show_bug.cgi?id=177473 Reviewed by Filip Pizlo, Saam Barati. JSTests: - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. * wasm/js-api/memory-grow.js: (assertEq): * wasm/js-api/table.js: (assert.throws): Source/JavaScriptCore: This change entails cleaning up and splitting a bunch of code which we had intertwined between C++ classes which represent JS objects, and pure C++ implementation objects. This specific change goes most of the way towards allowing JSC's WebAssembly to work without VM / JS, up to but excluding JSWebAssemblyInstance (there's Wasm::Instance, but it's not *the* thing yet). Because of this we still have a few FIXME identifying places that need to change. A follow-up change will go the rest of the way. I went about this change in the simplest way possible: grep the JavaScriptCore/wasm directory for "JS[^C_]" as well as "VM" and exclude the /js/ sub-directory (which contains the JS implementation of WebAssembly). None of this change removes the need for a JIT entitlement to be able to use WebAssembly. We don't have an interpreter, the process therefore still needs to be allowed to JIT to use these pure-C++ APIs. Interesting things to note: - Remove VM from Plan and associated places. It can just live as a capture in the callback lambda if it's needed. - Wasm::Memory shouldn't require a VM. It was only used to ask the GC to collect. We now instead pass two lambdas at construction time for this purpose: one to notify of memory pressure, and the other to ask for syncrhonous memory reclamation. This allows whoever creates the memory to dictate how to react to both these cases, and for a JS embedding that's to call the GC (async or sync, respectively). - Move grow logic from JSWebAssemblyMemory to Wasm::Memory::grow. Use Expected there, with an enum class for failure types. - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. - When generating the grow_memory opcode, no need to get the VM. Instead, reach directly for Wasm::Memory and grow it. - JSWebAssemblyMemory::grow can now always throw on failure, because it's only ever called from JS (not from grow_memory as before). - Wasm::Memory now takes a callback for successful growth. This allows JS wrappers to register themselves when growth succeeds without Wasm::Memory knowning anything about JS. It'll also allow creating a list of callbacks for when we add thread support (we'll want to notify many wrappers, all under a lock). - Wasm::Memory is now back to being the source of truth about address / size, used directly by generated code instead of JSWebAssemblyMemory. - Move wasmToJS from the general WasmBinding header to its own header under wasm/js. It's only used by wasm/js/JSWebAssemblyCodeBlock.cpp, and uses VM, and therefore isn't general WebAssembly. - Make Wasm::Context an actual type (just a struct holding a JSWebAssemlyInstance for now) instead of an alias for that. Notably this doesn't add anything to the Context and doesn't change what actually gets passed around in JIT code (fast TLS or registers) because these changes potentially impact performance. The entire purpose of this change is to allow passing Wasm::Context around without having to know about VM. Since VM contains a Wasm::Context the JS embedding is effectively the same, but with this setup a non-JS embedding is much better off. - Move JSWebAssembly into the JS folder. - OMGPlan: use Wasm::CodeBlock directly instead of JSWebAssemblyCodeBlock. - wasm->JS stubs are now on the instance's tail as raw pointers, instead of being on JSWebAssemblyCodeBlock, and are now called wasm->Embedder stubs. The owned reference is still on JSWebAssemblyCodeBlock, and is still called wasm->JS stub. This move means that the embedder must, after creating a Wasm::CodeBlock, somehow create the stubs to call back into the embedder. This removes an indirection in the generated code because the B3 IR generator now reaches into the instance instead of JSWebAssemblyCodeBlock. - Move more CodeBlock things. Compilation completion is now marked by its own atomic<bool> flag instead of a nullptr plan: that required using a lock, and was causing a deadlock in stack-trace.js because before my changes JSWebAssemblyCodeBlock did its own completion checking separately from Wasm::CodeBlock, without getting the lock. Now that everything points to Wasm::CodeBlock and there's no cached completion marker, the lock was being acquired in a sanity-check assertion. - Embedder -> Wasm wrappers are now generated through a function that's passed in at compilation time, instead of being hard-coded as a JS -> Wasm wrapper. - WasmMemory doens't need to know about fault handling thunks. Only the IR generator should know, and should make sure that the exception throwing thunk is generated if any memory is present (note: with signal handling not all of them generate an exception check). - Make exception throwing pluggable: instead of having a hard-coded JS-specific lambda we now have a regular C++ function being called from JIT code when a WebAssembly exception is thrown. This allows any embedder to get called as they wish. For now a process can only have a single of these functions (i.e. only one embedder per process) because the trap handler is a singleton. That can be fixed in in #177475. - Create WasmEmbedder.h where all embedder plugging will live. - Split up JSWebAssemblyTable into Wasm::Table which is refcounted. JSWebAssemblyTable now only contains the JS functions in the table, and Wasm::Table is what's used by the JIT code to lookup where to call and do the instance check (for context switch). Note that this creates an extra allocation for all the instances in Wasm::Table, and in exchange removes an indirection in JIT code because the instance used to be obtained off of the JS function. Also note that it's the embedder than keeps the instances alive, not Wasm::Table (which holds a dumb pointer to the instance), because doing otherwise would cause reference cycles. - Add WasmInstance. It doesn't do much for now, owns globals. - JSWebAssembly instance now doesn't just contain the imported functions as JSObjects, it also has the corresponding import's instance and wasm entrypoint. This triples the space allocated per instance's imported function, but there shouldn't be that many imports. This has two upsides: it creates smaller and faster code, and makes is easier to disassociate embedder-specific things from embedder-neutral things. The small / faster win is in two places: B3 IR generator only needs offsetOfImportFunction for the call opcode (when the called index is an import) to know whether the import is wasm->wasm or wasm->embedder (this isn't known at compile-time because it's dependent on the import object), this is now done by seeing if that import function has an associated target instance (only wasm->wasm does); the other place is wasmBinding which uses offsetOfImportFunction to figure out the wasm->wasm target instance, and then gets WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation to do a tail call. The disassociation comes because the target instance can be Wasm::Instance once we change what the Context is, and WasmEntrypointLoadLocation is already embedder-independent. As a next step I can move this tail allocation from JSWebAssemblyInstance to Wasm::Instance, and leave importFunction in as an opaque pointer which is embedder-specific, and in JS will remain WriteBarrier<JSObject>. - Rename VMEntryFrame to EntryFrame, and in many places pass a pointer to it around instead of VM. This is a first step in allowing entry frames which aren't stored on VM, but which are instead stored in an embedder-specific location. That change won't really affect JS except through code churn, but will allow WebAssembly to use some machinery in a generic manner without having a VM. * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * debugger/Debugger.cpp: (JSC::Debugger::stepOutOfFunction): (JSC::Debugger::returnEvent): (JSC::Debugger::unwindEvent): (JSC::Debugger::didExecuteProgram): * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::compileExceptionHandlers): * dfg/DFGOSREntry.cpp: (JSC::DFG::prepareOSREntry): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::compileOSRExit): (JSC::DFG::OSRExit::compileExit): * dfg/DFGThunks.cpp: (JSC::DFG::osrEntryThunkGenerator): * ftl/FTLCompile.cpp: (JSC::FTL::compile): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::lower): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): (JSC::CallFrame::callerFrame): (JSC::CallFrame::unsafeCallerFrame): * interpreter/CallFrame.h: (JSC::ExecState::callerFrame const): (JSC::ExecState::callerFrameOrEntryFrame const): (JSC::ExecState::unsafeCallerFrameOrEntryFrame const): * interpreter/FrameTracers.h: (JSC::NativeCallFrameTracer::NativeCallFrameTracer): (JSC::NativeCallFrameTracerWithRestore::NativeCallFrameTracerWithRestore): (JSC::NativeCallFrameTracerWithRestore::~NativeCallFrameTracerWithRestore): * interpreter/Interpreter.cpp: (JSC::UnwindFunctor::operator() const): (JSC::UnwindFunctor::copyCalleeSavesToEntryFrameCalleeSavesBuffer const): (JSC::Interpreter::unwind): * interpreter/StackVisitor.cpp: (JSC::StackVisitor::StackVisitor): (JSC::StackVisitor::gotoNextFrame): (JSC::StackVisitor::readNonInlinedFrame): (JSC::StackVisitor::Frame::dump const): * interpreter/StackVisitor.h: (JSC::StackVisitor::Frame::callerIsEntryFrame const): * interpreter/VMEntryRecord.h: (JSC::VMEntryRecord::prevTopEntryFrame): (JSC::VMEntryRecord::unsafePrevTopEntryFrame): (JSC::EntryFrame::vmEntryRecordOffset): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::restoreCalleeSavesFromEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::loadWasmContextInstance): (JSC::AssemblyHelpers::storeWasmContextInstance): (JSC::AssemblyHelpers::loadWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::storeWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBufferImpl): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::copyCalleeSavesToVMEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer): * jit/JIT.cpp: (JSC::JIT::emitEnterOptimizationCheck): (JSC::JIT::privateCompileExceptionHandlers): * jit/JITExceptions.cpp: (JSC::genericUnwind): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): (JSC::JIT::emitSlow_op_loop_hint): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): * jit/JITOperations.cpp: * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::nativeForGenerator): * jsc.cpp: (functionDumpCallFrame): * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LLIntThunks.cpp: (JSC::vmEntryRecord): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/Options.cpp: (JSC::recomputeDependentOptions): * runtime/Options.h: * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::FrameWalker): (JSC::FrameWalker::advanceToParentFrame): (JSC::SamplingProfiler::processUnverifiedStackTraces): * runtime/ThrowScope.cpp: (JSC::ThrowScope::~ThrowScope): * runtime/VM.cpp: (JSC::VM::VM): (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::topEntryFrameOffset): * runtime/VMTraps.cpp: (JSC::isSaneFrame): (JSC::VMTraps::tryInstallTrapBreakpoints): (JSC::VMTraps::invalidateCodeBlocksOnStack): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWasmContextInstance): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::parseAndCompile): * wasm/WasmB3IRGenerator.h: * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::BBQPlan): (JSC::Wasm::BBQPlan::compileFunctions): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBBQPlanInlines.h: (JSC::Wasm::BBQPlan::initializeCallees): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmBinding.h: * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::create): (JSC::Wasm::CodeBlock::CodeBlock): (JSC::Wasm::CodeBlock::compileAsync): (JSC::Wasm::CodeBlock::setCompilationFinished): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::offsetOfImportStubs): (JSC::Wasm::CodeBlock::allocationSize): (JSC::Wasm::CodeBlock::importWasmToEmbedderStub): (JSC::Wasm::CodeBlock::offsetOfImportWasmToEmbedderStub): (JSC::Wasm::CodeBlock::wasmToJSCallStubForImport): (JSC::Wasm::CodeBlock::compilationFinished): (JSC::Wasm::CodeBlock::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): * wasm/WasmContext.cpp: (JSC::Wasm::Context::useFastTLS): (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: Copied from Source/JavaScriptCore/wasm/WasmContext.h. * wasm/WasmFaultSignalHandler.cpp: * wasm/WasmFaultSignalHandler.h: * wasm/WasmFormat.h: * wasm/WasmInstance.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::~Instance): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: Added. (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::module): (JSC::Wasm::Instance::codeBlock): (JSC::Wasm::Instance::memory): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::loadF32Global const): (JSC::Wasm::Instance::loadF64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::offsetOfCachedStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::~Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::offsetOfSize): * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationCallback): (JSC::Wasm::Module::validateSync): (JSC::Wasm::Module::validateAsync): (JSC::Wasm::Module::getOrCreateCodeBlock): (JSC::Wasm::Module::compileSync): (JSC::Wasm::Module::compileAsync): * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseTableHelper): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::OMGPlan): (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::isValid const): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::runCompletionTasks): (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmPlan.h: (JSC::Wasm::Plan::dontFinalize): * wasm/WasmSignature.cpp: * wasm/WasmSignature.h: * wasm/WasmTable.cpp: Added. (JSC::Wasm::Table::create): (JSC::Wasm::Table::~Table): (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h. (JSC::Wasm::Table::maximum const): (JSC::Wasm::Table::size const): (JSC::Wasm::Table::offsetOfSize): (JSC::Wasm::Table::offsetOfFunctions): (JSC::Wasm::Table::offsetOfInstances): (JSC::Wasm::Table::isValidSize): * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): (JSC::Wasm::Thunks::setThrowWasmException): (JSC::Wasm::Thunks::throwWasmException): * wasm/WasmThunks.h: * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::stopAllPlansForContext): * wasm/WasmWorklist.h: * wasm/js/JSToWasm.cpp: Added. (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/JSWebAssembly.cpp: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.cpp. * wasm/js/JSWebAssembly.h: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.h. * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::create): (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::context const): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::webAssemblyToJSCallee): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::offsetOfTail): (JSC::JSWebAssemblyInstance::importFunctionInfo): (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): (JSC::JSWebAssemblyInstance::offsetOfImportFunction): (JSC::JSWebAssemblyInstance::importFunction): (JSC::JSWebAssemblyInstance::internalMemory): (JSC::JSWebAssemblyInstance::wasmCodeBlock const): (JSC::JSWebAssemblyInstance::offsetOfWasmTable): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::offsetOfGlobals): (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): (JSC::JSWebAssemblyInstance::cachedStackLimit const): (JSC::JSWebAssemblyInstance::setCachedStackLimit): (JSC::JSWebAssemblyInstance::wasmMemory): (JSC::JSWebAssemblyInstance::wasmModule): (JSC::JSWebAssemblyInstance::allocationSize): (JSC::JSWebAssemblyInstance::module const): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::create): (JSC::JSWebAssemblyMemory::adopt): (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::moduleInformation const): (JSC::JSWebAssemblyModule::exportSymbolTable const): (JSC::JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace const): (JSC::JSWebAssemblyModule::callee const): (JSC::JSWebAssemblyModule::codeBlock): (JSC::JSWebAssemblyModule::module): * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::create): (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::visitChildren): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::getFunction): (JSC::JSWebAssemblyTable::clearFunction): (JSC::JSWebAssemblyTable::setFunction): * wasm/js/JSWebAssemblyTable.h: (JSC::JSWebAssemblyTable::isValidSize): (JSC::JSWebAssemblyTable::maximum const): (JSC::JSWebAssemblyTable::size const): (JSC::JSWebAssemblyTable::table): * wasm/js/WasmToJS.cpp: Copied from Source/JavaScriptCore/wasm/WasmBinding.cpp. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): (JSC::WebAssemblyModuleConstructor::createModule): * wasm/js/WebAssemblyModuleConstructor.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::webAssemblyCompileFunc): (JSC::instantiate): (JSC::compileAndInstantiate): (JSC::webAssemblyValidateFunc): * wasm/js/WebAssemblyTableConstructor.cpp: (JSC::constructJSWebAssemblyTable): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Source/WebCore: * ForwardingHeaders/wasm/WasmModule.h: Added. This used to be included in JSWebAssemblyModule.h. * bindings/js/SerializedScriptValue.cpp: Update postMessage code according to C++ API changes. Canonical link: https://commits.webkit.org/194750@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223738 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-20 02:23:29 +00:00
private:
WebAssembly: restore cached stack limit after out-call https://bugs.webkit.org/show_bug.cgi?id=179106 <rdar://problem/35337525> Reviewed by Saam Barati. JSTests: * wasm/function-tests/double-instance.js: Added. (const.imp.boom): (const.imp.get callAnother): Source/JavaScriptCore: We cache the stack limit on the Instance so that we can do fast stack checks where required. In regular usage the stack limit never changes because we always run on the same thread, but in rare cases an API user can totally migrate which thread (and therefore stack) is used for execution between WebAssembly traces. For that reason we set the cached stack limit to UINTPTR_MAX on the outgoing Instance when transitioning back into a different Instance. We usually restore the cached stack limit in Context::store, but this wasn't called on all code paths. We had a bug where an Instance calling into itself indirectly would therefore fail to restore its cached stack limit properly. This patch therefore restores the cached stack limit after direct calls which could be to imports (both wasm->wasm and wasm->embedder). We have to do all of them because we have no way of knowing what imports will do (they're known at instantiation time, not compilation time, and different instances can have different imports). To make this efficient we also add a pointer to the canonical location of the stack limit (i.e. the extra indirection we're trying to save by caching the stack limit on the Instance in the first place). This is potentially a small perf hit on imported direct calls. It's hard to say what the performance cost will be because we haven't seen much code in the wild which does this. We're adding two dependent loads and a store of the loaded value, which is unlikely to get used soon after. It's more code, but on an out-of-order processor it doesn't contribute to the critical path. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): * wasm/WasmInstance.h: (JSC::Wasm::Instance::offsetOfPointerToActualStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::create): * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): Canonical link: https://commits.webkit.org/196260@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225411 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-01 21:58:36 +00:00
Instance(Context*, Ref<Module>&&, EntryFrame**, void**, StoreTopCallFrameCallback&&);
WebAssembly: no VM / JS version of our implementation https://bugs.webkit.org/show_bug.cgi?id=177472 Reviewed by Michael Saboff. This patch removes all appearances of "JS" and "VM" in the wasm directory. These now only appear in the wasm/js directory, which is only used in a JS embedding of wasm. It should therefore now be possible to create non-JS embeddings of wasm through JSC, though it'll still require: - Mild codegen for wasm<->embedder calls; - A strategy for trap handling (no need for full unwind! Could kill). - Creation of the Wasm::* objects. - Calling convention handling to call the embedder. - Handling of multiple embedders (see #177475, this is optional). Most of the patch consists in renaming JSWebAssemblyInstance to Instance, and removing temporary copies which I'd added to make this specific patch very simple. * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): this one place which needs to know about who "owns" the Wasm::Instance. In a JS embedding it's the JSWebAssemblyInstance. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::getGlobal): (JSC::Wasm::B3IRGenerator::setGlobal): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmContext.cpp: (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: add an "owner", the Wasm::Context, move the "tail" import information from JSWebAssemblyInstance over to here. (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::owner const): (JSC::Wasm::Instance::offsetOfOwner): (JSC::Wasm::Instance::context const): (JSC::Wasm::Instance::setMemory): (JSC::Wasm::Instance::setTable): (JSC::Wasm::Instance::offsetOfMemory): (JSC::Wasm::Instance::offsetOfGlobals): (JSC::Wasm::Instance::offsetOfTable): (JSC::Wasm::Instance::offsetOfTail): (JSC::Wasm::Instance::numImportFunctions const): (JSC::Wasm::Instance::importFunctionInfo): (JSC::Wasm::Instance::offsetOfTargetInstance): (JSC::Wasm::Instance::offsetOfWasmEntrypoint): (JSC::Wasm::Instance::offsetOfWasmToEmbedderStubExecutableAddress): (JSC::Wasm::Instance::offsetOfImportFunction): (JSC::Wasm::Instance::importFunction): (JSC::Wasm::Instance::allocationSize): (JSC::Wasm::Instance::create): Deleted. * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmTable.cpp: (JSC::Wasm::Table::Table): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyInstance.cpp: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): The embedder decides what the import function is. Here we must properly placement-new it to what we've elected (and initialize it later). (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::moduleNamespaceObject): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::setTable): (JSC::JSWebAssemblyInstance::offsetOfInstance): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::context const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTail): Deleted. (): Deleted. (JSC::JSWebAssemblyInstance::importFunctionInfo): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmToEmbedderStubExecutableAddress): Deleted. (JSC::JSWebAssemblyInstance::offsetOfImportFunction): Deleted. (JSC::JSWebAssemblyInstance::importFunction): Deleted. (JSC::JSWebAssemblyInstance::internalMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmCodeBlock const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmTable): Deleted. (JSC::JSWebAssemblyInstance::offsetOfGlobals): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTopEntryFramePointer): Deleted. (JSC::JSWebAssemblyInstance::cachedStackLimit const): Deleted. (JSC::JSWebAssemblyInstance::setCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::wasmMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmModule): Deleted. (JSC::JSWebAssemblyInstance::allocationSize): Deleted. * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::setFunction): * wasm/js/WasmToJS.cpp: One extra indirection to find the JSWebAssemblyInstance. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::instantiate): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Canonical link: https://commits.webkit.org/195012@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224020 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-26 15:33:55 +00:00
[WASM-References] Add support for multiple tables https://bugs.webkit.org/show_bug.cgi?id=198760 Reviewed by Saam Barati. JSTests: * wasm/Builder.js: * wasm/js-api/call-indirect.js: (const.oneTable): (const.multiTable): (multiTable): (multiTable.Polyphic2Import): (multiTable.VirtualImport): (const.wasmModuleWhichImportJS): Deleted. (const.makeTable): Deleted. (): Deleted. (Polyphic2Import): Deleted. (VirtualImport): Deleted. * wasm/js-api/table.js: (new.WebAssembly.Module): (assert.throws): (assertBadTableImport): (assert.truthy): (assert.throws.new.WebAssembly.Module.builder.WebAssembly): Deleted. * wasm/references/anyref_table.js: * wasm/references/anyref_table_import.js: (makeImport): (string_appeared_here.fullGC.assert.eq.1.exports.get_tbl.makeImport): (string_appeared_here.fullGC.assert.eq.1.exports.get_tbl): * wasm/references/multitable.js: Added. (assert.throws.1.exports.set_tbl0): (assert.throws): (assert.eq): * wasm/references/validation.js: (assert.throws.new.WebAssembly.Module.bin): (assert.throws): * wasm/spec-tests/imports.wast.js: * wasm/wasm.json: * wasm/Builder.js: * wasm/js-api/call-indirect.js: (const.oneTable): (const.multiTable): (multiTable): (multiTable.Polyphic2Import): (multiTable.VirtualImport): (const.wasmModuleWhichImportJS): Deleted. (const.makeTable): Deleted. (): Deleted. (Polyphic2Import): Deleted. (VirtualImport): Deleted. * wasm/js-api/table.js: (new.WebAssembly.Module): (assert.throws): (assertBadTableImport): (assert.truthy): (assert.throws.new.WebAssembly.Module.builder.WebAssembly): Deleted. * wasm/references/anyref_table.js: * wasm/references/anyref_table_import.js: (makeImport): (string_appeared_here.fullGC.assert.eq.1.exports.get_tbl.makeImport): (string_appeared_here.fullGC.assert.eq.1.exports.get_tbl): * wasm/references/func_ref.js: (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly.fun): Deleted. (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly.assert.throws): Deleted. (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly): Deleted. * wasm/references/multitable.js: Added. (assert.throws.1.exports.set_tbl0): (assert.throws): (assert.eq): (string_appeared_here.tableInsanity): (I32Const.0.GetLocal.0.TableSet.1.End.End.WebAssembly.): (I32Const.0.GetLocal.0.TableSet.1.End.End.WebAssembly): * wasm/references/validation.js: (assert.throws.new.WebAssembly.Module.bin): (assert.throws): * wasm/spec-tests/imports.wast.js: * wasm/wasm.json: Source/JavaScriptCore: Support multiple wasm tables. We turn tableInformation into a tables array, and update all of the existing users to give a table index. The array of Tables in Wasm::Instance is hung off the tail to make it easier to use from jit code. * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::AirIRGenerator): (JSC::Wasm::AirIRGenerator::addTableGet): (JSC::Wasm::AirIRGenerator::addTableSet): (JSC::Wasm::AirIRGenerator::addCallIndirect): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::addTableGet): (JSC::Wasm::B3IRGenerator::addTableSet): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmExceptionType.h: * wasm/WasmFormat.h: (JSC::Wasm::Element::Element): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parseExpression): (JSC::Wasm::FunctionParser<Context>::parseUnreachableExpression): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::extraMemoryAllocated const): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::setTable): * wasm/WasmInstance.h: (JSC::Wasm::Instance::updateCachedMemory): (JSC::Wasm::Instance::offsetOfGlobals): (JSC::Wasm::Instance::offsetOfTablePtr): (JSC::Wasm::Instance::allocationSize): (JSC::Wasm::Instance::table): Deleted. (JSC::Wasm::Instance::setTable): Deleted. (JSC::Wasm::Instance::offsetOfTable): Deleted. * wasm/WasmModuleInformation.h: (JSC::Wasm::ModuleInformation::tableCount const): * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseImport): (JSC::Wasm::SectionParser::parseTableHelper): (JSC::Wasm::SectionParser::parseTable): (JSC::Wasm::SectionParser::parseElement): * wasm/WasmTable.h: (JSC::Wasm::Table::owner const): * wasm/WasmValidate.cpp: (JSC::Wasm::Validate::addTableGet): (JSC::Wasm::Validate::addTableSet): (JSC::Wasm::Validate::addCallIndirect): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/JSWebAssemblyInstance.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/wasm.json: Canonical link: https://commits.webkit.org/212963@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@246571 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-06-18 22:01:02 +00:00
static size_t allocationSize(Checked<size_t> numImportFunctions, Checked<size_t> numTables)
WebAssembly: no VM / JS version of our implementation https://bugs.webkit.org/show_bug.cgi?id=177472 Reviewed by Michael Saboff. This patch removes all appearances of "JS" and "VM" in the wasm directory. These now only appear in the wasm/js directory, which is only used in a JS embedding of wasm. It should therefore now be possible to create non-JS embeddings of wasm through JSC, though it'll still require: - Mild codegen for wasm<->embedder calls; - A strategy for trap handling (no need for full unwind! Could kill). - Creation of the Wasm::* objects. - Calling convention handling to call the embedder. - Handling of multiple embedders (see #177475, this is optional). Most of the patch consists in renaming JSWebAssemblyInstance to Instance, and removing temporary copies which I'd added to make this specific patch very simple. * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): this one place which needs to know about who "owns" the Wasm::Instance. In a JS embedding it's the JSWebAssemblyInstance. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::getGlobal): (JSC::Wasm::B3IRGenerator::setGlobal): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmContext.cpp: (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: add an "owner", the Wasm::Context, move the "tail" import information from JSWebAssemblyInstance over to here. (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::owner const): (JSC::Wasm::Instance::offsetOfOwner): (JSC::Wasm::Instance::context const): (JSC::Wasm::Instance::setMemory): (JSC::Wasm::Instance::setTable): (JSC::Wasm::Instance::offsetOfMemory): (JSC::Wasm::Instance::offsetOfGlobals): (JSC::Wasm::Instance::offsetOfTable): (JSC::Wasm::Instance::offsetOfTail): (JSC::Wasm::Instance::numImportFunctions const): (JSC::Wasm::Instance::importFunctionInfo): (JSC::Wasm::Instance::offsetOfTargetInstance): (JSC::Wasm::Instance::offsetOfWasmEntrypoint): (JSC::Wasm::Instance::offsetOfWasmToEmbedderStubExecutableAddress): (JSC::Wasm::Instance::offsetOfImportFunction): (JSC::Wasm::Instance::importFunction): (JSC::Wasm::Instance::allocationSize): (JSC::Wasm::Instance::create): Deleted. * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmTable.cpp: (JSC::Wasm::Table::Table): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyInstance.cpp: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): The embedder decides what the import function is. Here we must properly placement-new it to what we've elected (and initialize it later). (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::moduleNamespaceObject): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::setTable): (JSC::JSWebAssemblyInstance::offsetOfInstance): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::context const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTail): Deleted. (): Deleted. (JSC::JSWebAssemblyInstance::importFunctionInfo): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmToEmbedderStubExecutableAddress): Deleted. (JSC::JSWebAssemblyInstance::offsetOfImportFunction): Deleted. (JSC::JSWebAssemblyInstance::importFunction): Deleted. (JSC::JSWebAssemblyInstance::internalMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmCodeBlock const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmTable): Deleted. (JSC::JSWebAssemblyInstance::offsetOfGlobals): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTopEntryFramePointer): Deleted. (JSC::JSWebAssemblyInstance::cachedStackLimit const): Deleted. (JSC::JSWebAssemblyInstance::setCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::wasmMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmModule): Deleted. (JSC::JSWebAssemblyInstance::allocationSize): Deleted. * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::setFunction): * wasm/js/WasmToJS.cpp: One extra indirection to find the JSWebAssemblyInstance. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::instantiate): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Canonical link: https://commits.webkit.org/195012@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224020 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-26 15:33:55 +00:00
{
Rename Checked::unsafeGet() to Checked::value() https://bugs.webkit.org/show_bug.cgi?id=226514 Reviewed by Darin Adler. Rename Checked::unsafeGet() to Checked::value(). The "unsafeGet" naming is confusing as this function isn't really unsafe since it will crash if the value has overflowed. Also add an `operator T()` to implicitly convert a Checked to its underlying type without needing to call value(). Source/JavaScriptCore: * b3/B3Const32Value.cpp: (JSC::B3::Const32Value::checkAddConstant const): (JSC::B3::Const32Value::checkSubConstant const): (JSC::B3::Const32Value::checkMulConstant const): * b3/B3Const64Value.cpp: (JSC::B3::Const64Value::checkAddConstant const): (JSC::B3::Const64Value::checkSubConstant const): (JSC::B3::Const64Value::checkMulConstant const): * bytecompiler/BytecodeGenerator.h: (JSC::FinallyContext::numberOfBreaksOrContinues const): * dfg/DFGConstantFoldingPhase.cpp: (JSC::DFG::ConstantFoldingPhase::foldConstants): * dfg/DFGOperations.cpp: (JSC::DFG::JSC_DEFINE_JIT_OPERATION): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::compileNewArrayWithSpread): (JSC::FTL::DFG::LowerDFGToB3::compileSpread): (JSC::FTL::DFG::LowerDFGToB3::compileCallOrConstructVarargsSpread): (JSC::FTL::DFG::LowerDFGToB3::compileForwardVarargsWithSpread): * ftl/FTLOperations.cpp: (JSC::FTL::JSC_DEFINE_JIT_OPERATION): * heap/Heap.cpp: (JSC::Heap::deprecatedReportExtraMemorySlowCase): (JSC::Heap::extraMemorySize): (JSC::Heap::updateAllocationLimits): (JSC::Heap::reportExtraMemoryVisited): * heap/SlotVisitor.cpp: (JSC::SlotVisitor::propagateExternalMemoryVisitedIfNecessary): * runtime/ArgList.cpp: (JSC::MarkedArgumentBuffer::slowEnsureCapacity): (JSC::MarkedArgumentBuffer::expandCapacity): * runtime/ArrayPrototype.cpp: (JSC::concatAppendOne): (JSC::JSC_DEFINE_HOST_FUNCTION): * runtime/CommonSlowPaths.cpp: (JSC::JSC_DEFINE_COMMON_SLOW_PATH): * runtime/DirectArguments.h: * runtime/HashMapImpl.h: (JSC::HashMapBuffer::allocationSize): (JSC::HashMapImpl::HashMapImpl): * runtime/HashMapImplInlines.h: (JSC::nextCapacity): (JSC::HashMapImpl<HashMapBucketType>::finishCreation): * runtime/JSBigInt.cpp: (JSC::JSBigInt::parseInt): * runtime/JSImmutableButterfly.h: (JSC::JSImmutableButterfly::tryCreate): * runtime/JSLexicalEnvironment.h: (JSC::JSLexicalEnvironment::offsetOfVariable): (JSC::JSLexicalEnvironment::allocationSizeForScopeSize): * runtime/JSObject.h: * runtime/JSPropertyNameEnumerator.cpp: (JSC::JSPropertyNameEnumerator::create): * runtime/JSString.h: * runtime/ScopedArguments.cpp: (JSC::ScopedArguments::createUninitialized): * runtime/StringPrototype.cpp: (JSC::jsSpliceSubstrings): (JSC::jsSpliceSubstringsWithSeparators): * runtime/StructureChain.cpp: (JSC::StructureChain::create): * runtime/VM.h: (JSC::ScratchBuffer::allocationSize): * runtime/WeakMapImpl.h: (JSC::WeakMapBuffer::allocationSize): * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::AirIRGenerator): (JSC::Wasm::AirIRGenerator::emitCallPatchpoint): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): * wasm/WasmInstance.cpp: * wasm/WasmInstance.h: (JSC::Wasm::Instance::allocationSize): * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::push): (JSC::Wasm::LLIntGenerator::getDropKeepCount): (JSC::Wasm::LLIntGenerator::walkExpressionStack): (JSC::Wasm::LLIntGenerator::finalize): (JSC::Wasm::LLIntGenerator::callInformationForCaller): (JSC::Wasm::LLIntGenerator::addLoop): (JSC::Wasm::LLIntGenerator::addTopLevel): (JSC::Wasm::LLIntGenerator::addBlock): (JSC::Wasm::LLIntGenerator::addIf): (JSC::Wasm::LLIntGenerator::addElseToUnreachable): * wasm/WasmSignature.h: (JSC::Wasm::Signature::allocatedSize): * wasm/WasmStreamingParser.cpp: (JSC::Wasm::StreamingParser::addBytes): * wasm/WasmTable.cpp: (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::FuncRefTable::FuncRefTable): * yarr/YarrInterpreter.cpp: (JSC::Yarr::Interpreter::DisjunctionContext::allocationSize): (JSC::Yarr::Interpreter::ParenthesesDisjunctionContext::allocationSize): (JSC::Yarr::Interpreter::allocParenthesesDisjunctionContext): (JSC::Yarr::ByteCompiler::atomCharacterClass): (JSC::Yarr::ByteCompiler::atomBackReference): (JSC::Yarr::ByteCompiler::atomParentheticalAssertionEnd): (JSC::Yarr::ByteCompiler::atomParenthesesSubpatternEnd): (JSC::Yarr::ByteCompiler::atomParenthesesOnceEnd): (JSC::Yarr::ByteCompiler::atomParenthesesTerminalEnd): (JSC::Yarr::ByteCompiler::emitDisjunction): * yarr/YarrInterpreter.h: (JSC::Yarr::ByteTerm::ByteTerm): (JSC::Yarr::ByteTerm::CheckInput): (JSC::Yarr::ByteTerm::UncheckInput): * yarr/YarrJIT.cpp: * yarr/YarrParser.h: (JSC::Yarr::Parser::consumeNumber): * yarr/YarrPattern.cpp: (JSC::Yarr::PatternTerm::dumpQuantifier): Source/WebCore: * bindings/js/SerializedScriptValue.cpp: (WebCore::CloneDeserializer::readTerminal): * dom/TextEncoderStreamEncoder.cpp: (WebCore::TextEncoderStreamEncoder::encode): * editing/markup.cpp: (WebCore::StyledMarkupAccumulator::takeResults): * html/FileInputType.cpp: (WebCore::FileInputType::saveFormControlState const): * html/ImageData.cpp: (WebCore::ImageData::create): (WebCore::ImageData::createUninitialized): * html/MediaElementSession.cpp: (WebCore::isElementRectMostlyInMainFrame): * html/canvas/WebGL2RenderingContext.cpp: (WebCore::WebGL2RenderingContext::sliceArrayBufferView): (WebCore::WebGL2RenderingContext::copyBufferSubData): (WebCore::WebGL2RenderingContext::getBufferSubData): (WebCore::WebGL2RenderingContext::validateClearBuffer): * html/canvas/WebGLBuffer.cpp: (WebCore::WebGLBuffer::associateBufferSubDataImpl): (WebCore::WebGLBuffer::associateCopyBufferSubData): * html/canvas/WebGLRenderingContextBase.cpp: (WebCore::clip2D): (WebCore::WebGLRenderingContextBase::validateDrawArrays): (WebCore::WebGLRenderingContextBase::validateDrawElements): (WebCore::WebGLRenderingContextBase::validateTexFuncData): (WebCore::WebGLRenderingContextBase::validateCompressedTexFuncData): (WebCore::WebGLRenderingContextBase::validateSimulatedVertexAttrib0): * html/canvas/WebGLRenderingContextBase.h: (WebCore::WebGLRenderingContextBase::validateTexImageSubRectangle): (WebCore::WebGLRenderingContextBase::checkedAddAndMultiply): * page/FrameView.h: (WebCore::FrameView::incrementVisuallyNonEmptyPixelCount): * page/History.cpp: (WebCore::History::stateObjectAdded): * platform/audio/AudioArray.h: (WebCore::AudioArray::resize): * platform/audio/cocoa/AudioFileReaderCocoa.cpp: (WebCore::tryCreateAudioBufferList): * platform/audio/cocoa/CARingBuffer.cpp: (WebCore::CARingBuffer::adoptStorage): (WebCore::CARingBuffer::initializeAfterAllocation): (WebCore::CARingBuffer::allocate): * platform/audio/cocoa/WebAudioBufferList.cpp: (WebCore::WebAudioBufferList::WebAudioBufferList): * platform/graphics/FormatConverter.h: (WebCore::FormatConverter::FormatConverter): * platform/graphics/GraphicsContextGL.cpp: (WebCore::GraphicsContextGL::computeImageSizeInBytes): * platform/graphics/ImageBackingStore.h: (WebCore::ImageBackingStore::setSize): (WebCore::ImageBackingStore::clear): * platform/graphics/ImageBufferBackend.cpp: (WebCore::ImageBufferBackend::calculateMemoryCost): * platform/graphics/ImageFrame.h: (WebCore::ImageFrame::frameBytes const): * platform/graphics/ImageSource.cpp: (WebCore::ImageSource::maximumSubsamplingLevel): * platform/graphics/PixelBuffer.cpp: (WebCore::PixelBuffer::tryCreateForDecoding): (WebCore::PixelBuffer::tryCreate): * platform/graphics/PixelBuffer.h: (WebCore::PixelBuffer::encode const): (WebCore::PixelBuffer::decode): * platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm: (WebCore::ImageDecoderAVFObjC::frameBytesAtIndex const): * platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm: (WebCore::MediaSampleAVFObjC::setByteRangeOffset): (WebCore::MediaSampleAVFObjC::byteRangeForAttachment const): * platform/graphics/ca/GraphicsLayerCA.cpp: (WebCore::GraphicsLayerCA::updateBackdropFilters): * platform/graphics/ca/LayerPool.cpp: (WebCore::LayerPool::backingStoreBytesForSize): * platform/graphics/cg/GraphicsContextGLCG.cpp: (WebCore::GraphicsContextGLImageExtractor::extractImage): * platform/graphics/cg/ImageBufferCGBackend.cpp: (WebCore::ImageBufferCGBackend::calculateBytesPerRow): * platform/graphics/cg/ImageDecoderCG.cpp: (WebCore::ImageDecoderCG::frameBytesAtIndex const): * platform/graphics/cocoa/SourceBufferParser.cpp: (WebCore::SourceBufferParser::Segment::read const): * platform/graphics/filters/FEColorMatrix.cpp: (WebCore::effectApplyAccelerated): * platform/graphics/filters/FEGaussianBlur.cpp: (WebCore::FEGaussianBlur::platformApplySoftware): * platform/graphics/filters/FETurbulence.cpp: (WebCore::FETurbulence::platformApplySoftware): * platform/graphics/filters/FilterEffect.cpp: (WebCore::FilterEffect::unmultipliedResult): (WebCore::FilterEffect::premultipliedResult): (WebCore::copyPremultiplyingAlpha): (WebCore::copyUnpremultiplyingAlpha): * platform/graphics/gpu/cocoa/GPUBindGroupAllocatorMetal.mm: (WebCore::GPUBindGroupAllocator::allocateAndSetEncoders): (WebCore::GPUBindGroupAllocator::reallocate): * platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm: (WebCore::GPUCommandBuffer::copyBufferToBuffer): * platform/graphics/gpu/cocoa/GPURenderPassEncoderMetal.mm: (WebCore::GPURenderPassEncoder::drawIndexed): * platform/graphics/gstreamer/ImageDecoderGStreamer.cpp: (WebCore::ImageDecoderGStreamer::frameBytesAtIndex const): * platform/graphics/nicosia/NicosiaBuffer.cpp: (Nicosia::Buffer::Buffer): * platform/graphics/win/Direct2DUtilities.cpp: (WebCore::Direct2D::createDirect2DImageSurfaceWithData): * platform/graphics/win/ImageBufferDirect2DBackend.cpp: (WebCore::ImageBufferDirect2DBackend::compatibleBitmap): * platform/graphics/win/ImageDecoderDirect2D.cpp: (WebCore::ImageDecoderDirect2D::frameBytesAtIndex const): * platform/image-decoders/ScalableImageDecoder.cpp: (WebCore::ScalableImageDecoder::frameBytesAtIndex const): * platform/image-decoders/jpeg2000/JPEG2000ImageDecoder.cpp: (WebCore::sycc444ToRGB): (WebCore::sycc422ToRGB): (WebCore::sycc420ToRGB): * platform/ios/LegacyTileLayerPool.mm: (WebCore::LegacyTileLayerPool::bytesBackingLayerWithPixelSize): * platform/text/TextCodecUTF16.cpp: (WebCore::TextCodecUTF16::encode const): * platform/text/TextCodecUTF8.cpp: (WebCore::TextCodecUTF8::encodeUTF8): * rendering/RenderLayerCompositor.cpp: (WebCore::RenderLayerCompositor::requiresCompositingForCanvas const): * rendering/shapes/Shape.cpp: (WebCore::Shape::createRasterShape): * storage/StorageMap.cpp: (WebCore::StorageMap::setItem): * xml/XSLStyleSheetLibxslt.cpp: (WebCore::XSLStyleSheet::parseString): * xml/XSLTProcessorLibxslt.cpp: (WebCore::xsltParamArrayFromParameterMap): * xml/parser/CharacterReferenceParserInlines.h: (WebCore::consumeCharacterReference): Source/WebKit: * GPUProcess/graphics/RemoteRenderingBackend.cpp: (WebKit::RemoteRenderingBackend::nextDestinationImageBufferAfterApplyingDisplayLists): * NetworkProcess/WebStorage/LocalStorageDatabase.cpp: (WebKit::LocalStorageDatabase::setItem): * NetworkProcess/cache/CacheStorageEngineCache.cpp: (WebKit::CacheStorage::Cache::put): * Platform/IPC/ArgumentCoders.h: * Platform/IPC/cocoa/ConnectionCocoa.mm: (IPC::Connection::sendOutgoingMessage): (IPC::createMessageDecoder): * Platform/IPC/cocoa/MachMessage.cpp: (IPC::MachMessage::create): * Shared/ShareableBitmap.cpp: (WebKit::ShareableBitmap::Handle::encode const): (WebKit::ShareableBitmap::create): (WebKit::ShareableBitmap::createShareable): * Shared/ShareableBitmap.h: (WebKit::ShareableBitmap::bytesPerRow const): (WebKit::ShareableBitmap::sizeInBytes const): * Shared/ShareableResource.cpp: (WebKit::ShareableResource::create): * Shared/cg/ShareableBitmapCG.cpp: (WebKit::ShareableBitmap::calculateBytesPerRow): (WebKit::ShareableBitmap::createGraphicsContext): (WebKit::ShareableBitmap::createCGImage const): * Shared/mac/MediaFormatReader/MediaFormatReader.cpp: (WebKit::MediaFormatReader::copyTrackArray): * Shared/mac/MediaFormatReader/MediaSampleCursor.cpp: (WebKit::MediaSampleCursor::copySampleLocation const): * WebProcess/GPU/graphics/DisplayListWriterHandle.cpp: (WebKit::DisplayListWriterHandle::advance): * WebProcess/GPU/graphics/ImageBufferShareableBitmapBackend.cpp: (WebKit::ImageBufferShareableBitmapBackend::calculateBytesPerRow): * WebProcess/GPU/media/RemoteImageDecoderAVF.cpp: (WebKit::RemoteImageDecoderAVF::frameBytesAtIndex const): * WebProcess/Network/WebSocketChannel.cpp: (WebKit::WebSocketChannel::increaseBufferedAmount): * WebProcess/WebPage/ios/WebPageIOS.mm: (WebKit::WebPage::requestEvasionRectsAboveSelection): (WebKit::WebPage::updateSelectionWithDelta): Source/WTF: * wtf/CheckedArithmetic.h: (WTF::Checked::operator! const): (WTF::Checked::operator bool const): (WTF::Checked::operator T const): (WTF::Checked::value const): (WTF::Checked::operator==): (WTF::Checked::operator< const): (WTF::Checked::operator<= const): (WTF::Checked::operator> const): (WTF::Checked::operator>= const): * wtf/ConcurrentBuffer.h: * wtf/FastMalloc.cpp: (WTF::fastCalloc): (WTF::tryFastCalloc): * wtf/Gigacage.cpp: (Gigacage::tryMallocArray): * wtf/URLHelpers.cpp: (WTF::URLHelpers::userVisibleURL): * wtf/URLParser.cpp: (WTF::URLParser::parseIPv4Piece): * wtf/UniqueArray.h: * wtf/cocoa/NSURLExtras.mm: (WTF::dataWithUserTypedString): * wtf/glib/SocketConnection.cpp: (WTF::SocketConnection::readMessage): (WTF::SocketConnection::sendMessage): * wtf/text/CString.cpp: (WTF::CStringBuffer::createUninitialized): * wtf/text/StringBuffer.h: (WTF::StringBuffer::StringBuffer): * wtf/text/StringBuilderJSON.cpp: (WTF::StringBuilder::appendQuotedJSONString): * wtf/text/StringConcatenate.h: (WTF::tryMakeStringFromAdapters): * wtf/text/StringImpl.h: (WTF::StringImpl::allocationSize): * wtf/text/StringToIntegerConversion.h: (WTF::parseInteger): Tools: * TestWebKitAPI/Tests/WTF/CheckedArithmeticOperations.cpp: (TestWebKitAPI::CheckedArithmeticTester::run): (TestWebKitAPI::AllowMixedSignednessTest::run): (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/IntRectTests.cpp: (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WebCore/IntSizeTests.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/238371@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@278338 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-06-02 05:21:13 +00:00
return offsetOfTail() + sizeof(ImportFunctionInfo) * numImportFunctions + sizeof(Table*) * numTables;
WebAssembly: no VM / JS version of our implementation https://bugs.webkit.org/show_bug.cgi?id=177472 Reviewed by Michael Saboff. This patch removes all appearances of "JS" and "VM" in the wasm directory. These now only appear in the wasm/js directory, which is only used in a JS embedding of wasm. It should therefore now be possible to create non-JS embeddings of wasm through JSC, though it'll still require: - Mild codegen for wasm<->embedder calls; - A strategy for trap handling (no need for full unwind! Could kill). - Creation of the Wasm::* objects. - Calling convention handling to call the embedder. - Handling of multiple embedders (see #177475, this is optional). Most of the patch consists in renaming JSWebAssemblyInstance to Instance, and removing temporary copies which I'd added to make this specific patch very simple. * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): this one place which needs to know about who "owns" the Wasm::Instance. In a JS embedding it's the JSWebAssemblyInstance. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::getGlobal): (JSC::Wasm::B3IRGenerator::setGlobal): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmContext.cpp: (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: add an "owner", the Wasm::Context, move the "tail" import information from JSWebAssemblyInstance over to here. (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::owner const): (JSC::Wasm::Instance::offsetOfOwner): (JSC::Wasm::Instance::context const): (JSC::Wasm::Instance::setMemory): (JSC::Wasm::Instance::setTable): (JSC::Wasm::Instance::offsetOfMemory): (JSC::Wasm::Instance::offsetOfGlobals): (JSC::Wasm::Instance::offsetOfTable): (JSC::Wasm::Instance::offsetOfTail): (JSC::Wasm::Instance::numImportFunctions const): (JSC::Wasm::Instance::importFunctionInfo): (JSC::Wasm::Instance::offsetOfTargetInstance): (JSC::Wasm::Instance::offsetOfWasmEntrypoint): (JSC::Wasm::Instance::offsetOfWasmToEmbedderStubExecutableAddress): (JSC::Wasm::Instance::offsetOfImportFunction): (JSC::Wasm::Instance::importFunction): (JSC::Wasm::Instance::allocationSize): (JSC::Wasm::Instance::create): Deleted. * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmTable.cpp: (JSC::Wasm::Table::Table): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyInstance.cpp: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): The embedder decides what the import function is. Here we must properly placement-new it to what we've elected (and initialize it later). (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::moduleNamespaceObject): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::setTable): (JSC::JSWebAssemblyInstance::offsetOfInstance): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::context const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTail): Deleted. (): Deleted. (JSC::JSWebAssemblyInstance::importFunctionInfo): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmToEmbedderStubExecutableAddress): Deleted. (JSC::JSWebAssemblyInstance::offsetOfImportFunction): Deleted. (JSC::JSWebAssemblyInstance::importFunction): Deleted. (JSC::JSWebAssemblyInstance::internalMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmCodeBlock const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmTable): Deleted. (JSC::JSWebAssemblyInstance::offsetOfGlobals): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTopEntryFramePointer): Deleted. (JSC::JSWebAssemblyInstance::cachedStackLimit const): Deleted. (JSC::JSWebAssemblyInstance::setCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::wasmMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmModule): Deleted. (JSC::JSWebAssemblyInstance::allocationSize): Deleted. * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::setFunction): * wasm/js/WasmToJS.cpp: One extra indirection to find the JSWebAssemblyInstance. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::instantiate): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Canonical link: https://commits.webkit.org/195012@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224020 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-26 15:33:55 +00:00
}
void* m_owner { nullptr }; // In a JS embedding, this is a JSWebAssemblyInstance*.
Context* m_context { nullptr };
CagedPtr<Gigacage::Primitive, void, tagCagedPtr> m_cachedMemory;
Unreviewed, relanding r269940 https://bugs.webkit.org/show_bug.cgi?id=219076 JSTests: * wasm/function-tests/trap-load-shared.js: Added. (wasmFrameCountFromError): * wasm/function-tests/trap-store-shared.js: Added. * wasm/js-api/test_memory.js: (binaryShouldNotParse): * wasm/stress/shared-memory-errors.js: Added. (assert.throws): * wasm/stress/shared-wasm-memory-buffer.js: Added. LayoutTests/imported/w3c: * web-platform-tests/html/webappapis/scripting/processing-model-2/integration-with-the-javascript-agent-formalism/requires-success.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/memory/constructor-shared.tentative.any-expected.txt: * web-platform-tests/wasm/jsapi/memory/constructor-shared.tentative.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/memory/constructor.any-expected.txt: * web-platform-tests/wasm/jsapi/memory/constructor.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/memory/grow.any-expected.txt: * web-platform-tests/wasm/jsapi/memory/grow.any.worker-expected.txt: * web-platform-tests/webaudio/the-audio-api/the-audiobuffer-interface/audiobuffer-copy-channel-expected.txt: Source/JavaScriptCore: ARM64E clang optimizer is broken and optimizing forever if Wasm::MemoryHandle::memory() is inlined. Putting NEVER_INLINE onto this function for now (unfortunate). * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * llint/LLIntPCRanges.h: (JSC::LLInt::isWasmLLIntPC): * llint/LowLevelInterpreter.asm: * llint/WebAssembly.asm: * runtime/JSArrayBuffer.h: (JSC::JSArrayBuffer::toWrappedAllowShared): * runtime/JSArrayBufferView.h: * runtime/JSArrayBufferViewInlines.h: (JSC::JSArrayBufferView::toWrappedAllowShared): * runtime/JSGenericTypedArrayView.h: (JSC::JSGenericTypedArrayView<Adaptor>::toWrappedAllowShared): * runtime/Options.cpp: (JSC::overrideDefaults): (JSC::Options::initialize): * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::AirIRGenerator): (JSC::Wasm::AirIRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::AirIRGenerator::addCurrentMemory): (JSC::Wasm::AirIRGenerator::emitCheckAndPreparePointer): (JSC::Wasm::AirIRGenerator::addCall): (JSC::Wasm::AirIRGenerator::addCallIndirect): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::emitCheckAndPreparePointer): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmFaultSignalHandler.cpp: (JSC::Wasm::trapHandler): (JSC::Wasm::enableFastMemory): (JSC::Wasm::prepareFastMemory): * wasm/WasmInstance.h: (JSC::Wasm::Instance::cachedMemory const): (JSC::Wasm::Instance::cachedBoundsCheckingSize const): (JSC::Wasm::Instance::updateCachedMemory): (JSC::Wasm::Instance::offsetOfCachedBoundsCheckingSize): (JSC::Wasm::Instance::cachedMemorySize const): Deleted. (JSC::Wasm::Instance::offsetOfCachedMemorySize): Deleted. * wasm/WasmMemory.cpp: (JSC::Wasm::MemoryHandle::MemoryHandle): (JSC::Wasm::MemoryHandle::~MemoryHandle): (JSC::Wasm::MemoryHandle::memory const): (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::tryCreate): (JSC::Wasm::Memory::addressIsInGrowableOrFastMemory): (JSC::Wasm::Memory::growShared): (JSC::Wasm::Memory::grow): (JSC::Wasm::Memory::dump const): (JSC::Wasm::Memory::~Memory): Deleted. (JSC::Wasm::Memory::addressIsInActiveFastMemory): Deleted. * wasm/WasmMemory.h: (JSC::Wasm::Memory::addressIsInGrowableOrFastMemory): (JSC::Wasm::Memory::operator bool const): Deleted. (JSC::Wasm::Memory::memory const): Deleted. (JSC::Wasm::Memory::size const): Deleted. (JSC::Wasm::Memory::sizeInPages const): Deleted. (JSC::Wasm::Memory::initial const): Deleted. (JSC::Wasm::Memory::maximum const): Deleted. (JSC::Wasm::Memory::mode const): Deleted. (JSC::Wasm::Memory::check): Deleted. (JSC::Wasm::Memory::offsetOfMemory): Deleted. (JSC::Wasm::Memory::offsetOfSize): Deleted. (JSC::Wasm::Memory::addressIsInActiveFastMemory): Deleted. * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::tryCreate): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::buffer): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::WebAssemblyFunction::jsCallEntrypointSlow): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::evaluate): Source/WebCore: Tests: js/dom/webassembly-memory-normal-fail.html js/dom/webassembly-memory-shared-basic.html js/dom/webassembly-memory-shared-fail.html storage/indexeddb/shared-memory-structured-clone.html * Headers.cmake: * Modules/indexeddb/server/IDBSerializationContext.cpp: (WebCore::IDBServer::IDBSerializationContext::initializeVM): * WebCore.xcodeproj/project.pbxproj: * bindings/IDLTypes.h: * bindings/js/CommonVM.cpp: (WebCore::commonVMSlow): * bindings/js/JSDOMConvertBufferSource.h: (WebCore::Detail::BufferSourceConverter::convert): (WebCore::Converter<IDLArrayBuffer>::convert): (WebCore::Converter<IDLDataView>::convert): (WebCore::Converter<IDLInt8Array>::convert): (WebCore::Converter<IDLInt16Array>::convert): (WebCore::Converter<IDLInt32Array>::convert): (WebCore::Converter<IDLUint8Array>::convert): (WebCore::Converter<IDLUint16Array>::convert): (WebCore::Converter<IDLUint32Array>::convert): (WebCore::Converter<IDLUint8ClampedArray>::convert): (WebCore::Converter<IDLFloat32Array>::convert): (WebCore::Converter<IDLFloat64Array>::convert): (WebCore::Converter<IDLArrayBufferView>::convert): (WebCore::Converter<IDLAllowSharedAdaptor<T>>::convert): * bindings/js/JSDOMConvertUnion.h: * bindings/js/SerializedScriptValue.cpp: (WebCore::CloneSerializer::serialize): (WebCore::CloneSerializer::CloneSerializer): (WebCore::CloneSerializer::dumpIfTerminal): (WebCore::CloneDeserializer::deserialize): (WebCore::CloneDeserializer::CloneDeserializer): (WebCore::CloneDeserializer::readTerminal): (WebCore::SerializedScriptValue::SerializedScriptValue): (WebCore::SerializedScriptValue::computeMemoryCost const): (WebCore::SerializedScriptValue::create): (WebCore::SerializedScriptValue::deserialize): * bindings/js/SerializedScriptValue.h: * bindings/js/WebCoreJSClientData.cpp: (WebCore::JSVMClientData::initNormalWorld): * bindings/js/WebCoreJSClientData.h: * bindings/js/WebCoreTypedArrayController.cpp: (WebCore::WebCoreTypedArrayController::WebCoreTypedArrayController): (WebCore::WebCoreTypedArrayController::isAtomicsWaitAllowedOnCurrentThread): * bindings/js/WebCoreTypedArrayController.h: * bindings/scripts/CodeGeneratorJS.pm: (IsAnnotatedType): (GetAnnotatedIDLType): * bindings/scripts/IDLAttributes.json: * bindings/scripts/test/JS/JSTestObj.cpp: (WebCore::JSTestObjDOMConstructor::construct): (WebCore::jsTestObjPrototypeFunction_encodeIntoBody): (WebCore::JSC_DEFINE_HOST_FUNCTION): * bindings/scripts/test/TestObj.idl: * dom/TextDecoder.idl: * dom/TextDecoderStreamDecoder.idl: * dom/TextEncoder.idl: * workers/DedicatedWorkerGlobalScope.cpp: (WebCore::DedicatedWorkerGlobalScope::DedicatedWorkerGlobalScope): * workers/WorkerGlobalScope.cpp: (WebCore::WorkerGlobalScope::WorkerGlobalScope): * workers/WorkerGlobalScope.h: * workers/WorkerOrWorkletGlobalScope.cpp: (WebCore::WorkerOrWorkletGlobalScope::WorkerOrWorkletGlobalScope): * workers/WorkerOrWorkletGlobalScope.h: * workers/WorkerOrWorkletScriptController.cpp: (WebCore::WorkerOrWorkletScriptController::WorkerOrWorkletScriptController): * workers/WorkerOrWorkletScriptController.h: * workers/WorkerThreadType.h: Added. * workers/service/ServiceWorkerGlobalScope.cpp: (WebCore::ServiceWorkerGlobalScope::ServiceWorkerGlobalScope): * worklets/WorkletGlobalScope.cpp: (WebCore::WorkletGlobalScope::WorkletGlobalScope): Source/WTF: * wtf/PlatformEnable.h: LayoutTests: * js/dom/resources/webassembly-memory-normal-fail-worker.js: Added. * js/dom/resources/webassembly-memory-shared-worker.js: Added. (onmessage): * js/dom/webassembly-memory-normal-fail-expected.txt: Added. * js/dom/webassembly-memory-normal-fail.html: Added. * js/dom/webassembly-memory-shared-basic-expected.txt: Added. * js/dom/webassembly-memory-shared-basic.html: Added. * js/dom/webassembly-memory-shared-fail-expected.txt: Added. * js/dom/webassembly-memory-shared-fail.html: Added. * platform/win/TestExpectations: * storage/indexeddb/resources/shared-memory-structured-clone.js: Added. (prepareDatabase): (async startTests): (testSharedWebAssemblyMemory): * storage/indexeddb/shared-memory-structured-clone-expected.txt: Added. * storage/indexeddb/shared-memory-structured-clone.html: Added. Canonical link: https://commits.webkit.org/231721@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@269974 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-11-18 20:22:16 +00:00
size_t m_cachedBoundsCheckingSize { 0 };
WebAssembly: no VM / JS version of everything but Instance https://bugs.webkit.org/show_bug.cgi?id=177473 Reviewed by Filip Pizlo, Saam Barati. JSTests: - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. * wasm/js-api/memory-grow.js: (assertEq): * wasm/js-api/table.js: (assert.throws): Source/JavaScriptCore: This change entails cleaning up and splitting a bunch of code which we had intertwined between C++ classes which represent JS objects, and pure C++ implementation objects. This specific change goes most of the way towards allowing JSC's WebAssembly to work without VM / JS, up to but excluding JSWebAssemblyInstance (there's Wasm::Instance, but it's not *the* thing yet). Because of this we still have a few FIXME identifying places that need to change. A follow-up change will go the rest of the way. I went about this change in the simplest way possible: grep the JavaScriptCore/wasm directory for "JS[^C_]" as well as "VM" and exclude the /js/ sub-directory (which contains the JS implementation of WebAssembly). None of this change removes the need for a JIT entitlement to be able to use WebAssembly. We don't have an interpreter, the process therefore still needs to be allowed to JIT to use these pure-C++ APIs. Interesting things to note: - Remove VM from Plan and associated places. It can just live as a capture in the callback lambda if it's needed. - Wasm::Memory shouldn't require a VM. It was only used to ask the GC to collect. We now instead pass two lambdas at construction time for this purpose: one to notify of memory pressure, and the other to ask for syncrhonous memory reclamation. This allows whoever creates the memory to dictate how to react to both these cases, and for a JS embedding that's to call the GC (async or sync, respectively). - Move grow logic from JSWebAssemblyMemory to Wasm::Memory::grow. Use Expected there, with an enum class for failure types. - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. - When generating the grow_memory opcode, no need to get the VM. Instead, reach directly for Wasm::Memory and grow it. - JSWebAssemblyMemory::grow can now always throw on failure, because it's only ever called from JS (not from grow_memory as before). - Wasm::Memory now takes a callback for successful growth. This allows JS wrappers to register themselves when growth succeeds without Wasm::Memory knowning anything about JS. It'll also allow creating a list of callbacks for when we add thread support (we'll want to notify many wrappers, all under a lock). - Wasm::Memory is now back to being the source of truth about address / size, used directly by generated code instead of JSWebAssemblyMemory. - Move wasmToJS from the general WasmBinding header to its own header under wasm/js. It's only used by wasm/js/JSWebAssemblyCodeBlock.cpp, and uses VM, and therefore isn't general WebAssembly. - Make Wasm::Context an actual type (just a struct holding a JSWebAssemlyInstance for now) instead of an alias for that. Notably this doesn't add anything to the Context and doesn't change what actually gets passed around in JIT code (fast TLS or registers) because these changes potentially impact performance. The entire purpose of this change is to allow passing Wasm::Context around without having to know about VM. Since VM contains a Wasm::Context the JS embedding is effectively the same, but with this setup a non-JS embedding is much better off. - Move JSWebAssembly into the JS folder. - OMGPlan: use Wasm::CodeBlock directly instead of JSWebAssemblyCodeBlock. - wasm->JS stubs are now on the instance's tail as raw pointers, instead of being on JSWebAssemblyCodeBlock, and are now called wasm->Embedder stubs. The owned reference is still on JSWebAssemblyCodeBlock, and is still called wasm->JS stub. This move means that the embedder must, after creating a Wasm::CodeBlock, somehow create the stubs to call back into the embedder. This removes an indirection in the generated code because the B3 IR generator now reaches into the instance instead of JSWebAssemblyCodeBlock. - Move more CodeBlock things. Compilation completion is now marked by its own atomic<bool> flag instead of a nullptr plan: that required using a lock, and was causing a deadlock in stack-trace.js because before my changes JSWebAssemblyCodeBlock did its own completion checking separately from Wasm::CodeBlock, without getting the lock. Now that everything points to Wasm::CodeBlock and there's no cached completion marker, the lock was being acquired in a sanity-check assertion. - Embedder -> Wasm wrappers are now generated through a function that's passed in at compilation time, instead of being hard-coded as a JS -> Wasm wrapper. - WasmMemory doens't need to know about fault handling thunks. Only the IR generator should know, and should make sure that the exception throwing thunk is generated if any memory is present (note: with signal handling not all of them generate an exception check). - Make exception throwing pluggable: instead of having a hard-coded JS-specific lambda we now have a regular C++ function being called from JIT code when a WebAssembly exception is thrown. This allows any embedder to get called as they wish. For now a process can only have a single of these functions (i.e. only one embedder per process) because the trap handler is a singleton. That can be fixed in in #177475. - Create WasmEmbedder.h where all embedder plugging will live. - Split up JSWebAssemblyTable into Wasm::Table which is refcounted. JSWebAssemblyTable now only contains the JS functions in the table, and Wasm::Table is what's used by the JIT code to lookup where to call and do the instance check (for context switch). Note that this creates an extra allocation for all the instances in Wasm::Table, and in exchange removes an indirection in JIT code because the instance used to be obtained off of the JS function. Also note that it's the embedder than keeps the instances alive, not Wasm::Table (which holds a dumb pointer to the instance), because doing otherwise would cause reference cycles. - Add WasmInstance. It doesn't do much for now, owns globals. - JSWebAssembly instance now doesn't just contain the imported functions as JSObjects, it also has the corresponding import's instance and wasm entrypoint. This triples the space allocated per instance's imported function, but there shouldn't be that many imports. This has two upsides: it creates smaller and faster code, and makes is easier to disassociate embedder-specific things from embedder-neutral things. The small / faster win is in two places: B3 IR generator only needs offsetOfImportFunction for the call opcode (when the called index is an import) to know whether the import is wasm->wasm or wasm->embedder (this isn't known at compile-time because it's dependent on the import object), this is now done by seeing if that import function has an associated target instance (only wasm->wasm does); the other place is wasmBinding which uses offsetOfImportFunction to figure out the wasm->wasm target instance, and then gets WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation to do a tail call. The disassociation comes because the target instance can be Wasm::Instance once we change what the Context is, and WasmEntrypointLoadLocation is already embedder-independent. As a next step I can move this tail allocation from JSWebAssemblyInstance to Wasm::Instance, and leave importFunction in as an opaque pointer which is embedder-specific, and in JS will remain WriteBarrier<JSObject>. - Rename VMEntryFrame to EntryFrame, and in many places pass a pointer to it around instead of VM. This is a first step in allowing entry frames which aren't stored on VM, but which are instead stored in an embedder-specific location. That change won't really affect JS except through code churn, but will allow WebAssembly to use some machinery in a generic manner without having a VM. * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * debugger/Debugger.cpp: (JSC::Debugger::stepOutOfFunction): (JSC::Debugger::returnEvent): (JSC::Debugger::unwindEvent): (JSC::Debugger::didExecuteProgram): * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::compileExceptionHandlers): * dfg/DFGOSREntry.cpp: (JSC::DFG::prepareOSREntry): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::compileOSRExit): (JSC::DFG::OSRExit::compileExit): * dfg/DFGThunks.cpp: (JSC::DFG::osrEntryThunkGenerator): * ftl/FTLCompile.cpp: (JSC::FTL::compile): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::lower): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): (JSC::CallFrame::callerFrame): (JSC::CallFrame::unsafeCallerFrame): * interpreter/CallFrame.h: (JSC::ExecState::callerFrame const): (JSC::ExecState::callerFrameOrEntryFrame const): (JSC::ExecState::unsafeCallerFrameOrEntryFrame const): * interpreter/FrameTracers.h: (JSC::NativeCallFrameTracer::NativeCallFrameTracer): (JSC::NativeCallFrameTracerWithRestore::NativeCallFrameTracerWithRestore): (JSC::NativeCallFrameTracerWithRestore::~NativeCallFrameTracerWithRestore): * interpreter/Interpreter.cpp: (JSC::UnwindFunctor::operator() const): (JSC::UnwindFunctor::copyCalleeSavesToEntryFrameCalleeSavesBuffer const): (JSC::Interpreter::unwind): * interpreter/StackVisitor.cpp: (JSC::StackVisitor::StackVisitor): (JSC::StackVisitor::gotoNextFrame): (JSC::StackVisitor::readNonInlinedFrame): (JSC::StackVisitor::Frame::dump const): * interpreter/StackVisitor.h: (JSC::StackVisitor::Frame::callerIsEntryFrame const): * interpreter/VMEntryRecord.h: (JSC::VMEntryRecord::prevTopEntryFrame): (JSC::VMEntryRecord::unsafePrevTopEntryFrame): (JSC::EntryFrame::vmEntryRecordOffset): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::restoreCalleeSavesFromEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::loadWasmContextInstance): (JSC::AssemblyHelpers::storeWasmContextInstance): (JSC::AssemblyHelpers::loadWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::storeWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBufferImpl): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::copyCalleeSavesToVMEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer): * jit/JIT.cpp: (JSC::JIT::emitEnterOptimizationCheck): (JSC::JIT::privateCompileExceptionHandlers): * jit/JITExceptions.cpp: (JSC::genericUnwind): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): (JSC::JIT::emitSlow_op_loop_hint): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): * jit/JITOperations.cpp: * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::nativeForGenerator): * jsc.cpp: (functionDumpCallFrame): * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LLIntThunks.cpp: (JSC::vmEntryRecord): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/Options.cpp: (JSC::recomputeDependentOptions): * runtime/Options.h: * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::FrameWalker): (JSC::FrameWalker::advanceToParentFrame): (JSC::SamplingProfiler::processUnverifiedStackTraces): * runtime/ThrowScope.cpp: (JSC::ThrowScope::~ThrowScope): * runtime/VM.cpp: (JSC::VM::VM): (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::topEntryFrameOffset): * runtime/VMTraps.cpp: (JSC::isSaneFrame): (JSC::VMTraps::tryInstallTrapBreakpoints): (JSC::VMTraps::invalidateCodeBlocksOnStack): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWasmContextInstance): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::parseAndCompile): * wasm/WasmB3IRGenerator.h: * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::BBQPlan): (JSC::Wasm::BBQPlan::compileFunctions): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBBQPlanInlines.h: (JSC::Wasm::BBQPlan::initializeCallees): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmBinding.h: * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::create): (JSC::Wasm::CodeBlock::CodeBlock): (JSC::Wasm::CodeBlock::compileAsync): (JSC::Wasm::CodeBlock::setCompilationFinished): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::offsetOfImportStubs): (JSC::Wasm::CodeBlock::allocationSize): (JSC::Wasm::CodeBlock::importWasmToEmbedderStub): (JSC::Wasm::CodeBlock::offsetOfImportWasmToEmbedderStub): (JSC::Wasm::CodeBlock::wasmToJSCallStubForImport): (JSC::Wasm::CodeBlock::compilationFinished): (JSC::Wasm::CodeBlock::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): * wasm/WasmContext.cpp: (JSC::Wasm::Context::useFastTLS): (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: Copied from Source/JavaScriptCore/wasm/WasmContext.h. * wasm/WasmFaultSignalHandler.cpp: * wasm/WasmFaultSignalHandler.h: * wasm/WasmFormat.h: * wasm/WasmInstance.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::~Instance): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: Added. (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::module): (JSC::Wasm::Instance::codeBlock): (JSC::Wasm::Instance::memory): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::loadF32Global const): (JSC::Wasm::Instance::loadF64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::offsetOfCachedStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::~Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::offsetOfSize): * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationCallback): (JSC::Wasm::Module::validateSync): (JSC::Wasm::Module::validateAsync): (JSC::Wasm::Module::getOrCreateCodeBlock): (JSC::Wasm::Module::compileSync): (JSC::Wasm::Module::compileAsync): * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseTableHelper): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::OMGPlan): (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::isValid const): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::runCompletionTasks): (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmPlan.h: (JSC::Wasm::Plan::dontFinalize): * wasm/WasmSignature.cpp: * wasm/WasmSignature.h: * wasm/WasmTable.cpp: Added. (JSC::Wasm::Table::create): (JSC::Wasm::Table::~Table): (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h. (JSC::Wasm::Table::maximum const): (JSC::Wasm::Table::size const): (JSC::Wasm::Table::offsetOfSize): (JSC::Wasm::Table::offsetOfFunctions): (JSC::Wasm::Table::offsetOfInstances): (JSC::Wasm::Table::isValidSize): * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): (JSC::Wasm::Thunks::setThrowWasmException): (JSC::Wasm::Thunks::throwWasmException): * wasm/WasmThunks.h: * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::stopAllPlansForContext): * wasm/WasmWorklist.h: * wasm/js/JSToWasm.cpp: Added. (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/JSWebAssembly.cpp: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.cpp. * wasm/js/JSWebAssembly.h: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.h. * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::create): (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::context const): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::webAssemblyToJSCallee): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::offsetOfTail): (JSC::JSWebAssemblyInstance::importFunctionInfo): (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): (JSC::JSWebAssemblyInstance::offsetOfImportFunction): (JSC::JSWebAssemblyInstance::importFunction): (JSC::JSWebAssemblyInstance::internalMemory): (JSC::JSWebAssemblyInstance::wasmCodeBlock const): (JSC::JSWebAssemblyInstance::offsetOfWasmTable): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::offsetOfGlobals): (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): (JSC::JSWebAssemblyInstance::cachedStackLimit const): (JSC::JSWebAssemblyInstance::setCachedStackLimit): (JSC::JSWebAssemblyInstance::wasmMemory): (JSC::JSWebAssemblyInstance::wasmModule): (JSC::JSWebAssemblyInstance::allocationSize): (JSC::JSWebAssemblyInstance::module const): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::create): (JSC::JSWebAssemblyMemory::adopt): (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::moduleInformation const): (JSC::JSWebAssemblyModule::exportSymbolTable const): (JSC::JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace const): (JSC::JSWebAssemblyModule::callee const): (JSC::JSWebAssemblyModule::codeBlock): (JSC::JSWebAssemblyModule::module): * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::create): (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::visitChildren): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::getFunction): (JSC::JSWebAssemblyTable::clearFunction): (JSC::JSWebAssemblyTable::setFunction): * wasm/js/JSWebAssemblyTable.h: (JSC::JSWebAssemblyTable::isValidSize): (JSC::JSWebAssemblyTable::maximum const): (JSC::JSWebAssemblyTable::size const): (JSC::JSWebAssemblyTable::table): * wasm/js/WasmToJS.cpp: Copied from Source/JavaScriptCore/wasm/WasmBinding.cpp. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): (JSC::WebAssemblyModuleConstructor::createModule): * wasm/js/WebAssemblyModuleConstructor.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::webAssemblyCompileFunc): (JSC::instantiate): (JSC::compileAndInstantiate): (JSC::webAssemblyValidateFunc): * wasm/js/WebAssemblyTableConstructor.cpp: (JSC::constructJSWebAssemblyTable): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Source/WebCore: * ForwardingHeaders/wasm/WasmModule.h: Added. This used to be included in JSWebAssemblyModule.h. * bindings/js/SerializedScriptValue.cpp: Update postMessage code according to C++ API changes. Canonical link: https://commits.webkit.org/194750@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223738 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-20 02:23:29 +00:00
Ref<Module> m_module;
RefPtr<CodeBlock> m_codeBlock;
RefPtr<Memory> m_memory;
[WASM-References] Support Anyref in globals https://bugs.webkit.org/show_bug.cgi?id=198102 Reviewed by Saam Barati. JSTests: Add test for anyrefs in globals, as well as adding a new RefNull initExpr for Builder. * wasm/Builder.js: (export.default.Builder.prototype._registerSectionBuilders.const.section.in.WASM.description.section.switch.section.case.string_appeared_here.this.section): * wasm/Builder_WebAssemblyBinary.js: (const.putInitExpr): * wasm/references/anyref_globals.js: Added. (GetGlobal.0.End.End.WebAssembly): (5.doGCSet): (doGCTest): (doGCSet.doGCTest.let.count.0.doBarrierSet): Source/JavaScriptCore: Support anyref for globals, imports and exports. This adds code in B3 and Air to emit a write barrier on the JSWebAssemblyWrapper whenever an anyref global is set. This also fixes a small bug in emitCCall for air where it adds code to the wrong block. * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::emitCCall): (JSC::Wasm::AirIRGenerator::moveOpForValueType): (JSC::Wasm::AirIRGenerator::setGlobal): (JSC::Wasm::AirIRGenerator::emitWriteBarrierForJSWrapper): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::setGlobal): (JSC::Wasm::B3IRGenerator::emitWriteBarrierForJSWrapper): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::setGlobal): * wasm/WasmInstance.h: (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::shouldMarkGlobal): (JSC::Wasm::Instance::numGlobals const): * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseInitExpr): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): Canonical link: https://commits.webkit.org/212290@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245765 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-25 00:51:21 +00:00
Experiment: create lots of different malloc zones for easier accounting of memory use https://bugs.webkit.org/show_bug.cgi?id=186422 Patch by Yusuke Suzuki <ysuzuki@apple.com> and Simon Fraser <simon.fraser@apple.com> on 2020-01-02 Reviewed by Saam Barati. Source/bmalloc: * bmalloc/BPlatform.h: * bmalloc/Environment.cpp: (bmalloc::Environment::computeIsDebugHeapEnabled): * bmalloc/IsoHeap.h: (bmalloc::api::IsoHeap::IsoHeap): * bmalloc/IsoHeapInlines.h: (bmalloc::api::IsoHeap<Type>::IsoHeap): * bmalloc/IsoTLSInlines.h: (bmalloc::IsoTLS::allocateSlow): (bmalloc::IsoTLS::deallocateSlow): Source/JavaScriptCore: * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * assembler/AssemblerBuffer.cpp: Copied from Source/JavaScriptCore/bytecode/InstructionStream.cpp. * assembler/AssemblerBuffer.h: (JSC::AssemblerData::AssemblerData): (JSC::AssemblerData::operator=): (JSC::AssemblerData::~AssemblerData): (JSC::AssemblerData::grow): * bytecode/AccessCase.cpp: * bytecode/AccessCase.h: * bytecode/BytecodeBasicBlock.cpp: * bytecode/BytecodeBasicBlock.h: * bytecode/CodeBlock.cpp: * bytecode/CodeBlock.h: * bytecode/InstructionStream.cpp: * bytecode/InstructionStream.h: * bytecode/PolymorphicAccess.cpp: * bytecode/PolymorphicAccess.h: * bytecode/UnlinkedMetadataTable.cpp: (JSC::UnlinkedMetadataTable::finalize): * bytecode/UnlinkedMetadataTable.h: * bytecode/UnlinkedMetadataTableInlines.h: (JSC::UnlinkedMetadataTable::UnlinkedMetadataTable): (JSC::UnlinkedMetadataTable::~UnlinkedMetadataTable): (JSC::UnlinkedMetadataTable::link): (JSC::UnlinkedMetadataTable::unlink): * bytecode/ValueProfile.h: (JSC::ValueProfileAndVirtualRegisterBuffer::ValueProfileAndVirtualRegisterBuffer): * bytecode/Watchpoint.cpp: * bytecode/Watchpoint.h: * dfg/DFGBasicBlock.cpp: * dfg/DFGBasicBlock.h: * dfg/DFGNode.cpp: * dfg/DFGNode.h: * dfg/DFGSpeculativeJIT.cpp: * dfg/DFGSpeculativeJIT.h: * heap/BlockDirectory.cpp: * heap/BlockDirectory.h: * heap/FastMallocAlignedMemoryAllocator.cpp: (JSC::FastMallocAlignedMemoryAllocator::FastMallocAlignedMemoryAllocator): (JSC::FastMallocAlignedMemoryAllocator::tryAllocateAlignedMemory): (JSC::FastMallocAlignedMemoryAllocator::freeAlignedMemory): (JSC::FastMallocAlignedMemoryAllocator::tryAllocateMemory): (JSC::FastMallocAlignedMemoryAllocator::freeMemory): (JSC::FastMallocAlignedMemoryAllocator::tryReallocateMemory): * heap/FastMallocAlignedMemoryAllocator.h: * heap/GCSegmentedArray.cpp: Copied from Source/JavaScriptCore/parser/SourceProviderCache.cpp. * heap/GCSegmentedArray.h: * heap/GCSegmentedArrayInlines.h: (JSC::GCArraySegment<T>::create): (JSC::GCArraySegment<T>::destroy): * heap/GigacageAlignedMemoryAllocator.cpp: (JSC::GigacageAlignedMemoryAllocator::GigacageAlignedMemoryAllocator): (JSC::GigacageAlignedMemoryAllocator::tryAllocateAlignedMemory): (JSC::GigacageAlignedMemoryAllocator::freeAlignedMemory): (JSC::GigacageAlignedMemoryAllocator::tryAllocateMemory): (JSC::GigacageAlignedMemoryAllocator::freeMemory): (JSC::GigacageAlignedMemoryAllocator::tryReallocateMemory): * heap/GigacageAlignedMemoryAllocator.h: * heap/IsoAlignedMemoryAllocator.cpp: (JSC::IsoAlignedMemoryAllocator::IsoAlignedMemoryAllocator): (JSC::IsoAlignedMemoryAllocator::~IsoAlignedMemoryAllocator): (JSC::IsoAlignedMemoryAllocator::tryAllocateAlignedMemory): (JSC::IsoAlignedMemoryAllocator::freeAlignedMemory): (JSC::IsoAlignedMemoryAllocator::tryAllocateMemory): (JSC::IsoAlignedMemoryAllocator::freeMemory): * heap/IsoAlignedMemoryAllocator.h: * heap/IsoSubspace.cpp: (JSC::IsoSubspace::IsoSubspace): * heap/MarkedBlock.cpp: * heap/MarkedBlock.h: * heap/WeakBlock.cpp: (JSC::WeakBlock::create): (JSC::WeakBlock::destroy): * heap/WeakBlock.h: * jit/JITCode.cpp: * jit/JITCode.h: * jit/RegisterAtOffsetList.cpp: * jit/RegisterAtOffsetList.h: * parser/Nodes.cpp: * parser/Nodes.h: * parser/ParserArena.cpp: (JSC::ParserArena::deallocateObjects): (JSC::ParserArena::allocateFreeablePool): * parser/ParserArena.h: * parser/SourceProvider.cpp: * parser/SourceProvider.h: * parser/SourceProviderCache.cpp: * parser/SourceProviderCache.h: * parser/SourceProviderCacheItem.h: (JSC::SourceProviderCacheItem::create): * runtime/CachePayload.cpp: (JSC::CachePayload::makeMallocPayload): * runtime/CachePayload.h: * runtime/CachedBytecode.h: (JSC::CachedBytecode::create): * runtime/CachedTypes.cpp: (JSC::Encoder::release): (JSC::Encoder::Page::Page): (JSC::CachedVector::encode): (JSC::CachedVector::decode const): (JSC::CachedInstructionStream::decode const): * runtime/PropertyMapHashTable.h: (JSC::PropertyTable::rehash): * runtime/PropertyTable.cpp: (JSC::PropertyTable::PropertyTable): (JSC::PropertyTable::~PropertyTable): * runtime/SymbolTable.cpp: * runtime/SymbolTable.h: * runtime/VM.cpp: (JSC::VM::~VM): * runtime/VM.h: (JSC::ScratchBuffer::create): (JSC::VM::exceptionFuzzingBuffer): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): * wasm/WasmInstance.h: * wasm/WasmTable.cpp: (JSC::Wasm::Table::Table): (JSC::Wasm::FuncRefTable::FuncRefTable): * wasm/WasmTable.h: Source/WebCore: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * bindings/js/SerializedScriptValue.cpp: * bindings/js/SerializedScriptValue.h: * css/CSSFontFace.cpp: * css/CSSFontFace.h: * css/CSSSelector.cpp: * css/CSSSelector.h: * css/CSSValue.cpp: * css/CSSValue.h: * css/StyleProperties.cpp: (WebCore::ImmutableStyleProperties::create): * css/StyleProperties.h: * css/StyleRule.cpp: * css/StyleRule.h: * dom/ElementData.cpp: (WebCore::ShareableElementData::createWithAttributes): (WebCore::UniqueElementData::makeShareableCopy const): * dom/ElementData.h: * dom/NodeRareData.cpp: * dom/NodeRareData.h: * dom/QualifiedName.cpp: * dom/QualifiedName.h: * html/parser/HTMLDocumentParser.cpp: * html/parser/HTMLDocumentParser.h: * loader/DocumentLoader.cpp: * loader/DocumentLoader.h: * loader/ResourceLoader.cpp: * loader/ResourceLoader.h: * loader/cache/CachedResource.cpp: * loader/cache/CachedResource.h: * page/PerformanceEntry.cpp: * page/PerformanceEntry.h: * platform/graphics/Font.cpp: * platform/graphics/Font.h: * platform/graphics/FontCascadeFonts.cpp: * platform/graphics/FontCascadeFonts.h: * platform/graphics/Region.cpp: * platform/graphics/Region.h: * platform/graphics/avfoundation/objc/MediaSampleAVFObjC.mm: (WebCore::releaseUint8Vector): * platform/graphics/cg/ImageBufferCG.cpp: (WebCore::ImageBuffer::ImageBuffer): * platform/graphics/nicosia/NicosiaBuffer.cpp: (Nicosia::Buffer::Buffer): * platform/network/ResourceHandle.cpp: * platform/network/ResourceHandleInternal.h: * platform/network/cf/FormDataStreamCFNet.cpp: (WebCore::closeCurrentStream): (WebCore::advanceCurrentStream): * rendering/RenderLayer.cpp: * rendering/RenderLayer.h: * rendering/TableLayout.cpp: Copied from Source/JavaScriptCore/parser/SourceProviderCache.cpp. * rendering/TableLayout.h: * rendering/style/RenderStyle.cpp: * rendering/style/RenderStyle.h: * rendering/style/SVGRenderStyle.cpp: * rendering/style/SVGRenderStyle.h: * rendering/style/SVGRenderStyleDefs.cpp: * rendering/style/SVGRenderStyleDefs.h: * rendering/style/StyleBoxData.cpp: * rendering/style/StyleBoxData.h: * rendering/style/StyleInheritedData.cpp: * rendering/style/StyleInheritedData.h: * rendering/style/StyleRareInheritedData.cpp: * rendering/style/StyleRareInheritedData.h: * rendering/style/StyleRareNonInheritedData.cpp: * rendering/style/StyleRareNonInheritedData.h: * rendering/style/StyleSurroundData.cpp: * rendering/style/StyleSurroundData.h: * rendering/style/StyleTransformData.cpp: * rendering/style/StyleTransformData.h: * style/StyleTreeResolver.cpp: * style/StyleTreeResolver.h: * svg/animation/SMILTimeContainer.cpp: * svg/animation/SMILTimeContainer.h: Source/WebKit: * Shared/ShareableBitmap.cpp: (WebKit::ShareableBitmap::create): (WebKit::ShareableBitmap::~ShareableBitmap): * UIProcess/mac/LegacySessionStateCoding.cpp: (WebKit::HistoryEntryDataEncoder::HistoryEntryDataEncoder): (WebKit::HistoryEntryDataEncoder::finishEncoding): (WebKit::encodeSessionHistoryEntryData): (WebKit::encodeLegacySessionState): Source/WTF: This patch introduces ENABLE(MALLOC_HEAP_BREAKDOWN). If this is enabled, we allocate malloc_zone per malloc kind. This offers the way to investigate the usage of memory per kind by using vmmap, like the following. VIRTUAL RESIDENT DIRTY SWAPPED ALLOCATION BYTES DIRTY+SWAP REGION MALLOC ZONE SIZE SIZE SIZE SIZE COUNT ALLOCATED FRAG SIZE % FRAG COUNT =========== ======= ========= ========= ========= ========= ========= ========= ====== ====== StringImpl_0x116efd000 188.0M 69.3M 30.9M 0K 139456 18.0M 12.9M 42% 34 DefaultMallocZone_0x10f487000 176.0M 53.9M 14.1M 0K 115956 9955K 4497K 32% 22 Vector_0x116eff000 162.0M 56.3M 55.3M 0K 140715 17.3M 37.9M 69% 36 MetadataTable_0x11843b000 152.0M 17.5M 17.5M 0K 14200 2353K 15.2M 87% 26 WebKit Using System Malloc_0x114cbe000 150.0M 31.6M 21.8M 0K 87422 16.7M 5278K 24% 23 InstructionStream_0x118469000 150.0M 5764K 5764K 0K 14470 4688K 1076K 19% 24 AssemblerData_0x117ee6000 150.0M 1928K 1928K 0K 1 16 1928K 100% 24 To achieve this goal without making very large change, we put a template type in various containers. For example, Vector will take Malloc parameter (the default one is FastMalloc allocator). If ENABLE(MALLOC_HEAP_BREAKDOWN) is enabled, we change this to specific VectorMalloc allocator, and vmmap can show memory usage of this allocator. This patch also supports malloc_zone per IsoHeap. So we can see memory allocation per IsoHeap in vmmap. To use this feature, we need to flip two compile time flags, ENABLE(MALLOC_HEAP_BREAKDOWN) in WTF and BENABLE_MALLOC_HEAP_BREAKDOWN in bmalloc. And use `vmmap $PID` to dump malloc zones. To allocate objects of a class with a specific malloc-zone, use WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(HeapIdentifier) for the class, and define allocator by DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(HeapIdentifier) in a header and DEFINE_ALLOCATOR_WITH_HEAP_IDENTIFIER(HeapIdentifier) in a cpp file. This patch also introduce callstack collector for malloc. Vector, HashMap etc. are used to allocate various things, but the above malloc_zone feature only tells thing like "Vector takes XXX MB memory". But what we want to know in this case is what Vector is consuming memory. We collect StackShot for each malloc call, and combine these information to tell which callsite is consuming much memory, which tell us that what Vector is consuming memory. * WTF.xcodeproj/project.pbxproj: * wtf/Bag.cpp: Copied from Source/JavaScriptCore/parser/SourceProviderCache.cpp. * wtf/Bag.h: (WTF::Private::BagNode::BagNode): Deleted. * wtf/BitVector.cpp: (WTF::BitVector::OutOfLineBits::create): (WTF::BitVector::OutOfLineBits::destroy): * wtf/CMakeLists.txt: * wtf/ConcurrentBuffer.cpp: Copied from Source/JavaScriptCore/parser/SourceProviderCache.cpp. * wtf/ConcurrentBuffer.h: * wtf/DebugHeap.cpp: Copied from Source/JavaScriptCore/runtime/CachePayload.cpp. (WTF::DebugHeap::DebugHeap): (WTF::DebugHeap::malloc): (WTF::DebugHeap::calloc): (WTF::DebugHeap::memalign): (WTF::DebugHeap::realloc): (WTF::DebugHeap::free): * wtf/DebugHeap.h: Added. * wtf/FastBitVector.cpp: (WTF::FastBitVectorWordOwner::setEqualsSlow): (WTF::FastBitVectorWordOwner::resizeSlow): * wtf/FastBitVector.h: (WTF::FastBitVectorWordOwner::~FastBitVectorWordOwner): * wtf/FastMalloc.cpp: (WTF::fastMallocDumpMallocStats): (WTF::AvoidRecordingScope::AvoidRecordingScope): (WTF::AvoidRecordingScope::~AvoidRecordingScope): (WTF::MallocCallTracker::MallocSiteData::MallocSiteData): (WTF::MallocCallTracker::singleton): (WTF::MallocCallTracker::MallocCallTracker): (WTF::MallocCallTracker::recordMalloc): (WTF::MallocCallTracker::recordRealloc): (WTF::MallocCallTracker::recordFree): (WTF::MallocCallTracker::dumpStats): (WTF::fastMalloc): (WTF::fastRealloc): (WTF::fastFree): (WTF::fastAlignedMalloc): (WTF::tryFastAlignedMalloc): (WTF::fastAlignedFree): * wtf/FastMalloc.h: (WTF::FastMalloc::zeroedMalloc): (WTF::FastMalloc::tryZeroedMalloc): * wtf/Forward.h: * wtf/HashTable.cpp: * wtf/HashTable.h: (WTF::KeyTraits>::allocateTable): (WTF::KeyTraits>::deallocateTable): (WTF::KeyTraits>::rehash): * wtf/MallocPtr.h: (WTF::MallocPtr::MallocPtr): (WTF::MallocPtr::malloc): (WTF::MallocPtr::zeroedMalloc): (WTF::MallocPtr::tryMalloc): (WTF::MallocPtr::tryZeroedMalloc): (WTF::adoptMallocPtr): * wtf/MetaAllocator.cpp: (WTF::MetaAllocator::allocFreeSpaceNode): (WTF::MetaAllocator::freeFreeSpaceNode): * wtf/MetaAllocatorHandle.h: * wtf/Platform.h: * wtf/RefCountedArray.cpp: Copied from Source/JavaScriptCore/bytecode/InstructionStream.cpp. * wtf/RefCountedArray.h: (WTF::RefCountedArray::RefCountedArray): (WTF::RefCountedArray::~RefCountedArray): (WTF::RefCountedArray::assign): * wtf/SegmentedVector.cpp: Copied from Source/JavaScriptCore/bytecode/InstructionStream.cpp. * wtf/SegmentedVector.h: * wtf/SmallPtrSet.cpp: Copied from Source/JavaScriptCore/bytecode/InstructionStream.cpp. * wtf/SmallPtrSet.h: (WTF::SmallPtrSet::~SmallPtrSet): (WTF::SmallPtrSet::grow): * wtf/UniqueArray.cpp: Copied from Source/JavaScriptCore/bytecode/InstructionStream.cpp. * wtf/UniqueArray.h: (WTF::UniqueArrayFree::operator() const): (WTF::UniqueArrayFree<T::operator() const): * wtf/Vector.cpp: Copied from Source/JavaScriptCore/bytecode/InstructionStream.cpp. * wtf/Vector.h: (WTF::VectorBufferBase::allocateBuffer): (WTF::VectorBufferBase::tryAllocateBuffer): (WTF::VectorBufferBase::reallocateBuffer): (WTF::VectorBufferBase::deallocateBuffer): (WTF::VectorBufferBase::releaseBuffer): (WTF::VectorBuffer::releaseBuffer): (WTF::Vector::swap): (WTF::Malloc>::Vector): (WTF::=): (WTF::Malloc>::contains const): (WTF::Malloc>::findMatching const): (WTF::Malloc>::find const): (WTF::Malloc>::reverseFind const): (WTF::Malloc>::appendIfNotContains): (WTF::Malloc>::fill): (WTF::Malloc>::appendRange): (WTF::Malloc>::expandCapacity): (WTF::Malloc>::tryExpandCapacity): (WTF::Malloc>::resize): (WTF::Malloc>::resizeToFit): (WTF::Malloc>::shrink): (WTF::Malloc>::grow): (WTF::Malloc>::asanSetInitialBufferSizeTo): (WTF::Malloc>::asanSetBufferSizeToFullCapacity): (WTF::Malloc>::asanBufferSizeWillChangeTo): (WTF::Malloc>::reserveCapacity): (WTF::Malloc>::tryReserveCapacity): (WTF::Malloc>::reserveInitialCapacity): (WTF::Malloc>::shrinkCapacity): (WTF::Malloc>::append): (WTF::Malloc>::tryAppend): (WTF::Malloc>::constructAndAppend): (WTF::Malloc>::tryConstructAndAppend): (WTF::Malloc>::appendSlowCase): (WTF::Malloc>::constructAndAppendSlowCase): (WTF::Malloc>::tryConstructAndAppendSlowCase): (WTF::Malloc>::uncheckedAppend): (WTF::Malloc>::uncheckedConstructAndAppend): (WTF::Malloc>::appendVector): (WTF::Malloc>::insert): (WTF::Malloc>::insertVector): (WTF::Malloc>::remove): (WTF::Malloc>::removeFirst): (WTF::Malloc>::removeFirstMatching): (WTF::Malloc>::removeAll): (WTF::Malloc>::removeAllMatching): (WTF::Malloc>::reverse): (WTF::Malloc>::map const): (WTF::Malloc>::releaseBuffer): (WTF::Malloc>::checkConsistency): (WTF::swap): (WTF::operator==): (WTF::operator!=): (WTF::Malloc>::isolatedCopy const): (WTF::removeRepeatedElements): (WTF::minCapacity>::Vector): Deleted. (WTF::minCapacity>::contains const): Deleted. (WTF::minCapacity>::findMatching const): Deleted. (WTF::minCapacity>::find const): Deleted. (WTF::minCapacity>::reverseFind const): Deleted. (WTF::minCapacity>::appendIfNotContains): Deleted. (WTF::minCapacity>::fill): Deleted. (WTF::minCapacity>::appendRange): Deleted. (WTF::minCapacity>::expandCapacity): Deleted. (WTF::minCapacity>::tryExpandCapacity): Deleted. (WTF::minCapacity>::resize): Deleted. (WTF::minCapacity>::resizeToFit): Deleted. (WTF::minCapacity>::shrink): Deleted. (WTF::minCapacity>::grow): Deleted. (WTF::minCapacity>::asanSetInitialBufferSizeTo): Deleted. (WTF::minCapacity>::asanSetBufferSizeToFullCapacity): Deleted. (WTF::minCapacity>::asanBufferSizeWillChangeTo): Deleted. (WTF::minCapacity>::reserveCapacity): Deleted. (WTF::minCapacity>::tryReserveCapacity): Deleted. (WTF::minCapacity>::reserveInitialCapacity): Deleted. (WTF::minCapacity>::shrinkCapacity): Deleted. (WTF::minCapacity>::append): Deleted. (WTF::minCapacity>::tryAppend): Deleted. (WTF::minCapacity>::constructAndAppend): Deleted. (WTF::minCapacity>::tryConstructAndAppend): Deleted. (WTF::minCapacity>::appendSlowCase): Deleted. (WTF::minCapacity>::constructAndAppendSlowCase): Deleted. (WTF::minCapacity>::tryConstructAndAppendSlowCase): Deleted. (WTF::minCapacity>::uncheckedAppend): Deleted. (WTF::minCapacity>::uncheckedConstructAndAppend): Deleted. (WTF::minCapacity>::appendVector): Deleted. (WTF::minCapacity>::insert): Deleted. (WTF::minCapacity>::insertVector): Deleted. (WTF::minCapacity>::remove): Deleted. (WTF::minCapacity>::removeFirst): Deleted. (WTF::minCapacity>::removeFirstMatching): Deleted. (WTF::minCapacity>::removeAll): Deleted. (WTF::minCapacity>::removeAllMatching): Deleted. (WTF::minCapacity>::reverse): Deleted. (WTF::minCapacity>::map const): Deleted. (WTF::minCapacity>::releaseBuffer): Deleted. (WTF::minCapacity>::checkConsistency): Deleted. (WTF::minCapacity>::isolatedCopy const): Deleted. * wtf/text/CString.cpp: (WTF::CStringBuffer::createUninitialized): * wtf/text/CString.h: * wtf/text/StringBuffer.cpp: Copied from Source/JavaScriptCore/bytecode/InstructionStream.cpp. * wtf/text/StringBuffer.h: (WTF::StringBuffer::StringBuffer): (WTF::StringBuffer::~StringBuffer): (WTF::StringBuffer::resize): (WTF::StringBuffer::release): * wtf/text/StringImpl.cpp: (WTF::StringImpl::~StringImpl): (WTF::StringImpl::destroy): (WTF::StringImpl::createUninitializedInternalNonEmpty): (WTF::StringImpl::reallocateInternal): * wtf/text/StringImpl.h: (WTF::StringImpl::StringImpl): (WTF::StringImpl::createSubstringSharingImpl): (WTF::StringImpl::tryCreateUninitialized): (WTF::StringImpl::adopt): * wtf/text/cf/StringImplCF.cpp: (WTF::StringWrapperCFAllocator::allocate): (WTF::StringWrapperCFAllocator::reallocate): (WTF::StringWrapperCFAllocator::deallocate): Canonical link: https://commits.webkit.org/218863@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@253987 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-01-03 02:36:43 +00:00
MallocPtr<Global::Value, VMMalloc> m_globals;
[WASM-References] Add support for Funcref in parameters and return types https://bugs.webkit.org/show_bug.cgi?id=198157 Reviewed by Yusuke Suzuki. JSTests: * wasm/Builder.js: (export.default.Builder.prototype._registerSectionBuilders.const.section.in.WASM.description.section.switch.section.case.string_appeared_here.this.section): * wasm/references/anyref_globals.js: * wasm/references/func_ref.js: Added. (fullGC.gc.makeExportedFunction): (makeExportedIdent): (makeAnyfuncIdent): (fun): (assert.eq.instance.exports.fix.fun): (assert.eq.instance.exports.fix): (string_appeared_here.End.End.Function.End.Code.End.WebAssembly.imp.ref): (string_appeared_here.End.End.Function.End.Code.End.WebAssembly): (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly.fun): (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly.assert.throws): (GetLocal.0.I32Const.0.TableSet.End.End.WebAssembly): (assert.throws): (assert.throws.doTest): (let.importedFun.of): (makeAnyfuncIdent.fun): * wasm/references/validation.js: (assert.throws): * wasm/wasm.json: Source/JavaScriptCore: Add support for funcref in parameters, globals, and in table.get/set. When converting a JSValue to a funcref (nee anyfunc), we first make sure it is an exported wasm function or null. We also add support for Ref.func. Anywhere a Ref.func is used, (statically) we construct a JS wrapper for it so that we never need to construct JSValues when handling references. This should make threads easier to implement. Finally, we add some missing bounds checks for table.get/set. * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::tmpForType): (JSC::Wasm::AirIRGenerator::moveOpForValueType): (JSC::Wasm::AirIRGenerator::AirIRGenerator): (JSC::Wasm::AirIRGenerator::addLocal): (JSC::Wasm::AirIRGenerator::addConstant): (JSC::Wasm::AirIRGenerator::addRefFunc): (JSC::Wasm::AirIRGenerator::addTableSet): (JSC::Wasm::AirIRGenerator::setGlobal): (JSC::Wasm::AirIRGenerator::addReturn): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::addLocal): (JSC::Wasm::B3IRGenerator::addTableSet): (JSC::Wasm::B3IRGenerator::addRefFunc): (JSC::Wasm::B3IRGenerator::setGlobal): * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::compileFunctions): * wasm/WasmCallingConvention.h: (JSC::Wasm::CallingConventionAir::marshallArgument const): (JSC::Wasm::CallingConventionAir::setupCall const): * wasm/WasmExceptionType.h: * wasm/WasmFormat.h: (JSC::Wasm::isValueType): (JSC::Wasm::isSubtype): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parseExpression): (JSC::Wasm::FunctionParser<Context>::parseUnreachableExpression): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::getFunctionWrapper const): (JSC::Wasm::Instance::setFunctionWrapper): * wasm/WasmInstance.h: * wasm/WasmModuleInformation.h: (JSC::Wasm::ModuleInformation::referencedFunctions const): (JSC::Wasm::ModuleInformation::addReferencedFunction const): * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseGlobal): (JSC::Wasm::SectionParser::parseInitExpr): * wasm/WasmValidate.cpp: (JSC::Wasm::Validate::addTableGet): (JSC::Wasm::Validate::addTableSet): (JSC::Wasm::Validate::addRefIsNull): (JSC::Wasm::Validate::addRefFunc): (JSC::Wasm::Validate::setLocal): (JSC::Wasm::Validate::addCall): (JSC::Wasm::Validate::addCallIndirect): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyHelpers.h: (JSC::isWebAssemblyHostFunction): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/JSWebAssemblyRuntimeError.cpp: (JSC::createJSWebAssemblyRuntimeError): * wasm/js/JSWebAssemblyRuntimeError.h: * wasm/js/WasmToJS.cpp: (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): (JSC::Wasm::emitWasmToJSException): * wasm/js/WasmToJS.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): (JSC::WebAssemblyFunction::jsCallEntrypointSlow): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): * wasm/wasm.json: Canonical link: https://commits.webkit.org/212896@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@246504 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-06-17 18:44:18 +00:00
FunctionWrapperMap m_functionWrappers;
[WASM-References] Support Anyref in globals https://bugs.webkit.org/show_bug.cgi?id=198102 Reviewed by Saam Barati. JSTests: Add test for anyrefs in globals, as well as adding a new RefNull initExpr for Builder. * wasm/Builder.js: (export.default.Builder.prototype._registerSectionBuilders.const.section.in.WASM.description.section.switch.section.case.string_appeared_here.this.section): * wasm/Builder_WebAssemblyBinary.js: (const.putInitExpr): * wasm/references/anyref_globals.js: Added. (GetGlobal.0.End.End.WebAssembly): (5.doGCSet): (doGCTest): (doGCSet.doGCTest.let.count.0.doBarrierSet): Source/JavaScriptCore: Support anyref for globals, imports and exports. This adds code in B3 and Air to emit a write barrier on the JSWebAssemblyWrapper whenever an anyref global is set. This also fixes a small bug in emitCCall for air where it adds code to the wrong block. * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::emitCCall): (JSC::Wasm::AirIRGenerator::moveOpForValueType): (JSC::Wasm::AirIRGenerator::setGlobal): (JSC::Wasm::AirIRGenerator::emitWriteBarrierForJSWrapper): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::setGlobal): (JSC::Wasm::B3IRGenerator::emitWriteBarrierForJSWrapper): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::setGlobal): * wasm/WasmInstance.h: (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::shouldMarkGlobal): (JSC::Wasm::Instance::numGlobals const): * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseInitExpr): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): Canonical link: https://commits.webkit.org/212290@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245765 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-05-25 00:51:21 +00:00
BitVector m_globalsToMark;
Adopt the new WebAssembly.Global system https://bugs.webkit.org/show_bug.cgi?id=186552 Reviewed by Keith Miller. JSTests: 1. Update spec-harness to accept newer tests. And we update several tests that does not work with the old harness. 2. Add WebAssembly.Global tests. * wasm/js-api/global-error.js: (assert.throws.new.WebAssembly.Module.bin): (new.WebAssembly.Module): (assert.throws): * wasm/js-api/global-external-init-from-import.js: * wasm/js-api/globals-export.js: * wasm/modules/js-wasm-global-namespace.js: (assert.throws): * wasm/modules/js-wasm-global.js: (assert.throws): * wasm/modules/wasm-import-wasm-export-i64-error.js: * wasm/references/anyref_globals.js: * wasm/references/func_ref.js: (assert.eq.instance.exports.fix): * wasm/spec-harness.js: (getGlobal): (let.console.log): * wasm/spec-harness/sync_index.js: Renamed from JSTests/wasm/spec-harness/index.js. (reinitializeRegistry.let.handler.get return): (module): * wasm/spec-tests/call.wast.js: * wasm/spec-tests/exports.wast.js: * wasm/spec-tests/globals.wast.js: * wasm/spec-tests/if.wast.js: * wasm/spec-tests/imports.wast.js: * wasm/spec-tests/linking.wast.js: * wasm/spec-tests/memory.wast.js: * wasm/stress/immutable-globals.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.assert.eq.instance.exports.getI32): (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.assert.eq): * wasm/stress/mutable-globals-cross.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.const.instance1): (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.const.instance2): * wasm/stress/mutable-globals.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.instance.exports.setI32AsI64): LayoutTests/imported/w3c: * web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any-expected.txt: * web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/constructor.any-expected.txt: * web-platform-tests/wasm/jsapi/global/constructor.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/toString.any-expected.txt: * web-platform-tests/wasm/jsapi/global/toString.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/value-set.any-expected.txt: * web-platform-tests/wasm/jsapi/global/value-set.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/valueOf.any-expected.txt: * web-platform-tests/wasm/jsapi/global/valueOf.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor.any-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/interface.any-expected.txt: * web-platform-tests/wasm/jsapi/interface.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/module/exports.any-expected.txt: * web-platform-tests/wasm/jsapi/module/exports.any.worker-expected.txt: Source/JavaScriptCore: This patch adds WebAssembly.Global implementation. It is already included in the Wasm spec (this means, it is not in staging right now: it was stage-4, and included in the spec). WebAssembly.Global is a wrapper object around "global" binding. This object can hold "immutable" and "mutable" global binding, and we can access Wasm globals through this object. Furthermore, we can share mutable global binding through this object across WebAssembly modules. To implement it efficiently, this patch introduces BindingMode to Wasm globals. If the mode is EmbeddedInInstance, we continue using the current existing mechanism. If the mode is Portable, we store a pointer to actual value in Wasm globals array in Wasm::Instance, so that we can access it through one additional dereference. And we mark all immutable globals as EmbeddedInInstance. If the binding is immutable, internally we do not need to have one binding. We can just continue using the current mechanism since users cannot observe whether immutable bindings' storage is shared or not. If the global is mutable, and it is exported outside of the module, we use Portable mode. So, all the previously used wasm global bindings are EmbeddedInInstance. Only newly added "mutable" "exported" bindings are Portable and requires one additional dereference. To access portable bindings efficiently, we add new Wasm bytecodes, `get_global_portable_binding`, `set_global_portable_binding`, and `set_global_ref_portable_binding`. This patch improves WPT wasm coverage significantly. * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/BytecodeList.rb: * heap/HeapCell.cpp: (JSC::keepAlive): (JSC::HeapCell::use const): Deleted. * heap/HeapCell.h: (JSC::keepAlive): (JSC::HeapCell::use const): * llint/WebAssembly.asm: * runtime/JSGlobalObject.cpp: * runtime/JSGlobalObject.h: * runtime/VM.cpp: (JSC::VM::VM): * runtime/VM.h: * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::getGlobal): (JSC::Wasm::AirIRGenerator::setGlobal): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::getGlobal): (JSC::Wasm::B3IRGenerator::setGlobal): * wasm/WasmFormat.h: * wasm/WasmGlobal.cpp: Added. (JSC::Wasm::Global::get const): (JSC::Wasm::Global::set): (JSC::Wasm::Global::visitAggregate): * wasm/WasmGlobal.h: Added. * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::linkGlobal): * wasm/WasmInstance.h: (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::globalsToBinding): (JSC::Wasm::Instance::getGlobalBinding): * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::getGlobal): (JSC::Wasm::LLIntGenerator::setGlobal): * wasm/WasmModuleInformation.h: * wasm/WasmOperations.cpp: (JSC::Wasm::operationWasmWriteBarrierSlowPath): * wasm/WasmOperations.h: * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseImport): (JSC::Wasm::SectionParser::parseGlobal): (JSC::Wasm::SectionParser::parseExport): (JSC::Wasm::SectionParser::parseInitExpr): (JSC::Wasm::SectionParser::parseGlobalType): * wasm/WasmSectionParser.h: * wasm/WasmSlowPaths.cpp: (JSC::LLInt::WASM_SLOW_PATH_DECL): * wasm/WasmSlowPaths.h: * wasm/WasmValidate.cpp: (JSC::Wasm::Validate::setGlobal): * wasm/js/JSWebAssembly.cpp: * wasm/js/JSWebAssemblyGlobal.cpp: Added. (JSC::JSWebAssemblyGlobal::create): (JSC::JSWebAssemblyGlobal::createStructure): (JSC::JSWebAssemblyGlobal::JSWebAssemblyGlobal): (JSC::JSWebAssemblyGlobal::finishCreation): (JSC::JSWebAssemblyGlobal::destroy): (JSC::JSWebAssemblyGlobal::visitChildren): * wasm/js/JSWebAssemblyGlobal.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/JSWebAssemblyInstance.h: * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::destroy): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.h: * wasm/js/WebAssemblyGlobalConstructor.cpp: Added. (JSC::constructJSWebAssemblyGlobal): (JSC::callJSWebAssemblyGlobal): (JSC::WebAssemblyGlobalConstructor::create): (JSC::WebAssemblyGlobalConstructor::createStructure): (JSC::WebAssemblyGlobalConstructor::finishCreation): (JSC::WebAssemblyGlobalConstructor::WebAssemblyGlobalConstructor): * wasm/js/WebAssemblyGlobalConstructor.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/WebAssemblyGlobalPrototype.cpp: Added. (JSC::getGlobal): (JSC::webAssemblyGlobalProtoFuncValueOf): (JSC::webAssemblyGlobalProtoGetterFuncValue): (JSC::webAssemblyGlobalProtoSetterFuncValue): (JSC::WebAssemblyGlobalPrototype::create): (JSC::WebAssemblyGlobalPrototype::createStructure): (JSC::WebAssemblyGlobalPrototype::finishCreation): (JSC::WebAssemblyGlobalPrototype::WebAssemblyGlobalPrototype): * wasm/js/WebAssemblyGlobalPrototype.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): Canonical link: https://commits.webkit.org/218038@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@253074 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-12-04 01:36:56 +00:00
BitVector m_globalsToBinding;
WebAssembly: restore cached stack limit after out-call https://bugs.webkit.org/show_bug.cgi?id=179106 <rdar://problem/35337525> Reviewed by Saam Barati. JSTests: * wasm/function-tests/double-instance.js: Added. (const.imp.boom): (const.imp.get callAnother): Source/JavaScriptCore: We cache the stack limit on the Instance so that we can do fast stack checks where required. In regular usage the stack limit never changes because we always run on the same thread, but in rare cases an API user can totally migrate which thread (and therefore stack) is used for execution between WebAssembly traces. For that reason we set the cached stack limit to UINTPTR_MAX on the outgoing Instance when transitioning back into a different Instance. We usually restore the cached stack limit in Context::store, but this wasn't called on all code paths. We had a bug where an Instance calling into itself indirectly would therefore fail to restore its cached stack limit properly. This patch therefore restores the cached stack limit after direct calls which could be to imports (both wasm->wasm and wasm->embedder). We have to do all of them because we have no way of knowing what imports will do (they're known at instantiation time, not compilation time, and different instances can have different imports). To make this efficient we also add a pointer to the canonical location of the stack limit (i.e. the extra indirection we're trying to save by caching the stack limit on the Instance in the first place). This is potentially a small perf hit on imported direct calls. It's hard to say what the performance cost will be because we haven't seen much code in the wild which does this. We're adding two dependent loads and a store of the loaded value, which is unlikely to get used soon after. It's more code, but on an out-of-order processor it doesn't contribute to the critical path. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): * wasm/WasmInstance.h: (JSC::Wasm::Instance::offsetOfPointerToActualStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::create): * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): Canonical link: https://commits.webkit.org/196260@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225411 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-12-01 21:58:36 +00:00
EntryFrame** m_pointerToTopEntryFrame { nullptr };
void** m_pointerToActualStackLimit { nullptr };
WebAssembly: no VM / JS version of everything but Instance https://bugs.webkit.org/show_bug.cgi?id=177473 Reviewed by Filip Pizlo, Saam Barati. JSTests: - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. * wasm/js-api/memory-grow.js: (assertEq): * wasm/js-api/table.js: (assert.throws): Source/JavaScriptCore: This change entails cleaning up and splitting a bunch of code which we had intertwined between C++ classes which represent JS objects, and pure C++ implementation objects. This specific change goes most of the way towards allowing JSC's WebAssembly to work without VM / JS, up to but excluding JSWebAssemblyInstance (there's Wasm::Instance, but it's not *the* thing yet). Because of this we still have a few FIXME identifying places that need to change. A follow-up change will go the rest of the way. I went about this change in the simplest way possible: grep the JavaScriptCore/wasm directory for "JS[^C_]" as well as "VM" and exclude the /js/ sub-directory (which contains the JS implementation of WebAssembly). None of this change removes the need for a JIT entitlement to be able to use WebAssembly. We don't have an interpreter, the process therefore still needs to be allowed to JIT to use these pure-C++ APIs. Interesting things to note: - Remove VM from Plan and associated places. It can just live as a capture in the callback lambda if it's needed. - Wasm::Memory shouldn't require a VM. It was only used to ask the GC to collect. We now instead pass two lambdas at construction time for this purpose: one to notify of memory pressure, and the other to ask for syncrhonous memory reclamation. This allows whoever creates the memory to dictate how to react to both these cases, and for a JS embedding that's to call the GC (async or sync, respectively). - Move grow logic from JSWebAssemblyMemory to Wasm::Memory::grow. Use Expected there, with an enum class for failure types. - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. - When generating the grow_memory opcode, no need to get the VM. Instead, reach directly for Wasm::Memory and grow it. - JSWebAssemblyMemory::grow can now always throw on failure, because it's only ever called from JS (not from grow_memory as before). - Wasm::Memory now takes a callback for successful growth. This allows JS wrappers to register themselves when growth succeeds without Wasm::Memory knowning anything about JS. It'll also allow creating a list of callbacks for when we add thread support (we'll want to notify many wrappers, all under a lock). - Wasm::Memory is now back to being the source of truth about address / size, used directly by generated code instead of JSWebAssemblyMemory. - Move wasmToJS from the general WasmBinding header to its own header under wasm/js. It's only used by wasm/js/JSWebAssemblyCodeBlock.cpp, and uses VM, and therefore isn't general WebAssembly. - Make Wasm::Context an actual type (just a struct holding a JSWebAssemlyInstance for now) instead of an alias for that. Notably this doesn't add anything to the Context and doesn't change what actually gets passed around in JIT code (fast TLS or registers) because these changes potentially impact performance. The entire purpose of this change is to allow passing Wasm::Context around without having to know about VM. Since VM contains a Wasm::Context the JS embedding is effectively the same, but with this setup a non-JS embedding is much better off. - Move JSWebAssembly into the JS folder. - OMGPlan: use Wasm::CodeBlock directly instead of JSWebAssemblyCodeBlock. - wasm->JS stubs are now on the instance's tail as raw pointers, instead of being on JSWebAssemblyCodeBlock, and are now called wasm->Embedder stubs. The owned reference is still on JSWebAssemblyCodeBlock, and is still called wasm->JS stub. This move means that the embedder must, after creating a Wasm::CodeBlock, somehow create the stubs to call back into the embedder. This removes an indirection in the generated code because the B3 IR generator now reaches into the instance instead of JSWebAssemblyCodeBlock. - Move more CodeBlock things. Compilation completion is now marked by its own atomic<bool> flag instead of a nullptr plan: that required using a lock, and was causing a deadlock in stack-trace.js because before my changes JSWebAssemblyCodeBlock did its own completion checking separately from Wasm::CodeBlock, without getting the lock. Now that everything points to Wasm::CodeBlock and there's no cached completion marker, the lock was being acquired in a sanity-check assertion. - Embedder -> Wasm wrappers are now generated through a function that's passed in at compilation time, instead of being hard-coded as a JS -> Wasm wrapper. - WasmMemory doens't need to know about fault handling thunks. Only the IR generator should know, and should make sure that the exception throwing thunk is generated if any memory is present (note: with signal handling not all of them generate an exception check). - Make exception throwing pluggable: instead of having a hard-coded JS-specific lambda we now have a regular C++ function being called from JIT code when a WebAssembly exception is thrown. This allows any embedder to get called as they wish. For now a process can only have a single of these functions (i.e. only one embedder per process) because the trap handler is a singleton. That can be fixed in in #177475. - Create WasmEmbedder.h where all embedder plugging will live. - Split up JSWebAssemblyTable into Wasm::Table which is refcounted. JSWebAssemblyTable now only contains the JS functions in the table, and Wasm::Table is what's used by the JIT code to lookup where to call and do the instance check (for context switch). Note that this creates an extra allocation for all the instances in Wasm::Table, and in exchange removes an indirection in JIT code because the instance used to be obtained off of the JS function. Also note that it's the embedder than keeps the instances alive, not Wasm::Table (which holds a dumb pointer to the instance), because doing otherwise would cause reference cycles. - Add WasmInstance. It doesn't do much for now, owns globals. - JSWebAssembly instance now doesn't just contain the imported functions as JSObjects, it also has the corresponding import's instance and wasm entrypoint. This triples the space allocated per instance's imported function, but there shouldn't be that many imports. This has two upsides: it creates smaller and faster code, and makes is easier to disassociate embedder-specific things from embedder-neutral things. The small / faster win is in two places: B3 IR generator only needs offsetOfImportFunction for the call opcode (when the called index is an import) to know whether the import is wasm->wasm or wasm->embedder (this isn't known at compile-time because it's dependent on the import object), this is now done by seeing if that import function has an associated target instance (only wasm->wasm does); the other place is wasmBinding which uses offsetOfImportFunction to figure out the wasm->wasm target instance, and then gets WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation to do a tail call. The disassociation comes because the target instance can be Wasm::Instance once we change what the Context is, and WasmEntrypointLoadLocation is already embedder-independent. As a next step I can move this tail allocation from JSWebAssemblyInstance to Wasm::Instance, and leave importFunction in as an opaque pointer which is embedder-specific, and in JS will remain WriteBarrier<JSObject>. - Rename VMEntryFrame to EntryFrame, and in many places pass a pointer to it around instead of VM. This is a first step in allowing entry frames which aren't stored on VM, but which are instead stored in an embedder-specific location. That change won't really affect JS except through code churn, but will allow WebAssembly to use some machinery in a generic manner without having a VM. * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * debugger/Debugger.cpp: (JSC::Debugger::stepOutOfFunction): (JSC::Debugger::returnEvent): (JSC::Debugger::unwindEvent): (JSC::Debugger::didExecuteProgram): * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::compileExceptionHandlers): * dfg/DFGOSREntry.cpp: (JSC::DFG::prepareOSREntry): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::compileOSRExit): (JSC::DFG::OSRExit::compileExit): * dfg/DFGThunks.cpp: (JSC::DFG::osrEntryThunkGenerator): * ftl/FTLCompile.cpp: (JSC::FTL::compile): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::lower): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): (JSC::CallFrame::callerFrame): (JSC::CallFrame::unsafeCallerFrame): * interpreter/CallFrame.h: (JSC::ExecState::callerFrame const): (JSC::ExecState::callerFrameOrEntryFrame const): (JSC::ExecState::unsafeCallerFrameOrEntryFrame const): * interpreter/FrameTracers.h: (JSC::NativeCallFrameTracer::NativeCallFrameTracer): (JSC::NativeCallFrameTracerWithRestore::NativeCallFrameTracerWithRestore): (JSC::NativeCallFrameTracerWithRestore::~NativeCallFrameTracerWithRestore): * interpreter/Interpreter.cpp: (JSC::UnwindFunctor::operator() const): (JSC::UnwindFunctor::copyCalleeSavesToEntryFrameCalleeSavesBuffer const): (JSC::Interpreter::unwind): * interpreter/StackVisitor.cpp: (JSC::StackVisitor::StackVisitor): (JSC::StackVisitor::gotoNextFrame): (JSC::StackVisitor::readNonInlinedFrame): (JSC::StackVisitor::Frame::dump const): * interpreter/StackVisitor.h: (JSC::StackVisitor::Frame::callerIsEntryFrame const): * interpreter/VMEntryRecord.h: (JSC::VMEntryRecord::prevTopEntryFrame): (JSC::VMEntryRecord::unsafePrevTopEntryFrame): (JSC::EntryFrame::vmEntryRecordOffset): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::restoreCalleeSavesFromEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::loadWasmContextInstance): (JSC::AssemblyHelpers::storeWasmContextInstance): (JSC::AssemblyHelpers::loadWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::storeWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBufferImpl): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::copyCalleeSavesToVMEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer): * jit/JIT.cpp: (JSC::JIT::emitEnterOptimizationCheck): (JSC::JIT::privateCompileExceptionHandlers): * jit/JITExceptions.cpp: (JSC::genericUnwind): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): (JSC::JIT::emitSlow_op_loop_hint): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): * jit/JITOperations.cpp: * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::nativeForGenerator): * jsc.cpp: (functionDumpCallFrame): * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LLIntThunks.cpp: (JSC::vmEntryRecord): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/Options.cpp: (JSC::recomputeDependentOptions): * runtime/Options.h: * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::FrameWalker): (JSC::FrameWalker::advanceToParentFrame): (JSC::SamplingProfiler::processUnverifiedStackTraces): * runtime/ThrowScope.cpp: (JSC::ThrowScope::~ThrowScope): * runtime/VM.cpp: (JSC::VM::VM): (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::topEntryFrameOffset): * runtime/VMTraps.cpp: (JSC::isSaneFrame): (JSC::VMTraps::tryInstallTrapBreakpoints): (JSC::VMTraps::invalidateCodeBlocksOnStack): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWasmContextInstance): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::parseAndCompile): * wasm/WasmB3IRGenerator.h: * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::BBQPlan): (JSC::Wasm::BBQPlan::compileFunctions): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBBQPlanInlines.h: (JSC::Wasm::BBQPlan::initializeCallees): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmBinding.h: * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::create): (JSC::Wasm::CodeBlock::CodeBlock): (JSC::Wasm::CodeBlock::compileAsync): (JSC::Wasm::CodeBlock::setCompilationFinished): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::offsetOfImportStubs): (JSC::Wasm::CodeBlock::allocationSize): (JSC::Wasm::CodeBlock::importWasmToEmbedderStub): (JSC::Wasm::CodeBlock::offsetOfImportWasmToEmbedderStub): (JSC::Wasm::CodeBlock::wasmToJSCallStubForImport): (JSC::Wasm::CodeBlock::compilationFinished): (JSC::Wasm::CodeBlock::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): * wasm/WasmContext.cpp: (JSC::Wasm::Context::useFastTLS): (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: Copied from Source/JavaScriptCore/wasm/WasmContext.h. * wasm/WasmFaultSignalHandler.cpp: * wasm/WasmFaultSignalHandler.h: * wasm/WasmFormat.h: * wasm/WasmInstance.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::~Instance): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: Added. (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::module): (JSC::Wasm::Instance::codeBlock): (JSC::Wasm::Instance::memory): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::loadF32Global const): (JSC::Wasm::Instance::loadF64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::offsetOfCachedStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::~Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::offsetOfSize): * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationCallback): (JSC::Wasm::Module::validateSync): (JSC::Wasm::Module::validateAsync): (JSC::Wasm::Module::getOrCreateCodeBlock): (JSC::Wasm::Module::compileSync): (JSC::Wasm::Module::compileAsync): * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseTableHelper): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::OMGPlan): (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::isValid const): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::runCompletionTasks): (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmPlan.h: (JSC::Wasm::Plan::dontFinalize): * wasm/WasmSignature.cpp: * wasm/WasmSignature.h: * wasm/WasmTable.cpp: Added. (JSC::Wasm::Table::create): (JSC::Wasm::Table::~Table): (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h. (JSC::Wasm::Table::maximum const): (JSC::Wasm::Table::size const): (JSC::Wasm::Table::offsetOfSize): (JSC::Wasm::Table::offsetOfFunctions): (JSC::Wasm::Table::offsetOfInstances): (JSC::Wasm::Table::isValidSize): * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): (JSC::Wasm::Thunks::setThrowWasmException): (JSC::Wasm::Thunks::throwWasmException): * wasm/WasmThunks.h: * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::stopAllPlansForContext): * wasm/WasmWorklist.h: * wasm/js/JSToWasm.cpp: Added. (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/JSWebAssembly.cpp: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.cpp. * wasm/js/JSWebAssembly.h: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.h. * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::create): (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::context const): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::webAssemblyToJSCallee): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::offsetOfTail): (JSC::JSWebAssemblyInstance::importFunctionInfo): (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): (JSC::JSWebAssemblyInstance::offsetOfImportFunction): (JSC::JSWebAssemblyInstance::importFunction): (JSC::JSWebAssemblyInstance::internalMemory): (JSC::JSWebAssemblyInstance::wasmCodeBlock const): (JSC::JSWebAssemblyInstance::offsetOfWasmTable): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::offsetOfGlobals): (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): (JSC::JSWebAssemblyInstance::cachedStackLimit const): (JSC::JSWebAssemblyInstance::setCachedStackLimit): (JSC::JSWebAssemblyInstance::wasmMemory): (JSC::JSWebAssemblyInstance::wasmModule): (JSC::JSWebAssemblyInstance::allocationSize): (JSC::JSWebAssemblyInstance::module const): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::create): (JSC::JSWebAssemblyMemory::adopt): (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::moduleInformation const): (JSC::JSWebAssemblyModule::exportSymbolTable const): (JSC::JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace const): (JSC::JSWebAssemblyModule::callee const): (JSC::JSWebAssemblyModule::codeBlock): (JSC::JSWebAssemblyModule::module): * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::create): (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::visitChildren): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::getFunction): (JSC::JSWebAssemblyTable::clearFunction): (JSC::JSWebAssemblyTable::setFunction): * wasm/js/JSWebAssemblyTable.h: (JSC::JSWebAssemblyTable::isValidSize): (JSC::JSWebAssemblyTable::maximum const): (JSC::JSWebAssemblyTable::size const): (JSC::JSWebAssemblyTable::table): * wasm/js/WasmToJS.cpp: Copied from Source/JavaScriptCore/wasm/WasmBinding.cpp. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): (JSC::WebAssemblyModuleConstructor::createModule): * wasm/js/WebAssemblyModuleConstructor.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::webAssemblyCompileFunc): (JSC::instantiate): (JSC::compileAndInstantiate): (JSC::webAssemblyValidateFunc): * wasm/js/WebAssemblyTableConstructor.cpp: (JSC::constructJSWebAssemblyTable): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Source/WebCore: * ForwardingHeaders/wasm/WasmModule.h: Added. This used to be included in JSWebAssemblyModule.h. * bindings/js/SerializedScriptValue.cpp: Update postMessage code according to C++ API changes. Canonical link: https://commits.webkit.org/194750@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223738 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-20 02:23:29 +00:00
void* m_cachedStackLimit { bitwise_cast<void*>(std::numeric_limits<uintptr_t>::max()) };
We need to set topCallFrame when calling Wasm::Memory::grow from the JIT https://bugs.webkit.org/show_bug.cgi?id=179639 <rdar://problem/35513018> Reviewed by JF Bastien. JSTests: * wasm/function-tests/grow-memory-cause-gc.js: Added. (escape): (i.func): Source/JavaScriptCore: Calling Wasm::Memory::grow from the JIT may cause us to GC. When we GC, we will walk the stack for ShadowChicken (and maybe other things). We weren't updating topCallFrame when calling grow from the Wasm JIT. This would cause the GC to use stale topCallFrame bits in VM, often leading to crashes. This patch fixes this bug by giving Wasm::Instance a lambda that is called when we need to store the topCallFrame. Users of Wasm::Instance can provide a function to do this action. Currently, JSWebAssemblyInstance passes in a lambda that stores to VM.topCallFrame. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::addGrowMemory): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): * wasm/WasmInstance.h: (JSC::Wasm::Instance::storeTopCallFrame): * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: * wasm/js/WasmToJS.cpp: (JSC::Wasm::wasmToJSException): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyPrototype.cpp: (JSC::instantiate): Canonical link: https://commits.webkit.org/195695@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224810 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-11-14 09:05:33 +00:00
StoreTopCallFrameCallback m_storeTopCallFrame;
WebAssembly: no VM / JS version of our implementation https://bugs.webkit.org/show_bug.cgi?id=177472 Reviewed by Michael Saboff. This patch removes all appearances of "JS" and "VM" in the wasm directory. These now only appear in the wasm/js directory, which is only used in a JS embedding of wasm. It should therefore now be possible to create non-JS embeddings of wasm through JSC, though it'll still require: - Mild codegen for wasm<->embedder calls; - A strategy for trap handling (no need for full unwind! Could kill). - Creation of the Wasm::* objects. - Calling convention handling to call the embedder. - Handling of multiple embedders (see #177475, this is optional). Most of the patch consists in renaming JSWebAssemblyInstance to Instance, and removing temporary copies which I'd added to make this specific patch very simple. * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): this one place which needs to know about who "owns" the Wasm::Instance. In a JS embedding it's the JSWebAssemblyInstance. * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::getGlobal): (JSC::Wasm::B3IRGenerator::setGlobal): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmContext.cpp: (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: add an "owner", the Wasm::Context, move the "tail" import information from JSWebAssemblyInstance over to here. (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::owner const): (JSC::Wasm::Instance::offsetOfOwner): (JSC::Wasm::Instance::context const): (JSC::Wasm::Instance::setMemory): (JSC::Wasm::Instance::setTable): (JSC::Wasm::Instance::offsetOfMemory): (JSC::Wasm::Instance::offsetOfGlobals): (JSC::Wasm::Instance::offsetOfTable): (JSC::Wasm::Instance::offsetOfTail): (JSC::Wasm::Instance::numImportFunctions const): (JSC::Wasm::Instance::importFunctionInfo): (JSC::Wasm::Instance::offsetOfTargetInstance): (JSC::Wasm::Instance::offsetOfWasmEntrypoint): (JSC::Wasm::Instance::offsetOfWasmToEmbedderStubExecutableAddress): (JSC::Wasm::Instance::offsetOfImportFunction): (JSC::Wasm::Instance::importFunction): (JSC::Wasm::Instance::allocationSize): (JSC::Wasm::Instance::create): Deleted. * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmTable.cpp: (JSC::Wasm::Table::Table): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): * wasm/js/JSToWasm.cpp: (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSWebAssemblyInstance.cpp: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): The embedder decides what the import function is. Here we must properly placement-new it to what we've elected (and initialize it later). (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: delete code that is now on Wasm::Instance (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::moduleNamespaceObject): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::setTable): (JSC::JSWebAssemblyInstance::offsetOfInstance): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::context const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTail): Deleted. (): Deleted. (JSC::JSWebAssemblyInstance::importFunctionInfo): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmToEmbedderStubExecutableAddress): Deleted. (JSC::JSWebAssemblyInstance::offsetOfImportFunction): Deleted. (JSC::JSWebAssemblyInstance::importFunction): Deleted. (JSC::JSWebAssemblyInstance::internalMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmCodeBlock const): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmTable): Deleted. (JSC::JSWebAssemblyInstance::offsetOfGlobals): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): Deleted. (JSC::JSWebAssemblyInstance::offsetOfCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): Deleted. (JSC::JSWebAssemblyInstance::offsetOfTopEntryFramePointer): Deleted. (JSC::JSWebAssemblyInstance::cachedStackLimit const): Deleted. (JSC::JSWebAssemblyInstance::setCachedStackLimit): Deleted. (JSC::JSWebAssemblyInstance::wasmMemory): Deleted. (JSC::JSWebAssemblyInstance::wasmModule): Deleted. (JSC::JSWebAssemblyInstance::allocationSize): Deleted. * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::setFunction): * wasm/js/WasmToJS.cpp: One extra indirection to find the JSWebAssemblyInstance. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::handleBadI64Use): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::instantiate): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Canonical link: https://commits.webkit.org/195012@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224020 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-26 15:33:55 +00:00
unsigned m_numImportFunctions { 0 };
Adopt the new WebAssembly.Global system https://bugs.webkit.org/show_bug.cgi?id=186552 Reviewed by Keith Miller. JSTests: 1. Update spec-harness to accept newer tests. And we update several tests that does not work with the old harness. 2. Add WebAssembly.Global tests. * wasm/js-api/global-error.js: (assert.throws.new.WebAssembly.Module.bin): (new.WebAssembly.Module): (assert.throws): * wasm/js-api/global-external-init-from-import.js: * wasm/js-api/globals-export.js: * wasm/modules/js-wasm-global-namespace.js: (assert.throws): * wasm/modules/js-wasm-global.js: (assert.throws): * wasm/modules/wasm-import-wasm-export-i64-error.js: * wasm/references/anyref_globals.js: * wasm/references/func_ref.js: (assert.eq.instance.exports.fix): * wasm/spec-harness.js: (getGlobal): (let.console.log): * wasm/spec-harness/sync_index.js: Renamed from JSTests/wasm/spec-harness/index.js. (reinitializeRegistry.let.handler.get return): (module): * wasm/spec-tests/call.wast.js: * wasm/spec-tests/exports.wast.js: * wasm/spec-tests/globals.wast.js: * wasm/spec-tests/if.wast.js: * wasm/spec-tests/imports.wast.js: * wasm/spec-tests/linking.wast.js: * wasm/spec-tests/memory.wast.js: * wasm/stress/immutable-globals.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.assert.eq.instance.exports.getI32): (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.assert.eq): * wasm/stress/mutable-globals-cross.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.const.instance1): (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.const.instance2): * wasm/stress/mutable-globals.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.i.instance.exports.setI32AsI64): LayoutTests/imported/w3c: * web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any-expected.txt: * web-platform-tests/wasm/jsapi/constructor/instantiate-bad-imports.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/constructor.any-expected.txt: * web-platform-tests/wasm/jsapi/global/constructor.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/toString.any-expected.txt: * web-platform-tests/wasm/jsapi/global/toString.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/value-set.any-expected.txt: * web-platform-tests/wasm/jsapi/global/value-set.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/global/valueOf.any-expected.txt: * web-platform-tests/wasm/jsapi/global/valueOf.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor-bad-imports.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor.any-expected.txt: * web-platform-tests/wasm/jsapi/instance/constructor.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/interface.any-expected.txt: * web-platform-tests/wasm/jsapi/interface.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/module/exports.any-expected.txt: * web-platform-tests/wasm/jsapi/module/exports.any.worker-expected.txt: Source/JavaScriptCore: This patch adds WebAssembly.Global implementation. It is already included in the Wasm spec (this means, it is not in staging right now: it was stage-4, and included in the spec). WebAssembly.Global is a wrapper object around "global" binding. This object can hold "immutable" and "mutable" global binding, and we can access Wasm globals through this object. Furthermore, we can share mutable global binding through this object across WebAssembly modules. To implement it efficiently, this patch introduces BindingMode to Wasm globals. If the mode is EmbeddedInInstance, we continue using the current existing mechanism. If the mode is Portable, we store a pointer to actual value in Wasm globals array in Wasm::Instance, so that we can access it through one additional dereference. And we mark all immutable globals as EmbeddedInInstance. If the binding is immutable, internally we do not need to have one binding. We can just continue using the current mechanism since users cannot observe whether immutable bindings' storage is shared or not. If the global is mutable, and it is exported outside of the module, we use Portable mode. So, all the previously used wasm global bindings are EmbeddedInInstance. Only newly added "mutable" "exported" bindings are Portable and requires one additional dereference. To access portable bindings efficiently, we add new Wasm bytecodes, `get_global_portable_binding`, `set_global_portable_binding`, and `set_global_ref_portable_binding`. This patch improves WPT wasm coverage significantly. * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/BytecodeList.rb: * heap/HeapCell.cpp: (JSC::keepAlive): (JSC::HeapCell::use const): Deleted. * heap/HeapCell.h: (JSC::keepAlive): (JSC::HeapCell::use const): * llint/WebAssembly.asm: * runtime/JSGlobalObject.cpp: * runtime/JSGlobalObject.h: * runtime/VM.cpp: (JSC::VM::VM): * runtime/VM.h: * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::getGlobal): (JSC::Wasm::AirIRGenerator::setGlobal): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::getGlobal): (JSC::Wasm::B3IRGenerator::setGlobal): * wasm/WasmFormat.h: * wasm/WasmGlobal.cpp: Added. (JSC::Wasm::Global::get const): (JSC::Wasm::Global::set): (JSC::Wasm::Global::visitAggregate): * wasm/WasmGlobal.h: Added. * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::linkGlobal): * wasm/WasmInstance.h: (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::globalsToBinding): (JSC::Wasm::Instance::getGlobalBinding): * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::getGlobal): (JSC::Wasm::LLIntGenerator::setGlobal): * wasm/WasmModuleInformation.h: * wasm/WasmOperations.cpp: (JSC::Wasm::operationWasmWriteBarrierSlowPath): * wasm/WasmOperations.h: * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseImport): (JSC::Wasm::SectionParser::parseGlobal): (JSC::Wasm::SectionParser::parseExport): (JSC::Wasm::SectionParser::parseInitExpr): (JSC::Wasm::SectionParser::parseGlobalType): * wasm/WasmSectionParser.h: * wasm/WasmSlowPaths.cpp: (JSC::LLInt::WASM_SLOW_PATH_DECL): * wasm/WasmSlowPaths.h: * wasm/WasmValidate.cpp: (JSC::Wasm::Validate::setGlobal): * wasm/js/JSWebAssembly.cpp: * wasm/js/JSWebAssemblyGlobal.cpp: Added. (JSC::JSWebAssemblyGlobal::create): (JSC::JSWebAssemblyGlobal::createStructure): (JSC::JSWebAssemblyGlobal::JSWebAssemblyGlobal): (JSC::JSWebAssemblyGlobal::finishCreation): (JSC::JSWebAssemblyGlobal::destroy): (JSC::JSWebAssemblyGlobal::visitChildren): * wasm/js/JSWebAssemblyGlobal.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::visitChildren): * wasm/js/JSWebAssemblyInstance.h: * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::destroy): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.h: * wasm/js/WebAssemblyGlobalConstructor.cpp: Added. (JSC::constructJSWebAssemblyGlobal): (JSC::callJSWebAssemblyGlobal): (JSC::WebAssemblyGlobalConstructor::create): (JSC::WebAssemblyGlobalConstructor::createStructure): (JSC::WebAssemblyGlobalConstructor::finishCreation): (JSC::WebAssemblyGlobalConstructor::WebAssemblyGlobalConstructor): * wasm/js/WebAssemblyGlobalConstructor.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/WebAssemblyGlobalPrototype.cpp: Added. (JSC::getGlobal): (JSC::webAssemblyGlobalProtoFuncValueOf): (JSC::webAssemblyGlobalProtoGetterFuncValue): (JSC::webAssemblyGlobalProtoSetterFuncValue): (JSC::WebAssemblyGlobalPrototype::create): (JSC::WebAssemblyGlobalPrototype::createStructure): (JSC::WebAssemblyGlobalPrototype::finishCreation): (JSC::WebAssemblyGlobalPrototype::WebAssemblyGlobalPrototype): * wasm/js/WebAssemblyGlobalPrototype.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h. * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): Canonical link: https://commits.webkit.org/218038@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@253074 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-12-04 01:36:56 +00:00
HashMap<uint32_t, Ref<Global>, IntHash<uint32_t>, WTF::UnsignedWithZeroKeyHashTraits<uint32_t>> m_linkedGlobals;
[WASM-References] Add table.init https://bugs.webkit.org/show_bug.cgi?id=219297 Patch by Dmitry Bezhetskov <dbezhetskov@igalia.com> on 2020-12-11 Reviewed by Yusuke Suzuki. JSTests: Added reference types spec tests for element section, table.init and elem.drop: https://github.com/WebAssembly/reference-types/blob/master/test/core/elem.wast, https://github.com/WebAssembly/reference-types/blob/master/test/core/table_init.wast. Added tests for checking table instructions immediates when they are unreachable. * wasm.yaml: * wasm/references-spec-tests/elem.wast.js: Added. * wasm/references-spec-tests/ref_is_null.js: Removed. * wasm/references-spec-tests/ref_is_null.wast.js: Added. * wasm/references-spec-tests/ref_null.js: Removed. * wasm/references-spec-tests/ref_null.wast.js: Added. * wasm/references-spec-tests/table_copy.wast.js: Renamed from JSTests/wasm/references-spec-tests/table_copy.js. * wasm/references-spec-tests/table_init.wast.js: Added. * wasm/spec-harness/wasm-constants.js: (hostref): * wasm/wasm.json: Source/JavaScriptCore: Add support for table.init, elem.drop and new element section from reference-type proposal: https://webassembly.github.io/reference-types/core/syntax/instructions.html#table-instructions, https://webassembly.github.io/reference-types/core/syntax/modules.html#element-segments. All in one patch because all this stuff are very coupled and ref-types spec tests require each other to run the its tests, so not to write hand-crafted tests this is in one PR. * bytecode/BytecodeList.rb: * llint/WebAssembly.asm: * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::addTableInit): (JSC::Wasm::AirIRGenerator::addElemDrop): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::addTableInit): (JSC::Wasm::B3IRGenerator::addElemDrop): * wasm/WasmFormat.h: (JSC::Wasm::Element::Element): (JSC::Wasm::Element::length const): (JSC::Wasm::Element::isPassive const): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parseExpression): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::elemDrop): (JSC::Wasm::Instance::elem const): (JSC::Wasm::Instance::initElementSegment): (JSC::Wasm::Instance::tableInit): * wasm/WasmInstance.h: (JSC::Wasm::Instance::isImportFunction const): * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::addTableInit): (JSC::Wasm::LLIntGenerator::addElemDrop): * wasm/WasmModuleInformation.h: (JSC::Wasm::ModuleInformation::elementCount const): * wasm/WasmOperations.cpp: (JSC::Wasm::JSC_DEFINE_JIT_OPERATION): * wasm/WasmOperations.h: * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseElement): (JSC::Wasm::SectionParser::parseElementSegmentVectorOfExpressions): (JSC::Wasm::SectionParser::parseElementSegmentVectorOfIndexes): (JSC::Wasm::SectionParser::parseFuncIndexFromRefExpForElementSection): Deleted. (JSC::Wasm::SectionParser::parseFuncIndexForElementSection): Deleted. * wasm/WasmSectionParser.h: * wasm/WasmSlowPaths.cpp: (JSC::LLInt::WASM_SLOW_PATH_DECL): * wasm/WasmSlowPaths.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::evaluate): * wasm/wasm.json: Tools: Support ref-types spec tests. * Scripts/run-jsc-stress-tests: Canonical link: https://commits.webkit.org/232352@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@270689 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-12-11 19:04:22 +00:00
BitVector m_passiveElements;
[WASM-References] Add support for memory.copy, memory.init and data.drop https://bugs.webkit.org/show_bug.cgi?id=219943 Patch by Dmitry Bezhetskov <dbezhetskov@igalia.com> on 2020-12-17 Reviewed by Yusuke Suzuki. JSTests: Added ref-types spec tests for memory.copy, memory.init and data.drop: https://github.com/WebAssembly/reference-types/tree/master/test/core. Renamed table_instructions_parse_unreachable test into just parse_unreachable to prevent confusion. * wasm.yaml: * wasm/references-spec-tests/memory_copy.wast.js: Added. * wasm/references-spec-tests/memory_init.wast.js: Added. * wasm/references/memory_copy.js: Added. (async test): * wasm/references/memory_copy_shared.js: Added. (async test): * wasm/references/parse_unreachable.js: Renamed from JSTests/wasm/references/table_instructions_parse_unreachable.js. (invalidMemoryCopyUnreachable): (invalidMemoryInitUnreachable): (invalidDataDropUnreachable): * wasm/wasm.json: Source/JavaScriptCore: Add support for memory.copy [dstAddress, srcAddress, length] -> [] that copies one memory segment to another memory segment. The memory.copy calls C memcpy function to utilize all possible optimization for copy. This instruction speedup copying data segments in wasm because without it we need to use a lot load/store instructions with loops in wasm. Add support for memory.init data_segment_index [dstAddress, srcAddress, length] -> [] that copies data from a passive data segment into a memory segment. This instruction is the same as memory.copy but for read-only data segments. It also utilize C memcpy under the hood. Add support for data.drop data_segment_index [] -> [] that resize given data segment to zero. Data.drop makes redundant data segment and prevents usage of it in the next. BTW, it is just a hint for the host runtime so we don't have to change data segment. Add support for Data count section. This section just stores the number of data segments. We need this to validate memory.init instruction's data index because Code section comes before Data section. These instructions are needed to support reference types proposal and bulk proposal. * bytecode/BytecodeList.rb: * llint/WebAssembly.asm: * wasm/WasmAirIRGenerator.cpp: (JSC::Wasm::AirIRGenerator::addMemoryCopy): (JSC::Wasm::AirIRGenerator::addMemoryInit): (JSC::Wasm::AirIRGenerator::addDataDrop): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::addMemoryInit): (JSC::Wasm::B3IRGenerator::addMemoryCopy): (JSC::Wasm::B3IRGenerator::addDataDrop): * wasm/WasmFormat.cpp: (JSC::Wasm::Segment::create): * wasm/WasmFormat.h: (JSC::Wasm::Segment::isActive const): (JSC::Wasm::Segment::isPassive const): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parseDataSegmentIndex): (JSC::Wasm::FunctionParser<Context>::parseMemoryCopyImmediates): (JSC::Wasm::FunctionParser<Context>::parseMemoryInitImmediates): (JSC::Wasm::FunctionParser<Context>::parseExpression): (JSC::Wasm::FunctionParser<Context>::parseUnreachableExpression): * wasm/WasmInstance.cpp: (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::memoryInit): (JSC::Wasm::Instance::dataDrop): * wasm/WasmInstance.h: * wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::addMemoryInit): (JSC::Wasm::LLIntGenerator::addDataDrop): (JSC::Wasm::LLIntGenerator::addMemoryCopy): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::copy): (JSC::Wasm::Memory::init): * wasm/WasmMemory.h: * wasm/WasmModuleInformation.h: (JSC::Wasm::ModuleInformation::dataSegmentsCount const): * wasm/WasmOperations.cpp: (JSC::Wasm::JSC_DEFINE_JIT_OPERATION): * wasm/WasmOperations.h: * wasm/WasmSectionParser.cpp: (JSC::Wasm::SectionParser::parseElement): (JSC::Wasm::SectionParser::parseI32InitExpr): (JSC::Wasm::SectionParser::parseI32InitExprForElementSection): (JSC::Wasm::SectionParser::parseI32InitExprForDataSection): (JSC::Wasm::SectionParser::parseDataSegmentCoreSpec): (JSC::Wasm::SectionParser::parseDataSegmentReferenceTypesSpec): (JSC::Wasm::SectionParser::parseGlobalType): (JSC::Wasm::SectionParser::parseData): (JSC::Wasm::SectionParser::parseDataCount): * wasm/WasmSectionParser.h: * wasm/WasmSections.h: (JSC::Wasm::validateOrder): * wasm/WasmSlowPaths.cpp: (JSC::LLInt::WASM_SLOW_PATH_DECL): * wasm/WasmSlowPaths.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::evaluate): * wasm/wasm.json: Canonical link: https://commits.webkit.org/232571@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@270948 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-12-17 22:25:20 +00:00
BitVector m_passiveDataSegments;
WebAssembly: no VM / JS version of everything but Instance https://bugs.webkit.org/show_bug.cgi?id=177473 Reviewed by Filip Pizlo, Saam Barati. JSTests: - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. * wasm/js-api/memory-grow.js: (assertEq): * wasm/js-api/table.js: (assert.throws): Source/JavaScriptCore: This change entails cleaning up and splitting a bunch of code which we had intertwined between C++ classes which represent JS objects, and pure C++ implementation objects. This specific change goes most of the way towards allowing JSC's WebAssembly to work without VM / JS, up to but excluding JSWebAssemblyInstance (there's Wasm::Instance, but it's not *the* thing yet). Because of this we still have a few FIXME identifying places that need to change. A follow-up change will go the rest of the way. I went about this change in the simplest way possible: grep the JavaScriptCore/wasm directory for "JS[^C_]" as well as "VM" and exclude the /js/ sub-directory (which contains the JS implementation of WebAssembly). None of this change removes the need for a JIT entitlement to be able to use WebAssembly. We don't have an interpreter, the process therefore still needs to be allowed to JIT to use these pure-C++ APIs. Interesting things to note: - Remove VM from Plan and associated places. It can just live as a capture in the callback lambda if it's needed. - Wasm::Memory shouldn't require a VM. It was only used to ask the GC to collect. We now instead pass two lambdas at construction time for this purpose: one to notify of memory pressure, and the other to ask for syncrhonous memory reclamation. This allows whoever creates the memory to dictate how to react to both these cases, and for a JS embedding that's to call the GC (async or sync, respectively). - Move grow logic from JSWebAssemblyMemory to Wasm::Memory::grow. Use Expected there, with an enum class for failure types. - Exceeding max on memory growth now returns a range error as per spec. This is a (very minor) breaking change: it used to throw OOM error. Update the corresponding test. - When generating the grow_memory opcode, no need to get the VM. Instead, reach directly for Wasm::Memory and grow it. - JSWebAssemblyMemory::grow can now always throw on failure, because it's only ever called from JS (not from grow_memory as before). - Wasm::Memory now takes a callback for successful growth. This allows JS wrappers to register themselves when growth succeeds without Wasm::Memory knowning anything about JS. It'll also allow creating a list of callbacks for when we add thread support (we'll want to notify many wrappers, all under a lock). - Wasm::Memory is now back to being the source of truth about address / size, used directly by generated code instead of JSWebAssemblyMemory. - Move wasmToJS from the general WasmBinding header to its own header under wasm/js. It's only used by wasm/js/JSWebAssemblyCodeBlock.cpp, and uses VM, and therefore isn't general WebAssembly. - Make Wasm::Context an actual type (just a struct holding a JSWebAssemlyInstance for now) instead of an alias for that. Notably this doesn't add anything to the Context and doesn't change what actually gets passed around in JIT code (fast TLS or registers) because these changes potentially impact performance. The entire purpose of this change is to allow passing Wasm::Context around without having to know about VM. Since VM contains a Wasm::Context the JS embedding is effectively the same, but with this setup a non-JS embedding is much better off. - Move JSWebAssembly into the JS folder. - OMGPlan: use Wasm::CodeBlock directly instead of JSWebAssemblyCodeBlock. - wasm->JS stubs are now on the instance's tail as raw pointers, instead of being on JSWebAssemblyCodeBlock, and are now called wasm->Embedder stubs. The owned reference is still on JSWebAssemblyCodeBlock, and is still called wasm->JS stub. This move means that the embedder must, after creating a Wasm::CodeBlock, somehow create the stubs to call back into the embedder. This removes an indirection in the generated code because the B3 IR generator now reaches into the instance instead of JSWebAssemblyCodeBlock. - Move more CodeBlock things. Compilation completion is now marked by its own atomic<bool> flag instead of a nullptr plan: that required using a lock, and was causing a deadlock in stack-trace.js because before my changes JSWebAssemblyCodeBlock did its own completion checking separately from Wasm::CodeBlock, without getting the lock. Now that everything points to Wasm::CodeBlock and there's no cached completion marker, the lock was being acquired in a sanity-check assertion. - Embedder -> Wasm wrappers are now generated through a function that's passed in at compilation time, instead of being hard-coded as a JS -> Wasm wrapper. - WasmMemory doens't need to know about fault handling thunks. Only the IR generator should know, and should make sure that the exception throwing thunk is generated if any memory is present (note: with signal handling not all of them generate an exception check). - Make exception throwing pluggable: instead of having a hard-coded JS-specific lambda we now have a regular C++ function being called from JIT code when a WebAssembly exception is thrown. This allows any embedder to get called as they wish. For now a process can only have a single of these functions (i.e. only one embedder per process) because the trap handler is a singleton. That can be fixed in in #177475. - Create WasmEmbedder.h where all embedder plugging will live. - Split up JSWebAssemblyTable into Wasm::Table which is refcounted. JSWebAssemblyTable now only contains the JS functions in the table, and Wasm::Table is what's used by the JIT code to lookup where to call and do the instance check (for context switch). Note that this creates an extra allocation for all the instances in Wasm::Table, and in exchange removes an indirection in JIT code because the instance used to be obtained off of the JS function. Also note that it's the embedder than keeps the instances alive, not Wasm::Table (which holds a dumb pointer to the instance), because doing otherwise would cause reference cycles. - Add WasmInstance. It doesn't do much for now, owns globals. - JSWebAssembly instance now doesn't just contain the imported functions as JSObjects, it also has the corresponding import's instance and wasm entrypoint. This triples the space allocated per instance's imported function, but there shouldn't be that many imports. This has two upsides: it creates smaller and faster code, and makes is easier to disassociate embedder-specific things from embedder-neutral things. The small / faster win is in two places: B3 IR generator only needs offsetOfImportFunction for the call opcode (when the called index is an import) to know whether the import is wasm->wasm or wasm->embedder (this isn't known at compile-time because it's dependent on the import object), this is now done by seeing if that import function has an associated target instance (only wasm->wasm does); the other place is wasmBinding which uses offsetOfImportFunction to figure out the wasm->wasm target instance, and then gets WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation to do a tail call. The disassociation comes because the target instance can be Wasm::Instance once we change what the Context is, and WasmEntrypointLoadLocation is already embedder-independent. As a next step I can move this tail allocation from JSWebAssemblyInstance to Wasm::Instance, and leave importFunction in as an opaque pointer which is embedder-specific, and in JS will remain WriteBarrier<JSObject>. - Rename VMEntryFrame to EntryFrame, and in many places pass a pointer to it around instead of VM. This is a first step in allowing entry frames which aren't stored on VM, but which are instead stored in an embedder-specific location. That change won't really affect JS except through code churn, but will allow WebAssembly to use some machinery in a generic manner without having a VM. * JavaScriptCore.xcodeproj/project.pbxproj: * Sources.txt: * bytecode/PolymorphicAccess.cpp: (JSC::AccessGenerationState::emitExplicitExceptionHandler): * debugger/Debugger.cpp: (JSC::Debugger::stepOutOfFunction): (JSC::Debugger::returnEvent): (JSC::Debugger::unwindEvent): (JSC::Debugger::didExecuteProgram): * dfg/DFGJITCompiler.cpp: (JSC::DFG::JITCompiler::compileExceptionHandlers): * dfg/DFGOSREntry.cpp: (JSC::DFG::prepareOSREntry): * dfg/DFGOSRExit.cpp: (JSC::DFG::OSRExit::compileOSRExit): (JSC::DFG::OSRExit::compileExit): * dfg/DFGThunks.cpp: (JSC::DFG::osrEntryThunkGenerator): * ftl/FTLCompile.cpp: (JSC::FTL::compile): * ftl/FTLLink.cpp: (JSC::FTL::link): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::lower): * ftl/FTLOSRExitCompiler.cpp: (JSC::FTL::compileStub): * interpreter/CallFrame.cpp: (JSC::CallFrame::wasmAwareLexicalGlobalObject): (JSC::CallFrame::callerFrame): (JSC::CallFrame::unsafeCallerFrame): * interpreter/CallFrame.h: (JSC::ExecState::callerFrame const): (JSC::ExecState::callerFrameOrEntryFrame const): (JSC::ExecState::unsafeCallerFrameOrEntryFrame const): * interpreter/FrameTracers.h: (JSC::NativeCallFrameTracer::NativeCallFrameTracer): (JSC::NativeCallFrameTracerWithRestore::NativeCallFrameTracerWithRestore): (JSC::NativeCallFrameTracerWithRestore::~NativeCallFrameTracerWithRestore): * interpreter/Interpreter.cpp: (JSC::UnwindFunctor::operator() const): (JSC::UnwindFunctor::copyCalleeSavesToEntryFrameCalleeSavesBuffer const): (JSC::Interpreter::unwind): * interpreter/StackVisitor.cpp: (JSC::StackVisitor::StackVisitor): (JSC::StackVisitor::gotoNextFrame): (JSC::StackVisitor::readNonInlinedFrame): (JSC::StackVisitor::Frame::dump const): * interpreter/StackVisitor.h: (JSC::StackVisitor::Frame::callerIsEntryFrame const): * interpreter/VMEntryRecord.h: (JSC::VMEntryRecord::prevTopEntryFrame): (JSC::VMEntryRecord::unsafePrevTopEntryFrame): (JSC::EntryFrame::vmEntryRecordOffset): * jit/AssemblyHelpers.cpp: (JSC::AssemblyHelpers::restoreCalleeSavesFromEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::loadWasmContextInstance): (JSC::AssemblyHelpers::storeWasmContextInstance): (JSC::AssemblyHelpers::loadWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::storeWasmContextInstanceNeedsMacroScratchRegister): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBufferImpl): * jit/AssemblyHelpers.h: (JSC::AssemblyHelpers::copyCalleeSavesToVMEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesToEntryFrameCalleeSavesBuffer): (JSC::AssemblyHelpers::copyCalleeSavesFromFrameOrRegisterToEntryFrameCalleeSavesBuffer): * jit/JIT.cpp: (JSC::JIT::emitEnterOptimizationCheck): (JSC::JIT::privateCompileExceptionHandlers): * jit/JITExceptions.cpp: (JSC::genericUnwind): * jit/JITOpcodes.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): (JSC::JIT::emitSlow_op_loop_hint): * jit/JITOpcodes32_64.cpp: (JSC::JIT::emit_op_throw): (JSC::JIT::emit_op_catch): * jit/JITOperations.cpp: * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromCallSlowPathGenerator): (JSC::nativeForGenerator): * jsc.cpp: (functionDumpCallFrame): * llint/LLIntSlowPaths.cpp: (JSC::LLInt::LLINT_SLOW_PATH_DECL): * llint/LLIntThunks.cpp: (JSC::vmEntryRecord): * llint/LowLevelInterpreter.asm: * llint/LowLevelInterpreter32_64.asm: * llint/LowLevelInterpreter64.asm: * runtime/Options.cpp: (JSC::recomputeDependentOptions): * runtime/Options.h: * runtime/SamplingProfiler.cpp: (JSC::FrameWalker::FrameWalker): (JSC::FrameWalker::advanceToParentFrame): (JSC::SamplingProfiler::processUnverifiedStackTraces): * runtime/ThrowScope.cpp: (JSC::ThrowScope::~ThrowScope): * runtime/VM.cpp: (JSC::VM::VM): (JSC::VM::~VM): * runtime/VM.h: (JSC::VM::topEntryFrameOffset): * runtime/VMTraps.cpp: (JSC::isSaneFrame): (JSC::VMTraps::tryInstallTrapBreakpoints): (JSC::VMTraps::invalidateCodeBlocksOnStack): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::restoreWasmContextInstance): (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): (JSC::Wasm::B3IRGenerator::addGrowMemory): (JSC::Wasm::B3IRGenerator::addCurrentMemory): (JSC::Wasm::B3IRGenerator::addCall): (JSC::Wasm::B3IRGenerator::addCallIndirect): (JSC::Wasm::parseAndCompile): * wasm/WasmB3IRGenerator.h: * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::BBQPlan): (JSC::Wasm::BBQPlan::compileFunctions): (JSC::Wasm::BBQPlan::complete): * wasm/WasmBBQPlan.h: * wasm/WasmBBQPlanInlines.h: (JSC::Wasm::BBQPlan::initializeCallees): * wasm/WasmBinding.cpp: (JSC::Wasm::wasmToWasm): * wasm/WasmBinding.h: * wasm/WasmCodeBlock.cpp: (JSC::Wasm::CodeBlock::create): (JSC::Wasm::CodeBlock::CodeBlock): (JSC::Wasm::CodeBlock::compileAsync): (JSC::Wasm::CodeBlock::setCompilationFinished): * wasm/WasmCodeBlock.h: (JSC::Wasm::CodeBlock::offsetOfImportStubs): (JSC::Wasm::CodeBlock::allocationSize): (JSC::Wasm::CodeBlock::importWasmToEmbedderStub): (JSC::Wasm::CodeBlock::offsetOfImportWasmToEmbedderStub): (JSC::Wasm::CodeBlock::wasmToJSCallStubForImport): (JSC::Wasm::CodeBlock::compilationFinished): (JSC::Wasm::CodeBlock::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::Wasm::CodeBlock::wasmEntrypointCalleeFromFunctionIndexSpace): * wasm/WasmContext.cpp: (JSC::Wasm::Context::useFastTLS): (JSC::Wasm::Context::load const): (JSC::Wasm::Context::store): * wasm/WasmContext.h: * wasm/WasmEmbedder.h: Copied from Source/JavaScriptCore/wasm/WasmContext.h. * wasm/WasmFaultSignalHandler.cpp: * wasm/WasmFaultSignalHandler.h: * wasm/WasmFormat.h: * wasm/WasmInstance.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::Instance::Instance): (JSC::Wasm::Instance::~Instance): (JSC::Wasm::Instance::extraMemoryAllocated const): * wasm/WasmInstance.h: Added. (JSC::Wasm::Instance::create): (JSC::Wasm::Instance::finalizeCreation): (JSC::Wasm::Instance::module): (JSC::Wasm::Instance::codeBlock): (JSC::Wasm::Instance::memory): (JSC::Wasm::Instance::table): (JSC::Wasm::Instance::loadI32Global const): (JSC::Wasm::Instance::loadI64Global const): (JSC::Wasm::Instance::loadF32Global const): (JSC::Wasm::Instance::loadF64Global const): (JSC::Wasm::Instance::setGlobal): (JSC::Wasm::Instance::offsetOfCachedStackLimit): (JSC::Wasm::Instance::cachedStackLimit const): (JSC::Wasm::Instance::setCachedStackLimit): * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::create): (JSC::Wasm::Memory::~Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::offsetOfSize): * wasm/WasmMemoryInformation.cpp: (JSC::Wasm::PinnedRegisterInfo::get): (JSC::Wasm::PinnedRegisterInfo::PinnedRegisterInfo): * wasm/WasmMemoryInformation.h: (JSC::Wasm::PinnedRegisterInfo::toSave const): * wasm/WasmMemoryMode.cpp: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. (JSC::Wasm::makeString): * wasm/WasmMemoryMode.h: Copied from Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h. * wasm/WasmModule.cpp: (JSC::Wasm::makeValidationCallback): (JSC::Wasm::Module::validateSync): (JSC::Wasm::Module::validateAsync): (JSC::Wasm::Module::getOrCreateCodeBlock): (JSC::Wasm::Module::compileSync): (JSC::Wasm::Module::compileAsync): * wasm/WasmModule.h: * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseTableHelper): * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::OMGPlan): (JSC::Wasm::OMGPlan::runForIndex): * wasm/WasmOMGPlan.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::isValid const): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::runCompletionTasks): (JSC::Wasm::Plan::addCompletionTask): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): * wasm/WasmPlan.h: (JSC::Wasm::Plan::dontFinalize): * wasm/WasmSignature.cpp: * wasm/WasmSignature.h: * wasm/WasmTable.cpp: Added. (JSC::Wasm::Table::create): (JSC::Wasm::Table::~Table): (JSC::Wasm::Table::Table): (JSC::Wasm::Table::grow): (JSC::Wasm::Table::clearFunction): (JSC::Wasm::Table::setFunction): * wasm/WasmTable.h: Copied from Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h. (JSC::Wasm::Table::maximum const): (JSC::Wasm::Table::size const): (JSC::Wasm::Table::offsetOfSize): (JSC::Wasm::Table::offsetOfFunctions): (JSC::Wasm::Table::offsetOfInstances): (JSC::Wasm::Table::isValidSize): * wasm/WasmThunks.cpp: (JSC::Wasm::throwExceptionFromWasmThunkGenerator): (JSC::Wasm::triggerOMGTierUpThunkGenerator): (JSC::Wasm::Thunks::setThrowWasmException): (JSC::Wasm::Thunks::throwWasmException): * wasm/WasmThunks.h: * wasm/WasmWorklist.cpp: (JSC::Wasm::Worklist::stopAllPlansForContext): * wasm/WasmWorklist.h: * wasm/js/JSToWasm.cpp: Added. (JSC::Wasm::createJSToWasmWrapper): * wasm/js/JSToWasm.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/JSWebAssembly.cpp: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.cpp. * wasm/js/JSWebAssembly.h: Renamed from Source/JavaScriptCore/wasm/JSWebAssembly.h. * wasm/js/JSWebAssemblyCodeBlock.cpp: (JSC::JSWebAssemblyCodeBlock::create): (JSC::JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock): * wasm/js/JSWebAssemblyCodeBlock.h: * wasm/js/JSWebAssemblyInstance.cpp: (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): (JSC::JSWebAssemblyInstance::finishCreation): (JSC::JSWebAssemblyInstance::visitChildren): (JSC::JSWebAssemblyInstance::finalizeCreation): (JSC::JSWebAssemblyInstance::create): * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::instance): (JSC::JSWebAssemblyInstance::context const): (JSC::JSWebAssemblyInstance::table): (JSC::JSWebAssemblyInstance::webAssemblyToJSCallee): (JSC::JSWebAssemblyInstance::setMemory): (JSC::JSWebAssemblyInstance::offsetOfTail): (JSC::JSWebAssemblyInstance::importFunctionInfo): (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): (JSC::JSWebAssemblyInstance::offsetOfImportFunction): (JSC::JSWebAssemblyInstance::importFunction): (JSC::JSWebAssemblyInstance::internalMemory): (JSC::JSWebAssemblyInstance::wasmCodeBlock const): (JSC::JSWebAssemblyInstance::offsetOfWasmTable): (JSC::JSWebAssemblyInstance::offsetOfCallee): (JSC::JSWebAssemblyInstance::offsetOfGlobals): (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): (JSC::JSWebAssemblyInstance::cachedStackLimit const): (JSC::JSWebAssemblyInstance::setCachedStackLimit): (JSC::JSWebAssemblyInstance::wasmMemory): (JSC::JSWebAssemblyInstance::wasmModule): (JSC::JSWebAssemblyInstance::allocationSize): (JSC::JSWebAssemblyInstance::module const): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::create): (JSC::JSWebAssemblyMemory::adopt): (JSC::JSWebAssemblyMemory::JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): (JSC::JSWebAssemblyMemory::growSuccessCallback): * wasm/js/JSWebAssemblyMemory.h: * wasm/js/JSWebAssemblyModule.cpp: (JSC::JSWebAssemblyModule::moduleInformation const): (JSC::JSWebAssemblyModule::exportSymbolTable const): (JSC::JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace const): (JSC::JSWebAssemblyModule::callee const): (JSC::JSWebAssemblyModule::codeBlock): (JSC::JSWebAssemblyModule::module): * wasm/js/JSWebAssemblyModule.h: * wasm/js/JSWebAssemblyTable.cpp: (JSC::JSWebAssemblyTable::create): (JSC::JSWebAssemblyTable::JSWebAssemblyTable): (JSC::JSWebAssemblyTable::visitChildren): (JSC::JSWebAssemblyTable::grow): (JSC::JSWebAssemblyTable::getFunction): (JSC::JSWebAssemblyTable::clearFunction): (JSC::JSWebAssemblyTable::setFunction): * wasm/js/JSWebAssemblyTable.h: (JSC::JSWebAssemblyTable::isValidSize): (JSC::JSWebAssemblyTable::maximum const): (JSC::JSWebAssemblyTable::size const): (JSC::JSWebAssemblyTable::table): * wasm/js/WasmToJS.cpp: Copied from Source/JavaScriptCore/wasm/WasmBinding.cpp. (JSC::Wasm::materializeImportJSCell): (JSC::Wasm::wasmToJS): (JSC::Wasm::wasmToJSException): * wasm/js/WasmToJS.h: Copied from Source/JavaScriptCore/wasm/WasmBinding.h. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): (JSC::WebAssemblyModuleConstructor::createModule): * wasm/js/WebAssemblyModuleConstructor.h: * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/js/WebAssemblyPrototype.cpp: (JSC::webAssemblyCompileFunc): (JSC::instantiate): (JSC::compileAndInstantiate): (JSC::webAssemblyValidateFunc): * wasm/js/WebAssemblyTableConstructor.cpp: (JSC::constructJSWebAssemblyTable): * wasm/js/WebAssemblyWrapperFunction.cpp: (JSC::WebAssemblyWrapperFunction::create): Source/WebCore: * ForwardingHeaders/wasm/WasmModule.h: Added. This used to be included in JSWebAssemblyModule.h. * bindings/js/SerializedScriptValue.cpp: Update postMessage code according to C++ API changes. Canonical link: https://commits.webkit.org/194750@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223738 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-20 02:23:29 +00:00
};
} } // namespace JSC::Wasm
#endif // ENABLE(WEBASSEMBLY)