Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/ObjectStampJoinTest.java @ 21556:48c1ebd24120
renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 27 May 2015 00:36:16 +0200 |
parents | 9a7125f0eeda |
children | 4f88bd1dbc61 |
rev | line source |
---|---|
11265 | 1 /* |
20928
35e1b66f2810
Rename Stamp.illegal() to Stamp.empty().
Roland Schatz <roland.schatz@oracle.com>
parents:
18490
diff
changeset
|
2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. |
11265 | 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.nodes.test; | |
24 | |
21556
48c1ebd24120
renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21212
diff
changeset
|
25 import com.oracle.jvmci.meta.Kind; |
11265 | 26 import org.junit.*; |
27 | |
15198
2c0cfbf454b5
Move LIRTypeTool and Stamp to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents:
14997
diff
changeset
|
28 import com.oracle.graal.compiler.common.type.*; |
11265 | 29 import com.oracle.graal.nodes.type.*; |
30 | |
17156
ac6e25901d62
Add trusted interface concept and use it for WordBase, fix a NPE and some tests
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15660
diff
changeset
|
31 public class ObjectStampJoinTest extends AbstractObjectStampTest { |
11265 | 32 |
15660
9c75a5e29052
tests for ObjectStamp.meet
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15524
diff
changeset
|
33 // class A |
9c75a5e29052
tests for ObjectStamp.meet
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15524
diff
changeset
|
34 // class B extends A |
9c75a5e29052
tests for ObjectStamp.meet
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15524
diff
changeset
|
35 // class C extends B implements I |
9c75a5e29052
tests for ObjectStamp.meet
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15524
diff
changeset
|
36 // class D extends A |
9c75a5e29052
tests for ObjectStamp.meet
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15524
diff
changeset
|
37 // abstract class E extends A |
9c75a5e29052
tests for ObjectStamp.meet
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15524
diff
changeset
|
38 // interface I |
11265 | 39 |
40 @Test | |
41 public void testJoin0() { | |
42 Stamp a = StampFactory.declared(getType(A.class)); | |
43 Stamp b = StampFactory.declared(getType(B.class)); | |
44 Assert.assertEquals(b, join(a, b)); | |
45 } | |
46 | |
47 @Test | |
48 public void testJoin1() { | |
49 Stamp aNonNull = StampFactory.declaredNonNull(getType(A.class)); | |
50 Stamp b = StampFactory.declared(getType(B.class)); | |
51 Stamp bNonNull = StampFactory.declaredNonNull(getType(B.class)); | |
52 Assert.assertEquals(bNonNull, join(aNonNull, b)); | |
53 } | |
54 | |
55 @Test | |
56 public void testJoin2() { | |
57 Stamp aExact = StampFactory.exactNonNull(getType(A.class)); | |
58 Stamp b = StampFactory.declared(getType(B.class)); | |
20928
35e1b66f2810
Rename Stamp.illegal() to Stamp.empty().
Roland Schatz <roland.schatz@oracle.com>
parents:
18490
diff
changeset
|
59 Assert.assertEquals(StampFactory.empty(Kind.Object), join(aExact, b)); |
11265 | 60 } |
61 | |
62 @Test | |
63 public void testJoin3() { | |
64 Stamp d = StampFactory.declared(getType(D.class)); | |
65 Stamp c = StampFactory.declared(getType(C.class)); | |
18490
ca81508f2a19
Generalize NULL handling to work on arbitrary pointers.
Roland Schatz <roland.schatz@oracle.com>
parents:
18416
diff
changeset
|
66 Assert.assertTrue(StampTool.isPointerAlwaysNull(join(c, d))); |
11265 | 67 } |
68 | |
69 @Test | |
70 public void testJoin4() { | |
71 Stamp dExactNonNull = StampFactory.exactNonNull(getType(D.class)); | |
72 Stamp c = StampFactory.declared(getType(C.class)); | |
20928
35e1b66f2810
Rename Stamp.illegal() to Stamp.empty().
Roland Schatz <roland.schatz@oracle.com>
parents:
18490
diff
changeset
|
73 Assert.assertEquals(StampFactory.empty(Kind.Object), join(c, dExactNonNull)); |
11265 | 74 } |
75 | |
76 @Test | |
77 public void testJoin5() { | |
78 Stamp dExact = StampFactory.exact(getType(D.class)); | |
79 Stamp c = StampFactory.declared(getType(C.class)); | |
11394
40c7cbe31aa9
Simplify ObjectStamp.join and make sure there is no type/exact type when going to an allways null stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11387
diff
changeset
|
80 Stamp join = join(c, dExact); |
18490
ca81508f2a19
Generalize NULL handling to work on arbitrary pointers.
Roland Schatz <roland.schatz@oracle.com>
parents:
18416
diff
changeset
|
81 Assert.assertTrue(StampTool.isPointerAlwaysNull(join)); |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
82 Assert.assertNull(StampTool.typeOrNull(join)); |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
83 Assert.assertFalse(StampTool.isExactType(join)); |
11265 | 84 } |
85 | |
86 @Test | |
87 public void testJoin6() { | |
88 Stamp dExactNonNull = StampFactory.exactNonNull(getType(D.class)); | |
14997
5e4ae8709830
Use typed illegal stamps and use IllegalStamp only for conflicting primitive types.
Roland Schatz <roland.schatz@oracle.com>
parents:
11959
diff
changeset
|
89 Stamp alwaysNull = StampFactory.alwaysNull(); |
5e4ae8709830
Use typed illegal stamps and use IllegalStamp only for conflicting primitive types.
Roland Schatz <roland.schatz@oracle.com>
parents:
11959
diff
changeset
|
90 Stamp join = join(alwaysNull, dExactNonNull); |
20928
35e1b66f2810
Rename Stamp.illegal() to Stamp.empty().
Roland Schatz <roland.schatz@oracle.com>
parents:
18490
diff
changeset
|
91 Assert.assertFalse(join.hasValues()); |
18490
ca81508f2a19
Generalize NULL handling to work on arbitrary pointers.
Roland Schatz <roland.schatz@oracle.com>
parents:
18416
diff
changeset
|
92 Assert.assertFalse(StampTool.isPointerNonNull(join)); |
ca81508f2a19
Generalize NULL handling to work on arbitrary pointers.
Roland Schatz <roland.schatz@oracle.com>
parents:
18416
diff
changeset
|
93 Assert.assertFalse(StampTool.isPointerAlwaysNull(join)); |
11265 | 94 } |
95 | |
96 @Test | |
11394
40c7cbe31aa9
Simplify ObjectStamp.join and make sure there is no type/exact type when going to an allways null stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11387
diff
changeset
|
97 public void testJoin7() { |
40c7cbe31aa9
Simplify ObjectStamp.join and make sure there is no type/exact type when going to an allways null stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11387
diff
changeset
|
98 Stamp aExact = StampFactory.exact(getType(A.class)); |
40c7cbe31aa9
Simplify ObjectStamp.join and make sure there is no type/exact type when going to an allways null stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11387
diff
changeset
|
99 Stamp e = StampFactory.declared(getType(E.class)); |
40c7cbe31aa9
Simplify ObjectStamp.join and make sure there is no type/exact type when going to an allways null stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11387
diff
changeset
|
100 Stamp join = join(aExact, e); |
18490
ca81508f2a19
Generalize NULL handling to work on arbitrary pointers.
Roland Schatz <roland.schatz@oracle.com>
parents:
18416
diff
changeset
|
101 Assert.assertTrue(StampTool.isPointerAlwaysNull(join)); |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
102 Assert.assertNull(StampTool.typeOrNull(join)); |
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
15198
diff
changeset
|
103 Assert.assertFalse(StampTool.isExactType(join)); |
11394
40c7cbe31aa9
Simplify ObjectStamp.join and make sure there is no type/exact type when going to an allways null stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11387
diff
changeset
|
104 } |
40c7cbe31aa9
Simplify ObjectStamp.join and make sure there is no type/exact type when going to an allways null stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11387
diff
changeset
|
105 |
40c7cbe31aa9
Simplify ObjectStamp.join and make sure there is no type/exact type when going to an allways null stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11387
diff
changeset
|
106 @Test |
15524
901b4440a451
Add two more ObjectStampJoinTest unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15260
diff
changeset
|
107 public void testJoin8() { |
901b4440a451
Add two more ObjectStampJoinTest unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15260
diff
changeset
|
108 Stamp bExact = StampFactory.exactNonNull(getType(B.class)); |
901b4440a451
Add two more ObjectStampJoinTest unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15260
diff
changeset
|
109 Stamp dExact = StampFactory.exact(getType(D.class)); |
901b4440a451
Add two more ObjectStampJoinTest unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15260
diff
changeset
|
110 Stamp join = join(bExact, dExact); |
20928
35e1b66f2810
Rename Stamp.illegal() to Stamp.empty().
Roland Schatz <roland.schatz@oracle.com>
parents:
18490
diff
changeset
|
111 Assert.assertFalse(join.hasValues()); |
15524
901b4440a451
Add two more ObjectStampJoinTest unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15260
diff
changeset
|
112 } |
901b4440a451
Add two more ObjectStampJoinTest unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15260
diff
changeset
|
113 |
901b4440a451
Add two more ObjectStampJoinTest unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15260
diff
changeset
|
114 @Test |
901b4440a451
Add two more ObjectStampJoinTest unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15260
diff
changeset
|
115 public void testJoin9() { |
901b4440a451
Add two more ObjectStampJoinTest unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15260
diff
changeset
|
116 Stamp bExact = StampFactory.exact(getType(B.class)); |
901b4440a451
Add two more ObjectStampJoinTest unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15260
diff
changeset
|
117 Stamp dExact = StampFactory.exact(getType(D.class)); |
901b4440a451
Add two more ObjectStampJoinTest unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15260
diff
changeset
|
118 Stamp join = join(bExact, dExact); |
18490
ca81508f2a19
Generalize NULL handling to work on arbitrary pointers.
Roland Schatz <roland.schatz@oracle.com>
parents:
18416
diff
changeset
|
119 Assert.assertTrue(StampTool.isPointerAlwaysNull(join)); |
15524
901b4440a451
Add two more ObjectStampJoinTest unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15260
diff
changeset
|
120 Assert.assertNull(StampTool.typeOrNull(join)); |
901b4440a451
Add two more ObjectStampJoinTest unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15260
diff
changeset
|
121 Assert.assertNull(StampTool.typeOrNull(join)); |
901b4440a451
Add two more ObjectStampJoinTest unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15260
diff
changeset
|
122 } |
901b4440a451
Add two more ObjectStampJoinTest unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15260
diff
changeset
|
123 |
901b4440a451
Add two more ObjectStampJoinTest unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
15260
diff
changeset
|
124 @Test |
21212
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
125 public void testJoinInterfaceSimple() { |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
126 // Tests joining of interface |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
127 testJoinInterface(A.class, B.class, I.class); |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
128 } |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
129 |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
130 @Test |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
131 public void testJoinInterfaceArray() { |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
132 // Tests joining of arrays interface |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
133 testJoinInterface(A[].class, B[].class, I[].class); |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
134 } |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
135 |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
136 @Test |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
137 public void testJoinInterfaceMultiArray() { |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
138 // Tests joining of multidimensional arrays of interface |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
139 testJoinInterface(A[][].class, B[][].class, I[][].class); |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
140 } |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
141 |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
142 private void testJoinInterface(Class<?> typeA, Class<?> typeB, Class<?> typeI) { |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
143 testJoinInterface0(typeA, typeI); |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
144 testJoinInterface1(typeA, typeI); |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
145 testJoinInterface2(typeB, typeI); |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
146 testJoinInterface3(typeB, typeI); |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
147 } |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
148 |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
149 private void testJoinInterface0(Class<?> typeA, Class<?> typeI) { |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
150 Stamp a = StampFactory.declared(getType(typeA)); |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
151 Stamp i = StampFactory.declaredTrusted(getType(typeI)); |
20928
35e1b66f2810
Rename Stamp.illegal() to Stamp.empty().
Roland Schatz <roland.schatz@oracle.com>
parents:
18490
diff
changeset
|
152 Assert.assertNotSame(StampFactory.empty(Kind.Object), join(a, i)); |
11265 | 153 } |
154 | |
21212
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
155 private void testJoinInterface1(Class<?> typeA, Class<?> typeI) { |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
156 Stamp aNonNull = StampFactory.declaredNonNull(getType(typeA)); |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
157 Stamp i = StampFactory.declaredTrusted(getType(typeI)); |
11265 | 158 Stamp join = join(aNonNull, i); |
159 Assert.assertTrue(join instanceof ObjectStamp); | |
160 Assert.assertTrue(((ObjectStamp) join).nonNull()); | |
161 } | |
162 | |
21212
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
163 private void testJoinInterface2(Class<?> typeB, Class<?> typeI) { |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
164 Stamp bExact = StampFactory.exactNonNull(getType(typeB)); |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
165 Stamp i = StampFactory.declaredTrusted(getType(typeI)); |
11265 | 166 Stamp join = join(i, bExact); |
20928
35e1b66f2810
Rename Stamp.illegal() to Stamp.empty().
Roland Schatz <roland.schatz@oracle.com>
parents:
18490
diff
changeset
|
167 Assert.assertEquals(StampFactory.empty(Kind.Object), join); |
11265 | 168 } |
169 | |
21212
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
170 private void testJoinInterface3(Class<?> typeB, Class<?> typeI) { |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
171 Stamp bExact = StampFactory.exactNonNull(getType(typeB)); |
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
172 Stamp i = StampFactory.declared(getType(typeI)); // not trusted |
17156
ac6e25901d62
Add trusted interface concept and use it for WordBase, fix a NPE and some tests
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15660
diff
changeset
|
173 Stamp join = join(i, bExact); |
ac6e25901d62
Add trusted interface concept and use it for WordBase, fix a NPE and some tests
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15660
diff
changeset
|
174 Assert.assertEquals(bExact, join); |
ac6e25901d62
Add trusted interface concept and use it for WordBase, fix a NPE and some tests
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
15660
diff
changeset
|
175 } |
21212
9a7125f0eeda
Add test for arrays of interface
Stefan Anzinger <stefan.anzinger@oracle.com>
parents:
20928
diff
changeset
|
176 |
11265 | 177 } |