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=500 -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies InvokeInterfaceICCE
  31  */
  32 
  33 import java.util.Arrays;
  34 import java.util.Collection;
  35 import java.util.EnumSet;
  36 import selectionresolution.ClassData;
  37 import selectionresolution.MethodData;
  38 import selectionresolution.Result;
  39 import selectionresolution.SelectionResolutionTest;
  40 import selectionresolution.SelectionResolutionTestCase;
  41 import selectionresolution.Template;
  42 
  43 public class InvokeInterfaceICCE 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                 /* invokeinterface tests */
  55 
  56                 /* resolved method is static*/
  57                 /* Group 168: methodref = expected */
  58                 new TestGroup.Simple(initBuilder,
  59                         Template.SetInvoke(SelectionResolutionTestCase.InvokeInstruction.INVOKEINTERFACE),
  60                         Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
  61                                              EnumSet.of(MethodData.Access.PUBLIC),
  62                                              EnumSet.of(MethodData.Context.STATIC),
  63                                              EnumSet.of(ClassData.Package.SAME,
  64                                                         ClassData.Package.DIFFERENT)),
  65                         Template.OverrideAbstractExpectedIface,
  66                         Template.MethodrefEqualsExpected,
  67                         Template.IgnoredAbstract,
  68                         Template.AllCallsiteCases,
  69                         Template.IfaceMethodrefSelection),
  70                 /* Group 169: methodref != expected */
  71                 new TestGroup.Simple(initBuilder,
  72                         Template.SetInvoke(SelectionResolutionTestCase.InvokeInstruction.INVOKEINTERFACE),
  73                         Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
  74                                              EnumSet.of(MethodData.Access.PUBLIC),
  75                                              EnumSet.of(MethodData.Context.STATIC),
  76                                              EnumSet.of(ClassData.Package.SAME,
  77                                                         ClassData.Package.DIFFERENT)),
  78                         Template.OverrideAbstractExpectedIface,
  79                         Template.IfaceMethodrefNotEqualsExpected,
  80                         Template.IgnoredAbstract,
  81                         Template.AllCallsiteCases,
  82                         Template.IfaceMethodrefSelection),
  83 
  84                 /* methodref is a class */
  85                 /* Group 170: methodref = expected */
  86                 new TestGroup.Simple(initBuilder,
  87                         Template.SetInvoke(SelectionResolutionTestCase.InvokeInstruction.INVOKEINTERFACE),
  88                         Template.ResultCombo(EnumSet.of(Template.Kind.CLASS),
  89                                              EnumSet.of(MethodData.Access.PUBLIC,
  90                                                         MethodData.Access.PACKAGE,
  91                                                         MethodData.Access.PROTECTED,
  92                                                         MethodData.Access.PRIVATE),
  93                                              EnumSet.of(MethodData.Context.STATIC),
  94                                              EnumSet.of(ClassData.Package.SAME,
  95                                                         ClassData.Package.DIFFERENT)),
  96                         Template.OverrideAbstractExpectedClass,
  97                         Template.MethodrefEqualsExpected,
  98                         Template.IgnoredAbstract,
  99                         Template.AllCallsiteCases,
 100                         Template.MethodrefSelectionResolvedIsClass),
 101                 /* Group 171: methodref != expected, expected is class */
 102                 new TestGroup.Simple(initBuilder,
 103                         Template.SetInvoke(SelectionResolutionTestCase.InvokeInstruction.INVOKEINTERFACE),
 104                         Template.ResultCombo(EnumSet.of(Template.Kind.CLASS),
 105                                              EnumSet.of(MethodData.Access.PUBLIC,
 106                                                         MethodData.Access.PACKAGE,
 107                                                         MethodData.Access.PROTECTED,
 108                                                         MethodData.Access.PRIVATE),
 109                                              EnumSet.of(MethodData.Context.STATIC),
 110                                              EnumSet.of(ClassData.Package.SAME,
 111                                                         ClassData.Package.DIFFERENT)),
 112                         Template.OverrideAbstractExpectedClass,
 113                         Template.MethodrefNotEqualsExpectedClass,
 114                         Template.IgnoredAbstract,
 115                         Template.AllCallsiteCases,
 116                         Template.MethodrefSelectionResolvedIsClass),
 117                 /* Group 172: methodref != expected expected is interface */
 118                 new TestGroup.Simple(initBuilder,
 119                         Template.SetInvoke(SelectionResolutionTestCase.InvokeInstruction.INVOKEINTERFACE),
 120                         Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
 121                                              EnumSet.of(MethodData.Access.PUBLIC,
 122                                                         MethodData.Access.PRIVATE),
 123                                              EnumSet.of(MethodData.Context.STATIC),
 124                                              EnumSet.of(ClassData.Package.SAME,
 125                                                         ClassData.Package.DIFFERENT)),
 126                         Template.OverrideAbstractExpectedIface,
 127                         Template.MethodrefNotEqualsExpectedIface,
 128                         Template.IgnoredAbstract,
 129                         Template.AllCallsiteCases,
 130                         Template.MethodrefSelectionResolvedIsIface),
 131                 /* Group 173: ambiguous resolution */
 132                 new TestGroup.Simple(initBuilder,
 133                         Template.SetInvoke(SelectionResolutionTestCase.InvokeInstruction.INVOKEINTERFACE),
 134                         Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
 135                                              EnumSet.of(MethodData.Access.PUBLIC),
 136                                              EnumSet.of(MethodData.Context.INSTANCE),
 137                                              EnumSet.of(ClassData.Package.SAME,
 138                                                         ClassData.Package.DIFFERENT)),
 139                         Template.OverrideAbstractExpectedIface,
 140                         Template.IfaceMethodrefAmbiguous,
 141                         Template.IgnoredAbstract,
 142                         Template.AllCallsiteCases,
 143                         Template.IfaceMethodrefSelectionNoOverride),
 144                 /* Group 174: ambiguous selection */
 145                 new TestGroup.Simple(initBuilder,
 146                         Template.SetInvoke(SelectionResolutionTestCase.InvokeInstruction.INVOKEINTERFACE),
 147                         Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
 148                                              EnumSet.of(MethodData.Access.PUBLIC),
 149                                              EnumSet.of(MethodData.Context.INSTANCE),
 150                                              EnumSet.of(ClassData.Package.SAME,
 151                                                         ClassData.Package.DIFFERENT)),
 152                         Template.OverrideAbstractExpectedIface,
 153                         Template.IfaceMethodrefNotEqualsExpected,
 154                         Template.IgnoredAbstract,
 155                         Template.AllCallsiteCases,
 156                         Template.IfaceMethodrefAmbiguousResolvedIsIface)
 157             );
 158 
 159     private InvokeInterfaceICCE() {
 160         super(testgroups);
 161     }
 162 
 163     public static void main(final String... args) {
 164         new InvokeInterfaceICCE().run();
 165     }
 166 }