Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> I've always wondered how production/robust JVM implementations make themselves "faster" after they warm up.

They compile the bytecode just-in-time to native machine code, using many of the same techniques a conventional native code compiler.



Maybe my knowledge isn't up to date, but I always understood (since Hotspot anyway) that not all bytecode is necessarily JIT'd to native code.

From the Hotspot Wikipedia page:

"Both VMs compile only often-run methods, using a configurable invocation-count threshold to decide which methods to compile."[1]

Also see very old discussions at StackOverflow[2][3]. Then of course there are compilers (eg. gcj) which compile to native up-front.

[1] https://en.wikipedia.org/wiki/HotSpot#Features

[2] https://stackoverflow.com/questions/7100365/why-doesnt-javas...

[3] https://stackoverflow.com/questions/16568253/difference-betw...


Only hot code paths get compiled. That's after 10000 executions on "server" JVM and 1000 executions on a "client" JVM by default.

This is by design, and if you need everything compiled right away you can set the compilation threshold to 1.

I don't see any value in compiling parts of code that only gets executed during bootstrap.


Nitpick: the HotSpot 'client' JVM's default JIT threshold is 1500, not 1000.

https://www.oracle.com/java/technologies/javase/vmoptions-js...


You're right, thank you for correcting me. For more popular archs (x86, arm, aarch64) it's 1500. It's only 1000 by default for ppc, s390 and sparc.

https://chriswhocodes.com/hotspot_options_jdk14.html


So we're both right! Didn't know it varied between architectures.


> I don't see any value in compiling parts of code that only gets executed during bootstrap.

Not disagreeing with you there, since stopping to compile code/optimize at runtime contributes to sluggish interactive performance.


Compilation is performed concurrently to the application in specialised compilation threads. Only OSR (on-stack-replacement) requires stopping execution.


> Not disagreeing with you there, since stopping to compile code/optimize at runtime contributes to sluggish interactive performance.

No JVM I am aware of stops to compile - the compiler runs on a background thread while the application continues to run as normal.


> I always understood (since Hotspot anyway) that not all bytecode is necessarily JIT'd to native code

Who are you disagreeing with? I didn’t say that’s the only way they execute bytecode, did I?

The question was how it’s executed ‘after they warm up’.

> Then of course there are compilers (eg. gcj) which compile to native up-front.

But I was replying to someone who asked specifically about how ‘production JVMs’ do it, not how discontinued compilers do it.


> Who are you disagreeing with? I didn’t say that’s the only way they execute bytecode, did I?

Nope, my bad. Thanks for clarifying.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: