How can I see the code generated by the JIT

Messages like http://aakinshin.net/en/blog/dotnet/ryujit-ctp5-and-loop-unrolling/ show assembly code generated by the JIT compiler. How can I get an extended assembly from a .NET program?

+3


source to share


1 answer


This was just copied from the Visual Studio debugger window. You just need to change a few options so you can debug the optimized code, it doesn't do otherwise to reverse the loop:

  • Tools> Options> Debugging> General> Select the Suppress JIT Optimization checkbox. Also disable "Just My Code" to be safe. This ensures that the optimizer is allowed to do its job, even if you are debugging.
  • Build> Configuration Manager> top left combo = Release. The Debug build is never optimized.
  • Project> Properties> Build> uncheck "Prefer 32-bit" and make sure the target combo Platform is AnyCPU. You need to get the new x64 jitter, not x86 jitter, to generate your code.
  • Set a breakpoint on the code you want to watch. Beware that breakpoints act in optimized code and may not break at all, it is best to set it on the method header or one step from the beginning.
  • Press F5. At the breakpoint, use Debug> Windows> Disassembly. You will see a mix of source and native code, just as it appears in a blog post.


Remember, you must write "essential" code that has enough side effects that it is not fully optimized. For example, Console.Write () might help. If you are having trouble correlating source code with native code, you can do this first to build Debug.

+4


source







All Articles