1 / 16

Just-In-Time Compilation

Just-In-Time Compilation. Introduction. Just-in-time compilation  ( JIT ), also known as  dynamic translation , is a method to improve the runtime performance of computer programs.

lowri
Download Presentation

Just-In-Time Compilation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Just-In-Time Compilation

  2. Introduction • Just-in-time compilation (JIT), also known as dynamic translation, is a method to improve the runtime performance of computer programs. • Traditionally, computer programs had two modes of runtime operation, either interpreted or static (ahead-of-time) compilation. • JIT compilers represent a hybrid approach, with translation occurring continuously, as with interpreters, but with caching of translated code to minimize performance degradation. 

  3. Just-In-Time Compiler

  4. Just-In-Time Compilation Functional Duties: • Class Loader • Resolves type references and loads assemblies into memory to be consumed by the verifier and JIT Compiler • JIT Compiler • Runtime component that compiles the MSIL stream into native code • Compares MSIL stream to metadata and verifies that the code is safe and legal (Verification)

  5. JIT Options for Application Developers .NET provides two JIT compilers and an install-time JIT option: • A “normal” JIT compiler, designed to provide the expected optimization when compiling MSIL to native code • The same level of optimization you might expect from a C compiler • This makes the compilation process take longer than otherwise • Ngen.exe, MSIL code is “pre-JIT’ed” or “zapped” and the native image is cached for future use

  6. Just-In-Time Compilation • IL must be compiled to native code in order to run • No files with *.il extensions involved • Multiple JIT compilers for differing processor architectures • Code compiled on an “as needed” basis • Method cached and subsequent calls are not recompiled • Can revert back to a stub using code pitching • Reduces memory footprint

  7. Calling a method for the first time Console Shared Sub WriteLine() Shared Sub WriteLine(String) (remaining members) Managed EXE Shared Sub Main() Console.WriteLine(“Paul”) Console.WriteLine(“Cross”) End Sub Jitter Jitter Native code … MSCorEE.dll • Function Jitter • In the assembly that implements the type (Console), look up the method (WriteLine) being called in the metadata. • From the metadata, get the IL for this method. • Allocate a block of memory. • Compile the IL into native code; save the code in the memory allocated in step 3. • Modify the method’s entry in the Type’s table so that it now points to the memory block allocated in step 3. • Jump to the native code contained inside the memory block. • End Function

  8. Just-In-Time Compilation

  9. JIT Features • Platform Independence • Realized when high-level language compilers convert source code to platform agnostic MSIL code • The application or software component is distributed in this form • JIT compiles to native code either at runtime or at install time

  10. JIT Features • Language Interoperability • Occurs when different language compilers compile to language-agnostic MSIL code • Metadata and the Common Type System play a major role in cross-language and platform independence

  11. JIT Features • Runtime Stack Manipulation • The JIT Compiler populates important data structures for object tracking and specific stack-frame construction • The JIT Compiler can be used to identify specific code elements as they are consumed, i.e., exception handlers and security descriptors

  12. JIT Optimizations • Small Memory Footprint • JIT compilation takes advantage of the possibility that some code may never be used • The JIT Compiler compiles methods only as needed

  13. JIT Optimization • Contiguous Native Code Alignment • The runtime method is optimized for fast data access • The execution engine has the option of aligning native function images in memory • Lends for a smaller footprint • Speeds up CPU access to memory where code is stored

  14. JIT Compilation must be slow • The “Nays”: • Unmanaged code is pre-compiled and can just execute • Managed code requires 2 compilation phases • Compiler produces IL • IL compiled to native code at runtime, requiring more memory to be allocated, and additional CPU cycles

  15. JIT Compilation is actually pretty fast • Reasons why this may be the case: • JIT compiler knows more about the execution environment than an unmanaged compiler would know • JIT compiler can take advantage of instructions offered by the chip that the unmanaged compiler knows nothing about • JIT compiler could detect that a certain test is always false, and short-circuit • The CLR could profile the code’s execution and recompile the IL on the fly reducing branching, etc.

  16. The End …… Thank You ……

More Related