Changeset 244295 in webkit


Ignore:
Timestamp:
Apr 15, 2019 2:55:33 PM (5 years ago)
Author:
Tadeu Zagallo
Message:

Incremental bytecode cache should not append function updates when loaded from memory
https://bugs.webkit.org/show_bug.cgi?id=196865

Reviewed by Filip Pizlo.

JSTests:

  • stress/bytecode-cache-shared-code-block.js: Added.

(b):
(program):

Source/JavaScriptCore:

Function updates hold the assumption that a function can only be executed/cached
after its containing code block has already been cached. This assumptions does
not hold if the UnlinkedCodeBlock is loaded from memory by the CodeCache, since
we might have two independent SourceProviders executing different paths of the
code and causing the same UnlinkedCodeBlock to be modified in memory.
Use a RefPtr instead of Ref for m_cachedBytecode in ShellSourceProvider to distinguish
between a new, empty cache and a cache that was not loaded and therefore cannot be updated.

  • jsc.cpp:

(ShellSourceProvider::ShellSourceProvider):

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r244241 r244295  
     12019-04-15  Tadeu Zagallo  <tzagallo@apple.com>
     2
     3        Incremental bytecode cache should not append function updates when loaded from memory
     4        https://bugs.webkit.org/show_bug.cgi?id=196865
     5
     6        Reviewed by Filip Pizlo.
     7
     8        * stress/bytecode-cache-shared-code-block.js: Added.
     9        (b):
     10        (program):
     11
    1122019-04-13  Tadeu Zagallo  <tzagallo@apple.com>
    213
  • trunk/Source/JavaScriptCore/ChangeLog

    r244287 r244295  
     12019-04-15  Tadeu Zagallo  <tzagallo@apple.com>
     2
     3        Incremental bytecode cache should not append function updates when loaded from memory
     4        https://bugs.webkit.org/show_bug.cgi?id=196865
     5
     6        Reviewed by Filip Pizlo.
     7
     8        Function updates hold the assumption that a function can only be executed/cached
     9        after its containing code block has already been cached. This assumptions does
     10        not hold if the UnlinkedCodeBlock is loaded from memory by the CodeCache, since
     11        we might have two independent SourceProviders executing different paths of the
     12        code and causing the same UnlinkedCodeBlock to be modified in memory.
     13        Use a RefPtr instead of Ref for m_cachedBytecode in ShellSourceProvider to distinguish
     14        between a new, empty cache and a cache that was not loaded and therefore cannot be updated.
     15
     16        * jsc.cpp:
     17        (ShellSourceProvider::ShellSourceProvider):
     18
    1192019-04-15  Saam barati  <sbarati@apple.com>
    220
  • trunk/Source/JavaScriptCore/jsc.cpp

    r244149 r244295  
    973973    RefPtr<CachedBytecode> cachedBytecode() const override
    974974    {
    975         if (!m_cachedBytecode->size())
     975        if (!m_cachedBytecode)
    976976            loadBytecode();
    977977        return m_cachedBytecode.copyRef();
     
    980980    void updateCache(const UnlinkedFunctionExecutable* executable, const SourceCode&, CodeSpecializationKind kind, const UnlinkedFunctionCodeBlock* codeBlock) const override
    981981    {
    982         if (!cacheEnabled())
     982        if (!cacheEnabled() || !m_cachedBytecode)
    983983            return;
    984984        Ref<CachedBytecode> cachedBytecode = encodeFunctionCodeBlock(*executable->vm(), codeBlock);
     
    990990        if (!cacheEnabled())
    991991            return;
     992        if (!m_cachedBytecode)
     993            m_cachedBytecode = CachedBytecode::create();
    992994        m_cachedBytecode->addGlobalUpdate(generator());
    993995    }
     
    996998    {
    997999#if OS(DARWIN)
    998         if (!cacheEnabled() || !m_cachedBytecode->hasUpdates())
     1000        if (!cacheEnabled() || !m_cachedBytecode || !m_cachedBytecode->hasUpdates())
    9991001            return;
    10001002
    10011003        auto clearBytecode = makeScopeExit([&] {
    1002             m_cachedBytecode = CachedBytecode::create();
     1004            m_cachedBytecode = nullptr;
    10031005        });
    10041006
     
    10761078    ShellSourceProvider(const String& source, const SourceOrigin& sourceOrigin, URL&& url, const TextPosition& startPosition, SourceProviderSourceType sourceType)
    10771079        : StringSourceProvider(source, sourceOrigin, WTFMove(url), startPosition, sourceType)
    1078         , m_cachedBytecode(CachedBytecode::create())
    1079     {
    1080         loadBytecode();
     1080    {
    10811081    }
    10821082
     
    10871087    }
    10881088
    1089     mutable Ref<CachedBytecode> m_cachedBytecode;
     1089    mutable RefPtr<CachedBytecode> m_cachedBytecode;
    10901090};
    10911091
Note: See TracChangeset for help on using the changeset viewer.