JDK-6853717 : jdk6u14+amd64: loop counter wrong in for loop
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 6u14
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2009-06-22
  • Updated: 2012-09-04
  • Resolved: 2012-09-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8Resolved
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) 64-Bit Server VM (build 14.0-b16, mixed mode)


FULL OS VERSION :
Linux server 2.6.29-gentoo-r5 #3 SMP PREEMPT Sat May 30 18:31:37 CEST 2009 x86_64 AMD Athlon(tm) 64 X2 Dual Core Processor 4600+ AuthenticAMD GNU/Linux


A DESCRIPTION OF THE PROBLEM :
x is supposed to be identical for both loops. And is if  max = Integer.MAX_VALUE-1:

238
2147483646
268
2147483646

But it's not if max=Integer.MAX_VALUE-0:

284
2147483635
205
2147483632

This appears to be a bug in jdk6u14 on amd64 only.


public class Loop
{
        public static void main( String[] args )
        {
                int max = Integer.MAX_VALUE;
                long x=0l;
                long t0,t1;

                t0 = System.currentTimeMillis();
                for(int i = 0; i < Math.max( 0,max); i++){
                                x++;
                }

                t1 = System.currentTimeMillis();

                System.out.println(t1-t0);
                System.out.println(x);

                x =0;
                t0 = System.currentTimeMillis();
                for(int i = 0, a = Math.max(0,max); i < a; i++){
                        x++;
                }

                t1 = System.currentTimeMillis();
               
                System.out.println(t1-t0);
                System.out.println(x);
               
        }
}



THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Did not try

THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Did not try

REPRODUCIBILITY :
This bug can be reproduced always.

Comments
EVALUATION I was not able to reproduce the problem with 6u14. Both reported results with MAX_VALUE-0 are incorrect, they should be 2147483647. There was problem (fixed in jdk7) with conuted loop limit Integer.MAX_VALUE. So I am closing this as duplicate of that.
04-09-2012