If I create a dll called xaisoft.dll like this:
Using System;
Using System.Reflection;
[assembly:AssemblyVersion("1.0.0.0")]
public class XaiSoft
{
public string PrintName()
{
return "XaiSoft";
}
}
and then compile it with
csc /t:library lib.cs
and then create a process assembly to use my library like so:
Using System;
Using System.Reflection;
class App
{
static void Main()
{
ShowAssemblies("Before creating type");
ShowName();
ShowAsseblies("After creating type");
}
static void ShowName();
{
XaiSoft x = new XaiSoft();
Console.WriteLine("Name: {0}", x.PrintName());
}
static void ShowAssemblies(string message)
{
Console.WriteLine(message);
foreach(Assembly a in AppDomain.CurrentDomain.GetAssemblies())
{
Console.WriteLine(a.FullName);
}
}
}
Now, if I compile the above with csc app.cs /r:XaiSoft.dll
and then run it
I will see that the XaiSoft.dll is loaded even before PrintName from XaiSoft is called.
This brings me to my questions:
I read that the reason it does this is that when the runtime JIT compiles the method, it inlines small methods call by the current method (Main). How small do the methods have to be in order for them to be inlined? and by inlining does it mean it extracts the contents of ShowName and puts it directly in the Main method.
I also read that when once a method is JIT compiled, it is cached in memory, I am a little confused by this. This is only when your application is running right? If I close it down and run it again, does it have to JIT compile my method again?
Can someone explain the statement : To Successfully JIT Compile a method, the runtime must have access to the types used by the method, so the runtime will load the assemblies that contain those types. Is the answer to the previous statement, the runtime will laod the assemblies that contain those types so it can jit compile the method or would changing the access modifier to private prevent it from being jit compiled
Also, does the compiler keep inlining methods within methods that they are called if they are small enough:
For example if I have the following code snippet:
static void Main()
{
ShowName();
}
static void ShowName()
{
ShowAge();
}
static void ShowAge()
{
ShowGender();
}
static void ShowGender()
{
//Show gender code
}
Would Main inline ShowName, ShowName inline ShowAge, ShowAge inline ShowGender? If it did do that, would it go further and would main end up inlining everything.