src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/FindUniqueDefaultMethodTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/FindUniqueDefaultMethodTest.java

Print this page




   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 package org.graalvm.compiler.core.test;
  24 
  25 import jdk.vm.ci.meta.Assumptions.AssumptionResult;
  26 import jdk.vm.ci.meta.ResolvedJavaMethod;
  27 import jdk.vm.ci.meta.ResolvedJavaType;
  28 
  29 import org.junit.Ignore;
  30 import org.junit.Test;
  31 
  32 import org.graalvm.compiler.debug.Debug;
  33 import org.graalvm.compiler.debug.Debug.Scope;
  34 import org.graalvm.compiler.nodes.ReturnNode;
  35 import org.graalvm.compiler.nodes.StructuredGraph;
  36 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;






  37 
  38 /**
  39  * This test illustrates problems and limitations with class hierarchy analysis when default methods
  40  * are involved.
  41  */
  42 public class FindUniqueDefaultMethodTest extends GraalCompilerTest {
  43 
  44     interface Interface1 {
  45         default int v1() {
  46             return 1;
  47         }
  48     }
  49 
  50     static class Implementor1 implements Interface1 {
  51         int callV1() {
  52             return v1();
  53         }
  54     }
  55 
  56     static class Subclass1 extends Implementor1 {


 122 
 123     public int runDefault(Implementor2 i) {
 124         return i.callV1();
 125     }
 126 
 127     public int runInherited(Implementor2 i) {
 128         return i.callV2();
 129     }
 130 
 131     private void testConstantReturn(String name, Object value) {
 132         StructuredGraph result = buildGraph(name);
 133         ReturnNode ret = result.getNodes(ReturnNode.TYPE).first();
 134         assertDeepEquals(1, result.getNodes(ReturnNode.TYPE).count());
 135 
 136         assertDeepEquals(true, ret.result().isConstant());
 137         assertDeepEquals(value, ret.result().asJavaConstant().asBoxedPrimitive());
 138     }
 139 
 140     @SuppressWarnings("try")
 141     protected StructuredGraph buildGraph(final String snippet) {
 142         try (Scope s = Debug.scope("InstanceOfTest", getMetaAccess().lookupJavaMethod(getMethod(snippet)))) {
 143             StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);

 144             compile(graph.method(), graph);
 145             Debug.dump(Debug.BASIC_LEVEL, graph, snippet);
 146             return graph;
 147         } catch (Throwable e) {
 148             throw Debug.handle(e);
 149         }
 150     }
 151 }


   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 package org.graalvm.compiler.core.test;
  24 
  25 import org.graalvm.compiler.debug.DebugContext;








  26 import org.graalvm.compiler.nodes.ReturnNode;
  27 import org.graalvm.compiler.nodes.StructuredGraph;
  28 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  29 import org.junit.Ignore;
  30 import org.junit.Test;
  31 
  32 import jdk.vm.ci.meta.Assumptions.AssumptionResult;
  33 import jdk.vm.ci.meta.ResolvedJavaMethod;
  34 import jdk.vm.ci.meta.ResolvedJavaType;
  35 
  36 /**
  37  * This test illustrates problems and limitations with class hierarchy analysis when default methods
  38  * are involved.
  39  */
  40 public class FindUniqueDefaultMethodTest extends GraalCompilerTest {
  41 
  42     interface Interface1 {
  43         default int v1() {
  44             return 1;
  45         }
  46     }
  47 
  48     static class Implementor1 implements Interface1 {
  49         int callV1() {
  50             return v1();
  51         }
  52     }
  53 
  54     static class Subclass1 extends Implementor1 {


 120 
 121     public int runDefault(Implementor2 i) {
 122         return i.callV1();
 123     }
 124 
 125     public int runInherited(Implementor2 i) {
 126         return i.callV2();
 127     }
 128 
 129     private void testConstantReturn(String name, Object value) {
 130         StructuredGraph result = buildGraph(name);
 131         ReturnNode ret = result.getNodes(ReturnNode.TYPE).first();
 132         assertDeepEquals(1, result.getNodes(ReturnNode.TYPE).count());
 133 
 134         assertDeepEquals(true, ret.result().isConstant());
 135         assertDeepEquals(value, ret.result().asJavaConstant().asBoxedPrimitive());
 136     }
 137 
 138     @SuppressWarnings("try")
 139     protected StructuredGraph buildGraph(final String snippet) {
 140         DebugContext debug = getDebugContext();
 141         try (DebugContext.Scope s = debug.scope("InstanceOfTest", getMetaAccess().lookupJavaMethod(getMethod(snippet)))) {
 142             StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES, debug);
 143             compile(graph.method(), graph);
 144             debug.dump(DebugContext.BASIC_LEVEL, graph, snippet);
 145             return graph;
 146         } catch (Throwable e) {
 147             throw debug.handle(e);
 148         }
 149     }
 150 }
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/FindUniqueDefaultMethodTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File