Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (287220 => 287221)
--- trunk/Source/_javascript_Core/ChangeLog 2021-12-18 10:17:05 UTC (rev 287220)
+++ trunk/Source/_javascript_Core/ChangeLog 2021-12-18 11:19:18 UTC (rev 287221)
@@ -1,3 +1,38 @@
+2021-12-18 Yusuke Suzuki <[email protected]>
+
+ [JSC] Do not allocate m_bbqCallee and m_omgCallee until it becomes necessary
+ https://bugs.webkit.org/show_bug.cgi?id=234457
+
+ Reviewed by Saam Barati.
+
+ WebAssembly memory import will require initializing both Wasm::CalleeGroup.
+ So, we should shrink memory size of Wasm::CalleeGroup as much as possible
+ to avoid memory regression. This patch allocates m_bbqCallee and m_omgCallee
+ only when it becomes available.
+
+ * wasm/WasmBBQPlan.cpp:
+ (JSC::Wasm::BBQPlan::work):
+ * wasm/WasmCalleeGroup.cpp:
+ (JSC::Wasm::CalleeGroup::CalleeGroup):
+ * wasm/WasmCalleeGroup.h:
+ (JSC::Wasm::CalleeGroup::compilationFinished): Deleted.
+ (JSC::Wasm::CalleeGroup::runnable): Deleted.
+ (JSC::Wasm::CalleeGroup::errorMessage): Deleted.
+ (JSC::Wasm::CalleeGroup::functionImportCount const): Deleted.
+ (JSC::Wasm::CalleeGroup::embedderEntrypointCalleeFromFunctionIndexSpace): Deleted.
+ (JSC::Wasm::CalleeGroup::wasmEntrypointCalleeFromFunctionIndexSpace): Deleted.
+ (JSC::Wasm::CalleeGroup::wasmBBQCalleeFromFunctionIndexSpace): Deleted.
+ (JSC::Wasm::CalleeGroup::entrypointLoadLocationFromFunctionIndexSpace): Deleted.
+ (JSC::Wasm::CalleeGroup::wasmToWasmExitStub): Deleted.
+ (JSC::Wasm::CalleeGroup::mode const): Deleted.
+ * wasm/WasmOMGForOSREntryPlan.cpp:
+ (JSC::Wasm::OMGForOSREntryPlan::work):
+ * wasm/WasmOMGPlan.cpp:
+ (JSC::Wasm::OMGPlan::work):
+ * wasm/WasmPlan.cpp:
+ (JSC::Wasm::Plan::updateCallSitesToCallUs):
+ * wasm/WasmPlan.h:
+
2021-12-17 Yusuke Suzuki <[email protected]>
[WTF] Introduce TrailingArray
Modified: trunk/Source/_javascript_Core/wasm/WasmBBQPlan.cpp (287220 => 287221)
--- trunk/Source/_javascript_Core/wasm/WasmBBQPlan.cpp 2021-12-18 10:17:05 UTC (rev 287220)
+++ trunk/Source/_javascript_Core/wasm/WasmBBQPlan.cpp 2021-12-18 11:19:18 UTC (rev 287221)
@@ -127,7 +127,6 @@
{
Ref<BBQCallee> callee = BBQCallee::create(WTFMove(function->entrypoint), functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace), WTFMove(tierUp), WTFMove(unlinkedWasmToWasmCalls), WTFMove(function->stackmaps), WTFMove(function->exceptionHandlers), WTFMove(exceptionHandlerLocations));
MacroAssembler::repatchPointer(function->calleeMoveLocation, CalleeBits::boxWasm(callee.ptr()));
- ASSERT(!m_calleeGroup->m_bbqCallees[m_functionIndex]);
entrypoint = callee->entrypoint();
if (context.pcToCodeOriginMap)
@@ -139,7 +138,7 @@
// the lock our code is ready to be published too.
Locker locker { m_calleeGroup->m_lock };
- m_calleeGroup->m_bbqCallees[m_functionIndex] = callee.copyRef();
+ m_calleeGroup->setBBQCallee(locker, m_functionIndex, callee.copyRef());
for (auto& call : callee->wasmToWasmCallsites()) {
MacroAssemblerCodePtr<WasmEntryPtrTag> entrypoint;
@@ -146,12 +145,12 @@
if (call.functionIndexSpace < m_moduleInformation->importFunctionCount())
entrypoint = m_calleeGroup->m_wasmToWasmExitStubs[call.functionIndexSpace].code();
else
- entrypoint = m_calleeGroup->wasmEntrypointCalleeFromFunctionIndexSpace(call.functionIndexSpace).entrypoint().retagged<WasmEntryPtrTag>();
+ entrypoint = m_calleeGroup->wasmEntrypointCalleeFromFunctionIndexSpace(locker, call.functionIndexSpace).entrypoint().retagged<WasmEntryPtrTag>();
MacroAssembler::repatchNearCall(call.callLocation, CodeLocationLabel<WasmEntryPtrTag>(entrypoint));
}
- Plan::updateCallSitesToCallUs(*m_calleeGroup, CodeLocationLabel<WasmEntryPtrTag>(entrypoint), m_functionIndex, functionIndexSpace);
+ Plan::updateCallSitesToCallUs(locker, *m_calleeGroup, CodeLocationLabel<WasmEntryPtrTag>(entrypoint), m_functionIndex, functionIndexSpace);
{
LLIntCallee& llintCallee = m_calleeGroup->m_llintCallees->at(m_functionIndex).get();
Modified: trunk/Source/_javascript_Core/wasm/WasmCalleeGroup.cpp (287220 => 287221)
--- trunk/Source/_javascript_Core/wasm/WasmCalleeGroup.cpp 2021-12-18 10:17:05 UTC (rev 287220)
+++ trunk/Source/_javascript_Core/wasm/WasmCalleeGroup.cpp 2021-12-18 11:19:18 UTC (rev 287221)
@@ -48,10 +48,6 @@
CalleeGroup::CalleeGroup(MemoryMode mode, const CalleeGroup& other)
: m_calleeCount(other.m_calleeCount)
, m_mode(mode)
-#if ENABLE(WEBASSEMBLY_B3JIT)
- , m_omgCallees(m_calleeCount)
- , m_bbqCallees(m_calleeCount)
-#endif
, m_llintCallees(other.m_llintCallees)
, m_embedderCallees(other.m_embedderCallees)
, m_wasmIndirectCallEntryPoints(other.m_wasmIndirectCallEntryPoints)
@@ -77,11 +73,6 @@
return;
}
-#if ENABLE(WEBASSEMBLY_B3JIT)
- // FIXME: we should eventually collect the BBQ code.
- m_bbqCallees = FixedVector<RefPtr<BBQCallee>>(m_calleeCount);
- m_omgCallees = FixedVector<RefPtr<OMGCallee>>(m_calleeCount);
-#endif
m_wasmIndirectCallEntryPoints = FixedVector<MacroAssemblerCodePtr<WasmEntryPtrTag>>(m_calleeCount);
for (unsigned i = 0; i < m_calleeCount; ++i)
@@ -104,9 +95,6 @@
return;
}
- // FIXME: we should eventually collect the BBQ code.
- m_bbqCallees = FixedVector<RefPtr<BBQCallee>>(m_calleeCount);
- m_omgCallees = FixedVector<RefPtr<OMGCallee>>(m_calleeCount);
m_wasmIndirectCallEntryPoints = FixedVector<MacroAssemblerCodePtr<WasmEntryPtrTag>>(m_calleeCount);
BBQPlan* bbqPlan = static_cast<BBQPlan*>(m_plan.get());
@@ -116,7 +104,7 @@
ASSERT_UNUSED(result, result.isNewEntry);
}
m_wasmIndirectCallEntryPoints[calleeIndex] = wasmEntrypoint->entrypoint();
- m_bbqCallees[calleeIndex] = adoptRef(static_cast<BBQCallee*>(wasmEntrypoint.leakRef()));
+ setBBQCallee(locker, calleeIndex, adoptRef(*static_cast<BBQCallee*>(wasmEntrypoint.leakRef())));
});
m_wasmToWasmExitStubs = m_plan->takeWasmToWasmExitStubs();
Modified: trunk/Source/_javascript_Core/wasm/WasmCalleeGroup.h (287220 => 287221)
--- trunk/Source/_javascript_Core/wasm/WasmCalleeGroup.h 2021-12-18 10:17:05 UTC (rev 287220)
+++ trunk/Source/_javascript_Core/wasm/WasmCalleeGroup.h 2021-12-18 11:19:18 UTC (rev 287221)
@@ -48,7 +48,7 @@
struct UnlinkedWasmToWasmCall;
enum class MemoryMode : uint8_t;
-class CalleeGroup : public ThreadSafeRefCounted<CalleeGroup> {
+class CalleeGroup final : public ThreadSafeRefCounted<CalleeGroup> {
public:
typedef void CallbackType(Ref<CalleeGroup>&&);
using AsyncCompilationCallback = RefPtr<WTF::SharedTask<CallbackType>>;
@@ -87,15 +87,15 @@
return *callee;
}
- Callee& wasmEntrypointCalleeFromFunctionIndexSpace(unsigned functionIndexSpace)
+ Callee& wasmEntrypointCalleeFromFunctionIndexSpace(const AbstractLocker&, unsigned functionIndexSpace)
{
ASSERT(runnable());
RELEASE_ASSERT(functionIndexSpace >= functionImportCount());
unsigned calleeIndex = functionIndexSpace - functionImportCount();
#if ENABLE(WEBASSEMBLY_B3JIT)
- if (m_omgCallees[calleeIndex])
+ if (!m_omgCallees.isEmpty() && m_omgCallees[calleeIndex])
return *m_omgCallees[calleeIndex].get();
- if (m_bbqCallees[calleeIndex])
+ if (!m_bbqCallees.isEmpty() && m_bbqCallees[calleeIndex])
return *m_bbqCallees[calleeIndex].get();
#endif
return m_llintCallees->at(calleeIndex).get();
@@ -104,11 +104,41 @@
#if ENABLE(WEBASSEMBLY_B3JIT)
BBQCallee& wasmBBQCalleeFromFunctionIndexSpace(unsigned functionIndexSpace)
{
+ // We do not look up without locking because this function is called from this BBQCallee itself.
ASSERT(runnable());
RELEASE_ASSERT(functionIndexSpace >= functionImportCount());
unsigned calleeIndex = functionIndexSpace - functionImportCount();
+ ASSERT(m_bbqCallees[calleeIndex]);
return *m_bbqCallees[calleeIndex].get();
}
+
+ BBQCallee* bbqCallee(const AbstractLocker&, unsigned functionIndex)
+ {
+ if (m_bbqCallees.isEmpty())
+ return nullptr;
+ return m_bbqCallees[functionIndex].get();
+ }
+
+ OMGCallee* omgCallee(const AbstractLocker&, unsigned functionIndex)
+ {
+ if (m_omgCallees.isEmpty())
+ return nullptr;
+ return m_omgCallees[functionIndex].get();
+ }
+
+ void setBBQCallee(const AbstractLocker&, unsigned functionIndex, Ref<BBQCallee>&& callee)
+ {
+ if (m_bbqCallees.isEmpty())
+ m_bbqCallees = FixedVector<RefPtr<BBQCallee>>(m_calleeCount);
+ m_bbqCallees[functionIndex] = WTFMove(callee);
+ }
+
+ void setOMGCallee(const AbstractLocker&, unsigned functionIndex, Ref<OMGCallee>&& callee)
+ {
+ if (m_omgCallees.isEmpty())
+ m_omgCallees = FixedVector<RefPtr<OMGCallee>>(m_calleeCount);
+ m_omgCallees[functionIndex] = WTFMove(callee);
+ }
#endif
MacroAssemblerCodePtr<WasmEntryPtrTag>* entrypointLoadLocationFromFunctionIndexSpace(unsigned functionIndexSpace)
Modified: trunk/Source/_javascript_Core/wasm/WasmOMGForOSREntryPlan.cpp (287220 => 287221)
--- trunk/Source/_javascript_Core/wasm/WasmOMGForOSREntryPlan.cpp 2021-12-18 10:17:05 UTC (rev 287220)
+++ trunk/Source/_javascript_Core/wasm/WasmOMGForOSREntryPlan.cpp 2021-12-18 11:19:18 UTC (rev 287221)
@@ -112,7 +112,7 @@
if (call.functionIndexSpace < m_module->moduleInformation().importFunctionCount())
entrypoint = m_calleeGroup->m_wasmToWasmExitStubs[call.functionIndexSpace].code();
else
- entrypoint = m_calleeGroup->wasmEntrypointCalleeFromFunctionIndexSpace(call.functionIndexSpace).entrypoint().retagged<WasmEntryPtrTag>();
+ entrypoint = m_calleeGroup->wasmEntrypointCalleeFromFunctionIndexSpace(locker, call.functionIndexSpace).entrypoint().retagged<WasmEntryPtrTag>();
MacroAssembler::repatchNearCall(call.callLocation, CodeLocationLabel<WasmEntryPtrTag>(entrypoint));
}
Modified: trunk/Source/_javascript_Core/wasm/WasmOMGPlan.cpp (287220 => 287221)
--- trunk/Source/_javascript_Core/wasm/WasmOMGPlan.cpp 2021-12-18 10:17:05 UTC (rev 287220)
+++ trunk/Source/_javascript_Core/wasm/WasmOMGPlan.cpp 2021-12-18 11:19:18 UTC (rev 287221)
@@ -106,7 +106,6 @@
ASSERT(m_calleeGroup.ptr() == m_module->calleeGroupFor(mode()));
Ref<OMGCallee> callee = OMGCallee::create(WTFMove(omgEntrypoint), functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace), WTFMove(unlinkedCalls), WTFMove(internalFunction->stackmaps), WTFMove(internalFunction->exceptionHandlers), WTFMove(exceptionHandlerLocations));
MacroAssembler::repatchPointer(internalFunction->calleeMoveLocation, CalleeBits::boxWasm(callee.ptr()));
- ASSERT(!m_calleeGroup->m_omgCallees[m_functionIndex]);
entrypoint = callee->entrypoint();
if (context.pcToCodeOriginMap)
@@ -118,7 +117,7 @@
// the lock our code is ready to be published too.
Locker locker { m_calleeGroup->m_lock };
- m_calleeGroup->m_omgCallees[m_functionIndex] = callee.copyRef();
+ m_calleeGroup->setOMGCallee(locker, m_functionIndex, callee.copyRef());
for (auto& call : callee->wasmToWasmCallsites()) {
MacroAssemblerCodePtr<WasmEntryPtrTag> entrypoint;
@@ -125,15 +124,15 @@
if (call.functionIndexSpace < m_module->moduleInformation().importFunctionCount())
entrypoint = m_calleeGroup->m_wasmToWasmExitStubs[call.functionIndexSpace].code();
else
- entrypoint = m_calleeGroup->wasmEntrypointCalleeFromFunctionIndexSpace(call.functionIndexSpace).entrypoint().retagged<WasmEntryPtrTag>();
+ entrypoint = m_calleeGroup->wasmEntrypointCalleeFromFunctionIndexSpace(locker, call.functionIndexSpace).entrypoint().retagged<WasmEntryPtrTag>();
MacroAssembler::repatchNearCall(call.callLocation, CodeLocationLabel<WasmEntryPtrTag>(entrypoint));
}
- Plan::updateCallSitesToCallUs(m_calleeGroup, CodeLocationLabel<WasmEntryPtrTag>(entrypoint), m_functionIndex, functionIndexSpace);
+ Plan::updateCallSitesToCallUs(locker, m_calleeGroup, CodeLocationLabel<WasmEntryPtrTag>(entrypoint), m_functionIndex, functionIndexSpace);
{
- if (BBQCallee* bbqCallee = m_calleeGroup->m_bbqCallees[m_functionIndex].get()) {
+ if (BBQCallee* bbqCallee = m_calleeGroup->bbqCallee(locker, m_functionIndex)) {
Locker locker { bbqCallee->tierUpCount()->getLock() };
bbqCallee->setReplacement(callee.copyRef());
bbqCallee->tierUpCount()->m_compilationStatusForOMG = TierUpCount::CompilationStatus::Compiled;
Modified: trunk/Source/_javascript_Core/wasm/WasmPlan.cpp (287220 => 287221)
--- trunk/Source/_javascript_Core/wasm/WasmPlan.cpp 2021-12-18 10:17:05 UTC (rev 287220)
+++ trunk/Source/_javascript_Core/wasm/WasmPlan.cpp 2021-12-18 11:19:18 UTC (rev 287221)
@@ -124,7 +124,7 @@
}
#if ENABLE(WEBASSEMBLY_B3JIT)
-void Plan::updateCallSitesToCallUs(CalleeGroup& calleeGroup, CodeLocationLabel<WasmEntryPtrTag> entrypoint, uint32_t functionIndex, uint32_t functionIndexSpace)
+void Plan::updateCallSitesToCallUs(const AbstractLocker& calleeGroupLocker, CalleeGroup& calleeGroup, CodeLocationLabel<WasmEntryPtrTag> entrypoint, uint32_t functionIndex, uint32_t functionIndexSpace)
{
HashMap<void*, CodeLocationLabel<WasmEntryPtrTag>> stagedCalls;
auto stageRepatch = [&] (const auto& callsites) {
@@ -144,7 +144,7 @@
if (OMGForOSREntryCallee* osrEntryCallee = llintCallee.osrEntryCallee(calleeGroup.mode()))
stageRepatch(osrEntryCallee->wasmToWasmCallsites());
}
- if (BBQCallee* bbqCallee = calleeGroup.m_bbqCallees[i].get()) {
+ if (BBQCallee* bbqCallee = calleeGroup.bbqCallee(calleeGroupLocker, i)) {
if (OMGCallee* replacementCallee = bbqCallee->replacement())
stageRepatch(replacementCallee->wasmToWasmCallsites());
if (OMGForOSREntryCallee* osrEntryCallee = bbqCallee->osrEntryCallee())
@@ -179,7 +179,7 @@
if (OMGForOSREntryCallee* osrEntryCallee = llintCallee.osrEntryCallee(calleeGroup.mode()))
repatchCalls(osrEntryCallee->wasmToWasmCallsites());
}
- if (BBQCallee* bbqCallee = calleeGroup.m_bbqCallees[i].get()) {
+ if (BBQCallee* bbqCallee = calleeGroup.bbqCallee(calleeGroupLocker, i)) {
if (OMGCallee* replacementCallee = bbqCallee->replacement())
repatchCalls(replacementCallee->wasmToWasmCallsites());
if (OMGForOSREntryCallee* osrEntryCallee = bbqCallee->osrEntryCallee())
Modified: trunk/Source/_javascript_Core/wasm/WasmPlan.h (287220 => 287221)
--- trunk/Source/_javascript_Core/wasm/WasmPlan.h 2021-12-18 10:17:05 UTC (rev 287220)
+++ trunk/Source/_javascript_Core/wasm/WasmPlan.h 2021-12-18 11:19:18 UTC (rev 287221)
@@ -85,7 +85,7 @@
virtual void complete() WTF_REQUIRES_LOCK(m_lock) = 0;
#if ENABLE(WEBASSEMBLY_B3JIT)
- static void updateCallSitesToCallUs(CalleeGroup&, CodeLocationLabel<WasmEntryPtrTag> entrypoint, uint32_t functionIndex, uint32_t functionIndexSpace);
+ static void updateCallSitesToCallUs(const AbstractLocker& calleeGroupLocker, CalleeGroup&, CodeLocationLabel<WasmEntryPtrTag> entrypoint, uint32_t functionIndex, uint32_t functionIndexSpace);
#endif
Ref<ModuleInformation> m_moduleInformation;