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 InvokeStaticSuccessTest 28 * @modules java.base/jdk.internal.org.objectweb.asm 29 * @library /runtime/SelectionResolution/classes 30 * @run main InvokeStaticSuccessTest 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 InvokeStaticSuccessTest extends SelectionResolutionTest { 43 44 private static final SelectionResolutionTestCase.Builder initBuilder = 45 new SelectionResolutionTestCase.Builder(); 46 47 static { 48 initBuilder.invoke = SelectionResolutionTestCase.InvokeInstruction.INVOKESTATIC; 49 } 50 51 private static final Collection<TestGroup> testgroups = 52 Arrays.asList( 53 /* invokestatic tests */ 54 /* Group 1: callsite = methodref = expected */ 55 new TestGroup.Simple(initBuilder, 56 Template.ResultCombo(EnumSet.of(Template.Kind.CLASS), 57 EnumSet.of(MethodData.Access.PUBLIC, 58 MethodData.Access.PACKAGE, 59 MethodData.Access.PROTECTED, 60 MethodData.Access.PRIVATE), 61 EnumSet.of(MethodData.Context.STATIC), 62 EnumSet.of(ClassData.Package.SAME)), 63 Template.MethodrefEqualsExpected, 64 Template.CallsiteEqualsMethodref, 65 Template.TrivialObjectref), 66 /* Group 2: callsite = methodref, methodref != expected, 67 * expected is class, expected and callsite in the same package 68 */ 69 new TestGroup.Simple(initBuilder, 70 Template.ResultCombo(EnumSet.of(Template.Kind.CLASS), 71 EnumSet.of(MethodData.Access.PUBLIC, 72 MethodData.Access.PACKAGE, 73 MethodData.Access.PROTECTED), 74 EnumSet.of(MethodData.Context.STATIC), 75 EnumSet.of(ClassData.Package.SAME)), 76 Template.MethodrefNotEqualsExpectedClass, 77 Template.CallsiteEqualsMethodref, 78 Template.TrivialObjectref), 79 /* Group 3: callsite :> methodref, methodref = expected, 80 * expected is class, expected and callsite in the same package 81 */ 82 new TestGroup.Simple(initBuilder, 83 Template.ResultCombo(EnumSet.of(Template.Kind.CLASS), 84 EnumSet.of(MethodData.Access.PUBLIC, 85 MethodData.Access.PACKAGE, 86 MethodData.Access.PROTECTED), 87 EnumSet.of(MethodData.Context.STATIC), 88 EnumSet.of(ClassData.Package.SAME)), 89 Template.MethodrefEqualsExpected, 90 Template.CallsiteSubclassMethodref, 91 Template.TrivialObjectref), 92 /* Group 4: callsite :> methodref, methodref = expected, 93 * expected is interface, expected and callsite in the same package 94 */ 95 new TestGroup.Simple(initBuilder, 96 Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE), 97 EnumSet.of(MethodData.Access.PUBLIC), 98 EnumSet.of(MethodData.Context.STATIC), 99 EnumSet.of(ClassData.Package.SAME)), 100 Template.MethodrefEqualsExpected, 101 Template.CallsiteSubclassMethodref, 102 Template.TrivialObjectref), 103 /* Group 5: callsite :> methodref, methodref != expected, 104 * expected is class, expected and callsite in the same package 105 */ 106 new TestGroup.Simple(initBuilder, 107 Template.ResultCombo(EnumSet.of(Template.Kind.CLASS), 108 EnumSet.of(MethodData.Access.PUBLIC, 109 MethodData.Access.PACKAGE, 110 MethodData.Access.PROTECTED), 111 EnumSet.of(MethodData.Context.STATIC), 112 EnumSet.of(ClassData.Package.SAME)), 113 Template.MethodrefNotEqualsExpectedClass, 114 Template.CallsiteSubclassMethodref, 115 Template.TrivialObjectref), 116 /* Group 6: callsite unrelated to methodref, methodref = expected, 117 * expected is class, expected and callsite in the same package 118 */ 119 new TestGroup.Simple(initBuilder, 120 Template.ResultCombo(EnumSet.of(Template.Kind.CLASS), 121 EnumSet.of(MethodData.Access.PUBLIC, 122 MethodData.Access.PACKAGE, 123 MethodData.Access.PROTECTED), 124 EnumSet.of(MethodData.Context.STATIC), 125 EnumSet.of(ClassData.Package.SAME)), 126 Template.MethodrefEqualsExpected, 127 Template.CallsiteUnrelatedToMethodref, 128 Template.TrivialObjectref), 129 /* Group 7: callsite unrelated to methodref, methodref = expected, 130 * expected is interface, expected and callsite in the same package 131 */ 132 new TestGroup.Simple(initBuilder, 133 Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE), 134 EnumSet.of(MethodData.Access.PUBLIC), 135 EnumSet.of(MethodData.Context.STATIC), 136 EnumSet.of(ClassData.Package.SAME)), 137 Template.MethodrefEqualsExpected, 138 Template.CallsiteUnrelatedToMethodref, 139 Template.TrivialObjectref), 140 /* Group 8: callsite unrelated to methodref, methodref != expected, 141 * expected is class, expected and callsite in the same package 142 */ 143 new TestGroup.Simple(initBuilder, 144 Template.ResultCombo(EnumSet.of(Template.Kind.CLASS), 145 EnumSet.of(MethodData.Access.PUBLIC, 146 MethodData.Access.PACKAGE, 147 MethodData.Access.PROTECTED), 148 EnumSet.of(MethodData.Context.STATIC), 149 EnumSet.of(ClassData.Package.SAME)), 150 Template.MethodrefNotEqualsExpectedClass, 151 Template.CallsiteUnrelatedToMethodref, 152 Template.TrivialObjectref), 153 /* Group 9: callsite = methodref, methodref != expected, 154 * expected is class, expected and callsite not in the same package 155 */ 156 new TestGroup.Simple(initBuilder, 157 Template.ResultCombo(EnumSet.of(Template.Kind.CLASS), 158 EnumSet.of(MethodData.Access.PUBLIC, 159 MethodData.Access.PROTECTED), 160 EnumSet.of(MethodData.Context.STATIC), 161 EnumSet.of(ClassData.Package.DIFFERENT)), 162 Template.MethodrefNotEqualsExpectedClass, 163 Template.CallsiteEqualsMethodref, 164 Template.TrivialObjectref), 165 /* Group 10: callsite :> methodref, methodref = expected, 166 * expected is class, expected and callsite not in the same package 167 */ 168 new TestGroup.Simple(initBuilder, 169 Template.ResultCombo(EnumSet.of(Template.Kind.CLASS), 170 EnumSet.of(MethodData.Access.PUBLIC, 171 MethodData.Access.PROTECTED), 172 EnumSet.of(MethodData.Context.STATIC), 173 EnumSet.of(ClassData.Package.DIFFERENT)), 174 Template.MethodrefEqualsExpected, 175 Template.CallsiteSubclassMethodref, 176 Template.TrivialObjectref), 177 /* Group 11: callsite :> methodref, methodref = expected, 178 * expected is interface, expected and callsite not in the same package 179 */ 180 new TestGroup.Simple(initBuilder, 181 Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE), 182 EnumSet.of(MethodData.Access.PUBLIC), 183 EnumSet.of(MethodData.Context.STATIC), 184 EnumSet.of(ClassData.Package.DIFFERENT)), 185 Template.MethodrefEqualsExpected, 186 Template.CallsiteSubclassMethodref, 187 Template.TrivialObjectref), 188 /* Group 12: callsite :> methodref, methodref != expected, 189 * expected is class, expected and callsite not in the same package 190 */ 191 new TestGroup.Simple(initBuilder, 192 Template.ResultCombo(EnumSet.of(Template.Kind.CLASS), 193 EnumSet.of(MethodData.Access.PUBLIC, 194 MethodData.Access.PROTECTED), 195 EnumSet.of(MethodData.Context.STATIC), 196 EnumSet.of(ClassData.Package.DIFFERENT)), 197 Template.MethodrefNotEqualsExpectedClass, 198 Template.CallsiteSubclassMethodref, 199 Template.TrivialObjectref), 200 /* Group 13: callsite unrelated to methodref, methodref = expected, 201 * expected is class, expected and callsite not in the same package 202 */ 203 new TestGroup.Simple(initBuilder, 204 Template.ResultCombo(EnumSet.of(Template.Kind.CLASS), 205 EnumSet.of(MethodData.Access.PUBLIC), 206 EnumSet.of(MethodData.Context.STATIC), 207 EnumSet.of(ClassData.Package.DIFFERENT)), 208 Template.MethodrefEqualsExpected, 209 Template.CallsiteUnrelatedToMethodref, 210 Template.TrivialObjectref), 211 /* Group 14: callsite unrelated to methodref, methodref = expected, 212 * expected is interface, expected and callsite not in the same package 213 */ 214 new TestGroup.Simple(initBuilder, 215 Template.ResultCombo(EnumSet.of(Template.Kind.INTERFACE), 216 EnumSet.of(MethodData.Access.PUBLIC), 217 EnumSet.of(MethodData.Context.STATIC), 218 EnumSet.of(ClassData.Package.DIFFERENT)), 219 Template.MethodrefEqualsExpected, 220 Template.CallsiteUnrelatedToMethodref, 221 Template.TrivialObjectref), 222 /* Group 15: callsite unrelated to methodref, methodref != expected, 223 * expected is class, expected and callsite not in the same package 224 */ 225 new TestGroup.Simple(initBuilder, 226 Template.ResultCombo(EnumSet.of(Template.Kind.CLASS), 227 EnumSet.of(MethodData.Access.PUBLIC), 228 EnumSet.of(MethodData.Context.STATIC), 229 EnumSet.of(ClassData.Package.DIFFERENT)), 230 Template.MethodrefNotEqualsExpectedClass, 231 Template.CallsiteUnrelatedToMethodref, 232 Template.TrivialObjectref) 233 ); 234 235 private InvokeStaticSuccessTest() { 236 super(testgroups); 237 } 238 239 public static void main(final String... args) { 240 new InvokeStaticSuccessTest().run(); 241 } 242 }