Reputation: 21173
Over time, Sun's JVM and JIT have gotten pretty smart. Things that used to be common knowledge as being a necessary micro-optimization are no longer needed, because it gets taken care of for you.
For example, it used to be the case that you should mark all possible classes as final, so the JVM inlines as much code as possible. However now, the JIT knows whether your class is final based on what classes get loaded in at runtime, and if you load a class to make the original one non-final-able, it un-inlines the methods and un-marks it as final.
What other smart micro-optimizations does the JVM or JIT do for you?
EDIT: I made this a community wiki; I'd like to collect these over time.
Upvotes: 6
Views: 974
Reputation: 99859
It's beyond impressive. All of these are things you can't
do in C++ (certainly to the same extent Java does). Keep in mind that early versions of Java started the "slow" reputation by not having these things, and we keep improving significantly over time. This is still a big research area.
Upvotes: 6
Reputation: 33936
Oracle has a wiki on Performance techniques used in the Hotspot JVM.
Upvotes: 4
Reputation: 533472
Java is smarter at inlining as it can
Upvotes: 3