C++ patch: Add support for calling Java interfaces

Bryce McKinlay bryce@albatross.co.nz
Tue Mar 20 20:11:00 GMT 2001

The following patch adds partial support for Java interfaces to the
C++ compiler. This means that cases like the following are now
possible with CNI:

// Java
interface Iface
  void a();

public class Impl implements Iface
  native void callA(Iface i);

  public void a()
    System.out.println ("a ok");

  public static void main(String[] args)
    Impl i = new Impl();

// C++
#include <Iface.h>
#include <Impl.h>

Impl::callA (Iface i)

Until now, code like this would compile but tended to crash the java
runtime, because C++ would attempt a normal vtbl method lookup which
Java does not use for interface dispatch.

C++ doesn't yet understand inheritence among Java interfaces, and gcjh
does not attempt to express this in the generated header file -
currently a cast will be needed in order to call a method declared in
a superinterface.  To support this properly might, I suspect, require
more extensive changes to C++ to ensure it remove interface types from
consideration when calculating vtable offsets for non-interface calls.
Calls to java.lang.Object methods are handled correctly.

I would also like to commit this to branch, because it fixes at least
one crash bug in the java runtime (in the File.list(FilenameFilter)
method) and will allow me to finish a complete Java 2 implementation
of the File class without ugly kludges. It doesn't touch much code and
ought to not break anything.

C++ testsuite looks ok. Bootstrapped i686-linux. OK to commit?


  [ bryce ]

More information about the Java-patches mailing list