compilation policy should adapt to past behavior
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Jun 2016 19:20:23 +0000 (19:20 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Jun 2016 19:20:23 +0000 (19:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=158759

Reviewed by Saam Barati.

This looks like a ~9% speedup on JSBench.

* bytecode/CodeBlock.cpp:
(JSC::CodeBlock::~CodeBlock): Record when a CodeBlock dies without ever
making it to DFG.

(JSC::CodeBlock::thresholdForJIT): CodeBlocks that make it to DFG should
compile sooner; CodeBlocks that don't should compile later. The goal is
to use past behavior, in addition to execution counts, to determine
whether compilation is profitable.

(JSC::CodeBlock::jitAfterWarmUp):
(JSC::CodeBlock::jitSoon): Apply the thresholdForJIT rule.

* bytecode/CodeBlock.h: Moved some code into the .cpp file so I could
change stuff without recompiling.
(JSC::CodeBlock::jitAfterWarmUp): Deleted.
(JSC::CodeBlock::jitSoon): Deleted.

* bytecode/UnlinkedCodeBlock.cpp:
(JSC::UnlinkedCodeBlock::UnlinkedCodeBlock):
* bytecode/UnlinkedCodeBlock.h:
(JSC::UnlinkedCodeBlock::didOptimize):
(JSC::UnlinkedCodeBlock::setDidOptimize): Added a piece of data to track
whether we made it to DFG.

* jit/JITOperations.cpp: Record when we make it to DFG.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202098 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/bytecode/CodeBlock.cpp
Source/JavaScriptCore/bytecode/CodeBlock.h
Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp
Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h
Source/JavaScriptCore/jit/JITOperations.cpp

index 8b8e601..8956ba2 100644 (file)
@@ -1,3 +1,38 @@
+2016-06-14  Geoffrey Garen  <ggaren@apple.com>
+
+        compilation policy should adapt to past behavior
+        https://bugs.webkit.org/show_bug.cgi?id=158759
+
+        Reviewed by Saam Barati.
+
+        This looks like a ~9% speedup on JSBench.
+
+        * bytecode/CodeBlock.cpp:
+        (JSC::CodeBlock::~CodeBlock): Record when a CodeBlock dies without ever
+        making it to DFG.
+
+        (JSC::CodeBlock::thresholdForJIT): CodeBlocks that make it to DFG should
+        compile sooner; CodeBlocks that don't should compile later. The goal is
+        to use past behavior, in addition to execution counts, to determine
+        whether compilation is profitable.
+
+        (JSC::CodeBlock::jitAfterWarmUp):
+        (JSC::CodeBlock::jitSoon): Apply the thresholdForJIT rule.
+
+        * bytecode/CodeBlock.h: Moved some code into the .cpp file so I could
+        change stuff without recompiling.
+        (JSC::CodeBlock::jitAfterWarmUp): Deleted.
+        (JSC::CodeBlock::jitSoon): Deleted.
+
+        * bytecode/UnlinkedCodeBlock.cpp:
+        (JSC::UnlinkedCodeBlock::UnlinkedCodeBlock):
+        * bytecode/UnlinkedCodeBlock.h:
+        (JSC::UnlinkedCodeBlock::didOptimize):
+        (JSC::UnlinkedCodeBlock::setDidOptimize): Added a piece of data to track
+        whether we made it to DFG.
+
+        * jit/JITOperations.cpp: Record when we make it to DFG.
+
 2016-06-15  Konstantin Tokarev  <annulen@yandex.ru>
 
         Only Mac port needs ObjC API for JSC.
index 65e8fab..0697c58 100644 (file)
@@ -2418,7 +2418,10 @@ CodeBlock::~CodeBlock()
 {
     if (m_vm->m_perBytecodeProfiler)
         m_vm->m_perBytecodeProfiler->notifyDestruction(this);
-    
+
+    if (unlinkedCodeBlock()->didOptimize() == MixedTriState)
+        unlinkedCodeBlock()->setDidOptimize(FalseTriState);
+
 #if ENABLE(VERBOSE_VALUE_PROFILE)
     dumpValueProfiles();
 #endif
@@ -4435,4 +4438,26 @@ Optional<unsigned> CodeBlock::bytecodeOffsetFromCallSiteIndex(CallSiteIndex call
     return bytecodeOffset;
 }
 
+int32_t CodeBlock::thresholdForJIT(int32_t threshold)
+{
+    switch (unlinkedCodeBlock()->didOptimize()) {
+    case MixedTriState:
+        return threshold;
+    case FalseTriState:
+        return threshold * 4;
+    case TrueTriState:
+        return threshold / 2;
+    }
+}
+
+void CodeBlock::jitAfterWarmUp()
+{
+    m_llintExecuteCounter.setNewThreshold(thresholdForJIT(Options::thresholdForJITAfterWarmUp()), this);
+}
+
+void CodeBlock::jitSoon()
+{
+    m_llintExecuteCounter.setNewThreshold(thresholdForJIT(Options::thresholdForJITSoon()), this);
+}
+
 } // namespace JSC
index 50d0749..5bba339 100644 (file)
@@ -664,15 +664,9 @@ public:
         m_llintExecuteCounter.deferIndefinitely();
     }
 
-    void jitAfterWarmUp()
-    {
-        m_llintExecuteCounter.setNewThreshold(Options::thresholdForJITAfterWarmUp(), this);
-    }
-
-    void jitSoon()
-    {
-        m_llintExecuteCounter.setNewThreshold(Options::thresholdForJITSoon(), this);
-    }
+    int32_t thresholdForJIT(int32_t threshold);
+    void jitAfterWarmUp();
+    void jitSoon();
 
     const BaselineExecutionCounter& llintExecuteCounter() const
     {
index b5ea519..299ac68 100644 (file)
@@ -72,6 +72,7 @@ UnlinkedCodeBlock::UnlinkedCodeBlock(VM* vm, Structure* structure, CodeType code
     , m_firstLine(0)
     , m_lineCount(0)
     , m_endColumn(UINT_MAX)
+    , m_didOptimize(MixedTriState)
     , m_parseMode(info.parseMode())
     , m_features(0)
     , m_codeType(codeType)
index 94437aa..91fdca4 100644 (file)
@@ -43,6 +43,7 @@
 #include "VirtualRegister.h"
 #include <wtf/FastBitVector.h>
 #include <wtf/RefCountedArray.h>
+#include <wtf/TriState.h>
 #include <wtf/Vector.h>
 
 namespace JSC {
@@ -370,6 +371,9 @@ public:
 
     bool wasCompiledWithDebuggingOpcodes() const { return m_wasCompiledWithDebuggingOpcodes; }
 
+    TriState didOptimize() const { return m_didOptimize; }
+    void setDidOptimize(TriState didOptimize) { m_didOptimize = didOptimize; }
+
 protected:
     UnlinkedCodeBlock(VM*, Structure*, CodeType, const ExecutableInfo&, DebuggerMode);
     ~UnlinkedCodeBlock();
@@ -416,6 +420,7 @@ private:
     unsigned m_lineCount;
     unsigned m_endColumn;
 
+    TriState m_didOptimize;
     SourceParseMode m_parseMode;
     CodeFeatures m_features;
     CodeType m_codeType;
index 7a9948a..b08c30f 100644 (file)
@@ -1388,6 +1388,7 @@ SlowPathReturnType JIT_OPERATION operationOptimize(ExecState* exec, int32_t byte
         }
 
         codeBlock->optimizeSoon();
+        codeBlock->unlinkedCodeBlock()->setDidOptimize(TrueTriState);
         return encodeResult(vm.getCTIStub(DFG::osrEntryThunkGenerator).code().executableAddress(), dataBuffer);
     }