bug in gcj constant folding

Konstantin L. Metlov metlov@fzu.cz
Thu May 27 14:22:00 GMT 1999

It seems there is a bug in a constant propagation (folding) code of gcj.
Sorry if it was already reported.

At the end of this message You'll find a test which shows a bug.

Unfortunately I was not able to run this test under latest egcs snapshot.
Compilation of recent libgcj failed for me with 
gcj: Internal compiler error: program jc1 got fatal signal 11 
when compiling class library to bytecode (gcj -C ... a lot of .java

Anyway gcj works great and runs my numerical simulation (physics) nearly
twice as fast as jdk with a JIT. This is my first simulation in java (all
others were in Fortran). I think java+gcj are great for numerical
computations when no special mathematical functions are required.

With the best regards,
        Konstantin L. Metlov.


public class GCJTest {

    public final static double TEST1=2  ;
    public final static double TEST2=2.0;
    public       static double TEST3=2  ;

    public static void main(String[] args) {
	double test1=TEST1/10;
	System.out.println("test1="+test1+" (should be 0.2, "+
			   "egcs-2.93.22 gives 0.0)");

	double test2=TEST2/10;
	System.out.println("test2="+test2+" (should be 0.2, "+
			   "egcs-2.93.22 gives correct answer)");

	double test3=TEST3/10;
	System.out.println("test3="+test3+" (should be 0.2, "+
			   "egcs-2.93.22 gives correct answer)");



[~/trials]$ ./GCJTest
test1=0.0 (should be 0.2, egcs-2.93.22 gives 0.0)
test2=0.2 (should be 0.2, egcs-2.93.22 gives correct answer)
test3=0.2 (should be 0.2, egcs-2.93.22 gives correct answer)

GNU/Linux, RedHat 6.0, kernel 2.2.9,

egcs-2.93.22 (1999-05-17)

My guess 
It seems that type of a constant (declared final in java) is determined by
the type of its initializer in gcj rather then by the explicit type in
declaration. This gives 2/10=0 integer division for test1, 2.0/10=0.2 for
test2, in the test3 the constant folding is not performed. It should be
simple to fix... but I have neither experience with gcc sources nor time.

More information about the Java mailing list