Pressacco
Pressacco

Reputation: 2875

How do you guarantee that the CLR JIT "method" cache has been cleared?

How do I guarantee that the CLR's JIT "method" cache has been cleared? Is it simply a matter of starting a new instance of the application, or do you have to re-boot the PC?

It is my understanding the the CLR JIT is process specific, and that this should work.

  1. Foobar.exe is started.
  2. DoWork() is invoked for the first time
    • CLR's JIT compiler converts the intermediate language (for DoWork()) to machine code
    • the generated machine code is cached in-memory for future calls
  3. DoWork() is called again, and existing machine code is used. (i.e. JIT is bypassed)
  4. Terminate Foobar.exe application.
    • there are no instances of Foobar.exe running
  5. Foobar.exe is started again.
  6. DoWork() is invoked for the first time
    • Terminating the previous application, and starting a new instance effectively cleared the JIT "method" cache.
    • CLR's JIT compiler converts the intermediate language (for DoWork()) to machine code
    • the generated machine code is cached in-memory for future calls
  7. DoWork() is called again, and existing machine code is used. (i.e. JIT is bypassed)

Any feedback that can be provided would be greatly appreciated.

Environment

Related Reading

Upvotes: 1

Views: 360

Answers (1)

Rodrigo Campos
Rodrigo Campos

Reputation: 68

Your understanding is very correct.

Every time the process is started, the JIT emits a new machine code that is used until the process is finished.

However, it's also possible to create a machine code cache, to avoid repetitive jit emission. It's know as NGen

Upvotes: 1

Related Questions