src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/NodePropertiesTest.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/NodePropertiesTest.java

Print this page




   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.api.directives.GraalDirectives;
  26 import org.graalvm.compiler.debug.Debug;
  27 import org.graalvm.compiler.graph.Node;
  28 import org.graalvm.compiler.graph.iterators.NodeIterable;
  29 import org.graalvm.compiler.graph.spi.Canonicalizable;
  30 import org.graalvm.compiler.graph.spi.SimplifierTool;
  31 import org.graalvm.compiler.java.ComputeLoopFrequenciesClosure;
  32 import org.graalvm.compiler.nodes.LoopBeginNode;
  33 import org.graalvm.compiler.nodes.StructuredGraph;
  34 import org.graalvm.compiler.nodes.ValueNode;
  35 import org.graalvm.compiler.phases.BasePhase;
  36 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  37 import org.graalvm.compiler.phases.common.CanonicalizerPhase.CustomCanonicalizer;
  38 import org.graalvm.compiler.phases.contract.NodeCostUtil;
  39 import org.graalvm.compiler.phases.tiers.HighTierContext;
  40 import org.graalvm.compiler.phases.tiers.PhaseContext;
  41 import org.junit.Assert;
  42 import org.junit.Test;
  43 
  44 public class NodePropertiesTest extends GraalCompilerTest {
  45 
  46     public static Object sideEffect;


 179 
 180     private static void assertFrequency(StructuredGraph g, int iterations) {
 181         NodeIterable<LoopBeginNode> loopBeginNodes = g.getNodes(LoopBeginNode.TYPE);
 182         LoopBeginNode loopBeginNode = loopBeginNodes.first();
 183         Assert.assertEquals("loop frequency of " + loopBeginNode, iterations, loopBeginNode.loopFrequency(), 0);
 184     }
 185 
 186     @Test
 187     public void testDifferentLoopFaster() {
 188         HighTierContext htc = getDefaultHighTierContext();
 189         StructuredGraph g1 = parseForCompile(getResolvedJavaMethod("testLoop01"));
 190         StructuredGraph g2 = parseForCompile(getResolvedJavaMethod("testLoop03"));
 191         prepareGraphForLoopFrequencies(g1, htc);
 192         prepareGraphForLoopFrequencies(g2, htc);
 193         assertFrequency(g1, ITERATIONS_LOOP_1);
 194         assertFrequency(g2, ITERATIONS_LOOP_1);
 195         GraphCostPhase gc1 = new GraphCostPhase();
 196         GraphCostPhase gc2 = new GraphCostPhase();
 197         gc1.apply(g1, htc);
 198         gc2.apply(g2, htc);
 199         Debug.log("Test testDifferentLoopFaster --> 1.Graph cycles:%f size:%f vs. 2.Graph cycles:%f size:%f\n", gc1.finalCycles, gc1.finalSize, gc2.finalCycles, gc2.finalSize);
 200         Assert.assertTrue(gc2.finalCycles > gc1.finalCycles);
 201         Assert.assertTrue(gc2.finalSize == gc1.finalSize);
 202     }
 203 
 204     @Test
 205     public void testSameLoopMoreIterationsCostlier() {
 206         HighTierContext htc = getDefaultHighTierContext();
 207         StructuredGraph g1 = parseForCompile(getResolvedJavaMethod("testLoop01"));
 208         StructuredGraph g2 = parseForCompile(getResolvedJavaMethod("testLoop02"));
 209         prepareGraphForLoopFrequencies(g1, htc);
 210         prepareGraphForLoopFrequencies(g2, htc);
 211         assertFrequency(g1, ITERATIONS_LOOP_1);
 212         assertFrequency(g2, ITERATIONS_LOOP_2);
 213         GraphCostPhase gc1 = new GraphCostPhase();
 214         GraphCostPhase gc2 = new GraphCostPhase();
 215         gc1.apply(g1, htc);
 216         gc2.apply(g2, htc);
 217         Debug.log("Test testSameLoopMoreIterationsCostlier --> 1.Graph cycles:%f size:%f vs. 2.Graph cycles:%f size:%f\n", gc1.finalCycles, gc1.finalSize, gc2.finalCycles, gc2.finalSize);
 218         Assert.assertTrue(gc2.finalCycles > gc1.finalCycles);
 219         Assert.assertTrue(gc2.finalSize == gc1.finalSize);
 220     }
 221 
 222     @Test
 223     public void testDifferentLoopsInnerOuter() {
 224         HighTierContext htc = getDefaultHighTierContext();
 225         StructuredGraph g1 = parseForCompile(getResolvedJavaMethod("testLoop04"));
 226         StructuredGraph g2 = parseForCompile(getResolvedJavaMethod("testLoop05"));
 227         prepareGraphForLoopFrequencies(g1, htc);
 228         prepareGraphForLoopFrequencies(g2, htc);
 229         assertFrequency(g1, ITERATIONS_LOOP_1 * ITERATIONS_LOOP_2);
 230         GraphCostPhase gc1 = new GraphCostPhase();
 231         GraphCostPhase gc2 = new GraphCostPhase();
 232         gc1.apply(g1, htc);
 233         gc2.apply(g2, htc);
 234         Debug.log("Test testDifferentLoopsInnerOuter --> 1.Graph cycles:%f size:%f vs. 2.Graph cycles:%f size:%f\n", gc1.finalCycles, gc1.finalSize, gc2.finalCycles, gc2.finalSize);
 235         Assert.assertTrue(gc2.finalSize > gc1.finalSize);
 236     }
 237 
 238     @Test
 239     public void testGraphCost() {
 240         StructuredGraph g1 = parseForCompile(getResolvedJavaMethod("test1Snippet"));
 241         StructuredGraph g2 = parseForCompile(getResolvedJavaMethod("test2Snippet"));
 242         HighTierContext htc = getDefaultHighTierContext();
 243         new CanonicalizerPhase().apply(g1, htc);
 244         new CanonicalizerPhase().apply(g2, htc);
 245         GraphCostPhase gc1 = new GraphCostPhase();
 246         GraphCostPhase gc2 = new GraphCostPhase();
 247         gc1.apply(g1, htc);
 248         gc2.apply(g2, htc);
 249         Debug.log("Test Graph Cost --> 1.Graph cost:%f vs. 2.Graph cost:%f\n", gc1.finalCycles, gc2.finalCycles);
 250         Assert.assertTrue(gc2.finalCycles > gc1.finalCycles);
 251         Assert.assertTrue(gc2.finalSize == gc1.finalSize);
 252     }
 253 
 254     @Test
 255     public void testExpectUntrusted() {
 256         StructuredGraph g1 = parseForCompile(getResolvedJavaMethod("untrused01"));
 257         HighTierContext htc = getDefaultHighTierContext();
 258         new CanonicalizerPhase().apply(g1, htc);
 259         GraphCostPhase gc1 = new GraphCostPhase();
 260         gc1.apply(g1, htc);
 261     }
 262 
 263     @Test
 264     public void testArrayLoad() {
 265         StructuredGraph g1 = parseForCompile(getResolvedJavaMethod("arrayLoadTest"));
 266         HighTierContext htc = getDefaultHighTierContext();
 267         new CanonicalizerPhase().apply(g1, htc);
 268         GraphCostPhase gc1 = new GraphCostPhase();
 269         gc1.apply(g1, htc);




   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.api.directives.GraalDirectives;

  26 import org.graalvm.compiler.graph.Node;
  27 import org.graalvm.compiler.graph.iterators.NodeIterable;
  28 import org.graalvm.compiler.graph.spi.Canonicalizable;
  29 import org.graalvm.compiler.graph.spi.SimplifierTool;
  30 import org.graalvm.compiler.java.ComputeLoopFrequenciesClosure;
  31 import org.graalvm.compiler.nodes.LoopBeginNode;
  32 import org.graalvm.compiler.nodes.StructuredGraph;
  33 import org.graalvm.compiler.nodes.ValueNode;
  34 import org.graalvm.compiler.phases.BasePhase;
  35 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  36 import org.graalvm.compiler.phases.common.CanonicalizerPhase.CustomCanonicalizer;
  37 import org.graalvm.compiler.phases.contract.NodeCostUtil;
  38 import org.graalvm.compiler.phases.tiers.HighTierContext;
  39 import org.graalvm.compiler.phases.tiers.PhaseContext;
  40 import org.junit.Assert;
  41 import org.junit.Test;
  42 
  43 public class NodePropertiesTest extends GraalCompilerTest {
  44 
  45     public static Object sideEffect;


 178 
 179     private static void assertFrequency(StructuredGraph g, int iterations) {
 180         NodeIterable<LoopBeginNode> loopBeginNodes = g.getNodes(LoopBeginNode.TYPE);
 181         LoopBeginNode loopBeginNode = loopBeginNodes.first();
 182         Assert.assertEquals("loop frequency of " + loopBeginNode, iterations, loopBeginNode.loopFrequency(), 0);
 183     }
 184 
 185     @Test
 186     public void testDifferentLoopFaster() {
 187         HighTierContext htc = getDefaultHighTierContext();
 188         StructuredGraph g1 = parseForCompile(getResolvedJavaMethod("testLoop01"));
 189         StructuredGraph g2 = parseForCompile(getResolvedJavaMethod("testLoop03"));
 190         prepareGraphForLoopFrequencies(g1, htc);
 191         prepareGraphForLoopFrequencies(g2, htc);
 192         assertFrequency(g1, ITERATIONS_LOOP_1);
 193         assertFrequency(g2, ITERATIONS_LOOP_1);
 194         GraphCostPhase gc1 = new GraphCostPhase();
 195         GraphCostPhase gc2 = new GraphCostPhase();
 196         gc1.apply(g1, htc);
 197         gc2.apply(g2, htc);
 198         g1.getDebug().log("Test testDifferentLoopFaster --> 1.Graph cycles:%f size:%f vs. 2.Graph cycles:%f size:%f\n", gc1.finalCycles, gc1.finalSize, gc2.finalCycles, gc2.finalSize);
 199         Assert.assertTrue(gc2.finalCycles > gc1.finalCycles);
 200         Assert.assertTrue(gc2.finalSize == gc1.finalSize);
 201     }
 202 
 203     @Test
 204     public void testSameLoopMoreIterationsCostlier() {
 205         HighTierContext htc = getDefaultHighTierContext();
 206         StructuredGraph g1 = parseForCompile(getResolvedJavaMethod("testLoop01"));
 207         StructuredGraph g2 = parseForCompile(getResolvedJavaMethod("testLoop02"));
 208         prepareGraphForLoopFrequencies(g1, htc);
 209         prepareGraphForLoopFrequencies(g2, htc);
 210         assertFrequency(g1, ITERATIONS_LOOP_1);
 211         assertFrequency(g2, ITERATIONS_LOOP_2);
 212         GraphCostPhase gc1 = new GraphCostPhase();
 213         GraphCostPhase gc2 = new GraphCostPhase();
 214         gc1.apply(g1, htc);
 215         gc2.apply(g2, htc);
 216         g1.getDebug().log("Test testSameLoopMoreIterationsCostlier --> 1.Graph cycles:%f size:%f vs. 2.Graph cycles:%f size:%f\n", gc1.finalCycles, gc1.finalSize, gc2.finalCycles, gc2.finalSize);
 217         Assert.assertTrue(gc2.finalCycles > gc1.finalCycles);
 218         Assert.assertTrue(gc2.finalSize == gc1.finalSize);
 219     }
 220 
 221     @Test
 222     public void testDifferentLoopsInnerOuter() {
 223         HighTierContext htc = getDefaultHighTierContext();
 224         StructuredGraph g1 = parseForCompile(getResolvedJavaMethod("testLoop04"));
 225         StructuredGraph g2 = parseForCompile(getResolvedJavaMethod("testLoop05"));
 226         prepareGraphForLoopFrequencies(g1, htc);
 227         prepareGraphForLoopFrequencies(g2, htc);
 228         assertFrequency(g1, ITERATIONS_LOOP_1 * ITERATIONS_LOOP_2);
 229         GraphCostPhase gc1 = new GraphCostPhase();
 230         GraphCostPhase gc2 = new GraphCostPhase();
 231         gc1.apply(g1, htc);
 232         gc2.apply(g2, htc);
 233         g1.getDebug().log("Test testDifferentLoopsInnerOuter --> 1.Graph cycles:%f size:%f vs. 2.Graph cycles:%f size:%f\n", gc1.finalCycles, gc1.finalSize, gc2.finalCycles, gc2.finalSize);
 234         Assert.assertTrue(gc2.finalSize > gc1.finalSize);
 235     }
 236 
 237     @Test
 238     public void testGraphCost() {
 239         StructuredGraph g1 = parseForCompile(getResolvedJavaMethod("test1Snippet"));
 240         StructuredGraph g2 = parseForCompile(getResolvedJavaMethod("test2Snippet"));
 241         HighTierContext htc = getDefaultHighTierContext();
 242         new CanonicalizerPhase().apply(g1, htc);
 243         new CanonicalizerPhase().apply(g2, htc);
 244         GraphCostPhase gc1 = new GraphCostPhase();
 245         GraphCostPhase gc2 = new GraphCostPhase();
 246         gc1.apply(g1, htc);
 247         gc2.apply(g2, htc);
 248         g1.getDebug().log("Test Graph Cost --> 1.Graph cost:%f vs. 2.Graph cost:%f\n", gc1.finalCycles, gc2.finalCycles);
 249         Assert.assertTrue(gc2.finalCycles > gc1.finalCycles);
 250         Assert.assertTrue(gc2.finalSize == gc1.finalSize);
 251     }
 252 
 253     @Test
 254     public void testExpectUntrusted() {
 255         StructuredGraph g1 = parseForCompile(getResolvedJavaMethod("untrused01"));
 256         HighTierContext htc = getDefaultHighTierContext();
 257         new CanonicalizerPhase().apply(g1, htc);
 258         GraphCostPhase gc1 = new GraphCostPhase();
 259         gc1.apply(g1, htc);
 260     }
 261 
 262     @Test
 263     public void testArrayLoad() {
 264         StructuredGraph g1 = parseForCompile(getResolvedJavaMethod("arrayLoadTest"));
 265         HighTierContext htc = getDefaultHighTierContext();
 266         new CanonicalizerPhase().apply(g1, htc);
 267         GraphCostPhase gc1 = new GraphCostPhase();
 268         gc1.apply(g1, htc);


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