This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Null pointer check elimination


Joe Buck wrote:
On Mon, Nov 14, 2005 at 01:43:38PM -0500, Michael N. Moran wrote:

Excuse me. IANALL nor am I a compiler expert but ...
what kind of optimization might be done with the information
that a reference *should* never be null? Especially within
the server code (the implementation of "int f(int& a)" in this case.)


There are several examples.  One is converting from a derived class
to a base class when there is multiple inheritance.  An offset must
be subtracted, unless it is a null pointer.

Why does it matter if the pointer is null? It is an error in the program if it uses the result, but the same is true for using null pointers. Do we try to do something if the reference is to another invalid address (e.g. 0x01)?

Do we want to hide the error by not crashing? Why not just do the
math and keep running? This seems like a run-time check that
is not a part of the C/C++ language as I understand it.

Another is the "delete" operator.  It must first check that the
argument is null; it only calls the underlying memory allocator if it is
not.

I have a similar problem with this.


Neither of these appear to be optimizations. As far as I know
there is nothing that requires an implementation to do this kind
of run-time checking even if we are dealing with pointers instead
of references.

Of course ... I *could* be wrong ;-)

Perhaps I am not understanding (most likely), but I am still
interested... Sorry if I'm just way off course.

--
Michael N. Moran           (h) 770 516 7918
5009 Old Field Ct.         (c) 678 521 5460
Kennesaw, GA, USA 30144    http://mnmoran.org

"So often times it happens, that we live our lives in chains
 and we never even know we have the key."
The Eagles, "Already Gone"

The Beatles were wrong: 1 & 1 & 1 is 1



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]