A compiler is a software program that converts computer programming code written by a human programmer into binary code (machine code) that can be understood and executed by a specific CPU. The act of transforming source code into machine code is called "compilation." When all the code is transformed at one time before it reaches the platforms that run it, the process is called ahead-of-time (AOT) compilation.
Which Programming Languages Use an AOT Compiler?
Many well-known programming languages require a compiler including:
- Assembly Language
Before Java and C#, all computer programs were either compiled or interpreted.
What About Interpreted Code?
Compiled code runs faster than interpreted code because it doesn't need to do any work at the time the action takes place. The work is already done.
Which Programming Languages Use a JIT Compiler?
Java and C# use just-in-time compilers. Just-in-time compilers are a combination of AOT compilers and interpreters. After a Java program is written, the JIT compiler turns the code into bytecode rather than into code that contains instructions for a specific hardware platform's processor. The bytecode is platform independent and can be sent and run on any platform that supports Java. In a sense, the program is compiled in a two-stage process.
Similarly, C# uses a JIT compiler that is part of the Common Language Runtime, which manages the execution of all .NET applications. Each target platform has a JIT compiler. As long as the intermediate bytecode language conversion can be understood by the platform, the program runs.
Pros and Cons of AOT and JIT Compilation
Ahead-of-time (AOT) compilation delivers faster startup time, particularly when much of the code executes at startup. However, it requires more memory and more disk space. JOT compilation must target the least capable of all possible execution platforms.
Just-in-time (JIT) compilation profiles the target platform while it runs and re-compiles on the fly to deliver improved performance. JIT generates improved code because it targets the current platform, although it usually takes more time to run than AOT compiled code.