JDK-8075052 : Autobox elimination hinders loop unrolling
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 9,10,11,12,13
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2015-03-12
  • Updated: 2021-02-04
  • Resolved: 2019-02-05
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 13
13 b07Fixed
Related Reports
Relates :  
Description
Consider 2 loops with Integer::<init> & Integer::valueOf:
@Benchmark
public void testIntegerValueOf(Blackhole bh) {
    int sum = 0;
    for (int idx = 0; idx < data.length; idx++) {
        sum += Integer.valueOf(data[idx]).intValue();
    }
    bh.consume(sum);
}

@Benchmark
public void testIntegerNew(Blackhole bh) {
    int sum = 0;
    for (int idx = 0; idx < data.length; idx++) {
        sum += new Integer(data[idx]).intValue();
    }
    bh.consume(sum);
}

$ java -jar bench_autobox.jar -jvmArgs '-XX:+UnlockExperimentalVMOptions -XX:+AggressiveUnboxing' '.*'

IteratorBench.testIntegerNew          3.130 �� 0.053  us/op
IteratorBench.testIntegerValueOf  12.546 �� 0.247  us/op

The problem is that VM doesn't unroll loop in testIntegerValueOf because it's not detected as counted.

Comments
Need ideal graph analysis.
12-03-2015

The numbers are measured with -XX:+AggressiveUnboxing. Otherwise, autobox elimination doesn't happen and testIntegerValueOf plummets to 32 us. The problem is that when elimination happens, it breaks counted loop detection logic.
12-03-2015

Try -XX:+ AggressiveUnboxing
12-03-2015

Tobias, as I asked before can you start looking on EA issues? Thanks!
12-03-2015

IteratorBench.testIntegerNew: 0x000000010f646990: add 0x10(%r10,%rcx,4),%r9d 0x000000010f646995: movslq %ecx,%r11 0x000000010f646998: add 0x14(%r10,%r11,4),%r9d 0x000000010f64699d: add 0x18(%r10,%r11,4),%r9d 0x000000010f6469a2: add 0x1c(%r10,%r11,4),%r9d 0x000000010f6469a7: add 0x20(%r10,%r11,4),%r9d ... 0x000000010f6469de: add 0x4c(%r10,%r11,4),%r9d 0x000000010f6469e3: add $0x10,%ecx 0x000000010f6469e6: cmp %ebx,%ecx 0x000000010f6469e8: jl 0x000000010f646990 IteratorBench.testIntegerValueOf: 0x000000010d4491e0: mov 0xc(%r12,%rdi,8),%r11d ;*getfield data ; - org.sample.IteratorBench$IntegerIterator::hasNext@8 (line 69) ; - org.sample.IteratorBench::sumIterator@8 (line 131) ; - org.sample.IteratorBench::testIterator@5 (line 159) 0x000000010d4491e5: mov 0xc(%r12,%r11,8),%r8d ; implicit exception: dispatches to 0x000000010d449345 0x000000010d4491ea: add %ecx,%r9d 0x000000010d4491ed: cmp %r8d,%r10d ;*synchronization entry ; - org.sample.IteratorBench$IntegerIterator::next@-1 (line 63) ; - org.sample.IteratorBench$IntegerIterator::next@1 (line 54) ; - org.sample.IteratorBench::sumIterator@17 (line 131) ; - org.sample.IteratorBench::testIterator@5 (line 159) 0x000000010d4491f0: jge 0x000000010d44925c 0x000000010d4491f2: mov %r10d,%ecx ;*aload_3 ; - org.sample.IteratorBench::sumIterator@16 (line 131) ; - org.sample.IteratorBench::testIterator@5 (line 159) 0x000000010d4491f5: mov 0xc(%r12,%r11,8),%r8d ; implicit exception: dispatches to 0x000000010d449335 0x000000010d4491fa: cmp %r8d,%ecx 0x000000010d4491fd: jge 0x000000010d4492d5 0x000000010d449203: mov %ecx,%r10d 0x000000010d449206: inc %r10d 0x000000010d449209: cmp %r8d,%ecx 0x000000010d44920c: jae 0x000000010d449287 0x000000010d44920e: shl $0x3,%r11 ;*synchronization entry ; - org.sample.IteratorBench$IntegerIterator::next@-1 (line 63) ; - org.sample.IteratorBench$IntegerIterator::next@1 (line 54) ; - org.sample.IteratorBench::sumIterator@17 (line 131) ; - org.sample.IteratorBench::testIterator@5 (line 159) 0x000000010d449212: mov 0x10(%r11,%rcx,4),%ecx ;*iaload ; - org.sample.IteratorBench$IntegerIterator::next@41 (line 65) ; - org.sample.IteratorBench$IntegerIterator::next@1 (line 54) ; - org.sample.IteratorBench::sumIterator@17 (line 131) ; - org.sample.IteratorBench::testIterator@5 (line 159) 0x000000010d449217: cmp $0xffffff80,%ecx 0x000000010d44921a: jl 0x000000010d4492b1 0x000000010d449220: cmp $0x7f,%ecx 0x000000010d449223: jg 0x000000010d4491e0 0x000000010d449225: mov %ecx,%ebp 0x000000010d449227: add $0x80,%ebp 0x000000010d44922d: cmp $0x100,%ebp ;*synchronization entry ; - org.sample.IteratorBench$IntegerIterator::next@-1 (line 63) ; - org.sample.IteratorBench$IntegerIterator::next@1 (line 54) ; - org.sample.IteratorBench::sumIterator@17 (line 131) ; - org.sample.IteratorBench::testIterator@5 (line 159) 0x000000010d449233: jb 0x000000010d4491e0 ;*aaload ; - java.lang.Integer::valueOf@21 (line 977) ; - org.sample.IteratorBench$IntegerIterator::next@42 (line 65) ; - org.sample.IteratorBench$IntegerIterator::next@1 (line 54) ; - org.sample.IteratorBench::sumIterator@17 (line 131) ; - org.sample.IteratorBench::testIterator@5 (line 159)
12-03-2015