Changeset 249319 in webkit


Ignore:
Timestamp:
Aug 30, 2019 3:00:31 AM (5 years ago)
Author:
ysuzuki@apple.com
Message:

[JSC] DFG ByteCodeParser should not copy JIT-related part of SimpleJumpTable
https://bugs.webkit.org/show_bug.cgi?id=201331

Reviewed by Mark Lam.

JSTests:

  • stress/simple-jump-table-copy.js: Added.

(let.code):
(g2):

Source/JavaScriptCore:

SimpleJumpTable's non-JIT part is not changed after CodeBlock is finalized well. On the other hand, JIT related part is allocated on-demand.
For example, ctiOffsets can be grown by Baseline JIT compiler. There is race condition as follows.

  1. DFG ByteCodeParser is inlining and copying SimpleJumpTable
  2. Baseline JIT compiler is expanding JIT-related part of SimpleJumpTable

Then, (1) reads the broken Vector, and crashes. Since JIT-related part is unnecessary in (1), we should not clone that.
This patch adds CodeBlock::addSwitchJumpTableFromProfiledCodeBlock, which only copies non JIT-related part of the given SimpleJumpTable offered
by profiled CodeBlock.

  • bytecode/CodeBlock.h:

(JSC::CodeBlock::addSwitchJumpTableFromProfiledCodeBlock):

  • bytecode/JumpTable.h:

(JSC::SimpleJumpTable::cloneNonJITPart const):
(JSC::SimpleJumpTable::clear):

  • dfg/DFGByteCodeParser.cpp:

(JSC::DFG::ByteCodeParser::InlineStackEntry::InlineStackEntry):

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r249317 r249319  
     12019-08-30  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] DFG ByteCodeParser should not copy JIT-related part of SimpleJumpTable
     4        https://bugs.webkit.org/show_bug.cgi?id=201331
     5
     6        Reviewed by Mark Lam.
     7
     8        * stress/simple-jump-table-copy.js: Added.
     9        (let.code):
     10        (g2):
     11
    1122019-08-30  Yusuke Suzuki  <ysuzuki@apple.com>
    213
  • trunk/Source/JavaScriptCore/ChangeLog

    r249317 r249319  
     12019-08-30  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] DFG ByteCodeParser should not copy JIT-related part of SimpleJumpTable
     4        https://bugs.webkit.org/show_bug.cgi?id=201331
     5
     6        Reviewed by Mark Lam.
     7
     8        SimpleJumpTable's non-JIT part is not changed after CodeBlock is finalized well. On the other hand, JIT related part is allocated on-demand.
     9        For example, ctiOffsets can be grown by Baseline JIT compiler. There is race condition as follows.
     10
     11            1. DFG ByteCodeParser is inlining and copying SimpleJumpTable
     12            2. Baseline JIT compiler is expanding JIT-related part of SimpleJumpTable
     13
     14        Then, (1) reads the broken Vector, and crashes. Since JIT-related part is unnecessary in (1), we should not clone that.
     15        This patch adds CodeBlock::addSwitchJumpTableFromProfiledCodeBlock, which only copies non JIT-related part of the given SimpleJumpTable offered
     16        by profiled CodeBlock.
     17
     18        * bytecode/CodeBlock.h:
     19        (JSC::CodeBlock::addSwitchJumpTableFromProfiledCodeBlock):
     20        * bytecode/JumpTable.h:
     21        (JSC::SimpleJumpTable::cloneNonJITPart const):
     22        (JSC::SimpleJumpTable::clear):
     23        * dfg/DFGByteCodeParser.cpp:
     24        (JSC::DFG::ByteCodeParser::InlineStackEntry::InlineStackEntry):
     25
    1262019-08-30  Yusuke Suzuki  <ysuzuki@apple.com>
    227
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.h

    r249175 r249319  
    599599        m_rareData->m_switchJumpTables.clear();
    600600    }
     601#if ENABLE(DFG_JIT)
     602    void addSwitchJumpTableFromProfiledCodeBlock(SimpleJumpTable& profiled)
     603    {
     604        createRareDataIfNecessary();
     605        m_rareData->m_switchJumpTables.append(profiled.cloneNonJITPart());
     606    }
     607#endif
    601608
    602609    size_t numberOfStringSwitchJumpTables() const { return m_rareData ? m_rareData->m_stringSwitchJumpTables.size() : 0; }
  • trunk/Source/JavaScriptCore/bytecode/JumpTable.h

    r230748 r249319  
    7878
    7979    struct SimpleJumpTable {
    80         // FIXME: The two Vectors can be combind into one Vector<OffsetLocation>
     80        // FIXME: The two Vectors can be combined into one Vector<OffsetLocation>
    8181        Vector<int32_t> branchOffsets;
    82         int32_t min;
     82        int32_t min { INT32_MIN };
    8383#if ENABLE(JIT)
    8484        Vector<CodeLocationLabel<JSSwitchPtrTag>> ctiOffsets;
    8585        CodeLocationLabel<JSSwitchPtrTag> ctiDefault;
     86#endif
     87
     88#if ENABLE(DFG_JIT)
     89        // JIT part can be later expanded without taking a lock while non-JIT part is stable after CodeBlock is finalized.
     90        SimpleJumpTable cloneNonJITPart() const
     91        {
     92            SimpleJumpTable result;
     93            result.branchOffsets = branchOffsets;
     94            result.min = min;
     95            return result;
     96        }
    8697#endif
    8798
     
    107118        }
    108119#endif
    109        
     120
     121#if ENABLE(DFG_JIT)
    110122        void clear()
    111123        {
    112124            branchOffsets.clear();
    113 #if ENABLE(JIT)
    114125            ctiOffsets.clear();
     126        }
    115127#endif
    116         }
    117128    };
    118129
  • trunk/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp

    r249317 r249319  
    71177117        for (unsigned i = 0; i < codeBlock->numberOfSwitchJumpTables(); ++i) {
    71187118            m_switchRemap[i] = byteCodeParser->m_codeBlock->numberOfSwitchJumpTables();
    7119             byteCodeParser->m_codeBlock->addSwitchJumpTable() = codeBlock->switchJumpTable(i);
     7119            byteCodeParser->m_codeBlock->addSwitchJumpTableFromProfiledCodeBlock(codeBlock->switchJumpTable(i));
    71207120        }
    71217121    } else {
Note: See TracChangeset for help on using the changeset viewer.