Skip to main content

Does the HotSpot JIT compiler optimize ... ?

1 reply [Last post]
davekriewall
Offline
Joined: 2005-08-23
Points: 0

I often encounter code that I think HotSpot should be able to optimize, but I have no way of easily finding out (short of trying to write a benchmark). For example:

- are native calls (like java.nio.ByteBuffer.put() and get() methods) candidates for inline optimization?

- to get a list of enumerations for a particular enum, you call getEnumConstants() which evidently returns a clone of the original enum constant array [a late addition to 1.5 to prevent the original array from possibly being changed]. If you only want to read a value out of the array, the clone is wasted effort, since the only reference to the cloned array is immediately discarded. Is the JIT compiler smart enough to see that the cloned array is only used to access one element, so it can discard the call to clone() and just use the original? [Apparently not, according to a performance talk I heard at 2005 JavaOne.]

My bigger question is, is there a document, FAQ, mailing list, or forum for finding out if a particular JIT (on a particular platform) performs a certain optimization such as the examples above? Or, is it possible to see the optimized code generated by a JIT?

TIA,
-Dave

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tackline
Offline
Joined: 2003-06-19
Points: 0

ByteBuffer.put/get eventually call intrinsics sun.misc.Unsafe methods.

If you download the Mustang source, hotspot/src/share/vm/oops/memoryOop.cpp maps from Java to intrinsic names. hotspot/src/share/vm/opto/library_call.cpp is the business end.

If the bytecode of the calling method is too long, then HotSpot will not inline methods. To inline intrisics used by NIO into your code requires multiple levels of inlining. Therefore, keep your inner loops in short methods.