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

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

Print this page




   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.ea;
  24 
  25 import java.util.List;
  26 
  27 import jdk.vm.ci.meta.JavaConstant;
  28 import jdk.vm.ci.meta.ResolvedJavaMethod;
  29 
  30 import org.junit.Assert;
  31 
  32 import org.graalvm.compiler.core.test.GraalCompilerTest;
  33 import org.graalvm.compiler.debug.Debug;
  34 import org.graalvm.compiler.debug.Debug.Scope;
  35 import org.graalvm.compiler.nodes.ReturnNode;
  36 import org.graalvm.compiler.nodes.StructuredGraph;
  37 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  38 import org.graalvm.compiler.nodes.java.NewArrayNode;
  39 import org.graalvm.compiler.nodes.java.NewInstanceNode;
  40 import org.graalvm.compiler.nodes.virtual.CommitAllocationNode;
  41 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  42 import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase;
  43 import org.graalvm.compiler.phases.common.inlining.InliningPhase;
  44 import org.graalvm.compiler.phases.tiers.HighTierContext;
  45 import org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase;




  46 
  47 //JaCoCo Exclude
  48 
  49 /**
  50  * This base class for all Escape Analysis tests does not contain tests itself, therefore it is not
  51  * automatically excluded from JaCoCo. Since it includes code that is used in the test snippets, it
  52  * needs to be excluded manually.
  53  */
  54 public class EATestBase extends GraalCompilerTest {
  55 
  56     public static class TestClassInt {
  57         public int x;
  58         public int y;
  59         public int z;
  60 
  61         public TestClassInt() {
  62             this(0, 0);
  63         }
  64 
  65         public TestClassInt(int x) {


 137      *            given constant return value
 138      * @param iterativeEscapeAnalysis true if escape analysis should be run for more than one
 139      *            iteration
 140      */
 141     protected void testEscapeAnalysis(String snippet, JavaConstant expectedConstantResult, boolean iterativeEscapeAnalysis) {
 142         prepareGraph(snippet, iterativeEscapeAnalysis);
 143         if (expectedConstantResult != null) {
 144             for (ReturnNode returnNode : returnNodes) {
 145                 Assert.assertTrue(returnNode.result().toString(), returnNode.result().isConstant());
 146                 Assert.assertEquals(expectedConstantResult, returnNode.result().asConstant());
 147             }
 148         }
 149         int newInstanceCount = graph.getNodes().filter(NewInstanceNode.class).count() + graph.getNodes().filter(NewArrayNode.class).count() +
 150                         graph.getNodes().filter(CommitAllocationNode.class).count();
 151         Assert.assertEquals(0, newInstanceCount);
 152     }
 153 
 154     @SuppressWarnings("try")
 155     protected void prepareGraph(String snippet, boolean iterativeEscapeAnalysis) {
 156         ResolvedJavaMethod method = getResolvedJavaMethod(snippet);
 157         try (Scope s = Debug.scope(getClass(), method, getCodeCache())) {
 158             graph = parseEager(method, AllowAssumptions.YES);

 159             context = getDefaultHighTierContext();
 160             new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
 161             new DeadCodeEliminationPhase().apply(graph);
 162             new CanonicalizerPhase().apply(graph, context);
 163             new PartialEscapePhase(iterativeEscapeAnalysis, false, new CanonicalizerPhase(), null, graph.getOptions()).apply(graph, context);
 164             returnNodes = graph.getNodes(ReturnNode.TYPE).snapshot();
 165         } catch (Throwable e) {
 166             throw Debug.handle(e);
 167         }
 168     }
 169 }


   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.ea;
  24 
  25 import java.util.List;
  26 





  27 import org.graalvm.compiler.core.test.GraalCompilerTest;
  28 import org.graalvm.compiler.debug.DebugContext;

  29 import org.graalvm.compiler.nodes.ReturnNode;
  30 import org.graalvm.compiler.nodes.StructuredGraph;
  31 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  32 import org.graalvm.compiler.nodes.java.NewArrayNode;
  33 import org.graalvm.compiler.nodes.java.NewInstanceNode;
  34 import org.graalvm.compiler.nodes.virtual.CommitAllocationNode;
  35 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  36 import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase;
  37 import org.graalvm.compiler.phases.common.inlining.InliningPhase;
  38 import org.graalvm.compiler.phases.tiers.HighTierContext;
  39 import org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase;
  40 import org.junit.Assert;
  41 
  42 import jdk.vm.ci.meta.JavaConstant;
  43 import jdk.vm.ci.meta.ResolvedJavaMethod;
  44 
  45 //JaCoCo Exclude
  46 
  47 /**
  48  * This base class for all Escape Analysis tests does not contain tests itself, therefore it is not
  49  * automatically excluded from JaCoCo. Since it includes code that is used in the test snippets, it
  50  * needs to be excluded manually.
  51  */
  52 public class EATestBase extends GraalCompilerTest {
  53 
  54     public static class TestClassInt {
  55         public int x;
  56         public int y;
  57         public int z;
  58 
  59         public TestClassInt() {
  60             this(0, 0);
  61         }
  62 
  63         public TestClassInt(int x) {


 135      *            given constant return value
 136      * @param iterativeEscapeAnalysis true if escape analysis should be run for more than one
 137      *            iteration
 138      */
 139     protected void testEscapeAnalysis(String snippet, JavaConstant expectedConstantResult, boolean iterativeEscapeAnalysis) {
 140         prepareGraph(snippet, iterativeEscapeAnalysis);
 141         if (expectedConstantResult != null) {
 142             for (ReturnNode returnNode : returnNodes) {
 143                 Assert.assertTrue(returnNode.result().toString(), returnNode.result().isConstant());
 144                 Assert.assertEquals(expectedConstantResult, returnNode.result().asConstant());
 145             }
 146         }
 147         int newInstanceCount = graph.getNodes().filter(NewInstanceNode.class).count() + graph.getNodes().filter(NewArrayNode.class).count() +
 148                         graph.getNodes().filter(CommitAllocationNode.class).count();
 149         Assert.assertEquals(0, newInstanceCount);
 150     }
 151 
 152     @SuppressWarnings("try")
 153     protected void prepareGraph(String snippet, boolean iterativeEscapeAnalysis) {
 154         ResolvedJavaMethod method = getResolvedJavaMethod(snippet);
 155         DebugContext debug = getDebugContext();
 156         try (DebugContext.Scope s = debug.scope(getClass(), method, getCodeCache())) {
 157             graph = parseEager(method, AllowAssumptions.YES, debug);
 158             context = getDefaultHighTierContext();
 159             new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
 160             new DeadCodeEliminationPhase().apply(graph);
 161             new CanonicalizerPhase().apply(graph, context);
 162             new PartialEscapePhase(iterativeEscapeAnalysis, false, new CanonicalizerPhase(), null, graph.getOptions()).apply(graph, context);
 163             returnNodes = graph.getNodes(ReturnNode.TYPE).snapshot();
 164         } catch (Throwable e) {
 165             throw debug.handle(e);
 166         }
 167     }
 168 }
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/ea/EATestBase.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File