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

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph.test/src/org/graalvm/compiler/graph/test/NodeMapTest.java

Print this page




  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.graph.test;
  24 
  25 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_IGNORED;
  26 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_IGNORED;
  27 import static org.junit.Assert.assertEquals;
  28 import static org.junit.Assert.fail;
  29 
  30 import org.junit.Before;
  31 import org.junit.Test;
  32 
  33 import org.graalvm.compiler.api.test.Graal;

  34 import org.graalvm.compiler.graph.Graph;
  35 import org.graalvm.compiler.graph.Node;
  36 import org.graalvm.compiler.graph.NodeClass;
  37 import org.graalvm.compiler.graph.NodeMap;
  38 import org.graalvm.compiler.nodeinfo.NodeInfo;
  39 
  40 public class NodeMapTest {
  41 
  42     @NodeInfo(cycles = CYCLES_IGNORED, size = SIZE_IGNORED)
  43     static final class TestNode extends Node {
  44         public static final NodeClass<TestNode> TYPE = NodeClass.create(TestNode.class);
  45 
  46         protected TestNode() {
  47             super(TYPE);
  48         }
  49     }
  50 
  51     private Graph graph;
  52     private TestNode[] nodes = new TestNode[100];
  53     private NodeMap<Integer> map;
  54 
  55     @Before
  56     public void before() {
  57         // Need to initialize HotSpotGraalRuntime before any Node class is initialized.
  58         Graal.getRuntime();
  59 
  60         graph = new Graph();
  61         for (int i = 0; i < nodes.length; i++) {
  62             nodes[i] = graph.add(new TestNode());
  63         }
  64         map = new NodeMap<>(graph);
  65         for (int i = 0; i < nodes.length; i += 2) {
  66             map.set(nodes[i], i);
  67         }
  68     }
  69 
  70     @Test
  71     public void testEmpty() {
  72         NodeMap<Integer> emptyMap = new NodeMap<>(graph);
  73         for (TestNode node : nodes) {
  74             assertEquals(null, emptyMap.get(node));
  75         }
  76     }
  77 
  78     @Test
  79     public void testSimple() {
  80         for (int i = 0; i < nodes.length; i++) {


  90     public void testSimpleChanged() {
  91         for (TestNode node : nodes) {
  92             map.set(node, 1);
  93         }
  94         for (TestNode node : nodes) {
  95             map.set(node, null);
  96         }
  97         for (int i = 0; i < nodes.length; i += 2) {
  98             map.set(nodes[i], i);
  99         }
 100 
 101         for (int i = 0; i < nodes.length; i++) {
 102             if ((i & 1) == 0) {
 103                 assertEquals((Integer) i, map.get(nodes[i]));
 104             } else {
 105                 assertEquals(null, map.get(nodes[i]));
 106             }
 107         }
 108     }
 109 
 110     @SuppressWarnings("all")
 111     private static boolean assertionsEnabled() {
 112         boolean assertionsEnabled = false;
 113         assert assertionsEnabled = true;
 114         return assertionsEnabled;
 115     }
 116 
 117     @Test
 118     public void testNewGet() {
 119         /*
 120          * Failing here is not required, but if this behavior changes, usages of get need to be
 121          * checked for compatibility.
 122          */
 123         TestNode newNode = graph.add(new TestNode());
 124         try {
 125             map.get(newNode);
 126             fail("expected " + (assertionsEnabled() ? AssertionError.class.getSimpleName() : ArrayIndexOutOfBoundsException.class.getSimpleName()));
 127         } catch (AssertionError ae) {
 128             // thrown when assertions are enabled
 129         } catch (ArrayIndexOutOfBoundsException e) {
 130             // thrown when assertions are disabled
 131         }
 132     }
 133 
 134     @Test
 135     public void testNewSet() {
 136         /*
 137          * Failing here is not required, but if this behavior changes, usages of set need to be
 138          * checked for compatibility.
 139          */
 140         TestNode newNode = graph.add(new TestNode());
 141         try {
 142             map.set(newNode, 1);
 143             fail("expected " + (assertionsEnabled() ? AssertionError.class.getSimpleName() : ArrayIndexOutOfBoundsException.class.getSimpleName()));
 144         } catch (AssertionError ae) {
 145             // thrown when assertions are enabled
 146         } catch (ArrayIndexOutOfBoundsException e) {
 147             // thrown when assertions are disabled
 148         }
 149     }
 150 
 151     @Test
 152     public void testNewGetAndGrow() {
 153         TestNode newNode = graph.add(new TestNode());
 154         assertEquals(null, map.getAndGrow(newNode));
 155     }
 156 
 157     @Test
 158     public void testNewSetAndGrow() {
 159         TestNode newNode = graph.add(new TestNode());
 160         map.setAndGrow(newNode, 1);
 161         assertEquals((Integer) 1, map.get(newNode));
 162     }
 163 }


  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.graph.test;
  24 
  25 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_IGNORED;
  26 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_IGNORED;
  27 import static org.junit.Assert.assertEquals;
  28 import static org.junit.Assert.fail;
  29 
  30 import org.junit.Before;
  31 import org.junit.Test;
  32 
  33 import org.graalvm.compiler.api.test.Graal;
  34 import org.graalvm.compiler.debug.Assertions;
  35 import org.graalvm.compiler.graph.Graph;
  36 import org.graalvm.compiler.graph.Node;
  37 import org.graalvm.compiler.graph.NodeClass;
  38 import org.graalvm.compiler.graph.NodeMap;
  39 import org.graalvm.compiler.nodeinfo.NodeInfo;
  40 
  41 public class NodeMapTest extends GraphTest {
  42 
  43     @NodeInfo(cycles = CYCLES_IGNORED, size = SIZE_IGNORED)
  44     static final class TestNode extends Node {
  45         public static final NodeClass<TestNode> TYPE = NodeClass.create(TestNode.class);
  46 
  47         protected TestNode() {
  48             super(TYPE);
  49         }
  50     }
  51 
  52     private Graph graph;
  53     private TestNode[] nodes = new TestNode[100];
  54     private NodeMap<Integer> map;
  55 
  56     @Before
  57     public void before() {
  58         // Need to initialize HotSpotGraalRuntime before any Node class is initialized.
  59         Graal.getRuntime();
  60 
  61         graph = new Graph(getOptions());
  62         for (int i = 0; i < nodes.length; i++) {
  63             nodes[i] = graph.add(new TestNode());
  64         }
  65         map = new NodeMap<>(graph);
  66         for (int i = 0; i < nodes.length; i += 2) {
  67             map.set(nodes[i], i);
  68         }
  69     }
  70 
  71     @Test
  72     public void testEmpty() {
  73         NodeMap<Integer> emptyMap = new NodeMap<>(graph);
  74         for (TestNode node : nodes) {
  75             assertEquals(null, emptyMap.get(node));
  76         }
  77     }
  78 
  79     @Test
  80     public void testSimple() {
  81         for (int i = 0; i < nodes.length; i++) {


  91     public void testSimpleChanged() {
  92         for (TestNode node : nodes) {
  93             map.set(node, 1);
  94         }
  95         for (TestNode node : nodes) {
  96             map.set(node, null);
  97         }
  98         for (int i = 0; i < nodes.length; i += 2) {
  99             map.set(nodes[i], i);
 100         }
 101 
 102         for (int i = 0; i < nodes.length; i++) {
 103             if ((i & 1) == 0) {
 104                 assertEquals((Integer) i, map.get(nodes[i]));
 105             } else {
 106                 assertEquals(null, map.get(nodes[i]));
 107             }
 108         }
 109     }
 110 







 111     @Test
 112     public void testNewGet() {
 113         /*
 114          * Failing here is not required, but if this behavior changes, usages of get need to be
 115          * checked for compatibility.
 116          */
 117         TestNode newNode = graph.add(new TestNode());
 118         try {
 119             map.get(newNode);
 120             fail("expected " + (Assertions.ENABLED ? AssertionError.class.getSimpleName() : ArrayIndexOutOfBoundsException.class.getSimpleName()));
 121         } catch (AssertionError ae) {
 122             // thrown when assertions are enabled
 123         } catch (ArrayIndexOutOfBoundsException e) {
 124             // thrown when assertions are disabled
 125         }
 126     }
 127 
 128     @Test
 129     public void testNewSet() {
 130         /*
 131          * Failing here is not required, but if this behavior changes, usages of set need to be
 132          * checked for compatibility.
 133          */
 134         TestNode newNode = graph.add(new TestNode());
 135         try {
 136             map.set(newNode, 1);
 137             fail("expected " + (Assertions.ENABLED ? AssertionError.class.getSimpleName() : ArrayIndexOutOfBoundsException.class.getSimpleName()));
 138         } catch (AssertionError ae) {
 139             // thrown when assertions are enabled
 140         } catch (ArrayIndexOutOfBoundsException e) {
 141             // thrown when assertions are disabled
 142         }
 143     }
 144 
 145     @Test
 146     public void testNewGetAndGrow() {
 147         TestNode newNode = graph.add(new TestNode());
 148         assertEquals(null, map.getAndGrow(newNode));
 149     }
 150 
 151     @Test
 152     public void testNewSetAndGrow() {
 153         TestNode newNode = graph.add(new TestNode());
 154         map.setAndGrow(newNode, 1);
 155         assertEquals((Integer) 1, map.get(newNode));
 156     }
 157 }
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph.test/src/org/graalvm/compiler/graph/test/NodeMapTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File