Unsafe.{get,put}-X-Unaligned performance

John Rose john.r.rose at oracle.com
Mon Mar 16 02:52:00 UTC 2015

On Mar 12, 2015, at 2:05 PM, Andrew Haley <aph at redhat.com> wrote:
> On 03/12/2015 07:29 PM, Peter Levart wrote:
>> What about the following variant (or similar with ifs in case switch is 
>> sub-optimal):
>>     public final long getLongUnaligned(Object o, long offset) {
>>         switch ((int) offset & 7)
> ...
> I tried that already, and it wasn't really any faster, and it won't
> vectorize nicely (vectorization was high on John's list).

...and switches are low on my list.  There are known performance problems with switch optimization.  If you can code the decision tree directly you are better off, even though an equivalent switch might present the decision tree more compactly or abstractly.  Ideally, a nice, clean switch should optimize to a decision tree that's as good or better as a handroll, but it doesn't.

For Unsafe, which is highly coupled to the platform, it's just fine to tie the details of the code to known optimization characteristics of the platform.

Andrew, thanks for going the extra mile and exploring the implementation alternatives so thoroughly.

— John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20150315/8792e9fe/attachment-0001.html>

More information about the hotspot-compiler-dev mailing list