Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 2 | * Copyright (C) 2012 The Android Open Source Project |
Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 3 | * |
| 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 | */ |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 16 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 17 | #include "reg_type.h" |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 18 | |
| 19 | #include <set> |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 20 | |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 21 | #include "base/casts.h" |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 22 | #include "common_runtime_test.h" |
| 23 | #include "reg_type_cache-inl.h" |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 24 | #include "reg_type-inl.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 25 | #include "scoped_thread_state_change.h" |
| 26 | #include "thread-inl.h" |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 27 | |
| 28 | namespace art { |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 29 | namespace verifier { |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 30 | |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 31 | class RegTypeTest : public CommonRuntimeTest {}; |
Sameer Abu Asal | 998be61 | 2013-03-31 18:40:48 -0700 | [diff] [blame] | 32 | |
| 33 | TEST_F(RegTypeTest, ConstLoHi) { |
| 34 | // Tests creating primitive types types. |
| 35 | ScopedObjectAccess soa(Thread::Current()); |
| 36 | RegTypeCache cache(true); |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 37 | 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 Asal | 998be61 | 2013-03-31 18:40:48 -0700 | [diff] [blame] | 41 | 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 Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 45 | 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 Asal | 998be61 | 2013-03-31 18:40:48 -0700 | [diff] [blame] | 47 | EXPECT_TRUE(ref_type_const_wide_0.Equals(ref_type_const_wide_1)); |
| 48 | |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 49 | 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 Asal | 998be61 | 2013-03-31 18:40:48 -0700 | [diff] [blame] | 52 | 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 | |
| 56 | TEST_F(RegTypeTest, Pairs) { |
| 57 | ScopedObjectAccess soa(Thread::Current()); |
| 58 | RegTypeCache cache(true); |
| 59 | int64_t val = static_cast<int32_t>(1234); |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 60 | 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 Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 65 | // Check sanity of types. |
Sameer Abu Asal | 998be61 | 2013-03-31 18:40:48 -0700 | [diff] [blame] | 66 | 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 Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 80 | TEST_F(RegTypeTest, Primitives) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 81 | ScopedObjectAccess soa(Thread::Current()); |
Elliott Hughes | 80537bb | 2013-01-04 16:37:26 -0800 | [diff] [blame] | 82 | RegTypeCache cache(true); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 83 | |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 84 | const RegType& bool_reg_type = cache.Boolean(); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 85 | EXPECT_FALSE(bool_reg_type.IsUndefined()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 86 | EXPECT_FALSE(bool_reg_type.IsConflict()); |
| 87 | EXPECT_FALSE(bool_reg_type.IsZero()); |
| 88 | EXPECT_FALSE(bool_reg_type.IsOne()); |
Ian Rogers | 84fa074 | 2011-10-25 18:13:30 -0700 | [diff] [blame] | 89 | EXPECT_FALSE(bool_reg_type.IsLongConstant()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 90 | 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 Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 114 | EXPECT_FALSE(bool_reg_type.IsNonZeroReferenceTypes()); |
Logan Chien | 10f0ca2 | 2014-09-23 23:01:47 +0800 | [diff] [blame] | 115 | EXPECT_TRUE(bool_reg_type.HasClass()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 116 | |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 117 | const RegType& byte_reg_type = cache.Byte(); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 118 | EXPECT_FALSE(byte_reg_type.IsUndefined()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 119 | EXPECT_FALSE(byte_reg_type.IsConflict()); |
| 120 | EXPECT_FALSE(byte_reg_type.IsZero()); |
| 121 | EXPECT_FALSE(byte_reg_type.IsOne()); |
Ian Rogers | 84fa074 | 2011-10-25 18:13:30 -0700 | [diff] [blame] | 122 | EXPECT_FALSE(byte_reg_type.IsLongConstant()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 123 | 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 Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 147 | EXPECT_FALSE(byte_reg_type.IsNonZeroReferenceTypes()); |
Logan Chien | 10f0ca2 | 2014-09-23 23:01:47 +0800 | [diff] [blame] | 148 | EXPECT_TRUE(byte_reg_type.HasClass()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 149 | |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 150 | const RegType& char_reg_type = cache.Char(); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 151 | EXPECT_FALSE(char_reg_type.IsUndefined()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 152 | EXPECT_FALSE(char_reg_type.IsConflict()); |
| 153 | EXPECT_FALSE(char_reg_type.IsZero()); |
| 154 | EXPECT_FALSE(char_reg_type.IsOne()); |
Ian Rogers | 84fa074 | 2011-10-25 18:13:30 -0700 | [diff] [blame] | 155 | EXPECT_FALSE(char_reg_type.IsLongConstant()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 156 | 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 Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 180 | EXPECT_FALSE(char_reg_type.IsNonZeroReferenceTypes()); |
Logan Chien | 10f0ca2 | 2014-09-23 23:01:47 +0800 | [diff] [blame] | 181 | EXPECT_TRUE(char_reg_type.HasClass()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 182 | |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 183 | const RegType& short_reg_type = cache.Short(); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 184 | EXPECT_FALSE(short_reg_type.IsUndefined()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 185 | EXPECT_FALSE(short_reg_type.IsConflict()); |
| 186 | EXPECT_FALSE(short_reg_type.IsZero()); |
| 187 | EXPECT_FALSE(short_reg_type.IsOne()); |
Ian Rogers | 84fa074 | 2011-10-25 18:13:30 -0700 | [diff] [blame] | 188 | EXPECT_FALSE(short_reg_type.IsLongConstant()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 189 | 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 Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 213 | EXPECT_FALSE(short_reg_type.IsNonZeroReferenceTypes()); |
Logan Chien | 10f0ca2 | 2014-09-23 23:01:47 +0800 | [diff] [blame] | 214 | EXPECT_TRUE(short_reg_type.HasClass()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 215 | |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 216 | const RegType& int_reg_type = cache.Integer(); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 217 | EXPECT_FALSE(int_reg_type.IsUndefined()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 218 | EXPECT_FALSE(int_reg_type.IsConflict()); |
| 219 | EXPECT_FALSE(int_reg_type.IsZero()); |
| 220 | EXPECT_FALSE(int_reg_type.IsOne()); |
Ian Rogers | 84fa074 | 2011-10-25 18:13:30 -0700 | [diff] [blame] | 221 | EXPECT_FALSE(int_reg_type.IsLongConstant()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 222 | 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 Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 246 | EXPECT_FALSE(int_reg_type.IsNonZeroReferenceTypes()); |
Logan Chien | 10f0ca2 | 2014-09-23 23:01:47 +0800 | [diff] [blame] | 247 | EXPECT_TRUE(int_reg_type.HasClass()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 248 | |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 249 | const RegType& long_reg_type = cache.LongLo(); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 250 | EXPECT_FALSE(long_reg_type.IsUndefined()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 251 | EXPECT_FALSE(long_reg_type.IsConflict()); |
| 252 | EXPECT_FALSE(long_reg_type.IsZero()); |
| 253 | EXPECT_FALSE(long_reg_type.IsOne()); |
Ian Rogers | 84fa074 | 2011-10-25 18:13:30 -0700 | [diff] [blame] | 254 | EXPECT_FALSE(long_reg_type.IsLongConstant()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 255 | 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 Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 279 | EXPECT_FALSE(long_reg_type.IsNonZeroReferenceTypes()); |
Logan Chien | 10f0ca2 | 2014-09-23 23:01:47 +0800 | [diff] [blame] | 280 | EXPECT_TRUE(long_reg_type.HasClass()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 281 | |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 282 | const RegType& float_reg_type = cache.Float(); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 283 | EXPECT_FALSE(float_reg_type.IsUndefined()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 284 | EXPECT_FALSE(float_reg_type.IsConflict()); |
| 285 | EXPECT_FALSE(float_reg_type.IsZero()); |
| 286 | EXPECT_FALSE(float_reg_type.IsOne()); |
Ian Rogers | 84fa074 | 2011-10-25 18:13:30 -0700 | [diff] [blame] | 287 | EXPECT_FALSE(float_reg_type.IsLongConstant()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 288 | 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 Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 312 | EXPECT_FALSE(float_reg_type.IsNonZeroReferenceTypes()); |
Logan Chien | 10f0ca2 | 2014-09-23 23:01:47 +0800 | [diff] [blame] | 313 | EXPECT_TRUE(float_reg_type.HasClass()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 314 | |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 315 | const RegType& double_reg_type = cache.DoubleLo(); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 316 | EXPECT_FALSE(double_reg_type.IsUndefined()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 317 | EXPECT_FALSE(double_reg_type.IsConflict()); |
| 318 | EXPECT_FALSE(double_reg_type.IsZero()); |
| 319 | EXPECT_FALSE(double_reg_type.IsOne()); |
Ian Rogers | 84fa074 | 2011-10-25 18:13:30 -0700 | [diff] [blame] | 320 | EXPECT_FALSE(double_reg_type.IsLongConstant()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 321 | 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 Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 345 | EXPECT_FALSE(double_reg_type.IsNonZeroReferenceTypes()); |
Logan Chien | 10f0ca2 | 2014-09-23 23:01:47 +0800 | [diff] [blame] | 346 | EXPECT_TRUE(double_reg_type.HasClass()); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 349 | class RegTypeReferenceTest : public CommonRuntimeTest {}; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 350 | |
| 351 | TEST_F(RegTypeReferenceTest, JavalangObjectImprecise) { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 352 | // Tests matching precisions. A reference type that was created precise doesn't |
| 353 | // match the one that is imprecise. |
Sameer Abu Asal | 998be61 | 2013-03-31 18:40:48 -0700 | [diff] [blame] | 354 | ScopedObjectAccess soa(Thread::Current()); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 355 | RegTypeCache cache(true); |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 356 | const RegType& imprecise_obj = cache.JavaLangObject(false); |
| 357 | const RegType& precise_obj = cache.JavaLangObject(true); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 358 | const RegType& precise_obj_2 = cache.FromDescriptor(nullptr, "Ljava/lang/Object;", true); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 359 | |
| 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 | |
| 366 | TEST_F(RegTypeReferenceTest, UnresolvedType) { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 367 | // Tests creating unresolved types. Miss for the first time asking the cache and |
| 368 | // a hit second time. |
Sameer Abu Asal | 998be61 | 2013-03-31 18:40:48 -0700 | [diff] [blame] | 369 | ScopedObjectAccess soa(Thread::Current()); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 370 | RegTypeCache cache(true); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 371 | const RegType& ref_type_0 = cache.FromDescriptor(nullptr, "Ljava/lang/DoesNotExist;", true); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 372 | EXPECT_TRUE(ref_type_0.IsUnresolvedReference()); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 373 | EXPECT_TRUE(ref_type_0.IsNonZeroReferenceTypes()); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 374 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 375 | const RegType& ref_type_1 = cache.FromDescriptor(nullptr, "Ljava/lang/DoesNotExist;", true); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 376 | EXPECT_TRUE(ref_type_0.Equals(ref_type_1)); |
| 377 | |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 378 | const RegType& unresolved_super_class = cache.FromUnresolvedSuperClass(ref_type_0); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 379 | EXPECT_TRUE(unresolved_super_class.IsUnresolvedSuperClass()); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 380 | EXPECT_TRUE(unresolved_super_class.IsNonZeroReferenceTypes()); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | TEST_F(RegTypeReferenceTest, UnresolvedUnintializedType) { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 384 | // Tests creating types uninitialized types from unresolved types. |
Sameer Abu Asal | 998be61 | 2013-03-31 18:40:48 -0700 | [diff] [blame] | 385 | ScopedObjectAccess soa(Thread::Current()); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 386 | RegTypeCache cache(true); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 387 | const RegType& ref_type_0 = cache.FromDescriptor(nullptr, "Ljava/lang/DoesNotExist;", true); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 388 | EXPECT_TRUE(ref_type_0.IsUnresolvedReference()); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 389 | const RegType& ref_type = cache.FromDescriptor(nullptr, "Ljava/lang/DoesNotExist;", true); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 390 | EXPECT_TRUE(ref_type_0.Equals(ref_type)); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 391 | // Create an uninitialized type of this unresolved type |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 392 | const RegType& unresolved_unintialised = cache.Uninitialized(ref_type, 1101ull); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 393 | EXPECT_TRUE(unresolved_unintialised.IsUnresolvedAndUninitializedReference()); |
| 394 | EXPECT_TRUE(unresolved_unintialised.IsUninitializedTypes()); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 395 | EXPECT_TRUE(unresolved_unintialised.IsNonZeroReferenceTypes()); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 396 | // Create an uninitialized type of this unresolved type with different PC |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 397 | const RegType& ref_type_unresolved_unintialised_1 = cache.Uninitialized(ref_type, 1102ull); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 398 | EXPECT_TRUE(unresolved_unintialised.IsUnresolvedAndUninitializedReference()); |
| 399 | EXPECT_FALSE(unresolved_unintialised.Equals(ref_type_unresolved_unintialised_1)); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 400 | // Create an uninitialized type of this unresolved type with the same PC |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 401 | const RegType& unresolved_unintialised_2 = cache.Uninitialized(ref_type, 1101ull); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 402 | EXPECT_TRUE(unresolved_unintialised.Equals(unresolved_unintialised_2)); |
| 403 | } |
| 404 | |
| 405 | TEST_F(RegTypeReferenceTest, Dump) { |
Sameer Abu Asal | 998be61 | 2013-03-31 18:40:48 -0700 | [diff] [blame] | 406 | // Tests types for proper Dump messages. |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 407 | ScopedObjectAccess soa(Thread::Current()); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 408 | RegTypeCache cache(true); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 409 | 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 Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 411 | 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 Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 415 | |
| 416 | std::string expected = "Unresolved Reference: java.lang.DoesNotExist"; |
| 417 | EXPECT_EQ(expected, unresolved_ref.Dump()); |
| 418 | expected = "Precise Reference: java.lang.String"; |
Brian Carlstrom | df62950 | 2013-07-17 22:39:56 -0700 | [diff] [blame] | 419 | EXPECT_EQ(expected, resolved_ref.Dump()); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 420 | 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 Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 428 | TEST_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 Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 434 | const RegType& ref_type = cache.JavaLangString(); |
| 435 | const RegType& ref_type_2 = cache.JavaLangString(); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 436 | const RegType& ref_type_3 = cache.FromDescriptor(nullptr, "Ljava/lang/String;", true); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 437 | |
| 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 Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 443 | const RegType& ref_type_unintialized = cache.Uninitialized(ref_type, 0110ull); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 444 | EXPECT_TRUE(ref_type_unintialized.IsUninitializedReference()); |
| 445 | EXPECT_FALSE(ref_type_unintialized.IsUnresolvedAndUninitializedReference()); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 446 | } |
Brian Carlstrom | 0cd7ec2 | 2013-07-17 23:40:20 -0700 | [diff] [blame] | 447 | |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 448 | TEST_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 Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 454 | const RegType& ref_type = cache.JavaLangObject(true); |
| 455 | const RegType& ref_type_2 = cache.JavaLangObject(true); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 456 | const RegType& ref_type_3 = cache.FromDescriptor(nullptr, "Ljava/lang/Object;", true); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 457 | |
| 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 | } |
| 462 | TEST_F(RegTypeReferenceTest, Merging) { |
| 463 | // Tests merging logic |
Sameer Abu Asal | 998be61 | 2013-03-31 18:40:48 -0700 | [diff] [blame] | 464 | // String and object , LUB is object. |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 465 | ScopedObjectAccess soa(Thread::Current()); |
| 466 | RegTypeCache cache_new(true); |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 467 | const RegType& string = cache_new.JavaLangString(); |
| 468 | const RegType& Object = cache_new.JavaLangObject(true); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 469 | EXPECT_TRUE(string.Merge(Object, &cache_new).IsJavaLangObject()); |
| 470 | // Merge two unresolved types. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 471 | const RegType& ref_type_0 = cache_new.FromDescriptor(nullptr, "Ljava/lang/DoesNotExist;", true); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 472 | EXPECT_TRUE(ref_type_0.IsUnresolvedReference()); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 473 | const RegType& ref_type_1 = cache_new.FromDescriptor(nullptr, "Ljava/lang/DoesNotExistToo;", true); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 474 | EXPECT_FALSE(ref_type_0.Equals(ref_type_1)); |
| 475 | |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 476 | const RegType& merged = ref_type_1.Merge(ref_type_0, &cache_new); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 477 | EXPECT_TRUE(merged.IsUnresolvedMergedReference()); |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 478 | RegType& merged_nonconst = const_cast<RegType&>(merged); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 479 | |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 480 | std::set<uint16_t> merged_ids = (down_cast<UnresolvedMergedType*>(&merged_nonconst))->GetMergedTypes(); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 481 | EXPECT_EQ(ref_type_0.GetId(), *(merged_ids.begin())); |
| 482 | EXPECT_EQ(ref_type_1.GetId(), *((++merged_ids.begin()))); |
| 483 | } |
| 484 | |
Sebastien Hertz | 757b304 | 2014-03-28 14:34:28 +0100 | [diff] [blame] | 485 | TEST_F(RegTypeTest, MergingFloat) { |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 486 | // 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 Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 491 | 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 Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 494 | { |
| 495 | // float MERGE precise cst => float. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 496 | const RegType& merged = float_type.Merge(precise_cst, &cache_new); |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 497 | EXPECT_TRUE(merged.IsFloat()); |
| 498 | } |
| 499 | { |
| 500 | // precise cst MERGE float => float. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 501 | const RegType& merged = precise_cst.Merge(float_type, &cache_new); |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 502 | EXPECT_TRUE(merged.IsFloat()); |
| 503 | } |
| 504 | { |
| 505 | // float MERGE imprecise cst => float. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 506 | const RegType& merged = float_type.Merge(imprecise_cst, &cache_new); |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 507 | EXPECT_TRUE(merged.IsFloat()); |
| 508 | } |
| 509 | { |
| 510 | // imprecise cst MERGE float => float. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 511 | const RegType& merged = imprecise_cst.Merge(float_type, &cache_new); |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 512 | EXPECT_TRUE(merged.IsFloat()); |
| 513 | } |
| 514 | } |
| 515 | |
Sebastien Hertz | 757b304 | 2014-03-28 14:34:28 +0100 | [diff] [blame] | 516 | TEST_F(RegTypeTest, MergingLong) { |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 517 | // 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 Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 522 | 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 Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 528 | { |
| 529 | // lo MERGE precise cst lo => lo. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 530 | const RegType& merged = long_lo_type.Merge(precise_cst_lo, &cache_new); |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 531 | EXPECT_TRUE(merged.IsLongLo()); |
| 532 | } |
| 533 | { |
| 534 | // precise cst lo MERGE lo => lo. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 535 | const RegType& merged = precise_cst_lo.Merge(long_lo_type, &cache_new); |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 536 | EXPECT_TRUE(merged.IsLongLo()); |
| 537 | } |
| 538 | { |
| 539 | // lo MERGE imprecise cst lo => lo. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 540 | const RegType& merged = long_lo_type.Merge(imprecise_cst_lo, &cache_new); |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 541 | EXPECT_TRUE(merged.IsLongLo()); |
| 542 | } |
| 543 | { |
| 544 | // imprecise cst lo MERGE lo => lo. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 545 | const RegType& merged = imprecise_cst_lo.Merge(long_lo_type, &cache_new); |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 546 | EXPECT_TRUE(merged.IsLongLo()); |
| 547 | } |
| 548 | { |
| 549 | // hi MERGE precise cst hi => hi. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 550 | const RegType& merged = long_hi_type.Merge(precise_cst_hi, &cache_new); |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 551 | EXPECT_TRUE(merged.IsLongHi()); |
| 552 | } |
| 553 | { |
| 554 | // precise cst hi MERGE hi => hi. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 555 | const RegType& merged = precise_cst_hi.Merge(long_hi_type, &cache_new); |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 556 | EXPECT_TRUE(merged.IsLongHi()); |
| 557 | } |
| 558 | { |
| 559 | // hi MERGE imprecise cst hi => hi. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 560 | const RegType& merged = long_hi_type.Merge(imprecise_cst_hi, &cache_new); |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 561 | EXPECT_TRUE(merged.IsLongHi()); |
| 562 | } |
| 563 | { |
| 564 | // imprecise cst hi MERGE hi => hi. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 565 | const RegType& merged = imprecise_cst_hi.Merge(long_hi_type, &cache_new); |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 566 | EXPECT_TRUE(merged.IsLongHi()); |
| 567 | } |
| 568 | } |
| 569 | |
Sebastien Hertz | 757b304 | 2014-03-28 14:34:28 +0100 | [diff] [blame] | 570 | TEST_F(RegTypeTest, MergingDouble) { |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 571 | // 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 Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 576 | 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 Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 582 | { |
| 583 | // lo MERGE precise cst lo => lo. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 584 | const RegType& merged = double_lo_type.Merge(precise_cst_lo, &cache_new); |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 585 | EXPECT_TRUE(merged.IsDoubleLo()); |
| 586 | } |
| 587 | { |
| 588 | // precise cst lo MERGE lo => lo. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 589 | const RegType& merged = precise_cst_lo.Merge(double_lo_type, &cache_new); |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 590 | EXPECT_TRUE(merged.IsDoubleLo()); |
| 591 | } |
| 592 | { |
| 593 | // lo MERGE imprecise cst lo => lo. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 594 | const RegType& merged = double_lo_type.Merge(imprecise_cst_lo, &cache_new); |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 595 | EXPECT_TRUE(merged.IsDoubleLo()); |
| 596 | } |
| 597 | { |
| 598 | // imprecise cst lo MERGE lo => lo. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 599 | const RegType& merged = imprecise_cst_lo.Merge(double_lo_type, &cache_new); |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 600 | EXPECT_TRUE(merged.IsDoubleLo()); |
| 601 | } |
| 602 | { |
| 603 | // hi MERGE precise cst hi => hi. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 604 | const RegType& merged = double_hi_type.Merge(precise_cst_hi, &cache_new); |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 605 | EXPECT_TRUE(merged.IsDoubleHi()); |
| 606 | } |
| 607 | { |
| 608 | // precise cst hi MERGE hi => hi. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 609 | const RegType& merged = precise_cst_hi.Merge(double_hi_type, &cache_new); |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 610 | EXPECT_TRUE(merged.IsDoubleHi()); |
| 611 | } |
| 612 | { |
| 613 | // hi MERGE imprecise cst hi => hi. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 614 | const RegType& merged = double_hi_type.Merge(imprecise_cst_hi, &cache_new); |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 615 | EXPECT_TRUE(merged.IsDoubleHi()); |
| 616 | } |
| 617 | { |
| 618 | // imprecise cst hi MERGE hi => hi. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 619 | const RegType& merged = imprecise_cst_hi.Merge(double_hi_type, &cache_new); |
Sebastien Hertz | aa0c00c | 2014-03-14 17:58:54 +0100 | [diff] [blame] | 620 | EXPECT_TRUE(merged.IsDoubleHi()); |
| 621 | } |
| 622 | } |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 623 | |
| 624 | TEST_F(RegTypeTest, ConstPrecision) { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 625 | // Tests creating primitive types types. |
| 626 | ScopedObjectAccess soa(Thread::Current()); |
| 627 | RegTypeCache cache_new(true); |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 628 | const RegType& imprecise_const = cache_new.FromCat1Const(10, false); |
| 629 | const RegType& precise_const = cache_new.FromCat1Const(10, true); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 630 | |
| 631 | EXPECT_TRUE(imprecise_const.IsImpreciseConstant()); |
| 632 | EXPECT_TRUE(precise_const.IsPreciseConstant()); |
| 633 | EXPECT_FALSE(imprecise_const.Equals(precise_const)); |
| 634 | } |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 635 | |
| 636 | } // namespace verifier |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 637 | } // namespace art |