JSC profiler should show reasons for jettison
https://bugs.webkit.org/show_bug.cgi?id=128047

Source/JavaScriptCore: 

Reviewed by Geoffrey Garen.
        
Henceforth if you want to jettison a CodeBlock, you gotta tell the Profiler why you did
it. This makes figuring out convergence issues - where some code seems to take a long
time to get into the top tier compiler - a lot easier.

* CMakeLists.txt:
* GNUmakefile.list.am:
* JavaScriptCore.vcxproj/JavaScriptCore.vcxproj:
* JavaScriptCore.xcodeproj/project.pbxproj:
* bytecode/CodeBlock.cpp:
(JSC::CodeBlock::finalizeUnconditionally):
(JSC::CodeBlock::jettison):
(JSC::CodeBlock::addBreakpoint):
(JSC::CodeBlock::setSteppingMode):
* bytecode/CodeBlock.h:
* bytecode/CodeBlockJettisoningWatchpoint.cpp:
(JSC::CodeBlockJettisoningWatchpoint::fireInternal):
* bytecode/ProfiledCodeBlockJettisoningWatchpoint.cpp:
(JSC::ProfiledCodeBlockJettisoningWatchpoint::fireInternal):
* dfg/DFGOperations.cpp:
* jit/JITOperations.cpp:
* profiler/ProfilerCompilation.cpp:
(JSC::Profiler::Compilation::Compilation):
(JSC::Profiler::Compilation::toJS):
* profiler/ProfilerCompilation.h:
(JSC::Profiler::Compilation::setJettisonReason):
* profiler/ProfilerJettisonReason.cpp: Added.
(WTF::printInternal):
* profiler/ProfilerJettisonReason.h: Added.
* runtime/CommonIdentifiers.h:
* runtime/VM.cpp:
(JSC::SetEnabledProfilerFunctor::operator()):

Tools: 

Reviewed by Geoffrey Garen.
        
Gave the tool a "log" command, that tells you all of the interesting things
that happened to a piece of bytecode, from the standpoint of optimization.
It's a great summary view for seeing how our tier-up machinery works.
        
This uses a lot of information that was already available, plus the newly
added jettisonReason field.

* Scripts/display-profiler-output:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@163254 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/bytecode/CodeBlock.cpp b/Source/JavaScriptCore/bytecode/CodeBlock.cpp
index 94d6f01..732e726 100644
--- a/Source/JavaScriptCore/bytecode/CodeBlock.cpp
+++ b/Source/JavaScriptCore/bytecode/CodeBlock.cpp
@@ -2287,7 +2287,7 @@
             }
         }
         
-        jettison();
+        jettison(Profiler::JettisonDueToWeakReference);
         return;
     }
 #endif // ENABLE(DFG_JIT)
@@ -2766,19 +2766,24 @@
 }
 #endif
 
-void CodeBlock::jettison(ReoptimizationMode mode)
+void CodeBlock::jettison(Profiler::JettisonReason reason, ReoptimizationMode mode)
 {
+    RELEASE_ASSERT(reason != Profiler::NotJettisoned);
+    
 #if ENABLE(DFG_JIT)
     if (DFG::shouldShowDisassembly()) {
         dataLog("Jettisoning ", *this);
         if (mode == CountReoptimization)
             dataLog(" and counting reoptimization");
-        dataLog(".\n");
+        dataLog(" due to ", reason, ".\n");
     }
     
     DeferGCForAWhile deferGC(*m_heap);
     RELEASE_ASSERT(JITCode::isOptimizingJIT(jitType()));
     
+    if (Profiler::Compilation* compilation = jitCode()->dfgCommon()->compilation.get())
+        compilation->setJettisonReason(reason);
+    
     // We want to accomplish two things here:
     // 1) Make sure that if this CodeBlock is on the stack right now, then if we return to it
     //    we should OSR exit at the top of the next bytecode instruction after the return.
@@ -3559,14 +3564,14 @@
     m_numBreakpoints += numBreakpoints;
     ASSERT(m_numBreakpoints);
     if (JITCode::isOptimizingJIT(jitType()))
-        jettison();
+        jettison(Profiler::JettisonDueToDebuggerBreakpoint);
 }
 
 void CodeBlock::setSteppingMode(CodeBlock::SteppingMode mode)
 {
     m_steppingMode = mode;
     if (mode == SteppingModeEnabled && JITCode::isOptimizingJIT(jitType()))
-        jettison();
+        jettison(Profiler::JettisonDueToDebuggerStepping);
 }
 
 } // namespace JSC