Bug in self-compiled J2SDK

Tushar T tush at yahoo.com
Thu Nov 7 14:38:37 PST 2002


Thanks to Bernhard Stegmaier, a Gentoo user, a bug was discovered in the 
self compiled JDK. The bug cause incorrect calculations in Math 
functions (especially java.lang.Math.pow).

This is the program he coded that causes the bug to surface.
    public class TestPow {
        public static void main(String[] args) {
            double tmp = (1.0 - Math.sqrt(5.0))/2.0;
            double p = Math.pow(tmp, 10.0);
            System.out.println("tmp=" + tmp);
            System.out.println("p=" + p);
        }
    }
The result should be:
    tmp=-0.6180339887498949
    p=0.008130618755783355
If you get a different value, that indicates that there is a problem 
with the jdk you compiled.

He also determined that it is caused by optimizing flags used during the 
compilation of hotspot. The build uses -O3 by default which is the cause 
of the problem. Changing it to -O2 also causes problems (the build 
doesn't finish). The optimization flags need to be completely removed.

To avoid this bug, I had to change the optimiztion flags as follows:
    OTHER_CFLAGS="-march=i686 -fomit-frame-pointer -s -w"
    OTHER_CXXFLAGS="-march=i686 -fomit-frame-pointer -s -w"

Since the above flags don't affect the hotspot build, do the following 
to change the default flags that are hard coded into the makefiles:
    for i in hotspot/build/linux/makefiles/gcc.make \
        hotspot/build/solaris/makefiles/gcc.make \
        j2se/make/sun/image/generic/Makefile
    do
        chmod +w $i
        cp $i $i.orig
        sed -e "s:\-O3:\-march=i686 \-fomit\-frame\-pointer \-s \-w:g" 
$i.orig > $i
        chmod -w $i
    done

-- 
Tushar Teredesai
LFS ID: 1377
http://tushar.lfsforum.org/

-- 
Unsubscribe: send email to listar at linuxfromscratch.org
and put 'unsubscribe blfs-support' in the subject header of the message



More information about the blfs-support mailing list