⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 286992 in webkit


Ignore:
Timestamp:
Dec 13, 2021, 3:56:13 PM (5 years ago)
Author:
ysuzuki@apple.com
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):

Location:
trunk/Source/JavaScriptCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r286969 r286992  
     12021-12-13  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Use FixedVector for wasm exception in Wasm::Instance
     4        https://bugs.webkit.org/show_bug.cgi?id=234224
     5
     6        Reviewed by Saam Barati.
     7
     8        Since we know # of exception tags when instantiating Wasm::Instance,
     9        we can use FixedVector instead of Vector. This is the same to Table,
     10        Functions etc.
     11
     12        We also remove Wasm::Tag::m_id. Since we do not copy Wasm::Tag and
     13        we always allocate Wasm::Tag from heap, we can just use pointer
     14        comparison. Then, we do not need to have this m_id.
     15
     16        * wasm/WasmInstance.cpp:
     17        (JSC::Wasm::Instance::Instance):
     18        (JSC::Wasm::Instance::setTag):
     19        (JSC::Wasm::Instance::addTag): Deleted.
     20        * wasm/WasmInstance.h:
     21        * wasm/WasmModuleInformation.h:
     22        (JSC::Wasm::ModuleInformation::internalExceptionCount const):
     23        * wasm/WasmTag.cpp:
     24        * wasm/WasmTag.h:
     25        (JSC::Wasm::Tag::create): Deleted.
     26        (JSC::Wasm::Tag::parameterCount const): Deleted.
     27        (JSC::Wasm::Tag::parameter const): Deleted.
     28        (JSC::Wasm::Tag::operator== const): Deleted.
     29        (JSC::Wasm::Tag::operator!= const): Deleted.
     30        (JSC::Wasm::Tag::signature const): Deleted.
     31        (JSC::Wasm::Tag::Tag): Deleted.
     32        * wasm/js/WebAssemblyModuleRecord.cpp:
     33        (JSC::WebAssemblyModuleRecord::initializeImportsAndExports):
     34
    1352021-12-13  waddlesplash  <waddlesplash@gmail.com>
    236
  • trunk/Source/JavaScriptCore/wasm/WasmInstance.cpp

    r283852 r286992  
    5959    , m_passiveElements(m_module->moduleInformation().elementCount())
    6060    , m_passiveDataSegments(m_module->moduleInformation().dataSegmentsCount())
     61    , m_tags(m_module->moduleInformation().exceptionIndexSpaceSize())
    6162{
    6263    for (unsigned i = 0; i < m_numImportFunctions; ++i)
     
    301302}
    302303
    303 void Instance::addTag(const Tag& tag)
    304 {
    305     m_tags.append(Ref { tag });
    306 }
    307 
    308 void Instance::addTag(Ref<Tag>&& tag)
    309 {
    310     m_tags.append(WTFMove(tag));
     304void Instance::setTag(unsigned index, Ref<const Tag>&& tag)
     305{
     306    m_tags[index] = WTFMove(tag);
    311307}
    312308
  • trunk/Source/JavaScriptCore/wasm/WasmInstance.h

    r286703 r286992  
    210210    }
    211211
    212     void addTag(const Tag&);
    213     void addTag(Ref<Tag>&&);
    214212    const Tag& tag(unsigned i) const { return *m_tags[i]; }
     213    void setTag(unsigned, Ref<const Tag>&&);
    215214
    216215private:
     
    240239    BitVector m_passiveElements;
    241240    BitVector m_passiveDataSegments;
    242     Vector<RefPtr<const Tag>> m_tags;
     241    FixedVector<RefPtr<const Tag>> m_tags;
    243242};
    244243
  • trunk/Source/JavaScriptCore/wasm/WasmModuleInformation.h

    r283852 r286992  
    7575    uint32_t internalFunctionCount() const { return internalFunctionSignatureIndices.size(); }
    7676    uint32_t importExceptionCount() const { return importExceptionSignatureIndices.size(); }
     77    uint32_t internalExceptionCount() const { return internalExceptionSignatureIndices.size(); }
    7778
    7879    // Currently, our wasm implementation allows only one memory and table.
  • trunk/Source/JavaScriptCore/wasm/WasmTag.cpp

    r283852 r286992  
    3232namespace Wasm {
    3333
    34 std::atomic<uint32_t> Tag::s_id = 0;
    35 
    3634} } // namespace JSC::Wasm
    3735
  • trunk/Source/JavaScriptCore/wasm/WasmTag.h

    r283852 r286992  
    3232namespace JSC { namespace Wasm {
    3333
    34 class Tag : public ThreadSafeRefCounted<Tag> {
     34class Tag final : public ThreadSafeRefCounted<Tag> {
    3535    WTF_MAKE_FAST_ALLOCATED;
    3636    WTF_MAKE_NONCOPYABLE(Tag);
     
    4141    Type parameter(SignatureArgCount i) const { return m_signature->argument(i); }
    4242
    43     bool operator==(const Tag& other) const { return m_id == other.m_id; }
    44     bool operator!=(const Tag& other) const { return m_id != other.m_id; }
     43    // Since (1) we do not copy Wasm::Tag and (2) we always allocate Wasm::Tag from heap, we can use
     44    // pointer comparison for identity check.
     45    bool operator==(const Tag& other) const { return this == &other; }
     46    bool operator!=(const Tag& other) const { return this != &other; }
    4547
    4648    const Signature& signature() const { return m_signature.get(); }
     
    4850private:
    4951    Tag(const Signature& signature)
    50         : m_id(++s_id)
    51         , m_signature(Ref { signature })
     52        : m_signature(Ref { signature })
    5253    {
    5354    }
    5455
    55     static std::atomic<uint32_t> s_id;
    56     uint32_t m_id;
    5756    Ref<const Signature> m_signature;
    5857};
  • trunk/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp

    r286703 r286992  
    406406                return exception(createJSWebAssemblyLinkError(globalObject, vm, importFailMessage(import, "imported Tag", "signature doesn't match the imported WebAssembly Tag's signature")));
    407407
    408             m_instance->instance().addTag(tag->tag());
     408            m_instance->instance().setTag(import.kindIndex, tag->tag());
    409409            break;
    410410        }
     
    479479    Wasm::CodeBlock* codeBlock = m_instance->instance().codeBlock();
    480480
    481     for (Wasm::SignatureIndex signatureIndex : moduleInformation.internalExceptionSignatureIndices)
    482         m_instance->instance().addTag(Wasm::Tag::create(Wasm::SignatureInformation::get(signatureIndex)));
     481    for (unsigned index = 0; index < moduleInformation.internalExceptionSignatureIndices.size(); ++index) {
     482        Wasm::SignatureIndex signatureIndex = moduleInformation.internalExceptionSignatureIndices[index];
     483        m_instance->instance().setTag(moduleInformation.importExceptionCount() + index, Wasm::Tag::create(Wasm::SignatureInformation::get(signatureIndex)));
     484    }
    483485
    484486    unsigned functionImportCount = codeBlock->functionImportCount();
Note: See TracChangeset for help on using the changeset viewer.