<!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>[213718] 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/213718">213718</a></dd>
<dt>Author</dt> <dd>mark.lam@apple.com</dd>
<dt>Date</dt> <dd>2017-03-10 11:01:57 -0800 (Fri, 10 Mar 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Re-landing] Implement a StackTrace utility object that can capture stack traces for debugging.
https://bugs.webkit.org/show_bug.cgi?id=169454

Reviewed by Michael Saboff.

The underlying implementation is hoisted right out of Assertions.cpp from the
implementations of WTFPrintBacktrace().

The reason we need this StackTrace object is because during heap debugging, we
sometimes want to capture the stack trace that allocated the objects of interest.
Dumping the stack trace directly to stdout (using WTFReportBacktrace()) may
perturb the execution profile sufficiently that an issue may not reproduce,
while alternatively, just capturing the stack trace and deferring printing it
till we actually need it later perturbs the execution profile less.

In addition, just capturing the stack traces (instead of printing them
immediately at each capture site) allows us to avoid polluting stdout with tons
of stack traces that may be irrelevant.

For now, we only capture the native stack trace.  We'll leave capturing and
integrating the JS stack trace as an exercise for the future if we need it then.

Here's an example of how to use this StackTrace utility:

    // Capture a stack trace of the top 10 frames.
    std::unique_ptr&lt;StackTrace&gt; trace(StackTrace::captureStackTrace(10));
    // Print the trace.
    dataLog(*trace);

* CMakeLists.txt:
* JavaScriptCore.xcodeproj/project.pbxproj:
* tools/StackTrace.cpp: Added.
(JSC::StackTrace::instanceSize):
(JSC::StackTrace::captureStackTrace):
(JSC::StackTrace::dump):
* tools/StackTrace.h: Added.
(JSC::StackTrace::size):
(JSC::StackTrace::StackTrace):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreCMakeListstxt">trunk/Source/JavaScriptCore/CMakeLists.txt</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreJavaScriptCorexcodeprojprojectpbxproj">trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoretoolsStackTracecpp">trunk/Source/JavaScriptCore/tools/StackTrace.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoretoolsStackTraceh">trunk/Source/JavaScriptCore/tools/StackTrace.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreCMakeListstxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/CMakeLists.txt (213717 => 213718)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/CMakeLists.txt        2017-03-10 18:32:20 UTC (rev 213717)
+++ trunk/Source/JavaScriptCore/CMakeLists.txt        2017-03-10 19:01:57 UTC (rev 213718)
</span><span class="lines">@@ -924,6 +924,7 @@
</span><span class="cx">     tools/JSDollarVM.cpp
</span><span class="cx">     tools/JSDollarVMPrototype.cpp
</span><span class="cx">     tools/SigillCrashAnalyzer.cpp
</span><ins>+    tools/StackTrace.cpp
</ins><span class="cx">     tools/VMInspector.cpp
</span><span class="cx"> 
</span><span class="cx">     wasm/JSWebAssembly.cpp
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (213717 => 213718)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2017-03-10 18:32:20 UTC (rev 213717)
+++ trunk/Source/JavaScriptCore/ChangeLog        2017-03-10 19:01:57 UTC (rev 213718)
</span><span class="lines">@@ -1,3 +1,44 @@
</span><ins>+2017-03-10  Mark Lam  &lt;mark.lam@apple.com&gt;
+
+        [Re-landing] Implement a StackTrace utility object that can capture stack traces for debugging.
+        https://bugs.webkit.org/show_bug.cgi?id=169454
+
+        Reviewed by Michael Saboff.
+
+        The underlying implementation is hoisted right out of Assertions.cpp from the
+        implementations of WTFPrintBacktrace().
+
+        The reason we need this StackTrace object is because during heap debugging, we
+        sometimes want to capture the stack trace that allocated the objects of interest.
+        Dumping the stack trace directly to stdout (using WTFReportBacktrace()) may
+        perturb the execution profile sufficiently that an issue may not reproduce,
+        while alternatively, just capturing the stack trace and deferring printing it
+        till we actually need it later perturbs the execution profile less.
+
+        In addition, just capturing the stack traces (instead of printing them
+        immediately at each capture site) allows us to avoid polluting stdout with tons
+        of stack traces that may be irrelevant.
+
+        For now, we only capture the native stack trace.  We'll leave capturing and
+        integrating the JS stack trace as an exercise for the future if we need it then.
+
+        Here's an example of how to use this StackTrace utility:
+
+            // Capture a stack trace of the top 10 frames.
+            std::unique_ptr&lt;StackTrace&gt; trace(StackTrace::captureStackTrace(10));
+            // Print the trace.
+            dataLog(*trace);
+
+        * CMakeLists.txt:
+        * JavaScriptCore.xcodeproj/project.pbxproj:
+        * tools/StackTrace.cpp: Added.
+        (JSC::StackTrace::instanceSize):
+        (JSC::StackTrace::captureStackTrace):
+        (JSC::StackTrace::dump):
+        * tools/StackTrace.h: Added.
+        (JSC::StackTrace::size):
+        (JSC::StackTrace::StackTrace):
+
</ins><span class="cx"> 2017-03-04  Filip Pizlo  &lt;fpizlo@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         B3 should have comprehensive support for atomic operations
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreJavaScriptCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj (213717 => 213718)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj        2017-03-10 18:32:20 UTC (rev 213717)
+++ trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj        2017-03-10 19:01:57 UTC (rev 213718)
</span><span class="lines">@@ -2371,6 +2371,8 @@
</span><span class="cx">                 FE1BD0211E72027900134BC9 /* CellProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = FE1BD0201E72027000134BC9 /* CellProfile.h */; };
</span><span class="cx">                 FE1BD0241E72053800134BC9 /* HeapVerifier.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE1BD0221E72052F00134BC9 /* HeapVerifier.cpp */; };
</span><span class="cx">                 FE1BD0251E72053800134BC9 /* HeapVerifier.h in Headers */ = {isa = PBXBuildFile; fileRef = FE1BD0231E72052F00134BC9 /* HeapVerifier.h */; };
</span><ins>+                FE1BD02B1E721B4C00134BC9 /* StackTrace.h in Headers */ = {isa = PBXBuildFile; fileRef = FE1BD02A1E721B3700134BC9 /* StackTrace.h */; };
+                FE1BD02C1E721B5100134BC9 /* StackTrace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE1BD0291E721B3700134BC9 /* StackTrace.cpp */; };
</ins><span class="cx">                 FE1C0FFD1B193E9800B53FCA /* Exception.h in Headers */ = {isa = PBXBuildFile; fileRef = FE1C0FFC1B193E9800B53FCA /* Exception.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 FE1C0FFF1B194FD100B53FCA /* Exception.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE1C0FFE1B194FD100B53FCA /* Exception.cpp */; };
</span><span class="cx">                 FE20CE9D15F04A9500DF3430 /* LLIntCLoop.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE20CE9B15F04A9500DF3430 /* LLIntCLoop.cpp */; };
</span><span class="lines">@@ -4957,6 +4959,8 @@
</span><span class="cx">                 FE1BD0201E72027000134BC9 /* CellProfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CellProfile.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 FE1BD0221E72052F00134BC9 /* HeapVerifier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HeapVerifier.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 FE1BD0231E72052F00134BC9 /* HeapVerifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HeapVerifier.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                FE1BD0291E721B3700134BC9 /* StackTrace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StackTrace.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
+                FE1BD02A1E721B3700134BC9 /* StackTrace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StackTrace.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 FE1C0FFC1B193E9800B53FCA /* Exception.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Exception.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 FE1C0FFE1B194FD100B53FCA /* Exception.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Exception.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 FE20CE9B15F04A9500DF3430 /* LLIntCLoop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LLIntCLoop.cpp; path = llint/LLIntCLoop.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -6955,6 +6959,8 @@
</span><span class="cx">                                 86B5822C14D22F5F00A9C306 /* ProfileTreeNode.h */,
</span><span class="cx">                                 FE3022D01E3D739600BAC493 /* SigillCrashAnalyzer.cpp */,
</span><span class="cx">                                 FE3022D11E3D739600BAC493 /* SigillCrashAnalyzer.h */,
</span><ins>+                                FE1BD0291E721B3700134BC9 /* StackTrace.cpp */,
+                                FE1BD02A1E721B3700134BC9 /* StackTrace.h */,
</ins><span class="cx">                                 86B5826A14D35D5100A9C306 /* TieredMMapArray.h */,
</span><span class="cx">                                 FE3022D41E42856700BAC493 /* VMInspector.cpp */,
</span><span class="cx">                                 FE3022D51E42856700BAC493 /* VMInspector.h */,
</span><span class="lines">@@ -8759,6 +8765,7 @@
</span><span class="cx">                                 FE187A0D1C030D5C0038BBCA /* JITDivGenerator.h in Headers */,
</span><span class="cx">                                 0F46808214BA572D00BFE272 /* JITExceptions.h in Headers */,
</span><span class="cx">                                 0FB14E1F18124ACE009B6B4D /* JITInlineCacheGenerator.h in Headers */,
</span><ins>+                                FE1BD02B1E721B4C00134BC9 /* StackTrace.h in Headers */,
</ins><span class="cx">                                 86CC85A10EE79A4700288682 /* JITInlines.h in Headers */,
</span><span class="cx">                                 FE3A06BE1C11041200390FDD /* JITLeftShiftGenerator.h in Headers */,
</span><span class="cx">                                 79233C2B1D34715700C5A834 /* JITMathIC.h in Headers */,
</span><span class="lines">@@ -10200,6 +10207,7 @@
</span><span class="cx">                                 0FC97F4118202119002C9B26 /* DFGWatchpointCollectionPhase.cpp in Sources */,
</span><span class="cx">                                 0FDB2CE7174830A2007B3C1B /* DFGWorklist.cpp in Sources */,
</span><span class="cx">                                 0FE050171AA9091100D33B33 /* DirectArguments.cpp in Sources */,
</span><ins>+                                FE1BD02C1E721B5100134BC9 /* StackTrace.cpp in Sources */,
</ins><span class="cx">                                 0FE050151AA9091100D33B33 /* DirectArgumentsOffset.cpp in Sources */,
</span><span class="cx">                                 0F2EBBAB1DEDF95000990369 /* DirectEvalCodeCache.cpp in Sources */,
</span><span class="cx">                                 14386A741DD69895008652C4 /* DirectEvalExecutable.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretoolsStackTracecpp"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tools/StackTrace.cpp (0 => 213718)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tools/StackTrace.cpp                                (rev 0)
+++ trunk/Source/JavaScriptCore/tools/StackTrace.cpp        2017-03-10 19:01:57 UTC (rev 213718)
</span><span class="lines">@@ -0,0 +1,105 @@
</span><ins>+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include &quot;config.h&quot;
+#include &quot;StackTrace.h&quot;
+
+#include &lt;wtf/Assertions.h&gt;
+
+#if OS(DARWIN) || (OS(LINUX) &amp;&amp; defined(__GLIBC__) &amp;&amp; !defined(__UCLIBC__))
+#include &lt;cxxabi.h&gt;
+#include &lt;dlfcn.h&gt;
+#include &lt;execinfo.h&gt;
+#endif
+
+#if OS(DARWIN) || OS(LINUX)
+#  if PLATFORM(GTK)
+#    if defined(__GLIBC__) &amp;&amp; !defined(__UCLIBC__)
+#      define USE_BACKTRACE_SYMBOLS 1
+#    endif
+#  else
+#    define USE_DLADDR 1
+#  endif
+#endif
+
+namespace JSC {
+
+ALWAYS_INLINE size_t StackTrace::instanceSize(int capacity)
+{
+    ASSERT(capacity &gt;= 1);
+    return sizeof(StackTrace) + (capacity - 1) * sizeof(void*);
+}
+
+StackTrace* StackTrace::captureStackTrace(int maxFrames)
+{
+    maxFrames = std::max(1, maxFrames);
+    size_t sizeToAllocate = instanceSize(maxFrames);
+    StackTrace* trace = new (NotNull, fastMalloc(sizeToAllocate)) StackTrace();
+
+    static const int framesToSkip = 2;
+    int numberOfFrames = maxFrames + framesToSkip;
+    
+    WTFGetBacktrace(&amp;trace-&gt;m_skippedFrame0, &amp;numberOfFrames);
+    ASSERT(numberOfFrames &gt; framesToSkip);
+    trace-&gt;m_size = numberOfFrames - framesToSkip;
+    trace-&gt;m_capacity = maxFrames;
+
+    return trace;
+}
+
+void StackTrace::dump(PrintStream&amp; out) const
+{
+#if USE(BACKTRACE_SYMBOLS)
+    char** symbols = backtrace_symbols(m_stack, m_size);
+    if (!symbols)
+        return;
+#endif
+    
+    for (int i = 0; i &lt; m_size; ++i) {
+        const char* mangledName = 0;
+        char* cxaDemangled = 0;
+#if USE(BACKTRACE_SYMBOLS)
+        mangledName = symbols[i];
+#elif USE(DLADDR)
+        Dl_info info;
+        if (dladdr(m_stack[i], &amp;info) &amp;&amp; info.dli_sname)
+            mangledName = info.dli_sname;
+        if (mangledName)
+            cxaDemangled = abi::__cxa_demangle(mangledName, 0, 0, 0);
+#endif
+        const int frameNumber = i + 1;
+        if (mangledName || cxaDemangled)
+            out.printf(&quot;%-3d %p %s\n&quot;, frameNumber, m_stack[i], cxaDemangled ? cxaDemangled : mangledName);
+        else
+            out.printf(&quot;%-3d %p\n&quot;, frameNumber, m_stack[i]);
+        free(cxaDemangled);
+    }
+    
+#if USE(BACKTRACE_SYMBOLS)
+    free(symbols);
+#endif
+}
+
+} // namespace JSC
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoretoolsStackTraceh"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tools/StackTrace.h (0 => 213718)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tools/StackTrace.h                                (rev 0)
+++ trunk/Source/JavaScriptCore/tools/StackTrace.h        2017-03-10 19:01:57 UTC (rev 213718)
</span><span class="lines">@@ -0,0 +1,65 @@
</span><ins>+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include &lt;wtf/PrintStream.h&gt;
+
+namespace JSC {
+
+class StackTrace {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    static StackTrace* captureStackTrace(int maxFrames);
+
+    int size() const { return m_size; }
+
+    void dump(PrintStream&amp;) const;
+
+private:
+    inline static size_t instanceSize(int capacity);
+
+    StackTrace()
+        : m_size(0)
+    { }
+
+    // We structure the top fields this way because the underlying stack capture
+    // facility will capture from the top of the stack, and we'll need to skip the
+    // top 2 frame which is of no interest. Setting up the fields layout this way
+    // allows us to capture the stack in place and minimize space wastage.
+    union {
+        struct {
+            int m_size;
+            int m_capacity;
+        };
+        struct {
+            void* m_skippedFrame0;
+            void* m_skippedFrame1;
+        };
+    };
+    void* m_stack[1];
+};
+
+} // namespace JSC
</ins></span></pre>
</div>
</div>

</body>
</html>