WebAssembly: address no VM / JS follow-ups
authorjfbastien@apple.com <jfbastien@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Oct 2017 20:20:43 +0000 (20:20 +0000)
committerjfbastien@apple.com <jfbastien@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Oct 2017 20:20:43 +0000 (20:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=177887

Reviewed by Saam Barati.

All minor fixes, no functional changes.

* wasm/WasmB3IRGenerator.cpp:
(JSC::Wasm::B3IRGenerator::B3IRGenerator):
(JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState):
(JSC::Wasm::B3IRGenerator::addCurrentMemory):
(JSC::Wasm::B3IRGenerator::addCall):
(JSC::Wasm::B3IRGenerator::addCallIndirect):
* wasm/WasmContext.cpp:
(JSC::Wasm::Context::store):
* wasm/WasmMemoryMode.h:
* wasm/WasmTable.h:
* wasm/js/JSWebAssemblyInstance.cpp:
(JSC::JSWebAssemblyInstance::JSWebAssemblyInstance):
* wasm/js/JSWebAssemblyTable.cpp:
(JSC::JSWebAssemblyTable::JSWebAssemblyTable):
(JSC::JSWebAssemblyTable::grow):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222873 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp
Source/JavaScriptCore/wasm/WasmContext.cpp
Source/JavaScriptCore/wasm/WasmMemoryMode.h
Source/JavaScriptCore/wasm/WasmTable.h
Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp
Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.cpp

index 1497a11..6b52ef9 100644 (file)
@@ -1,3 +1,28 @@
+2017-10-04  JF Bastien  <jfbastien@apple.com>
+
+        WebAssembly: address no VM / JS follow-ups
+        https://bugs.webkit.org/show_bug.cgi?id=177887
+
+        Reviewed by Saam Barati.
+
+        All minor fixes, no functional changes.
+
+        * wasm/WasmB3IRGenerator.cpp:
+        (JSC::Wasm::B3IRGenerator::B3IRGenerator):
+        (JSC::Wasm::B3IRGenerator::restoreWebAssemblyGlobalState):
+        (JSC::Wasm::B3IRGenerator::addCurrentMemory):
+        (JSC::Wasm::B3IRGenerator::addCall):
+        (JSC::Wasm::B3IRGenerator::addCallIndirect):
+        * wasm/WasmContext.cpp:
+        (JSC::Wasm::Context::store):
+        * wasm/WasmMemoryMode.h:
+        * wasm/WasmTable.h:
+        * wasm/js/JSWebAssemblyInstance.cpp:
+        (JSC::JSWebAssemblyInstance::JSWebAssemblyInstance):
+        * wasm/js/JSWebAssemblyTable.cpp:
+        (JSC::JSWebAssemblyTable::JSWebAssemblyTable):
+        (JSC::JSWebAssemblyTable::grow):
+
 2017-10-04  Mark Lam  <mark.lam@apple.com>
 
         Add support for using Probe DFG OSR Exit behind a runtime flag.
index af6cfe8..42164d4 100644 (file)
@@ -369,7 +369,10 @@ B3IRGenerator::B3IRGenerator(const ModuleInformation& info, Procedure& procedure
         case MemoryMode::BoundsChecking:
             break;
         case MemoryMode::Signaling:
-        // Most memory accesses in signaling mode don't do an explicit exception check because they can rely on fault handling to detect out-of-bounds accesses. FaultSignalHandler nonetheless needs the thunk to exist so that it can jump to that thunk.
+            // Most memory accesses in signaling mode don't do an explicit
+            // exception check because they can rely on fault handling to detect
+            // out-of-bounds accesses. FaultSignalHandler nonetheless needs the
+            // thunk to exist so that it can jump to that thunk.
             if (UNLIKELY(!Thunks::singleton().stub(throwExceptionFromWasmThunkGenerator)))
                 CRASH();
             break;
@@ -473,8 +476,8 @@ void B3IRGenerator::restoreWebAssemblyGlobalState(const MemoryInformation& memor
             const auto& sizeRegs = pinnedRegs->sizeRegisters;
             ASSERT(sizeRegs.size() >= 1);
             ASSERT(!sizeRegs[0].sizeOffset); // The following code assumes we start at 0, and calculates subsequent size registers relative to 0.
-            jit.loadPtr(CCallHelpers::Address(baseMemory, Wasm::Memory::offsetOfSize()), sizeRegs[0].sizeRegister);
-            jit.loadPtr(CCallHelpers::Address(baseMemory, Wasm::Memory::offsetOfMemory()), baseMemory);
+            jit.loadPtr(CCallHelpers::Address(baseMemory, Memory::offsetOfSize()), sizeRegs[0].sizeRegister);
+            jit.loadPtr(CCallHelpers::Address(baseMemory, Memory::offsetOfMemory()), baseMemory);
             for (unsigned i = 1; i < sizeRegs.size(); ++i)
                 jit.add64(CCallHelpers::TrustedImm32(-sizeRegs[i].sizeOffset), sizeRegs[0].sizeRegister, sizeRegs[i].sizeRegister);
         });
@@ -583,8 +586,8 @@ auto B3IRGenerator::addCurrentMemory(ExpressionType& result) -> PartialResult
 {
     Value* memoryObject = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(), instanceValue(), safeCast<int32_t>(JSWebAssemblyInstance::offsetOfWasmMemory()));
 
-    static_assert(sizeof(decltype(static_cast<Wasm::Memory*>(nullptr)->size())) == sizeof(uint64_t), "codegen relies on this size");
-    Value* size = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, Int64, origin(), memoryObject, safeCast<int32_t>(Wasm::Memory::offsetOfSize()));
+    static_assert(sizeof(decltype(static_cast<Memory*>(nullptr)->size())) == sizeof(uint64_t), "codegen relies on this size");
+    Value* size = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, Int64, origin(), memoryObject, safeCast<int32_t>(Memory::offsetOfSize()));
     
     constexpr uint32_t shiftValue = 16;
     static_assert(PageCount::pageSize == 1ull << shiftValue, "This must hold for the code below to be correct.");
@@ -1107,7 +1110,7 @@ auto B3IRGenerator::addCall(uint32_t functionIndex, const Signature& signature,
 
         // FIXME: Let's remove this indirection by creating a PIC friendly IC
         // for calls out to JS. This shouldn't be that hard to do. We could probably
-        // implement the IC to be over Wasm::Context*.
+        // implement the IC to be over Context*.
         // https://bugs.webkit.org/show_bug.cgi?id=170375
         Value* codeBlock = isEmbedderBlock->appendNew<MemoryValue>(m_proc,
             Load, pointerType(), origin(), instanceValue(), safeCast<int32_t>(JSWebAssemblyInstance::offsetOfWasmCodeBlock()));
@@ -1179,11 +1182,11 @@ auto B3IRGenerator::addCallIndirect(const Signature& signature, Vector<Expressio
         ExpressionType table = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(),
             instanceValue(), safeCast<int32_t>(JSWebAssemblyInstance::offsetOfWasmTable()));
         callableFunctionBuffer = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(),
-            table, safeCast<int32_t>(Wasm::Table::offsetOfFunctions()));
+            table, safeCast<int32_t>(Table::offsetOfFunctions()));
         instancesBuffer = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(),
-            table, safeCast<int32_t>(Wasm::Table::offsetOfInstances()));
+            table, safeCast<int32_t>(Table::offsetOfInstances()));
         callableFunctionBufferSize = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, Int32, origin(),
-            table, safeCast<int32_t>(Wasm::Table::offsetOfSize()));
+            table, safeCast<int32_t>(Table::offsetOfSize()));
     }
 
     // Check the index we are looking for is valid.
@@ -1232,7 +1235,7 @@ auto B3IRGenerator::addCallIndirect(const Signature& signature, Vector<Expressio
     {
         Value* offset = m_currentBlock->appendNew<Value>(m_proc, Mul, origin(),
             m_currentBlock->appendNew<Value>(m_proc, ZExt32, origin(), calleeIndex),
-            constant(pointerType(), sizeof(Wasm::Instance*)));
+            constant(pointerType(), sizeof(Instance*)));
         Value* newContextInstance = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, pointerType(), origin(),
             m_currentBlock->appendNew<Value>(m_proc, Add, origin(), instancesBuffer, offset));
 
@@ -1263,13 +1266,13 @@ auto B3IRGenerator::addCallIndirect(const Signature& signature, Vector<Expressio
             jit.loadPtr(CCallHelpers::Address(oldContextInstance, JSWebAssemblyInstance::offsetOfCachedStackLimit()), baseMemory);
             jit.storePtr(baseMemory, CCallHelpers::Address(newContextInstance, JSWebAssemblyInstance::offsetOfCachedStackLimit()));
             jit.storeWasmContextInstance(newContextInstance);
-            jit.loadPtr(CCallHelpers::Address(newContextInstance, JSWebAssemblyInstance::offsetOfWasmMemory()), baseMemory); // Wasm::Memory*.
+            jit.loadPtr(CCallHelpers::Address(newContextInstance, JSWebAssemblyInstance::offsetOfWasmMemory()), baseMemory); // Memory*.
             ASSERT(sizeRegs.size() == 1);
             ASSERT(sizeRegs[0].sizeRegister != baseMemory);
             ASSERT(sizeRegs[0].sizeRegister != newContextInstance);
             ASSERT(!sizeRegs[0].sizeOffset);
-            jit.loadPtr(CCallHelpers::Address(baseMemory, Wasm::Memory::offsetOfSize()), sizeRegs[0].sizeRegister); // Memory size.
-            jit.loadPtr(CCallHelpers::Address(baseMemory, Wasm::Memory::offsetOfMemory()), baseMemory); // Wasm::Memory::void*.
+            jit.loadPtr(CCallHelpers::Address(baseMemory, Memory::offsetOfSize()), sizeRegs[0].sizeRegister); // Memory size.
+            jit.loadPtr(CCallHelpers::Address(baseMemory, Memory::offsetOfMemory()), baseMemory); // Memory::void*.
         });
         doContextSwitch->appendNewControlValue(m_proc, Jump, origin(), continuation);
 
index e059fc1..cf34851 100644 (file)
@@ -54,13 +54,13 @@ JSWebAssemblyInstance* Context::load() const
     return instance;
 }
 
-void Context::store(JSWebAssemblyInstance* i, void* softStackLimit)
+void Context::store(JSWebAssemblyInstance* inst, void* softStackLimit)
 {
 #if ENABLE(FAST_TLS_JIT)
     if (useFastTLS())
-        _pthread_setspecific_direct(WTF_WASM_CONTEXT_KEY, bitwise_cast<void*>(i));
+        _pthread_setspecific_direct(WTF_WASM_CONTEXT_KEY, bitwise_cast<void*>(inst));
 #endif
-    instance = i;
+    instance = inst;
     if (instance)
         instance->setCachedStackLimit(softStackLimit);
 }
index 14fc896..0a2855a 100644 (file)
@@ -29,9 +29,7 @@
 
 #include "JSExportMacros.h"
 
-namespace JSC {
-
-namespace Wasm {
+namespace JSC { namespace Wasm {
 
 // FIXME: We should support other modes. see: https://bugs.webkit.org/show_bug.cgi?id=162693
 enum class MemoryMode : uint8_t {
index b908ec8..a92a9a9 100644 (file)
@@ -42,9 +42,6 @@ namespace Wasm {
 
 class Table : public ThreadSafeRefCounted<Table> {
 public:
-    enum class CreateFail {
-        InvalidSize,
-    };
     static RefPtr<Table> create(uint32_t initial, std::optional<uint32_t> maximum);
 
     JS_EXPORT_PRIVATE ~Table();
index 72aa0a0..bb2b5e1 100644 (file)
@@ -59,7 +59,7 @@ JSWebAssemblyInstance::JSWebAssemblyInstance(VM& vm, Structure* structure, unsig
     , m_numImportFunctions(numImportFunctions)
 {
     for (unsigned i = 0; i < m_numImportFunctions; ++i)
-        new (importFunctionInfo(i)) ImportFunctionInfo();
+        default_construct_at(importFunctionInfo(i));
 }
 
 void JSWebAssemblyInstance::finishCreation(VM& vm, JSWebAssemblyModule* module, JSModuleNamespaceObject* moduleNamespaceObject)
index adaa749..99be06d 100644 (file)
@@ -62,7 +62,7 @@ JSWebAssemblyTable::JSWebAssemblyTable(VM& vm, Structure* structure, Ref<Wasm::T
     // But for now, we're not doing that.
     m_jsFunctions = MallocPtr<WriteBarrier<JSObject>>::malloc(sizeof(WriteBarrier<JSObject>) * static_cast<size_t>(size()));
     for (uint32_t i = 0; i < size(); ++i)
-        new (&m_jsFunctions.get()[i]) WriteBarrier<JSObject>();
+        default_construct_at(&m_jsFunctions.get()[i]);
 }
 
 void JSWebAssemblyTable::finishCreation(VM& vm)
@@ -102,7 +102,7 @@ bool JSWebAssemblyTable::grow(uint32_t delta)
     m_jsFunctions.realloc(sizeof(WriteBarrier<JSObject>) * newSize);
 
     for (size_t i = oldSize; i < newSize; ++i)
-        new (&m_jsFunctions.get()[i]) WriteBarrier<JSObject>();
+        default_construct_at(&m_jsFunctions.get()[i]);
 
     return true;
 }