Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/ObjectStampJoinTest.java @ 11394:40c7cbe31aa9
Simplify ObjectStamp.join and make sure there is no type/exact type when going to an allways null stamp
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Thu, 22 Aug 2013 14:06:25 +0200 |
parents | 9088d13767f3 |
children | 23ccaa863eda |
rev | line source |
---|---|
11265 | 1 /* |
2 * Copyright (c) 2013, 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.nodes.test; | |
24 | |
25 import org.junit.*; | |
26 | |
27 import com.oracle.graal.api.meta.*; | |
28 import com.oracle.graal.compiler.test.*; | |
29 import com.oracle.graal.nodes.type.*; | |
30 | |
11385
e119ba892b45
Rename StampTest to ObjectStampJoinTest and move IntegerStampTest to com.oracle.graal.nodes.test
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11265
diff
changeset
|
31 public class ObjectStampJoinTest extends GraalCompilerTest { |
11265 | 32 |
33 private static class A { | |
34 | |
35 } | |
36 | |
37 private static class B extends A { | |
38 | |
39 } | |
40 | |
41 private static class C extends B implements I { | |
42 | |
43 } | |
44 | |
45 private static class D extends A { | |
46 | |
47 } | |
48 | |
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
|
49 private abstract static class E extends A { |
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
|
50 |
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
|
51 } |
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
|
52 |
11265 | 53 private interface I { |
54 | |
55 } | |
56 | |
57 @Test | |
58 public void testJoin0() { | |
59 Stamp a = StampFactory.declared(getType(A.class)); | |
60 Stamp b = StampFactory.declared(getType(B.class)); | |
61 Assert.assertEquals(b, join(a, b)); | |
62 } | |
63 | |
64 @Test | |
65 public void testJoin1() { | |
66 Stamp aNonNull = StampFactory.declaredNonNull(getType(A.class)); | |
67 Stamp b = StampFactory.declared(getType(B.class)); | |
68 Stamp bNonNull = StampFactory.declaredNonNull(getType(B.class)); | |
69 Assert.assertEquals(bNonNull, join(aNonNull, b)); | |
70 } | |
71 | |
72 @Test | |
73 public void testJoin2() { | |
74 Stamp aExact = StampFactory.exactNonNull(getType(A.class)); | |
75 Stamp b = StampFactory.declared(getType(B.class)); | |
11387
9088d13767f3
Keep a kind in the illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11385
diff
changeset
|
76 Assert.assertEquals(StampFactory.illegal(Kind.Object), join(aExact, b)); |
11265 | 77 } |
78 | |
79 @Test | |
80 public void testJoin3() { | |
81 Stamp d = StampFactory.declared(getType(D.class)); | |
82 Stamp c = StampFactory.declared(getType(C.class)); | |
83 Assert.assertTrue(ObjectStamp.isObjectAlwaysNull(join(c, d))); | |
84 } | |
85 | |
86 @Test | |
87 public void testJoin4() { | |
88 Stamp dExactNonNull = StampFactory.exactNonNull(getType(D.class)); | |
89 Stamp c = StampFactory.declared(getType(C.class)); | |
11387
9088d13767f3
Keep a kind in the illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11385
diff
changeset
|
90 Assert.assertEquals(StampFactory.illegal(Kind.Object), join(c, dExactNonNull)); |
11265 | 91 } |
92 | |
93 @Test | |
94 public void testJoin5() { | |
95 Stamp dExact = StampFactory.exact(getType(D.class)); | |
96 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
|
97 Stamp join = join(c, dExact); |
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 Assert.assertTrue(ObjectStamp.isObjectAlwaysNull(join)); |
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 Assert.assertNull(ObjectStamp.typeOrNull(join)); |
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 Assert.assertFalse(ObjectStamp.isExactType(join)); |
11265 | 101 } |
102 | |
103 @Test | |
104 public void testJoin6() { | |
105 Stamp dExactNonNull = StampFactory.exactNonNull(getType(D.class)); | |
106 Stamp allwaysNull = StampFactory.alwaysNull(); | |
107 Stamp join = join(allwaysNull, dExactNonNull); | |
108 Assert.assertFalse(ObjectStamp.isObjectNonNull(join)); | |
109 Assert.assertFalse(ObjectStamp.isObjectAlwaysNull(join)); | |
110 } | |
111 | |
112 @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
|
113 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
|
114 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
|
115 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
|
116 Stamp join = join(aExact, e); |
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
|
117 Assert.assertTrue(ObjectStamp.isObjectAlwaysNull(join)); |
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
|
118 Assert.assertNull(ObjectStamp.typeOrNull(join)); |
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
|
119 Assert.assertFalse(ObjectStamp.isExactType(join)); |
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
|
120 } |
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
|
121 |
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
|
122 @Test |
11265 | 123 public void testJoinInterface0() { |
124 Stamp a = StampFactory.declared(getType(A.class)); | |
125 Stamp b = StampFactory.declared(getType(I.class)); | |
11387
9088d13767f3
Keep a kind in the illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11385
diff
changeset
|
126 Assert.assertNotSame(StampFactory.illegal(Kind.Object), join(a, b)); |
11265 | 127 } |
128 | |
129 @Test | |
130 public void testJoinInterface1() { | |
131 Stamp aNonNull = StampFactory.declaredNonNull(getType(A.class)); | |
132 Stamp i = StampFactory.declared(getType(I.class)); | |
133 Stamp join = join(aNonNull, i); | |
134 Assert.assertTrue(join instanceof ObjectStamp); | |
135 Assert.assertTrue(((ObjectStamp) join).nonNull()); | |
136 } | |
137 | |
138 @Test | |
139 public void testJoinInterface2() { | |
140 Stamp bExact = StampFactory.exactNonNull(getType(B.class)); | |
141 Stamp i = StampFactory.declared(getType(I.class)); | |
142 Stamp join = join(i, bExact); | |
11387
9088d13767f3
Keep a kind in the illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
11385
diff
changeset
|
143 Assert.assertEquals(StampFactory.illegal(Kind.Object), join); |
11265 | 144 } |
145 | |
146 private static Stamp join(Stamp a, Stamp b) { | |
147 Stamp ab = a.join(b); | |
148 Stamp ba = b.join(a); | |
149 Assert.assertEquals(ab, ba); | |
150 return ab; | |
151 } | |
152 | |
153 private ResolvedJavaType getType(Class<?> clazz) { | |
154 return runtime().lookupJavaType(clazz); | |
155 } | |
156 } |