interface dispatch

Per Bothner per@bothner.com
Sat Oct 23 17:43:00 GMT 1999


Godmar Back <gback@cs.utah.edu> writes:

> What are union types?  I assume you're suggesting a verifier design
> where the verifier keeps track the union of possible types that can be
> in a given local variable or on the operand stack at any given time.
> In this case, you could check that every type in the union would
> implement the interface.

Loosely.  The problem is that verifying requires calculating the
"Merged type" that is the "least common supertype".  That is easy
to define for single inheritance, but we can't do it for multiple
inheritance.   Sun's solution is to define Object as the merged
type, and doing the checking at run-time.

The problem is:

interface A { ... }
interface B { ... }
interface X implement A, B { .. } 
interface Y implement A, B { .. } 
class W implements X, Y { ... }
W w = new W();
X x = w;  Y y = w;
A a;
if (test) a = x; else a = y;

In the bytecode, we don't know the type of a;  it is just a
"local variable".  The verifier has to give it the intersction
of X and Y.  That is the union of A and B.  (I don't know if
it is better to represent this as intersect(X,Y) or union(A,B).)
A later instruction may do an interface call on an A method using a.
At that point, the type collapses to A.

> On another note regarding the size of the ioffset tables, how would you 
> deal with
> 	invokeinterface	InterfaceMethodRef(InterfaceType, "equals")
> instructions?
> 
> If you adopted the assumption that java.lang.Object is an interface

Why?  Object is a class.  My assumption was that class inheritance
and virtual calls would be handled using a simpler and faster scheme
than what you use for interfaces.
-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/~per/


More information about the Java mailing list