JDK-8136820 : Generate better code for some Unsafe addressing patterns
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2015-09-21
  • Updated: 2015-11-12
  • Resolved: 2015-09-25
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
9 b89Fixed
Related Reports
Relates :  
Description
The main loop in:

    static int[] array;
    static long base;
    static int test1() {
        int res = 0;
        for (int i = 0; i < 100; i++) {
            long address = (((long) i) << 2) + base;
            res += UNSAFE.getInt(array, address);
        }
        return res;
    }

is compiled as:

0b0   B2: #     B2 B3 <- B1 B2  Loop: B2-B2 inner  Freq: 101.492
0b0     movslq  R9, R10 # i2l
0b3     salq    R9, #2
0b7     addq    R9, [R11 + #112 (8-bit)]        # long
0bb     addl    RAX, [R8 + R9]  # int
0bf     incl    R10     # int
0c2     cmpl    R10, #100
0c6     jl,s   B2       # loop end  P=0.990147 C=6732.000000

but could be compiled as:

0b2   B2: #     B2 B3 <- B1 B2  Loop: B2-B2 inner  Freq: 101.492
0b2     addl    RAX, [R8 + pos R10 << #2]       # int
0b6     incl    R10     # int
0b9     cmpl    R10, #100
0bd     jl,s   B2       # loop end  P=0.990147 C=6732.000000

base and array are loop invariant so array + base can be computed before the loop.
Comments
regarding lack of test case: this affects code generation in a subtle way and is very hard to observe from a java test case
25-09-2015