Null pointer check elimination

Anthony Green green@redhat.com
Fri Nov 11 22:24:00 GMT 2005


Our compiler inlines many null pointer tests because the language
requires that we throw NullPointerExeceptions in certain cases that can
only be detected through explicit tests.

What's frustrating is that there are many cases where we're testing the
nullness of a function return value that we know can never be null.  For
instance, the result of string appends can never be null.  Neither can
object allocations.

The attached experimental patch detects one special instance of a
non-null function result (gnu.gcj.runtime.StringBuffer.append()), and
marks it as being non-null.  GCC's value range propagation code then
magically eliminates any redundant null pointer checks.

Eventually we should manually mark certain function DECLs as
not-returning-null instead of my kludgy test for this one case.  I don't
know if/when I can get to that.  Perhaps somebody else can take it from
here.

In any case, here's a patch Diego and I came up with.  It will eliminate
null-pointer checks related to the string concatenation operator (foo =
"blah" + bar).

(Thanks Diego!)

AG


-------------- next part --------------
A non-text attachment was scrubbed...
Name: 20051111.patch
Type: text/x-patch
Size: 2530 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java/attachments/20051111/2fd05a7a/attachment.bin>


More information about the Java mailing list