[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Libjit] Function recompilation and deletion

From: Aleksey Demakov
Subject: Re: [Libjit] Function recompilation and deletion
Date: Wed, 14 Feb 2018 09:06:34 +0300

Hi Tom,

On Wed, Feb 14, 2018 at 2:51 AM, Tom Tromey <address@hidden> wrote:
> One of the problems is that I didn't see a way to free a single
> function.  In Emacs, this may be needed when a function is redefined: if
> the old definition is garbage collected, then the JIT-compiled function
> should be freed as well.
> One way to accomplish this would be to allocate each function in its own
> jit_context_t.  However, that seemed expensive to me.  I didn't look
> into the memory management code yet -- would it be difficult to
> implement per-function freeing?

Yes, the memory management mechanism in libjit is, in principe,
intended exactly for this, however nobody tried it yet in practice.

It is hard to do it in generic way as it would be required to protect
against concurrent execution of the code that is being freed. But if
your particular runtime have just one thread or have some sort of
control over threads (can stop them and prevent entering a given
function) then it should be doable.

Another thing is that after recompiling a function it is required to
redirect all old call sites to it. It could be done trivially if you
used indirect calls in the first place. Then it would be required to
change just one memory location that contains the function address.
But this incurs a tiny performance hit on every call. If instead you
want to use direct calls then at the start of the freed function you
will need to emit a trampoline that 1) patches the call site (getting
its address from the stack top (which would be problematic if using
tail-call optimization)) 2) jumps to the new function address. But
then again you cannot reuse the freed region of memory until all
potential call sites are patched. I guess tracking this in a generic
way would be difficult. So indirect calls seem to be the way to go for
recompilation  anyway.

> Also, is there a bug tracker somewhere?

The official one:

Or alternatively you might use github:


reply via email to

[Prev in Thread] Current Thread [Next in Thread]