Null pointer check elimination

Michael Koch konqueror@gmx.de
Sat Nov 12 09:09:00 GMT 2005


On Fri, Nov 11, 2005 at 02:24:12PM -0800, Anthony Green wrote:
> 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).

Great work!
In NIO (and probably in other areas too we often have code like this in
instance methods:
... do someting ...
return this;
In this case its known that this method never returns null. Perhaps it
would make sense to eliminate the null-checks for such cases too.
Cheers,
Michael
-- 
Escape the Java Trap with GNU Classpath!
http://www.gnu.org/philosophy/java-trap.html
Join the community at http://planet.classpath.org/


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /