Mon, 21 Jan 2013 20:15:16 +0000
8005851: Remove support for synchronized interface methods
Summary: Synchronized default methods are no longer supported
Reviewed-by: jjg
rfield@1422 | 1 | /* |
katleman@1448 | 2 | * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
rfield@1422 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
rfield@1422 | 4 | * |
rfield@1422 | 5 | * This code is free software; you can redistribute it and/or modify it |
rfield@1422 | 6 | * under the terms of the GNU General Public License version 2 only, as |
rfield@1422 | 7 | * published by the Free Software Foundation. Oracle designates this |
rfield@1422 | 8 | * particular file as subject to the "Classpath" exception as provided |
rfield@1422 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
rfield@1422 | 10 | * |
rfield@1422 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
rfield@1422 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
rfield@1422 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
rfield@1422 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
rfield@1422 | 15 | * accompanied this code). |
rfield@1422 | 16 | * |
rfield@1422 | 17 | * You should have received a copy of the GNU General Public License version |
rfield@1422 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
rfield@1422 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
rfield@1422 | 20 | * |
rfield@1422 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
rfield@1422 | 22 | * or visit www.oracle.com if you need additional information or have any |
rfield@1422 | 23 | * questions. |
rfield@1422 | 24 | */ |
rfield@1422 | 25 | |
rfield@1422 | 26 | package org.openjdk.tests.vm; |
rfield@1422 | 27 | |
rfield@1422 | 28 | import java.util.*; |
rfield@1422 | 29 | |
rfield@1422 | 30 | import org.testng.ITestResult; |
rfield@1422 | 31 | import org.testng.annotations.Test; |
rfield@1422 | 32 | import org.testng.annotations.DataProvider; |
rfield@1422 | 33 | import org.testng.annotations.AfterMethod; |
rfield@1422 | 34 | import org.testng.annotations.AfterSuite; |
rfield@1422 | 35 | |
rfield@1422 | 36 | import org.openjdk.tests.separate.*; |
rfield@1422 | 37 | import org.openjdk.tests.separate.Compiler; |
rfield@1422 | 38 | |
rfield@1422 | 39 | import org.openjdk.tests.shapegen.Hierarchy; |
rfield@1422 | 40 | import org.openjdk.tests.shapegen.HierarchyGenerator; |
rfield@1422 | 41 | import org.openjdk.tests.shapegen.ClassCase; |
rfield@1422 | 42 | |
rfield@1422 | 43 | import static org.testng.Assert.*; |
rfield@1422 | 44 | import static org.openjdk.tests.separate.SourceModel.*; |
rfield@1422 | 45 | import static org.openjdk.tests.separate.SourceModel.Class; |
rfield@1422 | 46 | import static org.openjdk.tests.separate.SourceModel.Method; |
rfield@1422 | 47 | import static org.openjdk.tests.separate.SourceModel.Type; |
rfield@1422 | 48 | |
rfield@1422 | 49 | public class FDSeparateCompilationTest extends TestHarness { |
rfield@1422 | 50 | |
rfield@1422 | 51 | private static String EMPTY = "\"\""; |
rfield@1422 | 52 | |
rfield@1422 | 53 | public FDSeparateCompilationTest() { |
rfield@1422 | 54 | super(false, true); |
rfield@1422 | 55 | } |
rfield@1422 | 56 | |
rfield@1422 | 57 | @DataProvider(name = "allShapes", parallel = true) |
rfield@1422 | 58 | public Object[][] hierarchyGenerator() { |
rfield@1422 | 59 | ArrayList<Object[]> allCases = new ArrayList<>(); |
rfield@1422 | 60 | |
rfield@1422 | 61 | HierarchyGenerator hg = new HierarchyGenerator(); |
rfield@1422 | 62 | for (Object x : hg.getOK()) { |
rfield@1422 | 63 | allCases.add(new Object[]{x}); |
rfield@1422 | 64 | } |
rfield@1422 | 65 | for (Object x : hg.getErr()) { |
rfield@1422 | 66 | allCases.add(new Object[]{x}); |
rfield@1422 | 67 | } |
rfield@1422 | 68 | return allCases.toArray(new Object[0][]); |
rfield@1422 | 69 | } |
rfield@1422 | 70 | |
rfield@1422 | 71 | // The expected value obtained when invoking the method from the specified |
rfield@1422 | 72 | // class. If returns null, then an AbstractMethodError is expected. |
rfield@1422 | 73 | private static String getExpectedResult(ClassCase cc) { |
rfield@1422 | 74 | Set<ClassCase> provs = cc.get_mprov(); |
rfield@1422 | 75 | if (cc.get_mres() != null) { |
rfield@1422 | 76 | return cc.get_mres().getName(); |
rfield@1422 | 77 | } else if (provs != null && provs.size() == 1) { |
rfield@1422 | 78 | ClassCase cand = provs.iterator().next(); |
rfield@1422 | 79 | switch (cand.kind) { |
rfield@1422 | 80 | case CCONCRETE: |
rfield@1422 | 81 | case IDEFAULT: |
rfield@1422 | 82 | return cand.getName(); |
rfield@1422 | 83 | case CNONE: |
rfield@1422 | 84 | case IVAC: |
rfield@1422 | 85 | return getExpectedResult(cand); |
rfield@1422 | 86 | } |
rfield@1422 | 87 | } |
rfield@1422 | 88 | return null; |
rfield@1422 | 89 | } |
rfield@1422 | 90 | |
rfield@1422 | 91 | private static final ConcreteMethod canonicalMethod = new ConcreteMethod( |
rfield@1422 | 92 | "String", "m", "returns " + EMPTY + ";", AccessFlag.PUBLIC); |
rfield@1422 | 93 | |
rfield@1422 | 94 | @Test(groups = "vm", dataProvider = "allShapes") |
rfield@1422 | 95 | public void separateCompilationTest(Hierarchy hs) { |
rfield@1422 | 96 | ClassCase cc = hs.root; |
rfield@1422 | 97 | Type type = sourceTypeFrom(hs.root); |
rfield@1422 | 98 | |
rfield@1422 | 99 | Class specimen = null; |
rfield@1422 | 100 | if (type instanceof Class) { |
rfield@1422 | 101 | Class ctype = (Class)type; |
rfield@1422 | 102 | if (ctype.isAbstract()) { |
rfield@1422 | 103 | specimen = new Class("Test" + ctype.getName(), ctype); |
rfield@1422 | 104 | } else { |
rfield@1422 | 105 | specimen = ctype; |
rfield@1422 | 106 | } |
rfield@1422 | 107 | } else { |
rfield@1422 | 108 | specimen = new Class("Test" + type.getName(), (Interface)type); |
rfield@1422 | 109 | } |
rfield@1422 | 110 | |
rfield@1422 | 111 | String value = getExpectedResult(cc); |
rfield@1422 | 112 | if (value != null) { |
rfield@1422 | 113 | assertInvokeVirtualEquals(value, specimen, canonicalMethod, EMPTY); |
rfield@1422 | 114 | } else { |
rfield@1422 | 115 | assertThrows(AbstractMethodError.class, specimen, |
rfield@1422 | 116 | canonicalMethod, EMPTY); |
rfield@1422 | 117 | } |
rfield@1422 | 118 | } |
rfield@1422 | 119 | |
rfield@1422 | 120 | @AfterMethod |
rfield@1422 | 121 | public void printCaseError(ITestResult result) { |
rfield@1422 | 122 | if (result.getStatus() == ITestResult.FAILURE) { |
rfield@1422 | 123 | Hierarchy hs = (Hierarchy)result.getParameters()[0]; |
rfield@1422 | 124 | System.out.println("Separate compilation case " + hs); |
rfield@1422 | 125 | printCaseDetails(hs); |
rfield@1422 | 126 | } |
rfield@1422 | 127 | } |
rfield@1422 | 128 | |
rfield@1422 | 129 | @AfterSuite |
rfield@1422 | 130 | public void cleanupCompilerCache() { |
rfield@1422 | 131 | Compiler.purgeCache(); |
rfield@1422 | 132 | } |
rfield@1422 | 133 | |
rfield@1422 | 134 | private void printCaseDetails(Hierarchy hs) { |
rfield@1422 | 135 | String exp = getExpectedResult(hs.root); |
rfield@1422 | 136 | for (String s : hs.getDescription()) { |
rfield@1422 | 137 | System.out.println(" " + s); |
rfield@1422 | 138 | } |
rfield@1422 | 139 | if (exp != null) { |
rfield@1422 | 140 | System.out.println(" Expected \"" + exp + "\""); |
rfield@1422 | 141 | } else { |
rfield@1422 | 142 | System.out.println(" Expected AbstractMethodError"); |
rfield@1422 | 143 | } |
rfield@1422 | 144 | } |
rfield@1422 | 145 | |
rfield@1422 | 146 | private Type sourceTypeFrom(ClassCase cc) { |
rfield@1422 | 147 | Type type = null; |
rfield@1422 | 148 | |
rfield@1422 | 149 | if (cc.isInterface()) { |
rfield@1422 | 150 | Interface iface = new Interface(cc.getName()); |
rfield@1422 | 151 | for (ClassCase scc : cc.getInterfaces()) { |
rfield@1422 | 152 | Interface supertype = (Interface)sourceTypeFrom(scc); |
rfield@1422 | 153 | iface.addSuperType(supertype); |
rfield@1422 | 154 | } |
rfield@1422 | 155 | type = iface; |
rfield@1422 | 156 | } else { |
rfield@1422 | 157 | Class cls = new Class(cc.getName()); |
rfield@1422 | 158 | if (cc.hasSuperclass()) { |
rfield@1422 | 159 | Class superc = (Class)sourceTypeFrom(cc.getSuperclass()); |
rfield@1422 | 160 | cls.setSuperClass(superc); |
rfield@1422 | 161 | } |
rfield@1422 | 162 | for (ClassCase scc : cc.getInterfaces()) { |
rfield@1422 | 163 | Interface supertype = (Interface)sourceTypeFrom(scc); |
rfield@1422 | 164 | cls.addSuperType(supertype); |
rfield@1422 | 165 | } |
rfield@1422 | 166 | if (cc.isAbstract()) { |
rfield@1422 | 167 | cls.getAccessFlags().add(AccessFlag.ABSTRACT); |
rfield@1422 | 168 | } |
rfield@1422 | 169 | type = cls; |
rfield@1422 | 170 | } |
rfield@1422 | 171 | Method method = methodFrom(cc); |
rfield@1422 | 172 | if (method != null) { |
rfield@1422 | 173 | type.addMethod(method); |
rfield@1422 | 174 | } |
rfield@1422 | 175 | return type; |
rfield@1422 | 176 | } |
rfield@1422 | 177 | |
rfield@1422 | 178 | private Method methodFrom(ClassCase cc) { |
rfield@1422 | 179 | switch (cc.kind) { |
rfield@1422 | 180 | case IVAC: |
rfield@1422 | 181 | case CNONE: return null; |
rfield@1422 | 182 | case IPRESENT: |
rfield@1422 | 183 | case CABSTRACT: |
rfield@1422 | 184 | return new AbstractMethod("String", "m", AccessFlag.PUBLIC); |
rfield@1422 | 185 | case IDEFAULT: |
rfield@1422 | 186 | return new DefaultMethod( |
rfield@1422 | 187 | "String", "m", "return \"" + cc.getName() + "\";"); |
rfield@1422 | 188 | case CCONCRETE: |
rfield@1422 | 189 | return new ConcreteMethod( |
rfield@1422 | 190 | "String", "m", "return \"" + cc.getName() + "\";", |
rfield@1422 | 191 | AccessFlag.PUBLIC); |
rfield@1422 | 192 | default: |
rfield@1422 | 193 | fail("Unknown method type in class"); |
rfield@1422 | 194 | return null; |
rfield@1422 | 195 | } |
rfield@1422 | 196 | } |
rfield@1422 | 197 | } |