This document summarizes a talk on what happens when Java code is executed, from compilation to bytecode to machine code. It discusses how the Java compiler converts code to bytecode and how the JIT compiler further converts it to machine code. It also demonstrates how optimizations like inlining can improve performance and how data structures like linked lists perform poorly due to cache misses. The document emphasizes that modern computing involves many layers of abstraction and technology below the surface.
4. What Lies Beneath
• What, another ”Hello World” talk?
• Yes! It’s about what happens when we type
• It’s amazingly complicated
— and interesting!
java Hello.java
12. JMH tells us...
REMEMBER: The numbers below are just data. To gain reusable insights, you need to
follow up on why the numbers are the way they are...
Do not assume the numbers tell you what you want them to tell.
Benchmark Mode Cnt Score Error Units
ComputerBenchmark.compute avgt 15 423.276 ± 22.782 ns/op
13. Improving Our Program…
private int add(int value) {
return value + 254;
}
public int compute(int value) {
return add(value / 0xdeadbeef);
}
public static void main(String[] args) {
System.out.println(new Computer().compute(0xcafebabe));
}
14. private int add(int value) {
return value + 254;
}
public int compute(int value) {
return (value / 0xdeadbeef) + 254;
}
public static void main(String[] args) {
System.out.println(new Computer().compute(0xcafebabe));
}
Improving Our Program…
18. Now JMH tells us…
REMEMBER: The numbers below are just data. To gain reusable insights, you need to
follow up on why the numbers are the way they are...
Do not assume the numbers tell you what you want them to tell.
Benchmark Mode Cnt Score Error Units
ComputerBenchmark.compute (interpreted) avgt 15 423.276 ± 22.782 ns/op
ComputerBenchmark.compute (no inlining) avgt 15 11.831 ± 0.002 ns/op
ComputerBenchmark.compute (w/ inlining) avgt 15 6.307 ± 0.006 ns/op
28. Conclusions
From javac soup to hardware nuts, there’s a lot of advanced
technology here.
And as everyone knows, to the ignorant –
“Any sufficiently advanced
technology is indistinguishable
from magic.”
Don’t believe in magic!