Changeset 256498 in webkit


Ignore:
Timestamp:
Feb 12, 2020, 6:30:05 PM (6 years ago)
Author:
ysuzuki@apple.com
Message:

[JSC] Compact JITCodeMap by storing BytecodeIndex and CodeLocation separately
https://bugs.webkit.org/show_bug.cgi?id=207673

Reviewed by Mark Lam.

Source/JavaScriptCore:

While BytecodeIndex is 4 bytes, CodeLocation is 8 bytes. So the tuple of them "JITCodeMap::Entry"
becomes 16 bytes because it adds 4 bytes padding. We should store BytecodeIndex and CodeLocation separately
to avoid this padding.

This patch introduces JITCodeMapBuilder. We use this to build JITCodeMap data structure as a immutable final result.

  • jit/JIT.cpp:

(JSC::JIT::link):

  • jit/JITCodeMap.h:

(JSC::JITCodeMap::JITCodeMap):
(JSC::JITCodeMap::find const):
(JSC::JITCodeMap::operator bool const):
(JSC::JITCodeMap::codeLocations const):
(JSC::JITCodeMap::indexes const):
(JSC::JITCodeMapBuilder::append):
(JSC::JITCodeMapBuilder::finalize):
(JSC::JITCodeMap::Entry::Entry): Deleted.
(JSC::JITCodeMap::Entry::bytecodeIndex const): Deleted.
(JSC::JITCodeMap::Entry::codeLocation): Deleted.
(JSC::JITCodeMap::append): Deleted.
(JSC::JITCodeMap::finish): Deleted.

Source/WTF:

  • wtf/MallocPtr.h:
Location:
trunk/Source
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r256497 r256498  
     12020-02-12  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Compact JITCodeMap by storing BytecodeIndex and CodeLocation separately
     4        https://bugs.webkit.org/show_bug.cgi?id=207673
     5
     6        Reviewed by Mark Lam.
     7
     8        While BytecodeIndex is 4 bytes, CodeLocation is 8 bytes. So the tuple of them "JITCodeMap::Entry"
     9        becomes 16 bytes because it adds 4 bytes padding. We should store BytecodeIndex and CodeLocation separately
     10        to avoid this padding.
     11
     12        This patch introduces JITCodeMapBuilder. We use this to build JITCodeMap data structure as a immutable final result.
     13
     14        * jit/JIT.cpp:
     15        (JSC::JIT::link):
     16        * jit/JITCodeMap.h:
     17        (JSC::JITCodeMap::JITCodeMap):
     18        (JSC::JITCodeMap::find const):
     19        (JSC::JITCodeMap::operator bool const):
     20        (JSC::JITCodeMap::codeLocations const):
     21        (JSC::JITCodeMap::indexes const):
     22        (JSC::JITCodeMapBuilder::append):
     23        (JSC::JITCodeMapBuilder::finalize):
     24        (JSC::JITCodeMap::Entry::Entry): Deleted.
     25        (JSC::JITCodeMap::Entry::bytecodeIndex const): Deleted.
     26        (JSC::JITCodeMap::Entry::codeLocation): Deleted.
     27        (JSC::JITCodeMap::append): Deleted.
     28        (JSC::JITCodeMap::finish): Deleted.
     29
    1302020-02-12  Pavel Feldman  <pavel.feldman@gmail.com>
    231
  • trunk/Source/JavaScriptCore/jit/JIT.cpp

    r256015 r256498  
    913913    }
    914914
    915     JITCodeMap jitCodeMap;
    916     for (unsigned bytecodeOffset = 0; bytecodeOffset < m_labels.size(); ++bytecodeOffset) {
    917         if (m_labels[bytecodeOffset].isSet())
    918             jitCodeMap.append(BytecodeIndex(bytecodeOffset), patchBuffer.locationOf<JSEntryPtrTag>(m_labels[bytecodeOffset]));
    919     }
    920     jitCodeMap.finish();
    921     m_codeBlock->setJITCodeMap(WTFMove(jitCodeMap));
     915    {
     916        JITCodeMapBuilder jitCodeMapBuilder;
     917        for (unsigned bytecodeOffset = 0; bytecodeOffset < m_labels.size(); ++bytecodeOffset) {
     918            if (m_labels[bytecodeOffset].isSet())
     919                jitCodeMapBuilder.append(BytecodeIndex(bytecodeOffset), patchBuffer.locationOf<JSEntryPtrTag>(m_labels[bytecodeOffset]));
     920        }
     921        m_codeBlock->setJITCodeMap(jitCodeMapBuilder.finalize());
     922    }
    922923
    923924    MacroAssemblerCodePtr<JSEntryPtrTag> withArityCheck = patchBuffer.locationOf<JSEntryPtrTag>(m_arityCheck);
  • trunk/Source/JavaScriptCore/jit/JITCodeMap.h

    r251468 r256498  
    3535
    3636class JITCodeMap {
    37 private:
    38     struct Entry {
    39         Entry() { }
    40 
    41         Entry(BytecodeIndex bytecodeIndex, CodeLocationLabel<JSEntryPtrTag> codeLocation)
    42             : m_bytecodeIndex(bytecodeIndex)
    43             , m_codeLocation(codeLocation)
    44         { }
    45 
    46         inline BytecodeIndex bytecodeIndex() const { return m_bytecodeIndex; }
    47         inline CodeLocationLabel<JSEntryPtrTag> codeLocation() { return m_codeLocation; }
    48 
    49     private:
    50         BytecodeIndex m_bytecodeIndex;
    51         CodeLocationLabel<JSEntryPtrTag> m_codeLocation;
    52     };
    53 
    5437public:
    55     void append(BytecodeIndex bytecodeIndex, CodeLocationLabel<JSEntryPtrTag> codeLocation)
     38    static_assert(std::is_trivially_destructible_v<BytecodeIndex>);
     39    static_assert(std::is_trivially_destructible_v<CodeLocationLabel<JSEntryPtrTag>>);
     40    static_assert(alignof(CodeLocationLabel<JSEntryPtrTag>) >= alignof(BytecodeIndex), "Putting CodeLocationLabel vector first since we can avoid alignment consideration of BytecodeIndex vector");
     41    JITCodeMap() = default;
     42    JITCodeMap(Vector<BytecodeIndex>&& indexes, Vector<CodeLocationLabel<JSEntryPtrTag>>&& codeLocations)
     43        : m_size(indexes.size())
    5644    {
    57         m_entries.append({ bytecodeIndex, codeLocation });
     45        ASSERT(indexes.size() == codeLocations.size());
     46        m_pointer = MallocPtr<uint8_t>::malloc(sizeof(CodeLocationLabel<JSEntryPtrTag>) * m_size + sizeof(BytecodeIndex) * m_size);
     47        std::copy(codeLocations.begin(), codeLocations.end(), this->codeLocations());
     48        std::copy(indexes.begin(), indexes.end(), this->indexes());
    5849    }
    59 
    60     void finish() { m_entries.shrinkToFit(); }
    6150
    6251    CodeLocationLabel<JSEntryPtrTag> find(BytecodeIndex bytecodeIndex) const
    6352    {
    64         auto* entry =
    65             binarySearch<Entry, BytecodeIndex>(m_entries,
    66                 m_entries.size(), bytecodeIndex, [] (Entry* entry) {
    67                     return entry->bytecodeIndex();
    68                 });
    69         if (!entry)
     53        auto* index = binarySearch<BytecodeIndex, BytecodeIndex>(indexes(), m_size, bytecodeIndex, [] (BytecodeIndex* index) { return *index; });
     54        if (!index)
    7055            return CodeLocationLabel<JSEntryPtrTag>();
    71         return entry->codeLocation();
     56        return codeLocations()[index - indexes()];
    7257    }
    7358
    74     explicit operator bool() const { return m_entries.size(); }
     59    explicit operator bool() const { return m_size; }
    7560
    7661private:
    77     Vector<Entry> m_entries;
     62    CodeLocationLabel<JSEntryPtrTag>* codeLocations() const
     63    {
     64        return bitwise_cast<CodeLocationLabel<JSEntryPtrTag>*>(m_pointer.get());
     65    }
     66
     67    BytecodeIndex* indexes() const
     68    {
     69        return bitwise_cast<BytecodeIndex*>(m_pointer.get() + sizeof(CodeLocationLabel<JSEntryPtrTag>) * m_size);
     70    }
     71
     72    MallocPtr<uint8_t> m_pointer;
     73    unsigned m_size { 0 };
     74};
     75
     76class JITCodeMapBuilder {
     77    WTF_MAKE_NONCOPYABLE(JITCodeMapBuilder);
     78public:
     79    JITCodeMapBuilder() = default;
     80    void append(BytecodeIndex bytecodeIndex, CodeLocationLabel<JSEntryPtrTag> codeLocation)
     81    {
     82        m_indexes.append(bytecodeIndex);
     83        m_codeLocations.append(codeLocation);
     84    }
     85
     86    JITCodeMap finalize()
     87    {
     88        return JITCodeMap(WTFMove(m_indexes), WTFMove(m_codeLocations));
     89    }
     90
     91private:
     92    Vector<BytecodeIndex> m_indexes;
     93    Vector<CodeLocationLabel<JSEntryPtrTag>> m_codeLocations;
    7894};
    7995
  • trunk/Source/WTF/ChangeLog

    r256493 r256498  
     12020-02-12  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Compact JITCodeMap by storing BytecodeIndex and CodeLocation separately
     4        https://bugs.webkit.org/show_bug.cgi?id=207673
     5
     6        Reviewed by Mark Lam.
     7
     8        * wtf/MallocPtr.h:
     9
    1102020-02-12  Ryan Haddad  <ryanhaddad@apple.com>
    211
  • trunk/Source/WTF/wtf/MallocPtr.h

    r253987 r256498  
    2727
    2828#include <wtf/FastMalloc.h>
     29#include <wtf/Noncopyable.h>
    2930
    3031// MallocPtr is a smart pointer class that calls fastFree in its destructor.
     
    3536
    3637template<typename T, typename Malloc = FastMalloc> class MallocPtr {
     38    WTF_MAKE_NONCOPYABLE(MallocPtr);
    3739public:
    3840    MallocPtr() = default;
Note: See TracChangeset for help on using the changeset viewer.