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