<!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>[211684] 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/211684">211684</a></dd>
<dt>Author</dt> <dd>mark.lam@apple.com</dd>
<dt>Date</dt> <dd>2017-02-05 11:26:50 -0800 (Sun, 05 Feb 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>The VMInspector should use an RAII Locker.
https://bugs.webkit.org/show_bug.cgi?id=167854

Reviewed by Saam Barati.

Previously, VMInspector::lock() was returning an expected LockToken, and there's
no way to unlock it when we're done with it.  This was not a problem before
because the VMInspector had only one client, the SigillCrashAnalyzer, that
expected the process to crash due to a SIGILL shortly thereafter.

However, the VMInspector is useful as a debugging tool that we can apply in other
debugging tasks.  Fixing VMInspector::lock() to return an RAII locker will enable
other use cases.  Plus it's just bad form to be able to lock something and never
be able to unlock it.

* tools/SigillCrashAnalyzer.cpp:
(JSC::SigillCrashAnalyzer::analyze):
* tools/VMInspector.cpp:
* tools/VMInspector.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoretoolsSigillCrashAnalyzercpp">trunk/Source/JavaScriptCore/tools/SigillCrashAnalyzer.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoretoolsVMInspectorcpp">trunk/Source/JavaScriptCore/tools/VMInspector.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoretoolsVMInspectorh">trunk/Source/JavaScriptCore/tools/VMInspector.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (211683 => 211684)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2017-02-05 19:18:16 UTC (rev 211683)
+++ trunk/Source/JavaScriptCore/ChangeLog        2017-02-05 19:26:50 UTC (rev 211684)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2017-02-05  Mark Lam  &lt;mark.lam@apple.com&gt;
+
+        The VMInspector should use an RAII Locker.
+        https://bugs.webkit.org/show_bug.cgi?id=167854
+
+        Reviewed by Saam Barati.
+
+        Previously, VMInspector::lock() was returning an expected LockToken, and there's
+        no way to unlock it when we're done with it.  This was not a problem before
+        because the VMInspector had only one client, the SigillCrashAnalyzer, that
+        expected the process to crash due to a SIGILL shortly thereafter.
+
+        However, the VMInspector is useful as a debugging tool that we can apply in other
+        debugging tasks.  Fixing VMInspector::lock() to return an RAII locker will enable
+        other use cases.  Plus it's just bad form to be able to lock something and never
+        be able to unlock it.
+
+        * tools/SigillCrashAnalyzer.cpp:
+        (JSC::SigillCrashAnalyzer::analyze):
+        * tools/VMInspector.cpp:
+        * tools/VMInspector.h:
+
</ins><span class="cx"> 2017-02-04  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Static Analyzer: Value stored to 'recordedMachineThreads' during its initialization is never read
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretoolsSigillCrashAnalyzercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/tools/SigillCrashAnalyzer.cpp (211683 => 211684)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tools/SigillCrashAnalyzer.cpp        2017-02-05 19:18:16 UTC (rev 211683)
+++ trunk/Source/JavaScriptCore/tools/SigillCrashAnalyzer.cpp        2017-02-05 19:26:50 UTC (rev 211684)
</span><span class="lines">@@ -241,16 +241,16 @@
</span><span class="cx"> 
</span><span class="cx">         // Use a timeout period of 2 seconds. The client is about to crash, and we don't
</span><span class="cx">         // want to turn the crash into a hang by re-trying the lock for too long.
</span><del>-        auto expectedLockToken = inspector.lock(Seconds(2));
-        if (!expectedLockToken) {
-            ASSERT(expectedLockToken.error() == VMInspector::Error::TimedOut);
</del><ins>+        auto expectedLocker = inspector.lock(Seconds(2));
+        if (!expectedLocker) {
+            ASSERT(expectedLocker.error() == VMInspector::Error::TimedOut);
</ins><span class="cx">             log(&quot;ERROR: Unable to analyze SIGILL. Timed out while waiting to iterate VMs.&quot;);
</span><span class="cx">             return;
</span><span class="cx">         }
</span><del>-        auto lockToken = expectedLockToken.value();
</del><ins>+        auto&amp; locker = expectedLocker.value();
</ins><span class="cx"> 
</span><span class="cx">         void* pc = context.machinePC;
</span><del>-        auto isInJITMemory = inspector.isValidExecutableMemory(lockToken, pc);
</del><ins>+        auto isInJITMemory = inspector.isValidExecutableMemory(locker, pc);
</ins><span class="cx">         if (!isInJITMemory) {
</span><span class="cx">             log(&quot;ERROR: Timed out: not able to determine if pc %p is in valid JIT executable memory&quot;, pc);
</span><span class="cx">             return;
</span><span class="lines">@@ -274,7 +274,7 @@
</span><span class="cx">         log(&quot;instruction bits at pc %p is: 0x%08x&quot;, pc, wordAtPC);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-        auto expectedCodeBlock = inspector.codeBlockForMachinePC(lockToken, pc);
</del><ins>+        auto expectedCodeBlock = inspector.codeBlockForMachinePC(locker, pc);
</ins><span class="cx">         if (!expectedCodeBlock) {
</span><span class="cx">             if (expectedCodeBlock.error() == VMInspector::Error::TimedOut)
</span><span class="cx">                 log(&quot;ERROR: Timed out: not able to determine if pc %p is in a valid CodeBlock&quot;, pc);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretoolsVMInspectorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/tools/VMInspector.cpp (211683 => 211684)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tools/VMInspector.cpp        2017-02-05 19:18:16 UTC (rev 211683)
+++ trunk/Source/JavaScriptCore/tools/VMInspector.cpp        2017-02-05 19:26:50 UTC (rev 211684)
</span><span class="lines">@@ -60,7 +60,7 @@
</span><span class="cx">     m_list.remove(vm);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-auto VMInspector::lock(Seconds timeout) -&gt; Expected&lt;LockToken, Error&gt;
</del><ins>+auto VMInspector::lock(Seconds timeout) -&gt; Expected&lt;Locker, Error&gt;
</ins><span class="cx"> {
</span><span class="cx">     // This function may be called from a signal handler (e.g. via visit()). Hence,
</span><span class="cx">     // it should only use APIs that are safe to call from signal handlers. This is
</span><span class="lines">@@ -69,19 +69,19 @@
</span><span class="cx">     // We'll be doing sleep(1) between tries below. Hence, sleepPerRetry is 1.
</span><span class="cx">     unsigned maxRetries = (timeout &lt; Seconds::infinity()) ? timeout.value() : UINT_MAX;
</span><span class="cx"> 
</span><del>-    bool locked = m_lock.tryLock();
</del><ins>+    Expected&lt;Locker, Error&gt; locker = Locker::tryLock(m_lock);
</ins><span class="cx">     unsigned tryCount = 0;
</span><del>-    while (!locked &amp;&amp; tryCount &lt; maxRetries) {
</del><ins>+    while (!locker &amp;&amp; tryCount &lt; maxRetries) {
</ins><span class="cx">         // We want the version of sleep from unistd.h. Cast to disambiguate.
</span><span class="cx"> #if !OS(WINDOWS)
</span><span class="cx">         (static_cast&lt;unsigned (*)(unsigned)&gt;(sleep))(1);
</span><span class="cx"> #endif
</span><del>-        locked = m_lock.tryLock();
</del><ins>+        locker = Locker::tryLock(m_lock);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (!locked)
</del><ins>+    if (!locker)
</ins><span class="cx">         return makeUnexpected(Error::TimedOut);
</span><del>-    return LockToken::LockedValue;
</del><ins>+    return locker;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(JIT)
</span><span class="lines">@@ -101,7 +101,7 @@
</span><span class="cx"> };
</span><span class="cx"> #endif // ENABLE(JIT)
</span><span class="cx"> 
</span><del>-auto VMInspector::isValidExecutableMemory(VMInspector::LockToken, void* machinePC) -&gt; Expected&lt;bool, Error&gt;
</del><ins>+auto VMInspector::isValidExecutableMemory(const VMInspector::Locker&amp;, void* machinePC) -&gt; Expected&lt;bool, Error&gt;
</ins><span class="cx"> {
</span><span class="cx"> #if ENABLE(JIT)
</span><span class="cx">     bool found = false;
</span><span class="lines">@@ -133,7 +133,7 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-auto VMInspector::codeBlockForMachinePC(VMInspector::LockToken, void* machinePC) -&gt; Expected&lt;CodeBlock*, Error&gt;
</del><ins>+auto VMInspector::codeBlockForMachinePC(const VMInspector::Locker&amp;, void* machinePC) -&gt; Expected&lt;CodeBlock*, Error&gt;
</ins><span class="cx"> {
</span><span class="cx"> #if ENABLE(JIT)
</span><span class="cx">     CodeBlock* codeBlock = nullptr;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretoolsVMInspectorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/tools/VMInspector.h (211683 => 211684)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tools/VMInspector.h        2017-02-05 19:18:16 UTC (rev 211683)
+++ trunk/Source/JavaScriptCore/tools/VMInspector.h        2017-02-05 19:26:50 UTC (rev 211684)
</span><span class="lines">@@ -39,7 +39,7 @@
</span><span class="cx">         TimedOut
</span><span class="cx">     };
</span><span class="cx"> 
</span><del>-    enum class LockToken { LockedValue };
</del><ins>+    typedef WTF::Locker&lt;Lock&gt; Locker;
</ins><span class="cx"> 
</span><span class="cx">     static VMInspector&amp; instance();
</span><span class="cx"> 
</span><span class="lines">@@ -46,10 +46,10 @@
</span><span class="cx">     void add(VM*);
</span><span class="cx">     void remove(VM*);
</span><span class="cx"> 
</span><del>-    Expected&lt;LockToken, Error&gt; lock(Seconds timeout = Seconds::infinity());
</del><ins>+    Expected&lt;Locker, Error&gt; lock(Seconds timeout = Seconds::infinity());
</ins><span class="cx"> 
</span><del>-    Expected&lt;bool, Error&gt; isValidExecutableMemory(LockToken, void*);
-    Expected&lt;CodeBlock*, Error&gt; codeBlockForMachinePC(LockToken, void*);
</del><ins>+    Expected&lt;bool, Error&gt; isValidExecutableMemory(const Locker&amp;, void*);
+    Expected&lt;CodeBlock*, Error&gt; codeBlockForMachinePC(const Locker&amp;, void*);
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     enum class FunctorStatus {
</span></span></pre>
</div>
</div>

</body>
</html>