<div dir="ltr">Hi Javier,<div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 28, 2018 at 7:36 AM, Javier Pimás <span dir="ltr"><<a href="mailto:elpochodelagente@gmail.com" target="_blank">elpochodelagente@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><br><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Feb 28, 2018 at 11:13 AM, Clément Bera <span dir="ltr"><<a href="mailto:bera.clement@gmail.com" target="_blank">bera.clement@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"> <div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Feb 28, 2018 at 2:16 PM, Javier Pimás <span dir="ltr"><<a href="mailto:elpochodelagente@gmail.com" target="_blank">elpochodelagente@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"> <br><div dir="ltr">Hi! This time I'm investigating how cog jit handles pointers to objects in native code. In x86-32 its easier because you have immediates of the size of a pointer, but in x64 the immediates are restricted to 32bits (and I think less in arm). So I wonder how people works around that, if using a movabs instruction every time you need a pointer or if doing something else. I found a mail in the list dated from 2011 (titled "questions about cog internals") where you (Eliot) said that pointers were inlined in jit code, but I don't know if that's still the case. Looking at the slang code I found CogOutOfLineLiteralsX64C<wbr>ompiler, but it seems it is not used (yet?).<br clear="all"></div></blockquote><div><br></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);float:none;display:inline">Just generate & disassemble any method with literals from the Squeak image (in-image compilation workspace scripts) with different ISA and look at the disassembled code, it takes 1 second and you'll see by yourself how pointer size constants (literals) are dealt with.</span> </div><div><br></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);float:none;display:inline">The ARM JIT</span> dumps pointer size constants somewhere unreachable by machine code execution but near by (in-between jumps for example) and access it with <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);float:none;display:inline">PC-relative instructions, that's one good way to work around it.</span></div></div></div></div></blockquote><div><br></div><div>The arm jit also seems to support the two approaches (CogInLineLiteralsARMCompiler, CogOutOfLineLiteralsARMCompile<wbr>r), how do you do gc with inline literals there?</div></div></div></div></blockquote><div><br></div><div>With suitably layered abstractions.  The method map is traversed using Cogit>>#mapFor:performUntil:arg:.  mapObjectReferencesInMachineCode: is the entry point for GC and become.  e.g. a scavenge applies remapIfObjectRef:pc:hasYoung: via mapFor:performUntil:arg: to every method in the youngReferrers list (which drastically reduces the amount of machine code scanned in each scavenge; most methods don't have any references to young objects), whereas mapObjectReferencesInMachineCodeForFullGC applies #remapIfObjectRef:pc:hasYoung: via mapFor:performUntil:arg: to every machine code method, and to any object references in the generated run-time.</div><div><br></div><div><br></div><div>remapIfObjectRef:pc:hasYoung: has the following signature:<br></div><div><br></div><div>remapIfObjectRef: annotation pc: mcpc hasYoung: hasYoungPtr<br></div><div><br></div><div>If annotation is IsObjectReference then the literalsManager is asked to fetch and store literal referenced at pc via fetchLiteralAtAnnotatedAddress:using: and storeLiteral:atAnnotatedAddress:using:.  These in turn defer to the backEnd (an instance of the current CogCompilerClass, such as CogInLineLiteralsX64Compiler) to extract the address or literal from the machine code and store it back.  With in-line literals the address following the instruction is added to the map.  With out-of-line literals the address of the literal is added to the map.</div><div><br></div><div>Then once all relevant methods haver been processed the instruction cache is flushed and execution proceeds.</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Best,</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Cheers!</div><div>Pocho</div>-- <br><div class="gmail-m_9180718590834913071gmail-m_-6477871057394922900m_-2223832529553718695gmail_signature"><div dir="ltr">Javier Pimás<br>Ciudad de Buenos Aires</div></div></div></blockquote></div>-- <br><div class="gmail-m_9180718590834913071gmail-m_-6477871057394922900gmail_signature"><div dir="ltr"><span style="font-size:12.8px">Clément Béra</span><div style="font-size:12.8px">Pharo consortium engineer</div><div style="font-size:12.8px"><a href="https://clementbera.wordpress.com/" target="_blank">https://clementbera.wordpress.<wbr>com/</a><br></div><div style="font-size:12.8px"><span style="line-height:16px">Bâtiment B 40, avenue Halley 59650 </span><span style="font-weight:bold;line-height:16px">Villeneuve d'Ascq</span></div></div></div></div></div></blockquote></div>-- <br><div class="gmail-m_9180718590834913071gmail_signature"><div dir="ltr">Javier Pimás<br>Ciudad de Buenos Aires</div></div>
</div></div>
</blockquote></div><br><div class="gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div>
</div></div>