1/*
2 * Copyright (c) 2016, 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
24/*
25 * @test
26 * @summary Test of method selection and resolution cases that
27 * generate IncompatibleClassChangeError
28 * @modules java.base/jdk.internal.org.objectweb.asm
29 * @library /runtime/SelectionResolution/classes
30 * @run main/othervm/timeout=1200 -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies InvokeVirtualICCE
31 */
32
33import java.util.Arrays;
34import java.util.Collection;
35import java.util.EnumSet;
36import selectionresolution.ClassData;
37import selectionresolution.MethodData;
38import selectionresolution.Result;
39import selectionresolution.SelectionResolutionTest;
40import selectionresolution.SelectionResolutionTestCase;
41import selectionresolution.Template;
42
43public class InvokeVirtualICCE extends SelectionResolutionTest {
44
45    private static final SelectionResolutionTestCase.Builder initBuilder =
46        new SelectionResolutionTestCase.Builder();
47
48    static {
49        initBuilder.setResult(Result.ICCE);
50    }
51
52    private static final Collection<TestGroup> testgroups =
53        Arrays.asList(
54                /* invokevirtual tests */
55
56                /* resolved method is static*/
57                /* Group 161: callsite = methodref = expected */
58                new TestGroup.Simple(initBuilder,
59                        Template.SetInvoke(SelectionResolutionTestCase.InvokeInstruction.INVOKEVIRTUAL),
60                        Template.ResultCombo(EnumSet.of(Template.Kind.CLASS),
61                                             EnumSet.of(MethodData.Access.PUBLIC,
62                                                        MethodData.Access.PACKAGE,
63                                                        MethodData.Access.PRIVATE),
64                                             EnumSet.of(MethodData.Context.STATIC),
65                                             EnumSet.of(ClassData.Package.SAME,
66                                                        ClassData.Package.DIFFERENT)),
67                        Template.OverrideAbstractExpectedClass,
68                        Template.MethodrefEqualsExpected,
69                        Template.IgnoredAbstract,
70                        Template.AllCallsiteCases,
71                        Template.MethodrefSelectionResolvedIsClass),
72                /* Group 162: callsite = methodref, methodref != expected,
73                 * expected is class, expected and callsite in the same package
74                 */
75                new TestGroup.Simple(initBuilder,
76                        Template.SetInvoke(SelectionResolutionTestCase.InvokeInstruction.INVOKEVIRTUAL),
77                        Template.ResultCombo(EnumSet.of(Template.Kind.CLASS),
78                                             EnumSet.of(MethodData.Access.PUBLIC,
79                                                        MethodData.Access.PACKAGE,
80                                                        MethodData.Access.PRIVATE),
81                                             EnumSet.of(MethodData.Context.STATIC),
82                                             EnumSet.of(ClassData.Package.SAME,
83                                                        ClassData.Package.DIFFERENT)),
84                        Template.OverrideAbstractExpectedClass,
85                        Template.MethodrefNotEqualsExpectedClass,
86                        Template.IgnoredAbstract,
87                        Template.AllCallsiteCases,
88                        Template.MethodrefSelectionResolvedIsClass),
89                /* Group 163: callsite = methodref, methodref != expected,
90                 * expected is interface, expected and callsite in the same package
91                 */
92                new TestGroup.Simple(initBuilder,
93                        Template.SetInvoke(SelectionResolutionTestCase.InvokeInstruction.INVOKEVIRTUAL),
94                        Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
95                                             EnumSet.of(MethodData.Access.PUBLIC,
96                                                        MethodData.Access.PRIVATE),
97                                             EnumSet.of(MethodData.Context.STATIC),
98                                             EnumSet.of(ClassData.Package.SAME,
99                                                        ClassData.Package.DIFFERENT)),
100                        Template.OverrideAbstractExpectedIface,
101                        Template.MethodrefNotEqualsExpectedIface,
102                        Template.IgnoredAbstract,
103                        Template.AllCallsiteCases,
104                        Template.MethodrefSelectionResolvedIsIface),
105
106                /* methodref is an interface */
107                /* Group 164: callsite = methodref = expected */
108                new TestGroup.Simple(initBuilder,
109                        Template.SetInvoke(SelectionResolutionTestCase.InvokeInstruction.INVOKEVIRTUAL),
110                        Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
111                                             EnumSet.of(MethodData.Access.PUBLIC,
112                                                        MethodData.Access.PRIVATE),
113                                             EnumSet.allOf(MethodData.Context.class),
114                                             EnumSet.of(ClassData.Package.SAME,
115                                                        ClassData.Package.DIFFERENT)),
116                        Template.OverrideAbstractExpectedIface,
117                        Template.MethodrefEqualsExpected,
118                        Template.IgnoredAbstract,
119                        Template.AllCallsiteCases,
120                        Template.IfaceMethodrefSelection),
121                /* Group 165: callsite = methodref, methodref != expected,
122                 * expected and callsite in the same package
123                 */
124                new TestGroup.Simple(initBuilder,
125                        Template.SetInvoke(SelectionResolutionTestCase.InvokeInstruction.INVOKEVIRTUAL),
126                        Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
127                                             EnumSet.of(MethodData.Access.PUBLIC,
128                                                        MethodData.Access.PRIVATE),
129                                             EnumSet.allOf(MethodData.Context.class),
130                                             EnumSet.of(ClassData.Package.SAME,
131                                                        ClassData.Package.DIFFERENT)),
132                        Template.OverrideAbstractExpectedIface,
133                        Template.IfaceMethodrefNotEqualsExpected,
134                        Template.IgnoredAbstract,
135                        Template.AllCallsiteCases,
136                        Template.IfaceMethodrefSelection),
137
138                /* Group 166: Ambiguous resolution tests */
139                new TestGroup.Simple(initBuilder,
140                        Template.SetInvoke(SelectionResolutionTestCase.InvokeInstruction.INVOKEVIRTUAL),
141                        Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
142                                             EnumSet.of(MethodData.Access.PUBLIC),
143                                             EnumSet.allOf(MethodData.Context.class),
144                                             EnumSet.of(ClassData.Package.SAME,
145                                                        ClassData.Package.DIFFERENT)),
146                        Template.OverrideAbstractExpectedIface,
147                        Template.MethodrefAmbiguous,
148                        Template.IgnoredAbstract,
149                        Template.AllCallsiteCases,
150                        Template.MethodrefSelectionResolvedIsIfaceNoOverride),
151                /* Group 167: ambiguous selection */
152                new TestGroup.Simple(initBuilder,
153                        Template.SetInvoke(SelectionResolutionTestCase.InvokeInstruction.INVOKEVIRTUAL),
154                        Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
155                                             EnumSet.of(MethodData.Access.PUBLIC),
156                                             EnumSet.of(MethodData.Context.INSTANCE),
157                                             EnumSet.of(ClassData.Package.SAME,
158                                                        ClassData.Package.DIFFERENT)),
159                        Template.OverrideAbstractExpectedIface,
160                        Template.MethodrefNotEqualsExpectedIface,
161                        Template.IgnoredAbstract,
162                        Template.AllCallsiteCases,
163                        Template.MethodrefAmbiguousResolvedIsIface)
164                );
165
166    private InvokeVirtualICCE() {
167        super(testgroups);
168    }
169
170    public static void main(final String... args) {
171        new InvokeVirtualICCE().run();
172    }
173}
174