C++ and Java CNI: Check Java references

Mark Mitchell mark@codesourcery.com
Wed Apr 25 10:02:00 GMT 2001

>>>>> "Andrew" == Andrew Haley <aph@cambridge.redhat.com> writes:

    Andrew> Anyway, it's just dawned on me that this solution could
    Andrew> never work: the `this' pointer in C++ isn't a smart

That's because `this' should never be NULL.  (Really `this' should
have reference type, not pointer type, but nobody realized this until
too late in the game.)

You'll have already checked for the non-NULLness of `this' before
calling the member function.  For example, if you have:
  JavaPointer<Foo> f;


You don't need to check `this' in `Foo::bar'; you'll have checked at
the call-site.

If you didn't get to Foo::bar via a pointer, like this:

  Foo f;

then there's no point in checking the `this' pointer in that case
either; you called it directly on an object.  

So, you magically do the right thing.

I think this shows that there will be a huge efficiency win over the
patch as posted: you'll not check all the references through `this'
because `this' is always known to be non-NULL.
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

More information about the Java mailing list