Ignore:
Timestamp:
Jan 13, 2022, 6:40:08 PM (3 years ago)
Author:
[email protected]
Message:

Link Wasm code on the same thread that JITs
https://bugs.webkit.org/show_bug.cgi?id=235201

Reviewed by Yusuke Suzuki and Mark Lam.

This is preparing us for the changes that'll be needed by
https://bugs.webkit.org/show_bug.cgi?id=235192.

It should also be a small perf improvement, as we're now linking
in parallel instead of doing it after all compilations have finished.

  • wasm/WasmB3IRGenerator.cpp:

(JSC::Wasm::parseAndCompileB3):

  • wasm/WasmBBQPlan.cpp:

(JSC::Wasm::BBQPlan::prepareImpl):
(JSC::Wasm::BBQPlan::compileFunction):
(JSC::Wasm::BBQPlan::didCompleteCompilation):
(JSC::Wasm::BBQPlan::initializeCallees):

  • wasm/WasmBBQPlan.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/wasm/WasmBBQPlan.cpp

    r287864 r288002  
    6464    const auto& functions = m_moduleInformation->functions;
    6565    if (!tryReserveCapacity(m_wasmInternalFunctions, functions.size(), " WebAssembly functions")
     66        || !tryReserveCapacity(m_wasmInternalFunctionLinkBuffers, functions.size(), " compilation contexts")
    6667        || !tryReserveCapacity(m_compilationContexts, functions.size(), " compilation contexts")
    6768        || !tryReserveCapacity(m_tierUpCounts, functions.size(), " tier-up counts")
     
    7071
    7172    m_wasmInternalFunctions.resize(functions.size());
     73    m_wasmInternalFunctionLinkBuffers.resize(functions.size());
    7274    m_exceptionHandlerLocations.resize(functions.size());
    7375    m_compilationContexts.resize(functions.size());
     
    183185
    184186    m_wasmInternalFunctions[functionIndex] = compileFunction(functionIndex, m_compilationContexts[functionIndex], m_unlinkedWasmToWasmCalls[functionIndex], m_tierUpCounts[functionIndex].get());
     187    {
     188        auto linkBuffer = makeUnique<LinkBuffer>(*m_compilationContexts[functionIndex].wasmEntrypointJIT, nullptr, LinkBuffer::Profile::Wasm, JITCompilationCanFail);
     189        if (linkBuffer->isValid())
     190            m_wasmInternalFunctionLinkBuffers[functionIndex] = WTFMove(linkBuffer);
     191    }
    185192
    186193    if (m_exportedFunctionIndices.contains(functionIndex) || m_moduleInformation->referencedFunctions().contains(functionIndex)) {
     
    188195        SignatureIndex signatureIndex = m_moduleInformation->internalFunctionSignatureIndices[functionIndex];
    189196        const Signature& signature = SignatureInformation::get(signatureIndex);
    190         auto result = m_embedderToWasmInternalFunctions.add(functionIndex, createJSToWasmWrapper(*m_compilationContexts[functionIndex].embedderEntrypointJIT, signature, &m_unlinkedWasmToWasmCalls[functionIndex], m_moduleInformation.get(), m_mode, functionIndex));
     197
     198        auto embedderToWasmInternalFunction = createJSToWasmWrapper(*m_compilationContexts[functionIndex].embedderEntrypointJIT, signature, &m_unlinkedWasmToWasmCalls[functionIndex], m_moduleInformation.get(), m_mode, functionIndex);
     199        auto linkBuffer = makeUnique<LinkBuffer>(*m_compilationContexts[functionIndex].embedderEntrypointJIT, nullptr, LinkBuffer::Profile::Wasm, JITCompilationCanFail);
     200
     201        auto result = m_embedderToWasmInternalFunctions.add(functionIndex, std::pair { WTFMove(linkBuffer), WTFMove(embedderToWasmInternalFunction) });
    191202        ASSERT_UNUSED(result, result.isNewEntry);
    192203    }
     
    239250        {
    240251            InternalFunction* function = m_wasmInternalFunctions[functionIndex].get();
    241             LinkBuffer linkBuffer(*context.wasmEntrypointJIT, nullptr, LinkBuffer::Profile::Wasm, JITCompilationCanFail);
    242             if (UNLIKELY(linkBuffer.didFailToAllocate())) {
     252            if (!m_wasmInternalFunctionLinkBuffers[functionIndex]) {
    243253                Base::fail(makeString("Out of executable memory in function at index ", String::number(functionIndex)));
    244254                return;
    245255            }
     256           
     257            auto& linkBuffer = *m_wasmInternalFunctionLinkBuffers[functionIndex];
    246258
    247259            computeExceptionHandlerAndLoopEntrypointLocations(m_exceptionHandlerLocations[functionIndex], m_allLoopEntrypoints[functionIndex], function, context, linkBuffer);
     
    254266        }
    255267
    256         if (const auto& embedderToWasmInternalFunction = m_embedderToWasmInternalFunctions.get(functionIndex)) {
    257             LinkBuffer linkBuffer(*context.embedderEntrypointJIT, nullptr, LinkBuffer::Profile::Wasm, JITCompilationCanFail);
    258             if (UNLIKELY(linkBuffer.didFailToAllocate())) {
    259                 Base::fail(makeString("Out of executable memory in function entrypoint at index ", String::number(functionIndex)));
    260                 return;
     268        {
     269            auto iter = m_embedderToWasmInternalFunctions.find(functionIndex);
     270            if (iter != m_embedderToWasmInternalFunctions.end()) {
     271                LinkBuffer& linkBuffer = *iter->value.first;
     272                const auto& embedderToWasmInternalFunction = iter->value.second;
     273
     274                if (linkBuffer.didFailToAllocate()) {
     275                    Base::fail(makeString("Out of executable memory in function entrypoint at index ", String::number(functionIndex)));
     276                    return;
     277                }
     278
     279                embedderToWasmInternalFunction->entrypoint.compilation = makeUnique<Compilation>(
     280                    FINALIZE_CODE(linkBuffer, JITCompilationPtrTag, "Embedder->WebAssembly entrypoint[%i] %s name %s", functionIndex, signature.toString().ascii().data(), makeString(IndexOrName(functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace))).ascii().data()),
     281                    nullptr);
    261282            }
    262 
    263             embedderToWasmInternalFunction->entrypoint.compilation = makeUnique<Compilation>(
    264                 FINALIZE_CODE(linkBuffer, JITCompilationPtrTag, "Embedder->WebAssembly entrypoint[%i] %s name %s", functionIndex, signature.toString().ascii().data(), makeString(IndexOrName(functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace))).ascii().data()),
    265                 nullptr);
    266283        }
    267284    }
     
    286303
    287304        RefPtr<EmbedderEntrypointCallee> embedderEntrypointCallee;
    288         if (auto embedderToWasmFunction = m_embedderToWasmInternalFunctions.get(internalFunctionIndex)) {
    289             embedderEntrypointCallee = EmbedderEntrypointCallee::create(WTFMove(embedderToWasmFunction->entrypoint));
    290             for (auto& moveLocation : embedderToWasmFunction->calleeMoveLocations)
    291                 MacroAssembler::repatchPointer(moveLocation, CalleeBits::boxWasm(embedderEntrypointCallee.get()));
     305        {
     306            auto iter = m_embedderToWasmInternalFunctions.find(internalFunctionIndex);
     307            if (iter != m_embedderToWasmInternalFunctions.end()) {
     308                const auto& embedderToWasmFunction = iter->value.second;
     309                embedderEntrypointCallee = EmbedderEntrypointCallee::create(WTFMove(embedderToWasmFunction->entrypoint));
     310                for (auto& moveLocation : embedderToWasmFunction->calleeMoveLocations)
     311                    MacroAssembler::repatchPointer(moveLocation, CalleeBits::boxWasm(embedderEntrypointCallee.get()));
     312            }
    292313        }
    293314
Note: See TracChangeset for help on using the changeset viewer.