author | mcimadamore |
Mon, 31 Aug 2015 17:33:34 +0100 | |
changeset 32454 | b0ac04e0fefe |
parent 31114 | d4045e8aaf1e |
child 36526 | 3b41f1c69604 |
permissions | -rw-r--r-- |
31114 | 1 |
/* |
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
|
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 |
||
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
24 |
/* |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
25 |
* @test |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
26 |
* @bug 8082311 8129962 |
31114 | 27 |
* @summary Verify that bitwise operators don't allow to mix numeric and boolean operands. |
28 |
* @library ../lib |
|
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
29 |
* @modules jdk.compiler/com.sun.tools.javac.api |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
30 |
* jdk.compiler/com.sun.tools.javac.util |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
31 |
* @build combo.ComboTestHelper |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
32 |
* @run main BitWiseOperators |
31114 | 33 |
*/ |
34 |
||
35 |
import com.sun.tools.javac.util.StringUtils; |
|
36 |
||
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
37 |
import java.io.IOException; |
31114 | 38 |
|
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
39 |
import combo.ComboInstance; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
40 |
import combo.ComboParameter; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
41 |
import combo.ComboTask.Result; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
42 |
import combo.ComboTestHelper; |
31114 | 43 |
|
44 |
||
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
45 |
public class BitWiseOperators extends ComboInstance<BitWiseOperators> { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
46 |
|
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
47 |
enum OperandType implements ComboParameter { |
31114 | 48 |
BYTE, |
49 |
CHAR, |
|
50 |
SHORT, |
|
51 |
INT, |
|
52 |
LONG, |
|
53 |
BOOLEAN; |
|
54 |
||
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
55 |
public static boolean compatible(OperandType op1, OperandType op2) { |
31114 | 56 |
return !(op1 == BOOLEAN ^ op2 == BOOLEAN); |
57 |
} |
|
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
58 |
|
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
59 |
@Override |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
60 |
public String expand(String optParameter) { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
61 |
return StringUtils.toLowerCase(name()); |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
62 |
} |
31114 | 63 |
} |
64 |
||
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
65 |
enum OperatorKind implements ComboParameter { |
31114 | 66 |
BITAND("&"), |
67 |
BITOR("|"), |
|
68 |
BITXOR("^"); |
|
69 |
||
70 |
String op; |
|
71 |
||
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
72 |
OperatorKind(String op) { |
31114 | 73 |
this.op = op; |
74 |
} |
|
75 |
||
76 |
@Override |
|
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
77 |
public String expand(String optParameter) { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
78 |
return op; |
31114 | 79 |
} |
80 |
} |
|
81 |
||
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
82 |
public static void main(String... args) { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
83 |
new ComboTestHelper<BitWiseOperators>() |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
84 |
.withArrayDimension("TYPE", (x, type, idx) -> x.opTypes[idx] = type, 2, OperandType.values()) |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
85 |
.withDimension("OP", OperatorKind.values()) |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
86 |
.run(BitWiseOperators::new); |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
87 |
} |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
88 |
|
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
89 |
OperandType[] opTypes = new OperandType[2]; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
90 |
|
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
91 |
String template = "class Test {\n" + |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
92 |
" public Object test(#{TYPE[0]} var1, #{TYPE[1]} var2) {\n" + |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
93 |
" return var1 #{OP} var2;\n" + |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
94 |
" }\n" + |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
95 |
"}"; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
96 |
|
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
97 |
@Override |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
98 |
public void doWork() throws IOException { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
99 |
Result<?> res = newCompilationTask() |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
100 |
.withSourceFromTemplate(template) |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
101 |
.analyze(); |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
102 |
if (res.hasErrors() == OperandType.compatible(opTypes[0], opTypes[1])) { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
103 |
fail("Unexpected behavior. Type1: " + opTypes[0] + |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
104 |
"; type2: " + opTypes[1] + |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
105 |
"; " + res.compilationInfo()); |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
106 |
} |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
31114
diff
changeset
|
107 |
} |
31114 | 108 |
} |