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

Changeset 249706 in webkit


Ignore:
Timestamp:
Sep 9, 2019, 10:03:13 PM (7 years ago)
Author:
ysuzuki@apple.com
Message:

[JSC] CodeBlock::m_constantRegisters should be guarded by ConcurrentJSLock when Vector reallocate memory
https://bugs.webkit.org/show_bug.cgi?id=201622

Reviewed by Mark Lam.

CodeBlock::visitChildren takes ConcurrentJSLock while iterating m_constantRegisters, some of the places reallocate
this Vector without taking a lock. If a Vector memory is reallocated while iterating it in concurrent collector,
the concurrent collector can see a garbage. This patch guards m_constantRegisters reallocation with ConcurrentJSLock.

  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::finishCreation):
(JSC::CodeBlock::setConstantRegisters):

  • bytecode/CodeBlock.h:

(JSC::CodeBlock::addConstant):
(JSC::CodeBlock::addConstantLazily):

  • dfg/DFGDesiredWatchpoints.cpp:

(JSC::DFG::ArrayBufferViewWatchpointAdaptor::add):
(JSC::DFG::SymbolTableAdaptor::add):
(JSC::DFG::FunctionExecutableAdaptor::add):

  • dfg/DFGGraph.cpp:

(JSC::DFG::Graph::registerFrozenValues):

  • dfg/DFGJITFinalizer.cpp:

(JSC::DFG::JITFinalizer::finalizeCommon):

  • dfg/DFGLazyJSValue.cpp:

(JSC::DFG::LazyJSValue::emit const):

Location:
trunk/Source/JavaScriptCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r249677 r249706  
     12019-09-09  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] CodeBlock::m_constantRegisters should be guarded by ConcurrentJSLock when Vector reallocate memory
     4        https://bugs.webkit.org/show_bug.cgi?id=201622
     5
     6        Reviewed by Mark Lam.
     7
     8        CodeBlock::visitChildren takes ConcurrentJSLock while iterating m_constantRegisters, some of the places reallocate
     9        this Vector without taking a lock. If a Vector memory is reallocated while iterating it in concurrent collector,
     10        the concurrent collector can see a garbage. This patch guards m_constantRegisters reallocation with ConcurrentJSLock.
     11
     12        * bytecode/CodeBlock.cpp:
     13        (JSC::CodeBlock::finishCreation):
     14        (JSC::CodeBlock::setConstantRegisters):
     15        * bytecode/CodeBlock.h:
     16        (JSC::CodeBlock::addConstant):
     17        (JSC::CodeBlock::addConstantLazily):
     18        * dfg/DFGDesiredWatchpoints.cpp:
     19        (JSC::DFG::ArrayBufferViewWatchpointAdaptor::add):
     20        (JSC::DFG::SymbolTableAdaptor::add):
     21        (JSC::DFG::FunctionExecutableAdaptor::add):
     22        * dfg/DFGGraph.cpp:
     23        (JSC::DFG::Graph::registerFrozenValues):
     24        * dfg/DFGJITFinalizer.cpp:
     25        (JSC::DFG::JITFinalizer::finalizeCommon):
     26        * dfg/DFGLazyJSValue.cpp:
     27        (JSC::DFG::LazyJSValue::emit const):
     28
    1292019-09-09  Robin Morisset  <rmorisset@apple.com>
    230
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp

    r249668 r249706  
    597597                    // Keep the linked module environment strongly referenced.
    598598                    if (stronglyReferencedModuleEnvironments.add(jsCast<JSModuleEnvironment*>(op.lexicalEnvironment)).isNewEntry)
    599                         addConstant(op.lexicalEnvironment);
     599                        addConstant(ConcurrentJSLocker(m_lock), op.lexicalEnvironment);
    600600                    metadata.m_lexicalEnvironment.set(vm, this, op.lexicalEnvironment);
    601601                } else
     
    900900    ASSERT(constants.size() == constantsSourceCodeRepresentation.size());
    901901    size_t count = constants.size();
    902     m_constantRegisters.resizeToFit(count);
     902    {
     903        ConcurrentJSLocker locker(m_lock);
     904        m_constantRegisters.resizeToFit(count);
     905    }
    903906    for (size_t i = 0; i < count; i++) {
    904907        JSValue constant = constants[i].get();
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.h

    r249319 r249706  
    547547    Vector<WriteBarrier<Unknown>>& constants() { return m_constantRegisters; }
    548548    Vector<SourceCodeRepresentation>& constantsSourceCodeRepresentation() { return m_constantsSourceCodeRepresentation; }
    549     unsigned addConstant(JSValue v)
     549    unsigned addConstant(const ConcurrentJSLocker&, JSValue v)
    550550    {
    551551        unsigned result = m_constantRegisters.size();
     
    556556    }
    557557
    558     unsigned addConstantLazily()
     558    unsigned addConstantLazily(const ConcurrentJSLocker&)
    559559    {
    560560        unsigned result = m_constantRegisters.size();
  • trunk/Source/JavaScriptCore/dfg/DFGDesiredWatchpoints.cpp

    r249175 r249706  
    4444        ArrayBufferNeuteringWatchpointSet::create(vm);
    4545    neuteringWatchpoint->set().add(watchpoint);
    46     codeBlock->addConstant(neuteringWatchpoint);
     46    codeBlock->addConstant(ConcurrentJSLocker(codeBlock->m_lock), neuteringWatchpoint);
    4747    // FIXME: We don't need to set this watchpoint at all for shared buffers.
    4848    // https://bugs.webkit.org/show_bug.cgi?id=164108
     
    5353    CodeBlock* codeBlock, SymbolTable* symbolTable, CommonData& common)
    5454{
    55     codeBlock->addConstant(symbolTable); // For common users, it doesn't really matter if it's weak or not. If references to it go away, we go away, too.
     55    codeBlock->addConstant(ConcurrentJSLocker(codeBlock->m_lock), symbolTable); // For common users, it doesn't really matter if it's weak or not. If references to it go away, we go away, too.
    5656    symbolTable->singleton().add(common.watchpoints.add(codeBlock));
    5757}
     
    6060    CodeBlock* codeBlock, FunctionExecutable* executable, CommonData& common)
    6161{
    62     codeBlock->addConstant(executable); // For common users, it doesn't really matter if it's weak or not. If references to it go away, we go away, too.
     62    codeBlock->addConstant(ConcurrentJSLocker(codeBlock->m_lock), executable); // For common users, it doesn't really matter if it's weak or not. If references to it go away, we go away, too.
    6363    executable->singleton().add(common.watchpoints.add(codeBlock));
    6464}
  • trunk/Source/JavaScriptCore/dfg/DFGGraph.cpp

    r249509 r249706  
    14061406void Graph::registerFrozenValues()
    14071407{
     1408    ConcurrentJSLocker locker(m_codeBlock->m_lock);
    14081409    m_codeBlock->constants().shrink(0);
    14091410    m_codeBlock->constantsSourceCodeRepresentation().resize(0);
     
    14211422        }
    14221423        case StrongValue: {
    1423             unsigned constantIndex = m_codeBlock->addConstantLazily();
     1424            unsigned constantIndex = m_codeBlock->addConstantLazily(locker);
    14241425            // We already have a barrier on the code block.
    14251426            m_codeBlock->constants()[constantIndex].setWithoutWriteBarrier(value->value());
  • trunk/Source/JavaScriptCore/dfg/DFGJITFinalizer.cpp

    r244764 r249706  
    8383{
    8484    // Some JIT finalizers may have added more constants. Shrink-to-fit those things now.
    85     m_plan.codeBlock()->constants().shrinkToFit();
    86     m_plan.codeBlock()->constantsSourceCodeRepresentation().shrinkToFit();
     85    {
     86        ConcurrentJSLocker locker(m_plan.codeBlock()->m_lock);
     87        m_plan.codeBlock()->constants().shrinkToFit();
     88        m_plan.codeBlock()->constantsSourceCodeRepresentation().shrinkToFit();
     89    }
    8790
    8891#if ENABLE(FTL_JIT)
  • trunk/Source/JavaScriptCore/dfg/DFGLazyJSValue.cpp

    r249175 r249706  
    255255            RELEASE_ASSERT(realValue.isCell());
    256256
    257             codeBlock->addConstant(realValue);
     257            codeBlock->addConstant(ConcurrentJSLocker(codeBlock->m_lock), realValue);
    258258           
    259259            if (thisValue.m_kind == NewStringImpl)
Note: See TracChangeset for help on using the changeset viewer.