Bug 303096

Summary: compiled class (eclipse) runs with error (compiled with JDK it runs without)
Product: [Eclipse Project] JDT Reporter: Stefan2110
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED NOT_ECLIPSE QA Contact:
Severity: major    
Priority: P3 CC: Olivier_Thomann, Stefan2110
Version: 3.6   
Target Milestone: 3.6 M6   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Stefan2110 CLA 2010-02-17 13:08:23 EST
Build Identifier: I20100129-1300 (win64)

When I compile a small test class with eclipse and then run it with JVM 1.6.0_18 64Bit there will be an incorrect result. Running it with JVM 1.6.0_18 32Bit to get the proper result.

But When the class is compiled directly with the jdk 1.6.0_18 x64 you get the same (right) result on x64/x32 JVM.

Hava a look at
http://forums.sun.com/thread.jspa?threadID=5427954 
there i explained it too!

Here is the class
public class problem64Bit
{
 
	/**
	 * @param args
	 *            Arguments
	 */
	public static void main(final String[] args)
	{
		booleanInvert(Integer.MAX_VALUE);
		booleanInvert(Integer.MAX_VALUE - 1);
	}
 
	private static void booleanInvert(final int max)
	{
		boolean test1 = false;
		boolean test2 = false;
 
		for (int i = 0; i < max; i++)
		{
			test1 = !test1;
		}
 
		for (int i = 0; i < max; i++)
		{
			test2 ^= true;
		}
 
		if (test1 != test2)
		{
			System.out.println("ERROR: Boolean invert\n\ttest1=" + test1
					+ "\n\ttest2=" + test2);
		} else
		{
			System.out.println("Everything as it should be!");
		}
	}
}

Both loops should result in the same boolean state - but when the loop iterates over INTEGER.MAX_VALUE then the compiled class (compiled with eclipse 3.6 x64 or 3.5 x64) will result in a different state.

Here is the output from the JVM 1.6.0_18 x64
ERROR: Boolean invert
	test1=true
	test2=false
Everything as it should be!

Reproducible: Always
Comment 2 Olivier Thomann CLA 2010-02-17 13:16:25 EST
I'll investigate.
Comment 3 Olivier Thomann CLA 2010-02-17 14:12:13 EST
If I run the class file compiled by Eclipse using:
java version "1.6.0_13"
Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
Java HotSpot(TM) 64-Bit Server VM (build 11.3-b02, mixed mode)

I do get the expected output.

Could you please try to run your test case on the VM you have and disable the JIT ?

I'll try to retrieve the VM that you are using, but so far it looks like a VM issue.
Comment 4 Olivier Thomann CLA 2010-02-17 14:43:07 EST
This looks like a VM issue:

...>\Test\jdk\jdk6_18\bin\java X
ERROR: Boolean invert
        test1=true
        test2=false
Everything as it should be!

...>\Test\jdk\jdk6_18\bin\java -Djava.compiler=none X
Everything as it should be!
Everything as it should be!

So no JIT over the same .class file works.
Differences in the javap can be explained by the way the for loop is generated.
Nothing noticable on that side.

Closing as NOT_ECLIPSE.
Comment 5 Olivier Thomann CLA 2010-02-17 14:43:38 EST
Note that 1.6.0_13 64Bit VM works fine.
Comment 6 Frederic Fusier CLA 2010-03-08 13:37:46 EST
Verified