[9] RFR (XS): 8148518: Unsafe.getCharUnaligned() loads aren't folded in case of -XX:-UseUnalignedAccesses

Vladimir Ivanov vladimir.x.ivanov at oracle.com
Mon Feb 15 19:01:47 UTC 2016


Current Unsafe::getCharUnaligned Java implementation isn't fully 
optimized by C2: it never constant folds such loads from char fields.

C2 matches the types of a load and a location and does constant folding 
only if they match. For getCharUnaligned it sees a load of a short 
value, but the field is of type char.

The fix is to call Unsafe::getChar when offset is aligned. It doesn't 
matter what is used for unaligned case, so I decided to keep makeShort().

Testing: failing test, JPRT.

Best regards,
Vladimir Ivanov

PS: I don't update the test because it was refactored in Jigsaw [1]. To 
avoid unnecessary conflicts during merges, I filed an RFE [2] to adjust 
the test once the fix and Jake are integrated.


[2] https://bugs.openjdk.java.net/browse/JDK-8149844

More information about the core-libs-dev mailing list