<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Courier New";}
span.EmailStyle20
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
span.EmailStyle21
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
span.EmailStyle22
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:1605916574;
        mso-list-type:hybrid;
        mso-list-template-ids:-524383778 67698705 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
        {mso-level-text:"%1\)";
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level2
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level3
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level4
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level5
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level6
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level7
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level8
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level9
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">My comments are
</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#7F6000;mso-style-textfill-fill-color:#7F6000;mso-style-textfill-fill-alpha:100.0%">inline</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Swaroop.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Andrew Trick [mailto:atrick@apple.com]
<br>
<b>Sent:</b> Thursday, July 9, 2015 4:36 PM<br>
<b>To:</b> Swaroop Sridhar<br>
<b>Cc:</b> Juergen Ributzka; LLVM Dev; Lang Hames; Phil Pizlo; Philip Reames; Sanjoy Das; Russell Hadley<br>
<b>Subject:</b> Re: [RFC] New StackMap format proposal (StackMap v2)<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">On Jul 9, 2015, at 3:33 PM, Swaroop Sridhar <<a href="mailto:Swaroop.Sridhar@microsoft.com">Swaroop.Sridhar@microsoft.com</a>> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Regarding Call-site size specification:</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">CoreCLR (<a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_dotnet_coreclr&d=AwMGaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=Y5HT62-PDFURHtBTN_g2hBkEz7DiufWi8dZm7PyKNKc&s=7zEpxhtd5GTxVkPP2y91PCJ_gd5uwjnkOiilpqCaTxc&e=">https://github.com/dotnet/coreclr</a>) requires the size of the Call-instruction to be reported in the GCInfo
 encoding.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">The runtime performs querries for StackMap records using instruction offsets as follows:</span><o:p></o:p></p>
<p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo2"><![if !supportLists]><span style="mso-list:Ignore">1)<span style="font:7.0pt "Times New Roman"">     
</span></span><![endif]><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Offset at the end of the call instruction (offset of next instruction-1) if the call instruction occurs in code where GC can only take control at safe-points.</span><o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal">As part of this change it would be great if LLVM could now guarantee that the call will be emitted at the end of the patchable space. It currently happens to emit at the beginning, but makes no guarantee. Emitting at the end works better
 for tracking the return address.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><br>
<span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#7F6000;mso-style-textfill-fill-color:#7F6000;mso-style-textfill-fill-alpha:100.0%">I second emitting the call-instruction at the end of the patch-space.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo2"><![if !supportLists]><span style="mso-list:Ignore">2)<span style="font:7.0pt "Times New Roman"">     
</span></span><![endif]><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Offset of the start of the call instruction if the call instruction occurs within a code-range that allows full interruption (that is, all instructions in
 a range are considered safe-points)</span><o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">If the JIT requires knowledge of call's encoding, it should probably be emitting the call instruction itself within the patchable space reserved by LLVM. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Note that the patchpoint may include a mov in addition to call, so the patchpoint address is not the same as the call address.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">LLVM/statepoint GC does not support option (2), but the CoreCLR’s GC-table Encoding has an interface designed to suite both modes.</span><o:p></o:p></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:blue">void</span><span style="font-size:10.0pt;font-family:Consolas"> DefineCallSites(<span style="color:#2B91AF">UINT32</span>* <span style="color:gray">pCallSites</span>, <span style="color:#2B91AF">BYTE</span>* <span style="color:gray">pCallSiteSizes</span>, <span style="color:#2B91AF">UINT32</span> <span style="color:gray">numCallSites</span>)</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Therefore, it is helpful to have Call-Site size specified in
</span><span style="font-family:"Courier New"">StackMapRecord</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">I agree with Andy, that the call-site size should include all bytes between the start of the call instruction and the start of the next instruction.</span><o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I suggested this because we want to support a dynamic callback that determines the patchpoint size (given the set of register arguments), and it would be nice to record that decision within the stack map. This is important information for
 any code that is responsible for patching because it must patch over all reserved bytes.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">The alternative would be for LLVM to emit the call at the end and record just the size of the call instruction encoding. That seems like a silly, x86-specific waste of stackmap space though. The JIT can either do the encoding and keep track
 of the info, or a small nop+move_immediate decoder can figure it out for all reasonable cases.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#7F6000;mso-style-textfill-fill-color:#7F6000;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#7F6000;mso-style-textfill-fill-color:#7F6000;mso-style-textfill-fill-alpha:100.0%">I agree here too.  CallSiteSize should record the size of the entire patch-point –
 to facilitate versatile use of the CallSiteSize field.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#7F6000;mso-style-textfill-fill-color:#7F6000;mso-style-textfill-fill-alpha:100.0%">Recording just the size of the call-instruction breaks the patchpoint abstraction.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#7F6000;mso-style-textfill-fill-color:#7F6000;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#7F6000;mso-style-textfill-fill-color:#7F6000;mso-style-textfill-fill-alpha:100.0%">Given the size of the patchpoint, a Jit needing just the Call-Instruction size can
 do a local decoding as you’ve suggested.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal">Andy<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Thanks,</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Swaroop.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><o:p></o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Juergen Ributzka [<a href="mailto:juergen@apple.com">mailto:juergen@apple.com</a>]
<br>
<b>Sent:</b> Thursday, July 9, 2015 2:04 PM<br>
<b>To:</b> LLVM Dev<br>
<b>Cc:</b> Lang Hames; Andrew Trick; Phil Pizlo; Philip Reames; Sanjoy Das; Swaroop Sridhar; Russell Hadley<br>
<b>Subject:</b> [RFC] New StackMap format proposal (StackMap v2)</span><o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Hi @ll,<o:p></o:p></p>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">over the past year we gained more experience with the patchpoint/stackmap/statepoint intrinsics and it exposed limitations in the stackmap format.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">The following proposal includes feedback and request from several interested parties and I would like to hear your feedback.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Missing correlation between functions and stackmap records:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Originally the client had to keep track of the ID to know which stackmap record belongs to which function, but this would stop working once functions are inlined.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">The new format fixes that by adding a direct reference from the function to the stackmap records.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Call Size and Function Size:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">These are additional information that are of interest and have been added to the format.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">@Swaroop: Could you please provide a little more detailed explanation on the "Call Size" field and what exactly is there recorded. Is it just the call instruction<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">or also the materialization code for the address? For what is this used for?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Flat format:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">We think moving to a flat form will make parsing easier, because every record has a fixed size and offsets can be calculated easily. The plan is to also<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">provide parsers for both stackmap versions (there is already one for the first format in tree) and a corresponding C-API to make it easier for clients to<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">adopt the new format. There is no plan to drop the original format and we will continue to support both formats. I will ask for feedback on the C API in a<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">separate RFC. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Another benefit we hope to achieve from this format is to optimize for size by uniquing entries - but that is independent optimization and not required.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">More detailed frame record:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Clients require more information about the function frame, such as spilled registers, etc. The frame base register i.e. might change when dynamic stack<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">realignment is performed on X86.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">If there is anything missing please let me know.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Thanks<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Cheers,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Juergen<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">Header v2 {<br>
  uint8  : Stack Map Version (2)<br>
  uint8  : Reserved [3] (0)<br>
  uint32 : Constants Offset (bytes)<br>
  uint32 : Frame Records Offset (bytes)<br>
  uint32 : Frame Registers Offset (bytes)<br>
  uint32 : StackMap Records Offset (bytes)<br>
  uint32 : Locations Offset (bytes)<br>
  uint32 : LiveOuts Offset (bytes)</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">}<br>
<br>
align to 8 bytes<br>
Constants[] {<br>
  uint64 : LargeConstant<br>
}<br>
<br>
align to 8 bytes<br>
FrameRecord[] {<br>
  uint64 : Function Address<br>
  uint32 : Function Size<br>
  uint32 : Stack Size<br>
  uint16 : Flags {<br>
    bool : HasFrame<br>
    bool : HasVariableSizeAlloca<br>
    bool : HasStackRealignment<br>
    bool : HasLiveOutInfo<br>
    bool : Reserved [12]<br>
  }<br>
  uint16 : Frame Base Register Dwarf RegNum<br>
  uint16 : Num Frame Registers<br>
  uint16 : Frame Register Index<br>
  uint16 : Num StackMap Records<br>
  uint16 : StackMap Record Index</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">}<br>
<br>
align to 4 bytes<br>
FrameRegister[] {<br>
  uint16 : Dwarf RegNum<br>
  int16  : Offset<br>
  uint8  : Size in Bytes<br>
  uint8  : Flags {<br>
    bool : IsSpilled<br>
    bool : Reserved [7]<br>
  }<br>
}<br>
<br>
align to 8 bytes<br>
StackMapRecord[] {<br>
  uint64 : PatchPoint ID<br>
  uint32 : Instruction Offset<br>
  uint8  : Call size (bytes)<br>
  uint8  : Flags {<br>
    bool : HasLiveOutInfo<br>
    bool : Reserved [7]<br>
  }<br>
  uint16 : Num Locations<br>
  uint16 : Location Index<br>
  uint16 : Num LiveOuts<br>
  uint16 : LiveOut Index<br>
}</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">align to 4 bytes</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New"">Location[] {<br>
  uint8  : Register | Direct | Indirect | Constant | ConstantIndex<br>
  uint8  : Reserved (location flags)<br>
  uint16 : Dwarf RegNum<br>
  int32  : Offset or SmallConstant<br>
}<br>
<br>
align to 2 bytes<br>
LiveOuts[] {<br>
  uint16 : Dwarf RegNum<br>
  uint8  : Reserved<br>
  uint8  : Size in Bytes<br>
}</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>