Changeset 224020 in webkit
- Timestamp:
- Oct 26, 2017 8:33:55 AM (6 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r224002 r224020 1 2017-10-26 JF Bastien <jfbastien@apple.com> 2 3 WebAssembly: no VM / JS version of our implementation 4 https://bugs.webkit.org/show_bug.cgi?id=177472 5 6 Reviewed by Michael Saboff. 7 8 This patch removes all appearances of "JS" and "VM" in the wasm 9 directory. These now only appear in the wasm/js directory, which 10 is only used in a JS embedding of wasm. It should therefore now be 11 possible to create non-JS embeddings of wasm through JSC, though 12 it'll still require: 13 14 - Mild codegen for wasm<->embedder calls; 15 - A strategy for trap handling (no need for full unwind! Could kill). 16 - Creation of the Wasm::* objects. 17 - Calling convention handling to call the embedder. 18 - Handling of multiple embedders (see #177475, this is optional). 19 20 Most of the patch consists in renaming JSWebAssemblyInstance to 21 Instance, and removing temporary copies which I'd added to make 22 this specific patch very simple. 23 24 * interpreter/CallFrame.cpp: 25 (JSC::CallFrame::wasmAwareLexicalGlobalObject): this one place 26 which needs to know about who "owns" the Wasm::Instance. In a JS 27 embedding it's the JSWebAssemblyInstance. 28 * wasm/WasmB3IRGenerator.cpp: 29 (JSC::Wasm::B3IRGenerator::B3IRGenerator): 30 (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState): 31 (JSC::Wasm::B3IRGenerator::addGrowMemory): 32 (JSC::Wasm::B3IRGenerator::addCurrentMemory): 33 (JSC::Wasm::B3IRGenerator::getGlobal): 34 (JSC::Wasm::B3IRGenerator::setGlobal): 35 (JSC::Wasm::B3IRGenerator::addCall): 36 (JSC::Wasm::B3IRGenerator::addCallIndirect): 37 * wasm/WasmBinding.cpp: 38 (JSC::Wasm::wasmToWasm): 39 * wasm/WasmContext.cpp: 40 (JSC::Wasm::Context::load const): 41 (JSC::Wasm::Context::store): 42 * wasm/WasmContext.h: 43 * wasm/WasmEmbedder.h: 44 * wasm/WasmInstance.cpp: 45 (JSC::Wasm::Instance::Instance): 46 (JSC::Wasm::Instance::create): 47 (JSC::Wasm::Instance::extraMemoryAllocated const): 48 * wasm/WasmInstance.h: add an "owner", the Wasm::Context, move the 49 "tail" import information from JSWebAssemblyInstance over to here. 50 (JSC::Wasm::Instance::finalizeCreation): 51 (JSC::Wasm::Instance::owner const): 52 (JSC::Wasm::Instance::offsetOfOwner): 53 (JSC::Wasm::Instance::context const): 54 (JSC::Wasm::Instance::setMemory): 55 (JSC::Wasm::Instance::setTable): 56 (JSC::Wasm::Instance::offsetOfMemory): 57 (JSC::Wasm::Instance::offsetOfGlobals): 58 (JSC::Wasm::Instance::offsetOfTable): 59 (JSC::Wasm::Instance::offsetOfTail): 60 (JSC::Wasm::Instance::numImportFunctions const): 61 (JSC::Wasm::Instance::importFunctionInfo): 62 (JSC::Wasm::Instance::offsetOfTargetInstance): 63 (JSC::Wasm::Instance::offsetOfWasmEntrypoint): 64 (JSC::Wasm::Instance::offsetOfWasmToEmbedderStubExecutableAddress): 65 (JSC::Wasm::Instance::offsetOfImportFunction): 66 (JSC::Wasm::Instance::importFunction): 67 (JSC::Wasm::Instance::allocationSize): 68 (JSC::Wasm::Instance::create): Deleted. 69 * wasm/WasmOMGPlan.cpp: 70 (JSC::Wasm::OMGPlan::runForIndex): 71 * wasm/WasmOMGPlan.h: 72 * wasm/WasmTable.cpp: 73 (JSC::Wasm::Table::Table): 74 (JSC::Wasm::Table::setFunction): 75 * wasm/WasmTable.h: 76 * wasm/WasmThunks.cpp: 77 (JSC::Wasm::throwExceptionFromWasmThunkGenerator): 78 (JSC::Wasm::triggerOMGTierUpThunkGenerator): 79 * wasm/js/JSToWasm.cpp: 80 (JSC::Wasm::createJSToWasmWrapper): 81 * wasm/js/JSWebAssemblyInstance.cpp: delete code that is now on Wasm::Instance 82 (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance): The embedder 83 decides what the import function is. Here we must properly 84 placement-new it to what we've elected (and initialize it later). 85 (JSC::JSWebAssemblyInstance::visitChildren): 86 (JSC::JSWebAssemblyInstance::finalizeCreation): 87 (JSC::JSWebAssemblyInstance::create): 88 * wasm/js/JSWebAssemblyInstance.h: delete code that is now on Wasm::Instance 89 (JSC::JSWebAssemblyInstance::instance): 90 (JSC::JSWebAssemblyInstance::moduleNamespaceObject): 91 (JSC::JSWebAssemblyInstance::setMemory): 92 (JSC::JSWebAssemblyInstance::table): 93 (JSC::JSWebAssemblyInstance::setTable): 94 (JSC::JSWebAssemblyInstance::offsetOfInstance): 95 (JSC::JSWebAssemblyInstance::offsetOfCallee): 96 (JSC::JSWebAssemblyInstance::context const): Deleted. 97 (JSC::JSWebAssemblyInstance::offsetOfTail): Deleted. 98 (): Deleted. 99 (JSC::JSWebAssemblyInstance::importFunctionInfo): Deleted. 100 (JSC::JSWebAssemblyInstance::offsetOfTargetInstance): Deleted. 101 (JSC::JSWebAssemblyInstance::offsetOfWasmEntrypoint): Deleted. 102 (JSC::JSWebAssemblyInstance::offsetOfWasmToEmbedderStubExecutableAddress): Deleted. 103 (JSC::JSWebAssemblyInstance::offsetOfImportFunction): Deleted. 104 (JSC::JSWebAssemblyInstance::importFunction): Deleted. 105 (JSC::JSWebAssemblyInstance::internalMemory): Deleted. 106 (JSC::JSWebAssemblyInstance::wasmCodeBlock const): Deleted. 107 (JSC::JSWebAssemblyInstance::offsetOfWasmTable): Deleted. 108 (JSC::JSWebAssemblyInstance::offsetOfGlobals): Deleted. 109 (JSC::JSWebAssemblyInstance::offsetOfCodeBlock): Deleted. 110 (JSC::JSWebAssemblyInstance::offsetOfWasmCodeBlock): Deleted. 111 (JSC::JSWebAssemblyInstance::offsetOfCachedStackLimit): Deleted. 112 (JSC::JSWebAssemblyInstance::offsetOfWasmMemory): Deleted. 113 (JSC::JSWebAssemblyInstance::offsetOfTopEntryFramePointer): Deleted. 114 (JSC::JSWebAssemblyInstance::cachedStackLimit const): Deleted. 115 (JSC::JSWebAssemblyInstance::setCachedStackLimit): Deleted. 116 (JSC::JSWebAssemblyInstance::wasmMemory): Deleted. 117 (JSC::JSWebAssemblyInstance::wasmModule): Deleted. 118 (JSC::JSWebAssemblyInstance::allocationSize): Deleted. 119 * wasm/js/JSWebAssemblyTable.cpp: 120 (JSC::JSWebAssemblyTable::setFunction): 121 * wasm/js/WasmToJS.cpp: One extra indirection to find the JSWebAssemblyInstance. 122 (JSC::Wasm::materializeImportJSCell): 123 (JSC::Wasm::handleBadI64Use): 124 (JSC::Wasm::wasmToJS): 125 (JSC::Wasm::wasmToJSException): 126 * wasm/js/WasmToJS.h: 127 * wasm/js/WebAssemblyFunction.cpp: 128 (JSC::callWebAssemblyFunction): 129 * wasm/js/WebAssemblyInstanceConstructor.cpp: 130 (JSC::constructJSWebAssemblyInstance): 131 * wasm/js/WebAssemblyModuleRecord.cpp: 132 (JSC::WebAssemblyModuleRecord::link): 133 (JSC::WebAssemblyModuleRecord::evaluate): 134 * wasm/js/WebAssemblyPrototype.cpp: 135 (JSC::instantiate): 136 * wasm/js/WebAssemblyWrapperFunction.cpp: 137 (JSC::WebAssemblyWrapperFunction::create): 138 1 139 2017-10-25 Devin Rousso <webkit@devinrousso.com> 2 140 -
trunk/Source/JavaScriptCore/interpreter/CallFrame.cpp
r223738 r224020 34 34 #include "VMEntryScope.h" 35 35 #include "WasmContext.h" 36 #include "WasmInstance.h" 36 37 #include <wtf/StringPrintStream.h> 37 38 … … 219 220 if (!callee().isWasm()) 220 221 return lexicalGlobalObject(); 221 return vm.wasmContext.load()-> globalObject();222 return vm.wasmContext.load()->owner<JSWebAssemblyInstance>()->globalObject(); 222 223 #else 223 224 UNUSED_PARAM(vm); -
trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp
r223907 r224020 49 49 #include "B3WasmBoundsCheckValue.h" 50 50 #include "JSCInlines.h" 51 #include "JSWebAssemblyInstance.h"52 51 #include "ScratchRegisterAllocator.h" 53 52 #include "VirtualRegister.h" … … 56 55 #include "WasmExceptionType.h" 57 56 #include "WasmFunctionParser.h" 57 #include "WasmInstance.h" 58 58 #include "WasmMemory.h" 59 59 #include "WasmOMGPlan.h" … … 429 429 jit.loadWasmContextInstance(contextInstance); 430 430 431 jit.loadPtr(CCallHelpers::Address(contextInstance, JSWebAssemblyInstance::offsetOfCachedStackLimit()), scratch2);431 jit.loadPtr(CCallHelpers::Address(contextInstance, Instance::offsetOfCachedStackLimit()), scratch2); 432 432 jit.addPtr(CCallHelpers::TrustedImm32(-checkSize), fp, scratch1); 433 433 MacroAssembler::JumpList overflow; … … 473 473 patchpoint->setGenerator([pinnedRegs] (CCallHelpers& jit, const B3::StackmapGenerationParams& params) { 474 474 GPRReg baseMemory = pinnedRegs->baseMemoryPointer; 475 jit.loadPtr(CCallHelpers::Address(params[0].gpr(), JSWebAssemblyInstance::offsetOfWasmMemory()), baseMemory);475 jit.loadPtr(CCallHelpers::Address(params[0].gpr(), Instance::offsetOfMemory()), baseMemory); 476 476 const auto& sizeRegs = pinnedRegs->sizeRegisters; 477 477 ASSERT(sizeRegs.size() >= 1); … … 556 556 auto B3IRGenerator::addGrowMemory(ExpressionType delta, ExpressionType& result) -> PartialResult 557 557 { 558 int32_t (*growMemory)( JSWebAssemblyInstance*, int32_t) = [] (JSWebAssemblyInstance* instance, int32_t delta) -> int32_t {558 int32_t (*growMemory)(Instance*, int32_t) = [] (Instance* instance, int32_t delta) -> int32_t { 559 559 if (delta < 0) 560 560 return -1; 561 561 562 auto grown = instance-> internalMemory().grow(PageCount(delta));562 auto grown = instance->memory()->grow(PageCount(delta)); 563 563 if (!grown) { 564 564 switch (grown.error()) { … … 585 585 auto B3IRGenerator::addCurrentMemory(ExpressionType& result) -> PartialResult 586 586 { 587 Value* memoryObject = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(), instanceValue(), safeCast<int32_t>( JSWebAssemblyInstance::offsetOfWasmMemory()));587 Value* memoryObject = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(), instanceValue(), safeCast<int32_t>(Instance::offsetOfMemory())); 588 588 589 589 static_assert(sizeof(decltype(static_cast<Memory*>(nullptr)->size())) == sizeof(uint64_t), "codegen relies on this size"); … … 609 609 auto B3IRGenerator::getGlobal(uint32_t index, ExpressionType& result) -> PartialResult 610 610 { 611 Value* globalsArray = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(), instanceValue(), safeCast<int32_t>( JSWebAssemblyInstance::offsetOfGlobals()));611 Value* globalsArray = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(), instanceValue(), safeCast<int32_t>(Instance::offsetOfGlobals())); 612 612 result = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, toB3Type(m_info.globals[index].type), origin(), globalsArray, safeCast<int32_t>(index * sizeof(Register))); 613 613 return { }; … … 617 617 { 618 618 ASSERT(toB3Type(m_info.globals[index].type) == value->type()); 619 Value* globalsArray = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(), instanceValue(), safeCast<int32_t>( JSWebAssemblyInstance::offsetOfGlobals()));619 Value* globalsArray = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(), instanceValue(), safeCast<int32_t>(Instance::offsetOfGlobals())); 620 620 m_currentBlock->appendNew<MemoryValue>(m_proc, Store, origin(), value, globalsArray, safeCast<int32_t>(index * sizeof(Register))); 621 621 return { }; … … 1082 1082 1083 1083 // FIXME imports can be linked here, instead of generating a patchpoint, because all import stubs are generated before B3 compilation starts. https://bugs.webkit.org/show_bug.cgi?id=166462 1084 Value* targetInstance = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(), instanceValue(), safeCast<int32_t>(JSWebAssemblyInstance::offsetOfTargetInstance(functionIndex))); 1084 Value* targetInstance = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(), instanceValue(), safeCast<int32_t>(Instance::offsetOfTargetInstance(functionIndex))); 1085 // The target instance is 0 unless the call is wasm->wasm. 1085 1086 Value* isWasmCall = m_currentBlock->appendNew<Value>(m_proc, NotEqual, origin(), targetInstance, m_currentBlock->appendNew<Const64Value>(m_proc, origin(), 0)); 1086 1087 … … 1114 1115 // https://bugs.webkit.org/show_bug.cgi?id=170375 1115 1116 Value* jumpDestination = isEmbedderBlock->appendNew<MemoryValue>(m_proc, 1116 Load, pointerType(), origin(), instanceValue(), safeCast<int32_t>( JSWebAssemblyInstance::offsetOfWasmToEmbedderStubExecutableAddress(functionIndex)));1117 Load, pointerType(), origin(), instanceValue(), safeCast<int32_t>(Instance::offsetOfWasmToEmbedderStubExecutableAddress(functionIndex))); 1117 1118 Value* embedderCallResult = wasmCallingConvention().setupCall(m_proc, isEmbedderBlock, origin(), args, toB3Type(returnType), 1118 1119 [&] (PatchpointValue* patchpoint) { … … 1179 1180 { 1180 1181 ExpressionType table = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(), 1181 instanceValue(), safeCast<int32_t>( JSWebAssemblyInstance::offsetOfWasmTable()));1182 instanceValue(), safeCast<int32_t>(Instance::offsetOfTable())); 1182 1183 callableFunctionBuffer = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(), 1183 1184 table, safeCast<int32_t>(Table::offsetOfFunctions())); … … 1262 1263 GPRReg baseMemory = pinnedRegs.baseMemoryPointer; 1263 1264 ASSERT(newContextInstance != baseMemory); 1264 jit.loadPtr(CCallHelpers::Address(oldContextInstance, JSWebAssemblyInstance::offsetOfCachedStackLimit()), baseMemory);1265 jit.storePtr(baseMemory, CCallHelpers::Address(newContextInstance, JSWebAssemblyInstance::offsetOfCachedStackLimit()));1265 jit.loadPtr(CCallHelpers::Address(oldContextInstance, Instance::offsetOfCachedStackLimit()), baseMemory); 1266 jit.storePtr(baseMemory, CCallHelpers::Address(newContextInstance, Instance::offsetOfCachedStackLimit())); 1266 1267 jit.storeWasmContextInstance(newContextInstance); 1267 jit.loadPtr(CCallHelpers::Address(newContextInstance, JSWebAssemblyInstance::offsetOfWasmMemory()), baseMemory); // Memory*.1268 jit.loadPtr(CCallHelpers::Address(newContextInstance, Instance::offsetOfMemory()), baseMemory); // Memory*. 1268 1269 ASSERT(sizeRegs.size() == 1); 1269 1270 ASSERT(sizeRegs[0].sizeRegister != baseMemory); -
trunk/Source/JavaScriptCore/wasm/WasmBinding.cpp
r223738 r224020 31 31 #include "CCallHelpers.h" 32 32 #include "JSCInlines.h" 33 #include "JSWebAssemblyInstance.h"34 33 #include "LinkBuffer.h" 34 #include "WasmInstance.h" 35 35 36 36 namespace JSC { namespace Wasm { … … 54 54 // B3's call codegen ensures that the JSCell is a WebAssemblyFunction. 55 55 jit.loadWasmContextInstance(sizeRegAsScratch); // Old Instance* 56 // Get the callee's W ebAssembly.Instance and set it as WasmContext's instance. The caller will take care of restoring its own Instance.57 jit.loadPtr(JIT::Address(sizeRegAsScratch, JSWebAssemblyInstance::offsetOfTargetInstance(importIndex)), baseMemory); // JSWebAssemblyInstance*.56 // Get the callee's Wasm::Instance and set it as WasmContext's instance. The caller will take care of restoring its own Instance. 57 jit.loadPtr(JIT::Address(sizeRegAsScratch, Instance::offsetOfTargetInstance(importIndex)), baseMemory); // Instance*. 58 58 // While we're accessing that cacheline, also get the wasm entrypoint so we can tail call to it below. 59 jit.loadPtr(JIT::Address(sizeRegAsScratch, JSWebAssemblyInstance::offsetOfWasmEntrypoint(importIndex)), scratch); // Wasm::WasmEntrypointLoadLocation.59 jit.loadPtr(JIT::Address(sizeRegAsScratch, Instance::offsetOfWasmEntrypoint(importIndex)), scratch); // Wasm::WasmEntrypointLoadLocation. 60 60 jit.storeWasmContextInstance(baseMemory); 61 61 62 jit.loadPtr(JIT::Address(sizeRegAsScratch, JSWebAssemblyInstance::offsetOfCachedStackLimit()), sizeRegAsScratch);63 jit.storePtr(sizeRegAsScratch, JIT::Address(baseMemory, JSWebAssemblyInstance::offsetOfCachedStackLimit()));62 jit.loadPtr(JIT::Address(sizeRegAsScratch, Instance::offsetOfCachedStackLimit()), sizeRegAsScratch); 63 jit.storePtr(sizeRegAsScratch, JIT::Address(baseMemory, Instance::offsetOfCachedStackLimit())); 64 64 65 // FIXME the following code assumes that all W ebAssembly.Instance have the same pinned registers. https://bugs.webkit.org/show_bug.cgi?id=16295265 // FIXME the following code assumes that all Wasm::Instance have the same pinned registers. https://bugs.webkit.org/show_bug.cgi?id=162952 66 66 // Set up the callee's baseMemory register as well as the memory size registers. 67 jit.loadPtr(JIT::Address(baseMemory, JSWebAssemblyInstance::offsetOfWasmMemory()), baseMemory); // Wasm::Memory*.67 jit.loadPtr(JIT::Address(baseMemory, Instance::offsetOfMemory()), baseMemory); // Wasm::Memory*. 68 68 ASSERT(!sizeRegs[0].sizeOffset); // The following code assumes we start at 0, and calculates subsequent size registers relative to 0. 69 69 jit.loadPtr(JIT::Address(baseMemory, Wasm::Memory::offsetOfSize()), sizeRegs[0].sizeRegister); // Memory size. -
trunk/Source/JavaScriptCore/wasm/WasmContext.cpp
r223738 r224020 29 29 #if ENABLE(WEBASSEMBLY) 30 30 31 #include "JSWebAssemblyInstance.h"32 31 #include "Options.h" 32 #include "WasmInstance.h" 33 33 34 34 #include <mutex> … … 46 46 } 47 47 48 JSWebAssemblyInstance* Context::load() const48 Instance* Context::load() const 49 49 { 50 50 #if ENABLE(FAST_TLS_JIT) 51 51 if (useFastTLS()) 52 return bitwise_cast< JSWebAssemblyInstance*>(_pthread_getspecific_direct(WTF_WASM_CONTEXT_KEY));52 return bitwise_cast<Instance*>(_pthread_getspecific_direct(WTF_WASM_CONTEXT_KEY)); 53 53 #endif 54 54 return instance; 55 55 } 56 56 57 void Context::store( JSWebAssemblyInstance* inst, void* softStackLimit)57 void Context::store(Instance* inst, void* softStackLimit) 58 58 { 59 59 #if ENABLE(FAST_TLS_JIT) -
trunk/Source/JavaScriptCore/wasm/WasmContext.h
r223738 r224020 28 28 #if ENABLE(WEBASSEMBLY) 29 29 30 namespace JSC { 30 namespace JSC { namespace Wasm { 31 31 32 class JSWebAssemblyInstance; 33 34 namespace Wasm { 32 class Instance; 35 33 36 34 struct Context { 37 JSWebAssemblyInstance* instance { nullptr };35 Instance* instance { nullptr }; 38 36 39 JSWebAssemblyInstance* load() const;40 void store( JSWebAssemblyInstance*, void* softStackLimit);37 Instance* load() const; 38 void store(Instance*, void* softStackLimit); 41 39 42 40 static bool useFastTLS(); -
trunk/Source/JavaScriptCore/wasm/WasmEmbedder.h
r223738 r224020 38 38 39 39 class ExecState; 40 class JSWebAssemblyInstance; // FIXME this should be Wasm::Instance, so should use below. https://webkit.org/b/17747241 40 42 41 namespace Wasm { 43 42 44 43 struct CompilationContext; 44 class Instance; 45 45 struct InternalFunction; 46 46 struct ModuleInformation; … … 52 52 53 53 // Called as soon as an exception is detected. The return value is the PC to continue at. 54 using ThrowWasmException = void* (*)(ExecState*, Wasm::ExceptionType, JSWebAssemblyInstance*);54 using ThrowWasmException = void* (*)(ExecState*, Wasm::ExceptionType, Instance*); 55 55 56 56 } } // namespace JSC::Wasm -
trunk/Source/JavaScriptCore/wasm/WasmInstance.cpp
r223875 r224020 41 41 } 42 42 43 Instance::Instance(Ref<Module>&& module, EntryFrame** topEntryFramePointer) 44 : m_module(WTFMove(module)) 43 Instance::Instance(Context* context, Ref<Module>&& module, EntryFrame** topEntryFramePointer) 44 : m_context(context) 45 , m_module(WTFMove(module)) 45 46 , m_globals(MallocPtr<uint64_t>::malloc(globalMemoryByteSize(m_module.get()))) 46 47 , m_topEntryFramePointer(topEntryFramePointer) 48 , m_numImportFunctions(m_module->moduleInformation().importFunctionCount()) 47 49 { 50 for (unsigned i = 0; i < m_numImportFunctions; ++i) 51 new (importFunctionInfo(i)) ImportFunctionInfo(); 52 } 53 54 Ref<Instance> Instance::create(Context* context, Ref<Module>&& module, EntryFrame** topEntryFramePointer) 55 { 56 return adoptRef(*new (NotNull, fastMalloc(allocationSize(module->moduleInformation().importFunctionCount()))) Instance(context, WTFMove(module), topEntryFramePointer)); 48 57 } 49 58 … … 52 61 size_t Instance::extraMemoryAllocated() const 53 62 { 54 return globalMemoryByteSize(m_module.get()) ;63 return globalMemoryByteSize(m_module.get()) + allocationSize(m_numImportFunctions); 55 64 } 56 65 -
trunk/Source/JavaScriptCore/wasm/WasmInstance.h
r223875 r224020 39 39 namespace JSC { namespace Wasm { 40 40 41 struct Context; 42 41 43 class Instance : public ThreadSafeRefCounted<Instance> { 42 44 public: 43 static Ref<Instance> create(Ref<Module>&& module, EntryFrame** topEntryFramePointer) 45 static Ref<Instance> create(Context* context, Ref<Module>&& module, EntryFrame** topEntryFramePointer); 46 47 void finalizeCreation(void* owner, Ref<CodeBlock>&& codeBlock) 44 48 { 45 return adoptRef(*new Instance(WTFMove(module), topEntryFramePointer)); 46 } 47 48 void finalizeCreation(Ref<CodeBlock>&& codeBlock) 49 { 49 m_owner = owner; 50 50 m_codeBlock = WTFMove(codeBlock); 51 51 } … … 53 53 JS_EXPORT_PRIVATE ~Instance(); 54 54 55 template<typename T> T* owner() const { return reinterpret_cast<T*>(m_owner); } 56 static ptrdiff_t offsetOfOwner() { return OBJECT_OFFSETOF(Instance, m_owner); } 57 55 58 size_t extraMemoryAllocated() const; 59 60 Wasm::Context* context() const { return m_context; } 56 61 57 62 Module& module() { return m_module.get(); } … … 59 64 Memory* memory() { return m_memory.get(); } 60 65 Table* table() { return m_table.get(); } 66 67 void setMemory(Ref<Memory>&& memory) { m_memory = WTFMove(memory); } 68 void setTable(Ref<Table>&& table) { m_table = WTFMove(table); } 61 69 62 70 int32_t loadI32Global(unsigned i) const { return m_globals.get()[i]; } … … 66 74 void setGlobal(unsigned i, int64_t bits) { m_globals.get()[i] = bits; } 67 75 76 static ptrdiff_t offsetOfMemory() { return OBJECT_OFFSETOF(Instance, m_memory); } 77 static ptrdiff_t offsetOfGlobals() { return OBJECT_OFFSETOF(Instance, m_globals); } 78 static ptrdiff_t offsetOfTable() { return OBJECT_OFFSETOF(Instance, m_table); } 68 79 static ptrdiff_t offsetOfTopEntryFramePointer() { return OBJECT_OFFSETOF(Instance, m_topEntryFramePointer); } 69 80 … … 72 83 void setCachedStackLimit(void* limit) { m_cachedStackLimit = limit; } 73 84 74 friend class JSC::JSWebAssemblyInstance; // FIXME remove this once refactored https://webkit.org/b/177472. 85 // Tail accessors. 86 static size_t offsetOfTail() { return WTF::roundUpToMultipleOf<sizeof(uint64_t)>(sizeof(Instance)); } 87 struct ImportFunctionInfo { 88 // Target instance and entrypoint are only set for wasm->wasm calls, and are otherwise nullptr. The embedder-specific logic occurs through import function. 89 Instance* targetInstance { nullptr }; 90 Wasm::WasmEntrypointLoadLocation wasmEntrypoint { nullptr }; 91 void* wasmToEmbedderStubExecutableAddress { nullptr }; 92 void* importFunction { nullptr }; // In a JS embedding, this is a WriteBarrier<JSObject>. 93 }; 94 unsigned numImportFunctions() const { return m_numImportFunctions; } 95 ImportFunctionInfo* importFunctionInfo(size_t importFunctionNum) 96 { 97 RELEASE_ASSERT(importFunctionNum < m_numImportFunctions); 98 return &bitwise_cast<ImportFunctionInfo*>(bitwise_cast<char*>(this) + offsetOfTail())[importFunctionNum]; 99 } 100 static size_t offsetOfTargetInstance(size_t importFunctionNum) { return offsetOfTail() + importFunctionNum * sizeof(ImportFunctionInfo) + OBJECT_OFFSETOF(ImportFunctionInfo, targetInstance); } 101 static size_t offsetOfWasmEntrypoint(size_t importFunctionNum) { return offsetOfTail() + importFunctionNum * sizeof(ImportFunctionInfo) + OBJECT_OFFSETOF(ImportFunctionInfo, wasmEntrypoint); } 102 static size_t offsetOfWasmToEmbedderStubExecutableAddress(size_t importFunctionNum) { return offsetOfTail() + importFunctionNum * sizeof(ImportFunctionInfo) + OBJECT_OFFSETOF(ImportFunctionInfo, wasmToEmbedderStubExecutableAddress); } 103 static size_t offsetOfImportFunction(size_t importFunctionNum) { return offsetOfTail() + importFunctionNum * sizeof(ImportFunctionInfo) + OBJECT_OFFSETOF(ImportFunctionInfo, importFunction); } 104 template<typename T> T* importFunction(unsigned importFunctionNum) { return reinterpret_cast<T*>(&importFunctionInfo(importFunctionNum)->importFunction); } 75 105 76 106 private: 77 Instance(Ref<Module>&&, EntryFrame**); 107 Instance(Context* context, Ref<Module>&&, EntryFrame**); 108 109 static size_t allocationSize(Checked<size_t> numImportFunctions) 110 { 111 return (offsetOfTail() + sizeof(ImportFunctionInfo) * numImportFunctions).unsafeGet(); 112 } 78 113 114 void* m_owner { nullptr }; // In a JS embedding, this is a JSWebAssemblyInstance*. 115 Context* m_context { nullptr }; 79 116 Ref<Module> m_module; 80 117 RefPtr<CodeBlock> m_codeBlock; … … 84 121 EntryFrame** m_topEntryFramePointer { nullptr }; 85 122 void* m_cachedStackLimit { bitwise_cast<void*>(std::numeric_limits<uintptr_t>::max()) }; 123 124 unsigned m_numImportFunctions { 0 }; 86 125 }; 87 126 -
trunk/Source/JavaScriptCore/wasm/WasmOMGPlan.cpp
r223738 r224020 32 32 #include "B3OpaqueByproducts.h" 33 33 #include "JSCInlines.h" 34 #include "JSWebAssemblyInstance.h"35 34 #include "LinkBuffer.h" 36 35 #include "WasmB3IRGenerator.h" 37 36 #include "WasmCallee.h" 38 37 #include "WasmContext.h" 38 #include "WasmInstance.h" 39 39 #include "WasmMachineThreads.h" 40 40 #include "WasmMemory.h" … … 164 164 } 165 165 166 void OMGPlan::runForIndex( JSWebAssemblyInstance* instance, uint32_t functionIndex)166 void OMGPlan::runForIndex(Instance* instance, uint32_t functionIndex) 167 167 { 168 Wasm::CodeBlock& codeBlock = instance->wasmCodeBlock();169 ASSERT(instance-> wasmMemory()->mode() == codeBlock.mode());168 Wasm::CodeBlock& codeBlock = *instance->codeBlock(); 169 ASSERT(instance->memory()->mode() == codeBlock.mode()); 170 170 171 171 if (codeBlock.tierUpCount(functionIndex).shouldStartTierUp()) { 172 Ref<Plan> plan = adoptRef(*new OMGPlan(instance->context(), Ref<Wasm::Module>(instance-> wasmModule()), functionIndex, codeBlock.mode(), Plan::dontFinalize()));172 Ref<Plan> plan = adoptRef(*new OMGPlan(instance->context(), Ref<Wasm::Module>(instance->module()), functionIndex, codeBlock.mode(), Plan::dontFinalize())); 173 173 ensureWorklist().enqueue(plan.copyRef()); 174 174 if (UNLIKELY(!Options::useConcurrentJIT())) -
trunk/Source/JavaScriptCore/wasm/WasmOMGPlan.h
r223738 r224020 46 46 bool multiThreaded() const override { return false; } 47 47 48 static void runForIndex( JSWebAssemblyInstance*, uint32_t functionIndex);48 static void runForIndex(Instance*, uint32_t functionIndex); 49 49 50 50 private: -
trunk/Source/JavaScriptCore/wasm/WasmTable.cpp
r223738 r224020 56 56 // But for now, we're not doing that. 57 57 m_functions = MallocPtr<Wasm::CallableFunction>::malloc(sizeof(Wasm::CallableFunction) * static_cast<size_t>(size())); 58 m_instances = MallocPtr< JSWebAssemblyInstance*>::malloc(sizeof(JSWebAssemblyInstance*) * static_cast<size_t>(size()));58 m_instances = MallocPtr<Instance*>::malloc(sizeof(Instance*) * static_cast<size_t>(size())); 59 59 for (uint32_t i = 0; i < size(); ++i) { 60 60 new (&m_functions.get()[i]) CallableFunction(); … … 111 111 } 112 112 113 void Table::setFunction(uint32_t index, CallableFunction function, JSWebAssemblyInstance* instance)113 void Table::setFunction(uint32_t index, CallableFunction function, Instance* instance) 114 114 { 115 115 RELEASE_ASSERT(index < size()); -
trunk/Source/JavaScriptCore/wasm/WasmTable.h
r223738 r224020 35 35 #include <wtf/ThreadSafeRefCounted.h> 36 36 37 namespace JSC { 37 namespace JSC { namespace Wasm { 38 38 39 class JSWebAssemblyInstance; // FIXME this should be Wasm::Instance https://webkit.org/b/177472 40 41 namespace Wasm { 39 class Instance; 42 40 43 41 class Table : public ThreadSafeRefCounted<Table> { … … 51 49 std::optional<uint32_t> grow(uint32_t delta) WARN_UNUSED_RETURN; 52 50 void clearFunction(uint32_t); 53 void setFunction(uint32_t, CallableFunction, JSWebAssemblyInstance*); // FIXME make this Wasm::Instance. https://webkit.org/b/17747251 void setFunction(uint32_t, CallableFunction, Instance*); 54 52 55 53 static ptrdiff_t offsetOfSize() { return OBJECT_OFFSETOF(Table, m_size); } … … 66 64 MallocPtr<CallableFunction> m_functions; 67 65 // call_indirect needs to do an Instance check to potentially context switch when calling a function to another instance. We can hold raw pointers to Instance here because the embedder ensures that Table keeps all the instances alive. We couldn't hold a Ref here because it would cause cycles. 68 MallocPtr< JSWebAssemblyInstance*> m_instances; // FIXME make this a Wasm::Instance. https://webkit.org/b/17747266 MallocPtr<Instance*> m_instances; 69 67 }; 70 68 -
trunk/Source/JavaScriptCore/wasm/WasmThunks.cpp
r223875 r224020 32 32 #include "HeapCellInlines.h" 33 33 #include "JITExceptions.h" 34 #include "JSWebAssemblyInstance.h"35 34 #include "LinkBuffer.h" 36 35 #include "ScratchRegisterAllocator.h" 37 36 #include "WasmContext.h" 38 37 #include "WasmExceptionType.h" 38 #include "WasmInstance.h" 39 39 #include "WasmOMGPlan.h" 40 40 … … 48 48 // We're allowed to use temp registers here. We are not allowed to use callee saves. 49 49 jit.loadWasmContextInstance(GPRInfo::argumentGPR2); 50 jit.loadPtr(CCallHelpers::Address(GPRInfo::argumentGPR2, JSWebAssemblyInstance::offsetOfTopEntryFramePointer()), GPRInfo::argumentGPR0);50 jit.loadPtr(CCallHelpers::Address(GPRInfo::argumentGPR2, Instance::offsetOfTopEntryFramePointer()), GPRInfo::argumentGPR0); 51 51 jit.loadPtr(CCallHelpers::Address(GPRInfo::argumentGPR0), GPRInfo::argumentGPR0); 52 52 jit.copyCalleeSavesToEntryFrameCalleeSavesBuffer(GPRInfo::argumentGPR0); … … 92 92 93 93 jit.loadWasmContextInstance(GPRInfo::argumentGPR0); 94 typedef void (*Run)( JSWebAssemblyInstance*, uint32_t);94 typedef void (*Run)(Instance*, uint32_t); 95 95 Run run = OMGPlan::runForIndex; 96 96 jit.move(MacroAssembler::TrustedImmPtr(reinterpret_cast<void*>(run)), GPRInfo::argumentGPR2); -
trunk/Source/JavaScriptCore/wasm/js/JSToWasm.cpp
r223907 r224020 113 113 ptrdiff_t jsOffset = CallFrameSlot::thisArgument * sizeof(EncodedJSValue); 114 114 115 // vmEntryToWasm passes Wasm::Context*'s instance as the first JS argument when we're 116 // not using fast TLS to hold the Wasm::Context*'s instance. 115 // vmEntryToWasm passes the JSWebAssemblyInstance corresponding to Wasm::Context*'s 116 // instance as the first JS argument when we're not using fast TLS to hold the 117 // Wasm::Context*'s instance. 117 118 if (!Context::useFastTLS()) { 118 119 jit.loadPtr(CCallHelpers::Address(GPRInfo::callFrameRegister, jsOffset), wasmContextInstanceGPR); 120 jit.loadPtr(CCallHelpers::Address(wasmContextInstanceGPR, JSWebAssemblyInstance::offsetOfInstance()), wasmContextInstanceGPR); 119 121 jsOffset += sizeof(EncodedJSValue); 120 122 } … … 173 175 174 176 if (!Context::useFastTLS()) 175 jit.loadPtr(CCallHelpers::Address(wasmContextInstanceGPR, JSWebAssemblyInstance::offsetOfWasmMemory()), baseMemory);177 jit.loadPtr(CCallHelpers::Address(wasmContextInstanceGPR, Instance::offsetOfMemory()), baseMemory); 176 178 else { 177 179 jit.loadWasmContextInstance(baseMemory); 178 jit.loadPtr(CCallHelpers::Address(baseMemory, JSWebAssemblyInstance::offsetOfWasmMemory()), baseMemory);180 jit.loadPtr(CCallHelpers::Address(baseMemory, Instance::offsetOfMemory()), baseMemory); 179 181 } 180 182 -
trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp
r223875 r224020 50 50 } 51 51 52 JSWebAssemblyInstance::JSWebAssemblyInstance(VM& vm, Structure* structure, unsigned numImportFunctions,Ref<Wasm::Instance>&& instance)52 JSWebAssemblyInstance::JSWebAssemblyInstance(VM& vm, Structure* structure, Ref<Wasm::Instance>&& instance) 53 53 : Base(vm, structure) 54 54 , m_instance(WTFMove(instance)) 55 , m_vm(&vm) 56 , m_wasmModule(m_instance->module()) 57 , m_wasmTable(m_instance->m_table.get()) 58 , m_globals(m_instance->m_globals.get()) 59 , m_topEntryFramePointer(m_instance->m_topEntryFramePointer) 60 , m_numImportFunctions(numImportFunctions) 61 { 62 for (unsigned i = 0; i < m_numImportFunctions; ++i) 63 new (importFunctionInfo(i)) ImportFunctionInfo(); 55 { 56 for (unsigned i = 0; i < this->instance().numImportFunctions(); ++i) 57 new (this->instance().importFunction<WriteBarrier<JSObject>>(i)) WriteBarrier<JSObject>(); 64 58 } 65 59 … … 94 88 visitor.append(thisObject->m_callee); 95 89 visitor.reportExtraMemoryVisited(thisObject->m_instance->extraMemoryAllocated()); 96 for (unsigned i = 0; i < thisObject-> m_numImportFunctions; ++i)97 visitor.append( thisObject->importFunctionInfo(i)->importFunction); // This also keeps the functions' JSWebAssemblyInstance alive.90 for (unsigned i = 0; i < thisObject->instance().numImportFunctions(); ++i) 91 visitor.append(*thisObject->instance().importFunction<WriteBarrier<JSObject>>(i)); // This also keeps the functions' JSWebAssemblyInstance alive. 98 92 } 99 93 100 94 void JSWebAssemblyInstance::finalizeCreation(VM& vm, ExecState* exec, Ref<Wasm::CodeBlock>&& wasmCodeBlock) 101 95 { 102 m_instance->finalizeCreation(wasmCodeBlock.copyRef()); 103 m_wasmCodeBlock = wasmCodeBlock.ptr(); 96 m_instance->finalizeCreation(this, wasmCodeBlock.copyRef()); 104 97 105 98 auto scope = DECLARE_THROW_SCOPE(vm); … … 120 113 m_codeBlock.set(vm, this, jsCodeBlock); 121 114 } else { 122 jsCodeBlock = JSWebAssemblyCodeBlock::create(vm, WTFMove(wasmCodeBlock), wasmModule().moduleInformation());115 jsCodeBlock = JSWebAssemblyCodeBlock::create(vm, WTFMove(wasmCodeBlock), module()->module().moduleInformation()); 123 116 if (UNLIKELY(!jsCodeBlock->runnable())) { 124 117 throwException(exec, scope, JSWebAssemblyLinkError::create(exec, vm, globalObject()->WebAssemblyLinkErrorStructure(), jsCodeBlock->errorMessage())); … … 129 122 } 130 123 131 for ( size_t importFunctionNum = 0; importFunctionNum < m_numImportFunctions; ++importFunctionNum) {132 ImportFunctionInfo* info =importFunctionInfo(importFunctionNum);124 for (unsigned importFunctionNum = 0; importFunctionNum < instance().numImportFunctions(); ++importFunctionNum) { 125 auto* info = instance().importFunctionInfo(importFunctionNum); 133 126 info->wasmToEmbedderStubExecutableAddress = m_codeBlock->wasmToEmbedderStubExecutableAddress(importFunctionNum); 134 127 } … … 172 165 JSModuleNamespaceObject* moduleNamespace = moduleRecord->getModuleNamespace(exec); 173 166 // FIXME: These objects could be pretty big we should try to throw OOM here. 174 auto* jsInstance = new (NotNull, allocateCell<JSWebAssemblyInstance>(vm.heap , allocationSize(moduleInformation.importFunctionCount()))) JSWebAssemblyInstance(vm, instanceStructure, moduleInformation.importFunctionCount(), WTFMove(instance));167 auto* jsInstance = new (NotNull, allocateCell<JSWebAssemblyInstance>(vm.heap)) JSWebAssemblyInstance(vm, instanceStructure, WTFMove(instance)); 175 168 jsInstance->finishCreation(vm, jsModule, moduleNamespace); 176 169 RETURN_IF_EXCEPTION(throwScope, nullptr); … … 204 197 return exception(createJSWebAssemblyLinkError(exec, vm, importFailMessage(import, "import function", "must be callable"))); 205 198 206 JSWebAssemblyInstance* calleeInstance = nullptr;199 Wasm::Instance* calleeInstance = nullptr; 207 200 Wasm::WasmEntrypointLoadLocation wasmEntrypoint = nullptr; 208 201 JSObject* function = jsCast<JSObject*>(value); … … 216 209 if (wasmFunction) { 217 210 importedSignatureIndex = wasmFunction->signatureIndex(); 218 calleeInstance = wasmFunction->instance();211 calleeInstance = &wasmFunction->instance()->instance(); 219 212 wasmEntrypoint = wasmFunction->wasmEntrypointLoadLocation(); 220 213 } … … 235 228 236 229 ASSERT(numImportFunctions == import.kindIndex); 237 ImportFunctionInfo* info = jsInstance->importFunctionInfo(numImportFunctions++);230 auto* info = jsInstance->instance().importFunctionInfo(numImportFunctions); 238 231 info->targetInstance = calleeInstance; 239 232 info->wasmEntrypoint = wasmEntrypoint; 240 info->importFunction.set(vm, jsInstance, function); 233 jsInstance->instance().importFunction<WriteBarrier<JSObject>>(numImportFunctions)->set(vm, jsInstance, function); 234 ++numImportFunctions; 241 235 // v. Append closure to imports. 242 236 break; … … 266 260 // ii. Append v to tables. 267 261 // iii. Append v.[[Table]] to imports. 268 jsInstance-> m_table.set(vm, jsInstance, table);269 jsInstance->m_wasmTable = table->table();262 jsInstance->setTable(vm, table); 263 RETURN_IF_EXCEPTION(throwScope, nullptr); 270 264 break; 271 265 } … … 297 291 // ii. Append v to memories. 298 292 // iii. Append v.[[Memory]] to imports. 299 ASSERT(!jsInstance->m_memory);300 293 jsInstance->setMemory(vm, memory); 301 294 RETURN_IF_EXCEPTION(throwScope, nullptr); … … 375 368 throwScope.assertNoException(); 376 369 ASSERT(table); 377 jsInstance-> m_table.set(vm, jsInstance, table);378 jsInstance->m_wasmTable = table->table();370 jsInstance->setTable(vm, table); 371 RETURN_IF_EXCEPTION(throwScope, nullptr); 379 372 } 380 373 } -
trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.h
r223875 r224020 33 33 #include "JSWebAssemblyMemory.h" 34 34 #include "JSWebAssemblyTable.h" 35 #include "WasmContext.h"36 35 #include "WasmInstance.h" 37 36 … … 44 43 namespace Wasm { 45 44 class CodeBlock; 46 class Table; // FIXME remove this after refactoring. https://webkit.org/b/17747247 45 } 48 46 … … 59 57 60 58 Wasm::Instance& instance() { return m_instance.get(); } 61 Wasm::Context* context() const { return &m_vm->wasmContext; }62 59 JSModuleNamespaceObject* moduleNamespaceObject() { return m_moduleNamespaceObject.get(); } 63 JSWebAssemblyTable* table() { return m_table.get(); }64 60 WebAssemblyToJSCallee* webAssemblyToJSCallee() { return m_callee.get(); } 65 61 66 62 JSWebAssemblyMemory* memory() { return m_memory.get(); } 67 void setMemory(VM& vm, JSWebAssemblyMemory* value) { ASSERT(!memory()); m_memory.set(vm, this, value); m_wasmMemory = &memory()->memory(); } 63 void setMemory(VM& vm, JSWebAssemblyMemory* value) { 64 ASSERT(!memory()); 65 m_memory.set(vm, this, value); 66 instance().setMemory(makeRef(memory()->memory())); 67 } 68 68 Wasm::MemoryMode memoryMode() { return memory()->memory().mode(); } 69 69 70 // Tail accessors. 71 static size_t offsetOfTail() { return WTF::roundUpToMultipleOf<sizeof(uint64_t)>(sizeof(JSWebAssemblyInstance)); } 72 struct ImportFunctionInfo { 73 // Target instance and entrypoint are only set for wasm->wasm calls, and are otherwise nullptr. The embedder-specific logic occurs through import function. 74 JSWebAssemblyInstance* targetInstance { nullptr }; 75 Wasm::WasmEntrypointLoadLocation wasmEntrypoint { nullptr }; 76 void* wasmToEmbedderStubExecutableAddress { nullptr }; 77 WriteBarrier<JSObject> importFunction { WriteBarrier<JSObject>() }; 78 }; 79 ImportFunctionInfo* importFunctionInfo(size_t importFunctionNum) 80 { 81 RELEASE_ASSERT(importFunctionNum < m_numImportFunctions); 82 return &bitwise_cast<ImportFunctionInfo*>(bitwise_cast<char*>(this) + offsetOfTail())[importFunctionNum]; 70 JSWebAssemblyTable* table() { return m_table.get(); } 71 void setTable(VM& vm, JSWebAssemblyTable* value) { 72 ASSERT(!table()); 73 m_table.set(vm, this, value); 74 instance().setTable(makeRef(*table()->table())); 83 75 } 84 static size_t offsetOfTargetInstance(size_t importFunctionNum) { return offsetOfTail() + importFunctionNum * sizeof(ImportFunctionInfo) + OBJECT_OFFSETOF(ImportFunctionInfo, targetInstance); }85 static size_t offsetOfWasmEntrypoint(size_t importFunctionNum) { return offsetOfTail() + importFunctionNum * sizeof(ImportFunctionInfo) + OBJECT_OFFSETOF(ImportFunctionInfo, wasmEntrypoint); }86 static size_t offsetOfWasmToEmbedderStubExecutableAddress(size_t importFunctionNum) { return offsetOfTail() + importFunctionNum * sizeof(ImportFunctionInfo) + OBJECT_OFFSETOF(ImportFunctionInfo, wasmToEmbedderStubExecutableAddress); }87 static size_t offsetOfImportFunction(size_t importFunctionNum) { return offsetOfTail() + importFunctionNum * sizeof(ImportFunctionInfo) + OBJECT_OFFSETOF(ImportFunctionInfo, importFunction); }88 JSObject* importFunction(unsigned importFunctionNum) { return importFunctionInfo(importFunctionNum)->importFunction.get(); }89 76 90 // FIXME remove these after refactoring them out. https://webkit.org/b/177472 91 Wasm::Memory& internalMemory() { return memory()->memory(); } 92 Wasm::CodeBlock& wasmCodeBlock() const { return *m_instance->codeBlock(); } 93 static ptrdiff_t offsetOfWasmTable() { return OBJECT_OFFSETOF(JSWebAssemblyInstance, m_wasmTable); } 94 static ptrdiff_t offsetOfCallee() { return OBJECT_OFFSETOF(JSWebAssemblyInstance, m_callee); } 95 static ptrdiff_t offsetOfGlobals() { return OBJECT_OFFSETOF(JSWebAssemblyInstance, m_globals); } 96 static ptrdiff_t offsetOfCodeBlock() { return OBJECT_OFFSETOF(JSWebAssemblyInstance, m_codeBlock); } 97 static ptrdiff_t offsetOfWasmCodeBlock() { return OBJECT_OFFSETOF(JSWebAssemblyInstance, m_wasmCodeBlock); } 98 static ptrdiff_t offsetOfCachedStackLimit() { return OBJECT_OFFSETOF(JSWebAssemblyInstance, m_cachedStackLimit); } 99 static ptrdiff_t offsetOfWasmMemory() { return OBJECT_OFFSETOF(JSWebAssemblyInstance, m_wasmMemory); } 100 static ptrdiff_t offsetOfTopEntryFramePointer() { return OBJECT_OFFSETOF(JSWebAssemblyInstance, m_topEntryFramePointer); } 101 void* cachedStackLimit() const { RELEASE_ASSERT(m_instance->cachedStackLimit() == m_cachedStackLimit); return m_cachedStackLimit; } 102 void setCachedStackLimit(void* limit) { m_instance->setCachedStackLimit(limit); m_cachedStackLimit = limit; } 103 Wasm::Memory* wasmMemory() { return m_wasmMemory; } 104 Wasm::Module& wasmModule() { return m_wasmModule; } 77 static size_t offsetOfInstance() { return OBJECT_OFFSETOF(JSWebAssemblyInstance, m_instance); } 78 static size_t offsetOfCallee() { return OBJECT_OFFSETOF(JSWebAssemblyInstance, m_callee); } 105 79 106 80 protected: 107 JSWebAssemblyInstance(VM&, Structure*, unsigned numImportFunctions,Ref<Wasm::Instance>&&);81 JSWebAssemblyInstance(VM&, Structure*, Ref<Wasm::Instance>&&); 108 82 void finishCreation(VM&, JSWebAssemblyModule*, JSModuleNamespaceObject*); 109 83 static void destroy(JSCell*); 110 84 static void visitChildren(JSCell*, SlotVisitor&); 111 112 static size_t allocationSize(Checked<size_t> numImportFunctions)113 {114 return (offsetOfTail() + sizeof(ImportFunctionInfo) * numImportFunctions).unsafeGet();115 }116 85 117 86 private: … … 120 89 Ref<Wasm::Instance> m_instance; 121 90 122 VM* m_vm;123 91 WriteBarrier<JSWebAssemblyModule> m_module; 124 92 WriteBarrier<JSWebAssemblyCodeBlock> m_codeBlock; … … 127 95 WriteBarrier<JSWebAssemblyTable> m_table; 128 96 WriteBarrier<WebAssemblyToJSCallee> m_callee; 129 130 // FIXME remove these after refactoring them out. https://webkit.org/b/177472131 void* m_cachedStackLimit { bitwise_cast<void*>(std::numeric_limits<uintptr_t>::max()) };132 Wasm::CodeBlock* m_wasmCodeBlock { nullptr };133 Wasm::Module& m_wasmModule;134 Wasm::Memory* m_wasmMemory { nullptr };135 Wasm::Table* m_wasmTable { nullptr };136 uint64_t* m_globals { nullptr };137 EntryFrame** m_topEntryFramePointer { nullptr };138 139 unsigned m_numImportFunctions;140 97 }; 141 98 -
trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.cpp
r223738 r224020 30 30 31 31 #include "JSCInlines.h" 32 #include "JSWebAssemblyInstance.h" 32 33 33 34 namespace JSC { … … 122 123 void JSWebAssemblyTable::setFunction(VM& vm, uint32_t index, WebAssemblyFunction* function) 123 124 { 124 m_table->setFunction(index, function->callableFunction(), function->instance());125 m_table->setFunction(index, function->callableFunction(), &function->instance()->instance()); 125 126 m_jsFunctions.get()[index].set(vm, this, function); 126 127 } … … 128 129 void JSWebAssemblyTable::setFunction(VM& vm, uint32_t index, WebAssemblyWrapperFunction* function) 129 130 { 130 m_table->setFunction(index, function->callableFunction(), function->instance());131 m_table->setFunction(index, function->callableFunction(), &function->instance()->instance()); 131 132 m_jsFunctions.get()[index].set(vm, this, function); 132 133 } -
trunk/Source/JavaScriptCore/wasm/js/WasmToJS.cpp
r223738 r224020 41 41 #include "WasmContext.h" 42 42 #include "WasmExceptionType.h" 43 #include "WasmInstance.h" 43 44 44 45 namespace JSC { namespace Wasm { … … 50 51 // We're calling out of the current WebAssembly.Instance. That Instance has a list of all its import functions. 51 52 jit.loadWasmContextInstance(result); 52 jit.loadPtr(JIT::Address(result, JSWebAssemblyInstance::offsetOfImportFunction(importIndex)), result);53 jit.loadPtr(JIT::Address(result, Instance::offsetOfImportFunction(importIndex)), result); 53 54 } 54 55 … … 83 84 84 85 // Store Callee. 86 jit.loadPtr(CCallHelpers::Address(GPRInfo::argumentGPR1, Instance::offsetOfOwner()), GPRInfo::argumentGPR1); 85 87 jit.loadPtr(CCallHelpers::Address(GPRInfo::argumentGPR1, JSWebAssemblyInstance::offsetOfCallee()), GPRInfo::argumentGPR2); 86 88 jit.storePtr(GPRInfo::argumentGPR2, JIT::Address(GPRInfo::callFrameRegister, CallFrameSlot::callee * static_cast<int>(sizeof(Register)))); … … 278 280 279 281 jit.loadWasmContextInstance(GPRInfo::argumentGPR0); 282 jit.loadPtr(CCallHelpers::Address(GPRInfo::argumentGPR0, Instance::offsetOfOwner()), GPRInfo::argumentGPR0); 280 283 jit.loadPtr(CCallHelpers::Address(GPRInfo::argumentGPR0, JSWebAssemblyInstance::offsetOfCallee()), GPRInfo::argumentGPR0); 281 284 jit.storePtr(GPRInfo::argumentGPR0, JIT::Address(GPRInfo::callFrameRegister, CallFrameSlot::callee * static_cast<int>(sizeof(Register)))); … … 287 290 auto noException = jit.emitExceptionCheck(*vm, AssemblyHelpers::InvertedExceptionCheck); 288 291 289 // exception here.292 // Exception here. 290 293 jit.copyCalleeSavesToEntryFrameCalleeSavesBuffer(vm->topEntryFrame); 291 294 jit.move(GPRInfo::callFrameRegister, GPRInfo::argumentGPR0); … … 460 463 461 464 jit.loadWasmContextInstance(GPRInfo::argumentGPR0); 465 jit.loadPtr(CCallHelpers::Address(GPRInfo::argumentGPR0, Instance::offsetOfOwner()), GPRInfo::argumentGPR0); 462 466 jit.loadPtr(CCallHelpers::Address(GPRInfo::argumentGPR0, JSWebAssemblyInstance::offsetOfCallee()), GPRInfo::argumentGPR0); 463 467 jit.storePtr(GPRInfo::argumentGPR0, JIT::Address(GPRInfo::callFrameRegister, CallFrameSlot::callee * static_cast<int>(sizeof(Register)))); … … 629 633 } 630 634 631 void* wasmToJSException(ExecState* exec, Wasm::ExceptionType type, JSWebAssemblyInstance* instance)635 void* wasmToJSException(ExecState* exec, Wasm::ExceptionType type, Instance* wasmInstance) 632 636 { 637 JSWebAssemblyInstance* instance = wasmInstance->owner<JSWebAssemblyInstance>(); 633 638 VM* vm = instance->vm(); 634 639 NativeCallFrameTracer tracer(vm, exec); -
trunk/Source/JavaScriptCore/wasm/js/WasmToJS.h
r223738 r224020 41 41 namespace Wasm { 42 42 43 class Instance; 44 43 45 Expected<MacroAssemblerCodeRef, BindingFailure> wasmToJS(VM*, Bag<CallLinkInfo>& callLinkInfos, SignatureIndex, unsigned importIndex); 44 46 45 void* wasmToJSException(ExecState*, Wasm::ExceptionType, JSWebAssemblyInstance*);47 void* wasmToJSException(ExecState*, Wasm::ExceptionType, Instance*); 46 48 47 49 } } // namespace JSC::Wasm -
trunk/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp
r223738 r224020 84 84 Vector<JSValue> boxedArgs; 85 85 JSWebAssemblyInstance* instance = wasmFunction->instance(); 86 Wasm::Instance* wasmInstance = &instance->instance(); 86 87 // When we don't use fast TLS to store the context, the JS 87 // entry wrapper expects the instance as the first argument.88 // entry wrapper expects a JSWebAssemblyInstance as the first argument. 88 89 if (!Wasm::Context::useFastTLS()) 89 90 boxedArgs.append(instance); … … 128 129 129 130 // FIXME Do away with this entire function, and only use the entrypoint generated by B3. https://bugs.webkit.org/show_bug.cgi?id=166486 130 JSWebAssemblyInstance* prevInstance = vm.wasmContext.load();131 Wasm::Instance* prevWasmInstance = vm.wasmContext.load(); 131 132 { 132 133 // We do the stack check here for the wrapper function because we don't … … 138 139 return JSValue::encode(throwException(exec, scope, createStackOverflowError(exec))); 139 140 } 140 vm.wasmContext.store( instance, vm.softStackLimit());141 vm.wasmContext.store(wasmInstance, vm.softStackLimit()); 141 142 ASSERT(wasmFunction->instance()); 142 ASSERT( wasmFunction->instance() == vm.wasmContext.load());143 ASSERT(&wasmFunction->instance()->instance() == vm.wasmContext.load()); 143 144 EncodedJSValue rawResult = vmEntryToWasm(wasmFunction->jsEntrypoint(), &vm, &protoCallFrame); 144 145 // We need to make sure this is in a register or on the stack since it's stored in Vector<JSValue>. … … 146 147 // alive. But it's good hygiene. 147 148 instance->use(); 148 if (prev Instance != instance) {149 if (prevWasmInstance != wasmInstance) { 149 150 // This is just for some extra safety instead of leaving a cached 150 151 // value in there. If we ever forget to set the value to be a real 151 152 // bounds, this will force every stack overflow check to immediately 152 153 // fire. 153 instance->setCachedStackLimit(bitwise_cast<void*>(std::numeric_limits<uintptr_t>::max()));154 } 155 vm.wasmContext.store(prev Instance, vm.softStackLimit());154 wasmInstance->setCachedStackLimit(bitwise_cast<void*>(std::numeric_limits<uintptr_t>::max())); 155 } 156 vm.wasmContext.store(prevWasmInstance, vm.softStackLimit()); 156 157 RETURN_IF_EXCEPTION(scope, { }); 157 158 -
trunk/Source/JavaScriptCore/wasm/js/WebAssemblyInstanceConstructor.cpp
r223875 r224020 78 78 RETURN_IF_EXCEPTION(scope, { }); 79 79 80 JSWebAssemblyInstance* instance = JSWebAssemblyInstance::create(vm, exec, module, importObject, instanceStructure, Wasm::Instance::create( Ref<Wasm::Module>(module->module()), &vm.topEntryFrame));80 JSWebAssemblyInstance* instance = JSWebAssemblyInstance::create(vm, exec, module, importObject, instanceStructure, Wasm::Instance::create(&vm.wasmContext, Ref<Wasm::Module>(module->module()), &vm.topEntryFrame)); 81 81 RETURN_IF_EXCEPTION(scope, { }); 82 82 -
trunk/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp
r223907 r224020 111 111 if (exp.kindIndex < functionImportCount) { 112 112 unsigned functionIndex = exp.kindIndex; 113 JSObject* functionImport = instance->i mportFunction(functionIndex);113 JSObject* functionImport = instance->instance().importFunction<WriteBarrier<JSObject>>(functionIndex)->get(); 114 114 if (isWebAssemblyHostFunction(vm, functionImport)) 115 115 exportedValue = functionImport; … … 192 192 ASSERT(signature.returnType() == Wasm::Void); 193 193 if (startFunctionIndexSpace < codeBlock->functionImportCount()) { 194 JSObject* startFunction = instance->i mportFunction(startFunctionIndexSpace);194 JSObject* startFunction = instance->instance().importFunction<WriteBarrier<JSObject>>(startFunctionIndexSpace)->get(); 195 195 m_startFunction.set(vm, this, startFunction); 196 196 } else { … … 296 296 Wasm::SignatureIndex signatureIndex = module.signatureIndexFromFunctionIndexSpace(functionIndex); 297 297 if (functionIndex < codeBlock->functionImportCount()) { 298 JSObject* functionImport = jsCast<JSObject*>(m_instance->importFunction(functionIndex));298 JSObject* functionImport = m_instance->instance().importFunction<WriteBarrier<JSObject>>(functionIndex)->get(); 299 299 if (isWebAssemblyHostFunction(vm, functionImport)) { 300 300 WebAssemblyFunction* wasmFunction = jsDynamicCast<WebAssemblyFunction*>(vm, functionImport); -
trunk/Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.cpp
r223875 r224020 138 138 auto scope = DECLARE_CATCH_SCOPE(vm); 139 139 // In order to avoid potentially recompiling a module. We first gather all the import/memory information prior to compiling code. 140 JSWebAssemblyInstance* instance = JSWebAssemblyInstance::create(vm, exec, module, importObject, exec->lexicalGlobalObject()->WebAssemblyInstanceStructure(), Wasm::Instance::create( Ref<Wasm::Module>(module->module()), &vm.topEntryFrame));140 JSWebAssemblyInstance* instance = JSWebAssemblyInstance::create(vm, exec, module, importObject, exec->lexicalGlobalObject()->WebAssemblyInstanceStructure(), Wasm::Instance::create(&vm.wasmContext, Ref<Wasm::Module>(module->module()), &vm.topEntryFrame)); 141 141 RETURN_IF_EXCEPTION(scope, reject(exec, scope, promise)); 142 142 -
trunk/Source/JavaScriptCore/wasm/js/WebAssemblyWrapperFunction.cpp
r223738 r224020 64 64 String name = ""; 65 65 NativeExecutable* executable = vm.getHostFunction(callWebAssemblyWrapperFunction, NoIntrinsic, callHostFunctionAsConstructor, nullptr, name); 66 WebAssemblyWrapperFunction* result = new (NotNull, allocateCell<WebAssemblyWrapperFunction>(vm.heap)) WebAssemblyWrapperFunction(vm, globalObject, globalObject->webAssemblyWrapperFunctionStructure(), Wasm::CallableFunction { signatureIndex, &instance->i mportFunctionInfo(importIndex)->wasmToEmbedderStubExecutableAddress } );66 WebAssemblyWrapperFunction* result = new (NotNull, allocateCell<WebAssemblyWrapperFunction>(vm.heap)) WebAssemblyWrapperFunction(vm, globalObject, globalObject->webAssemblyWrapperFunctionStructure(), Wasm::CallableFunction { signatureIndex, &instance->instance().importFunctionInfo(importIndex)->wasmToEmbedderStubExecutableAddress } ); 67 67 const Wasm::Signature& signature = Wasm::SignatureInformation::get(signatureIndex); 68 68 result->finishCreation(vm, executable, signature.argumentCount(), name, function, instance);
Note: See TracChangeset
for help on using the changeset viewer.