[PATCH] Java: verification of interface types

Per Bothner per@bothner.com
Sun Jan 14 21:17:00 GMT 2001


Bryce McKinlay <bryce@albatross.co.nz> writes:
> Per Bothner wrote:
>> > Sun catches type-unsafe interface
> > calls at run-time by type-checking at each invokeinterface call.
>> That is surprising. Maybe it actually does this check once when the
> invokeinterface is compiled by the JIT.

That is not my impression - I think it really is tested at run-time.
I believe they implement invokeinterface using a caching scheme:
Check if the receiver matches that saved in the cache; if so call
the cached method; otherwise, do a search. The type cheking is done
as a side effect of the search.
> > I actually don't know if we catch this in Gcj after the constant-type
> > inteface method calls have been implemented.
>> We don't. Its definatly something that should be sorted out at compile time,
> for native compiled classes. For bytecode maybe it needs to be done at runtime
> in order to conform to the Java ABI rules.

I don't think we need to. If we work out a verification algorithm
that works in jc1, the same algorithm can be used I think for a
run-time verifier. Even though our verifier might reject a program
that Sun's verifier might allow, I don't think such a program could
be "correct" in any sense.
> Perhaps I dont really understand the problem here, but whats wrong with
> interface_of_p () ? When compiling/verifying bytecode, it is difficult to
> determine the compile-time type of the variable you're invoking the interface
> method on?

Yes. That's what makes verification difficult - you don't know the
compile-time types of the variables. Consider:
interface A { }
interface B { }
interface C extends A, B { };
interface D extends A, B { };
class E implements A, B { };
A a;
B b;
C c;
if (b) c = a;
else c = b;
Consider determining the type of c at this point in the generated
bytecode. All we know if c can be either A or B, so it must have a
type that is the intersection of A and B. But it could be any of C,
D, or E or any other class or interface that inherits from both A and
B. We won't know which until the value in c is further refined.
-- 
	--Per Bothner
per@bothner.com http://www.bothner.com/~per/


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /