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 invokestatic method selection and resolution cases that
  27  * generate IncompatibleClassChangeError
  28  * @modules java.base/jdk.internal.org.objectweb.asm
  29  * @library /runtime/SelectionResolution/classes
  30  * @build selectionresolution.*
  31  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies InvokeStaticICCE
  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 InvokeStaticICCE 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                 /* invokestatic tests */
  56                 /* Group 157: methodref = expected */
  57                 new TestGroup.Simple(initBuilder,
  58                         Template.SetInvoke(SelectionResolutionTestCase.InvokeInstruction.INVOKESTATIC),
  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.INSTANCE,
  65                                                         MethodData.Context.ABSTRACT),
  66                                              EnumSet.of(ClassData.Package.SAME,
  67                                                         ClassData.Package.DIFFERENT)),
  68                         Template.OverrideAbstractExpectedClass,
  69                         Template.MethodrefEqualsExpected,
  70                         Template.AllCallsiteCases,
  71                         Template.TrivialObjectref),
  72                 /* Group 158: methodref = expected, expected is interface */
  73                 new TestGroup.Simple(initBuilder,
  74                         Template.SetInvoke(SelectionResolutionTestCase.InvokeInstruction.INVOKESTATIC),
  75                         Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
  76                                              EnumSet.of(MethodData.Access.PUBLIC,
  77                                                         MethodData.Access.PRIVATE),
  78                                              EnumSet.of(MethodData.Context.INSTANCE,
  79                                                         MethodData.Context.ABSTRACT),
  80                                              EnumSet.of(ClassData.Package.SAME,
  81                                                         ClassData.Package.DIFFERENT)),
  82                         Template.OverrideAbstractExpectedIface,
  83                         Template.MethodrefEqualsExpected,
  84                         Template.AllCallsiteCases,
  85                         Template.TrivialObjectref),
  86                 /* Group 159: methodref != expected, expected is class
  87                  */
  88                 new TestGroup.Simple(initBuilder,
  89                         Template.SetInvoke(SelectionResolutionTestCase.InvokeInstruction.INVOKESTATIC),
  90                         Template.ResultCombo(EnumSet.of(Template.Kind.CLASS),
  91                                              EnumSet.of(MethodData.Access.PUBLIC,
  92                                                         MethodData.Access.PACKAGE,
  93                                                         MethodData.Access.PROTECTED,
  94                                                         MethodData.Access.PRIVATE),
  95                                              EnumSet.of(MethodData.Context.INSTANCE,
  96                                                         MethodData.Context.ABSTRACT),
  97                                              EnumSet.of(ClassData.Package.SAME,
  98                                                         ClassData.Package.DIFFERENT)),
  99                         Template.OverrideAbstractExpectedClass,
 100                         Template.MethodrefNotEqualsExpectedClass,
 101                         Template.AllCallsiteCases,
 102                         Template.TrivialObjectref),
 103                 /* Group 160: methodref = expected, expected is interface */
 104                 new TestGroup.Simple(initBuilder,
 105                         Template.SetInvoke(SelectionResolutionTestCase.InvokeInstruction.INVOKESTATIC),
 106                         Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE),
 107                                              EnumSet.of(MethodData.Access.PUBLIC,
 108                                                         MethodData.Access.PRIVATE),
 109                                              EnumSet.of(MethodData.Context.INSTANCE,
 110                                                         MethodData.Context.ABSTRACT),
 111                                              EnumSet.of(ClassData.Package.SAME,
 112                                                         ClassData.Package.DIFFERENT)),
 113                         Template.OverrideAbstractExpectedIface,
 114                         Template.MethodrefNotEqualsExpectedIface,
 115                         Template.AllCallsiteCases,
 116                         Template.TrivialObjectref)
 117             );
 118 
 119     private InvokeStaticICCE() {
 120         super(testgroups);
 121     }
 122 
 123     public static void main(final String... args) {
 124         new InvokeStaticICCE().run();
 125     }
 126 }