<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[196147] trunk/Source/JavaScriptCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/196147">196147</a></dd>
<dt>Author</dt> <dd>sbarati@apple.com</dd>
<dt>Date</dt> <dd>2016-02-04 13:51:40 -0800 (Thu, 04 Feb 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>JSC Sampling Profiler: (host) is confusing in cases where I would expect to see JS name
https://bugs.webkit.org/show_bug.cgi?id=153663
&lt;rdar://problem/24415092&gt;

Reviewed by Geoffrey Garen.

We now collect the Callee in the processed StackFrame
when the Callee is a valid GC object. We later ask
the Callee for it's .displayName or .name property.
When we don't have a valid callee, we will still
use the Executable for this information.

This helps us come up with good names for frames where 
the Callee object is a bound function or an InternalFunction.

* inspector/agents/InspectorScriptProfilerAgent.cpp:
(Inspector::InspectorScriptProfilerAgent::addEvent):
(Inspector::buildSamples):
(Inspector::InspectorScriptProfilerAgent::trackingComplete):
* runtime/SamplingProfiler.cpp:
(JSC::reportStats):
(JSC::FrameWalker::walk):
(JSC::SamplingProfiler::processUnverifiedStackTraces):
(JSC::SamplingProfiler::visit):
(JSC::SamplingProfiler::shutdown):
(JSC::SamplingProfiler::clearData):
(JSC::SamplingProfiler::StackFrame::nameFromCallee):
(JSC::SamplingProfiler::StackFrame::displayName):
(JSC::SamplingProfiler::StackFrame::displayNameForJSONTests):
(JSC::SamplingProfiler::stackTracesAsJSON):
* runtime/SamplingProfiler.h:
(JSC::SamplingProfiler::UnprocessedStackFrame::UnprocessedStackFrame):
(JSC::SamplingProfiler::StackFrame::StackFrame):
* tests/stress/sampling-profiler-basic.js:
(platformSupportsSamplingProfiler.nothing):
(platformSupportsSamplingProfiler.top):
* tests/stress/sampling-profiler-bound-function-name.js: Added.
(platformSupportsSamplingProfiler.foo):
(platformSupportsSamplingProfiler.bar):
(platformSupportsSamplingProfiler.let.baz):
(platformSupportsSamplingProfiler):
* tests/stress/sampling-profiler-display-name.js: Added.
(platformSupportsSamplingProfiler.foo):
(platformSupportsSamplingProfiler.baz):
(platformSupportsSamplingProfiler.):
(platformSupportsSamplingProfiler.bar):
(platformSupportsSamplingProfiler.jaz):
(platformSupportsSamplingProfiler.makeFunction.let.result):
(platformSupportsSamplingProfiler.makeFunction):
* tests/stress/sampling-profiler-internal-function-name.js: Added.
(platformSupportsSamplingProfiler.foo):
(platformSupportsSamplingProfiler.bar):
(platformSupportsSamplingProfiler):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectoragentsInspectorScriptProfilerAgentcpp">trunk/Source/JavaScriptCore/inspector/agents/InspectorScriptProfilerAgent.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeSamplingProfilercpp">trunk/Source/JavaScriptCore/runtime/SamplingProfiler.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeSamplingProfilerh">trunk/Source/JavaScriptCore/runtime/SamplingProfiler.h</a></li>
<li><a href="#trunkSourceJavaScriptCoretestsstresssamplingprofilerbasicjs">trunk/Source/JavaScriptCore/tests/stress/sampling-profiler-basic.js</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoretestsstresssamplingprofilerboundfunctionnamejs">trunk/Source/JavaScriptCore/tests/stress/sampling-profiler-bound-function-name.js</a></li>
<li><a href="#trunkSourceJavaScriptCoretestsstresssamplingprofilerdisplaynamejs">trunk/Source/JavaScriptCore/tests/stress/sampling-profiler-display-name.js</a></li>
<li><a href="#trunkSourceJavaScriptCoretestsstresssamplingprofilerinternalfunctionnamejs">trunk/Source/JavaScriptCore/tests/stress/sampling-profiler-internal-function-name.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (196146 => 196147)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-02-04 21:51:26 UTC (rev 196146)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-02-04 21:51:40 UTC (rev 196147)
</span><span class="lines">@@ -1,3 +1,59 @@
</span><ins>+2016-02-04  Saam barati  &lt;sbarati@apple.com&gt;
+
+        JSC Sampling Profiler: (host) is confusing in cases where I would expect to see JS name
+        https://bugs.webkit.org/show_bug.cgi?id=153663
+        &lt;rdar://problem/24415092&gt;
+
+        Reviewed by Geoffrey Garen.
+
+        We now collect the Callee in the processed StackFrame
+        when the Callee is a valid GC object. We later ask
+        the Callee for it's .displayName or .name property.
+        When we don't have a valid callee, we will still
+        use the Executable for this information.
+
+        This helps us come up with good names for frames where 
+        the Callee object is a bound function or an InternalFunction.
+
+        * inspector/agents/InspectorScriptProfilerAgent.cpp:
+        (Inspector::InspectorScriptProfilerAgent::addEvent):
+        (Inspector::buildSamples):
+        (Inspector::InspectorScriptProfilerAgent::trackingComplete):
+        * runtime/SamplingProfiler.cpp:
+        (JSC::reportStats):
+        (JSC::FrameWalker::walk):
+        (JSC::SamplingProfiler::processUnverifiedStackTraces):
+        (JSC::SamplingProfiler::visit):
+        (JSC::SamplingProfiler::shutdown):
+        (JSC::SamplingProfiler::clearData):
+        (JSC::SamplingProfiler::StackFrame::nameFromCallee):
+        (JSC::SamplingProfiler::StackFrame::displayName):
+        (JSC::SamplingProfiler::StackFrame::displayNameForJSONTests):
+        (JSC::SamplingProfiler::stackTracesAsJSON):
+        * runtime/SamplingProfiler.h:
+        (JSC::SamplingProfiler::UnprocessedStackFrame::UnprocessedStackFrame):
+        (JSC::SamplingProfiler::StackFrame::StackFrame):
+        * tests/stress/sampling-profiler-basic.js:
+        (platformSupportsSamplingProfiler.nothing):
+        (platformSupportsSamplingProfiler.top):
+        * tests/stress/sampling-profiler-bound-function-name.js: Added.
+        (platformSupportsSamplingProfiler.foo):
+        (platformSupportsSamplingProfiler.bar):
+        (platformSupportsSamplingProfiler.let.baz):
+        (platformSupportsSamplingProfiler):
+        * tests/stress/sampling-profiler-display-name.js: Added.
+        (platformSupportsSamplingProfiler.foo):
+        (platformSupportsSamplingProfiler.baz):
+        (platformSupportsSamplingProfiler.):
+        (platformSupportsSamplingProfiler.bar):
+        (platformSupportsSamplingProfiler.jaz):
+        (platformSupportsSamplingProfiler.makeFunction.let.result):
+        (platformSupportsSamplingProfiler.makeFunction):
+        * tests/stress/sampling-profiler-internal-function-name.js: Added.
+        (platformSupportsSamplingProfiler.foo):
+        (platformSupportsSamplingProfiler.bar):
+        (platformSupportsSamplingProfiler):
+
</ins><span class="cx"> 2016-02-04  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Object.getOwnPropertyDescriptor() returns incomplete descriptor for instance properties
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectoragentsInspectorScriptProfilerAgentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/agents/InspectorScriptProfilerAgent.cpp (196146 => 196147)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/agents/InspectorScriptProfilerAgent.cpp        2016-02-04 21:51:26 UTC (rev 196146)
+++ trunk/Source/JavaScriptCore/inspector/agents/InspectorScriptProfilerAgent.cpp        2016-02-04 21:51:40 UTC (rev 196147)
</span><span class="lines">@@ -157,7 +157,7 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(SAMPLING_PROFILER)
</span><del>-static Ref&lt;Protocol::ScriptProfiler::Samples&gt; buildSamples(Vector&lt;SamplingProfiler::StackTrace&gt;&amp;&amp; samplingProfilerStackTraces, double totalTime)
</del><ins>+static Ref&lt;Protocol::ScriptProfiler::Samples&gt; buildSamples(VM&amp; vm, Vector&lt;SamplingProfiler::StackTrace&gt;&amp;&amp; samplingProfilerStackTraces, double totalTime)
</ins><span class="cx"> {
</span><span class="cx">     Ref&lt;Protocol::Array&lt;Protocol::ScriptProfiler::StackTrace&gt;&gt; stackTraces = Protocol::Array&lt;Protocol::ScriptProfiler::StackTrace&gt;::create();
</span><span class="cx">     for (SamplingProfiler::StackTrace&amp; stackTrace : samplingProfilerStackTraces) {
</span><span class="lines">@@ -165,7 +165,7 @@
</span><span class="cx">         for (SamplingProfiler::StackFrame&amp; stackFrame : stackTrace.frames) {
</span><span class="cx">             Ref&lt;Protocol::ScriptProfiler::StackFrame&gt; frame = Protocol::ScriptProfiler::StackFrame::create()
</span><span class="cx">                 .setSourceID(String::number(stackFrame.sourceID()))
</span><del>-                .setName(stackFrame.displayName())
</del><ins>+                .setName(stackFrame.displayName(vm))
</ins><span class="cx">                 .setLine(stackFrame.functionStartLine())
</span><span class="cx">                 .setColumn(stackFrame.functionStartColumn())
</span><span class="cx">                 .setUrl(stackFrame.url())
</span><span class="lines">@@ -195,7 +195,7 @@
</span><span class="cx">         LockHolder locker(samplingProfiler-&gt;getLock());
</span><span class="cx">         samplingProfiler-&gt;stop(locker);
</span><span class="cx">         Vector&lt;SamplingProfiler::StackTrace&gt; stackTraces = samplingProfiler-&gt;releaseStackTraces(locker);
</span><del>-        Ref&lt;Protocol::ScriptProfiler::Samples&gt; samples = buildSamples(WTFMove(stackTraces), samplingProfiler-&gt;totalTime(locker));
</del><ins>+        Ref&lt;Protocol::ScriptProfiler::Samples&gt; samples = buildSamples(m_environment.scriptDebugServer().vm(), WTFMove(stackTraces), samplingProfiler-&gt;totalTime(locker));
</ins><span class="cx"> 
</span><span class="cx">         locker.unlockEarly();
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeSamplingProfilercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/SamplingProfiler.cpp (196146 => 196147)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/SamplingProfiler.cpp        2016-02-04 21:51:26 UTC (rev 196146)
+++ trunk/Source/JavaScriptCore/runtime/SamplingProfiler.cpp        2016-02-04 21:51:40 UTC (rev 196147)
</span><span class="lines">@@ -44,6 +44,7 @@
</span><span class="cx"> #include &quot;PCToCodeOriginMap.h&quot;
</span><span class="cx"> #include &quot;SlotVisitor.h&quot;
</span><span class="cx"> #include &quot;SlotVisitorInlines.h&quot;
</span><ins>+#include &quot;StructureInlines.h&quot;
</ins><span class="cx"> #include &quot;VM.h&quot;
</span><span class="cx"> #include &quot;VMEntryScope.h&quot;
</span><span class="cx"> 
</span><span class="lines">@@ -58,7 +59,6 @@
</span><span class="cx"> static const bool sReportStats = false;
</span><span class="cx"> 
</span><span class="cx"> using FrameType = SamplingProfiler::FrameType;
</span><del>-using UnprocessedFrameType = SamplingProfiler::UnprocessedFrameType;
</del><span class="cx"> using UnprocessedStackFrame = SamplingProfiler::UnprocessedStackFrame;
</span><span class="cx"> 
</span><span class="cx"> ALWAYS_INLINE static void reportStats()
</span><span class="lines">@@ -89,14 +89,14 @@
</span><span class="cx">         resetAtMachineFrame();
</span><span class="cx">         size_t maxStackTraceSize = stackTrace.size();
</span><span class="cx">         while (!isAtTop() &amp;&amp; !m_bailingOut &amp;&amp; m_depth &lt; maxStackTraceSize) {
</span><del>-            if (CodeBlock* codeBlock = m_callFrame-&gt;codeBlock()) {
</del><ins>+            CallSiteIndex callSiteIndex;
+            JSValue unsafeCallee = m_callFrame-&gt;unsafeCallee();
+            CodeBlock* codeBlock = m_callFrame-&gt;codeBlock();
+            if (codeBlock) {
</ins><span class="cx">                 ASSERT(isValidCodeBlock(codeBlock));
</span><del>-                stackTrace[m_depth] = UnprocessedStackFrame(codeBlock, m_callFrame-&gt;callSiteIndex());
-            } else {
-                RELEASE_ASSERT(codeBlock == nullptr);
-                JSValue unsafeCallee = m_callFrame-&gt;unsafeCallee();
-                stackTrace[m_depth] = UnprocessedStackFrame(JSValue::encode(unsafeCallee));
</del><ins>+                callSiteIndex = m_callFrame-&gt;callSiteIndex();
</ins><span class="cx">             }
</span><ins>+            stackTrace[m_depth] = UnprocessedStackFrame(codeBlock, JSValue::encode(unsafeCallee), callSiteIndex);
</ins><span class="cx">             m_depth++;
</span><span class="cx">             advanceToParentFrame();
</span><span class="cx">             resetAtMachineFrame();
</span><span class="lines">@@ -330,7 +330,7 @@
</span><span class="cx"> 
</span><span class="cx">         auto appendCodeBlock = [&amp;] (CodeBlock* codeBlock, unsigned bytecodeIndex) {
</span><span class="cx">             stackTrace.frames.append(StackFrame(codeBlock-&gt;ownerExecutable()));
</span><del>-            m_seenExecutables.add(codeBlock-&gt;ownerExecutable());
</del><ins>+            m_liveCellPointers.add(codeBlock-&gt;ownerExecutable());
</ins><span class="cx"> 
</span><span class="cx">             if (bytecodeIndex &lt; codeBlock-&gt;instructionCount()) {
</span><span class="cx">                 int divot;
</span><span class="lines">@@ -341,16 +341,24 @@
</span><span class="cx">             }
</span><span class="cx">         };
</span><span class="cx"> 
</span><del>-        auto appendUnverifiedCallee = [&amp;] (JSValue callee) {
</del><ins>+        auto appendEmptyFrame = [&amp;] {
</ins><span class="cx">             stackTrace.frames.append(StackFrame());
</span><ins>+        };
+
+        auto storeCalleeIntoTopFrame = [&amp;] (EncodedJSValue encodedCallee) {
+            // Set the callee if it's a valid GC object.
+            JSValue callee = JSValue::decode(encodedCallee);
</ins><span class="cx">             StackFrame&amp; stackFrame = stackTrace.frames.last();
</span><ins>+            bool alreadyHasExecutable = !!stackFrame.executable;
</ins><span class="cx">             if (!Heap::isValueGCObject(filter, markedBlockSet, callee)) {
</span><del>-                stackFrame.frameType = FrameType::Unknown;
</del><ins>+                if (!alreadyHasExecutable)
+                    stackFrame.frameType = FrameType::Unknown;
</ins><span class="cx">                 return;
</span><span class="cx">             }
</span><span class="cx"> 
</span><span class="cx">             JSCell* calleeCell = callee.asCell();
</span><del>-            auto frameTypeFromCallData = [&amp;] () -&gt; FrameType {
</del><ins>+            auto setFallbackFrameType = [&amp;] {
+                ASSERT(!alreadyHasExecutable);
</ins><span class="cx">                 FrameType result = FrameType::Unknown;
</span><span class="cx">                 CallData callData;
</span><span class="cx">                 CallType callType;
</span><span class="lines">@@ -358,30 +366,47 @@
</span><span class="cx">                 if (callType == CallTypeHost)
</span><span class="cx">                     result = FrameType::Host;
</span><span class="cx"> 
</span><del>-                return result;
</del><ins>+                stackFrame.frameType = result;
</ins><span class="cx">             };
</span><span class="cx"> 
</span><ins>+            auto addCallee = [&amp;] (JSObject* callee) {
+                stackFrame.callee = callee;
+                m_liveCellPointers.add(callee);
+            };
+
</ins><span class="cx">             if (calleeCell-&gt;type() != JSFunctionType) {
</span><del>-                stackFrame.frameType = frameTypeFromCallData();
</del><ins>+                if (JSObject* object = jsDynamicCast&lt;JSObject*&gt;(calleeCell))
+                    addCallee(object);
+
+                if (!alreadyHasExecutable)
+                    setFallbackFrameType();
+
</ins><span class="cx">                 return;
</span><span class="cx">             }
</span><del>-            ExecutableBase* executable = static_cast&lt;JSFunction*&gt;(calleeCell)-&gt;executable();
</del><ins>+
+            addCallee(jsCast&lt;JSFunction*&gt;(calleeCell));
+
+            if (alreadyHasExecutable)
+                return;
+
+            ExecutableBase* executable = jsCast&lt;JSFunction*&gt;(calleeCell)-&gt;executable();
</ins><span class="cx">             if (!executable) {
</span><del>-                stackFrame.frameType = frameTypeFromCallData();
</del><ins>+                setFallbackFrameType();
</ins><span class="cx">                 return;
</span><span class="cx">             }
</span><span class="cx"> 
</span><span class="cx">             RELEASE_ASSERT(Heap::isPointerGCObject(filter, markedBlockSet, executable));
</span><span class="cx">             stackFrame.frameType = FrameType::Executable;
</span><span class="cx">             stackFrame.executable = executable;
</span><del>-            m_seenExecutables.add(executable);
</del><ins>+            m_liveCellPointers.add(executable);
</ins><span class="cx">         };
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx">         // Prepend the top-most inlined frame if needed and gather
</span><span class="cx">         // location information about where the top frame is executing.
</span><span class="cx">         size_t startIndex = 0;
</span><del>-        if (unprocessedStackTrace.frames.size() &amp;&amp; unprocessedStackTrace.frames[0].frameType == UnprocessedFrameType::VerifiedCodeBlock) {
-            CodeBlock* topCodeBlock = unprocessedStackTrace.frames[0].u.verifiedCodeBlock;
</del><ins>+        if (unprocessedStackTrace.frames.size() &amp;&amp; !!unprocessedStackTrace.frames[0].verifiedCodeBlock) {
+            CodeBlock* topCodeBlock = unprocessedStackTrace.frames[0].verifiedCodeBlock;
</ins><span class="cx">             if (unprocessedStackTrace.topFrameIsLLInt) {
</span><span class="cx">                 // We reuse LLInt CodeBlocks for the baseline JIT, so we need to check for both jit types.
</span><span class="cx">                 // This might also be false for various reasons (known and unknown), even though
</span><span class="lines">@@ -403,20 +428,21 @@
</span><span class="cx">                     UNUSED_PARAM(isValidPC); // FIXME: do something with this info for the web inspector: https://bugs.webkit.org/show_bug.cgi?id=153455
</span><span class="cx"> 
</span><span class="cx">                     appendCodeBlock(topCodeBlock, bytecodeIndex);
</span><ins>+                    storeCalleeIntoTopFrame(unprocessedStackTrace.frames[0].unverifiedCallee);
</ins><span class="cx">                     startIndex = 1;
</span><span class="cx">                 }
</span><span class="cx">             } else if (Optional&lt;CodeOrigin&gt; codeOrigin = topCodeBlock-&gt;findPC(unprocessedStackTrace.topPC)) {
</span><span class="cx">                 codeOrigin-&gt;walkUpInlineStack([&amp;] (const CodeOrigin&amp; codeOrigin) {
</span><span class="cx">                     appendCodeBlock(codeOrigin.inlineCallFrame ? codeOrigin.inlineCallFrame-&gt;baselineCodeBlock.get() : topCodeBlock, codeOrigin.bytecodeIndex);
</span><span class="cx">                 });
</span><ins>+                storeCalleeIntoTopFrame(unprocessedStackTrace.frames[0].unverifiedCallee);
</ins><span class="cx">                 startIndex = 1;
</span><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         for (size_t i = startIndex; i &lt; unprocessedStackTrace.frames.size(); i++) {
</span><span class="cx">             UnprocessedStackFrame&amp; unprocessedStackFrame = unprocessedStackTrace.frames[i];
</span><del>-            if (unprocessedStackFrame.frameType == UnprocessedFrameType::VerifiedCodeBlock) {
-                CodeBlock* codeBlock = unprocessedStackFrame.u.verifiedCodeBlock;
</del><ins>+            if (CodeBlock* codeBlock = unprocessedStackFrame.verifiedCodeBlock) {
</ins><span class="cx">                 CallSiteIndex callSiteIndex = unprocessedStackFrame.callSiteIndex;
</span><span class="cx"> 
</span><span class="cx">                 auto appendCodeBlockNoInlining = [&amp;] {
</span><span class="lines">@@ -437,10 +463,12 @@
</span><span class="cx"> #else
</span><span class="cx">                 appendCodeBlockNoInlining();
</span><span class="cx"> #endif
</span><del>-            } else {
-                ASSERT(unprocessedStackFrame.frameType == UnprocessedFrameType::UnverifiedCallee);
-                appendUnverifiedCallee(JSValue::decode(unprocessedStackFrame.u.unverifiedCallee));
-            }
</del><ins>+            } else
+                appendEmptyFrame();
+
+            // Note that this is okay to do if we walked the inline stack because
+            // the machine frame will be at the top of the processed stack trace.
+            storeCalleeIntoTopFrame(unprocessedStackFrame.unverifiedCallee);
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -450,8 +478,8 @@
</span><span class="cx"> void SamplingProfiler::visit(SlotVisitor&amp; slotVisitor)
</span><span class="cx"> {
</span><span class="cx">     RELEASE_ASSERT(m_lock.isLocked());
</span><del>-    for (ExecutableBase* executable : m_seenExecutables)
-        slotVisitor.appendUnbarrieredReadOnlyPointer(executable);
</del><ins>+    for (JSCell* cell : m_liveCellPointers)
+        slotVisitor.appendUnbarrieredReadOnlyPointer(cell);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void SamplingProfiler::shutdown()
</span><span class="lines">@@ -539,12 +567,44 @@
</span><span class="cx"> {
</span><span class="cx">     ASSERT(m_lock.isLocked());
</span><span class="cx">     m_stackTraces.clear();
</span><del>-    m_seenExecutables.clear();
</del><ins>+    m_liveCellPointers.clear();
</ins><span class="cx">     m_unprocessedStackTraces.clear();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-String SamplingProfiler::StackFrame::displayName()
</del><ins>+String SamplingProfiler::StackFrame::nameFromCallee(VM&amp; vm)
</ins><span class="cx"> {
</span><ins>+    if (!callee)
+        return String();
+
+    ExecState* exec = callee-&gt;globalObject()-&gt;globalExec();
+    auto getPropertyIfPureOperation = [&amp;] (const Identifier&amp; ident) -&gt; String {
+        PropertySlot slot(callee);
+        PropertyName propertyName(ident);
+        if (callee-&gt;getPropertySlot(exec, propertyName, slot)) {
+            if (slot.isValue()) {
+                JSValue nameValue = slot.getValue(exec, propertyName);
+                if (isJSString(nameValue))
+                    return asString(nameValue)-&gt;tryGetValue();
+            }
+        }
+        return String();
+    };
+
+    String name = getPropertyIfPureOperation(vm.propertyNames-&gt;displayName);
+    if (!name.isEmpty())
+        return name;
+
+    return getPropertyIfPureOperation(vm.propertyNames-&gt;name);
+}
+
+String SamplingProfiler::StackFrame::displayName(VM&amp; vm)
+{
+    {
+        String name = nameFromCallee(vm);
+        if (!name.isEmpty())
+            return name;
+    }
+
</ins><span class="cx">     if (frameType == FrameType::Unknown)
</span><span class="cx">         return ASCIILiteral(&quot;(unknown)&quot;);
</span><span class="cx">     if (frameType == FrameType::Host)
</span><span class="lines">@@ -564,8 +624,14 @@
</span><span class="cx">     return String();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-String SamplingProfiler::StackFrame::displayNameForJSONTests()
</del><ins>+String SamplingProfiler::StackFrame::displayNameForJSONTests(VM&amp; vm)
</ins><span class="cx"> {
</span><ins>+    {
+        String name = nameFromCallee(vm);
+        if (!name.isEmpty())
+            return name;
+    }
+
</ins><span class="cx">     if (frameType == FrameType::Unknown)
</span><span class="cx">         return ASCIILiteral(&quot;(unknown)&quot;);
</span><span class="cx">     if (frameType == FrameType::Host)
</span><span class="lines">@@ -674,7 +740,7 @@
</span><span class="cx">         for (StackFrame&amp; stackFrame : stackTrace.frames) {
</span><span class="cx">             comma();
</span><span class="cx">             json.appendLiteral(&quot;\&quot;&quot;);
</span><del>-            json.append(stackFrame.displayNameForJSONTests());
</del><ins>+            json.append(stackFrame.displayNameForJSONTests(m_vm));
</ins><span class="cx">             json.appendLiteral(&quot;\&quot;&quot;);
</span><span class="cx">             loopedOnce = true;
</span><span class="cx">         }
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeSamplingProfilerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/SamplingProfiler.h (196146 => 196147)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/SamplingProfiler.h        2016-02-04 21:51:26 UTC (rev 196146)
+++ trunk/Source/JavaScriptCore/runtime/SamplingProfiler.h        2016-02-04 21:51:40 UTC (rev 196147)
</span><span class="lines">@@ -45,35 +45,20 @@
</span><span class="cx">     WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx"> public:
</span><span class="cx"> 
</span><del>-    enum class UnprocessedFrameType { 
-        UnverifiedCallee,
-        VerifiedCodeBlock
-    };
-
</del><span class="cx">     struct UnprocessedStackFrame {
</span><del>-        UnprocessedStackFrame(EncodedJSValue callee)
-            : frameType(UnprocessedFrameType::UnverifiedCallee)
-        {
-            u.unverifiedCallee = callee;
-        }
-        UnprocessedStackFrame(CodeBlock* codeBlock, CallSiteIndex callSiteIndex)
-            : frameType(UnprocessedFrameType::VerifiedCodeBlock)
</del><ins>+        UnprocessedStackFrame(CodeBlock* codeBlock, EncodedJSValue callee, CallSiteIndex callSiteIndex)
+            : unverifiedCallee(callee)
+            , verifiedCodeBlock(codeBlock)
</ins><span class="cx">             , callSiteIndex(callSiteIndex)
</span><del>-        {
-            u.unverifiedCallee = JSValue::encode(JSValue());
-            u.verifiedCodeBlock = codeBlock;
-        }
</del><ins>+        { }
</ins><span class="cx">         UnprocessedStackFrame()
</span><del>-            : frameType(UnprocessedFrameType::UnverifiedCallee)
</del><span class="cx">         {
</span><del>-            u.unverifiedCallee = JSValue::encode(JSValue());
</del><ins>+            unverifiedCallee = JSValue::encode(JSValue());
+            verifiedCodeBlock = nullptr;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><del>-        UnprocessedFrameType frameType;
-        union {
-            EncodedJSValue unverifiedCallee;
-            CodeBlock* verifiedCodeBlock;
-        } u;
</del><ins>+        EncodedJSValue unverifiedCallee;
+        CodeBlock* verifiedCodeBlock;
</ins><span class="cx">         CallSiteIndex callSiteIndex;
</span><span class="cx">     };
</span><span class="cx"> 
</span><span class="lines">@@ -88,21 +73,21 @@
</span><span class="cx">             : frameType(FrameType::Executable)
</span><span class="cx">             , executable(executable)
</span><span class="cx">         { }
</span><ins>+
</ins><span class="cx">         StackFrame()
</span><del>-            : frameType(FrameType::Unknown)
-            , executable(nullptr)
</del><span class="cx">         { }
</span><span class="cx"> 
</span><del>-        FrameType frameType;
-        ExecutableBase* executable;
-
</del><ins>+        FrameType frameType { FrameType::Unknown };
+        ExecutableBase* executable { nullptr };
+        JSObject* callee { nullptr };
</ins><span class="cx">         // These attempt to be expression-level line and column number.
</span><span class="cx">         unsigned lineNumber { std::numeric_limits&lt;unsigned&gt;::max() };
</span><span class="cx">         unsigned columnNumber { std::numeric_limits&lt;unsigned&gt;::max() };
</span><span class="cx"> 
</span><span class="cx">         // These are function-level data.
</span><del>-        String displayName();
-        String displayNameForJSONTests(); // Used for JSC stress tests because they want the &quot;(anonymous function)&quot; string for anonymous functions and they want &quot;(eval)&quot; for eval'd code.
</del><ins>+        String nameFromCallee(VM&amp;);
+        String displayName(VM&amp;);
+        String displayNameForJSONTests(VM&amp;); // Used for JSC stress tests because they want the &quot;(anonymous function)&quot; string for anonymous functions and they want &quot;(eval)&quot; for eval'd code.
</ins><span class="cx">         int functionStartLine();
</span><span class="cx">         unsigned functionStartColumn();
</span><span class="cx">         intptr_t sourceID();
</span><span class="lines">@@ -168,7 +153,7 @@
</span><span class="cx">     bool m_isActive;
</span><span class="cx">     bool m_isPaused;
</span><span class="cx">     bool m_hasDispatchedFunction;
</span><del>-    HashSet&lt;ExecutableBase*&gt; m_seenExecutables;
</del><ins>+    HashSet&lt;JSCell*&gt; m_liveCellPointers;
</ins><span class="cx">     Vector&lt;UnprocessedStackFrame&gt; m_currentFrames;
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstresssamplingprofilerbasicjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/tests/stress/sampling-profiler-basic.js (196146 => 196147)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/sampling-profiler-basic.js        2016-02-04 21:51:26 UTC (rev 196146)
+++ trunk/Source/JavaScriptCore/tests/stress/sampling-profiler-basic.js        2016-02-04 21:51:40 UTC (rev 196147)
</span><span class="lines">@@ -17,7 +17,7 @@
</span><span class="cx">     function nothing(x) { return x; }
</span><span class="cx">     noInline(nothing);
</span><span class="cx"> 
</span><del>-    runTest(foo, [&quot;(host)&quot;, &quot;bar&quot;, &quot;foo&quot;]);
</del><ins>+    runTest(foo, [&quot;Error&quot;, &quot;bar&quot;, &quot;foo&quot;]);
</ins><span class="cx"> 
</span><span class="cx">     function top() { 
</span><span class="cx">         let x = 0;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstresssamplingprofilerboundfunctionnamejs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/sampling-profiler-bound-function-name.js (0 => 196147)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/sampling-profiler-bound-function-name.js                                (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/sampling-profiler-bound-function-name.js        2016-02-04 21:51:40 UTC (rev 196147)
</span><span class="lines">@@ -0,0 +1,28 @@
</span><ins>+if (platformSupportsSamplingProfiler()) {
+    load(&quot;./sampling-profiler/samplingProfiler.js&quot;);
+
+    function foo() {
+        let o = {};
+        for (let i = 0; i &lt; 100; i++) {
+            o[i + &quot;p&quot;] = i;
+        }
+    }
+
+    function bar() {
+        let o = {};
+        for (let i = 0; i &lt; 100; i++) {
+            o[i + &quot;p&quot;] = i;
+        }
+    }
+
+    let boundFoo = foo.bind(null);
+    let boundBar = bar.bind(null);
+
+    let baz = function() {
+        boundFoo();
+        boundBar();
+    }
+
+    runTest(baz, [&quot;foo&quot;, &quot;bound foo&quot;, &quot;baz&quot;]);
+    runTest(baz, [&quot;bar&quot;, &quot;bound bar&quot;, &quot;baz&quot;]);
+}
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstresssamplingprofilerdisplaynamejs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/sampling-profiler-display-name.js (0 => 196147)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/sampling-profiler-display-name.js                                (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/sampling-profiler-display-name.js        2016-02-04 21:51:40 UTC (rev 196147)
</span><span class="lines">@@ -0,0 +1,49 @@
</span><ins>+if (platformSupportsSamplingProfiler()) {
+    load(&quot;./sampling-profiler/samplingProfiler.js&quot;);
+
+    function foo() {
+        let o = {};
+        for (let i = 0; i &lt; 500; i++)
+            o[i + &quot;p&quot;] = i;
+    }
+    foo.displayName = &quot;display foo&quot;;
+    runTest(foo, [&quot;display foo&quot;]);
+
+
+    function baz() {
+        let o = {};
+        for (let i = 0; i &lt; 500; i++)
+            o[i + &quot;p&quot;] = i;
+    }
+    Object.defineProperty(baz, 'displayName', { get: function() { throw new Error(&quot;shouldnt be called&quot;); } }); // We should ignore this because it's a getter.
+    runTest(baz, [&quot;baz&quot;]);
+
+
+    function bar() {
+        let o = {};
+        for (let i = 0; i &lt; 500; i++)
+            o[i + &quot;p&quot;] = i;
+    }
+    bar.displayName = 20; // We should ignore this because it's not a string.
+    runTest(bar, [&quot;bar&quot;]);
+
+    function jaz() {
+        let o = {};
+        for (let i = 0; i &lt; 500; i++)
+            o[i + &quot;p&quot;] = i;
+    }
+    jaz.displayName = &quot;&quot;; // We should ignore this because it's the empty string.
+    runTest(jaz, [&quot;jaz&quot;]);
+
+    function makeFunction(displayName) {
+        let result = function() {
+            let o = {};
+            for (let i = 0; i &lt; 500; i++)
+                o[i + &quot;p&quot;] = i;
+        };
+        result.displayName = displayName;
+        return result;
+    }
+
+    runTest(makeFunction(&quot;hello world&quot;), [&quot;hello world&quot;])
+}
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstresssamplingprofilerinternalfunctionnamejs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/sampling-profiler-internal-function-name.js (0 => 196147)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/sampling-profiler-internal-function-name.js                                (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/sampling-profiler-internal-function-name.js        2016-02-04 21:51:40 UTC (rev 196147)
</span><span class="lines">@@ -0,0 +1,17 @@
</span><ins>+if (platformSupportsSamplingProfiler()) {
+    load(&quot;./sampling-profiler/samplingProfiler.js&quot;);
+
+    function foo() {
+        let x;
+        for (let i = 0; i &lt; 1000; i++)
+            x = new Error();
+    }
+    runTest(foo, [&quot;Error&quot;, &quot;foo&quot;]);
+
+    function bar() {
+        let x;
+        for (let i = 0; i &lt; 1000; i++)
+            x = new Function();
+    }
+    runTest(bar, [&quot;Function&quot;, &quot;bar&quot;]);
+}
</ins></span></pre>
</div>
</div>

</body>
</html>