OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef V8_TYPES_INL_H_ |
| 6 #define V8_TYPES_INL_H_ |
| 7 |
| 8 #include "factory.h" |
| 9 #include "handles-inl.h" |
| 10 #include "types.h" |
| 11 |
| 12 namespace v8 { |
| 13 namespace internal { |
| 14 |
| 15 // static |
| 16 ZoneTypeConfig::Tagged* ZoneTypeConfig::tagged_create( |
| 17 Tag tag, int size, Zone* zone) { |
| 18 Tagged* tagged = new(zone) Tagged(size + 1, zone); |
| 19 tagged->Add(reinterpret_cast<void*>(tag), zone); |
| 20 tagged->AddBlock(NULL, size, zone); |
| 21 return tagged; |
| 22 } |
| 23 |
| 24 |
| 25 // static |
| 26 void ZoneTypeConfig::tagged_shrink(Tagged* tagged, int size) { |
| 27 tagged->Rewind(size + 1); |
| 28 } |
| 29 |
| 30 |
| 31 // static |
| 32 ZoneTypeConfig::Tag ZoneTypeConfig::tagged_tag(Tagged* tagged) { |
| 33 return static_cast<Tag>(reinterpret_cast<intptr_t>(tagged->at(0))); |
| 34 } |
| 35 |
| 36 |
| 37 // static |
| 38 template<class T> |
| 39 T ZoneTypeConfig::tagged_get(Tagged* tagged, int i) { |
| 40 return reinterpret_cast<T>(tagged->at(i + 1)); |
| 41 } |
| 42 |
| 43 |
| 44 // static |
| 45 template<class T> |
| 46 void ZoneTypeConfig::tagged_set(Tagged* tagged, int i, T value) { |
| 47 tagged->at(i + 1) = reinterpret_cast<void*>(value); |
| 48 } |
| 49 |
| 50 |
| 51 // static |
| 52 int ZoneTypeConfig::tagged_length(Tagged* tagged) { |
| 53 return tagged->length() - 1; |
| 54 } |
| 55 |
| 56 |
| 57 // static |
| 58 Type* ZoneTypeConfig::handle(Type* type) { |
| 59 return type; |
| 60 } |
| 61 |
| 62 |
| 63 // static |
| 64 bool ZoneTypeConfig::is(Type* type, Tag tag) { |
| 65 return is_tagged(type) && tagged_tag(as_tagged(type)) == tag; |
| 66 } |
| 67 |
| 68 |
| 69 // static |
| 70 bool ZoneTypeConfig::is_bitset(Type* type) { |
| 71 return reinterpret_cast<intptr_t>(type) & 1; |
| 72 } |
| 73 |
| 74 |
| 75 // static |
| 76 bool ZoneTypeConfig::is_tagged(Type* type) { |
| 77 return !is_bitset(type); |
| 78 } |
| 79 |
| 80 |
| 81 // static |
| 82 bool ZoneTypeConfig::is_class(Type* type) { |
| 83 return is(type, kClassTag); |
| 84 } |
| 85 |
| 86 |
| 87 // static |
| 88 bool ZoneTypeConfig::is_constant(Type* type) { |
| 89 return is(type, kConstantTag); |
| 90 } |
| 91 |
| 92 |
| 93 // static |
| 94 bool ZoneTypeConfig::is_union(Type* type) { |
| 95 return is(type, kUnionTag); |
| 96 } |
| 97 |
| 98 |
| 99 // static |
| 100 bool ZoneTypeConfig::tagged_is_union(Tagged* tagged) { |
| 101 return is(from_tagged(tagged), kUnionTag); |
| 102 } |
| 103 |
| 104 |
| 105 // static |
| 106 int ZoneTypeConfig::as_bitset(Type* type) { |
| 107 ASSERT(is_bitset(type)); |
| 108 return static_cast<int>(reinterpret_cast<intptr_t>(type) >> 1); |
| 109 } |
| 110 |
| 111 |
| 112 // static |
| 113 ZoneTypeConfig::Tagged* ZoneTypeConfig::as_tagged(Type* type) { |
| 114 ASSERT(is_tagged(type)); |
| 115 return reinterpret_cast<Tagged*>(type); |
| 116 } |
| 117 |
| 118 |
| 119 // static |
| 120 i::Handle<i::Map> ZoneTypeConfig::as_class(Type* type) { |
| 121 ASSERT(is_class(type)); |
| 122 return i::Handle<i::Map>(tagged_get<i::Map**>(as_tagged(type), 1)); |
| 123 } |
| 124 |
| 125 |
| 126 // static |
| 127 i::Handle<i::Object> ZoneTypeConfig::as_constant(Type* type) { |
| 128 ASSERT(is_constant(type)); |
| 129 return i::Handle<i::Object>(tagged_get<i::Object**>(as_tagged(type), 1)); |
| 130 } |
| 131 |
| 132 |
| 133 // static |
| 134 ZoneTypeConfig::Unioned* ZoneTypeConfig::as_union(Type* type) { |
| 135 ASSERT(is_union(type)); |
| 136 return tagged_as_union(as_tagged(type)); |
| 137 } |
| 138 |
| 139 |
| 140 // static |
| 141 ZoneTypeConfig::Unioned* ZoneTypeConfig::tagged_as_union(Tagged* tagged) { |
| 142 ASSERT(tagged_is_union(tagged)); |
| 143 return reinterpret_cast<Unioned*>(tagged); |
| 144 } |
| 145 |
| 146 |
| 147 // static |
| 148 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset) { |
| 149 return reinterpret_cast<Type*>((bitset << 1) | 1); |
| 150 } |
| 151 |
| 152 |
| 153 // static |
| 154 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset, Zone* Zone) { |
| 155 return from_bitset(bitset); |
| 156 } |
| 157 |
| 158 |
| 159 // static |
| 160 ZoneTypeConfig::Type* ZoneTypeConfig::from_tagged(Tagged* tagged) { |
| 161 return reinterpret_cast<Type*>(tagged); |
| 162 } |
| 163 |
| 164 |
| 165 // static |
| 166 ZoneTypeConfig::Type* ZoneTypeConfig::from_class( |
| 167 i::Handle<i::Map> map, int lub, Zone* zone) { |
| 168 Tagged* tagged = tagged_create(kClassTag, 2, zone); |
| 169 tagged_set(tagged, 0, lub); |
| 170 tagged_set(tagged, 1, map.location()); |
| 171 return from_tagged(tagged); |
| 172 } |
| 173 |
| 174 |
| 175 // static |
| 176 ZoneTypeConfig::Type* ZoneTypeConfig::from_constant( |
| 177 i::Handle<i::Object> value, int lub, Zone* zone) { |
| 178 Tagged* tagged = tagged_create(kConstantTag, 2, zone); |
| 179 tagged_set(tagged, 0, lub); |
| 180 tagged_set(tagged, 1, value.location()); |
| 181 return from_tagged(tagged); |
| 182 } |
| 183 |
| 184 |
| 185 // static |
| 186 ZoneTypeConfig::Type* ZoneTypeConfig::from_union(Unioned* unioned) { |
| 187 return from_tagged(tagged_from_union(unioned)); |
| 188 } |
| 189 |
| 190 |
| 191 // static |
| 192 ZoneTypeConfig::Tagged* ZoneTypeConfig::tagged_from_union(Unioned* unioned) { |
| 193 return reinterpret_cast<Tagged*>(unioned); |
| 194 } |
| 195 |
| 196 |
| 197 // static |
| 198 ZoneTypeConfig::Unioned* ZoneTypeConfig::union_create(int size, Zone* zone) { |
| 199 return tagged_as_union(tagged_create(kUnionTag, size, zone)); |
| 200 } |
| 201 |
| 202 |
| 203 // static |
| 204 void ZoneTypeConfig::union_shrink(Unioned* unioned, int size) { |
| 205 tagged_shrink(tagged_from_union(unioned), size); |
| 206 } |
| 207 |
| 208 |
| 209 // static |
| 210 ZoneTypeConfig::Type* ZoneTypeConfig::union_get(Unioned* unioned, int i) { |
| 211 Type* type = tagged_get<Type*>(tagged_from_union(unioned), i); |
| 212 ASSERT(!is_union(type)); |
| 213 return type; |
| 214 } |
| 215 |
| 216 |
| 217 // static |
| 218 void ZoneTypeConfig::union_set(Unioned* unioned, int i, Type* type) { |
| 219 ASSERT(!is_union(type)); |
| 220 tagged_set(tagged_from_union(unioned), i, type); |
| 221 } |
| 222 |
| 223 |
| 224 // static |
| 225 int ZoneTypeConfig::union_length(Unioned* unioned) { |
| 226 return tagged_length(tagged_from_union(unioned)); |
| 227 } |
| 228 |
| 229 |
| 230 // static |
| 231 int ZoneTypeConfig::lub_bitset(Type* type) { |
| 232 ASSERT(is_class(type) || is_constant(type)); |
| 233 return static_cast<int>(tagged_get<intptr_t>(as_tagged(type), 0)); |
| 234 } |
| 235 |
| 236 |
| 237 // static |
| 238 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::handle(Type* type) { |
| 239 return i::handle(type, i::HeapObject::cast(type)->GetIsolate()); |
| 240 } |
| 241 |
| 242 |
| 243 // static |
| 244 bool HeapTypeConfig::is_bitset(Type* type) { |
| 245 return type->IsSmi(); |
| 246 } |
| 247 |
| 248 |
| 249 // static |
| 250 bool HeapTypeConfig::is_class(Type* type) { |
| 251 return type->IsMap(); |
| 252 } |
| 253 |
| 254 |
| 255 // static |
| 256 bool HeapTypeConfig::is_constant(Type* type) { |
| 257 return type->IsBox(); |
| 258 } |
| 259 |
| 260 |
| 261 // static |
| 262 bool HeapTypeConfig::is_union(Type* type) { |
| 263 return type->IsFixedArray(); |
| 264 } |
| 265 |
| 266 |
| 267 // static |
| 268 int HeapTypeConfig::as_bitset(Type* type) { |
| 269 return Smi::cast(type)->value(); |
| 270 } |
| 271 |
| 272 |
| 273 // static |
| 274 i::Handle<i::Map> HeapTypeConfig::as_class(Type* type) { |
| 275 return i::handle(i::Map::cast(type)); |
| 276 } |
| 277 |
| 278 |
| 279 // static |
| 280 i::Handle<i::Object> HeapTypeConfig::as_constant(Type* type) { |
| 281 i::Box* box = i::Box::cast(type); |
| 282 return i::handle(box->value(), box->GetIsolate()); |
| 283 } |
| 284 |
| 285 |
| 286 // static |
| 287 i::Handle<HeapTypeConfig::Unioned> HeapTypeConfig::as_union(Type* type) { |
| 288 return i::handle(i::FixedArray::cast(type)); |
| 289 } |
| 290 |
| 291 |
| 292 // static |
| 293 HeapTypeConfig::Type* HeapTypeConfig::from_bitset(int bitset) { |
| 294 return Type::cast(i::Smi::FromInt(bitset)); |
| 295 } |
| 296 |
| 297 |
| 298 // static |
| 299 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_bitset( |
| 300 int bitset, Isolate* isolate) { |
| 301 return i::handle(from_bitset(bitset), isolate); |
| 302 } |
| 303 |
| 304 |
| 305 // static |
| 306 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_class( |
| 307 i::Handle<i::Map> map, int lub, Isolate* isolate) { |
| 308 return i::Handle<Type>::cast(i::Handle<Object>::cast(map)); |
| 309 } |
| 310 |
| 311 |
| 312 // static |
| 313 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_constant( |
| 314 i::Handle<i::Object> value, int lub, Isolate* isolate) { |
| 315 i::Handle<Box> box = isolate->factory()->NewBox(value); |
| 316 return i::Handle<Type>::cast(i::Handle<Object>::cast(box)); |
| 317 } |
| 318 |
| 319 |
| 320 // static |
| 321 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_union( |
| 322 i::Handle<Unioned> unioned) { |
| 323 return i::Handle<Type>::cast(i::Handle<Object>::cast(unioned)); |
| 324 } |
| 325 |
| 326 |
| 327 // static |
| 328 i::Handle<HeapTypeConfig::Unioned> HeapTypeConfig::union_create( |
| 329 int size, Isolate* isolate) { |
| 330 return isolate->factory()->NewFixedArray(size); |
| 331 } |
| 332 |
| 333 |
| 334 // static |
| 335 void HeapTypeConfig::union_shrink(i::Handle<Unioned> unioned, int size) { |
| 336 unioned->Shrink(size); |
| 337 } |
| 338 |
| 339 |
| 340 // static |
| 341 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::union_get( |
| 342 i::Handle<Unioned> unioned, int i) { |
| 343 Type* type = static_cast<Type*>(unioned->get(i)); |
| 344 ASSERT(!is_union(type)); |
| 345 return i::handle(type, unioned->GetIsolate()); |
| 346 } |
| 347 |
| 348 |
| 349 // static |
| 350 void HeapTypeConfig::union_set( |
| 351 i::Handle<Unioned> unioned, int i, i::Handle<Type> type) { |
| 352 ASSERT(!is_union(*type)); |
| 353 unioned->set(i, *type); |
| 354 } |
| 355 |
| 356 |
| 357 // static |
| 358 int HeapTypeConfig::union_length(i::Handle<Unioned> unioned) { |
| 359 return unioned->length(); |
| 360 } |
| 361 |
| 362 |
| 363 // static |
| 364 int HeapTypeConfig::lub_bitset(Type* type) { |
| 365 return 0; // kNone, which causes recomputation. |
| 366 } |
| 367 |
| 368 } } // namespace v8::internal |
| 369 |
| 370 #endif // V8_TYPES_INL_H_ |
OLD | NEW |