Details
-
Enhancement
-
Resolution: Fixed
-
P4
-
9, 10, 11, 12, 13
-
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.
@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
Issue Links
- relates to
-
JDK-8261137 Optimization of Box nodes in uncommon_trap
-
- Closed
-