简体   繁体   中英

Does the Hotspot JVM Compile the code to machine code or simply runs it

To simplify the question, lets assume that in our JRE we have a Hotspot JVM implementation that doesn't use JIT. Meaning we won't have machine code precompiled.

I am trying to understand, the JVM when it encounters byte code, does the interpreter uses the Hotspot compiler to compile the code to machine code and only then can the JVM run the code? Or does the interpreter simply runs the code as the JVM has some kind of native methods that correspond to each byte code command?

Meaning we won't have machine code precompiled.

The above sentence of yours indicates your misunderstanding of what the JIT compiler is. It doesn't compile code ahead of time, but just in time, hence its name.

This makes the rest of your question harder to understand because the "HotSpot compiler" is the JIT compiler.

But, to sum this up for you: in a normal case, HotSpot begins by interpreting the bytecode, then JIT-compiles those pieces whose runtime profiling data indicates that they are the "hot spots", being executed a lot (default threshold is 10,000 passes over a piece of code).

If you disable JIT compiling, HotSpot will indeed just interpret all of the Java bytecode.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM