Title: [244295] trunk
Revision
244295
Author
[email protected]
Date
2019-04-15 14:55:33 -0700 (Mon, 15 Apr 2019)

Log 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/_javascript_Core:

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):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (244294 => 244295)


--- trunk/JSTests/ChangeLog	2019-04-15 21:53:48 UTC (rev 244294)
+++ trunk/JSTests/ChangeLog	2019-04-15 21:55:33 UTC (rev 244295)
@@ -1,3 +1,14 @@
+2019-04-15  Tadeu Zagallo  <[email protected]>
+
+        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.
+
+        * stress/bytecode-cache-shared-code-block.js: Added.
+        (b):
+        (program):
+
 2019-04-13  Tadeu Zagallo  <[email protected]>
 
         CodeCache should check that the UnlinkedCodeBlock was successfully created before caching it

Added: trunk/JSTests/stress/bytecode-cache-shared-code-block.js (0 => 244295)


--- trunk/JSTests/stress/bytecode-cache-shared-code-block.js	                        (rev 0)
+++ trunk/JSTests/stress/bytecode-cache-shared-code-block.js	2019-04-15 21:55:33 UTC (rev 244295)
@@ -0,0 +1,10 @@
+//@ runBytecodeCache
+
+var program = `(function () {
+    function a() { }
+    function b() { }
+    return { a, b };
+})`;
+
+loadString(program)().a();
+loadString(program)().b();

Modified: trunk/Source/_javascript_Core/ChangeLog (244294 => 244295)


--- trunk/Source/_javascript_Core/ChangeLog	2019-04-15 21:53:48 UTC (rev 244294)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-04-15 21:55:33 UTC (rev 244295)
@@ -1,3 +1,21 @@
+2019-04-15  Tadeu Zagallo  <[email protected]>
+
+        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.
+
+        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):
+
 2019-04-15  Saam barati  <[email protected]>
 
         mergeOSREntryValue is wrong when the incoming value does not match up with the flush format

Modified: trunk/Source/_javascript_Core/jsc.cpp (244294 => 244295)


--- trunk/Source/_javascript_Core/jsc.cpp	2019-04-15 21:53:48 UTC (rev 244294)
+++ trunk/Source/_javascript_Core/jsc.cpp	2019-04-15 21:55:33 UTC (rev 244295)
@@ -972,7 +972,7 @@
 
     RefPtr<CachedBytecode> cachedBytecode() const override
     {
-        if (!m_cachedBytecode->size())
+        if (!m_cachedBytecode)
             loadBytecode();
         return m_cachedBytecode.copyRef();
     }
@@ -979,7 +979,7 @@
 
     void updateCache(const UnlinkedFunctionExecutable* executable, const SourceCode&, CodeSpecializationKind kind, const UnlinkedFunctionCodeBlock* codeBlock) const override
     {
-        if (!cacheEnabled())
+        if (!cacheEnabled() || !m_cachedBytecode)
             return;
         Ref<CachedBytecode> cachedBytecode = encodeFunctionCodeBlock(*executable->vm(), codeBlock);
         m_cachedBytecode->addFunctionUpdate(executable, kind, WTFMove(cachedBytecode));
@@ -989,6 +989,8 @@
     {
         if (!cacheEnabled())
             return;
+        if (!m_cachedBytecode)
+            m_cachedBytecode = CachedBytecode::create();
         m_cachedBytecode->addGlobalUpdate(generator());
     }
 
@@ -995,11 +997,11 @@
     void commitCachedBytecode() const override
     {
 #if OS(DARWIN)
-        if (!cacheEnabled() || !m_cachedBytecode->hasUpdates())
+        if (!cacheEnabled() || !m_cachedBytecode || !m_cachedBytecode->hasUpdates())
             return;
 
         auto clearBytecode = makeScopeExit([&] {
-            m_cachedBytecode = CachedBytecode::create();
+            m_cachedBytecode = nullptr;
         });
 
         String filename = cachePath();
@@ -1075,9 +1077,7 @@
 
     ShellSourceProvider(const String& source, const SourceOrigin& sourceOrigin, URL&& url, const TextPosition& startPosition, SourceProviderSourceType sourceType)
         : StringSourceProvider(source, sourceOrigin, WTFMove(url), startPosition, sourceType)
-        , m_cachedBytecode(CachedBytecode::create())
     {
-        loadBytecode();
     }
 
     static bool cacheEnabled()
@@ -1086,7 +1086,7 @@
         return enabled;
     }
 
-    mutable Ref<CachedBytecode> m_cachedBytecode;
+    mutable RefPtr<CachedBytecode> m_cachedBytecode;
 };
 
 static inline SourceCode jscSource(const String& source, const SourceOrigin& sourceOrigin, URL&& url = "" const TextPosition& startPosition = TextPosition(), SourceProviderSourceType sourceType = SourceProviderSourceType::Program)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to