Implicit null-check in hot-loop?
Benedikt Wedenik
benedikt.wedenik at theobroma-systems.com
Wed May 27 10:27:46 UTC 2015
Hey there!
I wrote a small Fibonacci-Micro-Benchmark to examine the generated assembly (eg. loop unrolling, pipeline, and so on). This is the relevant Java Code:
2 private static long fib(long n) {
3 if(n == 0) {
4 return 0;
5 }
6 if(n == 1) {
7 return 1;
8 }
9
10 long res = 3;
11 long imm0 = 0;
12 long imm1 = 1;
13
14 for(long i = 1; i < n; ++i) {
15 res = imm0 + imm1;
16 imm0 = imm1;
17 imm1 = res;
18 }
19 return res;
20 }
In the hot-loop there is this “ldr” which looked a little “strange” at the first glance.
I think that this load is a null-check? Is that the case?
If so, why does HotSpot needs to check for null in every iteration step?
I also investigated the generated code on x86 which is quite similar, but instead of a load, they are
using the “test”-instruction which performs an “and” but only sets the flags discarding the result.
Is there any similar instruction available on aarch64 or is this already the closest solution?
Here the relevant assembly:
541 0x0000007fa4188a4c: adrp x23, 0x0000007fb5580000
542 ; {poll}
543 0x0000007fa4188a50: b 0x0000007fa4188a74
544 0x0000007fa4188a54: nop
545 0x0000007fa4188a58: nop
546 0x0000007fa4188a5c: nop
547 0x0000007fa4188a60: add x19, x19, #0x1 ;*ladd
548 ; - Fib::fib at 52 (line 14)
549
550 0x0000007fa4188a64: add xlocals, xbcp, xdispatch
551 ; OopMap{off=104}
552 ;*goto
553 ; - Fib::fib at 55 (line 14)
554
555 0x0000007fa4188a68: ldr wzr, [x23] ;*goto
556 ; - Fib::fib at 55 (line 14)
557 ; {poll}
558 0x0000007fa4188a6c: mov xbcp, xdispatch
559 0x0000007fa4188a70: mov xdispatch, xlocals ;*lload
560 ; - Fib::fib at 29 (line 14)
561
562 0x0000007fa4188a74: cmp x19, xesp
563 0x0000007fa4188a78: b.lt 0x0000007fa4188a60 ;*ifge
Btw - why does HotSpot not unroll this loop?
Thanks and best regards,
Benedikt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20150527/4ed50989/attachment.html>
More information about the hotspot-compiler-dev
mailing list