author | lana |
Thu, 21 Jan 2016 09:46:01 -0800 | |
changeset 35340 | 38f7386ed942 |
parent 30730 | d3ce7619db2c |
child 36526 | 3b41f1c69604 |
permissions | -rw-r--r-- |
23791 | 1 |
/* |
28340 | 2 |
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
23791 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 8025505 |
|
27 |
* @summary Constant folding deficiency |
|
26100 | 28 |
* @library /tools/lib |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
28340
diff
changeset
|
29 |
* @modules jdk.compiler/com.sun.tools.javac.api |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
28340
diff
changeset
|
30 |
* jdk.compiler/com.sun.tools.javac.file |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
28340
diff
changeset
|
31 |
* jdk.compiler/com.sun.tools.javac.main |
23791 | 32 |
* @build ToolBox |
33 |
* @run main ConstFoldTest |
|
34 |
*/ |
|
35 |
||
36 |
import java.net.URL; |
|
28340 | 37 |
import java.nio.file.Path; |
38 |
import java.nio.file.Paths; |
|
23791 | 39 |
import java.util.List; |
40 |
||
41 |
public class ConstFoldTest { |
|
42 |
public static void main(String... args) throws Exception { |
|
43 |
new ConstFoldTest().run(); |
|
44 |
} |
|
45 |
||
46 |
// This is the test case. This class should end up |
|
47 |
// as straight-line code with no conditionals |
|
48 |
class CFTest { |
|
49 |
void m() { |
|
50 |
int x; |
|
51 |
if (1 != 2) x=1; else x=0; |
|
52 |
if (1 == 2) x=1; else x=0; |
|
26100 | 53 |
if ("" != null) x=1; else x=0; |
54 |
if ("" == null) x=1; else x=0; |
|
23791 | 55 |
if (null == null) x=1; else x=0; |
56 |
if (null != null) x=1; else x=0; |
|
57 |
||
58 |
x = 1 != 2 ? 1 : 0; |
|
59 |
x = 1 == 2 ? 1 : 0; |
|
26100 | 60 |
x = "" != null ? 1 : 0; |
61 |
x = "" == null ? 1 : 0; |
|
23791 | 62 |
x = null == null ? 1 : 0; |
63 |
x = null != null ? 1 : 0; |
|
64 |
||
65 |
boolean b; |
|
66 |
b = 1 != 2 && true; |
|
67 |
b = 1 == 2 || true; |
|
26100 | 68 |
b = ("" != null) && true; |
69 |
b = ("" == null) || true; |
|
23791 | 70 |
b = (null == null) && true; |
71 |
b = (null != null) || true; |
|
72 |
} |
|
73 |
} |
|
74 |
||
75 |
// All of the conditionals above should be eliminated. |
|
76 |
// these if* bytecodes should not be seen |
|
77 |
final String regex = "\\sif(?:null|nonnull|eq|ne){1}\\s"; |
|
78 |
||
79 |
void run() throws Exception { |
|
26100 | 80 |
ToolBox tb = new ToolBox(); |
81 |
||
23791 | 82 |
URL url = ConstFoldTest.class.getResource("ConstFoldTest$CFTest.class"); |
28340 | 83 |
Path file = Paths.get(url.toURI()); |
26100 | 84 |
List<String> result = tb.new JavapTask() |
85 |
.options("-c") |
|
28340 | 86 |
.classes(file.toString()) |
26100 | 87 |
.run() |
88 |
.write(ToolBox.OutputKind.DIRECT) |
|
89 |
.getOutputLines(ToolBox.OutputKind.DIRECT); |
|
23791 | 90 |
|
26100 | 91 |
List<String> bad_codes = tb.grep(regex, result); |
23791 | 92 |
if (!bad_codes.isEmpty()) { |
93 |
for (String code : bad_codes) |
|
94 |
System.out.println("Bad OpCode Found: " + code); |
|
95 |
throw new Exception("constant folding failed"); |
|
96 |
} |
|
97 |
} |
|
98 |
} |