blob: 2fecc8b25fa9a34ef569d177ee5169180142c071 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
Ian Rogers776ac1f2012-04-13 23:36:36 -07002 * Copyright (C) 2012 The Android Open Source Project
Elliott Hughes2faa5f12012-01-30 14:42:07 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
jeffhaoba5ebb92011-08-25 17:24:37 -070016
Ian Rogers776ac1f2012-04-13 23:36:36 -070017#include "reg_type.h"
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080018
19#include <set>
Elliott Hughes90a33692011-08-30 13:27:07 -070020
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -080021#include "base/casts.h"
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080022#include "common_runtime_test.h"
23#include "reg_type_cache-inl.h"
Ian Rogers7b078e82014-09-10 14:44:24 -070024#include "reg_type-inl.h"
Ian Rogerse63db272014-07-15 15:36:11 -070025#include "scoped_thread_state_change.h"
26#include "thread-inl.h"
jeffhaoba5ebb92011-08-25 17:24:37 -070027
28namespace art {
Ian Rogersd81871c2011-10-03 13:57:23 -070029namespace verifier {
jeffhaoba5ebb92011-08-25 17:24:37 -070030
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080031class RegTypeTest : public CommonRuntimeTest {};
Sameer Abu Asal998be612013-03-31 18:40:48 -070032
33TEST_F(RegTypeTest, ConstLoHi) {
34 // Tests creating primitive types types.
35 ScopedObjectAccess soa(Thread::Current());
36 RegTypeCache cache(true);
Ian Rogersd8f69b02014-09-10 21:43:52 +000037 const RegType& ref_type_const_0 = cache.FromCat1Const(10, true);
38 const RegType& ref_type_const_1 = cache.FromCat1Const(10, true);
39 const RegType& ref_type_const_2 = cache.FromCat1Const(30, true);
40 const RegType& ref_type_const_3 = cache.FromCat1Const(30, false);
Sameer Abu Asal998be612013-03-31 18:40:48 -070041 EXPECT_TRUE(ref_type_const_0.Equals(ref_type_const_1));
42 EXPECT_FALSE(ref_type_const_0.Equals(ref_type_const_2));
43 EXPECT_FALSE(ref_type_const_0.Equals(ref_type_const_3));
44
Ian Rogersd8f69b02014-09-10 21:43:52 +000045 const RegType& ref_type_const_wide_0 = cache.FromCat2ConstHi(50, true);
46 const RegType& ref_type_const_wide_1 = cache.FromCat2ConstHi(50, true);
Sameer Abu Asal998be612013-03-31 18:40:48 -070047 EXPECT_TRUE(ref_type_const_wide_0.Equals(ref_type_const_wide_1));
48
Ian Rogersd8f69b02014-09-10 21:43:52 +000049 const RegType& ref_type_const_wide_2 = cache.FromCat2ConstLo(50, true);
50 const RegType& ref_type_const_wide_3 = cache.FromCat2ConstLo(50, true);
51 const RegType& ref_type_const_wide_4 = cache.FromCat2ConstLo(55, true);
Sameer Abu Asal998be612013-03-31 18:40:48 -070052 EXPECT_TRUE(ref_type_const_wide_2.Equals(ref_type_const_wide_3));
53 EXPECT_FALSE(ref_type_const_wide_2.Equals(ref_type_const_wide_4));
54}
55
56TEST_F(RegTypeTest, Pairs) {
57 ScopedObjectAccess soa(Thread::Current());
58 RegTypeCache cache(true);
59 int64_t val = static_cast<int32_t>(1234);
Ian Rogersd8f69b02014-09-10 21:43:52 +000060 const RegType& precise_lo = cache.FromCat2ConstLo(static_cast<int32_t>(val), true);
61 const RegType& precise_hi = cache.FromCat2ConstHi(static_cast<int32_t>(val >> 32), true);
62 const RegType& precise_const = cache.FromCat1Const(static_cast<int32_t>(val >> 32), true);
63 const RegType& long_lo = cache.LongLo();
64 const RegType& long_hi = cache.LongHi();
Brian Carlstrom7934ac22013-07-26 10:54:15 -070065 // Check sanity of types.
Sameer Abu Asal998be612013-03-31 18:40:48 -070066 EXPECT_TRUE(precise_lo.IsLowHalf());
67 EXPECT_FALSE(precise_hi.IsLowHalf());
68 EXPECT_FALSE(precise_lo.IsHighHalf());
69 EXPECT_TRUE(precise_hi.IsHighHalf());
70 EXPECT_TRUE(long_hi.IsLongHighTypes());
71 EXPECT_TRUE(precise_hi.IsLongHighTypes());
72 // Check Pairing.
73 EXPECT_FALSE(precise_lo.CheckWidePair(precise_const));
74 EXPECT_TRUE(precise_lo.CheckWidePair(precise_hi));
75 // Test Merging.
76 EXPECT_TRUE((long_lo.Merge(precise_lo, &cache)).IsLongTypes());
77 EXPECT_TRUE((long_hi.Merge(precise_hi, &cache)).IsLongHighTypes());
78}
79
Ian Rogers776ac1f2012-04-13 23:36:36 -070080TEST_F(RegTypeTest, Primitives) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -070081 ScopedObjectAccess soa(Thread::Current());
Elliott Hughes80537bb2013-01-04 16:37:26 -080082 RegTypeCache cache(true);
Ian Rogersd81871c2011-10-03 13:57:23 -070083
Ian Rogersd8f69b02014-09-10 21:43:52 +000084 const RegType& bool_reg_type = cache.Boolean();
Ian Rogersad0b3a32012-04-16 14:50:24 -070085 EXPECT_FALSE(bool_reg_type.IsUndefined());
Ian Rogersd81871c2011-10-03 13:57:23 -070086 EXPECT_FALSE(bool_reg_type.IsConflict());
87 EXPECT_FALSE(bool_reg_type.IsZero());
88 EXPECT_FALSE(bool_reg_type.IsOne());
Ian Rogers84fa0742011-10-25 18:13:30 -070089 EXPECT_FALSE(bool_reg_type.IsLongConstant());
Ian Rogersd81871c2011-10-03 13:57:23 -070090 EXPECT_TRUE(bool_reg_type.IsBoolean());
91 EXPECT_FALSE(bool_reg_type.IsByte());
92 EXPECT_FALSE(bool_reg_type.IsChar());
93 EXPECT_FALSE(bool_reg_type.IsShort());
94 EXPECT_FALSE(bool_reg_type.IsInteger());
95 EXPECT_FALSE(bool_reg_type.IsLong());
96 EXPECT_FALSE(bool_reg_type.IsFloat());
97 EXPECT_FALSE(bool_reg_type.IsDouble());
98 EXPECT_FALSE(bool_reg_type.IsReference());
99 EXPECT_FALSE(bool_reg_type.IsLowHalf());
100 EXPECT_FALSE(bool_reg_type.IsHighHalf());
101 EXPECT_FALSE(bool_reg_type.IsLongOrDoubleTypes());
102 EXPECT_FALSE(bool_reg_type.IsReferenceTypes());
103 EXPECT_TRUE(bool_reg_type.IsCategory1Types());
104 EXPECT_FALSE(bool_reg_type.IsCategory2Types());
105 EXPECT_TRUE(bool_reg_type.IsBooleanTypes());
106 EXPECT_TRUE(bool_reg_type.IsByteTypes());
107 EXPECT_TRUE(bool_reg_type.IsShortTypes());
108 EXPECT_TRUE(bool_reg_type.IsCharTypes());
109 EXPECT_TRUE(bool_reg_type.IsIntegralTypes());
110 EXPECT_FALSE(bool_reg_type.IsFloatTypes());
111 EXPECT_FALSE(bool_reg_type.IsLongTypes());
112 EXPECT_FALSE(bool_reg_type.IsDoubleTypes());
113 EXPECT_TRUE(bool_reg_type.IsArrayIndexTypes());
Ian Rogers637c65b2013-05-31 11:46:00 -0700114 EXPECT_FALSE(bool_reg_type.IsNonZeroReferenceTypes());
Logan Chien10f0ca22014-09-23 23:01:47 +0800115 EXPECT_TRUE(bool_reg_type.HasClass());
Ian Rogersd81871c2011-10-03 13:57:23 -0700116
Ian Rogersd8f69b02014-09-10 21:43:52 +0000117 const RegType& byte_reg_type = cache.Byte();
Ian Rogersad0b3a32012-04-16 14:50:24 -0700118 EXPECT_FALSE(byte_reg_type.IsUndefined());
Ian Rogersd81871c2011-10-03 13:57:23 -0700119 EXPECT_FALSE(byte_reg_type.IsConflict());
120 EXPECT_FALSE(byte_reg_type.IsZero());
121 EXPECT_FALSE(byte_reg_type.IsOne());
Ian Rogers84fa0742011-10-25 18:13:30 -0700122 EXPECT_FALSE(byte_reg_type.IsLongConstant());
Ian Rogersd81871c2011-10-03 13:57:23 -0700123 EXPECT_FALSE(byte_reg_type.IsBoolean());
124 EXPECT_TRUE(byte_reg_type.IsByte());
125 EXPECT_FALSE(byte_reg_type.IsChar());
126 EXPECT_FALSE(byte_reg_type.IsShort());
127 EXPECT_FALSE(byte_reg_type.IsInteger());
128 EXPECT_FALSE(byte_reg_type.IsLong());
129 EXPECT_FALSE(byte_reg_type.IsFloat());
130 EXPECT_FALSE(byte_reg_type.IsDouble());
131 EXPECT_FALSE(byte_reg_type.IsReference());
132 EXPECT_FALSE(byte_reg_type.IsLowHalf());
133 EXPECT_FALSE(byte_reg_type.IsHighHalf());
134 EXPECT_FALSE(byte_reg_type.IsLongOrDoubleTypes());
135 EXPECT_FALSE(byte_reg_type.IsReferenceTypes());
136 EXPECT_TRUE(byte_reg_type.IsCategory1Types());
137 EXPECT_FALSE(byte_reg_type.IsCategory2Types());
138 EXPECT_FALSE(byte_reg_type.IsBooleanTypes());
139 EXPECT_TRUE(byte_reg_type.IsByteTypes());
140 EXPECT_TRUE(byte_reg_type.IsShortTypes());
141 EXPECT_FALSE(byte_reg_type.IsCharTypes());
142 EXPECT_TRUE(byte_reg_type.IsIntegralTypes());
143 EXPECT_FALSE(byte_reg_type.IsFloatTypes());
144 EXPECT_FALSE(byte_reg_type.IsLongTypes());
145 EXPECT_FALSE(byte_reg_type.IsDoubleTypes());
146 EXPECT_TRUE(byte_reg_type.IsArrayIndexTypes());
Ian Rogers637c65b2013-05-31 11:46:00 -0700147 EXPECT_FALSE(byte_reg_type.IsNonZeroReferenceTypes());
Logan Chien10f0ca22014-09-23 23:01:47 +0800148 EXPECT_TRUE(byte_reg_type.HasClass());
Ian Rogersd81871c2011-10-03 13:57:23 -0700149
Ian Rogersd8f69b02014-09-10 21:43:52 +0000150 const RegType& char_reg_type = cache.Char();
Ian Rogersad0b3a32012-04-16 14:50:24 -0700151 EXPECT_FALSE(char_reg_type.IsUndefined());
Ian Rogersd81871c2011-10-03 13:57:23 -0700152 EXPECT_FALSE(char_reg_type.IsConflict());
153 EXPECT_FALSE(char_reg_type.IsZero());
154 EXPECT_FALSE(char_reg_type.IsOne());
Ian Rogers84fa0742011-10-25 18:13:30 -0700155 EXPECT_FALSE(char_reg_type.IsLongConstant());
Ian Rogersd81871c2011-10-03 13:57:23 -0700156 EXPECT_FALSE(char_reg_type.IsBoolean());
157 EXPECT_FALSE(char_reg_type.IsByte());
158 EXPECT_TRUE(char_reg_type.IsChar());
159 EXPECT_FALSE(char_reg_type.IsShort());
160 EXPECT_FALSE(char_reg_type.IsInteger());
161 EXPECT_FALSE(char_reg_type.IsLong());
162 EXPECT_FALSE(char_reg_type.IsFloat());
163 EXPECT_FALSE(char_reg_type.IsDouble());
164 EXPECT_FALSE(char_reg_type.IsReference());
165 EXPECT_FALSE(char_reg_type.IsLowHalf());
166 EXPECT_FALSE(char_reg_type.IsHighHalf());
167 EXPECT_FALSE(char_reg_type.IsLongOrDoubleTypes());
168 EXPECT_FALSE(char_reg_type.IsReferenceTypes());
169 EXPECT_TRUE(char_reg_type.IsCategory1Types());
170 EXPECT_FALSE(char_reg_type.IsCategory2Types());
171 EXPECT_FALSE(char_reg_type.IsBooleanTypes());
172 EXPECT_FALSE(char_reg_type.IsByteTypes());
173 EXPECT_FALSE(char_reg_type.IsShortTypes());
174 EXPECT_TRUE(char_reg_type.IsCharTypes());
175 EXPECT_TRUE(char_reg_type.IsIntegralTypes());
176 EXPECT_FALSE(char_reg_type.IsFloatTypes());
177 EXPECT_FALSE(char_reg_type.IsLongTypes());
178 EXPECT_FALSE(char_reg_type.IsDoubleTypes());
179 EXPECT_TRUE(char_reg_type.IsArrayIndexTypes());
Ian Rogers637c65b2013-05-31 11:46:00 -0700180 EXPECT_FALSE(char_reg_type.IsNonZeroReferenceTypes());
Logan Chien10f0ca22014-09-23 23:01:47 +0800181 EXPECT_TRUE(char_reg_type.HasClass());
Ian Rogersd81871c2011-10-03 13:57:23 -0700182
Ian Rogersd8f69b02014-09-10 21:43:52 +0000183 const RegType& short_reg_type = cache.Short();
Ian Rogersad0b3a32012-04-16 14:50:24 -0700184 EXPECT_FALSE(short_reg_type.IsUndefined());
Ian Rogersd81871c2011-10-03 13:57:23 -0700185 EXPECT_FALSE(short_reg_type.IsConflict());
186 EXPECT_FALSE(short_reg_type.IsZero());
187 EXPECT_FALSE(short_reg_type.IsOne());
Ian Rogers84fa0742011-10-25 18:13:30 -0700188 EXPECT_FALSE(short_reg_type.IsLongConstant());
Ian Rogersd81871c2011-10-03 13:57:23 -0700189 EXPECT_FALSE(short_reg_type.IsBoolean());
190 EXPECT_FALSE(short_reg_type.IsByte());
191 EXPECT_FALSE(short_reg_type.IsChar());
192 EXPECT_TRUE(short_reg_type.IsShort());
193 EXPECT_FALSE(short_reg_type.IsInteger());
194 EXPECT_FALSE(short_reg_type.IsLong());
195 EXPECT_FALSE(short_reg_type.IsFloat());
196 EXPECT_FALSE(short_reg_type.IsDouble());
197 EXPECT_FALSE(short_reg_type.IsReference());
198 EXPECT_FALSE(short_reg_type.IsLowHalf());
199 EXPECT_FALSE(short_reg_type.IsHighHalf());
200 EXPECT_FALSE(short_reg_type.IsLongOrDoubleTypes());
201 EXPECT_FALSE(short_reg_type.IsReferenceTypes());
202 EXPECT_TRUE(short_reg_type.IsCategory1Types());
203 EXPECT_FALSE(short_reg_type.IsCategory2Types());
204 EXPECT_FALSE(short_reg_type.IsBooleanTypes());
205 EXPECT_FALSE(short_reg_type.IsByteTypes());
206 EXPECT_TRUE(short_reg_type.IsShortTypes());
207 EXPECT_FALSE(short_reg_type.IsCharTypes());
208 EXPECT_TRUE(short_reg_type.IsIntegralTypes());
209 EXPECT_FALSE(short_reg_type.IsFloatTypes());
210 EXPECT_FALSE(short_reg_type.IsLongTypes());
211 EXPECT_FALSE(short_reg_type.IsDoubleTypes());
212 EXPECT_TRUE(short_reg_type.IsArrayIndexTypes());
Ian Rogers637c65b2013-05-31 11:46:00 -0700213 EXPECT_FALSE(short_reg_type.IsNonZeroReferenceTypes());
Logan Chien10f0ca22014-09-23 23:01:47 +0800214 EXPECT_TRUE(short_reg_type.HasClass());
Ian Rogersd81871c2011-10-03 13:57:23 -0700215
Ian Rogersd8f69b02014-09-10 21:43:52 +0000216 const RegType& int_reg_type = cache.Integer();
Ian Rogersad0b3a32012-04-16 14:50:24 -0700217 EXPECT_FALSE(int_reg_type.IsUndefined());
Ian Rogersd81871c2011-10-03 13:57:23 -0700218 EXPECT_FALSE(int_reg_type.IsConflict());
219 EXPECT_FALSE(int_reg_type.IsZero());
220 EXPECT_FALSE(int_reg_type.IsOne());
Ian Rogers84fa0742011-10-25 18:13:30 -0700221 EXPECT_FALSE(int_reg_type.IsLongConstant());
Ian Rogersd81871c2011-10-03 13:57:23 -0700222 EXPECT_FALSE(int_reg_type.IsBoolean());
223 EXPECT_FALSE(int_reg_type.IsByte());
224 EXPECT_FALSE(int_reg_type.IsChar());
225 EXPECT_FALSE(int_reg_type.IsShort());
226 EXPECT_TRUE(int_reg_type.IsInteger());
227 EXPECT_FALSE(int_reg_type.IsLong());
228 EXPECT_FALSE(int_reg_type.IsFloat());
229 EXPECT_FALSE(int_reg_type.IsDouble());
230 EXPECT_FALSE(int_reg_type.IsReference());
231 EXPECT_FALSE(int_reg_type.IsLowHalf());
232 EXPECT_FALSE(int_reg_type.IsHighHalf());
233 EXPECT_FALSE(int_reg_type.IsLongOrDoubleTypes());
234 EXPECT_FALSE(int_reg_type.IsReferenceTypes());
235 EXPECT_TRUE(int_reg_type.IsCategory1Types());
236 EXPECT_FALSE(int_reg_type.IsCategory2Types());
237 EXPECT_FALSE(int_reg_type.IsBooleanTypes());
238 EXPECT_FALSE(int_reg_type.IsByteTypes());
239 EXPECT_FALSE(int_reg_type.IsShortTypes());
240 EXPECT_FALSE(int_reg_type.IsCharTypes());
241 EXPECT_TRUE(int_reg_type.IsIntegralTypes());
242 EXPECT_FALSE(int_reg_type.IsFloatTypes());
243 EXPECT_FALSE(int_reg_type.IsLongTypes());
244 EXPECT_FALSE(int_reg_type.IsDoubleTypes());
245 EXPECT_TRUE(int_reg_type.IsArrayIndexTypes());
Ian Rogers637c65b2013-05-31 11:46:00 -0700246 EXPECT_FALSE(int_reg_type.IsNonZeroReferenceTypes());
Logan Chien10f0ca22014-09-23 23:01:47 +0800247 EXPECT_TRUE(int_reg_type.HasClass());
Ian Rogersd81871c2011-10-03 13:57:23 -0700248
Ian Rogersd8f69b02014-09-10 21:43:52 +0000249 const RegType& long_reg_type = cache.LongLo();
Ian Rogersad0b3a32012-04-16 14:50:24 -0700250 EXPECT_FALSE(long_reg_type.IsUndefined());
Ian Rogersd81871c2011-10-03 13:57:23 -0700251 EXPECT_FALSE(long_reg_type.IsConflict());
252 EXPECT_FALSE(long_reg_type.IsZero());
253 EXPECT_FALSE(long_reg_type.IsOne());
Ian Rogers84fa0742011-10-25 18:13:30 -0700254 EXPECT_FALSE(long_reg_type.IsLongConstant());
Ian Rogersd81871c2011-10-03 13:57:23 -0700255 EXPECT_FALSE(long_reg_type.IsBoolean());
256 EXPECT_FALSE(long_reg_type.IsByte());
257 EXPECT_FALSE(long_reg_type.IsChar());
258 EXPECT_FALSE(long_reg_type.IsShort());
259 EXPECT_FALSE(long_reg_type.IsInteger());
260 EXPECT_TRUE(long_reg_type.IsLong());
261 EXPECT_FALSE(long_reg_type.IsFloat());
262 EXPECT_FALSE(long_reg_type.IsDouble());
263 EXPECT_FALSE(long_reg_type.IsReference());
264 EXPECT_TRUE(long_reg_type.IsLowHalf());
265 EXPECT_FALSE(long_reg_type.IsHighHalf());
266 EXPECT_TRUE(long_reg_type.IsLongOrDoubleTypes());
267 EXPECT_FALSE(long_reg_type.IsReferenceTypes());
268 EXPECT_FALSE(long_reg_type.IsCategory1Types());
269 EXPECT_TRUE(long_reg_type.IsCategory2Types());
270 EXPECT_FALSE(long_reg_type.IsBooleanTypes());
271 EXPECT_FALSE(long_reg_type.IsByteTypes());
272 EXPECT_FALSE(long_reg_type.IsShortTypes());
273 EXPECT_FALSE(long_reg_type.IsCharTypes());
274 EXPECT_FALSE(long_reg_type.IsIntegralTypes());
275 EXPECT_FALSE(long_reg_type.IsFloatTypes());
276 EXPECT_TRUE(long_reg_type.IsLongTypes());
277 EXPECT_FALSE(long_reg_type.IsDoubleTypes());
278 EXPECT_FALSE(long_reg_type.IsArrayIndexTypes());
Ian Rogers637c65b2013-05-31 11:46:00 -0700279 EXPECT_FALSE(long_reg_type.IsNonZeroReferenceTypes());
Logan Chien10f0ca22014-09-23 23:01:47 +0800280 EXPECT_TRUE(long_reg_type.HasClass());
Ian Rogersd81871c2011-10-03 13:57:23 -0700281
Ian Rogersd8f69b02014-09-10 21:43:52 +0000282 const RegType& float_reg_type = cache.Float();
Ian Rogersad0b3a32012-04-16 14:50:24 -0700283 EXPECT_FALSE(float_reg_type.IsUndefined());
Ian Rogersd81871c2011-10-03 13:57:23 -0700284 EXPECT_FALSE(float_reg_type.IsConflict());
285 EXPECT_FALSE(float_reg_type.IsZero());
286 EXPECT_FALSE(float_reg_type.IsOne());
Ian Rogers84fa0742011-10-25 18:13:30 -0700287 EXPECT_FALSE(float_reg_type.IsLongConstant());
Ian Rogersd81871c2011-10-03 13:57:23 -0700288 EXPECT_FALSE(float_reg_type.IsBoolean());
289 EXPECT_FALSE(float_reg_type.IsByte());
290 EXPECT_FALSE(float_reg_type.IsChar());
291 EXPECT_FALSE(float_reg_type.IsShort());
292 EXPECT_FALSE(float_reg_type.IsInteger());
293 EXPECT_FALSE(float_reg_type.IsLong());
294 EXPECT_TRUE(float_reg_type.IsFloat());
295 EXPECT_FALSE(float_reg_type.IsDouble());
296 EXPECT_FALSE(float_reg_type.IsReference());
297 EXPECT_FALSE(float_reg_type.IsLowHalf());
298 EXPECT_FALSE(float_reg_type.IsHighHalf());
299 EXPECT_FALSE(float_reg_type.IsLongOrDoubleTypes());
300 EXPECT_FALSE(float_reg_type.IsReferenceTypes());
301 EXPECT_TRUE(float_reg_type.IsCategory1Types());
302 EXPECT_FALSE(float_reg_type.IsCategory2Types());
303 EXPECT_FALSE(float_reg_type.IsBooleanTypes());
304 EXPECT_FALSE(float_reg_type.IsByteTypes());
305 EXPECT_FALSE(float_reg_type.IsShortTypes());
306 EXPECT_FALSE(float_reg_type.IsCharTypes());
307 EXPECT_FALSE(float_reg_type.IsIntegralTypes());
308 EXPECT_TRUE(float_reg_type.IsFloatTypes());
309 EXPECT_FALSE(float_reg_type.IsLongTypes());
310 EXPECT_FALSE(float_reg_type.IsDoubleTypes());
311 EXPECT_FALSE(float_reg_type.IsArrayIndexTypes());
Ian Rogers637c65b2013-05-31 11:46:00 -0700312 EXPECT_FALSE(float_reg_type.IsNonZeroReferenceTypes());
Logan Chien10f0ca22014-09-23 23:01:47 +0800313 EXPECT_TRUE(float_reg_type.HasClass());
Ian Rogersd81871c2011-10-03 13:57:23 -0700314
Ian Rogersd8f69b02014-09-10 21:43:52 +0000315 const RegType& double_reg_type = cache.DoubleLo();
Ian Rogersad0b3a32012-04-16 14:50:24 -0700316 EXPECT_FALSE(double_reg_type.IsUndefined());
Ian Rogersd81871c2011-10-03 13:57:23 -0700317 EXPECT_FALSE(double_reg_type.IsConflict());
318 EXPECT_FALSE(double_reg_type.IsZero());
319 EXPECT_FALSE(double_reg_type.IsOne());
Ian Rogers84fa0742011-10-25 18:13:30 -0700320 EXPECT_FALSE(double_reg_type.IsLongConstant());
Ian Rogersd81871c2011-10-03 13:57:23 -0700321 EXPECT_FALSE(double_reg_type.IsBoolean());
322 EXPECT_FALSE(double_reg_type.IsByte());
323 EXPECT_FALSE(double_reg_type.IsChar());
324 EXPECT_FALSE(double_reg_type.IsShort());
325 EXPECT_FALSE(double_reg_type.IsInteger());
326 EXPECT_FALSE(double_reg_type.IsLong());
327 EXPECT_FALSE(double_reg_type.IsFloat());
328 EXPECT_TRUE(double_reg_type.IsDouble());
329 EXPECT_FALSE(double_reg_type.IsReference());
330 EXPECT_TRUE(double_reg_type.IsLowHalf());
331 EXPECT_FALSE(double_reg_type.IsHighHalf());
332 EXPECT_TRUE(double_reg_type.IsLongOrDoubleTypes());
333 EXPECT_FALSE(double_reg_type.IsReferenceTypes());
334 EXPECT_FALSE(double_reg_type.IsCategory1Types());
335 EXPECT_TRUE(double_reg_type.IsCategory2Types());
336 EXPECT_FALSE(double_reg_type.IsBooleanTypes());
337 EXPECT_FALSE(double_reg_type.IsByteTypes());
338 EXPECT_FALSE(double_reg_type.IsShortTypes());
339 EXPECT_FALSE(double_reg_type.IsCharTypes());
340 EXPECT_FALSE(double_reg_type.IsIntegralTypes());
341 EXPECT_FALSE(double_reg_type.IsFloatTypes());
342 EXPECT_FALSE(double_reg_type.IsLongTypes());
343 EXPECT_TRUE(double_reg_type.IsDoubleTypes());
344 EXPECT_FALSE(double_reg_type.IsArrayIndexTypes());
Ian Rogers637c65b2013-05-31 11:46:00 -0700345 EXPECT_FALSE(double_reg_type.IsNonZeroReferenceTypes());
Logan Chien10f0ca22014-09-23 23:01:47 +0800346 EXPECT_TRUE(double_reg_type.HasClass());
Ian Rogersd81871c2011-10-03 13:57:23 -0700347}
348
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -0800349class RegTypeReferenceTest : public CommonRuntimeTest {};
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800350
351TEST_F(RegTypeReferenceTest, JavalangObjectImprecise) {
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800352 // Tests matching precisions. A reference type that was created precise doesn't
353 // match the one that is imprecise.
Sameer Abu Asal998be612013-03-31 18:40:48 -0700354 ScopedObjectAccess soa(Thread::Current());
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800355 RegTypeCache cache(true);
Ian Rogersd8f69b02014-09-10 21:43:52 +0000356 const RegType& imprecise_obj = cache.JavaLangObject(false);
357 const RegType& precise_obj = cache.JavaLangObject(true);
Ian Rogers7b078e82014-09-10 14:44:24 -0700358 const RegType& precise_obj_2 = cache.FromDescriptor(nullptr, "Ljava/lang/Object;", true);
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800359
360 EXPECT_TRUE(precise_obj.Equals(precise_obj_2));
361 EXPECT_FALSE(imprecise_obj.Equals(precise_obj));
362 EXPECT_FALSE(imprecise_obj.Equals(precise_obj));
363 EXPECT_FALSE(imprecise_obj.Equals(precise_obj_2));
364}
365
366TEST_F(RegTypeReferenceTest, UnresolvedType) {
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800367 // Tests creating unresolved types. Miss for the first time asking the cache and
368 // a hit second time.
Sameer Abu Asal998be612013-03-31 18:40:48 -0700369 ScopedObjectAccess soa(Thread::Current());
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800370 RegTypeCache cache(true);
Ian Rogers7b078e82014-09-10 14:44:24 -0700371 const RegType& ref_type_0 = cache.FromDescriptor(nullptr, "Ljava/lang/DoesNotExist;", true);
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800372 EXPECT_TRUE(ref_type_0.IsUnresolvedReference());
Ian Rogers637c65b2013-05-31 11:46:00 -0700373 EXPECT_TRUE(ref_type_0.IsNonZeroReferenceTypes());
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800374
Ian Rogers7b078e82014-09-10 14:44:24 -0700375 const RegType& ref_type_1 = cache.FromDescriptor(nullptr, "Ljava/lang/DoesNotExist;", true);
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800376 EXPECT_TRUE(ref_type_0.Equals(ref_type_1));
377
Ian Rogersd8f69b02014-09-10 21:43:52 +0000378 const RegType& unresolved_super_class = cache.FromUnresolvedSuperClass(ref_type_0);
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800379 EXPECT_TRUE(unresolved_super_class.IsUnresolvedSuperClass());
Ian Rogers637c65b2013-05-31 11:46:00 -0700380 EXPECT_TRUE(unresolved_super_class.IsNonZeroReferenceTypes());
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800381}
382
383TEST_F(RegTypeReferenceTest, UnresolvedUnintializedType) {
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800384 // Tests creating types uninitialized types from unresolved types.
Sameer Abu Asal998be612013-03-31 18:40:48 -0700385 ScopedObjectAccess soa(Thread::Current());
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800386 RegTypeCache cache(true);
Ian Rogers7b078e82014-09-10 14:44:24 -0700387 const RegType& ref_type_0 = cache.FromDescriptor(nullptr, "Ljava/lang/DoesNotExist;", true);
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800388 EXPECT_TRUE(ref_type_0.IsUnresolvedReference());
Ian Rogers7b078e82014-09-10 14:44:24 -0700389 const RegType& ref_type = cache.FromDescriptor(nullptr, "Ljava/lang/DoesNotExist;", true);
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800390 EXPECT_TRUE(ref_type_0.Equals(ref_type));
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800391 // Create an uninitialized type of this unresolved type
Ian Rogersd8f69b02014-09-10 21:43:52 +0000392 const RegType& unresolved_unintialised = cache.Uninitialized(ref_type, 1101ull);
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800393 EXPECT_TRUE(unresolved_unintialised.IsUnresolvedAndUninitializedReference());
394 EXPECT_TRUE(unresolved_unintialised.IsUninitializedTypes());
Ian Rogers637c65b2013-05-31 11:46:00 -0700395 EXPECT_TRUE(unresolved_unintialised.IsNonZeroReferenceTypes());
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800396 // Create an uninitialized type of this unresolved type with different PC
Ian Rogersd8f69b02014-09-10 21:43:52 +0000397 const RegType& ref_type_unresolved_unintialised_1 = cache.Uninitialized(ref_type, 1102ull);
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800398 EXPECT_TRUE(unresolved_unintialised.IsUnresolvedAndUninitializedReference());
399 EXPECT_FALSE(unresolved_unintialised.Equals(ref_type_unresolved_unintialised_1));
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800400 // Create an uninitialized type of this unresolved type with the same PC
Ian Rogersd8f69b02014-09-10 21:43:52 +0000401 const RegType& unresolved_unintialised_2 = cache.Uninitialized(ref_type, 1101ull);
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800402 EXPECT_TRUE(unresolved_unintialised.Equals(unresolved_unintialised_2));
403}
404
405TEST_F(RegTypeReferenceTest, Dump) {
Sameer Abu Asal998be612013-03-31 18:40:48 -0700406 // Tests types for proper Dump messages.
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800407 ScopedObjectAccess soa(Thread::Current());
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800408 RegTypeCache cache(true);
Ian Rogers7b078e82014-09-10 14:44:24 -0700409 const RegType& unresolved_ref = cache.FromDescriptor(nullptr, "Ljava/lang/DoesNotExist;", true);
410 const RegType& unresolved_ref_another = cache.FromDescriptor(nullptr, "Ljava/lang/DoesNotExistEither;", true);
Ian Rogersd8f69b02014-09-10 21:43:52 +0000411 const RegType& resolved_ref = cache.JavaLangString();
412 const RegType& resolved_unintialiesd = cache.Uninitialized(resolved_ref, 10);
413 const RegType& unresolved_unintialized = cache.Uninitialized(unresolved_ref, 12);
414 const RegType& unresolved_merged = cache.FromUnresolvedMerge(unresolved_ref, unresolved_ref_another);
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800415
416 std::string expected = "Unresolved Reference: java.lang.DoesNotExist";
417 EXPECT_EQ(expected, unresolved_ref.Dump());
418 expected = "Precise Reference: java.lang.String";
Brian Carlstromdf629502013-07-17 22:39:56 -0700419 EXPECT_EQ(expected, resolved_ref.Dump());
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800420 expected ="Uninitialized Reference: java.lang.String Allocation PC: 10";
421 EXPECT_EQ(expected, resolved_unintialiesd.Dump());
422 expected = "Unresolved And Uninitialized Reference: java.lang.DoesNotExist Allocation PC: 12";
423 EXPECT_EQ(expected, unresolved_unintialized.Dump());
424 expected = "UnresolvedMergedReferences(Unresolved Reference: java.lang.DoesNotExist, Unresolved Reference: java.lang.DoesNotExistEither)";
425 EXPECT_EQ(expected, unresolved_merged.Dump());
426}
427
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800428TEST_F(RegTypeReferenceTest, JavalangString) {
429 // Add a class to the cache then look for the same class and make sure it is a
430 // Hit the second time. Then check for the same effect when using
431 // The JavaLangObject method instead of FromDescriptor. String class is final.
432 ScopedObjectAccess soa(Thread::Current());
433 RegTypeCache cache(true);
Ian Rogersd8f69b02014-09-10 21:43:52 +0000434 const RegType& ref_type = cache.JavaLangString();
435 const RegType& ref_type_2 = cache.JavaLangString();
Ian Rogers7b078e82014-09-10 14:44:24 -0700436 const RegType& ref_type_3 = cache.FromDescriptor(nullptr, "Ljava/lang/String;", true);
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800437
438 EXPECT_TRUE(ref_type.Equals(ref_type_2));
439 EXPECT_TRUE(ref_type_2.Equals(ref_type_3));
440 EXPECT_TRUE(ref_type.IsPreciseReference());
441
442 // Create an uninitialized type out of this:
Ian Rogersd8f69b02014-09-10 21:43:52 +0000443 const RegType& ref_type_unintialized = cache.Uninitialized(ref_type, 0110ull);
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800444 EXPECT_TRUE(ref_type_unintialized.IsUninitializedReference());
445 EXPECT_FALSE(ref_type_unintialized.IsUnresolvedAndUninitializedReference());
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800446}
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700447
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800448TEST_F(RegTypeReferenceTest, JavalangObject) {
449 // Add a class to the cache then look for the same class and make sure it is a
450 // Hit the second time. Then I am checking for the same effect when using
451 // The JavaLangObject method instead of FromDescriptor. Object Class in not final.
452 ScopedObjectAccess soa(Thread::Current());
453 RegTypeCache cache(true);
Ian Rogersd8f69b02014-09-10 21:43:52 +0000454 const RegType& ref_type = cache.JavaLangObject(true);
455 const RegType& ref_type_2 = cache.JavaLangObject(true);
Ian Rogers7b078e82014-09-10 14:44:24 -0700456 const RegType& ref_type_3 = cache.FromDescriptor(nullptr, "Ljava/lang/Object;", true);
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800457
458 EXPECT_TRUE(ref_type.Equals(ref_type_2));
459 EXPECT_TRUE(ref_type_3.Equals(ref_type_2));
460 EXPECT_EQ(ref_type.GetId(), ref_type_3.GetId());
461}
462TEST_F(RegTypeReferenceTest, Merging) {
463 // Tests merging logic
Sameer Abu Asal998be612013-03-31 18:40:48 -0700464 // String and object , LUB is object.
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800465 ScopedObjectAccess soa(Thread::Current());
466 RegTypeCache cache_new(true);
Ian Rogersd8f69b02014-09-10 21:43:52 +0000467 const RegType& string = cache_new.JavaLangString();
468 const RegType& Object = cache_new.JavaLangObject(true);
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800469 EXPECT_TRUE(string.Merge(Object, &cache_new).IsJavaLangObject());
470 // Merge two unresolved types.
Ian Rogers7b078e82014-09-10 14:44:24 -0700471 const RegType& ref_type_0 = cache_new.FromDescriptor(nullptr, "Ljava/lang/DoesNotExist;", true);
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800472 EXPECT_TRUE(ref_type_0.IsUnresolvedReference());
Ian Rogers7b078e82014-09-10 14:44:24 -0700473 const RegType& ref_type_1 = cache_new.FromDescriptor(nullptr, "Ljava/lang/DoesNotExistToo;", true);
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800474 EXPECT_FALSE(ref_type_0.Equals(ref_type_1));
475
Ian Rogersd8f69b02014-09-10 21:43:52 +0000476 const RegType& merged = ref_type_1.Merge(ref_type_0, &cache_new);
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800477 EXPECT_TRUE(merged.IsUnresolvedMergedReference());
Ian Rogersd8f69b02014-09-10 21:43:52 +0000478 RegType& merged_nonconst = const_cast<RegType&>(merged);
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800479
Ian Rogersd8f69b02014-09-10 21:43:52 +0000480 std::set<uint16_t> merged_ids = (down_cast<UnresolvedMergedType*>(&merged_nonconst))->GetMergedTypes();
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800481 EXPECT_EQ(ref_type_0.GetId(), *(merged_ids.begin()));
482 EXPECT_EQ(ref_type_1.GetId(), *((++merged_ids.begin())));
483}
484
Sebastien Hertz757b3042014-03-28 14:34:28 +0100485TEST_F(RegTypeTest, MergingFloat) {
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100486 // Testing merging logic with float and float constants.
487 ScopedObjectAccess soa(Thread::Current());
488 RegTypeCache cache_new(true);
489
490 constexpr int32_t kTestConstantValue = 10;
Ian Rogersd8f69b02014-09-10 21:43:52 +0000491 const RegType& float_type = cache_new.Float();
492 const RegType& precise_cst = cache_new.FromCat1Const(kTestConstantValue, true);
493 const RegType& imprecise_cst = cache_new.FromCat1Const(kTestConstantValue, false);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100494 {
495 // float MERGE precise cst => float.
Ian Rogersd8f69b02014-09-10 21:43:52 +0000496 const RegType& merged = float_type.Merge(precise_cst, &cache_new);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100497 EXPECT_TRUE(merged.IsFloat());
498 }
499 {
500 // precise cst MERGE float => float.
Ian Rogersd8f69b02014-09-10 21:43:52 +0000501 const RegType& merged = precise_cst.Merge(float_type, &cache_new);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100502 EXPECT_TRUE(merged.IsFloat());
503 }
504 {
505 // float MERGE imprecise cst => float.
Ian Rogersd8f69b02014-09-10 21:43:52 +0000506 const RegType& merged = float_type.Merge(imprecise_cst, &cache_new);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100507 EXPECT_TRUE(merged.IsFloat());
508 }
509 {
510 // imprecise cst MERGE float => float.
Ian Rogersd8f69b02014-09-10 21:43:52 +0000511 const RegType& merged = imprecise_cst.Merge(float_type, &cache_new);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100512 EXPECT_TRUE(merged.IsFloat());
513 }
514}
515
Sebastien Hertz757b3042014-03-28 14:34:28 +0100516TEST_F(RegTypeTest, MergingLong) {
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100517 // Testing merging logic with long and long constants.
518 ScopedObjectAccess soa(Thread::Current());
519 RegTypeCache cache_new(true);
520
521 constexpr int32_t kTestConstantValue = 10;
Ian Rogersd8f69b02014-09-10 21:43:52 +0000522 const RegType& long_lo_type = cache_new.LongLo();
523 const RegType& long_hi_type = cache_new.LongHi();
524 const RegType& precise_cst_lo = cache_new.FromCat2ConstLo(kTestConstantValue, true);
525 const RegType& imprecise_cst_lo = cache_new.FromCat2ConstLo(kTestConstantValue, false);
526 const RegType& precise_cst_hi = cache_new.FromCat2ConstHi(kTestConstantValue, true);
527 const RegType& imprecise_cst_hi = cache_new.FromCat2ConstHi(kTestConstantValue, false);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100528 {
529 // lo MERGE precise cst lo => lo.
Ian Rogersd8f69b02014-09-10 21:43:52 +0000530 const RegType& merged = long_lo_type.Merge(precise_cst_lo, &cache_new);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100531 EXPECT_TRUE(merged.IsLongLo());
532 }
533 {
534 // precise cst lo MERGE lo => lo.
Ian Rogersd8f69b02014-09-10 21:43:52 +0000535 const RegType& merged = precise_cst_lo.Merge(long_lo_type, &cache_new);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100536 EXPECT_TRUE(merged.IsLongLo());
537 }
538 {
539 // lo MERGE imprecise cst lo => lo.
Ian Rogersd8f69b02014-09-10 21:43:52 +0000540 const RegType& merged = long_lo_type.Merge(imprecise_cst_lo, &cache_new);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100541 EXPECT_TRUE(merged.IsLongLo());
542 }
543 {
544 // imprecise cst lo MERGE lo => lo.
Ian Rogersd8f69b02014-09-10 21:43:52 +0000545 const RegType& merged = imprecise_cst_lo.Merge(long_lo_type, &cache_new);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100546 EXPECT_TRUE(merged.IsLongLo());
547 }
548 {
549 // hi MERGE precise cst hi => hi.
Ian Rogersd8f69b02014-09-10 21:43:52 +0000550 const RegType& merged = long_hi_type.Merge(precise_cst_hi, &cache_new);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100551 EXPECT_TRUE(merged.IsLongHi());
552 }
553 {
554 // precise cst hi MERGE hi => hi.
Ian Rogersd8f69b02014-09-10 21:43:52 +0000555 const RegType& merged = precise_cst_hi.Merge(long_hi_type, &cache_new);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100556 EXPECT_TRUE(merged.IsLongHi());
557 }
558 {
559 // hi MERGE imprecise cst hi => hi.
Ian Rogersd8f69b02014-09-10 21:43:52 +0000560 const RegType& merged = long_hi_type.Merge(imprecise_cst_hi, &cache_new);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100561 EXPECT_TRUE(merged.IsLongHi());
562 }
563 {
564 // imprecise cst hi MERGE hi => hi.
Ian Rogersd8f69b02014-09-10 21:43:52 +0000565 const RegType& merged = imprecise_cst_hi.Merge(long_hi_type, &cache_new);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100566 EXPECT_TRUE(merged.IsLongHi());
567 }
568}
569
Sebastien Hertz757b3042014-03-28 14:34:28 +0100570TEST_F(RegTypeTest, MergingDouble) {
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100571 // Testing merging logic with double and double constants.
572 ScopedObjectAccess soa(Thread::Current());
573 RegTypeCache cache_new(true);
574
575 constexpr int32_t kTestConstantValue = 10;
Ian Rogersd8f69b02014-09-10 21:43:52 +0000576 const RegType& double_lo_type = cache_new.DoubleLo();
577 const RegType& double_hi_type = cache_new.DoubleHi();
578 const RegType& precise_cst_lo = cache_new.FromCat2ConstLo(kTestConstantValue, true);
579 const RegType& imprecise_cst_lo = cache_new.FromCat2ConstLo(kTestConstantValue, false);
580 const RegType& precise_cst_hi = cache_new.FromCat2ConstHi(kTestConstantValue, true);
581 const RegType& imprecise_cst_hi = cache_new.FromCat2ConstHi(kTestConstantValue, false);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100582 {
583 // lo MERGE precise cst lo => lo.
Ian Rogersd8f69b02014-09-10 21:43:52 +0000584 const RegType& merged = double_lo_type.Merge(precise_cst_lo, &cache_new);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100585 EXPECT_TRUE(merged.IsDoubleLo());
586 }
587 {
588 // precise cst lo MERGE lo => lo.
Ian Rogersd8f69b02014-09-10 21:43:52 +0000589 const RegType& merged = precise_cst_lo.Merge(double_lo_type, &cache_new);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100590 EXPECT_TRUE(merged.IsDoubleLo());
591 }
592 {
593 // lo MERGE imprecise cst lo => lo.
Ian Rogersd8f69b02014-09-10 21:43:52 +0000594 const RegType& merged = double_lo_type.Merge(imprecise_cst_lo, &cache_new);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100595 EXPECT_TRUE(merged.IsDoubleLo());
596 }
597 {
598 // imprecise cst lo MERGE lo => lo.
Ian Rogersd8f69b02014-09-10 21:43:52 +0000599 const RegType& merged = imprecise_cst_lo.Merge(double_lo_type, &cache_new);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100600 EXPECT_TRUE(merged.IsDoubleLo());
601 }
602 {
603 // hi MERGE precise cst hi => hi.
Ian Rogersd8f69b02014-09-10 21:43:52 +0000604 const RegType& merged = double_hi_type.Merge(precise_cst_hi, &cache_new);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100605 EXPECT_TRUE(merged.IsDoubleHi());
606 }
607 {
608 // precise cst hi MERGE hi => hi.
Ian Rogersd8f69b02014-09-10 21:43:52 +0000609 const RegType& merged = precise_cst_hi.Merge(double_hi_type, &cache_new);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100610 EXPECT_TRUE(merged.IsDoubleHi());
611 }
612 {
613 // hi MERGE imprecise cst hi => hi.
Ian Rogersd8f69b02014-09-10 21:43:52 +0000614 const RegType& merged = double_hi_type.Merge(imprecise_cst_hi, &cache_new);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100615 EXPECT_TRUE(merged.IsDoubleHi());
616 }
617 {
618 // imprecise cst hi MERGE hi => hi.
Ian Rogersd8f69b02014-09-10 21:43:52 +0000619 const RegType& merged = imprecise_cst_hi.Merge(double_hi_type, &cache_new);
Sebastien Hertzaa0c00c2014-03-14 17:58:54 +0100620 EXPECT_TRUE(merged.IsDoubleHi());
621 }
622}
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800623
624TEST_F(RegTypeTest, ConstPrecision) {
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800625 // Tests creating primitive types types.
626 ScopedObjectAccess soa(Thread::Current());
627 RegTypeCache cache_new(true);
Ian Rogersd8f69b02014-09-10 21:43:52 +0000628 const RegType& imprecise_const = cache_new.FromCat1Const(10, false);
629 const RegType& precise_const = cache_new.FromCat1Const(10, true);
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -0800630
631 EXPECT_TRUE(imprecise_const.IsImpreciseConstant());
632 EXPECT_TRUE(precise_const.IsPreciseConstant());
633 EXPECT_FALSE(imprecise_const.Equals(precise_const));
634}
Ian Rogersd81871c2011-10-03 13:57:23 -0700635
636} // namespace verifier
jeffhaoba5ebb92011-08-25 17:24:37 -0700637} // namespace art