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 -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies InvokeSpecialICCE
  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 InvokeSpecialICCE 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                 /* invokespecial tests */
  55                 /* resolved method is static*/
  56                 /* Group 170: methodref = expected */
  57                 new TestGroup.Simple(initBuilder,
  58                         Template.SetInvoke(SelectionResolutionTestCase.InvokeInstruction.INVOKESPECIAL),
  59                         Template.ResultCombo(EnumSet.of(Template.Kind.CLASS),
  60                                              EnumSet.of(MethodData.Access.PUBLIC,
  61                                                         MethodData.Access.PACKAGE,
  62                                                         MethodData.Access.PROTECTED,
  63                                                         MethodData.Access.PRIVATE),
  64                                              EnumSet.of(MethodData.Context.STATIC),
  65                                              EnumSet.of(ClassData.Package.SAME)),
  66                         Template.OverrideAbstractExpectedClass,
  67                         Template.MethodrefEqualsExpected,
  68                         Template.IgnoredAbstract,
  69                         Template.InvokespecialCallsiteCases,
  70                         Template.ObjectrefAssignableToCallsite),
  71                 /* Group 171: methodref != expected, expected is class */
  72                 new TestGroup.Simple(initBuilder,
  73                         Template.SetInvoke(SelectionResolutionTestCase.InvokeInstruction.INVOKESPECIAL),
  74                         Template.ResultCombo(EnumSet.of(Template.Kind.CLASS),
  75                                              EnumSet.of(MethodData.Access.PUBLIC,
  76                                                         MethodData.Access.PACKAGE,
  77                                                         MethodData.Access.PROTECTED,
  78                                                         MethodData.Access.PRIVATE),
  79                                              EnumSet.of(MethodData.Context.STATIC),
  80                                              EnumSet.of(ClassData.Package.SAME,
  81                                                         ClassData.Package.DIFFERENT)),
  82                         Template.OverrideAbstractExpectedClass,
  83                         Template.MethodrefNotEqualsExpectedClass,
  84                         Template.IgnoredAbstract,
  85                         Template.InvokespecialCallsiteCases,
  86                         Template.ObjectrefAssignableToCallsite),
  87                 /* Group 172: methodref != expected, expected is interface */
  88                 new TestGroup.Simple(initBuilder,
  89                         Template.SetInvoke(SelectionResolutionTestCase.InvokeInstruction.INVOKESPECIAL),
  90                         Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
  91                                              EnumSet.of(MethodData.Access.PUBLIC,
  92                                                         MethodData.Access.PRIVATE),
  93                                              EnumSet.of(MethodData.Context.STATIC),
  94                                              EnumSet.of(ClassData.Package.SAME,
  95                                                         ClassData.Package.DIFFERENT)),
  96                         Template.OverrideAbstractExpectedIface,
  97                         Template.MethodrefNotEqualsExpectedIface,
  98                         Template.IgnoredAbstract,
  99                         Template.InvokespecialCallsiteCases,
 100                         Template.ObjectrefAssignableToCallsite),
 101 
 102                 /* Group 173: Ambiguous resolution */
 103                 new TestGroup.Simple(initBuilder,
 104                         Template.SetInvoke(SelectionResolutionTestCase.InvokeInstruction.INVOKESPECIAL),
 105                         Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
 106                                              EnumSet.of(MethodData.Access.PUBLIC,
 107                                                         MethodData.Access.PRIVATE),
 108                                              EnumSet.allOf(MethodData.Context.class),
 109                                              EnumSet.of(ClassData.Package.SAME,
 110                                                         ClassData.Package.DIFFERENT)),
 111                         Template.OverrideAbstractExpectedIface,
 112                         Template.MethodrefAmbiguous,
 113                         Template.IgnoredAbstract,
 114                         Template.InvokespecialCallsiteCases,
 115                         Template.ObjectrefAssignableToCallsite)
 116             );
 117 
 118     private InvokeSpecialICCE() {
 119         super(testgroups);
 120     }
 121 
 122     public static void main(final String... args) {
 123         new InvokeSpecialICCE().run();
 124     }
 125 }