Just In Time introduction to JVM compilation
An introduction to compilation for the JVM, bytecode and JIT compilation, and benchmarking with JMH. It accompanies a talk I gave to the Berlin-Brandenburg Scala User Group.
Introduction
Scala code is a long way from the metal. In this talk we’ll see some of the steps in between, including some nuggets of JIT compilation, and I’ll introduce JMH as a tool for both benchmarking and investigating what your app is actually doing.
A lot of cleverness happens between writing your code in an IDE and having run on an actual CPU, and a lot of it looks like magic, at least from the outside. This talks aims to describe a selection of the steps between your IDE and the metal. It’s not going to be a complete end-to-end description, primarily because a lot of it is way beyond my expertise!
I hope that those who read this post (or attended the talk) will take away with them an idea of some of the tools that can be used to inspect the post-IDE lifetime of their code, and an idea of how to understand the output. I would not expect to use these tools every day, but a more important goal is to give some context of what’s happening at a level beneath your source code.
Contents
- [Series] Just In Time – introduction to JVM compilation
An introduction to compilation for the JVM, bytecode and JIT compilation, and benchmarking with JMH. It accompanies a talk I gave to the Berlin-Brandenburg Scala User Group.
- 1. What is Compilation? – introduction to JVM compilation
An introduction to what we mean by compilation and why it has multiple stages. A brief comparison between how Scala and Java compile similar structures for use in the JVM.
- 2. Bytecode – compilation at compile-time
What is bytecode and how does it work? What does Scala code look like when compiled to bytecode?
- 3. Benchmarking and Assembly – compilation at runtime
How you can see the assembler code that the JIT compiler generates to be run on the actual CPU, explored by way of some examples of benchmarking.
- Summary – benchmarking and compilation in perspective
The compiler is sneaky, but there's order behind the magic of the JVM. This is all fascinating, but it's probably not the bottleneck in your application.
Comments, corrections and clarifications are always welcome, whether by email, Twitter or a as a PR for this blog!
Further Reading
- Slides for this talk
- Alexey Shipilev’s blog, in particular his post on Nanotrusting Nanotime