JDK 9 build with GCC 6.1.1
Andrew Haley
aph at redhat.com
Tue Jun 28 07:58:40 UTC 2016
On 27/06/16 21:43, David Holmes wrote:
>
> Okay. So I know I was initially surprised we have code that can do:
>
> a->foo();
>
> when a is NULL, but that is because it is actually compiled as:
>
> foo(a);
Yes, it is.
> IIRC foo() has a "if (this != NULL)" check internally.
It doesn't, unless you write it in the body of foo().
> I'm kind of surprised that the compiler itself seems to think a->foo()
> implies a is not NULL.
That's what the standard says, and it's what GCC does.
> I also hope it either is extremely smart about this or else very
> conservative. Would want it to make a mess of this:
>
> if (init(&a) != NULL) {
> a->foo();
> }
> else {
> log(...);
> }
> if (a)
> a->bar();
This isn't enough to prove that a is non-null, so GCC won't eliminate
the test.
Andrew.
More information about the hotspot-dev
mailing list