RFR: JDK-8283326: Implement SafeFetch statically

Anton Kozlov akozlov at openjdk.java.net
Tue Apr 12 10:53:28 UTC 2022


On Tue, 12 Apr 2022 09:43:41 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

>> I'm surprised this would work. Can you really specify the same register as load destination and as load source?
>
> Ah, it seems to work. You live and learn :)

Yes, on arm32/64 it would not work if the instruction uses a register as a target and write-back, like `ldr r0, [r0, 4]!`, otherwise it's OK. AFAIR, it's also OK on ppc. 

As a reference, I've checked the output of gcc/clang, both don't use the extra register, so the argument regarding performance looks valid :) Not insisting on fixing, this is indeed minor.


anton at mercury:/tmp$ cat test.c
long test(long* addr) {
	return *addr;
}
anton at mercury:/tmp$ aarch64-linux-gnu-gcc --version
aarch64-linux-gnu-gcc (GCC) 11.2.0
anton at mercury:/tmp$ aarch64-linux-gnu-gcc -c -O3 -o test.o test.c
anton at mercury:/tmp$ aarch64-linux-gnu-objdump -d test.o

0000000000000000 <test>:
   0:	f9400000 	ldr	x0, [x0]
   4:	d65f03c0 	ret

-------------

PR: https://git.openjdk.java.net/jdk/pull/7865


More information about the hotspot-dev mailing list