Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8075052

Autobox elimination hinders loop unrolling

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 9, 10, 11, 12, 13
    • Fix Version/s: 13
    • Component/s: hotspot
    • Subcomponent:
    • Resolved In Build:
      b07

      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.

        Attachments

          Activity

            People

            • Assignee:
              vlivanov Vladimir Ivanov
              Reporter:
              vlivanov Vladimir Ivanov
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: