Skip to content

Commit 080f3c5

Browse files
committed
8286190: Add test to verify constant folding for Enum fields
Reviewed-by: kvn, thartmann
1 parent 1277f5d commit 080f3c5

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2022, Red Hat, Inc. 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+
24+
package compiler.c2.irTests;
25+
26+
import jdk.test.lib.Asserts;
27+
import compiler.lib.ir_framework.*;
28+
29+
/*
30+
* @test
31+
* @bug 8286190
32+
* @summary Verify constant folding for Enum fields
33+
* @library /test/lib /
34+
* @requires vm.compiler2.enabled
35+
* @run driver compiler.c2.irTests.TestEnumFinalFold
36+
*/
37+
public class TestEnumFinalFold {
38+
39+
public static void main(String[] args) {
40+
TestFramework.run();
41+
}
42+
43+
private enum MyEnum {
44+
VALUE1,
45+
VALUE2;
46+
}
47+
48+
@Test
49+
@IR(failOn = {IRNode.ADD_I, IRNode.LOAD_I})
50+
public int testOrdinalSum() {
51+
return MyEnum.VALUE1.ordinal() + MyEnum.VALUE2.ordinal();
52+
}
53+
54+
@Run(test = "testOrdinalSum")
55+
public void runOrdinalSum() {
56+
testOrdinalSum();
57+
}
58+
59+
@Test
60+
@IR(failOn = {IRNode.ADD_I})
61+
public int testNameLengthSum() {
62+
return MyEnum.VALUE1.name().length() + MyEnum.VALUE2.name().length();
63+
}
64+
65+
@Run(test = "testNameLengthSum")
66+
public void runNameLengthSum() {
67+
testNameLengthSum();
68+
}
69+
70+
}

0 commit comments

Comments
 (0)