Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible for JIT inlining to inline my code into some .NET runtime assembly code?

I'd like to understand how ubiquitous JIT inlining can be.

Suppose in my code I call some function from say System.IO assembly and pass a callback reference to a function implemented in my code for being called from inside that System.IO function. In my function there's GetCallingAssembly() call. So if my callback gets inlined into System.IO the call to GetCallingAssembly() that originally was in my code and was intended to say the "current" method is called from inside System.IO will say that it now is called from inside my code.

Is such inlining possible or are .NET runtime assemblies treated differently so that JIT inlining of user code into .NET runtime code is not allowed?

like image 347
sharptooth Avatar asked Oct 22 '22 08:10

sharptooth


1 Answers

You can safely assume the callback will not be inlined. .NET Framework assemblies are always pre-jitted by ngen.exe at install time, there's no option to alter that code afterwards. Furthermore, callbacks through a delegate are never inlined even if the jitter optimizer could deduce what the delegate's target method might be.

like image 125
Hans Passant Avatar answered Nov 02 '22 03:11

Hans Passant