Title: [286992] trunk/Source/_javascript_Core
Revision
286992
Author
ysuz...@apple.com
Date
2021-12-13 15:56:13 -0800 (Mon, 13 Dec 2021)

Log Message

[JSC] Use FixedVector for wasm exception in Wasm::Instance
https://bugs.webkit.org/show_bug.cgi?id=234224

Reviewed by Saam Barati.

Since we know # of exception tags when instantiating Wasm::Instance,
we can use FixedVector instead of Vector. This is the same to Table,
Functions etc.

We also remove Wasm::Tag::m_id. Since we do not copy Wasm::Tag and
we always allocate Wasm::Tag from heap, we can just use pointer
comparison. Then, we do not need to have this m_id.

* wasm/WasmInstance.cpp:
(JSC::Wasm::Instance::Instance):
(JSC::Wasm::Instance::setTag):
(JSC::Wasm::Instance::addTag): Deleted.
* wasm/WasmInstance.h:
* wasm/WasmModuleInformation.h:
(JSC::Wasm::ModuleInformation::internalExceptionCount const):
* wasm/WasmTag.cpp:
* wasm/WasmTag.h:
(JSC::Wasm::Tag::create): Deleted.
(JSC::Wasm::Tag::parameterCount const): Deleted.
(JSC::Wasm::Tag::parameter const): Deleted.
(JSC::Wasm::Tag::operator== const): Deleted.
(JSC::Wasm::Tag::operator!= const): Deleted.
(JSC::Wasm::Tag::signature const): Deleted.
(JSC::Wasm::Tag::Tag): Deleted.
* wasm/js/WebAssemblyModuleRecord.cpp:
(JSC::WebAssemblyModuleRecord::initializeImportsAndExports):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (286991 => 286992)


--- trunk/Source/_javascript_Core/ChangeLog	2021-12-13 23:49:02 UTC (rev 286991)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-12-13 23:56:13 UTC (rev 286992)
@@ -1,3 +1,37 @@
+2021-12-13  Yusuke Suzuki  <ysuz...@apple.com>
+
+        [JSC] Use FixedVector for wasm exception in Wasm::Instance
+        https://bugs.webkit.org/show_bug.cgi?id=234224
+
+        Reviewed by Saam Barati.
+
+        Since we know # of exception tags when instantiating Wasm::Instance,
+        we can use FixedVector instead of Vector. This is the same to Table,
+        Functions etc.
+
+        We also remove Wasm::Tag::m_id. Since we do not copy Wasm::Tag and
+        we always allocate Wasm::Tag from heap, we can just use pointer
+        comparison. Then, we do not need to have this m_id.
+
+        * wasm/WasmInstance.cpp:
+        (JSC::Wasm::Instance::Instance):
+        (JSC::Wasm::Instance::setTag):
+        (JSC::Wasm::Instance::addTag): Deleted.
+        * wasm/WasmInstance.h:
+        * wasm/WasmModuleInformation.h:
+        (JSC::Wasm::ModuleInformation::internalExceptionCount const):
+        * wasm/WasmTag.cpp:
+        * wasm/WasmTag.h:
+        (JSC::Wasm::Tag::create): Deleted.
+        (JSC::Wasm::Tag::parameterCount const): Deleted.
+        (JSC::Wasm::Tag::parameter const): Deleted.
+        (JSC::Wasm::Tag::operator== const): Deleted.
+        (JSC::Wasm::Tag::operator!= const): Deleted.
+        (JSC::Wasm::Tag::signature const): Deleted.
+        (JSC::Wasm::Tag::Tag): Deleted.
+        * wasm/js/WebAssemblyModuleRecord.cpp:
+        (JSC::WebAssemblyModuleRecord::initializeImportsAndExports):
+
 2021-12-13  waddlesplash  <waddlespl...@gmail.com>
 
         ExecutableAllocator: Do not store things in g_config when USE(SYSTEM_MALLOC).

Modified: trunk/Source/_javascript_Core/wasm/WasmInstance.cpp (286991 => 286992)


--- trunk/Source/_javascript_Core/wasm/WasmInstance.cpp	2021-12-13 23:49:02 UTC (rev 286991)
+++ trunk/Source/_javascript_Core/wasm/WasmInstance.cpp	2021-12-13 23:56:13 UTC (rev 286992)
@@ -58,6 +58,7 @@
     , m_numImportFunctions(m_module->moduleInformation().importFunctionCount())
     , m_passiveElements(m_module->moduleInformation().elementCount())
     , m_passiveDataSegments(m_module->moduleInformation().dataSegmentsCount())
+    , m_tags(m_module->moduleInformation().exceptionIndexSpaceSize())
 {
     for (unsigned i = 0; i < m_numImportFunctions; ++i)
         new (importFunctionInfo(i)) ImportFunctionInfo();
@@ -300,16 +301,11 @@
     m_linkedGlobals.set(i, WTFMove(global));
 }
 
-void Instance::addTag(const Tag& tag)
+void Instance::setTag(unsigned index, Ref<const Tag>&& tag)
 {
-    m_tags.append(Ref { tag });
+    m_tags[index] = WTFMove(tag);
 }
 
-void Instance::addTag(Ref<Tag>&& tag)
-{
-    m_tags.append(WTFMove(tag));
-}
-
 } } // namespace JSC::Wasm
 
 #endif // ENABLE(WEBASSEMBLY)

Modified: trunk/Source/_javascript_Core/wasm/WasmInstance.h (286991 => 286992)


--- trunk/Source/_javascript_Core/wasm/WasmInstance.h	2021-12-13 23:49:02 UTC (rev 286991)
+++ trunk/Source/_javascript_Core/wasm/WasmInstance.h	2021-12-13 23:56:13 UTC (rev 286992)
@@ -209,9 +209,8 @@
         m_storeTopCallFrame(callFrame);
     }
 
-    void addTag(const Tag&);
-    void addTag(Ref<Tag>&&);
     const Tag& tag(unsigned i) const { return *m_tags[i]; }
+    void setTag(unsigned, Ref<const Tag>&&);
 
 private:
     Instance(Context*, Ref<Module>&&, EntryFrame**, void**, StoreTopCallFrameCallback&&);
@@ -239,7 +238,7 @@
     HashMap<uint32_t, Ref<Global>, IntHash<uint32_t>, WTF::UnsignedWithZeroKeyHashTraits<uint32_t>> m_linkedGlobals;
     BitVector m_passiveElements;
     BitVector m_passiveDataSegments;
-    Vector<RefPtr<const Tag>> m_tags;
+    FixedVector<RefPtr<const Tag>> m_tags;
 };
 
 } } // namespace JSC::Wasm

Modified: trunk/Source/_javascript_Core/wasm/WasmModuleInformation.h (286991 => 286992)


--- trunk/Source/_javascript_Core/wasm/WasmModuleInformation.h	2021-12-13 23:49:02 UTC (rev 286991)
+++ trunk/Source/_javascript_Core/wasm/WasmModuleInformation.h	2021-12-13 23:56:13 UTC (rev 286992)
@@ -74,6 +74,7 @@
     uint32_t importFunctionCount() const { return importFunctionSignatureIndices.size(); }
     uint32_t internalFunctionCount() const { return internalFunctionSignatureIndices.size(); }
     uint32_t importExceptionCount() const { return importExceptionSignatureIndices.size(); }
+    uint32_t internalExceptionCount() const { return internalExceptionSignatureIndices.size(); }
 
     // Currently, our wasm implementation allows only one memory and table.
     // If we need to remove this limitation, we would have MemoryInformation and TableInformation in the Vectors.

Modified: trunk/Source/_javascript_Core/wasm/WasmTag.cpp (286991 => 286992)


--- trunk/Source/_javascript_Core/wasm/WasmTag.cpp	2021-12-13 23:49:02 UTC (rev 286991)
+++ trunk/Source/_javascript_Core/wasm/WasmTag.cpp	2021-12-13 23:56:13 UTC (rev 286992)
@@ -31,8 +31,6 @@
 namespace JSC {
 namespace Wasm {
 
-std::atomic<uint32_t> Tag::s_id = 0;
-
 } } // namespace JSC::Wasm
 
 #endif

Modified: trunk/Source/_javascript_Core/wasm/WasmTag.h (286991 => 286992)


--- trunk/Source/_javascript_Core/wasm/WasmTag.h	2021-12-13 23:49:02 UTC (rev 286991)
+++ trunk/Source/_javascript_Core/wasm/WasmTag.h	2021-12-13 23:56:13 UTC (rev 286992)
@@ -31,7 +31,7 @@
 
 namespace JSC { namespace Wasm {
 
-class Tag : public ThreadSafeRefCounted<Tag> {
+class Tag final : public ThreadSafeRefCounted<Tag> {
     WTF_MAKE_FAST_ALLOCATED;
     WTF_MAKE_NONCOPYABLE(Tag);
 public:
@@ -40,20 +40,19 @@
     SignatureArgCount parameterCount() const { return m_signature->argumentCount(); }
     Type parameter(SignatureArgCount i) const { return m_signature->argument(i); }
 
-    bool operator==(const Tag& other) const { return m_id == other.m_id; }
-    bool operator!=(const Tag& other) const { return m_id != other.m_id; }
+    // Since (1) we do not copy Wasm::Tag and (2) we always allocate Wasm::Tag from heap, we can use
+    // pointer comparison for identity check.
+    bool operator==(const Tag& other) const { return this == &other; }
+    bool operator!=(const Tag& other) const { return this != &other; }
 
     const Signature& signature() const { return m_signature.get(); }
 
 private:
     Tag(const Signature& signature)
-        : m_id(++s_id)
-        , m_signature(Ref { signature })
+        : m_signature(Ref { signature })
     {
     }
 
-    static std::atomic<uint32_t> s_id;
-    uint32_t m_id;
     Ref<const Signature> m_signature;
 };
 

Modified: trunk/Source/_javascript_Core/wasm/js/WebAssemblyModuleRecord.cpp (286991 => 286992)


--- trunk/Source/_javascript_Core/wasm/js/WebAssemblyModuleRecord.cpp	2021-12-13 23:49:02 UTC (rev 286991)
+++ trunk/Source/_javascript_Core/wasm/js/WebAssemblyModuleRecord.cpp	2021-12-13 23:56:13 UTC (rev 286992)
@@ -405,7 +405,7 @@
             if (expectedSignatureIndex != tag->tag().signature().index())
                 return exception(createJSWebAssemblyLinkError(globalObject, vm, importFailMessage(import, "imported Tag", "signature doesn't match the imported WebAssembly Tag's signature")));
 
-            m_instance->instance().addTag(tag->tag());
+            m_instance->instance().setTag(import.kindIndex, tag->tag());
             break;
         }
 
@@ -478,8 +478,10 @@
     // This needs to be looked up after the memory is initialized, as the codeBlock depends on the memory mode.
     Wasm::CodeBlock* codeBlock = m_instance->instance().codeBlock();
 
-    for (Wasm::SignatureIndex signatureIndex : moduleInformation.internalExceptionSignatureIndices)
-        m_instance->instance().addTag(Wasm::Tag::create(Wasm::SignatureInformation::get(signatureIndex)));
+    for (unsigned index = 0; index < moduleInformation.internalExceptionSignatureIndices.size(); ++index) {
+        Wasm::SignatureIndex signatureIndex = moduleInformation.internalExceptionSignatureIndices[index];
+        m_instance->instance().setTag(moduleInformation.importExceptionCount() + index, Wasm::Tag::create(Wasm::SignatureInformation::get(signatureIndex)));
+    }
 
     unsigned functionImportCount = codeBlock->functionImportCount();
     auto makeFunctionWrapper = [&] (uint32_t index) -> JSValue {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to