Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 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 | */ |
| 16 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_VERIFIER_REG_TYPE_H_ |
| 18 | #define ART_RUNTIME_VERIFIER_REG_TYPE_H_ |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 19 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 20 | #include <stdint.h> |
Ian Rogers | 8e1f4f8 | 2014-11-05 11:07:30 -0800 | [diff] [blame] | 21 | #include <limits> |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 22 | #include <set> |
| 23 | #include <string> |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 24 | |
Ian Rogers | 576ca0c | 2014-06-06 15:58:22 -0700 | [diff] [blame] | 25 | #include "base/macros.h" |
Ian Rogers | 68d8b42 | 2014-07-17 11:09:10 -0700 | [diff] [blame] | 26 | #include "base/mutex.h" |
Ian Rogers | 5441091 | 2014-09-10 15:33:05 -0700 | [diff] [blame] | 27 | #include "gc_root.h" |
Ian Rogers | 576ca0c | 2014-06-06 15:58:22 -0700 | [diff] [blame] | 28 | #include "object_callbacks.h" |
| 29 | #include "primitive.h" |
| 30 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 31 | namespace art { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 32 | namespace mirror { |
| 33 | class Class; |
| 34 | } // namespace mirror |
Ian Rogers | 8e1f4f8 | 2014-11-05 11:07:30 -0800 | [diff] [blame] | 35 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 36 | namespace verifier { |
| 37 | |
| 38 | class RegTypeCache; |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 39 | /* |
| 40 | * RegType holds information about the "type" of data held in a register. |
| 41 | */ |
| 42 | class RegType { |
| 43 | public: |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 44 | virtual bool IsUndefined() const { return false; } |
| 45 | virtual bool IsConflict() const { return false; } |
| 46 | virtual bool IsBoolean() const { return false; } |
| 47 | virtual bool IsByte() const { return false; } |
| 48 | virtual bool IsChar() const { return false; } |
| 49 | virtual bool IsShort() const { return false; } |
| 50 | virtual bool IsInteger() const { return false; } |
| 51 | virtual bool IsLongLo() const { return false; } |
| 52 | virtual bool IsLongHi() const { return false; } |
| 53 | virtual bool IsFloat() const { return false; } |
| 54 | virtual bool IsDouble() const { return false; } |
| 55 | virtual bool IsDoubleLo() const { return false; } |
| 56 | virtual bool IsDoubleHi() const { return false; } |
| 57 | virtual bool IsUnresolvedReference() const { return false; } |
| 58 | virtual bool IsUninitializedReference() const { return false; } |
| 59 | virtual bool IsUninitializedThisReference() const { return false; } |
| 60 | virtual bool IsUnresolvedAndUninitializedReference() const { return false; } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 61 | virtual bool IsUnresolvedAndUninitializedThisReference() const { |
| 62 | return false; |
| 63 | } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 64 | virtual bool IsUnresolvedMergedReference() const { return false; } |
| 65 | virtual bool IsUnresolvedSuperClass() const { return false; } |
| 66 | virtual bool IsReference() const { return false; } |
| 67 | virtual bool IsPreciseReference() const { return false; } |
| 68 | virtual bool IsPreciseConstant() const { return false; } |
| 69 | virtual bool IsPreciseConstantLo() const { return false; } |
| 70 | virtual bool IsPreciseConstantHi() const { return false; } |
| 71 | virtual bool IsImpreciseConstantLo() const { return false; } |
| 72 | virtual bool IsImpreciseConstantHi() const { return false; } |
| 73 | virtual bool IsImpreciseConstant() const { return false; } |
| 74 | virtual bool IsConstantTypes() const { return false; } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 75 | bool IsConstant() const { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 76 | return IsImpreciseConstant() || IsPreciseConstant(); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 77 | } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 78 | bool IsConstantLo() const { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 79 | return IsImpreciseConstantLo() || IsPreciseConstantLo(); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 80 | } |
| 81 | bool IsPrecise() const { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 82 | return IsPreciseConstantLo() || IsPreciseConstant() || |
| 83 | IsPreciseConstantHi(); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 84 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 85 | bool IsLongConstant() const { return IsConstantLo(); } |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 86 | bool IsConstantHi() const { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 87 | return (IsPreciseConstantHi() || IsImpreciseConstantHi()); |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 88 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 89 | bool IsLongConstantHigh() const { return IsConstantHi(); } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 90 | virtual bool IsUninitializedTypes() const { return false; } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 91 | virtual bool IsUnresolvedTypes() const { return false; } |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 92 | |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 93 | bool IsLowHalf() const { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 94 | return (IsLongLo() || IsDoubleLo() || IsPreciseConstantLo() || IsImpreciseConstantLo()); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 95 | } |
| 96 | bool IsHighHalf() const { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 97 | return (IsLongHi() || IsDoubleHi() || IsPreciseConstantHi() || IsImpreciseConstantHi()); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 98 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 99 | bool IsLongOrDoubleTypes() const { return IsLowHalf(); } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 100 | // Check this is the low half, and that type_h is its matching high-half. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 101 | inline bool CheckWidePair(const RegType& type_h) const { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 102 | if (IsLowHalf()) { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 103 | return ((IsImpreciseConstantLo() && type_h.IsPreciseConstantHi()) || |
Sameer Abu Asal | 998be61 | 2013-03-31 18:40:48 -0700 | [diff] [blame] | 104 | (IsImpreciseConstantLo() && type_h.IsImpreciseConstantHi()) || |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 105 | (IsPreciseConstantLo() && type_h.IsPreciseConstantHi()) || |
| 106 | (IsPreciseConstantLo() && type_h.IsImpreciseConstantHi()) || |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 107 | (IsDoubleLo() && type_h.IsDoubleHi()) || |
| 108 | (IsLongLo() && type_h.IsLongHi())); |
| 109 | } |
| 110 | return false; |
| 111 | } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 112 | // The high half that corresponds to this low half |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 113 | const RegType& HighHalf(RegTypeCache* cache) const |
| 114 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 115 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 116 | bool IsConstantBoolean() const; |
| 117 | virtual bool IsConstantChar() const { return false; } |
| 118 | virtual bool IsConstantByte() const { return false; } |
| 119 | virtual bool IsConstantShort() const { return false; } |
| 120 | virtual bool IsOne() const { return false; } |
| 121 | virtual bool IsZero() const { return false; } |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 122 | bool IsReferenceTypes() const { |
jeffhao | 182e90b | 2012-05-01 18:27:09 -0700 | [diff] [blame] | 123 | return IsNonZeroReferenceTypes() || IsZero(); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 124 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 125 | virtual bool IsNonZeroReferenceTypes() const { return false; } |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 126 | bool IsCategory1Types() const { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 127 | return IsChar() || IsInteger() || IsFloat() || IsConstant() || IsByte() || |
| 128 | IsShort() || IsBoolean(); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 129 | } |
| 130 | bool IsCategory2Types() const { |
| 131 | return IsLowHalf(); // Don't expect explicit testing of high halves |
| 132 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 133 | bool IsBooleanTypes() const { return IsBoolean() || IsConstantBoolean(); } |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 134 | bool IsByteTypes() const { |
Sameer Abu Asal | 2c6de22 | 2013-05-02 17:38:59 -0700 | [diff] [blame] | 135 | return IsConstantByte() || IsByte() || IsBoolean(); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 136 | } |
| 137 | bool IsShortTypes() const { |
| 138 | return IsShort() || IsByte() || IsBoolean() || IsConstantShort(); |
| 139 | } |
| 140 | bool IsCharTypes() const { |
| 141 | return IsChar() || IsBooleanTypes() || IsConstantChar(); |
| 142 | } |
| 143 | bool IsIntegralTypes() const { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 144 | return IsInteger() || IsConstant() || IsByte() || IsShort() || IsChar() || |
| 145 | IsBoolean(); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 146 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 147 | // Give the constant value encoded, but this shouldn't be called in the |
| 148 | // general case. |
| 149 | bool IsArrayIndexTypes() const { return IsIntegralTypes(); } |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 150 | // Float type may be derived from any constant type |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 151 | bool IsFloatTypes() const { return IsFloat() || IsConstant(); } |
| 152 | bool IsLongTypes() const { return IsLongLo() || IsLongConstant(); } |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 153 | bool IsLongHighTypes() const { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 154 | return (IsLongHi() || IsPreciseConstantHi() || IsImpreciseConstantHi()); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 155 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 156 | bool IsDoubleTypes() const { return IsDoubleLo() || IsLongConstant(); } |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 157 | bool IsDoubleHighTypes() const { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 158 | return (IsDoubleHi() || IsPreciseConstantHi() || IsImpreciseConstantHi()); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 159 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 160 | virtual bool IsLong() const { return false; } |
| 161 | bool HasClass() const { |
| 162 | bool result = !klass_.IsNull(); |
| 163 | DCHECK_EQ(result, HasClassVirtual()); |
| 164 | return result; |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 165 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 166 | virtual bool HasClassVirtual() const { return false; } |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 167 | bool IsJavaLangObject() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 168 | bool IsArrayTypes() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 169 | bool IsObjectArrayTypes() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 02c8cc6 | 2013-07-18 15:54:44 -0700 | [diff] [blame] | 170 | Primitive::Type GetPrimitiveType() const; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 171 | bool IsJavaLangObjectArray() const |
| 172 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 173 | bool IsInstantiableTypes() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sameer Abu Asal | 2c6de22 | 2013-05-02 17:38:59 -0700 | [diff] [blame] | 174 | const std::string& GetDescriptor() const { |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 175 | DCHECK(HasClass() || |
| 176 | (IsUnresolvedTypes() && !IsUnresolvedMergedReference() && |
| 177 | !IsUnresolvedSuperClass())); |
Elliott Hughes | 80537bb | 2013-01-04 16:37:26 -0800 | [diff] [blame] | 178 | return descriptor_; |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 179 | } |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 180 | mirror::Class* GetClass() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 181 | DCHECK(!IsUnresolvedReference()); |
Ian Rogers | 5441091 | 2014-09-10 15:33:05 -0700 | [diff] [blame] | 182 | DCHECK(!klass_.IsNull()) << Dump(); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 183 | DCHECK(HasClass()); |
Ian Rogers | 5441091 | 2014-09-10 15:33:05 -0700 | [diff] [blame] | 184 | return klass_.Read(); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 185 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 186 | uint16_t GetId() const { return cache_id_; } |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 187 | const RegType& GetSuperClass(RegTypeCache* cache) const |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 188 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 189 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 190 | virtual std::string Dump() const |
| 191 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0; |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 192 | |
| 193 | // Can this type access other? |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 194 | bool CanAccess(const RegType& other) const |
| 195 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 196 | |
| 197 | // Can this type access a member with the given properties? |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 198 | bool CanAccessMember(mirror::Class* klass, uint32_t access_flags) const |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 199 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 200 | |
| 201 | // Can this type be assigned by src? |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 202 | // Note: Object and interface types may always be assigned to one another, see |
| 203 | // comment on |
Ian Rogers | 16e3d2c | 2013-06-07 12:57:00 -0700 | [diff] [blame] | 204 | // ClassJoin. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 205 | bool IsAssignableFrom(const RegType& src) const |
| 206 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 16e3d2c | 2013-06-07 12:57:00 -0700 | [diff] [blame] | 207 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 208 | // Can this type be assigned by src? Variant of IsAssignableFrom that doesn't |
| 209 | // allow assignment to |
Ian Rogers | 16e3d2c | 2013-06-07 12:57:00 -0700 | [diff] [blame] | 210 | // an interface from an Object. |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 211 | bool IsStrictlyAssignableFrom(const RegType& src) const |
| 212 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 213 | |
| 214 | // Are these RegTypes the same? |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 215 | bool Equals(const RegType& other) const { return GetId() == other.GetId(); } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 216 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 217 | // Compute the merge of this register from one edge (path) with incoming_type |
| 218 | // from another. |
| 219 | const RegType& Merge(const RegType& incoming_type, RegTypeCache* reg_types) const |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 220 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 221 | |
Ian Rogers | 16e3d2c | 2013-06-07 12:57:00 -0700 | [diff] [blame] | 222 | /* |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 223 | * A basic Join operation on classes. For a pair of types S and T the Join, |
| 224 | *written S v T = J, is |
| 225 | * S <: J, T <: J and for-all U such that S <: U, T <: U then J <: U. That is |
| 226 | *J is the parent of |
| 227 | * S and T such that there isn't a parent of both S and T that isn't also the |
| 228 | *parent of J (ie J |
Ian Rogers | 16e3d2c | 2013-06-07 12:57:00 -0700 | [diff] [blame] | 229 | * is the deepest (lowest upper bound) parent of S and T). |
| 230 | * |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 231 | * This operation applies for regular classes and arrays, however, for |
| 232 | *interface types there |
| 233 | * needn't be a partial ordering on the types. We could solve the problem of a |
| 234 | *lack of a partial |
| 235 | * order by introducing sets of types, however, the only operation permissible |
| 236 | *on an interface is |
| 237 | * invoke-interface. In the tradition of Java verifiers [1] we defer the |
| 238 | *verification of interface |
| 239 | * types until an invoke-interface call on the interface typed reference at |
| 240 | *runtime and allow |
| 241 | * the perversion of Object being assignable to an interface type (note, |
| 242 | *however, that we don't |
| 243 | * allow assignment of Object or Interface to any concrete class and are |
| 244 | *therefore type safe). |
Ian Rogers | 16e3d2c | 2013-06-07 12:57:00 -0700 | [diff] [blame] | 245 | * |
| 246 | * [1] Java bytecode verification: algorithms and formalizations, Xavier Leroy |
| 247 | */ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 248 | static mirror::Class* ClassJoin(mirror::Class* s, mirror::Class* t) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 249 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 250 | |
| 251 | virtual ~RegType() {} |
| 252 | |
Mathieu Chartier | 12d625f | 2015-03-13 11:33:37 -0700 | [diff] [blame] | 253 | void VisitRoots(RootCallback* callback, void* arg, const RootInfo& root_info) const |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 254 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 255 | |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 256 | protected: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 257 | RegType(mirror::Class* klass, const std::string& descriptor, |
| 258 | uint16_t cache_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
Ian Rogers | d8f69b0 | 2014-09-10 21:43:52 +0000 | [diff] [blame] | 259 | : descriptor_(descriptor), klass_(klass), cache_id_(cache_id) { |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 260 | if (kIsDebugBuild) { |
| 261 | CheckInvariants(); |
| 262 | } |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 263 | } |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 264 | |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 265 | void CheckInvariants() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 266 | |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 267 | const std::string descriptor_; |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 268 | mutable GcRoot<mirror::Class> |
| 269 | klass_; // Non-const only due to moving classes. |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 270 | const uint16_t cache_id_; |
| 271 | |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 272 | friend class RegTypeCache; |
| 273 | |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 274 | private: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 275 | static bool AssignableFrom(const RegType& lhs, const RegType& rhs, bool strict) |
| 276 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 277 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 278 | DISALLOW_COPY_AND_ASSIGN(RegType); |
| 279 | }; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 280 | |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 281 | // Bottom type. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 282 | class ConflictType FINAL : public RegType { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 283 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 284 | bool IsConflict() const OVERRIDE { return true; } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 285 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 286 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 287 | |
| 288 | // Get the singleton Conflict instance. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 289 | static const ConflictType* GetInstance() PURE; |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 290 | |
| 291 | // Create the singleton instance. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 292 | static const ConflictType* CreateInstance(mirror::Class* klass, |
| 293 | const std::string& descriptor, |
| 294 | uint16_t cache_id) |
Ian Rogers | 1bf8d4d | 2013-05-30 00:18:49 -0700 | [diff] [blame] | 295 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 296 | |
| 297 | // Destroy the singleton instance. |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 298 | static void Destroy(); |
Brian Carlstrom | 0cd7ec2 | 2013-07-17 23:40:20 -0700 | [diff] [blame] | 299 | |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 300 | private: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 301 | ConflictType(mirror::Class* klass, const std::string& descriptor, |
| 302 | uint16_t cache_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 303 | : RegType(klass, descriptor, cache_id) {} |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 304 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 305 | static const ConflictType* instance_; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 306 | }; |
| 307 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 308 | // A variant of the bottom type used to specify an undefined value in the |
| 309 | // incoming registers. |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 310 | // Merging with UndefinedType yields ConflictType which is the true bottom. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 311 | class UndefinedType FINAL : public RegType { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 312 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 313 | bool IsUndefined() const OVERRIDE { return true; } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 314 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 315 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 316 | |
| 317 | // Get the singleton Undefined instance. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 318 | static const UndefinedType* GetInstance() PURE; |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 319 | |
| 320 | // Create the singleton instance. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 321 | static const UndefinedType* CreateInstance(mirror::Class* klass, |
| 322 | const std::string& descriptor, |
| 323 | uint16_t cache_id) |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 324 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 325 | |
| 326 | // Destroy the singleton instance. |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 327 | static void Destroy(); |
Brian Carlstrom | 0cd7ec2 | 2013-07-17 23:40:20 -0700 | [diff] [blame] | 328 | |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 329 | private: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 330 | UndefinedType(mirror::Class* klass, const std::string& descriptor, |
| 331 | uint16_t cache_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 332 | : RegType(klass, descriptor, cache_id) {} |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 333 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 334 | static const UndefinedType* instance_; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 335 | }; |
| 336 | |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 337 | class PrimitiveType : public RegType { |
| 338 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 339 | PrimitiveType(mirror::Class* klass, const std::string& descriptor, |
| 340 | uint16_t cache_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Logan Chien | 10f0ca2 | 2014-09-23 23:01:47 +0800 | [diff] [blame] | 341 | |
| 342 | bool HasClassVirtual() const OVERRIDE { return true; } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 343 | }; |
| 344 | |
| 345 | class Cat1Type : public PrimitiveType { |
| 346 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 347 | Cat1Type(mirror::Class* klass, const std::string& descriptor, |
| 348 | uint16_t cache_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 349 | }; |
| 350 | |
| 351 | class IntegerType : public Cat1Type { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 352 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 353 | bool IsInteger() const OVERRIDE { return true; } |
| 354 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 355 | static const IntegerType* CreateInstance(mirror::Class* klass, |
| 356 | const std::string& descriptor, |
| 357 | uint16_t cache_id) |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 358 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 359 | static const IntegerType* GetInstance() PURE; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 360 | static void Destroy(); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 361 | |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 362 | private: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 363 | IntegerType(mirror::Class* klass, const std::string& descriptor, |
| 364 | uint16_t cache_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 365 | : Cat1Type(klass, descriptor, cache_id) {} |
| 366 | static const IntegerType* instance_; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 367 | }; |
| 368 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 369 | class BooleanType FINAL : public Cat1Type { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 370 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 371 | bool IsBoolean() const OVERRIDE { return true; } |
| 372 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 373 | static const BooleanType* CreateInstance(mirror::Class* klass, |
| 374 | const std::string& descriptor, |
| 375 | uint16_t cache_id) |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 376 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 377 | static const BooleanType* GetInstance() PURE; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 378 | static void Destroy(); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 379 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 380 | private: |
| 381 | BooleanType(mirror::Class* klass, const std::string& descriptor, |
| 382 | uint16_t cache_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 383 | : Cat1Type(klass, descriptor, cache_id) {} |
| 384 | |
| 385 | static const BooleanType* instance_; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 386 | }; |
| 387 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 388 | class ByteType FINAL : public Cat1Type { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 389 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 390 | bool IsByte() const OVERRIDE { return true; } |
| 391 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 392 | static const ByteType* CreateInstance(mirror::Class* klass, |
| 393 | const std::string& descriptor, |
| 394 | uint16_t cache_id) |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 395 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 396 | static const ByteType* GetInstance() PURE; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 397 | static void Destroy(); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 398 | |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 399 | private: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 400 | ByteType(mirror::Class* klass, const std::string& descriptor, |
| 401 | uint16_t cache_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 402 | : Cat1Type(klass, descriptor, cache_id) {} |
| 403 | static const ByteType* instance_; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 404 | }; |
| 405 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 406 | class ShortType FINAL : public Cat1Type { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 407 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 408 | bool IsShort() const OVERRIDE { return true; } |
| 409 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 410 | static const ShortType* CreateInstance(mirror::Class* klass, |
| 411 | const std::string& descriptor, |
| 412 | uint16_t cache_id) |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 413 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 414 | static const ShortType* GetInstance() PURE; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 415 | static void Destroy(); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 416 | |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 417 | private: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 418 | ShortType(mirror::Class* klass, const std::string& descriptor, |
| 419 | uint16_t cache_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 420 | : Cat1Type(klass, descriptor, cache_id) {} |
| 421 | static const ShortType* instance_; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 422 | }; |
| 423 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 424 | class CharType FINAL : public Cat1Type { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 425 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 426 | bool IsChar() const OVERRIDE { return true; } |
| 427 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 428 | static const CharType* CreateInstance(mirror::Class* klass, |
| 429 | const std::string& descriptor, |
| 430 | uint16_t cache_id) |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 431 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 432 | static const CharType* GetInstance() PURE; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 433 | static void Destroy(); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 434 | |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 435 | private: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 436 | CharType(mirror::Class* klass, const std::string& descriptor, |
| 437 | uint16_t cache_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 438 | : Cat1Type(klass, descriptor, cache_id) {} |
| 439 | static const CharType* instance_; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 440 | }; |
| 441 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 442 | class FloatType FINAL : public Cat1Type { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 443 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 444 | bool IsFloat() const OVERRIDE { return true; } |
| 445 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 446 | static const FloatType* CreateInstance(mirror::Class* klass, |
| 447 | const std::string& descriptor, |
| 448 | uint16_t cache_id) |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 449 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 450 | static const FloatType* GetInstance() PURE; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 451 | static void Destroy(); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 452 | |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 453 | private: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 454 | FloatType(mirror::Class* klass, const std::string& descriptor, |
| 455 | uint16_t cache_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 456 | : Cat1Type(klass, descriptor, cache_id) {} |
| 457 | static const FloatType* instance_; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 458 | }; |
| 459 | |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 460 | class Cat2Type : public PrimitiveType { |
| 461 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 462 | Cat2Type(mirror::Class* klass, const std::string& descriptor, |
| 463 | uint16_t cache_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 464 | }; |
| 465 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 466 | class LongLoType FINAL : public Cat2Type { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 467 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 468 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 469 | bool IsLongLo() const OVERRIDE { return true; } |
| 470 | bool IsLong() const OVERRIDE { return true; } |
| 471 | static const LongLoType* CreateInstance(mirror::Class* klass, |
| 472 | const std::string& descriptor, |
| 473 | uint16_t cache_id) |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 474 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 475 | static const LongLoType* GetInstance() PURE; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 476 | static void Destroy(); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 477 | |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 478 | private: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 479 | LongLoType(mirror::Class* klass, const std::string& descriptor, |
| 480 | uint16_t cache_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 481 | : Cat2Type(klass, descriptor, cache_id) {} |
| 482 | static const LongLoType* instance_; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 483 | }; |
| 484 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 485 | class LongHiType FINAL : public Cat2Type { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 486 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 487 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 488 | bool IsLongHi() const OVERRIDE { return true; } |
| 489 | static const LongHiType* CreateInstance(mirror::Class* klass, |
| 490 | const std::string& descriptor, |
| 491 | uint16_t cache_id) |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 492 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 493 | static const LongHiType* GetInstance() PURE; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 494 | static void Destroy(); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 495 | |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 496 | private: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 497 | LongHiType(mirror::Class* klass, const std::string& descriptor, |
| 498 | uint16_t cache_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 499 | : Cat2Type(klass, descriptor, cache_id) {} |
| 500 | static const LongHiType* instance_; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 501 | }; |
| 502 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 503 | class DoubleLoType FINAL : public Cat2Type { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 504 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 505 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 506 | bool IsDoubleLo() const OVERRIDE { return true; } |
| 507 | bool IsDouble() const OVERRIDE { return true; } |
| 508 | static const DoubleLoType* CreateInstance(mirror::Class* klass, |
| 509 | const std::string& descriptor, |
| 510 | uint16_t cache_id) |
| 511 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 512 | static const DoubleLoType* GetInstance() PURE; |
| 513 | static void Destroy(); |
| 514 | |
| 515 | private: |
| 516 | DoubleLoType(mirror::Class* klass, const std::string& descriptor, |
| 517 | uint16_t cache_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 518 | : Cat2Type(klass, descriptor, cache_id) {} |
| 519 | static const DoubleLoType* instance_; |
| 520 | }; |
| 521 | |
| 522 | class DoubleHiType FINAL : public Cat2Type { |
| 523 | public: |
| 524 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 525 | virtual bool IsDoubleHi() const OVERRIDE { return true; } |
| 526 | static const DoubleHiType* CreateInstance(mirror::Class* klass, |
| 527 | const std::string& descriptor, |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 528 | uint16_t cache_id) |
| 529 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 530 | static const DoubleHiType* GetInstance() PURE; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 531 | static void Destroy(); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 532 | |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 533 | private: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 534 | DoubleHiType(mirror::Class* klass, const std::string& descriptor, |
| 535 | uint16_t cache_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 536 | : Cat2Type(klass, descriptor, cache_id) {} |
| 537 | static const DoubleHiType* instance_; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 538 | }; |
| 539 | |
| 540 | class ConstantType : public RegType { |
| 541 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 542 | ConstantType(uint32_t constant, uint16_t cache_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 543 | : RegType(nullptr, "", cache_id), constant_(constant) { |
| 544 | } |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 545 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 546 | |
| 547 | // If this is a 32-bit constant, what is the value? This value may be |
| 548 | // imprecise in which case |
| 549 | // the value represents part of the integer range of values that may be held |
| 550 | // in the register. |
Ian Rogers | fc0e94b | 2013-09-23 23:51:32 -0700 | [diff] [blame] | 551 | int32_t ConstantValue() const { |
| 552 | DCHECK(IsConstantTypes()); |
| 553 | return constant_; |
| 554 | } |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 555 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 556 | int32_t ConstantValueLo() const { |
| 557 | DCHECK(IsConstantLo()); |
| 558 | return constant_; |
| 559 | } |
| 560 | |
| 561 | int32_t ConstantValueHi() const { |
| 562 | if (IsConstantHi() || IsPreciseConstantHi() || IsImpreciseConstantHi()) { |
| 563 | return constant_; |
| 564 | } else { |
| 565 | DCHECK(false); |
| 566 | return 0; |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | bool IsZero() const OVERRIDE { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 571 | return IsPreciseConstant() && ConstantValue() == 0; |
| 572 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 573 | bool IsOne() const OVERRIDE { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 574 | return IsPreciseConstant() && ConstantValue() == 1; |
| 575 | } |
| 576 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 577 | bool IsConstantChar() const OVERRIDE { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 578 | return IsConstant() && ConstantValue() >= 0 && |
Ian Rogers | 8e1f4f8 | 2014-11-05 11:07:30 -0800 | [diff] [blame] | 579 | ConstantValue() <= std::numeric_limits<uint16_t>::max(); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 580 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 581 | bool IsConstantByte() const OVERRIDE { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 582 | return IsConstant() && |
Ian Rogers | 8e1f4f8 | 2014-11-05 11:07:30 -0800 | [diff] [blame] | 583 | ConstantValue() >= std::numeric_limits<int8_t>::min() && |
| 584 | ConstantValue() <= std::numeric_limits<int8_t>::max(); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 585 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 586 | bool IsConstantShort() const OVERRIDE { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 587 | return IsConstant() && |
Ian Rogers | 8e1f4f8 | 2014-11-05 11:07:30 -0800 | [diff] [blame] | 588 | ConstantValue() >= std::numeric_limits<int16_t>::min() && |
| 589 | ConstantValue() <= std::numeric_limits<int16_t>::max(); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 590 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 591 | virtual bool IsConstantTypes() const OVERRIDE { return true; } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 592 | |
| 593 | private: |
| 594 | const uint32_t constant_; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 595 | }; |
Sameer Abu Asal | 2c6de22 | 2013-05-02 17:38:59 -0700 | [diff] [blame] | 596 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 597 | class PreciseConstType FINAL : public ConstantType { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 598 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 599 | PreciseConstType(uint32_t constant, uint16_t cache_id) |
| 600 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 601 | : ConstantType(constant, cache_id) {} |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 602 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 603 | bool IsPreciseConstant() const OVERRIDE { return true; } |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 604 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 605 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 606 | }; |
Sameer Abu Asal | 2c6de22 | 2013-05-02 17:38:59 -0700 | [diff] [blame] | 607 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 608 | class PreciseConstLoType FINAL : public ConstantType { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 609 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 610 | PreciseConstLoType(uint32_t constant, uint16_t cache_id) |
| 611 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 612 | : ConstantType(constant, cache_id) {} |
| 613 | bool IsPreciseConstantLo() const OVERRIDE { return true; } |
| 614 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 615 | }; |
Sameer Abu Asal | 2c6de22 | 2013-05-02 17:38:59 -0700 | [diff] [blame] | 616 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 617 | class PreciseConstHiType FINAL : public ConstantType { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 618 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 619 | PreciseConstHiType(uint32_t constant, uint16_t cache_id) |
| 620 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 621 | : ConstantType(constant, cache_id) {} |
| 622 | bool IsPreciseConstantHi() const OVERRIDE { return true; } |
| 623 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 624 | }; |
| 625 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 626 | class ImpreciseConstType FINAL : public ConstantType { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 627 | public: |
| 628 | ImpreciseConstType(uint32_t constat, uint16_t cache_id) |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 629 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 630 | : ConstantType(constat, cache_id) { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 631 | } |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 632 | bool IsImpreciseConstant() const OVERRIDE { return true; } |
| 633 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 634 | }; |
Sameer Abu Asal | 2c6de22 | 2013-05-02 17:38:59 -0700 | [diff] [blame] | 635 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 636 | class ImpreciseConstLoType FINAL : public ConstantType { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 637 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 638 | ImpreciseConstLoType(uint32_t constant, uint16_t cache_id) |
| 639 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 640 | : ConstantType(constant, cache_id) {} |
| 641 | bool IsImpreciseConstantLo() const OVERRIDE { return true; } |
| 642 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 643 | }; |
Sameer Abu Asal | 2c6de22 | 2013-05-02 17:38:59 -0700 | [diff] [blame] | 644 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 645 | class ImpreciseConstHiType FINAL : public ConstantType { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 646 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 647 | ImpreciseConstHiType(uint32_t constant, uint16_t cache_id) |
| 648 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 649 | : ConstantType(constant, cache_id) {} |
| 650 | bool IsImpreciseConstantHi() const OVERRIDE { return true; } |
| 651 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 652 | }; |
Sameer Abu Asal | 2c6de22 | 2013-05-02 17:38:59 -0700 | [diff] [blame] | 653 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 654 | // Common parent of all uninitialized types. Uninitialized types are created by |
| 655 | // "new" dex |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 656 | // instructions and must be passed to a constructor. |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 657 | class UninitializedType : public RegType { |
| 658 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 659 | UninitializedType(mirror::Class* klass, const std::string& descriptor, |
| 660 | uint32_t allocation_pc, uint16_t cache_id) |
| 661 | : RegType(klass, descriptor, cache_id), allocation_pc_(allocation_pc) {} |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 662 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 663 | bool IsUninitializedTypes() const OVERRIDE; |
| 664 | bool IsNonZeroReferenceTypes() const OVERRIDE; |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 665 | |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 666 | uint32_t GetAllocationPc() const { |
| 667 | DCHECK(IsUninitializedTypes()); |
| 668 | return allocation_pc_; |
| 669 | } |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 670 | |
| 671 | private: |
| 672 | const uint32_t allocation_pc_; |
| 673 | }; |
| 674 | |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 675 | // Similar to ReferenceType but not yet having been passed to a constructor. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 676 | class UninitializedReferenceType FINAL : public UninitializedType { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 677 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 678 | UninitializedReferenceType(mirror::Class* klass, |
| 679 | const std::string& descriptor, |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 680 | uint32_t allocation_pc, uint16_t cache_id) |
| 681 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 682 | : UninitializedType(klass, descriptor, allocation_pc, cache_id) {} |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 683 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 684 | bool IsUninitializedReference() const OVERRIDE { return true; } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 685 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 686 | bool HasClassVirtual() const OVERRIDE { return true; } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 687 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 688 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 689 | }; |
| 690 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 691 | // Similar to UnresolvedReferenceType but not yet having been passed to a |
| 692 | // constructor. |
| 693 | class UnresolvedUninitializedRefType FINAL : public UninitializedType { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 694 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 695 | UnresolvedUninitializedRefType(const std::string& descriptor, |
| 696 | uint32_t allocation_pc, uint16_t cache_id) |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 697 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 698 | : UninitializedType(NULL, descriptor, allocation_pc, cache_id) { |
| 699 | if (kIsDebugBuild) { |
| 700 | CheckInvariants(); |
| 701 | } |
| 702 | } |
| 703 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 704 | bool IsUnresolvedAndUninitializedReference() const OVERRIDE { return true; } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 705 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 706 | bool IsUnresolvedTypes() const OVERRIDE { return true; } |
| 707 | |
| 708 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 709 | |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 710 | private: |
| 711 | void CheckInvariants() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 712 | }; |
| 713 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 714 | // Similar to UninitializedReferenceType but special case for the this argument |
| 715 | // of a constructor. |
| 716 | class UninitializedThisReferenceType FINAL : public UninitializedType { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 717 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 718 | UninitializedThisReferenceType(mirror::Class* klass, |
| 719 | const std::string& descriptor, |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 720 | uint16_t cache_id) |
| 721 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 722 | : UninitializedType(klass, descriptor, 0, cache_id) { |
| 723 | if (kIsDebugBuild) { |
| 724 | CheckInvariants(); |
| 725 | } |
| 726 | } |
| 727 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 728 | virtual bool IsUninitializedThisReference() const OVERRIDE { return true; } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 729 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 730 | bool HasClassVirtual() const OVERRIDE { return true; } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 731 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 732 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 733 | |
| 734 | private: |
| 735 | void CheckInvariants() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 736 | }; |
Sameer Abu Asal | 2c6de22 | 2013-05-02 17:38:59 -0700 | [diff] [blame] | 737 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 738 | class UnresolvedUninitializedThisRefType FINAL : public UninitializedType { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 739 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 740 | UnresolvedUninitializedThisRefType(const std::string& descriptor, |
| 741 | uint16_t cache_id) |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 742 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 743 | : UninitializedType(NULL, descriptor, 0, cache_id) { |
| 744 | if (kIsDebugBuild) { |
| 745 | CheckInvariants(); |
| 746 | } |
| 747 | } |
| 748 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 749 | bool IsUnresolvedAndUninitializedThisReference() const OVERRIDE { return true; } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 750 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 751 | bool IsUnresolvedTypes() const OVERRIDE { return true; } |
| 752 | |
| 753 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 754 | |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 755 | private: |
| 756 | void CheckInvariants() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 757 | }; |
| 758 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 759 | // A type of register holding a reference to an Object of type GetClass or a |
| 760 | // sub-class. |
| 761 | class ReferenceType FINAL : public RegType { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 762 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 763 | ReferenceType(mirror::Class* klass, const std::string& descriptor, |
| 764 | uint16_t cache_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 765 | : RegType(klass, descriptor, cache_id) {} |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 766 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 767 | bool IsReference() const OVERRIDE { return true; } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 768 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 769 | bool IsNonZeroReferenceTypes() const OVERRIDE { return true; } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 770 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 771 | bool HasClassVirtual() const OVERRIDE { return true; } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 772 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 773 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 774 | }; |
| 775 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 776 | // A type of register holding a reference to an Object of type GetClass and only |
| 777 | // an object of that |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 778 | // type. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 779 | class PreciseReferenceType FINAL : public RegType { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 780 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 781 | PreciseReferenceType(mirror::Class* klass, const std::string& descriptor, |
| 782 | uint16_t cache_id) |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 783 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 784 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 785 | bool IsPreciseReference() const OVERRIDE { return true; } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 786 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 787 | bool IsNonZeroReferenceTypes() const OVERRIDE { return true; } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 788 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 789 | bool HasClassVirtual() const OVERRIDE { return true; } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 790 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 791 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 792 | }; |
| 793 | |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 794 | // Common parent of unresolved types. |
| 795 | class UnresolvedType : public RegType { |
| 796 | public: |
| 797 | UnresolvedType(const std::string& descriptor, uint16_t cache_id) |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 798 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 799 | : RegType(NULL, descriptor, cache_id) {} |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 800 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 801 | bool IsNonZeroReferenceTypes() const OVERRIDE; |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 802 | }; |
| 803 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 804 | // Similar to ReferenceType except the Class couldn't be loaded. Assignability |
| 805 | // and other tests made |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 806 | // of this type must be conservative. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 807 | class UnresolvedReferenceType FINAL : public UnresolvedType { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 808 | public: |
Ian Rogers | 1bf8d4d | 2013-05-30 00:18:49 -0700 | [diff] [blame] | 809 | UnresolvedReferenceType(const std::string& descriptor, uint16_t cache_id) |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 810 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
| 811 | : UnresolvedType(descriptor, cache_id) { |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 812 | if (kIsDebugBuild) { |
| 813 | CheckInvariants(); |
| 814 | } |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 815 | } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 816 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 817 | bool IsUnresolvedReference() const OVERRIDE { return true; } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 818 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 819 | bool IsUnresolvedTypes() const OVERRIDE { return true; } |
| 820 | |
| 821 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 822 | |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 823 | private: |
| 824 | void CheckInvariants() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 825 | }; |
| 826 | |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 827 | // Type representing the super-class of an unresolved type. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 828 | class UnresolvedSuperClass FINAL : public UnresolvedType { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 829 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 830 | UnresolvedSuperClass(uint16_t child_id, RegTypeCache* reg_type_cache, |
| 831 | uint16_t cache_id) |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 832 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 833 | : UnresolvedType("", cache_id), |
| 834 | unresolved_child_id_(child_id), |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 835 | reg_type_cache_(reg_type_cache) { |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 836 | if (kIsDebugBuild) { |
| 837 | CheckInvariants(); |
| 838 | } |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 839 | } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 840 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 841 | bool IsUnresolvedSuperClass() const OVERRIDE { return true; } |
| 842 | |
| 843 | bool IsUnresolvedTypes() const OVERRIDE { return true; } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 844 | |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 845 | uint16_t GetUnresolvedSuperClassChildId() const { |
| 846 | DCHECK(IsUnresolvedSuperClass()); |
| 847 | return static_cast<uint16_t>(unresolved_child_id_ & 0xFFFF); |
| 848 | } |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 849 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 850 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 0cd7ec2 | 2013-07-17 23:40:20 -0700 | [diff] [blame] | 851 | |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 852 | private: |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 853 | void CheckInvariants() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 854 | |
Sameer Abu Asal | 2c6de22 | 2013-05-02 17:38:59 -0700 | [diff] [blame] | 855 | const uint16_t unresolved_child_id_; |
| 856 | const RegTypeCache* const reg_type_cache_; |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 857 | }; |
| 858 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 859 | // A merge of two unresolved types. If the types were resolved this may be |
| 860 | // Conflict or another |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 861 | // known ReferenceType. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 862 | class UnresolvedMergedType FINAL : public UnresolvedType { |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 863 | public: |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 864 | UnresolvedMergedType(uint16_t left_id, uint16_t right_id, |
| 865 | const RegTypeCache* reg_type_cache, uint16_t cache_id) |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 866 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 867 | : UnresolvedType("", cache_id), |
| 868 | reg_type_cache_(reg_type_cache), |
| 869 | merged_types_(left_id, right_id) { |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 870 | if (kIsDebugBuild) { |
| 871 | CheckInvariants(); |
| 872 | } |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 873 | } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 874 | |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 875 | // The top of a tree of merged types. |
| 876 | std::pair<uint16_t, uint16_t> GetTopMergedTypes() const { |
| 877 | DCHECK(IsUnresolvedMergedReference()); |
| 878 | return merged_types_; |
| 879 | } |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 880 | |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 881 | // The complete set of merged types. |
| 882 | std::set<uint16_t> GetMergedTypes() const; |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 883 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 884 | bool IsUnresolvedMergedReference() const OVERRIDE { return true; } |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 885 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 886 | bool IsUnresolvedTypes() const OVERRIDE { return true; } |
| 887 | |
| 888 | std::string Dump() const OVERRIDE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 0cd7ec2 | 2013-07-17 23:40:20 -0700 | [diff] [blame] | 889 | |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 890 | private: |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 891 | void CheckInvariants() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 892 | |
Sameer Abu Asal | 51a5fb7 | 2013-02-19 14:25:01 -0800 | [diff] [blame] | 893 | const RegTypeCache* const reg_type_cache_; |
| 894 | const std::pair<uint16_t, uint16_t> merged_types_; |
| 895 | }; |
| 896 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 897 | std::ostream& operator<<(std::ostream& os, const RegType& rhs) |
| 898 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 899 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 900 | } // namespace verifier |
| 901 | } // namespace art |
| 902 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 903 | #endif // ART_RUNTIME_VERIFIER_REG_TYPE_H_ |