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

Ben Maurer bmaurer at ximian.com
Sun Oct 24 20:01:06 EDT 2004


On Sun, 2004-10-24 at 23:25 +0200, Zoltan Varga wrote:
> The SIGSEGV will be sent by the processor itself when %r15 is 0, and the
> runtime will convert this to a NullReferenceException.
> 
> >   35:   49 8b ff                mov    %r15,%rdi
> >   38:   49 83 3f 00             cmpq   $0x0,(%r15)
> >   3c:   49 bb 30 6b f0 96 2a    mov    $0x2a96f06b30,%r11
> >   43:   00 00 00
> >   46:   49 ff d3                callq  *%r11
> > 
> > By looking at the code above, it's pretty obvious that mono issues calls on
> > AMD64 by a "mov IMM8, reg\n  call *reg" opcode combination. You've a fixme
> > in the codegen header at this position IIRC: Does that mean you want to use
> > the IP-relative imm4 version, if the call target is in reach?
> > 
> 
> 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...

>  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.

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.

-- 
Ben Maurer <bmaurer at ximian.com>




More information about the Mono-devel-list mailing list