[go: up one dir, main page]

DEV Community

Alexsandro Souza
Alexsandro Souza

Posted on

JVM execution dilemma - Interpret or compile?

I am always posting provoking post on my Linkedin, and I have decided to replicate those here. Let's socialize!

Alt Text

The JVM execution engine has a big dilemma: Interpret or compile the code?

The interpreter interprets the bytecode and executes the instructions one-by-one. Hence, it can interpret one bytecode line quickly, but executing the interpreted result is a slower task.

JIT compiler takes more time for compiling than for the interpreter to interpret. For a code segment that executes just once, it is better to interpret it instead of compiling, but when one method is called multiple times, each time a new interpretation and a slower execution are required.

To solve the dilemma, JIT compiler internally checks the frequency of each method call and decides to compile each only when the selected method has occurred more than a certain level of times.

This is known as adaptive compiling and it was brought by the introduction of Oracle Hotspot VMs.

Now you know what to answer when asked if Java is compiled or interpreted - it is both!

Top comments (0)