8148518: Unsafe.getCharUnaligned() loads aren't folded in case of -XX:-UseUnalignedAccesses
authorvlivanov
Wed, 17 Feb 2016 18:49:38 +0300
changeset 36121 ba46027ccfb5
parent 36120 192b3ccf06ba
child 36125 bcdde35f856f
8148518: Unsafe.getCharUnaligned() loads aren't folded in case of -XX:-UseUnalignedAccesses Reviewed-by: kvn, shade
jdk/src/java.base/share/classes/jdk/internal/misc/Unsafe.java
--- a/jdk/src/java.base/share/classes/jdk/internal/misc/Unsafe.java	Mon Feb 15 20:27:12 2016 +0300
+++ b/jdk/src/java.base/share/classes/jdk/internal/misc/Unsafe.java	Wed Feb 17 18:49:38 2016 +0300
@@ -1159,7 +1159,12 @@
     /** @see #getLongUnaligned(Object, long) */
     @HotSpotIntrinsicCandidate
     public final char getCharUnaligned(Object o, long offset) {
-        return (char)getShortUnaligned(o, offset);
+        if ((offset & 1) == 0) {
+            return getChar(o, offset);
+        } else {
+            return (char)makeShort(getByte(o, offset),
+                                   getByte(o, offset + 1));
+        }
     }
 
     /** @see #getLongUnaligned(Object, long, boolean) */