Skip to content
Permalink
Browse files
WebAssembly: no VM / JS version of everything but Instance
https://bugs.webkit.org/show_bug.cgi?id=177473

Reviewed by Filip Pizlo.

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 Wasm::CodeBlock'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 isn't adding any indirection to the generated code because
    the B3 IR generator now reaches for Wasm::CodeBlock 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.

Source/WTF:

* wtf/StdLibExtras.h:
(WTF::default_construct_at): this makes code in WasmTable much
more readable, and is generally useful for generic code


Canonical link: https://commits.webkit.org/194072@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222791 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
jfbastien committed Oct 3, 2017
1 parent d68ea0f commit 26ecac57e5564f3f60f9d513b0219571bc58555e
Showing with 3,169 additions and 1,746 deletions.
  1. +16 −0 JSTests/ChangeLog
  2. +1 −1 JSTests/wasm/js-api/memory-grow.js
  3. +2 −2 JSTests/wasm/js-api/table.js
  4. +458 −0 Source/JavaScriptCore/ChangeLog
  5. +81 −7 Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
  6. +11 −1 Source/JavaScriptCore/Sources.txt
  7. +1 −1 Source/JavaScriptCore/bytecode/PolymorphicAccess.cpp
  8. +9 −9 Source/JavaScriptCore/debugger/Debugger.cpp
  9. +2 −2 Source/JavaScriptCore/dfg/DFGJITCompiler.cpp
  10. +2 −2 Source/JavaScriptCore/dfg/DFGOSREntry.cpp
  11. +3 −3 Source/JavaScriptCore/dfg/DFGOSRExit.cpp
  12. +1 −1 Source/JavaScriptCore/dfg/DFGThunks.cpp
  13. +1 −1 Source/JavaScriptCore/ftl/FTLCompile.cpp
  14. +2 −2 Source/JavaScriptCore/ftl/FTLLink.cpp
  15. +1 −1 Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp
  16. +4 −4 Source/JavaScriptCore/ftl/FTLOSRExitCompiler.cpp
  17. +13 −12 Source/JavaScriptCore/interpreter/CallFrame.cpp
  18. +5 −5 Source/JavaScriptCore/interpreter/CallFrame.h
  19. +8 −8 Source/JavaScriptCore/interpreter/FrameTracers.h
  20. +5 −5 Source/JavaScriptCore/interpreter/Interpreter.cpp
  21. +13 −13 Source/JavaScriptCore/interpreter/StackVisitor.cpp
  22. +5 −6 Source/JavaScriptCore/interpreter/StackVisitor.h
  23. +10 −10 Source/JavaScriptCore/interpreter/VMEntryRecord.h
  24. +16 −16 Source/JavaScriptCore/jit/AssemblyHelpers.cpp
  25. +24 −24 Source/JavaScriptCore/jit/AssemblyHelpers.h
  26. +3 −3 Source/JavaScriptCore/jit/JIT.cpp
  27. +4 −4 Source/JavaScriptCore/jit/JITExceptions.cpp
  28. +3 −3 Source/JavaScriptCore/jit/JITOpcodes.cpp
  29. +3 −3 Source/JavaScriptCore/jit/JITOpcodes32_64.cpp
  30. +16 −16 Source/JavaScriptCore/jit/JITOperations.cpp
  31. +2 −2 Source/JavaScriptCore/jit/ThunkGenerators.cpp
  32. +2 −2 Source/JavaScriptCore/jsc.cpp
  33. +4 −4 Source/JavaScriptCore/llint/LLIntSlowPaths.cpp
  34. +2 −2 Source/JavaScriptCore/llint/LLIntThunks.cpp
  35. +3 −3 Source/JavaScriptCore/llint/LowLevelInterpreter.asm
  36. +9 −9 Source/JavaScriptCore/llint/LowLevelInterpreter32_64.asm
  37. +9 −10 Source/JavaScriptCore/llint/LowLevelInterpreter64.asm
  38. +1 −1 Source/JavaScriptCore/runtime/Options.cpp
  39. +1 −2 Source/JavaScriptCore/runtime/Options.h
  40. +4 −4 Source/JavaScriptCore/runtime/SamplingProfiler.cpp
  41. +4 −4 Source/JavaScriptCore/runtime/ThrowScope.cpp
  42. +2 −2 Source/JavaScriptCore/runtime/VM.cpp
  43. +8 −6 Source/JavaScriptCore/runtime/VM.h
  44. +9 −9 Source/JavaScriptCore/runtime/VMTraps.cpp
  45. +100 −281 Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp
  46. +2 −3 Source/JavaScriptCore/wasm/WasmB3IRGenerator.h
  47. +10 −12 Source/JavaScriptCore/wasm/WasmBBQPlan.cpp
  48. +6 −7 Source/JavaScriptCore/wasm/WasmBBQPlan.h
  49. +5 −5 Source/JavaScriptCore/wasm/WasmBBQPlanInlines.h
  50. +9 −593 Source/JavaScriptCore/wasm/WasmBinding.cpp
  51. +1 −4 Source/JavaScriptCore/wasm/WasmBinding.h
  52. +28 −11 Source/JavaScriptCore/wasm/WasmCodeBlock.cpp
  53. +37 −9 Source/JavaScriptCore/wasm/WasmCodeBlock.h
  54. +22 −11 Source/JavaScriptCore/wasm/WasmContext.cpp
  55. +7 −24 Source/JavaScriptCore/wasm/WasmContext.h
  56. +58 −0 Source/JavaScriptCore/wasm/WasmEmbedder.h
  57. +1 −1 Source/JavaScriptCore/wasm/WasmFaultSignalHandler.cpp
  58. +0 −2 Source/JavaScriptCore/wasm/WasmFaultSignalHandler.h
  59. +3 −2 Source/JavaScriptCore/wasm/WasmFormat.h
  60. +58 −0 Source/JavaScriptCore/wasm/WasmInstance.cpp
  61. +87 −0 Source/JavaScriptCore/wasm/WasmInstance.h
  62. +93 −66 Source/JavaScriptCore/wasm/WasmMemory.cpp
  63. +27 −17 Source/JavaScriptCore/wasm/WasmMemory.h
  64. +7 −7 Source/JavaScriptCore/wasm/WasmMemoryInformation.cpp
  65. +4 −4 Source/JavaScriptCore/wasm/WasmMemoryInformation.h
  66. +47 −0 Source/JavaScriptCore/wasm/WasmMemoryMode.cpp
  67. +47 −0 Source/JavaScriptCore/wasm/WasmMemoryMode.h
  68. +13 −14 Source/JavaScriptCore/wasm/WasmModule.cpp
  69. +9 −7 Source/JavaScriptCore/wasm/WasmModule.h
  70. +1 −2 Source/JavaScriptCore/wasm/WasmModuleParser.cpp
  71. +48 −0 Source/JavaScriptCore/wasm/WasmNameSection.h
  72. +11 −10 Source/JavaScriptCore/wasm/WasmOMGPlan.cpp
  73. +5 −5 Source/JavaScriptCore/wasm/WasmOMGPlan.h
  74. +6 −1 Source/JavaScriptCore/wasm/WasmPageCount.h
  75. +20 −15 Source/JavaScriptCore/wasm/WasmPlan.cpp
  76. +15 −10 Source/JavaScriptCore/wasm/WasmPlan.h
  77. +2 −2 Source/JavaScriptCore/wasm/WasmSignature.cpp
  78. +2 −4 Source/JavaScriptCore/wasm/WasmSignature.h
  79. +122 −0 Source/JavaScriptCore/wasm/WasmTable.cpp
  80. +76 −0 Source/JavaScriptCore/wasm/WasmTable.h
  81. +22 −37 Source/JavaScriptCore/wasm/WasmThunks.cpp
  82. +5 −0 Source/JavaScriptCore/wasm/WasmThunks.h
  83. +4 −3 Source/JavaScriptCore/wasm/WasmWorklist.cpp
  84. +2 −8 Source/JavaScriptCore/wasm/WasmWorklist.h
  85. +227 −0 Source/JavaScriptCore/wasm/js/JSToWasm.cpp
  86. +48 −0 Source/JavaScriptCore/wasm/js/JSToWasm.h
  87. 0 Source/JavaScriptCore/wasm/{ → js}/JSWebAssembly.cpp
  88. +25 −25 Source/JavaScriptCore/wasm/{ → js}/JSWebAssembly.h
  89. +4 −9 Source/JavaScriptCore/wasm/js/JSWebAssemblyCodeBlock.cpp
  90. +2 −44 Source/JavaScriptCore/wasm/js/JSWebAssemblyCodeBlock.h
  91. +70 −48 Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp
  92. +53 −32 Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.h
  93. +36 −40 Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.cpp
  94. +5 −8 Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h
  95. +32 −0 Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.cpp
  96. +13 −12 Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.h
  97. +28 −47 Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.cpp
  98. +14 −29 Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h
  99. +655 −0 Source/JavaScriptCore/wasm/js/WasmToJS.cpp
  100. +49 −0 Source/JavaScriptCore/wasm/js/WasmToJS.h
  101. +13 −13 Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp
  102. +4 −2 Source/JavaScriptCore/wasm/js/WebAssemblyInstanceConstructor.cpp
  103. +9 −4 Source/JavaScriptCore/wasm/js/WebAssemblyMemoryConstructor.cpp
  104. +1 −2 Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp
  105. +11 −9 Source/JavaScriptCore/wasm/js/WebAssemblyModuleConstructor.cpp
  106. +4 −1 Source/JavaScriptCore/wasm/js/WebAssemblyModuleConstructor.h
  107. +11 −11 Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp
  108. +8 −6 Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.cpp
  109. +8 −1 Source/JavaScriptCore/wasm/js/WebAssemblyTableConstructor.cpp
  110. +1 −1 Source/JavaScriptCore/wasm/js/WebAssemblyWrapperFunction.cpp
  111. +11 −0 Source/WTF/ChangeLog
  112. +7 −0 Source/WTF/wtf/StdLibExtras.h
  113. +12 −0 Source/WebCore/ChangeLog
  114. +2 −0 Source/WebCore/ForwardingHeaders/wasm/WasmModule.h
  115. +1 −0 Source/WebCore/bindings/js/SerializedScriptValue.cpp
@@ -1,3 +1,19 @@
2017-10-03 JF Bastien <jfbastien@apple.com>

WebAssembly: no VM / JS version of everything but Instance
https://bugs.webkit.org/show_bug.cgi?id=177473

Reviewed by Filip Pizlo.

- 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):

2017-10-03 Ryan Haddad <ryanhaddad@apple.com>

Skip JSC test stress/regress-159779-2.js on debug.
@@ -45,7 +45,7 @@ for (let buffer of buffers) {
assertEq(buffer.byteLength, 2*64*1024);

// This shouldn't neuter the buffer since it fails.
assertThrows(() => memory.grow(1000), Error, "Out of memory");
assertThrows(() => memory.grow(1000), RangeError, "WebAssembly.Memory.grow would exceed the memory's declared maximum size");
assertEq(buffer.byteLength, 2*64*1024);
assertEq(memory.buffer, buffer);
}
@@ -166,8 +166,8 @@ function assertBadTableImport(tableDescription, message) {
"WebAssembly.Module doesn't parse at byte 29 / 32: resizable limits has a initial page count of 4294967295 which is greater than its maximum 4294967294 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
"WebAssembly.Module doesn't parse at byte 37 / 43: resizable limits has a initial page count of 4294967295 which is greater than its maximum 4294967294 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
[{initial: 2**31, element: "anyfunc"},
"WebAssembly.Module doesn't parse at byte 24 / 27: Table's initial page count of 2147483648 is invalid (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
"WebAssembly.Module doesn't parse at byte 32 / 38: Table's initial page count of 2147483648 is invalid (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
"WebAssembly.Module doesn't parse at byte 24 / 27: Table's initial page count of 2147483648 is too big, maximum 10000000 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')",
"WebAssembly.Module doesn't parse at byte 32 / 38: Table's initial page count of 2147483648 is too big, maximum 10000000 (evaluating 'new WebAssembly.Module(builder.WebAssembly().get())')"],
];

for (const d of badDescriptions) {

Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -935,20 +935,23 @@ tools/JSDollarVMPrototype.cpp
tools/SigillCrashAnalyzer.cpp
tools/VMInspector.cpp

wasm/JSWebAssembly.cpp
wasm/WasmB3IRGenerator.cpp
wasm/WasmBBQPlan.cpp
wasm/WasmBinding.cpp
wasm/WasmCallee.cpp
wasm/WasmCallingConvention.cpp
wasm/WasmCodeBlock.cpp
wasm/WasmContext.cpp
wasm/WasmEmbedder.h
wasm/WasmFaultSignalHandler.cpp
wasm/WasmFormat.cpp
wasm/WasmIndexOrName.cpp
wasm/WasmInstance.cpp
wasm/WasmInstance.h
wasm/WasmMachineThreads.cpp
wasm/WasmMemory.cpp
wasm/WasmMemoryInformation.cpp
wasm/WasmMemoryMode.cpp
wasm/WasmModule.cpp
wasm/WasmModuleInformation.cpp
wasm/WasmModuleParser.cpp
@@ -958,10 +961,15 @@ wasm/WasmOpcodeOrigin.cpp
wasm/WasmPageCount.cpp
wasm/WasmPlan.cpp
wasm/WasmSignature.cpp
wasm/WasmTable.cpp
wasm/WasmTable.h
wasm/WasmThunks.cpp
wasm/WasmValidate.cpp
wasm/WasmWorklist.cpp

wasm/js/JSToWasm.cpp
wasm/js/JSToWasm.h
wasm/js/JSWebAssembly.cpp
wasm/js/JSWebAssemblyCodeBlock.cpp
wasm/js/JSWebAssemblyCodeBlockSubspace.cpp
wasm/js/JSWebAssemblyCompileError.cpp
@@ -971,6 +979,8 @@ wasm/js/JSWebAssemblyMemory.cpp
wasm/js/JSWebAssemblyModule.cpp
wasm/js/JSWebAssemblyRuntimeError.cpp
wasm/js/JSWebAssemblyTable.cpp
wasm/js/WasmToJS.cpp
wasm/js/WasmToJS.h
wasm/js/WebAssemblyCompileErrorConstructor.cpp
wasm/js/WebAssemblyCompileErrorPrototype.cpp
wasm/js/WebAssemblyFunction.cpp
@@ -179,7 +179,7 @@ CallSiteIndex AccessGenerationState::originalCallSiteIndex() const { return stub
void AccessGenerationState::emitExplicitExceptionHandler()
{
restoreScratch();
jit->copyCalleeSavesToVMEntryFrameCalleeSavesBuffer(m_vm);
jit->copyCalleeSavesToEntryFrameCalleeSavesBuffer(m_vm.topEntryFrame);
if (needsToRestoreRegistersIfException()) {
// To the JIT that produces the original exception handling
// call site, they will expect the OSR exit to be arrived
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008, 2013, 2014, 2016 Apple Inc. All rights reserved.
* Copyright (C) 2008-2017 Apple Inc. All rights reserved.
* Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
*
@@ -652,8 +652,8 @@ void Debugger::stepOutOfFunction()
if (!m_isPaused)
return;

VMEntryFrame* topVMEntryFrame = m_vm.topVMEntryFrame;
m_pauseOnCallFrame = m_currentCallFrame ? m_currentCallFrame->callerFrame(topVMEntryFrame) : nullptr;
EntryFrame* topEntryFrame = m_vm.topEntryFrame;
m_pauseOnCallFrame = m_currentCallFrame ? m_currentCallFrame->callerFrame(topEntryFrame) : nullptr;
m_pauseOnStepOut = true;
setSteppingMode(SteppingModeEnabled);
notifyDoneProcessingDebuggerEvents();
@@ -831,8 +831,8 @@ void Debugger::returnEvent(CallFrame* callFrame)
if (!m_currentCallFrame)
return;

VMEntryFrame* topVMEntryFrame = m_vm.topVMEntryFrame;
CallFrame* callerFrame = m_currentCallFrame->callerFrame(topVMEntryFrame);
EntryFrame* topEntryFrame = m_vm.topEntryFrame;
CallFrame* callerFrame = m_currentCallFrame->callerFrame(topEntryFrame);

// Returning from a call, there was at least one expression on the statement we are returning to.
m_pastFirstExpressionInStatement = true;
@@ -856,8 +856,8 @@ void Debugger::unwindEvent(CallFrame* callFrame)
if (!m_currentCallFrame)
return;

VMEntryFrame* topVMEntryFrame = m_vm.topVMEntryFrame;
CallFrame* callerFrame = m_currentCallFrame->callerFrame(topVMEntryFrame);
EntryFrame* topEntryFrame = m_vm.topEntryFrame;
CallFrame* callerFrame = m_currentCallFrame->callerFrame(topEntryFrame);

// Treat stepping over an exception location like a step-out.
if (m_currentCallFrame == m_pauseOnCallFrame)
@@ -886,8 +886,8 @@ void Debugger::didExecuteProgram(CallFrame* callFrame)
if (!m_currentCallFrame)
return;

VMEntryFrame* topVMEntryFrame = m_vm.topVMEntryFrame;
CallFrame* callerFrame = m_currentCallFrame->callerFrame(topVMEntryFrame);
EntryFrame* topEntryFrame = m_vm.topEntryFrame;
CallFrame* callerFrame = m_currentCallFrame->callerFrame(topEntryFrame);

// Returning from a program, could be eval(), there was at least one expression on the statement we are returning to.
m_pastFirstExpressionInStatement = true;
@@ -140,7 +140,7 @@ void JITCompiler::compileExceptionHandlers()
if (!m_exceptionChecksWithCallFrameRollback.empty()) {
m_exceptionChecksWithCallFrameRollback.link(this);

copyCalleeSavesToVMEntryFrameCalleeSavesBuffer(*vm());
copyCalleeSavesToEntryFrameCalleeSavesBuffer(vm()->topEntryFrame);

// lookupExceptionHandlerFromCallerFrame is passed two arguments, the VM and the exec (the CallFrame*).
move(TrustedImmPtr(vm()), GPRInfo::argumentGPR0);
@@ -160,7 +160,7 @@ void JITCompiler::compileExceptionHandlers()
if (!m_exceptionChecks.empty()) {
m_exceptionChecks.link(this);

copyCalleeSavesToVMEntryFrameCalleeSavesBuffer(*vm());
copyCalleeSavesToEntryFrameCalleeSavesBuffer(vm()->topEntryFrame);

// lookupExceptionHandler is passed two arguments, the VM and the exec (the CallFrame*).
move(TrustedImmPtr(vm()), GPRInfo::argumentGPR0);
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2011, 2013-2016 Apple Inc. All rights reserved.
* Copyright (C) 2011-2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -317,7 +317,7 @@ void* prepareOSREntry(ExecState* exec, CodeBlock* codeBlock, unsigned bytecodeIn
RegisterSet dontSaveRegisters = RegisterSet(RegisterSet::stackRegisters(), RegisterSet::allFPRs());

unsigned registerCount = registerSaveLocations->size();
VMEntryRecord* record = vmEntryRecord(vm->topVMEntryFrame);
VMEntryRecord* record = vmEntryRecord(vm->topEntryFrame);
for (unsigned i = 0; i < registerCount; i++) {
RegisterAtOffset currentEntry = registerSaveLocations->at(i);
if (dontSaveRegisters.get(currentEntry.reg()))
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2011, 2013 Apple Inc. All rights reserved.
* Copyright (C) 2011-2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -185,7 +185,7 @@ void JIT_OPERATION OSRExit::compileOSRExit(ExecState* exec)
if (exit.m_kind == GenericUnwind) {
// We are acting as a defacto op_catch because we arrive here from genericUnwind().
// So, we must restore our call frame and stack pointer.
jit.restoreCalleeSavesFromVMEntryFrameCalleeSavesBuffer(*vm);
jit.restoreCalleeSavesFromEntryFrameCalleeSavesBuffer(vm->topEntryFrame);
jit.loadPtr(vm->addressOfCallFrameForCatch(), GPRInfo::callFrameRegister);
}
jit.addPtr(
@@ -537,7 +537,7 @@ void OSRExit::compileExit(CCallHelpers& jit, VM& vm, const OSRExit& exit, const
jit.emitMaterializeTagCheckRegisters();

if (exit.isExceptionHandler())
jit.copyCalleeSavesToVMEntryFrameCalleeSavesBuffer(vm);
jit.copyCalleeSavesToEntryFrameCalleeSavesBuffer(vm.topEntryFrame);

// Do all data format conversions and store the results into the stack.

@@ -135,7 +135,7 @@ MacroAssemblerCodeRef osrEntryThunkGenerator(VM* vm)
jit.abortWithReason(DFGUnreasonableOSREntryJumpDestination);

ok.link(&jit);
jit.restoreCalleeSavesFromVMEntryFrameCalleeSavesBuffer(*vm);
jit.restoreCalleeSavesFromEntryFrameCalleeSavesBuffer(vm->topEntryFrame);
jit.emitMaterializeTagCheckRegisters();

jit.jump(GPRInfo::regT1);
@@ -131,7 +131,7 @@ void compile(State& state, Safepoint::Result& safepointResult)

// Emit the exception handler.
*state.exceptionHandler = jit.label();
jit.copyCalleeSavesToVMEntryFrameCalleeSavesBuffer(vm);
jit.copyCalleeSavesToEntryFrameCalleeSavesBuffer(vm.topEntryFrame);
jit.move(MacroAssembler::TrustedImmPtr(&vm), GPRInfo::argumentGPR0);
jit.move(GPRInfo::callFrameRegister, GPRInfo::argumentGPR1);
CCallHelpers::Call call = jit.call();
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
* Copyright (C) 2013-2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -143,7 +143,7 @@ void link(State& state)
CCallHelpers::Call callArityCheck = jit.call();

auto noException = jit.branch32(CCallHelpers::GreaterThanOrEqual, GPRInfo::returnValueGPR, CCallHelpers::TrustedImm32(0));
jit.copyCalleeSavesToVMEntryFrameCalleeSavesBuffer(vm);
jit.copyCalleeSavesToEntryFrameCalleeSavesBuffer(vm.topEntryFrame);
jit.move(CCallHelpers::TrustedImmPtr(&vm), GPRInfo::argumentGPR0);
jit.move(GPRInfo::callFrameRegister, GPRInfo::argumentGPR1);
CCallHelpers::Call callLookupExceptionHandlerFromCallerFrame = jit.call();
@@ -264,7 +264,7 @@ class LowerDFGToB3 {
jit.store32(
MacroAssembler::TrustedImm32(callSiteIndex.bits()),
CCallHelpers::tagFor(VirtualRegister(CallFrameSlot::argumentCount)));
jit.copyCalleeSavesToVMEntryFrameCalleeSavesBuffer(*vm);
jit.copyCalleeSavesToEntryFrameCalleeSavesBuffer(vm->topEntryFrame);

jit.move(GPRInfo::callFrameRegister, GPRInfo::argumentGPR0);
jit.move(CCallHelpers::TrustedImmPtr(jit.codeBlock()), GPRInfo::argumentGPR1);
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2016 Apple Inc. All rights reserved.
* Copyright (C) 2013-2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -186,7 +186,7 @@ static void compileStub(
// The first thing we need to do is restablish our frame in the case of an exception.
if (exit.isGenericUnwindHandler()) {
RELEASE_ASSERT(vm->callFrameForCatch); // The first time we hit this exit, like at all other times, this field should be non-null.
jit.restoreCalleeSavesFromVMEntryFrameCalleeSavesBuffer(*vm);
jit.restoreCalleeSavesFromEntryFrameCalleeSavesBuffer(vm->topEntryFrame);
jit.loadPtr(vm->addressOfCallFrameForCatch(), MacroAssembler::framePointerRegister);
jit.addPtr(CCallHelpers::TrustedImm32(codeBlock->stackPointerOffset() * sizeof(Register)),
MacroAssembler::framePointerRegister, CCallHelpers::stackPointerRegister);
@@ -412,8 +412,8 @@ static void compileStub(
RegisterAtOffsetList* vmCalleeSaves = VM::getAllCalleeSaveRegisterOffsets();
RegisterSet vmCalleeSavesToSkip = RegisterSet::stackRegisters();
if (exit.isExceptionHandler()) {
jit.loadPtr(&vm->topVMEntryFrame, GPRInfo::regT1);
jit.addPtr(CCallHelpers::TrustedImm32(VMEntryFrame::calleeSaveRegistersBufferOffset()), GPRInfo::regT1);
jit.loadPtr(&vm->topEntryFrame, GPRInfo::regT1);
jit.addPtr(CCallHelpers::TrustedImm32(EntryFrame::calleeSaveRegistersBufferOffset()), GPRInfo::regT1);
}

for (Reg reg = Reg::first(); reg <= Reg::last(); reg = reg.next()) {
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008, 2013-2014, 2016 Apple Inc. All Rights Reserved.
* Copyright (C) 2008-2017 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -30,6 +30,7 @@
#include "InlineCallFrame.h"
#include "Interpreter.h"
#include "JSCInlines.h"
#include "JSWebAssemblyInstance.h"
#include "VMEntryScope.h"
#include "WasmContext.h"
#include <wtf/StringPrintStream.h>
@@ -217,7 +218,7 @@ JSGlobalObject* CallFrame::wasmAwareLexicalGlobalObject(VM& vm)
#if ENABLE(WEBASSEMBLY)
if (!callee().isWasm())
return lexicalGlobalObject();
return Wasm::loadContext(vm)->globalObject();
return vm.wasmContext.load()->globalObject();
#else
UNUSED_PARAM(vm);
return lexicalGlobalObject();
@@ -237,24 +238,24 @@ bool CallFrame::isAnyWasmCallee()
return false;
}

CallFrame* CallFrame::callerFrame(VMEntryFrame*& currVMEntryFrame)
CallFrame* CallFrame::callerFrame(EntryFrame*& currEntryFrame)
{
if (callerFrameOrVMEntryFrame() == currVMEntryFrame) {
VMEntryRecord* currVMEntryRecord = vmEntryRecord(currVMEntryFrame);
currVMEntryFrame = currVMEntryRecord->prevTopVMEntryFrame();
if (callerFrameOrEntryFrame() == currEntryFrame) {
VMEntryRecord* currVMEntryRecord = vmEntryRecord(currEntryFrame);
currEntryFrame = currVMEntryRecord->prevTopEntryFrame();
return currVMEntryRecord->prevTopCallFrame();
}
return static_cast<CallFrame*>(callerFrameOrVMEntryFrame());
return static_cast<CallFrame*>(callerFrameOrEntryFrame());
}

SUPPRESS_ASAN CallFrame* CallFrame::unsafeCallerFrame(VMEntryFrame*& currVMEntryFrame)
SUPPRESS_ASAN CallFrame* CallFrame::unsafeCallerFrame(EntryFrame*& currEntryFrame)
{
if (unsafeCallerFrameOrVMEntryFrame() == currVMEntryFrame) {
VMEntryRecord* currVMEntryRecord = vmEntryRecord(currVMEntryFrame);
currVMEntryFrame = currVMEntryRecord->unsafePrevTopVMEntryFrame();
if (unsafeCallerFrameOrEntryFrame() == currEntryFrame) {
VMEntryRecord* currVMEntryRecord = vmEntryRecord(currEntryFrame);
currEntryFrame = currVMEntryRecord->unsafePrevTopEntryFrame();
return currVMEntryRecord->unsafePrevTopCallFrame();
}
return static_cast<CallFrame*>(unsafeCallerFrameOrVMEntryFrame());
return static_cast<CallFrame*>(unsafeCallerFrameOrEntryFrame());
}

SourceOrigin CallFrame::callerSourceOrigin()
@@ -141,12 +141,12 @@ namespace JSC {

CallFrame& operator=(const Register& r) { *static_cast<Register*>(this) = r; return *this; }

CallFrame* callerFrame() const { return static_cast<CallFrame*>(callerFrameOrVMEntryFrame()); }
void* callerFrameOrVMEntryFrame() const { return callerFrameAndPC().callerFrame; }
SUPPRESS_ASAN void* unsafeCallerFrameOrVMEntryFrame() const { return unsafeCallerFrameAndPC().callerFrame; }
CallFrame* callerFrame() const { return static_cast<CallFrame*>(callerFrameOrEntryFrame()); }
void* callerFrameOrEntryFrame() const { return callerFrameAndPC().callerFrame; }
SUPPRESS_ASAN void* unsafeCallerFrameOrEntryFrame() const { return unsafeCallerFrameAndPC().callerFrame; }

CallFrame* unsafeCallerFrame(VMEntryFrame*&);
JS_EXPORT_PRIVATE CallFrame* callerFrame(VMEntryFrame*&);
CallFrame* unsafeCallerFrame(EntryFrame*&);
JS_EXPORT_PRIVATE CallFrame* callerFrame(EntryFrame*&);

JS_EXPORT_PRIVATE SourceOrigin callerSourceOrigin();

0 comments on commit 26ecac5

Please sign in to comment.