Mercurial > hg > truffle
annotate graal/com.oracle.graal.graph.test/src/com/oracle/graal/graph/test/NodeMapTest.java @ 18226:6eda3b299460
Record compilation dependencies with +LogCompilation
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Fri, 31 Oct 2014 12:20:56 -0700 |
parents | 45b45f902bed |
children | f57d86eb036f |
rev | line source |
---|---|
15901 | 1 /* |
2 * Copyright (c) 2014, 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 package com.oracle.graal.graph.test; | |
24 | |
25 import static org.junit.Assert.*; | |
26 | |
27 import org.junit.*; | |
28 | |
17042
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
29 import com.oracle.graal.api.runtime.*; |
15901 | 30 import com.oracle.graal.graph.*; |
16895
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
15951
diff
changeset
|
31 import com.oracle.graal.nodeinfo.*; |
15901 | 32 |
33 public class NodeMapTest { | |
34 | |
16895
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
15951
diff
changeset
|
35 @NodeInfo |
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
15951
diff
changeset
|
36 static class TestNode extends Node { |
17309
845e881ce054
constructors in a Node class must be protected
Doug Simon <doug.simon@oracle.com>
parents:
17042
diff
changeset
|
37 protected TestNode() { |
16895
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
15951
diff
changeset
|
38 } |
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
15951
diff
changeset
|
39 |
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
15951
diff
changeset
|
40 public static TestNode create() { |
17450
45b45f902bed
removed Node generation (GRAAL-857)
Doug Simon <doug.simon@oracle.com>
parents:
17309
diff
changeset
|
41 return new TestNode(); |
16895
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
15951
diff
changeset
|
42 } |
15901 | 43 } |
44 | |
45 private Graph graph; | |
46 private TestNode[] nodes = new TestNode[100]; | |
47 private NodeMap<Integer> map; | |
48 | |
49 @Before | |
50 public void before() { | |
17042
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
51 // Need to initialize HotSpotGraalRuntime before any Node class is initialized. |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
52 Graal.getRuntime(); |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
53 |
15901 | 54 graph = new Graph(); |
55 for (int i = 0; i < nodes.length; i++) { | |
16895
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
15951
diff
changeset
|
56 nodes[i] = graph.add(TestNode.create()); |
15901 | 57 } |
58 map = new NodeMap<>(graph); | |
59 for (int i = 0; i < nodes.length; i += 2) { | |
60 map.set(nodes[i], i); | |
61 } | |
62 } | |
63 | |
64 @Test | |
65 public void testEmpty() { | |
66 NodeMap<Integer> emptyMap = new NodeMap<>(graph); | |
67 for (TestNode node : nodes) { | |
68 assertEquals(null, emptyMap.get(node)); | |
69 } | |
70 } | |
71 | |
72 @Test | |
73 public void testSimple() { | |
74 for (int i = 0; i < nodes.length; i++) { | |
75 if ((i & 1) == 0) { | |
76 assertEquals((Integer) i, map.get(nodes[i])); | |
77 } else { | |
78 assertEquals(null, map.get(nodes[i])); | |
79 } | |
80 } | |
81 } | |
82 | |
83 @Test | |
84 public void testSimpleChanged() { | |
85 for (TestNode node : nodes) { | |
86 map.set(node, 1); | |
87 } | |
88 for (TestNode node : nodes) { | |
89 map.set(node, null); | |
90 } | |
91 for (int i = 0; i < nodes.length; i += 2) { | |
92 map.set(nodes[i], i); | |
93 } | |
94 | |
95 for (int i = 0; i < nodes.length; i++) { | |
96 if ((i & 1) == 0) { | |
97 assertEquals((Integer) i, map.get(nodes[i])); | |
98 } else { | |
99 assertEquals(null, map.get(nodes[i])); | |
100 } | |
101 } | |
102 } | |
103 | |
17042
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
104 @SuppressWarnings("all") |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
105 private static boolean assertionsEnabled() { |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
106 boolean assertionsEnabled = false; |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
107 assert assertionsEnabled = true; |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
108 return assertionsEnabled; |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
109 } |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
110 |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
111 @Test |
15901 | 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 */ | |
16895
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
15951
diff
changeset
|
117 TestNode newNode = graph.add(TestNode.create()); |
17042
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
118 try { |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
119 map.get(newNode); |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
120 fail("expected " + (assertionsEnabled() ? AssertionError.class.getSimpleName() : ArrayIndexOutOfBoundsException.class.getSimpleName())); |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
121 } catch (AssertionError ae) { |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
122 // thrown when assertions are enabled |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
123 } catch (ArrayIndexOutOfBoundsException e) { |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
124 // thrown when assertions are disabled |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
125 } |
15901 | 126 } |
127 | |
17042
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
128 @Test |
15901 | 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 */ | |
16895
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
15951
diff
changeset
|
134 TestNode newNode = graph.add(TestNode.create()); |
17042
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
135 try { |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
136 map.set(newNode, 1); |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
137 fail("expected " + (assertionsEnabled() ? AssertionError.class.getSimpleName() : ArrayIndexOutOfBoundsException.class.getSimpleName())); |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
138 } catch (AssertionError ae) { |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
139 // thrown when assertions are enabled |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
140 } catch (ArrayIndexOutOfBoundsException e) { |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
141 // thrown when assertions are disabled |
9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
142 } |
15901 | 143 } |
144 | |
145 @Test | |
146 public void testNewGetAndGrow() { | |
16895
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
15951
diff
changeset
|
147 TestNode newNode = graph.add(TestNode.create()); |
15901 | 148 assertEquals(null, map.getAndGrow(newNode)); |
149 } | |
150 | |
151 @Test | |
152 public void testNewSetAndGrow() { | |
16895
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
15951
diff
changeset
|
153 TestNode newNode = graph.add(TestNode.create()); |
15901 | 154 map.setAndGrow(newNode, 1); |
155 assertEquals((Integer) 1, map.get(newNode)); | |
156 } | |
157 } |