author | stuefe |
Thu, 28 Apr 2016 15:40:45 +0200 | |
changeset 38215 | fe1677e95252 |
parent 31042 | 8cfcba31d855 |
child 40059 | c2304140ed64 |
permissions | -rw-r--r-- |
31042
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
1 |
/* |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
4 |
* |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
8 |
* |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
13 |
* accompanied this code). |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
14 |
* |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
18 |
* |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
21 |
* questions. |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
22 |
*/ |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
23 |
|
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
24 |
/* |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
25 |
* @test |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
26 |
* @bug 8080156 8060036 |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
27 |
* @summary Test correctness of type propagation to CmpUNodes. |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
28 |
* @run main TestTypePropagationToCmpU |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
29 |
*/ |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
30 |
public class TestTypePropagationToCmpU { |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
31 |
public static void main(String[] args) { |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
32 |
try { |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
33 |
// Trigger compilation |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
34 |
for (int i = 0; i < 100_000; ++i) { |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
35 |
test(); |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
36 |
} |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
37 |
} catch (NullPointerException e) { |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
38 |
// Test should never throw a NullPointerException |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
39 |
throw new RuntimeException("Test failed"); |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
40 |
} |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
41 |
} |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
42 |
|
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
43 |
static int global = 42; |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
44 |
|
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
45 |
public static void test() { |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
46 |
int a = Integer.MIN_VALUE; |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
47 |
int b = global; |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
48 |
char[] buf = { 0 }; |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
49 |
for (int i = 0; i <= b; ++i) { |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
50 |
a = i - b; |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
51 |
} |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
52 |
// C2 adds a range check and an uncommon trap here to ensure that the array index |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
53 |
// is in bounds. If type information is not propagated correctly to the corresponding |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
54 |
// CmpUNode, this trap may be always taken. Because C2 also removes the unnecessary |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
55 |
// allocation of 'buf', a NullPointerException is thrown in this case. |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
56 |
char c = buf[(a * 11) / 2 - a]; // a is 0 here if global >= 0 |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
57 |
buf[0] = 0; |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
58 |
} |
8cfcba31d855
8080156: Integer.toString(int value) sometimes throws NPE
thartmann
parents:
diff
changeset
|
59 |
} |