Compiler errors while parsing bytecode files.

Godmar Back gback@cs.utah.edu
Mon Oct 18 18:32:00 GMT 1999


We just encountered and fixed that problem in Kaffe.
Basically, all other javac compilers except jikes generate bad bytecode
here. Gilad Bracha from Sun told me that they'll fix javac soon.
Specifically, if you're asked to invoke a method "a" on an interface "B"
via INVOKEINTERFACE, you'll have to check whether "a" is defined in any 
interface B implements. If, at the source level, "B" extends "A", 
"B" will implement "A" at the bytecode-level. This is the example given 
below.
Other javac compilers would "see" that "a" was actually defined in "A"
and generate `INVOKEINTERFACE InterfaceMethodRef("A", "a")' instructions. 
However, this was wrong, for various reasons.
To make matters more complicated, the correct code to generate for
`INVOKEINTERFACE InterfaceMethodRef("B", "a")' is to check whether the 
run-time object indeed implements B, followed by the dispatch to "a".
To add another twist: the correct bytecode for
	((B)t).equals()
is
	INVOKEINTERFACE InterfaceMethodRef("B", "equals")
and not
	INVOKEVIRTUAL MethodRef("B", "equals")
or
	INVOKEVIRTUAL MethodRef("java.lang.Object", "equals")
even if neither "B" nor "A" have a method named "equals".
Implementation also requires an instanceof check followed by
the dispatch.
	- Godmar
>> Andrew Haley wrote:
>> > > From: Glenn Chambers <GChambers@provsol.com>
> > > Date: 1999年9月27日 13:26:37 -0400
> > >
> > > I get the following error messages while attempting to compile the
> > > Rhino javascript interpreter with the current CVS tip.
> > >
> > > The source code has a bunch of 1.1-isms in it, so a source compile
> > > isn't currently possible.
> > >
> > > What's my next step?
> >
> > Firstly, what bytecode compiler are you using? It might be that it's
> > generating illegal bytecode.
>> As a general warning, I've noticed several cases where bytecode produced
> by Jikes will not compile with gcj, while bytecode produced by javac or
> "gcj -C" from exactly the same source works fine. The jikes-generated
> bytecode does, however, seem to work fine in the JDK VM.
>> Here's an example:
>> public interface A
> {
> public void a();
> }
>> public interface B extends A
> {
> public void b();
> }
>> public class Test implements B
> {
> public static void main(String args[])
> {
> Test t = new Test();
> B a = (B) t;
> a.a();
> }
>> public void a()
> {
> System.out.println("A");
> }
>> public void b()
> {
> System.out.println("B");
> }
> }
>> [bryce@reason abstract]$ jikes *.java
> [bryce@reason abstract]$ java Test
> A
> [bryce@reason abstract]$ gcj *.class -o test --main=Test
> Test.java: In class `Test':
> Test.java: In method `main(java.lang.String[])':
> Test.java:7: Class 'B' has no method named 'a' matching signature '()V'
> gcj: Internal compiler error: program jc1 got fatal signal 11
> [bryce@reason abstract]$ javac *.java
> [bryce@reason abstract]$ gcj *.class -o test --main=Test
> [bryce@reason abstract]$ ./test
> A
>> I'm using jikes Version 0.55 (28 Jul 99).
>> regards
>> [ bryce ]
>


More information about the Java mailing list

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