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