Activator.CreateInstance() and JITing
-
Let's say I have 3 classes. Class 1 needs to create an instance of Class 2 or Class 3 depending on some evaluation. All three classes reside within the same assembly. When Activator.CreateInstance() is called does the loaded type get re-jitted even though the caller is in fact the same assembly and has already been jitted? Just wondering :) Any thoughts on this would be appreciated!!! Jarrod
-
Let's say I have 3 classes. Class 1 needs to create an instance of Class 2 or Class 3 depending on some evaluation. All three classes reside within the same assembly. When Activator.CreateInstance() is called does the loaded type get re-jitted even though the caller is in fact the same assembly and has already been jitted? Just wondering :) Any thoughts on this would be appreciated!!! Jarrod
JarrodM wrote: When Activator.CreateInstance() is called does the loaded type get re-jitted even though the caller is in fact the same assembly and has already been jitted? Unless you run the ngen utility on your assembly, JITting takes place on a method by method basis. So the JIT should only occur once per method. James - out of order -
-
JarrodM wrote: When Activator.CreateInstance() is called does the loaded type get re-jitted even though the caller is in fact the same assembly and has already been jitted? Unless you run the ngen utility on your assembly, JITting takes place on a method by method basis. So the JIT should only occur once per method. James - out of order -
So each time I call a method for the first time on one of these classes newly instantiated by reflection it will JIT? Jarrod
-
So each time I call a method for the first time on one of these classes newly instantiated by reflection it will JIT? Jarrod
Sorry, I meant to add that bit in but forgot :-O This part is tricky for me to word so please accept my apologies before hand. JITting occurs when one of a few things happen: A method is being run for the first time, the underlying IL of an already JITted method has changed, or in certain circumstances the native code produced by ngen will be ignored (ASP.NET is one case). There are also some Debug/Profiling methods that will perfrom a re-JIT. Unless you are causing the JIT by running ngen, the native code generated will be tossed out after the Assembly has been unloaded. The native code generated is also AppDomain specific, so if you have two AppDomains each loading the same assembly then each method will be JITted once for each AppDomain. Now in your case, the JIT will only occur the first time each method is used, regardless of whether the object using that method is created by Reflection or regular code. James - out of order -