<br><br><div class="gmail_quote">On Fri, Apr 1, 2011 at 1:26 PM, Eric Christopher <span dir="ltr"><<a href="mailto:echristo@apple.com">echristo@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div><div></div><div class="h5"><br>
On Apr 1, 2011, at 9:38 AM, Reid Kleckner wrote:<br>
<br>
> On Thu, Mar 31, 2011 at 11:15 PM, Eric Christopher <<a href="mailto:echristo@apple.com">echristo@apple.com</a>> wrote:<br>
>>><br>
>>><br>
>>> Then we would always have the location of the br B instruction in A, as it is pushed onto the stack or saved in link register when A calls B.<br>
>>><br>
>><br>
>> Right, unless you wanted to go with direct calls in the JIT. I don't know that inspecting a running program's stack for return values while compiling on a separate thread is sane :)<br>
>><br>
>> That said, the adaptive compilation strategy can always enforce the use of a stub for calls into jitted functions.<br>
><br>
> I think you said what I was going to say, but here's how I see it:<br>
><br>
> getPointerToFunction always returns the address of the stub, so any<br>
> indirect calls to the function hit the stub.  The stub will attempt to<br>
> backpatch the callsite, and should fail if it is a) outside the JIT or<br>
> b) an indirect call.  Indirect calls will always go through the stub.<br>
> Direct calls can be backpatched.<br>
><br>
> Alternatively, everything would go through the stub.<br>
><br>
> Finally, you have to be careful about the memory model of the<br>
> architecture you're dealing with if you care about threads.  On x86,<br>
> if you can align the operand of the call instruction, you can do an<br>
> atomic update.  You will also have to make sure you don't free the old<br>
> machine code while there are still functions executing in it.  An easy<br>
> (yet inefficient) way to deal with this is to update a refcount on<br>
> function entry/exit.<br>
<br></div></div></blockquote><div>Another way to do the patching is to first atomically inserted a self-loop jump -2 atomically (jump -2 takes 2 bytes and 2 bytes writing is atomic on x86 )  into the old branch address on x86 such that it stops all threads reaching this point. copy in the new compiled function address.  and then re-patch the jump -2 with the correct binary. <br>
<br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div class="h5">
</div></div>Well said :)<br>
<font color="#888888"><br>
-eric<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Kind Regards <br><br>Xin Tong <br>