performance issue with alignment-like checks
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Wed May 27 21:27:57 UTC 2020
This issue was already known to Vlad - not sure if a bug has been
submitted or not.
Currently Hotspot fail to hoist alignment-like checks (with either mod
operator or bitwise-and) outside of loops. Simple benchmark:
|static final int ALIGN_MASK = 3; static final int ALIGN = ALIGN_MASK +
1; @Benchmark @OutputTimeUnit(TimeUnit.MICROSECONDS) public int
align_loop() { int sum = 0; for (int i = 0 ; i < ELEM_SIZE ; i+= ALIGN)
{ if ((i & ALIGN_MASK) != 0) { throw new AssertionError(); } sum += i; }
return sum; } @Benchmark @OutputTimeUnit(TimeUnit.MICROSECONDS) public
int alignno_loop() { int sum = 0; for (int i = 0 ; i < ELEM_SIZE ; i+=
ALIGN) { sum += i; } return sum; } |
Result:
|Benchmark Mode Cnt Score Error Units PanamaPointer.align_loop avgt 30
12.589 ? 0.137 us/op PanamaPointer.alignno_loop avgt 30 7.443 ? 0.088 us/op |
I realized that this issue is the main offender behind performance
issues in code using MemoryAddress::addOffset in tight loops. Numbers
with Graal/JVMCI seem more consistent:
|Benchmark Mode Cnt Score Error Units PanamaPointer.align_loop avgt 30
7.052 ? 0.067 us/op PanamaPointer.alignno_loop avgt 30 6.988 ? 0.041 us/op |
The priority of this should be raised - it is probably a relatively
low-hanging fruit to fix, and it could help fixing our woes with
alignment checks in Panama.
Maurizio
More information about the panama-dev
mailing list