Gesticulations and Other Geekery » Page 'Inlining and optimization of methods in the JVM'

Inlining and optimization of methods in the JVM

I was just reminded of something that I often forget. So I thought I’d mention it here.

When the JVM (at least Sun’s HotSpot) optimizes a method it will only create one optimized version. So that if more than one type of object is passed to the function it will prevent inlineing and other optimization. This means you have to be conscious of what you allow to be passed into methods that should be optimized since the compiler will optimize for the lowerest common denominator of all input values.

This is standard for JITs. However as a side note, there are JITs that do produce multiple optimized versions for functions that are used in more than one context. One example is Psyco. Work on Psyco has stopped and new development is going into PyPy which is a fascinating (and kind of deranged) project.

Posted in JVM

Leave a comment