<div dir="ltr"><div>Hi Sanjoy,</div><div><br></div><div>this Sunday I held a presentation at FOSDEM where I explained Sulong using function pointer call inlining. Yesterday, I uploaded the slides [1].</div><div><br></div><div>We use a form of "guarded devirtualization" as you expected. We do this based on Abstract Syntax Tree (AST) node rewriting in the interpreter. We use a direct call node that directly calls a function if it matches the function that has been profiled before. If it doesn't, we either insert another such direct call node or fall back to an indirect call based on some threshold. Truffle then can perform the inlining on the AST level. After Graal compiles the AST to machine code and when the speculation on the target fails, a deoptimization handler transfers back to the interpreter where the node rewrite is handled.</div><div><br></div><div>We thus do not instrument the writes, but implement a polymorphic function pointer inlining cache at the call site.</div><div><br></div><div>Since polymorphic inline caches are also often used to implement other languages, Truffle's domain specific language allows to express this logic in only a few lines of code. You can have a look at the implementation in com.oracle.truffle.llvm.LLVMCallNode$LLVMFunctionCallChain.</div><div><br></div><div>- Manuel</div><div><br></div><div>[1] <a href="https://fosdem.org/2016/schedule/event/llvm_sulong/attachments/slides/1205/export/events/attachments/llvm_sulong/slides/1205/Sulong.pdf">https://fosdem.org/2016/schedule/event/llvm_sulong/attachments/slides/1205/export/events/attachments/llvm_sulong/slides/1205/Sulong.pdf</a></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-02-01 17:21 GMT+01:00 Sanjoy Das <span dir="ltr"><<a href="mailto:sanjoy@playingwithpointers.com" target="_blank">sanjoy@playingwithpointers.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">Manuel Rigger via llvm-dev wrote:<br>
> Hi everyone,<br>
><br>
> we started a new open source project Sulong: <a href="https://github.com/graalvm/sulong" rel="noreferrer" target="_blank">https://github.com/graalvm/sulong</a>.<br>
><br>
> Sulong is a LLVM IR interpreter with JIT compilation running on top of the JVM.<br>
> By using the Truffle framework, it implements speculative optimizations such as inlining of function pointer calls<br>
> through AST rewriting.<br>
<br></span>
I'm interested in hearing more about how you do this. Do you use<br>
guarded devirtualization (i.e. `if *fn_ptr_loc != @foo then<br>
side_exit(); else @foo()`), or is there something else? I'd guess<br>
implementing "invalidation" based deoptimization (i.e. the value of<br>
`fn_ptr_loc` changed, so deoptimize compiles that depend on it not<br>
changing) will require instrumenting all (?) writes that could alias<br>
`*fp_ptr_loc`?<span class="HOEnZb"><font color="#888888"><br>
<br>
-- Sanjoy<br>
</font></span></blockquote></div><br></div>