Kaffe's java compiler needs an update

Dalibor Topic kaffe@rufus.w3.org
Mon, 24 Jul 2000 12:44:54 +0200


Hi,

I've spent some time chasing a bug around which in the end turned out
to be a kjc 1.4D bug. It doesn't appear with kjc 1.4F, so I'd recommend
upgrading Kaffe's kjc.jar to 1.4F.

The bug in question shows up when you compile Klasses.jar with Kaffe's
kjc and try to read() a file until EOF. It won't work, because
java.io.Reader read() method returns 65535 instead of -1 on EOF. kjc
1.4D gets confused about the type of -1 (int/char) at line 43 in
java/io/Reader.java:

	        return read(single, 0, 1) < 0 ? -1 : single[0];

Here's a small test program that exposes the bug:

public class Main {
    private static int cnt = 0;
    private static char [] c = new char[1];

    public static void main(String [] args) {
	System.out.println(test());
    }

    public static int test() {

	c[0] = 'X';

	return cnt % 2 == 0 ? -1 : c[0];
    }
}

Running JDK 1.1.8 javap on the kjc 1.4D generated class file results in following
output for method test():

Method int test()
   0 getstatic #30 <Field char c[]>
   3 iconst_0
   4 bipush 88
   6 castore
   7 getstatic #32 <Field int cnt>
  10 iconst_2
  11 irem
  12 ifne 18
  15 ldc #33 <Integer 65535>
  17 ireturn
  18 getstatic #30 <Field char c[]>
  21 iconst_0
  22 caload
  23 ireturn

which is clearly wrong (byte 15 should be iconst_m1).

kjc 1.4F generates the iconst_m1 instead.

Although you could give a hint to kjc 1.4D how to compile the above
example properly, by casting c[0] to int, I propose to update the
compiler. Unless, of course, there are other issues that prevent us
from doing so.

Bye,

Dalibor Topic

__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com