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