< prev index next >

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

Print this page
rev 52889 : 8214023: Update Graal
   1 /*
   2  * Copyright (c) 2011, 2015, 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 package org.graalvm.compiler.core.test.ea;
  26 
  27 import java.util.List;
  28 
  29 import org.junit.Test;
  30 
  31 import org.graalvm.compiler.core.test.GraalCompilerTest;
  32 import org.graalvm.compiler.nodes.ProxyNode;
  33 import org.graalvm.compiler.nodes.ReturnNode;
  34 import org.graalvm.compiler.nodes.StructuredGraph;
  35 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  36 import org.graalvm.compiler.nodes.ValueNode;
  37 import org.graalvm.compiler.nodes.ValuePhiNode;
  38 import org.graalvm.compiler.nodes.java.LoadFieldNode;
  39 import org.graalvm.compiler.nodes.java.StoreFieldNode;
  40 import org.graalvm.compiler.nodes.memory.ReadNode;
  41 import org.graalvm.compiler.nodes.spi.LoweringTool;
  42 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  43 import org.graalvm.compiler.phases.common.LoweringPhase;
  44 import org.graalvm.compiler.phases.common.inlining.InliningPhase;
  45 import org.graalvm.compiler.phases.tiers.HighTierContext;
  46 import org.graalvm.compiler.virtual.phases.ea.EarlyReadEliminationPhase;

  47 
  48 public class EarlyReadEliminationTest extends GraalCompilerTest {
  49 
  50     public static Object staticField;
  51 
  52     public static class TestObject {
  53 
  54         public int x;
  55         public int y;
  56 
  57         public TestObject(int x, int y) {
  58             this.x = x;
  59             this.y = y;
  60         }
  61     }
  62 
  63     public static class TestObject2 {
  64 
  65         public Object x;
  66         public Object y;


 247         }
 248         sum += o.x;
 249         return sum;
 250     }
 251 
 252     @Test
 253     public void testValueProxy() {
 254         StructuredGraph graph = processMethod("testValueProxySnippet", false);
 255         assertDeepEquals(2, graph.getNodes().filter(LoadFieldNode.class).count());
 256     }
 257 
 258     ReturnNode getReturn(String snippet, boolean doLowering) {
 259         StructuredGraph graph = processMethod(snippet, doLowering);
 260         assertDeepEquals(1, graph.getNodes(ReturnNode.TYPE).count());
 261         return graph.getNodes(ReturnNode.TYPE).first();
 262     }
 263 
 264     protected StructuredGraph processMethod(String snippet, boolean doLowering) {
 265         StructuredGraph graph = parseEager(getResolvedJavaMethod(snippet), AllowAssumptions.NO);
 266         HighTierContext context = getDefaultHighTierContext();
 267         new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
 268         if (doLowering) {
 269             new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
 270         }
 271         new EarlyReadEliminationPhase(new CanonicalizerPhase()).apply(graph, context);
 272         return graph;
 273     }
 274 }
   1 /*
   2  * Copyright (c) 2011, 2018, 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 package org.graalvm.compiler.core.test.ea;
  26 
  27 import java.util.List;
  28 


  29 import org.graalvm.compiler.core.test.GraalCompilerTest;
  30 import org.graalvm.compiler.nodes.ProxyNode;
  31 import org.graalvm.compiler.nodes.ReturnNode;
  32 import org.graalvm.compiler.nodes.StructuredGraph;
  33 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  34 import org.graalvm.compiler.nodes.ValueNode;
  35 import org.graalvm.compiler.nodes.ValuePhiNode;
  36 import org.graalvm.compiler.nodes.java.LoadFieldNode;
  37 import org.graalvm.compiler.nodes.java.StoreFieldNode;
  38 import org.graalvm.compiler.nodes.memory.ReadNode;
  39 import org.graalvm.compiler.nodes.spi.LoweringTool;
  40 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  41 import org.graalvm.compiler.phases.common.LoweringPhase;

  42 import org.graalvm.compiler.phases.tiers.HighTierContext;
  43 import org.graalvm.compiler.virtual.phases.ea.EarlyReadEliminationPhase;
  44 import org.junit.Test;
  45 
  46 public class EarlyReadEliminationTest extends GraalCompilerTest {
  47 
  48     public static Object staticField;
  49 
  50     public static class TestObject {
  51 
  52         public int x;
  53         public int y;
  54 
  55         public TestObject(int x, int y) {
  56             this.x = x;
  57             this.y = y;
  58         }
  59     }
  60 
  61     public static class TestObject2 {
  62 
  63         public Object x;
  64         public Object y;


 245         }
 246         sum += o.x;
 247         return sum;
 248     }
 249 
 250     @Test
 251     public void testValueProxy() {
 252         StructuredGraph graph = processMethod("testValueProxySnippet", false);
 253         assertDeepEquals(2, graph.getNodes().filter(LoadFieldNode.class).count());
 254     }
 255 
 256     ReturnNode getReturn(String snippet, boolean doLowering) {
 257         StructuredGraph graph = processMethod(snippet, doLowering);
 258         assertDeepEquals(1, graph.getNodes(ReturnNode.TYPE).count());
 259         return graph.getNodes(ReturnNode.TYPE).first();
 260     }
 261 
 262     protected StructuredGraph processMethod(String snippet, boolean doLowering) {
 263         StructuredGraph graph = parseEager(getResolvedJavaMethod(snippet), AllowAssumptions.NO);
 264         HighTierContext context = getDefaultHighTierContext();
 265         createInliningPhase().apply(graph, context);
 266         if (doLowering) {
 267             new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
 268         }
 269         new EarlyReadEliminationPhase(new CanonicalizerPhase()).apply(graph, context);
 270         return graph;
 271     }
 272 }
< prev index next >