Title: [153176] trunk/Source/_javascript_Core
Revision
153176
Author
[email protected]
Date
2013-07-24 21:00:51 -0700 (Wed, 24 Jul 2013)

Log Message

fourthTier: Race between LLInt->Baseline tier-up and DFG reading Baseline profiling data
https://bugs.webkit.org/show_bug.cgi?id=116633

Reviewed by Mark Hahnenberg.

Previously we would check if we had Baseline JIT profiling data by seeing if the
appropriate vector was non-empty. This is horrible if we're doing LLInt->Baseline
tier-up at the same time. This will happen for code we are inlining, if we're
deciding to inline it before the LLInt->Baseline tier-up happened for that code.

This changes things to take advantage of the fact that the very last thing that
LLInt->Baseline tier-up will do (in JITDriver.h) is setJITCode(). We now precede
the actual work in setJITCode() with a store-store fence to ensure that all
stores to modify the CodeBlock happen before setting the JITCode, and we modify
CodeBlock::getJITType() to use load-load fences to ensure that if you see
JITCode::BaselineJIT then you will also see all of those vectors. Then this
changes all of the code that scrapes Baseline JIT profiles to check if
getJITType() returns JITCode::BaselineJIT instead of checking vector sizes.

The outcome is that for the non-racy cases we behave as we did before (we fall
back on LLInt profiling if the tier-up hasn't happened) and for racy cases we
use LLInt profiling conservatively.

Note that for some (but not all!) of the cases where we scrape Baseline JIT
profiling, we would have anyway been holding the CodeBlock::m_lock so we can also
fix those cases by just having setJITCode graph that lock. This patch does that
also, mainly because although we only call setJITCode() from the main thread, in
general it's dangerous to have a pointer to a ref-counted object being modified
in a racy way. So, this patch just does the most conservative thing possible that
does we can afford to do.

* bytecode/CallLinkStatus.cpp:
(JSC::CallLinkStatus::computeFor):
* bytecode/CodeBlock.h:
(JSC::CodeBlock::setJITCode):
(JSC::CodeBlock::getJITType):
(JSC::CodeBlock::hasBaselineJITProfiling):
(JSC::CodeBlock::likelyToTakeSlowCase):
(JSC::CodeBlock::couldTakeSlowCase):
(JSC::CodeBlock::likelyToTakeSpecialFastCase):
(JSC::CodeBlock::couldTakeSpecialFastCase):
(JSC::CodeBlock::likelyToTakeDeepestSlowCase):
(JSC::CodeBlock::likelyToTakeAnySlowCase):
* bytecode/GetByIdStatus.cpp:
(JSC::GetByIdStatus::computeFor):
* bytecode/PutByIdStatus.cpp:
(JSC::PutByIdStatus::computeFor):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (153175 => 153176)


--- trunk/Source/_javascript_Core/ChangeLog	2013-07-25 04:00:50 UTC (rev 153175)
+++ trunk/Source/_javascript_Core/ChangeLog	2013-07-25 04:00:51 UTC (rev 153176)
@@ -1,5 +1,55 @@
 2013-05-22  Filip Pizlo  <[email protected]>
 
+        fourthTier: Race between LLInt->Baseline tier-up and DFG reading Baseline profiling data
+        https://bugs.webkit.org/show_bug.cgi?id=116633
+
+        Reviewed by Mark Hahnenberg.
+        
+        Previously we would check if we had Baseline JIT profiling data by seeing if the
+        appropriate vector was non-empty. This is horrible if we're doing LLInt->Baseline
+        tier-up at the same time. This will happen for code we are inlining, if we're
+        deciding to inline it before the LLInt->Baseline tier-up happened for that code.
+        
+        This changes things to take advantage of the fact that the very last thing that
+        LLInt->Baseline tier-up will do (in JITDriver.h) is setJITCode(). We now precede
+        the actual work in setJITCode() with a store-store fence to ensure that all
+        stores to modify the CodeBlock happen before setting the JITCode, and we modify
+        CodeBlock::getJITType() to use load-load fences to ensure that if you see
+        JITCode::BaselineJIT then you will also see all of those vectors. Then this
+        changes all of the code that scrapes Baseline JIT profiles to check if
+        getJITType() returns JITCode::BaselineJIT instead of checking vector sizes.
+        
+        The outcome is that for the non-racy cases we behave as we did before (we fall
+        back on LLInt profiling if the tier-up hasn't happened) and for racy cases we
+        use LLInt profiling conservatively.
+        
+        Note that for some (but not all!) of the cases where we scrape Baseline JIT
+        profiling, we would have anyway been holding the CodeBlock::m_lock so we can also
+        fix those cases by just having setJITCode graph that lock. This patch does that
+        also, mainly because although we only call setJITCode() from the main thread, in
+        general it's dangerous to have a pointer to a ref-counted object being modified
+        in a racy way. So, this patch just does the most conservative thing possible that
+        does we can afford to do.
+
+        * bytecode/CallLinkStatus.cpp:
+        (JSC::CallLinkStatus::computeFor):
+        * bytecode/CodeBlock.h:
+        (JSC::CodeBlock::setJITCode):
+        (JSC::CodeBlock::getJITType):
+        (JSC::CodeBlock::hasBaselineJITProfiling):
+        (JSC::CodeBlock::likelyToTakeSlowCase):
+        (JSC::CodeBlock::couldTakeSlowCase):
+        (JSC::CodeBlock::likelyToTakeSpecialFastCase):
+        (JSC::CodeBlock::couldTakeSpecialFastCase):
+        (JSC::CodeBlock::likelyToTakeDeepestSlowCase):
+        (JSC::CodeBlock::likelyToTakeAnySlowCase):
+        * bytecode/GetByIdStatus.cpp:
+        (JSC::GetByIdStatus::computeFor):
+        * bytecode/PutByIdStatus.cpp:
+        (JSC::PutByIdStatus::computeFor):
+
+2013-05-22  Filip Pizlo  <[email protected]>
+
         fourthTier: It should be possible to use more than one compiler thread
         https://bugs.webkit.org/show_bug.cgi?id=116630
 

Modified: trunk/Source/_javascript_Core/bytecode/CallLinkStatus.cpp (153175 => 153176)


--- trunk/Source/_javascript_Core/bytecode/CallLinkStatus.cpp	2013-07-25 04:00:50 UTC (rev 153175)
+++ trunk/Source/_javascript_Core/bytecode/CallLinkStatus.cpp	2013-07-25 04:00:51 UTC (rev 153176)
@@ -102,7 +102,7 @@
     UNUSED_PARAM(profiledBlock);
     UNUSED_PARAM(bytecodeIndex);
 #if ENABLE(JIT) && ENABLE(VALUE_PROFILER)
-    if (!profiledBlock->numberOfCallLinkInfos())
+    if (!profiledBlock->hasBaselineJITProfiling())
         return computeFromLLInt(profiledBlock, bytecodeIndex);
     
     if (profiledBlock->couldTakeSlowCase(bytecodeIndex))

Modified: trunk/Source/_javascript_Core/bytecode/CodeBlock.h (153175 => 153176)


--- trunk/Source/_javascript_Core/bytecode/CodeBlock.h	2013-07-25 04:00:50 UTC (rev 153175)
+++ trunk/Source/_javascript_Core/bytecode/CodeBlock.h	2013-07-25 04:00:51 UTC (rev 153176)
@@ -275,6 +275,8 @@
 #if ENABLE(JIT)
         void setJITCode(PassRefPtr<JITCode> code, MacroAssemblerCodePtr codeWithArityCheck)
         {
+            ConcurrentJITLocker locker(m_lock);
+            WTF::storeStoreFence(); // This is probably not needed because the lock will also do something similar, but it's good to be paranoid.
             m_jitCode = code;
             m_jitCodeWithArityCheck = codeWithArityCheck;
 #if ENABLE(DFG_JIT)
@@ -284,7 +286,18 @@
         }
         PassRefPtr<JITCode> getJITCode() { return m_jitCode; }
         MacroAssemblerCodePtr getJITCodeWithArityCheck() { return m_jitCodeWithArityCheck; }
-        JITCode::JITType getJITType() const { return JITCode::jitTypeFor(m_jitCode.get()); }
+        JITCode::JITType getJITType() const
+        {
+            JITCode* jitCode = m_jitCode.get();
+            WTF::loadLoadFence();
+            JITCode::JITType result = JITCode::jitTypeFor(jitCode);
+            WTF::loadLoadFence(); // This probably isn't needed. Oh well, paranoia is good.
+            return result;
+        }
+        bool hasBaselineJITProfiling() const
+        {
+            return getJITType() == JITCode::BaselineJIT;
+        }
         virtual JSObject* compileOptimized(ExecState*, JSScope*, CompilationResult&, unsigned bytecodeIndex) = 0;
         virtual CompilationResult replaceWithDeferredOptimizedCode(PassRefPtr<DFG::Plan>) = 0;
         void jettison();
@@ -480,7 +493,7 @@
 
         bool likelyToTakeSlowCase(int bytecodeOffset)
         {
-            if (!numberOfRareCaseProfiles())
+            if (!hasBaselineJITProfiling())
                 return false;
             unsigned value = rareCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
             return value >= Options::likelyToTakeSlowCaseMinimumCount();
@@ -488,7 +501,7 @@
 
         bool couldTakeSlowCase(int bytecodeOffset)
         {
-            if (!numberOfRareCaseProfiles())
+            if (!hasBaselineJITProfiling())
                 return false;
             unsigned value = rareCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
             return value >= Options::couldTakeSlowCaseMinimumCount();
@@ -510,7 +523,7 @@
 
         bool likelyToTakeSpecialFastCase(int bytecodeOffset)
         {
-            if (!numberOfRareCaseProfiles())
+            if (!hasBaselineJITProfiling())
                 return false;
             unsigned specialFastCaseCount = specialFastCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
             return specialFastCaseCount >= Options::likelyToTakeSlowCaseMinimumCount();
@@ -518,7 +531,7 @@
 
         bool couldTakeSpecialFastCase(int bytecodeOffset)
         {
-            if (!numberOfRareCaseProfiles())
+            if (!hasBaselineJITProfiling())
                 return false;
             unsigned specialFastCaseCount = specialFastCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
             return specialFastCaseCount >= Options::couldTakeSlowCaseMinimumCount();
@@ -526,7 +539,7 @@
 
         bool likelyToTakeDeepestSlowCase(int bytecodeOffset)
         {
-            if (!numberOfRareCaseProfiles())
+            if (!hasBaselineJITProfiling())
                 return false;
             unsigned slowCaseCount = rareCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
             unsigned specialFastCaseCount = specialFastCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
@@ -536,7 +549,7 @@
 
         bool likelyToTakeAnySlowCase(int bytecodeOffset)
         {
-            if (!numberOfRareCaseProfiles())
+            if (!hasBaselineJITProfiling())
                 return false;
             unsigned slowCaseCount = rareCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
             unsigned specialFastCaseCount = specialFastCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;

Modified: trunk/Source/_javascript_Core/bytecode/GetByIdStatus.cpp (153175 => 153176)


--- trunk/Source/_javascript_Core/bytecode/GetByIdStatus.cpp	2013-07-25 04:00:50 UTC (rev 153175)
+++ trunk/Source/_javascript_Core/bytecode/GetByIdStatus.cpp	2013-07-25 04:00:51 UTC (rev 153176)
@@ -113,7 +113,7 @@
     UNUSED_PARAM(bytecodeIndex);
     UNUSED_PARAM(uid);
 #if ENABLE(JIT) && ENABLE(VALUE_PROFILER)
-    if (!profiledBlock->numberOfStructureStubInfos())
+    if (!profiledBlock->hasBaselineJITProfiling())
         return computeFromLLInt(profiledBlock, bytecodeIndex, uid);
     
     // First check if it makes either calls, in which case we want to be super careful, or

Modified: trunk/Source/_javascript_Core/bytecode/PutByIdStatus.cpp (153175 => 153176)


--- trunk/Source/_javascript_Core/bytecode/PutByIdStatus.cpp	2013-07-25 04:00:50 UTC (rev 153175)
+++ trunk/Source/_javascript_Core/bytecode/PutByIdStatus.cpp	2013-07-25 04:00:51 UTC (rev 153176)
@@ -89,7 +89,7 @@
     UNUSED_PARAM(bytecodeIndex);
     UNUSED_PARAM(uid);
 #if ENABLE(JIT) && ENABLE(VALUE_PROFILER)
-    if (!profiledBlock->numberOfStructureStubInfos())
+    if (!profiledBlock->hasBaselineJITProfiling())
         return computeFromLLInt(profiledBlock, bytecodeIndex, uid);
     
     if (profiledBlock->likelyToTakeSlowCase(bytecodeIndex))
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to