JDK-6946040 : add intrinsic for short and char reverseBytes
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: hs18
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_9
  • CPU: sparc
  • Submitted: 2010-04-21
  • Updated: 2011-03-08
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7 Other
6u21pFixed 7Fixed hs18Fixed
Description
Hi there,

I'd like to contribute this patch that implements the intrinsics for
Short/Character.reverseBytes (in C2):

 http://cr.openjdk.java.net/~rasbold/reversebytes/webrev.01/          (Patch 1)

(Thanks to Chuck for reviewing it and creating the webrev on my behalf.)

This adds new siblings for the existing Integer/Long.reverseBytes
intrinsics. Note: I did my best for the sparc implementation
(sparc.ad) but haven't been able to build or test it (I don't have
access to a sparc machine.)

An impact of this patch can be seen in the microbenchmark
jdk/test/java/nio/Buffer/SwapMicroBenchmark (which was written by
Martin) with an experimental patch that lets DirectByteBuffer use
those intrinsics (instead of simple Java implementations) on
non-native endian operations:

 http://cr.openjdk.java.net/~martin/webrevs/openjdk7/nioBits.java/
     (Patch 2)

This patch hasn't been checked in yet but is being worked on by Martin and Ulf.

The numbers from my measurements on x86 32 bit follow. Note the
numbers for BIG_ENDIAN.

----------Unmodified----------
Method                   Millis Ratio
swap char BIG_ENDIAN         64 1.000
swap char LITTLE_ENDIAN      31 0.492
swap short BIG_ENDIAN        75 1.176
swap short LITTLE_ENDIAN     31 0.496
swap int BIG_ENDIAN          45 0.711
swap int LITTLE_ENDIAN        8 0.125
swap long BIG_ENDIAN         72 1.131
swap long LITTLE_ENDIAN      17 0.277

----------Modified (with Patches 1 and 2)----------
Method                   Millis Ratio
swap char BIG_ENDIAN         44 1.000
swap char LITTLE_ENDIAN      31 0.709
swap short BIG_ENDIAN        44 1.004
swap short LITTLE_ENDIAN     31 0.708
swap int BIG_ENDIAN          18 0.423
swap int LITTLE_ENDIAN        8 0.180
swap long BIG_ENDIAN         24 0.544
swap long LITTLE_ENDIAN      17 0.400

The speedups are clearly non-trivial. The speedup for int/long is due
to the use of the existing Integer/Long.reverseBytes intrinsics in
DirectByteBuffer (Patch 2). The speedup for short/char is due to the
use of the new Character/Short.reverseBytes intrinsics in
DirectByteBuffer (Patch 1) and Patch 2.

Anyone willing to review it (Patch 1)?

Thanks,
Hiroshi

Comments
EVALUATION This is Hiroshi's patch for reverseShort and reverseChar intrinsics. I've redone the sparc implementation and fixed bugs in the original implementation as well. The existing versions were broken with implicit null checking since implicit null checks assume that the faulting load is the first instruction in the node but because of the way the memory was being handled it wasn't. The first instruction was actually an add so if an implicit null happened the JVM would die. The new code restricts these forms to use reg+reg addressing only so any address math is handled automatically. Tested with new test case and the original test case for the other intrinsics which I've moved from the closed repo to the open one. I also turned on the debug options in the adlc by default to make debugging adlc problems easier.
30-04-2010

EVALUATION http://hg.openjdk.java.net/jdk7/hotspot-comp/hotspot/rev/d7f654633cfe
26-04-2010