CNI vs interfaces

Bryce McKinlay bryce@albatross.co.nz
Wed Aug 2 20:23:00 GMT 2000


Tom Tromey wrote:

> Bryce> One way might be to make a dummy "JInterface" C++ class and
> Bryce> have gcjh make interfaces inherit from this in addition to
> Bryce> java.lang.Object. Would this work? Or is there a better option?
>
> One option would be to treat interfaces via real multiple inheritance,
> and change g++ to generate the appropriate call for Java objects whose
> class uses MI.  This might be hairy.
>
> Another choice would be an attribute on the class.  This is probably
> more straightforward, but also more hacky.

I'm thinking an __attribute__ (also suggested by Glenn Chambers) would
work nicely. The C++ compiler already recognises a "com_interface"
attribute, so a "java_interface" would be keeping consistent with that.

We'll still need to use multiple inheritance, as interfaces can have
multiple superinterfaces (currently gcjh doesn't "see" these). Also need
to make sure that the compiler allows assignment from a class field to a
compatible interface field.

Is the vtable lookup emitted by C++ for a java.lang.Object method call
going to work if the compiler sees multiple inheritance (I have no idea
how MI dispatch works)?

regards

  [ bryce ]




More information about the Java mailing list