[Mono-devel-list] AMD64, PInvoke + Native Exceptions

Paolo Molaro lupus at ximian.com
Mon Oct 25 09:54:38 EDT 2004


On 10/24/04 Ben Maurer wrote:
> > This could be optimized but this is not done yet. Mostly because originally
> > methods make calls to trampolines which call back into the JIT to compile the
> > method, then the call site is patched to call the newly compiled method.
> Well, unless the code has already been compiled, in which case you could
> make the call with whatever offset fits...

This can't be done, since at the time the code is emitted it's final
place in memory is not known yet. On ppc we optimistically emit the shorter
branch instruction and if the target is not reachable we use a small trampoline
which is allocated in an area of memory close enough to the code. I think the amd64
port should do the same, maybe taking advantage of ip-relative addressing.
The changes needed to emit code at the final destination in memory should not
be hard, but they have some overhead and they don't solve the issue anyway,
because of the call site patching.

> >  If the trampoline can be called with a 32 bit offset, but the newly compiled method
> > can't, then the call site can't be patched which could lead to perf problems.
> 
> It seems exceedingly unlikely that the new code would not land within
> 2gb of the old one.

The only way to guarantee that is to do a single mmap of all the memory
for storing code that is needed, which is impractical, mostly because
of appdomain support, but there are also calls to methods that are outside
the mmapped area.

> Even if this happens, there is an easy way out. As soon as you hit the
> first method where the call site can not be patched, change the
> trampoline be code to jmp to the compiled method. This avoids the huge
> overhead on every call. The only disadvantage is that you end up
> executing a tad bit more code per call. However, this small, unlikely
> cost is likely amortized by the savings in code space elsewhere.

This can't be done with the current trampoline code: it would help if you went
and read the code so you'd have some idea of the things you propose.

lupus

-- 
-----------------------------------------------------------------
lupus at debian.org                                     debian/rules
lupus at ximian.com                             Monkeys do it better



More information about the Mono-devel-list mailing list