JDK-7110586 : C2 generates incorrect results
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: hs22
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-11-10
  • Updated: 2013-04-24
  • Resolved: 2012-01-20
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 7 JDK 8 Other
7u2Fixed 8Fixed hs22Fixed
Related Reports
Relates :  
Description
See attached example.

Bug is reproduced on JDK7 b147 and still exist in HS23b05

Here is results for interpreter and C2:
Expected results (int):
[
Test.var_18 = 65
Test.var_20 = 218763548
Test.var_17 = false
Test.var_19 = [
Test_Class_0.var_1 = 11
Test_Class_0.var_4 = 0
Test_Class_0.var_5 = 640
Test_Class_0.var_2 = 612000468
Test_Class_0.var_3 = 1.413301352444783E308
]
]
Actual results(C2):
[
Test.var_18 = 65
Test.var_20 = 218763548
Test.var_17 = false
Test.var_19 = [
Test_Class_0.var_1 = 9
Test_Class_0.var_4 = 0
Test_Class_0.var_5 = 640
Test_Class_0.var_2 = 612000468
Test_Class_0.var_3 = 1.413301352444783E308
]

Comments
EVALUATION http://hg.openjdk.java.net/lambda/lambda/hotspot/rev/e8fdaf4a66cb
22-03-2012

EVALUATION http://hg.openjdk.java.net/hsx/hotspot-emb/hotspot/rev/e8fdaf4a66cb
15-12-2011

EVALUATION http://hg.openjdk.java.net/hsx/hsx22/hotspot/rev/742a2251c87b
17-11-2011

EVALUATION The method exact_limit() which has incorrect code is used in two places: 1. policy_do_remove_empty_loop() to calculate final value of iteration variable in empty loops. We found failing case for this: static int test2() { int i = 0; for ( ; i < 11; i+=2) {} return i; } Empty loop could be crated due to dead code elimination and also during loop unswitching: static int test2(int x, int arr[]) { int i = 0; for ( ; i < 11; i+=2) { if (x != 0) arr[i] = i; } return i; } which will be transformed into if (x != 0) { for ( ; i < 11; i+=2) { arr[i] = i; } } else { for ( ; i < 11; i+=2) { // empty loop } } 2. PhaseIdealLoop::rc_predicate() calculate limit for range check elimination with loop predicates. It would cause intermediate SEGV in compiled code when accessing array outside of it's range. Here is test which does not throw ArrayIndexOutOfBounds exception: intelsdv39% cat Test.java public class Test { static int test2(int x, int arr[]) { int res = 0; for (int i = 0 ; i < 11; i+=2) { if (x != 0) { res = arr[i]; } else { res = i; } } return res; } public static void main(String args[]) { int x2 = 0; // Warm up int[] arr = new int[11]; for (int i=0; i<10000; i++) { x2 = test2(i&1, arr); } for (int i=0; i<10000; i++) { x2 = test2(i&1, arr); } // Test range check in compiled code boolean failed = true; int[] arr_fail = new int[9]; try { for (int i=0; i<10000; i++) { x2 = test2(1, arr_fail); } } catch (ArrayIndexOutOfBoundsException ex) { failed = false; } if (failed) { System.out.println("ERROR: ArrayIndexOutOfBoundsException was not thrown"); System.exit(97); } } } intelsdv39% /java/re/jdk/7u2/latest/binaries/solaris-i586/fastdebug/bin/java -Xbatch -XX:+PrintCompilation Test VM option '+PrintCompilation' 349 1 b Test::test2 (31 bytes) ERROR: ArrayIndexOutOfBoundsException was not thrown intelsdv39% gamma -Xbatch -XX:+PrintCompilation Test Using java runtime at: /export/kvn/jdk7u2/jre VM option '+PrintCompilation' 2979 1 b Test::test2 (31 bytes) 3020 1 Test::test2 (31 bytes) made not entrant intelsdv39%
14-11-2011

EVALUATION http://hg.openjdk.java.net/hsx/hotspot-comp/hotspot/rev/e8fdaf4a66cb
11-11-2011

WORK AROUND -XX:-LoopLimitCheck
11-11-2011

EVALUATION Regression after 5091921 fix. Exact limit of empty loop calculated incorrectly.
11-11-2011