Mercurial > hg > graal-compiler
changeset 22639:18042e2d61b3
Update jvmci import: Add test exercising CHA with default methods
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Tue, 15 Sep 2015 22:35:17 -0700 |
parents | 70a4415a824b |
children | 6e7994809ab4 |
files | graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/FindUniqueDefaultMethodTest.java mx.graal/suite.py |
diffstat | 2 files changed, 152 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/FindUniqueDefaultMethodTest.java Tue Sep 15 22:35:17 2015 -0700 @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.compiler.test; + +import jdk.internal.jvmci.meta.Assumptions.AssumptionResult; +import jdk.internal.jvmci.meta.ResolvedJavaMethod; +import jdk.internal.jvmci.meta.ResolvedJavaType; + +import org.junit.Ignore; +import org.junit.Test; + +import com.oracle.graal.debug.Debug; +import com.oracle.graal.debug.Debug.Scope; +import com.oracle.graal.nodes.ReturnNode; +import com.oracle.graal.nodes.StructuredGraph; +import com.oracle.graal.nodes.StructuredGraph.AllowAssumptions; + +/** + * This test illustrates problems and limitations with class hierarchy analysis when default methods + * are involved. + */ +public class FindUniqueDefaultMethodTest extends GraalCompilerTest { + + interface Interface1 { + default int v1() { + return 1; + } + } + + static class Implementor1 implements Interface1 { + int callV1() { + return v1(); + } + } + + static class Subclass1 extends Implementor1 { + + } + + /** + * HotSpot has an internal mismatch with CHA and default methods. The initial query says that + * it's a unique method but the verification code that ensures that a dependence of this kind + * would pass will fail an assert in debug mode. + */ + @Test + public void testFindUnique() { + ResolvedJavaType cType = getMetaAccess().lookupJavaType(Implementor1.class); + cType.initialize(); + ResolvedJavaMethod v1Method = getMetaAccess().lookupJavaMethod(this.getMethod(Interface1.class, "v1")); + AssumptionResult<ResolvedJavaMethod> method = cType.findUniqueConcreteMethod(v1Method); + assertDeepEquals(null, method); + } + + interface Interface2 { + default int v1() { + return 1; + } + } + + static class Base2 { + public int v2() { + return 1; + } + } + + static class Implementor2 extends Base2 implements Interface2 { + int callV1() { + return v1(); + } + + int callV2() { + return v2(); + } + } + + static class Subclass2 extends Implementor2 { + + } + + /** + * This test illustrates a common pattern where a method at the root of a hierarchy is the only + * implementation and can be statically inlined. + */ + @SuppressWarnings("unused") + @Test + public void testInherited() { + Subclass2 s = new Subclass2(); + testConstantReturn("runInherited", 1); + } + + /** + * Test same pattern as above but using default methods instead. HotSpot doesn't allow this + * version to be optimized. + */ + @SuppressWarnings("unused") + @Test + @Ignore("HotSpot CHA doesn't treat default methods like regular methods") + public void testDefault() { + Subclass2 s = new Subclass2(); + testConstantReturn("runDefault", 1); + } + + public int runDefault(Implementor2 i) { + return i.callV1(); + } + + public int runInherited(Implementor2 i) { + return i.callV2(); + } + + private void testConstantReturn(String name, Object value) { + StructuredGraph result = buildGraph(name); + ReturnNode ret = result.getNodes(ReturnNode.TYPE).first(); + assertDeepEquals(1, result.getNodes(ReturnNode.TYPE).count()); + + assertDeepEquals(true, ret.result().isConstant()); + assertDeepEquals(value, ret.result().asJavaConstant().asBoxedPrimitive()); + } + + @SuppressWarnings("try") + protected StructuredGraph buildGraph(final String snippet) { + try (Scope s = Debug.scope("InstanceOfTest", getMetaAccess().lookupJavaMethod(getMethod(snippet)))) { + StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES); + compile(graph.method(), graph); + Debug.dump(graph, snippet); + return graph; + } catch (Throwable e) { + throw Debug.handle(e); + } + } +}
--- a/mx.graal/suite.py Wed Sep 16 01:09:19 2015 +0200 +++ b/mx.graal/suite.py Tue Sep 15 22:35:17 2015 -0700 @@ -6,7 +6,7 @@ "suites": [ { "name" : "jvmci", - "version" : "c345ad3a1cbb33587482209d5a0b106948c06f4e", + "version" : "94a604f431d35ab5c0f6b3632d94c3b98d35e2ef", "urls" : [ {"url" : "http://lafo.ssw.uni-linz.ac.at/hg/graal-jvmci-8", "kind" : "hg"}, {"url" : "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind" : "binary"},