Name: mc57594 Date: 11/30/99
C:\JAVA\Jdk13Bug>java -version
java version "1.3beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
Java(TM) HotSpot Client VM (build 1.3beta-O, mixed mode)
The JDK13beta1 Java HotSpot Client VM changes evaluation order
==============================================================
Using JDK13 beta 1 for Windows (W98, 128MB RAM, AMD-K62 350MHz), I isolated a
case
where optimized code evaluates in a different order than non-optimized code,
changing the result and breaking program logic.
The problematic statement is
aiResult[i] = (ai[i] - iCarry * iLoad) * iMultiplier + (iCarry = ai[++i] /
iLoad);
where normally the value of iCarry is used first, then recalculated and used
again.
After a certain number of passes through that code however, the recalculated
value is used twice. This should not occur
As an example (try the code linked to below) I produce a log file of a case
where
the error occured with the following entry values:
int[] ai = {3, 622, 7020800};
int[] aiResult = ai;
int iCarry = 0;
int iLoad = 100000;
int iMultiplier = 100;
int i = 1;
The correct exit values are then:
iCarry = 70; // 7020800/100000
aiResult[1] = 62270; // (622-0*100000)*100+(70)
i = 2;
Which are obtained for the first 67 passes through the complete code (main
method),
and for all passes with the JIT turned off (java -Xint).
After the first 67 passes however, the JIT wrongly optimizes this code to give
the
following wrong exit values:
iCarry = 70; // 7020800/100000
aiResult[1] = -699937730; // (622-70*100000)*100+(70)
i = 2; // ==== should have been 0
The problem statement is at line 208 in Jdk13Bug.java (follow the swLog field).
The exact number of iterations for the problem to occur, is extremely sensible
to the surrounding code and to the rest of the program. So you may see the same
error after a different number of iterations on another machine (or even not at
all).
I however saw the error over 200 times before tracking down the line number.
You can download a zip file containing logs and the complete code at:
http://www.ping.be/arci/download/jdk13bug.zip
Please do not try to understand the logic of the code, important parts have been
removed trying to isolate the problem. Also don't blame me for coding style. It
is as
I got it.
The log files have been produced as follows:
C:\JAVA\Jdk13Bug>java -version
java version "1.3beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
Java(TM) HotSpot Client VM (build 1.3beta-O, mixed mode)
C:\JAVA\Jdk13Bug>javac Jdk13Bug.java
C:\JAVA\Jdk13Bug>java -Xint Jdk13Bug >xint.log
C:\JAVA\Jdk13Bug>java Jdk13Bug >xjit.log
(Review ID: 98357)
======================================================================
C:\JAVA\Jdk13Bug>java -version
java version "1.3beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
Java(TM) HotSpot Client VM (build 1.3beta-O, mixed mode)
The JDK13beta1 Java HotSpot Client VM changes evaluation order
==============================================================
Using JDK13 beta 1 for Windows (W98, 128MB RAM, AMD-K62 350MHz), I isolated a
case
where optimized code evaluates in a different order than non-optimized code,
changing the result and breaking program logic.
The problematic statement is
aiResult[i] = (ai[i] - iCarry * iLoad) * iMultiplier + (iCarry = ai[++i] /
iLoad);
where normally the value of iCarry is used first, then recalculated and used
again.
After a certain number of passes through that code however, the recalculated
value is used twice. This should not occur
As an example (try the code linked to below) I produce a log file of a case
where
the error occured with the following entry values:
int[] ai = {3, 622, 7020800};
int[] aiResult = ai;
int iCarry = 0;
int iLoad = 100000;
int iMultiplier = 100;
int i = 1;
The correct exit values are then:
iCarry = 70; // 7020800/100000
aiResult[1] = 62270; // (622-0*100000)*100+(70)
i = 2;
Which are obtained for the first 67 passes through the complete code (main
method),
and for all passes with the JIT turned off (java -Xint).
After the first 67 passes however, the JIT wrongly optimizes this code to give
the
following wrong exit values:
iCarry = 70; // 7020800/100000
aiResult[1] = -699937730; // (622-70*100000)*100+(70)
i = 2; // ==== should have been 0
The problem statement is at line 208 in Jdk13Bug.java (follow the swLog field).
The exact number of iterations for the problem to occur, is extremely sensible
to the surrounding code and to the rest of the program. So you may see the same
error after a different number of iterations on another machine (or even not at
all).
I however saw the error over 200 times before tracking down the line number.
You can download a zip file containing logs and the complete code at:
http://www.ping.be/arci/download/jdk13bug.zip
Please do not try to understand the logic of the code, important parts have been
removed trying to isolate the problem. Also don't blame me for coding style. It
is as
I got it.
The log files have been produced as follows:
C:\JAVA\Jdk13Bug>java -version
java version "1.3beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
Java(TM) HotSpot Client VM (build 1.3beta-O, mixed mode)
C:\JAVA\Jdk13Bug>javac Jdk13Bug.java
C:\JAVA\Jdk13Bug>java -Xint Jdk13Bug >xint.log
C:\JAVA\Jdk13Bug>java Jdk13Bug >xjit.log
(Review ID: 98357)
======================================================================
- duplicates
-
JDK-4289029 110899 expression is evaluated in the wrong order.
-
- Resolved
-