<!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>[166013] 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/166013">166013</a></dd>
<dt>Author</dt> <dd>fpizlo@apple.com</dd>
<dt>Date</dt> <dd>2014-03-20 16:08:30 -0700 (Thu, 20 Mar 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Implement stackmap header version check and support new stackmap formats
https://bugs.webkit.org/show_bug.cgi?id=130535
&lt;rdar://problem/16164284&gt;

Reviewed by Geoffrey Garen.

Add the notion of versioning so that LLVMers can happily implement new stackmap formats
without worrying about WebKit getting version-locked to LLVM. In the future, we will have
to implement parsing for a new LLVM stackmap format before it lands in LLVM, or we'll have
to have a &quot;max usable LLVM revision&quot; limit. But, thanks to versioning, we'll always be
happy to move backward in time to older versions of LLVM.

* ftl/FTLStackMaps.cpp:
(JSC::FTL::readObject):
(JSC::FTL::StackMaps::Constant::parse):
(JSC::FTL::StackMaps::StackSize::parse):
(JSC::FTL::StackMaps::Location::parse):
(JSC::FTL::StackMaps::Record::parse):
(JSC::FTL::StackMaps::parse):
(JSC::FTL::StackMaps::dump):
(JSC::FTL::StackMaps::dumpMultiline):
* ftl/FTLStackMaps.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLStackMapscpp">trunk/Source/JavaScriptCore/ftl/FTLStackMaps.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLStackMapsh">trunk/Source/JavaScriptCore/ftl/FTLStackMaps.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (166012 => 166013)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2014-03-20 23:07:12 UTC (rev 166012)
+++ trunk/Source/JavaScriptCore/ChangeLog        2014-03-20 23:08:30 UTC (rev 166013)
</span><span class="lines">@@ -1,5 +1,30 @@
</span><span class="cx"> 2014-03-20  Filip Pizlo  &lt;fpizlo@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Implement stackmap header version check and support new stackmap formats
+        https://bugs.webkit.org/show_bug.cgi?id=130535
+        &lt;rdar://problem/16164284&gt;
+
+        Reviewed by Geoffrey Garen.
+        
+        Add the notion of versioning so that LLVMers can happily implement new stackmap formats
+        without worrying about WebKit getting version-locked to LLVM. In the future, we will have
+        to implement parsing for a new LLVM stackmap format before it lands in LLVM, or we'll have
+        to have a &quot;max usable LLVM revision&quot; limit. But, thanks to versioning, we'll always be
+        happy to move backward in time to older versions of LLVM.
+
+        * ftl/FTLStackMaps.cpp:
+        (JSC::FTL::readObject):
+        (JSC::FTL::StackMaps::Constant::parse):
+        (JSC::FTL::StackMaps::StackSize::parse):
+        (JSC::FTL::StackMaps::Location::parse):
+        (JSC::FTL::StackMaps::Record::parse):
+        (JSC::FTL::StackMaps::parse):
+        (JSC::FTL::StackMaps::dump):
+        (JSC::FTL::StackMaps::dumpMultiline):
+        * ftl/FTLStackMaps.h:
+
+2014-03-20  Filip Pizlo  &lt;fpizlo@apple.com&gt;
+
</ins><span class="cx">         Crash beneath operationTearOffActivation running this JS compression demo
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=130295
</span><span class="cx">         &lt;rdar://problem/16332337&gt;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLStackMapscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLStackMaps.cpp (166012 => 166013)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLStackMaps.cpp        2014-03-20 23:07:12 UTC (rev 166012)
+++ trunk/Source/JavaScriptCore/ftl/FTLStackMaps.cpp        2014-03-20 23:08:30 UTC (rev 166013)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2013 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -36,16 +36,16 @@
</span><span class="cx"> namespace JSC { namespace FTL {
</span><span class="cx"> 
</span><span class="cx"> template&lt;typename T&gt;
</span><del>-T readObject(DataView* view, unsigned&amp; offset)
</del><ins>+T readObject(StackMaps::ParseContext&amp; context)
</ins><span class="cx"> {
</span><span class="cx">     T result;
</span><del>-    result.parse(view, offset);
</del><ins>+    result.parse(context);
</ins><span class="cx">     return result;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void StackMaps::Constant::parse(DataView* view, unsigned&amp; offset)
</del><ins>+void StackMaps::Constant::parse(StackMaps::ParseContext&amp; context)
</ins><span class="cx"> {
</span><del>-    integer = view-&gt;read&lt;int64_t&gt;(offset, true);
</del><ins>+    integer = context.view-&gt;read&lt;int64_t&gt;(context.offset, true);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void StackMaps::Constant::dump(PrintStream&amp; out) const
</span><span class="lines">@@ -53,10 +53,19 @@
</span><span class="cx">     out.printf(&quot;0x%016llx&quot;, integer);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void StackMaps::StackSize::parse(DataView* view, unsigned&amp; offset)
</del><ins>+void StackMaps::StackSize::parse(StackMaps::ParseContext&amp; context)
</ins><span class="cx"> {
</span><del>-    functionOffset = view-&gt;read&lt;uint32_t&gt;(offset, true);
-    size = view-&gt;read&lt;uint32_t&gt;(offset, true);
</del><ins>+    switch (context.version) {
+    case 0:
+        functionOffset = context.view-&gt;read&lt;uint32_t&gt;(context.offset, true);
+        size = context.view-&gt;read&lt;uint32_t&gt;(context.offset, true);
+        break;
+        
+    default:
+        functionOffset = context.view-&gt;read&lt;uint64_t&gt;(context.offset, true);
+        size = context.view-&gt;read&lt;uint64_t&gt;(context.offset, true);
+        break;
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void StackMaps::StackSize::dump(PrintStream&amp; out) const
</span><span class="lines">@@ -64,12 +73,12 @@
</span><span class="cx">     out.print(&quot;(off:&quot;, functionOffset, &quot;, size:&quot;, size, &quot;)&quot;);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void StackMaps::Location::parse(DataView* view, unsigned&amp; offset)
</del><ins>+void StackMaps::Location::parse(StackMaps::ParseContext&amp; context)
</ins><span class="cx"> {
</span><del>-    kind = static_cast&lt;Kind&gt;(view-&gt;read&lt;uint8_t&gt;(offset, true));
-    size = view-&gt;read&lt;uint8_t&gt;(offset, true);
-    dwarfRegNum = view-&gt;read&lt;uint16_t&gt;(offset, true);
-    this-&gt;offset = view-&gt;read&lt;int32_t&gt;(offset, true);
</del><ins>+    kind = static_cast&lt;Kind&gt;(context.view-&gt;read&lt;uint8_t&gt;(context.offset, true));
+    size = context.view-&gt;read&lt;uint8_t&gt;(context.offset, true);
+    dwarfRegNum = context.view-&gt;read&lt;uint16_t&gt;(context.offset, true);
+    this-&gt;offset = context.view-&gt;read&lt;int32_t&gt;(context.offset, true);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void StackMaps::Location::dump(PrintStream&amp; out) const
</span><span class="lines">@@ -88,27 +97,35 @@
</span><span class="cx">     FTL::Location::forStackmaps(&amp;stackmaps, *this).restoreInto(jit, savedRegisters, result);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool StackMaps::Record::parse(DataView* view, unsigned&amp; offset)
</del><ins>+bool StackMaps::Record::parse(StackMaps::ParseContext&amp; context)
</ins><span class="cx"> {
</span><del>-    int64_t id = view-&gt;read&lt;int64_t&gt;(offset, true);
</del><ins>+    int64_t id = context.view-&gt;read&lt;int64_t&gt;(context.offset, true);
</ins><span class="cx">     ASSERT(static_cast&lt;int32_t&gt;(id) == id);
</span><span class="cx">     patchpointID = static_cast&lt;uint32_t&gt;(id);
</span><span class="cx">     if (static_cast&lt;int32_t&gt;(patchpointID) &lt; 0)
</span><span class="cx">         return false;
</span><span class="cx">     
</span><del>-    instructionOffset = view-&gt;read&lt;uint32_t&gt;(offset, true);
-    flags = view-&gt;read&lt;uint16_t&gt;(offset, true);
</del><ins>+    instructionOffset = context.view-&gt;read&lt;uint32_t&gt;(context.offset, true);
+    flags = context.view-&gt;read&lt;uint16_t&gt;(context.offset, true);
</ins><span class="cx">     
</span><del>-    unsigned length = view-&gt;read&lt;uint16_t&gt;(offset, true);
</del><ins>+    unsigned length = context.view-&gt;read&lt;uint16_t&gt;(context.offset, true);
</ins><span class="cx">     while (length--)
</span><del>-        locations.append(readObject&lt;Location&gt;(view, offset));
</del><ins>+        locations.append(readObject&lt;Location&gt;(context));
</ins><span class="cx">     
</span><del>-    unsigned numLiveOuts = view-&gt;read&lt;uint16_t&gt;(offset, true);
</del><ins>+    if (context.version &gt;= 1)
+        context.view-&gt;read&lt;uint16_t&gt;(context.offset, true); // padding
+    unsigned numLiveOuts = context.view-&gt;read&lt;uint16_t&gt;(context.offset, true);
</ins><span class="cx">     while (numLiveOuts--) {
</span><del>-        view-&gt;read&lt;uint16_t&gt;(offset, true); // regnum
-        view-&gt;read&lt;uint8_t&gt;(offset, true); // reserved
-        view-&gt;read&lt;uint8_t&gt;(offset, true); // size in bytes
</del><ins>+        context.view-&gt;read&lt;uint16_t&gt;(context.offset, true); // regnum
+        context.view-&gt;read&lt;uint8_t&gt;(context.offset, true); // reserved
+        context.view-&gt;read&lt;uint8_t&gt;(context.offset, true); // size in bytes
</ins><span class="cx">     }
</span><ins>+    if (context.version &gt;= 1) {
+        if (context.offset &amp; 7) {
+            ASSERT(!(context.offset &amp; 3));
+            context.view-&gt;read&lt;uint32_t&gt;(context.offset, true); // padding
+        }
+    }
</ins><span class="cx">     
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="lines">@@ -122,24 +139,38 @@
</span><span class="cx"> 
</span><span class="cx"> bool StackMaps::parse(DataView* view)
</span><span class="cx"> {
</span><del>-    unsigned offset = 0;
</del><ins>+    ParseContext context;
+    context.offset = 0;
+    context.view = view;
</ins><span class="cx">     
</span><del>-    view-&gt;read&lt;uint32_t&gt;(offset, true); // Reserved (header)
</del><ins>+    version = context.version = context.view-&gt;read&lt;uint8_t&gt;(context.offset, true);
+
+    context.view-&gt;read&lt;uint8_t&gt;(context.offset, true); // Reserved
+    context.view-&gt;read&lt;uint8_t&gt;(context.offset, true); // Reserved
+    context.view-&gt;read&lt;uint8_t&gt;(context.offset, true); // Reserved
+
+    uint32_t numFunctions;
+    uint32_t numConstants;
+    uint32_t numRecords;
</ins><span class="cx">     
</span><del>-    uint32_t numFunctions = view-&gt;read&lt;uint32_t&gt;(offset, true);
-    ASSERT(numFunctions == 1); // There should only be one stack size record
-    while (numFunctions--) {
-        stackSizes.append(readObject&lt;StackSize&gt;(view, offset));
</del><ins>+    numFunctions = context.view-&gt;read&lt;uint32_t&gt;(context.offset, true);
+    if (context.version &gt;= 1) {
+        numConstants = context.view-&gt;read&lt;uint32_t&gt;(context.offset, true);
+        numRecords = context.view-&gt;read&lt;uint32_t&gt;(context.offset, true);
</ins><span class="cx">     }
</span><ins>+    while (numFunctions--)
+        stackSizes.append(readObject&lt;StackSize&gt;(context));
</ins><span class="cx">     
</span><del>-    uint32_t numConstants = view-&gt;read&lt;uint32_t&gt;(offset, true);
</del><ins>+    if (!context.version)
+        numConstants = context.view-&gt;read&lt;uint32_t&gt;(context.offset, true);
</ins><span class="cx">     while (numConstants--)
</span><del>-        constants.append(readObject&lt;Constant&gt;(view, offset));
</del><ins>+        constants.append(readObject&lt;Constant&gt;(context));
</ins><span class="cx">     
</span><del>-    uint32_t numRecords = view-&gt;read&lt;uint32_t&gt;(offset, true);
</del><ins>+    if (!context.version)
+        numRecords = context.view-&gt;read&lt;uint32_t&gt;(context.offset, true);
</ins><span class="cx">     while (numRecords--) {
</span><span class="cx">         Record record;
</span><del>-        if (!record.parse(view, offset))
</del><ins>+        if (!record.parse(context))
</ins><span class="cx">             return false;
</span><span class="cx">         records.append(record);
</span><span class="cx">     }
</span><span class="lines">@@ -149,11 +180,12 @@
</span><span class="cx"> 
</span><span class="cx"> void StackMaps::dump(PrintStream&amp; out) const
</span><span class="cx"> {
</span><del>-    out.print(&quot;StackSizes[&quot;, listDump(stackSizes), &quot;], Constants:[&quot;, listDump(constants), &quot;], Records:[&quot;, listDump(records), &quot;]&quot;);
</del><ins>+    out.print(&quot;Version:&quot;, version, &quot;, StackSizes[&quot;, listDump(stackSizes), &quot;], Constants:[&quot;, listDump(constants), &quot;], Records:[&quot;, listDump(records), &quot;]&quot;);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void StackMaps::dumpMultiline(PrintStream&amp; out, const char* prefix) const
</span><span class="cx"> {
</span><ins>+    out.print(prefix, &quot;Version: &quot;, version, &quot;\n&quot;);
</ins><span class="cx">     out.print(prefix, &quot;StackSizes:\n&quot;);
</span><span class="cx">     for (unsigned i = 0; i &lt; stackSizes.size(); ++i)
</span><span class="cx">         out.print(prefix, &quot;    &quot;, stackSizes[i], &quot;\n&quot;);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLStackMapsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLStackMaps.h (166012 => 166013)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLStackMaps.h        2014-03-20 23:07:12 UTC (rev 166012)
+++ trunk/Source/JavaScriptCore/ftl/FTLStackMaps.h        2014-03-20 23:08:30 UTC (rev 166013)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2013 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -39,18 +39,24 @@
</span><span class="cx"> namespace FTL {
</span><span class="cx"> 
</span><span class="cx"> struct StackMaps {
</span><ins>+    struct ParseContext {
+        unsigned version;
+        DataView* view;
+        unsigned offset;
+    };
+    
</ins><span class="cx">     struct Constant {
</span><span class="cx">         int64_t integer;
</span><span class="cx">         
</span><del>-        void parse(DataView*, unsigned&amp; offset);
</del><ins>+        void parse(ParseContext&amp;);
</ins><span class="cx">         void dump(PrintStream&amp; out) const;
</span><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx">     struct StackSize {
</span><del>-        uint32_t functionOffset;
-        uint32_t size;
</del><ins>+        uint64_t functionOffset;
+        uint64_t size;
</ins><span class="cx"> 
</span><del>-        void parse(DataView*, unsigned&amp; offset);
</del><ins>+        void parse(ParseContext&amp;);
</ins><span class="cx">         void dump(PrintStream&amp;) const;
</span><span class="cx">     };
</span><span class="cx"> 
</span><span class="lines">@@ -69,7 +75,7 @@
</span><span class="cx">         Kind kind;
</span><span class="cx">         int32_t offset;
</span><span class="cx">         
</span><del>-        void parse(DataView*, unsigned&amp; offset);
</del><ins>+        void parse(ParseContext&amp;);
</ins><span class="cx">         void dump(PrintStream&amp; out) const;
</span><span class="cx">         
</span><span class="cx">         GPRReg directGPR() const;
</span><span class="lines">@@ -83,10 +89,11 @@
</span><span class="cx">         
</span><span class="cx">         Vector&lt;Location&gt; locations;
</span><span class="cx">         
</span><del>-        bool parse(DataView*, unsigned&amp; offset);
</del><ins>+        bool parse(ParseContext&amp;);
</ins><span class="cx">         void dump(PrintStream&amp;) const;
</span><span class="cx">     };
</span><span class="cx"> 
</span><ins>+    unsigned version;
</ins><span class="cx">     Vector&lt;StackSize&gt; stackSizes;
</span><span class="cx">     Vector&lt;Constant&gt; constants;
</span><span class="cx">     Vector&lt;Record&gt; records;
</span></span></pre>
</div>
</div>

</body>
</html>