Skip to content

Commit

Permalink
[JSC] Remove "Embedder" word from wasm implementation
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=251331
rdar://104791730

Reviewed by Mark Lam.

JSC Wasm implementation's embedder is always JS, and we are not planning to change it.
We should tightly couple our wasm implementation with the rest of JSC to make it super efficient and fast.
This patch removes "Embedder" word from wasm implementation. Replacing them with "JS".

* Source/JavaScriptCore/CMakeLists.txt:
* Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj:
* Source/JavaScriptCore/Sources.txt:
* Source/JavaScriptCore/wasm/WasmAirIRGeneratorBase.h:
(JSC::Wasm::ExpressionType>::AirIRGeneratorBase):
(JSC::Wasm::ExpressionType>::addCall):
(JSC::Wasm::ExpressionType>::addCallIndirect):
(JSC::Wasm::ExpressionType>::addCallRef):
* Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp:
(JSC::Wasm::B3IRGenerator::B3IRGenerator):
(JSC::Wasm::B3IRGenerator::addCall):
(JSC::Wasm::B3IRGenerator::addCallIndirect):
(JSC::Wasm::B3IRGenerator::addCallRef):
* Source/JavaScriptCore/wasm/WasmB3IRGenerator.h:
* Source/JavaScriptCore/wasm/WasmBBQPlan.cpp:
(JSC::Wasm::BBQPlan::compileFunction):
(JSC::Wasm::BBQPlan::didCompleteCompilation):
(JSC::Wasm::BBQPlan::initializeCallees):
* Source/JavaScriptCore/wasm/WasmBBQPlan.h:
* Source/JavaScriptCore/wasm/WasmCallee.cpp:
(JSC::Wasm::Callee::runWithDowncast):
* Source/JavaScriptCore/wasm/WasmCallee.h:
* Source/JavaScriptCore/wasm/WasmCalleeGroup.cpp:
(JSC::Wasm::CalleeGroup::CalleeGroup):
* Source/JavaScriptCore/wasm/WasmCalleeGroup.h:
* Source/JavaScriptCore/wasm/WasmCompilationMode.cpp:
(JSC::Wasm::makeString):
* Source/JavaScriptCore/wasm/WasmCompilationMode.h:
(JSC::Wasm::isOSREntry):
(JSC::Wasm::isAnyBBQ):
(JSC::Wasm::isAnyOMG):
* Source/JavaScriptCore/wasm/WasmInstance.cpp:
(JSC::Wasm::Instance::initElementSegment):
* Source/JavaScriptCore/wasm/WasmInstance.h:
* Source/JavaScriptCore/wasm/WasmJS.h: Renamed from Source/JavaScriptCore/wasm/WasmEmbedder.h.
* Source/JavaScriptCore/wasm/WasmLLIntPlan.cpp:
(JSC::Wasm::LLIntPlan::didCompleteCompilation):
* Source/JavaScriptCore/wasm/WasmLLIntPlan.h:
* Source/JavaScriptCore/wasm/WasmModule.h:
* Source/JavaScriptCore/wasm/WasmPlan.h:
* Source/JavaScriptCore/wasm/WasmTable.h:
* Source/JavaScriptCore/wasm/WasmThunks.h:
* Source/JavaScriptCore/wasm/js/WasmToJS.h:
* Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp:
(JSC::WebAssemblyModuleRecord::initializeExports):

Canonical link: https://commits.webkit.org/259534@main
  • Loading branch information
Constellation committed Jan 29, 2023
1 parent ac61096 commit 2a2d8e7
Show file tree
Hide file tree
Showing 25 changed files with 89 additions and 90 deletions.
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1275,13 +1275,13 @@ set(JavaScriptCore_PRIVATE_FRAMEWORK_HEADERS
wasm/WasmCompilationMode.h
wasm/WasmContext.h
wasm/WasmCreationMode.h
wasm/WasmEmbedder.h
wasm/WasmExceptionType.h
wasm/WasmFaultSignalHandler.h
wasm/WasmFormat.h
wasm/WasmFunctionCodeBlockGenerator.h
wasm/WasmHandlerInfo.h
wasm/WasmIndexOrName.h
wasm/WasmJS.h
wasm/WasmLLIntBuiltin.h
wasm/WasmLLIntTierUpCounter.h
wasm/WasmMemory.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1664,7 +1664,7 @@
AD4937D41DDD27DE0077C807 /* WebAssemblyFunction.h in Headers */ = {isa = PBXBuildFile; fileRef = AD4937CA1DDD27340077C807 /* WebAssemblyFunction.h */; };
AD4B1DFA1DF244E20071AE32 /* WasmBinding.h in Headers */ = {isa = PBXBuildFile; fileRef = AD4B1DF81DF244D70071AE32 /* WasmBinding.h */; };
AD5B416F1EBAFB77008EFA43 /* WasmName.h in Headers */ = {isa = PBXBuildFile; fileRef = AD5B416E1EBAFB65008EFA43 /* WasmName.h */; settings = {ATTRIBUTES = (Private, ); }; };
AD5C36DD1F688B65000BCAAF /* WasmEmbedder.h in Headers */ = {isa = PBXBuildFile; fileRef = AD5C36DC1F688B5F000BCAAF /* WasmEmbedder.h */; settings = {ATTRIBUTES = (Private, ); }; };
AD5C36DD1F688B65000BCAAF /* WasmJS.h in Headers */ = {isa = PBXBuildFile; fileRef = AD5C36DC1F688B5F000BCAAF /* WasmJS.h */; settings = {ATTRIBUTES = (Private, ); }; };
AD5C36E21F699EC0000BCAAF /* WasmInstance.h in Headers */ = {isa = PBXBuildFile; fileRef = AD5C36DF1F699EB6000BCAAF /* WasmInstance.h */; settings = {ATTRIBUTES = (Private, ); }; };
AD5C36E61F69EC91000BCAAF /* WasmTable.h in Headers */ = {isa = PBXBuildFile; fileRef = AD5C36E41F69EC8B000BCAAF /* WasmTable.h */; settings = {ATTRIBUTES = (Private, ); }; };
AD5C36EA1F75AD6A000BCAAF /* JSToWasm.h in Headers */ = {isa = PBXBuildFile; fileRef = AD8DD6CF1F67089F0004EB52 /* JSToWasm.h */; settings = {ATTRIBUTES = (Private, ); }; };
Expand Down Expand Up @@ -5104,7 +5104,7 @@
AD4B1DF71DF244D70071AE32 /* WasmBinding.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WasmBinding.cpp; sourceTree = "<group>"; };
AD4B1DF81DF244D70071AE32 /* WasmBinding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmBinding.h; sourceTree = "<group>"; };
AD5B416E1EBAFB65008EFA43 /* WasmName.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmName.h; sourceTree = "<group>"; };
AD5C36DC1F688B5F000BCAAF /* WasmEmbedder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WasmEmbedder.h; sourceTree = "<group>"; };
AD5C36DC1F688B5F000BCAAF /* WasmJS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WasmJS.h; sourceTree = "<group>"; };
AD5C36DE1F699EB6000BCAAF /* WasmInstance.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WasmInstance.cpp; sourceTree = "<group>"; };
AD5C36DF1F699EB6000BCAAF /* WasmInstance.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WasmInstance.h; sourceTree = "<group>"; };
AD5C36E31F69EC8B000BCAAF /* WasmTable.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WasmTable.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -7505,7 +7505,6 @@
E3915C062309682900CB2561 /* WasmContext.cpp */,
AD412B321E7B2E8A008AF157 /* WasmContext.h */,
E36CC9462086314F0051FFD6 /* WasmCreationMode.h */,
AD5C36DC1F688B5F000BCAAF /* WasmEmbedder.h */,
14AB0C91231747B6000250BC /* WasmEntryPlan.cpp */,
14AB0C94231747B7000250BC /* WasmEntryPlan.h */,
79DAE2791E03C82200B526AA /* WasmExceptionType.h */,
Expand All @@ -7526,6 +7525,7 @@
AD5C36DE1F699EB6000BCAAF /* WasmInstance.cpp */,
AD5C36DF1F699EB6000BCAAF /* WasmInstance.h */,
52FDABC22788076900C15B59 /* WasmIRGeneratorHelpers.h */,
AD5C36DC1F688B5F000BCAAF /* WasmJS.h */,
AD00659D1ECAC7FE000CA926 /* WasmLimits.h */,
E308A80D294D39330044A109 /* WasmLLIntBuiltin.h */,
14C5AD6822F33FBF00F1FB83 /* WasmLLIntGenerator.cpp */,
Expand Down Expand Up @@ -11400,7 +11400,6 @@
E3BD2B7622F275020011765C /* WasmCompilationMode.h in Headers */,
AD412B341E7B2E9E008AF157 /* WasmContext.h in Headers */,
E36CC9472086314F0051FFD6 /* WasmCreationMode.h in Headers */,
AD5C36DD1F688B65000BCAAF /* WasmEmbedder.h in Headers */,
79DAE27A1E03C82200B526AA /* WasmExceptionType.h in Headers */,
5381B9391E60E97D0090F794 /* WasmFaultSignalHandler.h in Headers */,
7BC547D31B6959A100959B58 /* WasmFormat.h in Headers */,
Expand All @@ -11411,6 +11410,7 @@
AD8FF3981EB5BDB20087FF82 /* WasmIndexOrName.h in Headers */,
AD5C36E21F699EC0000BCAAF /* WasmInstance.h in Headers */,
52FDABC32788076B00C15B59 /* WasmIRGeneratorHelpers.h in Headers */,
AD5C36DD1F688B65000BCAAF /* WasmJS.h in Headers */,
AD00659E1ECAC812000CA926 /* WasmLimits.h in Headers */,
E308A80E294D39340044A109 /* WasmLLIntBuiltin.h in Headers */,
1450FA1F2357BEC90093CD4D /* WasmLLIntTierUpCounter.h in Headers */,
Expand Down
1 change: 0 additions & 1 deletion Source/JavaScriptCore/Sources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,6 @@ wasm/WasmCalleeRegistry.cpp
wasm/WasmCallingConvention.cpp
wasm/WasmCompilationMode.cpp
wasm/WasmContext.cpp
wasm/WasmEmbedder.h
wasm/WasmEntryPlan.cpp
wasm/WasmFaultSignalHandler.cpp
wasm/WasmFormat.cpp
Expand Down
18 changes: 9 additions & 9 deletions Source/JavaScriptCore/wasm/WasmAirIRGeneratorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ AirIRGeneratorBase<Derived, ExpressionType>::AirIRGeneratorBase(const ModuleInfo
// 1. Emit less code.
// 2. Try to speed things up by skipping stack checks.
minimumParentCheckSize,
// This allows us to elide stack checks in the Wasm -> Embedder call IC stub. Since these will
// This allows us to elide stack checks in the Wasm -> JS call IC stub. Since these will
// spill all arguments to the stack, we ensure that a stack check here covers the
// stack that such a stub would use.
Checked<uint32_t>(m_maxNumJSCallArguments) * sizeof(Register) + jsCallingConvention().headerSizeInBytes
Expand Down Expand Up @@ -3168,7 +3168,7 @@ auto AirIRGeneratorBase<Derived, ExpressionType>::addCall(uint32_t functionIndex

if (m_info.isImportedFunctionFromFunctionIndexSpace(functionIndex)) {

auto emitCallToEmbedder = [&, this](CallPatchpointData data) -> void {
auto emitCallToImport = [&, this](CallPatchpointData data) -> void {
CallPatchpointData::first_type patchpoint = data.first;
CallPatchpointData::second_type handle = data.second;
// We need to clobber all potential pinned registers since we might be leaving the instance.
Expand All @@ -3181,7 +3181,7 @@ auto AirIRGeneratorBase<Derived, ExpressionType>::addCall(uint32_t functionIndex
prepareForTailCall(jit, params, tailCallStackOffsetFromFP);
if (handle)
handle->generate(jit, params, this);
JIT_COMMENT(jit, "Wasm to embedder imported function call patchpoint");
JIT_COMMENT(jit, "Wasm to imported function call patchpoint");
if (isTailCall) {
// In tail-call, we always configure JSWebAssemblyInstance* in |this| to anchor it from conservative GC roots.
CCallHelpers::Address thisSlot(CCallHelpers::stackPointerRegister, CallFrameSlot::thisArgument * static_cast<int>(sizeof(Register)) - prologueStackPointerDelta());
Expand All @@ -3201,11 +3201,11 @@ auto AirIRGeneratorBase<Derived, ExpressionType>::addCall(uint32_t functionIndex
append(Move, Arg::addr(jumpDestination), jumpDestination);

if (isTailCall) {
emitCallToEmbedder(self().emitTailCallPatchpoint(m_currentBlock, tailCallStackOffsetFromFP, wasmCalleeInfo.params, args, { { jumpDestination, B3::ValueRep(GPRInfo::nonPreservedNonArgumentGPR0) } }));
emitCallToImport(self().emitTailCallPatchpoint(m_currentBlock, tailCallStackOffsetFromFP, wasmCalleeInfo.params, args, { { jumpDestination, B3::ValueRep(GPRInfo::nonPreservedNonArgumentGPR0) } }));
return { };
}

emitCallToEmbedder(self().emitCallPatchpoint(m_currentBlock, self().toB3ResultType(&signature), results, args, wasmCalleeInfo, { { jumpDestination, B3::ValueRep(GPRInfo::nonPreservedNonArgumentGPR0) } }));
emitCallToImport(self().emitCallPatchpoint(m_currentBlock, self().toB3ResultType(&signature), results, args, wasmCalleeInfo, { { jumpDestination, B3::ValueRep(GPRInfo::nonPreservedNonArgumentGPR0) } }));

// The call could have been to another WebAssembly instance, and / or could have modified our Memory.
restoreWebAssemblyGlobalState(m_info.memory, currentInstance, m_currentBlock);
Expand Down Expand Up @@ -3272,8 +3272,8 @@ auto AirIRGeneratorBase<Derived, ExpressionType>::addCallIndirect(unsigned table
ASSERT(m_info.tables[tableIndex].type() == TableElementType::Funcref);

// Note: call indirect can call either WebAssemblyFunction or WebAssemblyWrapperFunction. Because
// WebAssemblyWrapperFunction is like calling into the embedder, we conservatively assume all call indirects
// can be to the embedder for our stack check calculation.
// WebAssemblyWrapperFunction is like calling into the js, we conservatively assume all call indirects
// can be to the js for our stack check calculation.
m_maxNumJSCallArguments = std::max(m_maxNumJSCallArguments, static_cast<uint32_t>(args.size()));

ExpressionType callableFunctionBuffer = self().gPtr();
Expand Down Expand Up @@ -3351,8 +3351,8 @@ auto AirIRGeneratorBase<Derived, ExpressionType>::addCallRef(const TypeDefinitio
{
m_makesCalls = true;
// Note: call ref can call either WebAssemblyFunction or WebAssemblyWrapperFunction. Because
// WebAssemblyWrapperFunction is like calling into the embedder, we conservatively assume all call indirects
// can be to the embedder for our stack check calculation.
// WebAssemblyWrapperFunction is like calling into the js, we conservatively assume all call indirects
// can be to the js for our stack check calculation.
ExpressionType calleeFunction = args.takeLast();
m_maxNumJSCallArguments = std::max(m_maxNumJSCallArguments, static_cast<uint32_t>(args.size()));
const TypeDefinition& signature = originalSignature.expand();
Expand Down
18 changes: 9 additions & 9 deletions Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ B3IRGenerator::B3IRGenerator(const ModuleInformation& info, Callee& callee, Proc
// 1. Emit less code.
// 2. Try to speed things up by skipping stack checks.
minimumParentCheckSize,
// This allows us to elide stack checks in the Wasm -> Embedder call IC stub. Since these will
// This allows us to elide stack checks in the Wasm -> JS call IC stub. Since these will
// spill all arguments to the stack, we ensure that a stack check here covers the
// stack that such a stub would use.
Checked<uint32_t>(m_maxNumJSCallArguments) * sizeof(Register) + JSCallingConvention::headerSizeInBytes
Expand Down Expand Up @@ -4017,7 +4017,7 @@ auto B3IRGenerator::addCall(uint32_t functionIndex, const TypeDefinition& signat

if (m_info.isImportedFunctionFromFunctionIndexSpace(functionIndex)) {

auto emitCallToEmbedder = [&, this](PatchpointValue* patchpoint, Box<PatchpointExceptionHandle> handle) -> void {
auto emitCallToImport = [&, this](PatchpointValue* patchpoint, Box<PatchpointExceptionHandle> handle) -> void {
patchpoint->append(jumpDestination, ValueRep(GPRInfo::nonPreservedNonArgumentGPR0));
// We need to clobber all potential pinned registers since we might be leaving the instance.
// We pessimistically assume we could be calling to something that is bounds checking.
Expand All @@ -4043,17 +4043,17 @@ auto B3IRGenerator::addCall(uint32_t functionIndex, const TypeDefinition& signat
m_maxNumJSCallArguments = std::max(m_maxNumJSCallArguments, static_cast<uint32_t>(args.size()));

// FIXME: Let's remove this indirection by creating a PIC friendly IC
// for calls out to the embedder. This shouldn't be that hard to do. We could probably
// for calls out to the js. This shouldn't be that hard to do. We could probably
// implement the IC to be over Context*.
// https://bugs.webkit.org/show_bug.cgi?id=170375
jumpDestination = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(), instanceValue(), safeCast<int32_t>(Instance::offsetOfImportFunctionStub(functionIndex)));

if (isTailCall) {
createTailCallPatchpoint(m_currentBlock, wasmCalleeInfo.params, args, tailCallStackOffsetFromFP, scopedLambdaRef<void(PatchpointValue*, Box<PatchpointExceptionHandle>)>(emitCallToEmbedder));
createTailCallPatchpoint(m_currentBlock, wasmCalleeInfo.params, args, tailCallStackOffsetFromFP, scopedLambdaRef<void(PatchpointValue*, Box<PatchpointExceptionHandle>)>(emitCallToImport));
return { };
}

Value* result = createCallPatchpoint(m_currentBlock, nullptr, returnType, wasmCalleeInfo, args, scopedLambdaRef<void(PatchpointValue*, Box<PatchpointExceptionHandle>)>(emitCallToEmbedder));
Value* result = createCallPatchpoint(m_currentBlock, nullptr, returnType, wasmCalleeInfo, args, scopedLambdaRef<void(PatchpointValue*, Box<PatchpointExceptionHandle>)>(emitCallToImport));

if (returnType != B3::Void)
fillResults(result);
Expand Down Expand Up @@ -4119,8 +4119,8 @@ auto B3IRGenerator::addCallIndirect(unsigned tableIndex, const TypeDefinition& o
ASSERT(signature.as<FunctionSignature>()->argumentCount() == args.size());

// Note: call indirect can call either WebAssemblyFunction or WebAssemblyWrapperFunction. Because
// WebAssemblyWrapperFunction is like calling into the embedder, we conservatively assume all call indirects
// can be to the embedder for our stack check calculation.
// WebAssemblyWrapperFunction is like calling into the js, we conservatively assume all call indirects
// can be to the js for our stack check calculation.
m_maxNumJSCallArguments = std::max(m_maxNumJSCallArguments, static_cast<uint32_t>(args.size()));

Value* callableFunctionBuffer = nullptr;
Expand Down Expand Up @@ -4189,8 +4189,8 @@ auto B3IRGenerator::addCallRef(const TypeDefinition& originalSignature, Vector<E
m_makesCalls = true;

// Note: call ref can call either WebAssemblyFunction or WebAssemblyWrapperFunction. Because
// WebAssemblyWrapperFunction is like calling into the embedder, we conservatively assume all call indirects
// can be to the embedder for our stack check calculation.
// WebAssemblyWrapperFunction is like calling into the js, we conservatively assume all call indirects
// can be to the js for our stack check calculation.
m_maxNumJSCallArguments = std::max(m_maxNumJSCallArguments, static_cast<uint32_t>(args.size()));

// Check the target reference for null.
Expand Down
4 changes: 2 additions & 2 deletions Source/JavaScriptCore/wasm/WasmB3IRGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "JITOpaqueByproducts.h"
#include "PCToCodeOriginMap.h"
#include "WasmCompilationMode.h"
#include "WasmEmbedder.h"
#include "WasmJS.h"
#include "WasmMemory.h"
#include "WasmModuleInformation.h"
#include "WasmTierUpCount.h"
Expand All @@ -50,7 +50,7 @@ namespace Wasm {
class MemoryInformation;

struct CompilationContext {
std::unique_ptr<CCallHelpers> embedderEntrypointJIT;
std::unique_ptr<CCallHelpers> jsEntrypointJIT;
std::unique_ptr<CCallHelpers> wasmEntrypointJIT;
std::unique_ptr<OpaqueByproducts> wasmEntrypointByproducts;
std::unique_ptr<B3::Procedure> procedure;
Expand Down
Loading

0 comments on commit 2a2d8e7

Please sign in to comment.