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 InvokeInterfaceSuccessTest
  28  * @modules java.base/jdk.internal.org.objectweb.asm
  29  * @library /runtime/SelectionResolution/classes
  30  * @run main/othervm/timeout=300 -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies InvokeInterfaceSuccessTest
  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.SelectionResolutionTest;
  39 import selectionresolution.SelectionResolutionTestCase;
  40 import selectionresolution.Template;
  41 
  42 public class InvokeInterfaceSuccessTest extends SelectionResolutionTest {
  43 
  44     private static final SelectionResolutionTestCase.Builder initBuilder =
  45         new SelectionResolutionTestCase.Builder();
  46 
  47     static {
  48         initBuilder.invoke = SelectionResolutionTestCase.InvokeInstruction.INVOKEINTERFACE;
  49     }
  50 
  51     private static final Collection<TestGroup> testgroups =
  52         Arrays.asList(
  53                 /* invokeinterface tests */
  54 
  55                 /* Group 40: callsite = methodref = expected */
  56                 new TestGroup.Simple(initBuilder,
  57                         Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
  58                                              EnumSet.of(MethodData.Access.PUBLIC),
  59                                              EnumSet.of(MethodData.Context.INSTANCE,
  60                                                         MethodData.Context.ABSTRACT),
  61                                              EnumSet.of(ClassData.Package.SAME)),
  62                         Template.OverrideAbstractExpectedIface,
  63                         Template.MethodrefEqualsExpected,
  64                         Template.IgnoredAbstract,
  65                         Template.CallsiteEqualsMethodref,
  66                         Template.IfaceMethodrefSelection,
  67                         Template.SelectionOverrideAbstract),
  68                 /* Group 41: callsite = methodref, methodref != expected */
  69                 new TestGroup.Simple(initBuilder,
  70                         Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
  71                                              EnumSet.of(MethodData.Access.PUBLIC),
  72                                              EnumSet.of(MethodData.Context.INSTANCE,
  73                                                         MethodData.Context.ABSTRACT),
  74                                              EnumSet.of(ClassData.Package.SAME,
  75                                                         ClassData.Package.DIFFERENT)),
  76                         Template.OverrideAbstractExpectedIface,
  77                         Template.IfaceMethodrefNotEqualsExpected,
  78                         Template.IgnoredAbstract,
  79                         Template.CallsiteEqualsMethodref,
  80                         Template.IfaceMethodrefSelection,
  81                         Template.SelectionOverrideAbstract),
  82                 /* Group 42: callsite :> methodref, methodref = expected */
  83                 new TestGroup.Simple(initBuilder,
  84                         Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
  85                                              EnumSet.of(MethodData.Access.PUBLIC),
  86                                              EnumSet.of(MethodData.Context.INSTANCE,
  87                                                         MethodData.Context.ABSTRACT),
  88                                              EnumSet.of(ClassData.Package.SAME,
  89                                                         ClassData.Package.DIFFERENT)),
  90                         Template.OverrideAbstractExpectedIface,
  91                         Template.MethodrefEqualsExpected,
  92                         Template.IgnoredAbstract,
  93                         Template.CallsiteSubclassMethodref,
  94                         Template.IfaceMethodrefSelection,
  95                         Template.SelectionOverrideAbstract),
  96                 /* Group 43: callsite :> methodref, methodref != expected */
  97                 new TestGroup.Simple(initBuilder,
  98                         Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
  99                                              EnumSet.of(MethodData.Access.PUBLIC),
 100                                              EnumSet.of(MethodData.Context.INSTANCE,
 101                                                         MethodData.Context.ABSTRACT),
 102                                              EnumSet.of(ClassData.Package.SAME,
 103                                                         ClassData.Package.DIFFERENT)),
 104                         Template.OverrideAbstractExpectedIface,
 105                         Template.IfaceMethodrefNotEqualsExpected,
 106                         Template.IgnoredAbstract,
 107                         Template.CallsiteSubclassMethodref,
 108                         Template.IfaceMethodrefSelection,
 109                         Template.SelectionOverrideAbstract),
 110                 /* Group 44: callsite unrelated to methodref, methodref = expected */
 111                 new TestGroup.Simple(initBuilder,
 112                         Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
 113                                              EnumSet.of(MethodData.Access.PUBLIC),
 114                                              EnumSet.of(MethodData.Context.INSTANCE,
 115                                                         MethodData.Context.ABSTRACT),
 116                                              EnumSet.of(ClassData.Package.SAME,
 117                                                         ClassData.Package.DIFFERENT)),
 118                         Template.OverrideAbstractExpectedIface,
 119                         Template.MethodrefEqualsExpected,
 120                         Template.IgnoredAbstract,
 121                         Template.CallsiteUnrelatedToMethodref,
 122                         Template.IfaceMethodrefSelection,
 123                         Template.SelectionOverrideAbstract),
 124                 /* Group 45: callsite unrelated to methodref, methodref != expected */
 125                 new TestGroup.Simple(initBuilder,
 126                         Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
 127                                              EnumSet.of(MethodData.Access.PUBLIC),
 128                                              EnumSet.of(MethodData.Context.INSTANCE,
 129                                                         MethodData.Context.ABSTRACT),
 130                                              EnumSet.of(ClassData.Package.SAME,
 131                                                         ClassData.Package.DIFFERENT)),
 132                         Template.OverrideAbstractExpectedIface,
 133                         Template.IfaceMethodrefNotEqualsExpected,
 134                         Template.IgnoredAbstract,
 135                         Template.CallsiteUnrelatedToMethodref,
 136                         Template.IfaceMethodrefSelection,
 137                         Template.SelectionOverrideAbstract)
 138             );
 139 
 140     private InvokeInterfaceSuccessTest() {
 141         super(testgroups);
 142     }
 143 
 144     public static void main(final String... args) {
 145         new InvokeInterfaceSuccessTest().run();
 146     }
 147 }