JDK-8075136 : Unnecessary sign extension for byte array access
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 8,9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2015-03-13
  • Updated: 2019-10-07
  • Resolved: 2015-03-23
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 9 Other
9 b64Fixed openjdk8u232Fixed
Related Reports
Blocks :  
Relates :  
Description
C2 adds an unnecessary sign extension while compiling a byte array access.

  public static byte[] byteArr;
    
  public static byte accessByte(int index) {
    return byteArr[index];
  }

The generated code contains:

  0x00007f76f4747208: movslq %esi,%r11
  0x00007f76f474720b: movsbl 0x10(%r10,%r11,1),%eax

Where the 'movslq' instruction is not necessary because we emit range checks guaranteeing that index %esi is not negative.

For a char array access no such sign extension is created:

  public static char[] charArr;
    
  public static char accessChar(int index) {
    return charArr[index];
  }

  0x00007fab3916b188: movzwl 0x10(%r10,%rsi,2),%eax
Comments
Fix Request (8u) This improves generated code around byte accesses. Patch applies cleanly to 8u, barring aarch64 parts that are missing in current 8u. They were in aarch64-port/jdk8u-shenandoah for a while now (http://hg.openjdk.java.net/aarch64-port/jdk8u-shenandoah/hotspot/rev/471988878307), and thus know it is good. Patched build passes tier1-like test suite. Targeted microbenchmarks show generated code is improving with the patch: movslq before byte array access is indeed gone.
19-07-2019

This is because we only have matching rules to fold the corresponding ConvI2LNode in the following case: match(AddP (AddP (DecodeN reg) (LShiftL (ConvI2L idx) scale)) off); This applies to charAccess [1] but not to byteAccess [2] because the byte array access does not require a scaling factor. [1] https://bugs.openjdk.java.net/secure/attachment/26108/accessChar.png [2] https://bugs.openjdk.java.net/secure/attachment/26107/accessByte.png
13-03-2015