gcj producing bad code
Eric Blake
ebb9@email.byu.edu
Sat Apr 6 08:22:00 GMT 2002
Nic Ferrier wrote:
>> GCJ is not compiling method calls quite right... it seems that all
> super invocations are done through invokespecial. invokespecial
> cannot be used when the target needs to be called through virtual
> dispatch however.
I'm not quite sure you said that right. Any call to super.method() is
required to compile to invokespecial (unless method is static, in which
case invokestatic is appropriate). By the way, in the case of
EnclosingClass.super.method(), it may require the assistance of an
accessor method to use invokespecial while still obeying access rules.
Consider this example, from the point of view of class C:
class A { void m() {} }
class B extends A {}
class C extends B { void foo() { super.m(); } }
class D extends C { void m() {} }
Here, the compiler must output the bytecode in class C for invokespecial
B.m(), and the VM is required to be able to resolve that at runtime to
be A.m(). If the compiler were to use invokevirtual in class C, you
would mistakenly invoke D.m(), not A.m(). And if the compiler were to
output invokespecial A.m() instead of B.m(), then recompiling B with an
added method m would fail binary compatibility rules.
--
This signature intentionally left boring.
Eric Blake ebb9@email.byu.edu
BYU student, free software programmer
More information about the Java
mailing list