[LLVMdev] On-Stack Replacement & Code Patching

Martin Süßkraut martin.suesskraut at googlemail.com
Wed Mar 10 14:24:12 PST 2010


On Wed, Mar 10, 2010 at 21:11, Nyx <mcheva at cs.mcgill.ca> wrote:
>
> I am interested in writing a JIT that makes use of on-stack replacement. This
> essentially means that the JIT must be able to compile new versions of
> already compiled functions (eg: more optimized versions) and ensure that the
> code for the new functions is executed. I was wondering if LLVM offers any
> support for this.
>
> Suppose a function f calls a function g, and f is recompiled while g is
> running, I would need to be able, when returning from g to f, to jump to the
> updated code for f. So, one way to implement this would be to insert a jump
> after every call in the body of the old function f, that jump to the
> corresponding point in the body of the new function. This would require me
> to overwrite some of the code of f. If LLVM has no direct support for this,
> I could potentially create auxiliary "call handler" functions which can do a
> long jump to the proper code on return.
>
> So what I would like to know is:
>
> 1. Does LLVM support code patching? By this, I mean overwriting some
> instructions
> 2. Does LLVM support long jumps?
> 3. Has anyone here implemented code patching or on-stack replacement in
> LLVM?
We have implemented on-stack replacement for switching from an
optimized code base to an unoptimized code base (maybe containing
additional runtime checks).

The basic idea is to prepare both code bases BEFORE applying any
further instrumentation (optimization or adding runtime checks).

We present the details about our LLVM-pass at CGO this year in a paper
called "Prospect: A Compiler Framework for Speculative
Parallelization".

If you are interested in the paper, please contact me off-line of the
mailing list.

Martin
>
> Another potential issue is that if I recompile some function, I would
> ideally want to keep the same stack representation for both. This could
> potentially be quite tricky. Any advice on how to go about this?
> --
> View this message in context: http://old.nabble.com/On-Stack-Replacement---Code-Patching-tp27855179p27855179.html
> Sent from the LLVM - Dev mailing list archive at Nabble.com.
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>



-- 
Martin Süßkraut
Dresden University of Technology,
Computer Science Department
Systems Engineering Group
Dresden, Germany
http://wwwse.inf.tu-dresden.de




More information about the llvm-dev mailing list