interface dispatch

Godmar Back gback@cs.utah.edu
Fri Oct 22 09:01:00 GMT 1999


> 
> If by "compile-time" you mean when bytecode is compiled to native
> code (either by gcj or a jit), then it depends on your verifier.
> It certainly is not determined by the verifier as described in
> the JVM spec, nor by Sun's verifier, nor by the verifier in Gcj.
> However, I do believe that can be verified by a smarter
> verifier that uses union type;  as a proof of concept, I believe
> Kresten Krab Thorup's verifier does use union types.
> 

Well, I certainly won't mind if you're right on this issue.

I was concerned about cases like
	((Interface_Type)x).interfaceMethod();

but wrongly so, because this is compiled into

	checkcast 	Interface_Type
	invokeinterface (Interface_Type, interfaceMethod)
and it's easy to see for a verifier that the object implements
the interface.

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.

So if this is true, then globally unique class iindices aren't needed 
for interface dispatch and I don't have to change my code, about which 
I'm rather happy.  

This would not solve the problem of checking for an interface type 
in checkcast though, IMO, because here the verifier obviously can't 
help you.


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
that's implemented by every class, you'd all the sudden have globally
unique iindices because Object's ioffset table would have entries for
every single class in the system.  I believe a good thing to do
in this case would be to transform the code and emit the equivalent
of
	checkcast	InterfaceType
	invokevirtual	java.lang.Object, "equals"
instead.  That should be equivalent, I think.

	- Godmar



More information about the Java mailing list