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

Autobox elimination hinders loop unrolling

XMLWordPrintable

    • b07

      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.

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

              Created:
              Updated:
              Resolved: