This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Java: verification of interface types
- To: Bryce McKinlay <bryce at albatross dot co dot nz>
- Subject: Re: [PATCH] Java: verification of interface types
- From: Per Bothner <per at bothner dot com>
- Date: 14 Jan 2001 21:22:39 -0800
- Cc: gcc-patches at gcc dot gnu dot org, java-discuss at sources dot redhat dot com
- References: <m2zogtn07d.fsf@kelso.bothner.com><3A6251CB.2A6642D4@albatross.co.nz>
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/