< prev index next >

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

Print this page
rev 52889 : 8214023: Update Graal
   1 /*
   2  * Copyright (c) 2017, 2017, 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.lang.reflect.Field;
  28 
  29 import org.graalvm.compiler.core.common.GraalOptions;
  30 import org.graalvm.compiler.core.test.GraalCompilerTest;
  31 import org.graalvm.compiler.nodes.StructuredGraph;
  32 import org.graalvm.compiler.nodes.extended.RawLoadNode;
  33 import org.graalvm.compiler.nodes.extended.RawStoreNode;
  34 import org.graalvm.compiler.nodes.virtual.CommitAllocationNode;
  35 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  36 import org.graalvm.compiler.phases.common.inlining.InliningPhase;
  37 import org.graalvm.compiler.phases.tiers.HighTierContext;
  38 import org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase;
  39 import org.junit.Test;
  40 
  41 import sun.misc.Unsafe;
  42 
  43 public class TrufflePEATest extends GraalCompilerTest {
  44 
  45     /**
  46      * This class mimics the behavior of {@code FrameWithoutBoxing}.
  47      */
  48     static class Frame {
  49         long[] primitiveLocals;
  50 
  51         Frame(int size) {
  52             primitiveLocals = new long[size];
  53         }
  54     }
  55 
  56     /**


 106 
 107     public static long newFrame(long v) {
 108         Frame frame = new Frame(FRAME_SIZE);
 109         // Testing unsafe accesses with other kinds requires special handling of the initialized
 110         // entry kind.
 111         UNSAFE.putLong(frame.primitiveLocals, offsetLong1, v);
 112         return UNSAFE.getLong(frame.primitiveLocals, offsetLong1);
 113     }
 114 
 115     @Test
 116     public void testNewFrame() {
 117         StructuredGraph graph = processMethod("newFrame");
 118         assertDeepEquals(0, graph.getNodes().filter(CommitAllocationNode.class).count());
 119         assertDeepEquals(0, graph.getNodes().filter(RawLoadNode.class).count());
 120         assertDeepEquals(0, graph.getNodes().filter(RawStoreNode.class).count());
 121     }
 122 
 123     protected StructuredGraph processMethod(final String snippet) {
 124         StructuredGraph graph = parseEager(snippet, StructuredGraph.AllowAssumptions.NO);
 125         HighTierContext context = getDefaultHighTierContext();
 126         new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
 127         new PartialEscapePhase(true, true, new CanonicalizerPhase(), null, graph.getOptions()).apply(graph, context);
 128         return graph;
 129     }
 130 
 131     public static double accessDynamicObject(double v) {
 132         DynamicObject obj = new DynamicObject();
 133         UNSAFE.putDouble(obj, primitiveField0Offset, v);
 134         return UNSAFE.getDouble(obj, primitiveField0Offset);
 135     }
 136 
 137     @Test
 138     public void testAccessDynamicObject() {
 139         StructuredGraph graph = processMethod("accessDynamicObject");
 140         assertDeepEquals(0, graph.getNodes().filter(CommitAllocationNode.class).count());
 141         assertDeepEquals(0, graph.getNodes().filter(RawLoadNode.class).count());
 142         assertDeepEquals(0, graph.getNodes().filter(RawStoreNode.class).count());
 143     }
 144 
 145 }
   1 /*
   2  * Copyright (c) 2017, 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.lang.reflect.Field;
  28 
  29 import org.graalvm.compiler.core.common.GraalOptions;
  30 import org.graalvm.compiler.core.test.GraalCompilerTest;
  31 import org.graalvm.compiler.nodes.StructuredGraph;
  32 import org.graalvm.compiler.nodes.extended.RawLoadNode;
  33 import org.graalvm.compiler.nodes.extended.RawStoreNode;
  34 import org.graalvm.compiler.nodes.virtual.CommitAllocationNode;
  35 import org.graalvm.compiler.phases.common.CanonicalizerPhase;

  36 import org.graalvm.compiler.phases.tiers.HighTierContext;
  37 import org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase;
  38 import org.junit.Test;
  39 
  40 import sun.misc.Unsafe;
  41 
  42 public class TrufflePEATest extends GraalCompilerTest {
  43 
  44     /**
  45      * This class mimics the behavior of {@code FrameWithoutBoxing}.
  46      */
  47     static class Frame {
  48         long[] primitiveLocals;
  49 
  50         Frame(int size) {
  51             primitiveLocals = new long[size];
  52         }
  53     }
  54 
  55     /**


 105 
 106     public static long newFrame(long v) {
 107         Frame frame = new Frame(FRAME_SIZE);
 108         // Testing unsafe accesses with other kinds requires special handling of the initialized
 109         // entry kind.
 110         UNSAFE.putLong(frame.primitiveLocals, offsetLong1, v);
 111         return UNSAFE.getLong(frame.primitiveLocals, offsetLong1);
 112     }
 113 
 114     @Test
 115     public void testNewFrame() {
 116         StructuredGraph graph = processMethod("newFrame");
 117         assertDeepEquals(0, graph.getNodes().filter(CommitAllocationNode.class).count());
 118         assertDeepEquals(0, graph.getNodes().filter(RawLoadNode.class).count());
 119         assertDeepEquals(0, graph.getNodes().filter(RawStoreNode.class).count());
 120     }
 121 
 122     protected StructuredGraph processMethod(final String snippet) {
 123         StructuredGraph graph = parseEager(snippet, StructuredGraph.AllowAssumptions.NO);
 124         HighTierContext context = getDefaultHighTierContext();
 125         createInliningPhase().apply(graph, context);
 126         new PartialEscapePhase(true, true, new CanonicalizerPhase(), null, graph.getOptions()).apply(graph, context);
 127         return graph;
 128     }
 129 
 130     public static double accessDynamicObject(double v) {
 131         DynamicObject obj = new DynamicObject();
 132         UNSAFE.putDouble(obj, primitiveField0Offset, v);
 133         return UNSAFE.getDouble(obj, primitiveField0Offset);
 134     }
 135 
 136     @Test
 137     public void testAccessDynamicObject() {
 138         StructuredGraph graph = processMethod("accessDynamicObject");
 139         assertDeepEquals(0, graph.getNodes().filter(CommitAllocationNode.class).count());
 140         assertDeepEquals(0, graph.getNodes().filter(RawLoadNode.class).count());
 141         assertDeepEquals(0, graph.getNodes().filter(RawStoreNode.class).count());
 142     }
 143 
 144 }
< prev index next >