Modified: trunk/Source/_javascript_Core/wasm/WasmBBQPlan.cpp (288001 => 288002)
--- trunk/Source/_javascript_Core/wasm/WasmBBQPlan.cpp 2022-01-14 01:57:40 UTC (rev 288001)
+++ trunk/Source/_javascript_Core/wasm/WasmBBQPlan.cpp 2022-01-14 02:40:08 UTC (rev 288002)
@@ -63,6 +63,7 @@
{
const auto& functions = m_moduleInformation->functions;
if (!tryReserveCapacity(m_wasmInternalFunctions, functions.size(), " WebAssembly functions")
+ || !tryReserveCapacity(m_wasmInternalFunctionLinkBuffers, functions.size(), " compilation contexts")
|| !tryReserveCapacity(m_compilationContexts, functions.size(), " compilation contexts")
|| !tryReserveCapacity(m_tierUpCounts, functions.size(), " tier-up counts")
|| !tryReserveCapacity(m_allLoopEntrypoints, functions.size(), " loop entrypoints"))
@@ -69,6 +70,7 @@
return false;
m_wasmInternalFunctions.resize(functions.size());
+ m_wasmInternalFunctionLinkBuffers.resize(functions.size());
m_exceptionHandlerLocations.resize(functions.size());
m_compilationContexts.resize(functions.size());
m_tierUpCounts.resize(functions.size());
@@ -182,12 +184,21 @@
m_tierUpCounts[functionIndex] = nullptr;
m_wasmInternalFunctions[functionIndex] = compileFunction(functionIndex, m_compilationContexts[functionIndex], m_unlinkedWasmToWasmCalls[functionIndex], m_tierUpCounts[functionIndex].get());
+ {
+ auto linkBuffer = makeUnique<LinkBuffer>(*m_compilationContexts[functionIndex].wasmEntrypointJIT, nullptr, LinkBuffer::Profile::Wasm, JITCompilationCanFail);
+ if (linkBuffer->isValid())
+ m_wasmInternalFunctionLinkBuffers[functionIndex] = WTFMove(linkBuffer);
+ }
if (m_exportedFunctionIndices.contains(functionIndex) || m_moduleInformation->referencedFunctions().contains(functionIndex)) {
Locker locker { m_lock };
SignatureIndex signatureIndex = m_moduleInformation->internalFunctionSignatureIndices[functionIndex];
const Signature& signature = SignatureInformation::get(signatureIndex);
- auto result = m_embedderToWasmInternalFunctions.add(functionIndex, createJSToWasmWrapper(*m_compilationContexts[functionIndex].embedderEntrypointJIT, signature, &m_unlinkedWasmToWasmCalls[functionIndex], m_moduleInformation.get(), m_mode, functionIndex));
+
+ auto embedderToWasmInternalFunction = createJSToWasmWrapper(*m_compilationContexts[functionIndex].embedderEntrypointJIT, signature, &m_unlinkedWasmToWasmCalls[functionIndex], m_moduleInformation.get(), m_mode, functionIndex);
+ auto linkBuffer = makeUnique<LinkBuffer>(*m_compilationContexts[functionIndex].embedderEntrypointJIT, nullptr, LinkBuffer::Profile::Wasm, JITCompilationCanFail);
+
+ auto result = m_embedderToWasmInternalFunctions.add(functionIndex, std::pair { WTFMove(linkBuffer), WTFMove(embedderToWasmInternalFunction) });
ASSERT_UNUSED(result, result.isNewEntry);
}
}
@@ -238,11 +249,12 @@
ASSERT(functionIndexSpace < m_moduleInformation->functionIndexSpaceSize());
{
InternalFunction* function = m_wasmInternalFunctions[functionIndex].get();
- LinkBuffer linkBuffer(*context.wasmEntrypointJIT, nullptr, LinkBuffer::Profile::Wasm, JITCompilationCanFail);
- if (UNLIKELY(linkBuffer.didFailToAllocate())) {
+ if (!m_wasmInternalFunctionLinkBuffers[functionIndex]) {
Base::fail(makeString("Out of executable memory in function at index ", String::number(functionIndex)));
return;
}
+
+ auto& linkBuffer = *m_wasmInternalFunctionLinkBuffers[functionIndex];
computeExceptionHandlerAndLoopEntrypointLocations(m_exceptionHandlerLocations[functionIndex], m_allLoopEntrypoints[functionIndex], function, context, linkBuffer);
@@ -253,16 +265,21 @@
WTFMove(context.wasmEntrypointByproducts));
}
- if (const auto& embedderToWasmInternalFunction = m_embedderToWasmInternalFunctions.get(functionIndex)) {
- LinkBuffer linkBuffer(*context.embedderEntrypointJIT, nullptr, LinkBuffer::Profile::Wasm, JITCompilationCanFail);
- if (UNLIKELY(linkBuffer.didFailToAllocate())) {
- Base::fail(makeString("Out of executable memory in function entrypoint at index ", String::number(functionIndex)));
- return;
+ {
+ auto iter = m_embedderToWasmInternalFunctions.find(functionIndex);
+ if (iter != m_embedderToWasmInternalFunctions.end()) {
+ LinkBuffer& linkBuffer = *iter->value.first;
+ const auto& embedderToWasmInternalFunction = iter->value.second;
+
+ if (linkBuffer.didFailToAllocate()) {
+ Base::fail(makeString("Out of executable memory in function entrypoint at index ", String::number(functionIndex)));
+ return;
+ }
+
+ embedderToWasmInternalFunction->entrypoint.compilation = makeUnique<Compilation>(
+ 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()),
+ nullptr);
}
-
- embedderToWasmInternalFunction->entrypoint.compilation = makeUnique<Compilation>(
- 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()),
- nullptr);
}
}
@@ -285,10 +302,14 @@
for (unsigned internalFunctionIndex = 0; internalFunctionIndex < m_wasmInternalFunctions.size(); ++internalFunctionIndex) {
RefPtr<EmbedderEntrypointCallee> embedderEntrypointCallee;
- if (auto embedderToWasmFunction = m_embedderToWasmInternalFunctions.get(internalFunctionIndex)) {
- embedderEntrypointCallee = EmbedderEntrypointCallee::create(WTFMove(embedderToWasmFunction->entrypoint));
- for (auto& moveLocation : embedderToWasmFunction->calleeMoveLocations)
- MacroAssembler::repatchPointer(moveLocation, CalleeBits::boxWasm(embedderEntrypointCallee.get()));
+ {
+ auto iter = m_embedderToWasmInternalFunctions.find(internalFunctionIndex);
+ if (iter != m_embedderToWasmInternalFunctions.end()) {
+ const auto& embedderToWasmFunction = iter->value.second;
+ embedderEntrypointCallee = EmbedderEntrypointCallee::create(WTFMove(embedderToWasmFunction->entrypoint));
+ for (auto& moveLocation : embedderToWasmFunction->calleeMoveLocations)
+ MacroAssembler::repatchPointer(moveLocation, CalleeBits::boxWasm(embedderEntrypointCallee.get()));
+ }
}
InternalFunction* function = m_wasmInternalFunctions[internalFunctionIndex].get();
Modified: trunk/Source/_javascript_Core/wasm/WasmBBQPlan.h (288001 => 288002)
--- trunk/Source/_javascript_Core/wasm/WasmBBQPlan.h 2022-01-14 01:57:40 UTC (rev 288001)
+++ trunk/Source/_javascript_Core/wasm/WasmBBQPlan.h 2022-01-14 02:40:08 UTC (rev 288002)
@@ -83,8 +83,9 @@
std::unique_ptr<InternalFunction> compileFunction(uint32_t functionIndex, CompilationContext&, Vector<UnlinkedWasmToWasmCall>&, TierUpCount*);
Vector<std::unique_ptr<InternalFunction>> m_wasmInternalFunctions;
+ Vector<std::unique_ptr<LinkBuffer>> m_wasmInternalFunctionLinkBuffers;
Vector<Vector<CodeLocationLabel<ExceptionHandlerPtrTag>>> m_exceptionHandlerLocations;
- HashMap<uint32_t, std::unique_ptr<InternalFunction>, DefaultHash<uint32_t>, WTF::UnsignedWithZeroKeyHashTraits<uint32_t>> m_embedderToWasmInternalFunctions;
+ HashMap<uint32_t, std::pair<std::unique_ptr<LinkBuffer>, std::unique_ptr<InternalFunction>>, DefaultHash<uint32_t>, WTF::UnsignedWithZeroKeyHashTraits<uint32_t>> m_embedderToWasmInternalFunctions;
Vector<CompilationContext> m_compilationContexts;
Vector<std::unique_ptr<TierUpCount>> m_tierUpCounts;
Vector<Vector<CodeLocationLabel<WasmEntryPtrTag>>> m_allLoopEntrypoints;