Changed code generation in JDK 9
Aleksey Shipilev
shade at redhat.com
Tue Mar 13 09:46:41 UTC 2018
On 03/13/2018 10:39 AM, Vladimir Parfinenko wrote:
> Hi all,
>
> I am trying to investigate how C2 generates code for method:
>
> public static boolean invert(boolean x) {
> return !x;
> }
>
> I have found out that in JDK 8 it generates just "xor arg, 1" which does
> not properly handle random integers as booleans:
>
> 0x0000000004af4a8c: mov %edx,%eax
> 0x0000000004af4a8e: xor $0x1,%eax ;*ireturn
> ; - Inverter::invert at 9
> (line 3)
>
> In JDK 9 it performs truncation of argument to range {0, 1} and then
> "xor arg, 1".
>
> 0x000001d92cc9f0ac: test %edx,%edx
> 0x000001d92cc9f0ae: setne %al
> 0x000001d92cc9f0b1: movzbl %al,%eax
> 0x000001d92cc9f0b4: xor $0x1,%eax ;*ireturn {reexecute=0
> rethrow=0 return_oop=0}
> ; - Inverter::invert at 9
> (line 3)
>
> Full logs are available here:
> https://gist.github.com/cypok/24b2f30060958e10321f44784a4187c0
>
> So now I am trying to find the commit responsible for this change or
> motivational bug.
> Could anyone help me?
I would speculate it is related to boolean value normalization:
https://bugs.openjdk.java.net/browse/JDK-8161720
It is puzzling how would that leak to normal loads though.
-Aleksey
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20180313/355f1b0c/signature-0001.asc>
More information about the hotspot-compiler-dev
mailing list