GCJ Optimizer troubles: testcase

Thomas Aeby aeby@graeff.com
Thu Aug 12 14:34:00 GMT 2004


On Tue, 2004-08-10 at 22:27, Bryce McKinlay wrote:
> Could you post a full test case please? That behaviour would surprise 
> me, too.

Ok, here it is:

public class testcase {

private static class encapsulatedInt {
    int value;

    public encapsulatedInt( int i ) {
        value = i;
    }

    public synchronized void increment() {
        value++;
    }

    public int intValue() {
        return value;
    }
}

public static void main( String args[] ) {
    encapsulatedInt tester = new encapsulatedInt(0);
    System.out.println( "value: " + tester.intValue() );
    tester.increment();
    System.out.println( "value: " + tester.intValue() );
}
}

Compiled with GCJ 3.4.0 (with <3.4 everything seems to work
as expected):

	$ gcj -O -o testcase --main=testcase testcase.java
        $ ./testcase
	value: 0
	value: 0
	$ gcj -o testcase --main=testcase testcase.java
	$ ./testcase
	value: 0
	value: 1
	$ gcj --version
	gcj (GCC) 3.4.0
	[...]

Now, isn't that cool?

Best regards,
Tom
--------------------------------------------------------------------
Thomas Aeby, Kirchweg 52, 1735 Giffers, Switzerland, aeby@graeff.com
Voice:(+41)26 4180040                       PGP public key available
--------------------------------------------------------------------




More information about the Java mailing list