Title: [162811] branches/jsCStack/Source/_javascript_Core
Revision
162811
Author
[email protected]
Date
2014-01-26 14:39:31 -0800 (Sun, 26 Jan 2014)

Log Message

FTL should do polyvariant GetById inlining
https://bugs.webkit.org/show_bug.cgi?id=127639

Not yet reviewed.
        
This does polyvariant inlining for GetByIds. It's pretty easy to do this, now that we
have all of that infrastructure from polyvariant Call/Construct inlining. Basically we
just keep around the StubInfoMaps of the DFG code block when compiling the FTL code
block.
        
The combination of Call, Construct, and GetById inlining causes a 17% speed-up on
V8v7/raytrace.
        
GetById inlining alone appears to be a speed-up on other benchmarks as well.

* bytecode/CallLinkStatus.cpp:
(JSC::CallLinkStatus::computeDFGStatuses):
* bytecode/CodeBlock.cpp:
(JSC::CodeBlock::dumpBytecode):
(JSC::CodeBlock::getStubInfoMap):
(JSC::CodeBlock::addStubInfo):
* bytecode/CodeBlock.h:
* bytecode/GetByIdStatus.cpp:
(JSC::GetByIdStatus::hasExitSite):
(JSC::GetByIdStatus::computeFor):
(JSC::GetByIdStatus::computeForStubInfo):
* bytecode/GetByIdStatus.h:
* dfg/DFGByteCodeParser.cpp:
(JSC::DFG::ByteCodeParser::parseBlock):
(JSC::DFG::ByteCodeParser::parse):
* runtime/Options.h:
* tests/stress/simple-polyvariant-get-by-id-inlining-example.js: Added.
(foo):
(fuzz):
(bar):

Modified Paths

Added Paths

Diff

Modified: branches/jsCStack/Source/_javascript_Core/ChangeLog (162810 => 162811)


--- branches/jsCStack/Source/_javascript_Core/ChangeLog	2014-01-26 22:34:13 UTC (rev 162810)
+++ branches/jsCStack/Source/_javascript_Core/ChangeLog	2014-01-26 22:39:31 UTC (rev 162811)
@@ -1,3 +1,41 @@
+2014-01-26  Filip Pizlo  <[email protected]>
+
+        FTL should do polyvariant GetById inlining
+        https://bugs.webkit.org/show_bug.cgi?id=127639
+
+        Not yet reviewed.
+        
+        This does polyvariant inlining for GetByIds. It's pretty easy to do this, now that we
+        have all of that infrastructure from polyvariant Call/Construct inlining. Basically we
+        just keep around the StubInfoMaps of the DFG code block when compiling the FTL code
+        block.
+        
+        The combination of Call, Construct, and GetById inlining causes a 17% speed-up on
+        V8v7/raytrace.
+        
+        GetById inlining alone appears to be a speed-up on other benchmarks as well.
+
+        * bytecode/CallLinkStatus.cpp:
+        (JSC::CallLinkStatus::computeDFGStatuses):
+        * bytecode/CodeBlock.cpp:
+        (JSC::CodeBlock::dumpBytecode):
+        (JSC::CodeBlock::getStubInfoMap):
+        (JSC::CodeBlock::addStubInfo):
+        * bytecode/CodeBlock.h:
+        * bytecode/GetByIdStatus.cpp:
+        (JSC::GetByIdStatus::hasExitSite):
+        (JSC::GetByIdStatus::computeFor):
+        (JSC::GetByIdStatus::computeForStubInfo):
+        * bytecode/GetByIdStatus.h:
+        * dfg/DFGByteCodeParser.cpp:
+        (JSC::DFG::ByteCodeParser::parseBlock):
+        (JSC::DFG::ByteCodeParser::parse):
+        * runtime/Options.h:
+        * tests/stress/simple-polyvariant-get-by-id-inlining-example.js: Added.
+        (foo):
+        (fuzz):
+        (bar):
+
 2014-01-25  Filip Pizlo  <[email protected]>
 
         StubInfoMap should use CodeOriginApproximateHash

Modified: branches/jsCStack/Source/_javascript_Core/bytecode/CallLinkStatus.cpp (162810 => 162811)


--- branches/jsCStack/Source/_javascript_Core/bytecode/CallLinkStatus.cpp	2014-01-26 22:34:13 UTC (rev 162810)
+++ branches/jsCStack/Source/_javascript_Core/bytecode/CallLinkStatus.cpp	2014-01-26 22:39:31 UTC (rev 162811)
@@ -182,10 +182,10 @@
         // challenging because it would require creating a CodeOrigin-based database in
         // baseline CodeBlocks, but those CodeBlocks don't really have a place to put the
         // InlineCallFrames.
+        CodeBlock* currentBaseline =
+            baselineCodeBlockForOriginAndBaselineCodeBlock(codeOrigin, baselineCodeBlock);
         {
-            ConcurrentJITLocker locker(baselineCodeBlock->m_lock);
-            CodeBlock* currentBaseline =
-                baselineCodeBlockForOriginAndBaselineCodeBlock(codeOrigin, baselineCodeBlock);
+            ConcurrentJITLocker locker(currentBaseline->m_lock);
             takeSlowPath =
                 currentBaseline->hasExitSite(locker, DFG::FrequentExitSite(codeOrigin.bytecodeIndex, BadCache, ExitFromFTL))
                 || currentBaseline->hasExitSite(locker, DFG::FrequentExitSite(codeOrigin.bytecodeIndex, BadCacheWatchpoint, ExitFromFTL))

Modified: branches/jsCStack/Source/_javascript_Core/bytecode/CodeBlock.cpp (162810 => 162811)


--- branches/jsCStack/Source/_javascript_Core/bytecode/CodeBlock.cpp	2014-01-26 22:34:13 UTC (rev 162810)
+++ branches/jsCStack/Source/_javascript_Core/bytecode/CodeBlock.cpp	2014-01-26 22:39:31 UTC (rev 162811)
@@ -534,12 +534,7 @@
     out.printf("\n");
     
     StubInfoMap stubInfos;
-#if ENABLE(JIT)
-    {
-        ConcurrentJITLocker locker(m_lock);
-        getStubInfoMap(locker, stubInfos);
-    }
-#endif
+    getStubInfoMap(stubInfos);
     
     const Instruction* begin = instructions().begin();
     const Instruction* end = instructions().end();
@@ -2330,16 +2325,26 @@
 #endif
 }
 
+void CodeBlock::getStubInfoMap(const ConcurrentJITLocker&, StubInfoMap& result)
+{
 #if ENABLE(JIT)
-StructureStubInfo* CodeBlock::addStubInfo()
+    toHashMap(m_stubInfos, getStructureStubInfoCodeOrigin, result);
+#else
+    UNUSED_PARAM(result);
+#endif
+}
+
+void CodeBlock::getStubInfoMap(StubInfoMap& result)
 {
     ConcurrentJITLocker locker(m_lock);
-    return m_stubInfos.add();
+    getStubInfoMap(locker, result);
 }
 
-void CodeBlock::getStubInfoMap(const ConcurrentJITLocker&, StubInfoMap& result)
+#if ENABLE(JIT)
+StructureStubInfo* CodeBlock::addStubInfo()
 {
-    toHashMap(m_stubInfos, getStructureStubInfoCodeOrigin, result);
+    ConcurrentJITLocker locker(m_lock);
+    return m_stubInfos.add();
 }
 
 void CodeBlock::resetStub(StructureStubInfo& stubInfo)

Modified: branches/jsCStack/Source/_javascript_Core/bytecode/CodeBlock.h (162810 => 162811)


--- branches/jsCStack/Source/_javascript_Core/bytecode/CodeBlock.h	2014-01-26 22:34:13 UTC (rev 162810)
+++ branches/jsCStack/Source/_javascript_Core/bytecode/CodeBlock.h	2014-01-26 22:39:31 UTC (rev 162811)
@@ -175,6 +175,9 @@
     void expressionRangeForBytecodeOffset(unsigned bytecodeOffset, int& divot,
                                           int& startOffset, int& endOffset, unsigned& line, unsigned& column);
 
+    void getStubInfoMap(const ConcurrentJITLocker&, StubInfoMap& result);
+    void getStubInfoMap(StubInfoMap& result);
+
 #if ENABLE(JIT)
     StructureStubInfo* addStubInfo();
     Bag<StructureStubInfo>::iterator begin() { return m_stubInfos.begin(); }
@@ -182,8 +185,6 @@
 
     void resetStub(StructureStubInfo&);
     
-    void getStubInfoMap(const ConcurrentJITLocker&, StubInfoMap& result);
-
     ByValInfo& getByValInfo(unsigned bytecodeIndex)
     {
         return *(binarySearch<ByValInfo, unsigned>(m_byValInfos, m_byValInfos.size(), bytecodeIndex, getByValInfoBytecodeIndex));

Modified: branches/jsCStack/Source/_javascript_Core/bytecode/GetByIdStatus.cpp (162810 => 162811)


--- branches/jsCStack/Source/_javascript_Core/bytecode/GetByIdStatus.cpp	2014-01-26 22:34:13 UTC (rev 162810)
+++ branches/jsCStack/Source/_javascript_Core/bytecode/GetByIdStatus.cpp	2014-01-26 22:39:31 UTC (rev 162811)
@@ -34,12 +34,12 @@
 
 namespace JSC {
 
-bool GetByIdStatus::hasExitSite(const ConcurrentJITLocker& locker, CodeBlock* profiledBlock, unsigned bytecodeIndex)
+bool GetByIdStatus::hasExitSite(const ConcurrentJITLocker& locker, CodeBlock* profiledBlock, unsigned bytecodeIndex, ExitingJITType jitType)
 {
-    return profiledBlock->hasExitSite(locker, DFG::FrequentExitSite(bytecodeIndex, BadCache))
-        || profiledBlock->hasExitSite(locker, DFG::FrequentExitSite(bytecodeIndex, BadCacheWatchpoint))
-        || profiledBlock->hasExitSite(locker, DFG::FrequentExitSite(bytecodeIndex, BadWeakConstantCache))
-        || profiledBlock->hasExitSite(locker, DFG::FrequentExitSite(bytecodeIndex, BadWeakConstantCacheWatchpoint));
+    return profiledBlock->hasExitSite(locker, DFG::FrequentExitSite(bytecodeIndex, BadCache, jitType))
+        || profiledBlock->hasExitSite(locker, DFG::FrequentExitSite(bytecodeIndex, BadCacheWatchpoint, jitType))
+        || profiledBlock->hasExitSite(locker, DFG::FrequentExitSite(bytecodeIndex, BadWeakConstantCache, jitType))
+        || profiledBlock->hasExitSite(locker, DFG::FrequentExitSite(bytecodeIndex, BadWeakConstantCacheWatchpoint, jitType));
 }
 
 GetByIdStatus GetByIdStatus::computeFromLLInt(CodeBlock* profiledBlock, unsigned bytecodeIndex, StringImpl* uid)
@@ -128,18 +128,28 @@
 {
     ConcurrentJITLocker locker(profiledBlock->m_lock);
     
-    UNUSED_PARAM(profiledBlock);
-    UNUSED_PARAM(bytecodeIndex);
-    UNUSED_PARAM(uid);
-#if ENABLE(JIT)
-    StructureStubInfo* stubInfo = map.get(CodeOrigin(bytecodeIndex));
-    if (!stubInfo || !stubInfo->seen) {
-        if (hasExitSite(locker, profiledBlock, bytecodeIndex))
-            return GetByIdStatus(TakesSlowPath, true);
+    GetByIdStatus result = computeForStubInfo(
+        locker, profiledBlock, map.get(CodeOrigin(bytecodeIndex)), uid);
     
+    if (!result.takesSlowPath()
+        && (hasExitSite(locker, profiledBlock, bytecodeIndex)
+            || profiledBlock->likelyToTakeSlowCase(bytecodeIndex)))
+        return GetByIdStatus(TakesSlowPath, true);
+
+    if (!result)
         return computeFromLLInt(profiledBlock, bytecodeIndex, uid);
-    }
     
+    return result;
+}
+
+GetByIdStatus GetByIdStatus::computeForStubInfo(
+    const ConcurrentJITLocker&, CodeBlock* profiledBlock, StructureStubInfo* stubInfo,
+    StringImpl* uid)
+{
+#if ENABLE(JIT)
+    if (!stubInfo || !stubInfo->seen)
+        return GetByIdStatus(NoInformation);
+    
     if (stubInfo->resetByGC)
         return GetByIdStatus(TakesSlowPath, true);
 
@@ -164,17 +174,12 @@
             return GetByIdStatus(MakesCalls, true);
     }
     
-    // Next check if it takes slow case, in which case we want to be kind of careful.
-    if (profiledBlock->likelyToTakeSlowCase(bytecodeIndex)
-        || hasExitSite(locker, profiledBlock, bytecodeIndex))
-        return GetByIdStatus(TakesSlowPath, true);
-    
     // Finally figure out if we can derive an access strategy.
     GetByIdStatus result;
     result.m_wasSeenInJIT = true; // This is interesting for bytecode dumping only.
     switch (stubInfo->accessType) {
     case access_unset:
-        return computeFromLLInt(profiledBlock, bytecodeIndex, uid);
+        return GetByIdStatus(NoInformation);
         
     case access_get_by_id_self: {
         Structure* structure = stubInfo->u.getByIdSelf.baseObjectStructure.get();
@@ -275,11 +280,40 @@
     
     return result;
 #else // ENABLE(JIT)
-    UNUSED_PARAM(map);
+    UNUSED_PARAM(profiledBlock);
+    UNUSED_PARAM(stubInfo);
+    UNUSED_PARAM(uid);
     return GetByIdStatus(NoInformation, false);
 #endif // ENABLE(JIT)
 }
 
+GetByIdStatus GetByIdStatus::computeFor(
+    CodeBlock* profiledBlock, CodeBlock* dfgBlock, StubInfoMap& baselineMap,
+    StubInfoMap& dfgMap, CodeOrigin codeOrigin, StringImpl* uid)
+{
+    if (dfgBlock) {
+        GetByIdStatus result;
+        {
+            ConcurrentJITLocker locker(dfgBlock->m_lock);
+            result = computeForStubInfo(locker, dfgBlock, dfgMap.get(codeOrigin), uid);
+        }
+    
+        if (result.takesSlowPath())
+            return result;
+    
+        {
+            ConcurrentJITLocker locker(profiledBlock->m_lock);
+            if (hasExitSite(locker, profiledBlock, codeOrigin.bytecodeIndex, ExitFromFTL))
+                return GetByIdStatus(TakesSlowPath, true);
+        }
+        
+        if (result.isSet())
+            return result;
+    }
+
+    return computeFor(profiledBlock, baselineMap, codeOrigin.bytecodeIndex, uid);
+}
+
 GetByIdStatus GetByIdStatus::computeFor(VM& vm, Structure* structure, StringImpl* uid)
 {
     // For now we only handle the super simple self access case. We could handle the

Modified: branches/jsCStack/Source/_javascript_Core/bytecode/GetByIdStatus.h (162810 => 162811)


--- branches/jsCStack/Source/_javascript_Core/bytecode/GetByIdStatus.h	2014-01-26 22:34:13 UTC (rev 162810)
+++ branches/jsCStack/Source/_javascript_Core/bytecode/GetByIdStatus.h	2014-01-26 22:39:31 UTC (rev 162811)
@@ -26,7 +26,9 @@
 #ifndef GetByIdStatus_h
 #define GetByIdStatus_h
 
+#include "CodeOrigin.h"
 #include "ConcurrentJITLock.h"
+#include "ExitingJITType.h"
 #include "IntendedStructureChain.h"
 #include "PropertyOffset.h"
 #include "StructureSet.h"
@@ -75,6 +77,8 @@
     static GetByIdStatus computeFor(CodeBlock*, StubInfoMap&, unsigned bytecodeIndex, StringImpl* uid);
     static GetByIdStatus computeFor(VM&, Structure*, StringImpl* uid);
     
+    static GetByIdStatus computeFor(CodeBlock* baselineBlock, CodeBlock* dfgBlock, StubInfoMap& baselineMap, StubInfoMap& dfgMap, CodeOrigin, StringImpl* uid);
+    
     State state() const { return m_state; }
     
     bool isSet() const { return m_state != NoInformation; }
@@ -91,7 +95,8 @@
     bool wasSeenInJIT() const { return m_wasSeenInJIT; }
     
 private:
-    static bool hasExitSite(const ConcurrentJITLocker&, CodeBlock*, unsigned bytecodeIndex);
+    static bool hasExitSite(const ConcurrentJITLocker&, CodeBlock*, unsigned bytecodeIndex, ExitingJITType = ExitFromAnything);
+    static GetByIdStatus computeForStubInfo(const ConcurrentJITLocker&, CodeBlock*, StructureStubInfo*, StringImpl* uid);
     static void computeForChain(GetByIdStatus& result, CodeBlock*, StringImpl* uid);
     static GetByIdStatus computeFromLLInt(CodeBlock*, unsigned bytecodeIndex, StringImpl* uid);
     

Modified: branches/jsCStack/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp (162810 => 162811)


--- branches/jsCStack/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp	2014-01-26 22:34:13 UTC (rev 162810)
+++ branches/jsCStack/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp	2014-01-26 22:39:31 UTC (rev 162811)
@@ -1136,7 +1136,9 @@
     // work-around for the fact that JSValueMap can't handle "empty" values.
     unsigned m_emptyJSValueIndex;
     
+    CodeBlock* m_dfgCodeBlock;
     CallLinkStatus::ContextMap m_callContextMap;
+    StubInfoMap m_dfgStubInfos;
     
     Instruction* m_currentInstruction;
 };
@@ -2518,8 +2520,9 @@
             
             StringImpl* uid = m_graph.identifiers()[identifierNumber];
             GetByIdStatus getByIdStatus = GetByIdStatus::computeFor(
-                m_inlineStackTop->m_profiledBlock, m_inlineStackTop->m_stubInfos,
-                m_currentIndex, uid);
+                m_inlineStackTop->m_profiledBlock, m_dfgCodeBlock,
+                m_inlineStackTop->m_stubInfos, m_dfgStubInfos,
+                currentCodeOrigin(), uid);
             
             handleGetById(
                 currentInstruction[1].u.operand, prediction, base, identifierNumber, getByIdStatus);
@@ -3717,11 +3720,14 @@
     // Set during construction.
     ASSERT(!m_currentIndex);
     
-    if (isFTL(m_graph.m_plan.mode)
-        && !!m_graph.m_plan.profiledDFGCodeBlock
-        && Options::enablePolyvariantCallInlining()) {
-        CallLinkStatus::computeDFGStatuses(
-            m_graph.m_plan.profiledDFGCodeBlock.get(), m_callContextMap);
+    if (isFTL(m_graph.m_plan.mode)) {
+        m_dfgCodeBlock = m_graph.m_plan.profiledDFGCodeBlock.get();
+        if (m_dfgCodeBlock) {
+            if (Options::enablePolyvariantCallInlining())
+                CallLinkStatus::computeDFGStatuses(m_dfgCodeBlock, m_callContextMap);
+            if (Options::enablePolyvariantByIdInlining())
+                m_dfgCodeBlock->getStubInfoMap(m_dfgStubInfos);
+        }
     }
     
     if (m_codeBlock->captureCount()) {

Modified: branches/jsCStack/Source/_javascript_Core/runtime/Options.h (162810 => 162811)


--- branches/jsCStack/Source/_javascript_Core/runtime/Options.h	2014-01-26 22:34:13 UTC (rev 162810)
+++ branches/jsCStack/Source/_javascript_Core/runtime/Options.h	2014-01-26 22:39:31 UTC (rev 162811)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011, 2012, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 2012, 2013, 2014 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -176,6 +176,7 @@
     v(unsigned, maximumInliningRecursionForMustInline, 3) \
     \
     v(bool, enablePolyvariantCallInlining, true) \
+    v(bool, enablePolyvariantByIdInlining, true) \
     \
     v(unsigned, maximumBinaryStringSwitchCaseLength, 50) \
     v(unsigned, maximumBinaryStringSwitchTotalLength, 2000) \

Added: branches/jsCStack/Source/_javascript_Core/tests/stress/simple-polyvariant-get-by-id-inlining-example.js (0 => 162811)


--- branches/jsCStack/Source/_javascript_Core/tests/stress/simple-polyvariant-get-by-id-inlining-example.js	                        (rev 0)
+++ branches/jsCStack/Source/_javascript_Core/tests/stress/simple-polyvariant-get-by-id-inlining-example.js	2014-01-26 22:39:31 UTC (rev 162811)
@@ -0,0 +1,24 @@
+function foo(o) {
+    return bar(o);
+}
+
+function fuzz(o) {
+    return bar(o);
+}
+
+function bar(o) {
+    return o.f;
+}
+
+noInline(foo);
+noInline(fuzz);
+
+for (var i = 0; i < 100000; ++i) {
+    var result = foo({f:42});
+    if (result != 42)
+        throw "Error: bad result: " + result;
+    var result = fuzz({g:23, f:24});
+    if (result != 24)
+        throw "Error: bad result: " + result;
+}
+
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to