[Mono-dev] (Delegate) Trampoline executed twice?

Martin Däumler mdae at cs.tu-chemnitz.de
Mon Dec 6 11:06:27 EST 2010


Hello,

I currently try to modify Mono (based on 2.6.1) to write C#
applications that meet soft real-time constraints. I want to do
a pre-JIT compilation of nearly all methods and a pre-execution
of most trampoline code.

Look at following snippet that starts a new thread:

	ThreadStart ts = new ThreadStart(mToCall);
	ts.Invoke();
	Thread t = new Thread(ts);
	t.Start();

The delegate trampoline of the ThreadStart object "ts" is executed
first through "ts.Invoke()". However, it is executed a second
time through "t.Start()".

Q#1: There are other trampoline types which might be called twice
for the same "object" it handles (in particular trampolines that are
expected to be called only once)? Which situations are relevant?

In order to pre-execute delegate trampolines we modified the code
generator so that it inserts a delegate calling sequence right
after the constructor call. This delegate call returns to the caller
instead to the callee. So, trampoline execution is shifted from
delegate invoke to delegate initialization. We modified the code
for the common case where a "CEE_LDFTN" followed by a "CEE_NEWOBJ"
CIL instruction is found in the assembly.

Q#2: There might be another situation where a call to a
delegate constructor is emitted by Mono's code generator?


If anybody needs more information, don't be afraid to ask.


With kind regard,
Martin Däumler


More information about the Mono-devel-list mailing list