Which optimizations does Hotspot apply?

Robert Stupp snazy at snazy.de
Wed Jan 22 22:37:16 UTC 2014

Is there any documentation available which optimizations Hotspot can perform and what "collecting a garbage" object costs?
I know that these are two completely different areas ;)

I was inspecting whether the following code
    for (Object o : someArrayList) { ... }
would be faster than
    for (int i=0, l=someArrayList.size(); i<l; i++) { Object o=someArrayList.get(i); }
for RandomAccessList implementations. The challenge here is not just to track the CPU time spent creating & using the iterator vs. size() & get() calls but also track GC effort (which is at least complicated if not impossible due to the variety of GC configuration options).

For example:
- Does it help Hotspot to declare parameters/variables as "final" or can Hotspot identify that?
- When does Hotspot inline method calls in general and getters/setters especially?

I think such a piece of documentation (just what Hotspot can do in which release) would be really helpful when someone tries to optimize code - want to say: the question is: "Is something worth to spend time on or is this special situation handled by Hotspot?"


More information about the core-libs-dev mailing list