Should support value profiling on CPU(X86)
authorbarraclough@apple.com <barraclough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Sep 2011 22:43:11 +0000 (22:43 +0000)
committerbarraclough@apple.com <barraclough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Sep 2011 22:43:11 +0000 (22:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=68575

Reviewed by Sam Weinig.

Fix verbose profiling in ToT (SlowCaseProfile had been
partially renamed to RareCaseProfile), add in-memory
bucket counter for CPU(X86), move JIT::m_canBeOptimized
out of the DFG_JIT ifdef.

* bytecode/CodeBlock.cpp:
(JSC::CodeBlock::resetRareCaseProfiles):
(JSC::CodeBlock::dumpValueProfiles):
* bytecode/CodeBlock.h:
* dfg/DFGByteCodeParser.cpp:
(JSC::DFG::ByteCodeParser::makeSafe):
* jit/JIT.cpp:
(JSC::JIT::privateCompileSlowCases):
(JSC::JIT::privateCompile):
* jit/JIT.h:
* jit/JITInlineMethods.h:
(JSC::JIT::emitValueProfilingSite):

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/bytecode/CodeBlock.cpp
Source/JavaScriptCore/bytecode/CodeBlock.h
Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp
Source/JavaScriptCore/jit/JIT.cpp
Source/JavaScriptCore/jit/JIT.h
Source/JavaScriptCore/jit/JITInlineMethods.h

index 7a7f967..6c5cde7 100644 (file)
@@ -1,3 +1,28 @@
+2011-09-21  Gavin Barraclough  <barraclough@apple.com>
+
+        Should support value profiling on CPU(X86)
+        https://bugs.webkit.org/show_bug.cgi?id=68575
+
+        Reviewed by Sam Weinig.
+
+        Fix verbose profiling in ToT (SlowCaseProfile had been
+        partially renamed to RareCaseProfile), add in-memory
+        bucket counter for CPU(X86), move JIT::m_canBeOptimized
+        out of the DFG_JIT ifdef.
+
+        * bytecode/CodeBlock.cpp:
+        (JSC::CodeBlock::resetRareCaseProfiles):
+        (JSC::CodeBlock::dumpValueProfiles):
+        * bytecode/CodeBlock.h:
+        * dfg/DFGByteCodeParser.cpp:
+        (JSC::DFG::ByteCodeParser::makeSafe):
+        * jit/JIT.cpp:
+        (JSC::JIT::privateCompileSlowCases):
+        (JSC::JIT::privateCompile):
+        * jit/JIT.h:
+        * jit/JITInlineMethods.h:
+        (JSC::JIT::emitValueProfilingSite):
+
 2011-09-21  Filip Pizlo  <fpizlo@apple.com>
 
         DFG does not support compiling functions as constructors
index e8c74b6..231ad2f 100644 (file)
@@ -1987,8 +1987,8 @@ bool CodeBlock::shouldOptimizeNow()
 #if ENABLE(VALUE_PROFILER)
 void CodeBlock::resetRareCaseProfiles()
 {
-    for (unsigned i = 0; i < numberOfSlowCaseProfiles(); ++i)
-        slowCaseProfile(i)->m_counter = 0;
+    for (unsigned i = 0; i < numberOfRareCaseProfiles(); ++i)
+        rareCaseProfile(i)->m_counter = 0;
     for (unsigned i = 0; i < numberOfSpecialFastCaseProfiles(); ++i)
         specialFastCaseProfile(i)->m_counter = 0;
 }
@@ -2012,9 +2012,9 @@ void CodeBlock::dumpValueProfiles()
         profile->dump(stderr);
         fprintf(stderr, "\n");
     }
-    fprintf(stderr, "SlowCaseProfile for %p:\n", this);
-    for (unsigned i = 0; i < numberOfSlowCaseProfiles(); ++i) {
-        SlowCaseProfile* profile = slowCaseProfile(i);
+    fprintf(stderr, "RareCaseProfile for %p:\n", this);
+    for (unsigned i = 0; i < numberOfRareCaseProfiles(); ++i) {
+        RareCaseProfile* profile = rareCaseProfile(i);
         fprintf(stderr, "   bc = %d: %u\n", profile->m_bytecodeOffset, profile->m_counter);
     }
 }
index 1ef7339..d8bcd0b 100644 (file)
@@ -489,22 +489,22 @@ namespace JSC {
             return result;
         }
         
-        RareCaseProfile* addSlowCaseProfile(int bytecodeOffset)
+        RareCaseProfile* addRareCaseProfile(int bytecodeOffset)
         {
-            m_slowCaseProfiles.append(RareCaseProfile(bytecodeOffset));
-            return &m_slowCaseProfiles.last();
+            m_rareCaseProfiles.append(RareCaseProfile(bytecodeOffset));
+            return &m_rareCaseProfiles.last();
         }
-        unsigned numberOfSlowCaseProfiles() { return m_slowCaseProfiles.size(); }
-        RareCaseProfile* slowCaseProfile(int index) { return &m_slowCaseProfiles[index]; }
-        RareCaseProfile* slowCaseProfileForBytecodeOffset(int bytecodeOffset)
+        unsigned numberOfRareCaseProfiles() { return m_rareCaseProfiles.size(); }
+        RareCaseProfile* rareCaseProfile(int index) { return &m_rareCaseProfiles[index]; }
+        RareCaseProfile* rareCaseProfileForBytecodeOffset(int bytecodeOffset)
         {
-            return WTF::genericBinarySearch<RareCaseProfile, int, getRareCaseProfileBytecodeOffset>(m_slowCaseProfiles, m_slowCaseProfiles.size(), bytecodeOffset);
+            return WTF::genericBinarySearch<RareCaseProfile, int, getRareCaseProfileBytecodeOffset>(m_rareCaseProfiles, m_rareCaseProfiles.size(), bytecodeOffset);
         }
         
         static uint32_t slowCaseThreshold() { return 100; }
         bool likelyToTakeSlowCase(int bytecodeOffset)
         {
-            return slowCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter >= slowCaseThreshold();
+            return rareCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter >= slowCaseThreshold();
         }
         
         RareCaseProfile* addSpecialFastCaseProfile(int bytecodeOffset)
@@ -521,7 +521,7 @@ namespace JSC {
         
         bool likelyToTakeDeepestSlowCase(int bytecodeOffset)
         {
-            unsigned slowCaseCount = slowCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
+            unsigned slowCaseCount = rareCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
             unsigned specialFastCaseCount = specialFastCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
             return (slowCaseCount - specialFastCaseCount) >= slowCaseThreshold();
         }
@@ -830,7 +830,7 @@ namespace JSC {
 #endif
 #if ENABLE(VALUE_PROFILER)
         SegmentedVector<ValueProfile, 8> m_valueProfiles;
-        SegmentedVector<RareCaseProfile, 8> m_slowCaseProfiles;
+        SegmentedVector<RareCaseProfile, 8> m_rareCaseProfiles;
         SegmentedVector<RareCaseProfile, 8> m_specialFastCaseProfiles;
 #endif
 
index 0348ad0..74d57cc 100644 (file)
@@ -513,7 +513,7 @@ private:
             return nodeIndex;
         
 #if ENABLE(DFG_DEBUG_VERBOSE)
-        printf("Making %s @%u safe at bc#%u because slow-case counter is at %u\n", Graph::opName(m_graph[nodeIndex].op), nodeIndex, m_currentIndex, m_profiledBlock->slowCaseProfileForBytecodeOffset(m_currentIndex)->m_counter);
+        printf("Making %s @%u safe at bc#%u because slow-case counter is at %u\n", Graph::opName(m_graph[nodeIndex].op), nodeIndex, m_currentIndex, m_profiledBlock->rareCaseProfileForBytecodeOffset(m_currentIndex)->m_counter);
 #endif
         
         switch (m_graph[nodeIndex].op) {
index f45f81d..43e8d2b 100644 (file)
@@ -415,9 +415,9 @@ void JIT::privateCompileSlowCases()
         Instruction* currentInstruction = instructionsBegin + m_bytecodeOffset;
         
 #if ENABLE(VALUE_PROFILER)
-        RareCaseProfile* slowCaseProfile = 0;
+        RareCaseProfile* rareCaseProfile = 0;
         if (m_canBeOptimized)
-            slowCaseProfile = m_codeBlock->addSlowCaseProfile(m_bytecodeOffset);
+            rareCaseProfile = m_codeBlock->addRareCaseProfile(m_bytecodeOffset);
 #endif
 
         switch (m_interpreter->getOpcodeID(currentInstruction->u.opcode)) {
@@ -494,7 +494,7 @@ void JIT::privateCompileSlowCases()
         
 #if ENABLE(VALUE_PROFILER)
         if (m_canBeOptimized)
-            add32(Imm32(1), AbsoluteAddress(&slowCaseProfile->m_counter));
+            add32(Imm32(1), AbsoluteAddress(&rareCaseProfile->m_counter));
 #endif
 
         emitJumpSlowToHot(jump(), 0);
@@ -514,8 +514,10 @@ void JIT::privateCompileSlowCases()
 
 JITCode JIT::privateCompile(CodePtr* functionEntryArityCheck)
 {
-#if ENABLE(DFG_JIT)
+#if ENABLE(VALUE_PROFILER)
     m_canBeOptimized = m_codeBlock->canCompileWithDFG();
+#endif
+#if ENABLE(DFG_JIT)
     if (m_canBeOptimized)
         m_startOfCode = label();
 #endif
index 0761811..d4d84f7 100644 (file)
@@ -1074,9 +1074,11 @@ namespace JSC {
 #endif
         WeakRandom m_randomGenerator;
         static CodeRef stringGetByValStubGenerator(JSGlobalData*);
-        
-#if ENABLE(DFG_JIT)
+
+#if ENABLE(VALUE_PROFILER)
         bool m_canBeOptimized;
+#endif
+#if ENABLE(DFG_JIT)
         Label m_startOfCode;
         CompactJITCodeMap::Encoder m_jitCodeMapEncoder;
 #endif
index bee36c4..7c5a4e1 100644 (file)
@@ -446,6 +446,10 @@ inline void JIT::emitAllocateJSFunction(FunctionExecutable* executable, Register
 #endif
 }
 
+#if CPU(X86)
+static int bucketCounter;
+#endif
+
 #if ENABLE(VALUE_PROFILER)
 inline void JIT::emitValueProfilingSite(ValueProfilingSiteKind siteKind)
 {
@@ -465,6 +469,17 @@ inline void JIT::emitValueProfilingSite(ValueProfilingSiteKind siteKind)
     
     ASSERT(valueProfile);
     
+#if CPU(X86)
+    if (m_randomGenerator.getUint32() & 1)
+        add32(Imm32(1), AbsoluteAddress(&bucketCounter));
+    else
+        add32(Imm32(3), AbsoluteAddress(&bucketCounter));
+    and32(Imm32(ValueProfile::bucketIndexMask), AbsoluteAddress(&bucketCounter));
+    load32(&bucketCounter, scratch);
+    lshift32(TrustedImm32(3), scratch);
+    addPtr(ImmPtr(valueProfile->m_buckets), scratch);
+    storePtr(value, scratch);
+#else
     if (m_randomGenerator.getUint32() & 1)
         add32(Imm32(1), bucketCounterRegister);
     else
@@ -472,6 +487,7 @@ inline void JIT::emitValueProfilingSite(ValueProfilingSiteKind siteKind)
     and32(Imm32(ValueProfile::bucketIndexMask), bucketCounterRegister);
     move(ImmPtr(valueProfile->m_buckets), scratch);
     storePtr(value, BaseIndex(scratch, bucketCounterRegister, TimesEight));
+#endif
 }
 #endif