OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_TYPES_INL_H_ | 5 #ifndef V8_TYPES_INL_H_ |
6 #define V8_TYPES_INL_H_ | 6 #define V8_TYPES_INL_H_ |
7 | 7 |
8 #include "types.h" | 8 #include "types.h" |
9 | 9 |
10 #include "factory.h" | 10 #include "factory.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 63 |
64 | 64 |
65 // static | 65 // static |
66 bool ZoneTypeConfig::is_struct(Type* type, int tag) { | 66 bool ZoneTypeConfig::is_struct(Type* type, int tag) { |
67 return !is_bitset(type) && struct_tag(as_struct(type)) == tag; | 67 return !is_bitset(type) && struct_tag(as_struct(type)) == tag; |
68 } | 68 } |
69 | 69 |
70 | 70 |
71 // static | 71 // static |
72 bool ZoneTypeConfig::is_class(Type* type) { | 72 bool ZoneTypeConfig::is_class(Type* type) { |
73 return is_struct(type, Type::StructuralType::kClassTag); | 73 return false; |
74 } | 74 } |
75 | 75 |
76 | 76 |
77 // static | |
78 bool ZoneTypeConfig::is_constant(Type* type) { | |
79 return is_struct(type, Type::StructuralType::kConstantTag); | |
80 } | |
81 | |
82 | |
83 // static | 77 // static |
84 int ZoneTypeConfig::as_bitset(Type* type) { | 78 int ZoneTypeConfig::as_bitset(Type* type) { |
85 ASSERT(is_bitset(type)); | 79 ASSERT(is_bitset(type)); |
86 return static_cast<int>(reinterpret_cast<intptr_t>(type) >> 1); | 80 return static_cast<int>(reinterpret_cast<intptr_t>(type) >> 1); |
87 } | 81 } |
88 | 82 |
89 | 83 |
90 // static | 84 // static |
91 ZoneTypeConfig::Struct* ZoneTypeConfig::as_struct(Type* type) { | 85 ZoneTypeConfig::Struct* ZoneTypeConfig::as_struct(Type* type) { |
92 ASSERT(!is_bitset(type)); | 86 ASSERT(!is_bitset(type)); |
93 return reinterpret_cast<Struct*>(type); | 87 return reinterpret_cast<Struct*>(type); |
94 } | 88 } |
95 | 89 |
96 | 90 |
97 // static | 91 // static |
98 i::Handle<i::Map> ZoneTypeConfig::as_class(Type* type) { | 92 i::Handle<i::Map> ZoneTypeConfig::as_class(Type* type) { |
99 ASSERT(is_class(type)); | 93 UNREACHABLE(); |
100 return i::Handle<i::Map>(static_cast<i::Map**>(as_struct(type)[3])); | 94 return i::Handle<i::Map>(); |
101 } | 95 } |
102 | 96 |
103 | 97 |
104 // static | |
105 i::Handle<i::Object> ZoneTypeConfig::as_constant(Type* type) { | |
106 ASSERT(is_constant(type)); | |
107 return i::Handle<i::Object>( | |
108 static_cast<i::Object**>(as_struct(type)[3])); | |
109 } | |
110 | |
111 | |
112 // static | 98 // static |
113 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset) { | 99 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset) { |
114 return reinterpret_cast<Type*>((bitset << 1) | 1); | 100 return reinterpret_cast<Type*>((bitset << 1) | 1); |
115 } | 101 } |
116 | 102 |
117 | 103 |
118 // static | 104 // static |
119 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset, Zone* Zone) { | 105 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset, Zone* Zone) { |
120 return from_bitset(bitset); | 106 return from_bitset(bitset); |
121 } | 107 } |
122 | 108 |
123 | 109 |
124 // static | 110 // static |
125 ZoneTypeConfig::Type* ZoneTypeConfig::from_struct(Struct* structured) { | 111 ZoneTypeConfig::Type* ZoneTypeConfig::from_struct(Struct* structure) { |
126 return reinterpret_cast<Type*>(structured); | 112 return reinterpret_cast<Type*>(structure); |
127 } | 113 } |
128 | 114 |
129 | 115 |
130 // static | 116 // static |
131 ZoneTypeConfig::Type* ZoneTypeConfig::from_class( | 117 ZoneTypeConfig::Type* ZoneTypeConfig::from_class( |
132 i::Handle<i::Map> map, int lub, Zone* zone) { | 118 i::Handle<i::Map> map, Zone* zone) { |
133 Struct* structured = struct_create(Type::StructuralType::kClassTag, 2, zone); | 119 return from_bitset(0); |
134 structured[2] = from_bitset(lub); | |
135 structured[3] = map.location(); | |
136 return from_struct(structured); | |
137 } | |
138 | |
139 | |
140 // static | |
141 ZoneTypeConfig::Type* ZoneTypeConfig::from_constant( | |
142 i::Handle<i::Object> value, int lub, Zone* zone) { | |
143 Struct* structured = | |
144 struct_create(Type::StructuralType::kConstantTag, 2, zone); | |
145 structured[2] = from_bitset(lub); | |
146 structured[3] = value.location(); | |
147 return from_struct(structured); | |
148 } | 120 } |
149 | 121 |
150 | 122 |
151 // static | 123 // static |
152 ZoneTypeConfig::Struct* ZoneTypeConfig::struct_create( | 124 ZoneTypeConfig::Struct* ZoneTypeConfig::struct_create( |
153 int tag, int length, Zone* zone) { | 125 int tag, int length, Zone* zone) { |
154 Struct* structured = reinterpret_cast<Struct*>( | 126 Struct* structure = reinterpret_cast<Struct*>( |
155 zone->New(sizeof(void*) * (length + 2))); // NOLINT | 127 zone->New(sizeof(void*) * (length + 2))); // NOLINT |
156 structured[0] = reinterpret_cast<void*>(tag); | 128 structure[0] = reinterpret_cast<void*>(tag); |
157 structured[1] = reinterpret_cast<void*>(length); | 129 structure[1] = reinterpret_cast<void*>(length); |
158 return structured; | 130 return structure; |
159 } | 131 } |
160 | 132 |
161 | 133 |
162 // static | 134 // static |
163 void ZoneTypeConfig::struct_shrink(Struct* structured, int length) { | 135 void ZoneTypeConfig::struct_shrink(Struct* structure, int length) { |
164 ASSERT(0 <= length && length <= struct_length(structured)); | 136 ASSERT(0 <= length && length <= struct_length(structure)); |
165 structured[1] = reinterpret_cast<void*>(length); | 137 structure[1] = reinterpret_cast<void*>(length); |
166 } | 138 } |
167 | 139 |
168 | 140 |
169 // static | 141 // static |
170 int ZoneTypeConfig::struct_tag(Struct* structured) { | 142 int ZoneTypeConfig::struct_tag(Struct* structure) { |
171 return static_cast<int>(reinterpret_cast<intptr_t>(structured[0])); | 143 return static_cast<int>(reinterpret_cast<intptr_t>(structure[0])); |
172 } | 144 } |
173 | 145 |
174 | 146 |
175 // static | 147 // static |
176 int ZoneTypeConfig::struct_length(Struct* structured) { | 148 int ZoneTypeConfig::struct_length(Struct* structure) { |
177 return static_cast<int>(reinterpret_cast<intptr_t>(structured[1])); | 149 return static_cast<int>(reinterpret_cast<intptr_t>(structure[1])); |
178 } | 150 } |
179 | 151 |
180 | 152 |
181 // static | 153 // static |
182 Type* ZoneTypeConfig::struct_get(Struct* structured, int i) { | 154 Type* ZoneTypeConfig::struct_get(Struct* structure, int i) { |
183 ASSERT(0 <= i && i <= struct_length(structured)); | 155 ASSERT(0 <= i && i <= struct_length(structure)); |
184 return static_cast<Type*>(structured[2 + i]); | 156 return static_cast<Type*>(structure[2 + i]); |
185 } | 157 } |
186 | 158 |
187 | 159 |
188 // static | 160 // static |
189 void ZoneTypeConfig::struct_set(Struct* structured, int i, Type* type) { | 161 void ZoneTypeConfig::struct_set(Struct* structure, int i, Type* x) { |
190 ASSERT(0 <= i && i <= struct_length(structured)); | 162 ASSERT(0 <= i && i <= struct_length(structure)); |
191 structured[2 + i] = type; | 163 structure[2 + i] = x; |
192 } | 164 } |
193 | 165 |
194 | 166 |
195 // static | 167 // static |
196 int ZoneTypeConfig::lub_bitset(Type* type) { | 168 template<class V> |
197 ASSERT(is_class(type) || is_constant(type)); | 169 i::Handle<V> ZoneTypeConfig::struct_get_value(Struct* structure, int i) { |
198 return as_bitset(struct_get(as_struct(type), 0)); | 170 ASSERT(0 <= i && i <= struct_length(structure)); |
| 171 return i::Handle<V>(static_cast<V**>(structure[2 + i])); |
199 } | 172 } |
200 | 173 |
201 | 174 |
| 175 // static |
| 176 template<class V> |
| 177 void ZoneTypeConfig::struct_set_value( |
| 178 Struct* structure, int i, i::Handle<V> x) { |
| 179 ASSERT(0 <= i && i <= struct_length(structure)); |
| 180 structure[2 + i] = x.location(); |
| 181 } |
| 182 |
| 183 |
202 // -------------------------------------------------------------------------- // | 184 // -------------------------------------------------------------------------- // |
203 // HeapTypeConfig | 185 // HeapTypeConfig |
204 | 186 |
205 // static | 187 // static |
206 template<class T> | 188 template<class T> |
207 i::Handle<T> HeapTypeConfig::handle(T* type) { | 189 i::Handle<T> HeapTypeConfig::handle(T* type) { |
208 return i::handle(type, i::HeapObject::cast(type)->GetIsolate()); | 190 return i::handle(type, i::HeapObject::cast(type)->GetIsolate()); |
209 } | 191 } |
210 | 192 |
211 | 193 |
(...skipping 10 matching lines...) Expand all Loading... |
222 } | 204 } |
223 | 205 |
224 | 206 |
225 // static | 207 // static |
226 bool HeapTypeConfig::is_class(Type* type) { | 208 bool HeapTypeConfig::is_class(Type* type) { |
227 return type->IsMap(); | 209 return type->IsMap(); |
228 } | 210 } |
229 | 211 |
230 | 212 |
231 // static | 213 // static |
232 bool HeapTypeConfig::is_constant(Type* type) { | |
233 return type->IsBox(); | |
234 } | |
235 | |
236 | |
237 // static | |
238 bool HeapTypeConfig::is_struct(Type* type, int tag) { | 214 bool HeapTypeConfig::is_struct(Type* type, int tag) { |
239 return type->IsFixedArray() && struct_tag(as_struct(type)) == tag; | 215 return type->IsFixedArray() && struct_tag(as_struct(type)) == tag; |
240 } | 216 } |
241 | 217 |
242 | 218 |
243 // static | 219 // static |
244 int HeapTypeConfig::as_bitset(Type* type) { | 220 int HeapTypeConfig::as_bitset(Type* type) { |
245 return i::Smi::cast(type)->value(); | 221 return i::Smi::cast(type)->value(); |
246 } | 222 } |
247 | 223 |
248 | 224 |
249 // static | 225 // static |
250 i::Handle<i::Map> HeapTypeConfig::as_class(Type* type) { | 226 i::Handle<i::Map> HeapTypeConfig::as_class(Type* type) { |
251 return i::handle(i::Map::cast(type)); | 227 return i::handle(i::Map::cast(type)); |
252 } | 228 } |
253 | 229 |
254 | 230 |
255 // static | 231 // static |
256 i::Handle<i::Object> HeapTypeConfig::as_constant(Type* type) { | |
257 i::Box* box = i::Box::cast(type); | |
258 return i::handle(box->value(), box->GetIsolate()); | |
259 } | |
260 | |
261 | |
262 // static | |
263 i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::as_struct(Type* type) { | 232 i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::as_struct(Type* type) { |
264 return i::handle(Struct::cast(type)); | 233 return i::handle(Struct::cast(type)); |
265 } | 234 } |
266 | 235 |
267 | 236 |
268 // static | 237 // static |
269 HeapTypeConfig::Type* HeapTypeConfig::from_bitset(int bitset) { | 238 HeapTypeConfig::Type* HeapTypeConfig::from_bitset(int bitset) { |
270 return Type::cast(i::Smi::FromInt(bitset)); | 239 return Type::cast(i::Smi::FromInt(bitset)); |
271 } | 240 } |
272 | 241 |
273 | 242 |
274 // static | 243 // static |
275 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_bitset( | 244 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_bitset( |
276 int bitset, Isolate* isolate) { | 245 int bitset, Isolate* isolate) { |
277 return i::handle(from_bitset(bitset), isolate); | 246 return i::handle(from_bitset(bitset), isolate); |
278 } | 247 } |
279 | 248 |
280 | 249 |
281 // static | 250 // static |
282 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_class( | 251 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_class( |
283 i::Handle<i::Map> map, int lub, Isolate* isolate) { | 252 i::Handle<i::Map> map, Isolate* isolate) { |
284 return i::Handle<Type>::cast(i::Handle<Object>::cast(map)); | 253 return i::Handle<Type>::cast(i::Handle<Object>::cast(map)); |
285 } | 254 } |
286 | 255 |
287 | 256 |
288 // static | 257 // static |
289 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_constant( | |
290 i::Handle<i::Object> value, int lub, Isolate* isolate) { | |
291 i::Handle<Box> box = isolate->factory()->NewBox(value); | |
292 return i::Handle<Type>::cast(i::Handle<Object>::cast(box)); | |
293 } | |
294 | |
295 | |
296 // static | |
297 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_struct( | 258 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_struct( |
298 i::Handle<Struct> structured) { | 259 i::Handle<Struct> structure) { |
299 return i::Handle<Type>::cast(i::Handle<Object>::cast(structured)); | 260 return i::Handle<Type>::cast(i::Handle<Object>::cast(structure)); |
300 } | 261 } |
301 | 262 |
302 | 263 |
303 // static | 264 // static |
304 i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::struct_create( | 265 i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::struct_create( |
305 int tag, int length, Isolate* isolate) { | 266 int tag, int length, Isolate* isolate) { |
306 i::Handle<Struct> structured = isolate->factory()->NewFixedArray(length + 1); | 267 i::Handle<Struct> structure = isolate->factory()->NewFixedArray(length + 1); |
307 structured->set(0, i::Smi::FromInt(tag)); | 268 structure->set(0, i::Smi::FromInt(tag)); |
308 return structured; | 269 return structure; |
309 } | 270 } |
310 | 271 |
311 | 272 |
312 // static | 273 // static |
313 void HeapTypeConfig::struct_shrink(i::Handle<Struct> structured, int length) { | 274 void HeapTypeConfig::struct_shrink(i::Handle<Struct> structure, int length) { |
314 structured->Shrink(length + 1); | 275 structure->Shrink(length + 1); |
315 } | 276 } |
316 | 277 |
317 | 278 |
318 // static | 279 // static |
319 int HeapTypeConfig::struct_tag(i::Handle<Struct> structured) { | 280 int HeapTypeConfig::struct_tag(i::Handle<Struct> structure) { |
320 return static_cast<i::Smi*>(structured->get(0))->value(); | 281 return static_cast<i::Smi*>(structure->get(0))->value(); |
321 } | 282 } |
322 | 283 |
323 | 284 |
324 // static | 285 // static |
325 int HeapTypeConfig::struct_length(i::Handle<Struct> structured) { | 286 int HeapTypeConfig::struct_length(i::Handle<Struct> structure) { |
326 return structured->length() - 1; | 287 return structure->length() - 1; |
327 } | 288 } |
328 | 289 |
329 | 290 |
330 // static | 291 // static |
331 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::struct_get( | 292 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::struct_get( |
332 i::Handle<Struct> structured, int i) { | 293 i::Handle<Struct> structure, int i) { |
333 Type* type = static_cast<Type*>(structured->get(i + 1)); | 294 Type* type = static_cast<Type*>(structure->get(i + 1)); |
334 return i::handle(type, structured->GetIsolate()); | 295 return i::handle(type, structure->GetIsolate()); |
335 } | 296 } |
336 | 297 |
337 | 298 |
338 // static | 299 // static |
339 void HeapTypeConfig::struct_set( | 300 void HeapTypeConfig::struct_set( |
340 i::Handle<Struct> structured, int i, i::Handle<Type> type) { | 301 i::Handle<Struct> structure, int i, i::Handle<Type> type) { |
341 structured->set(i + 1, *type); | 302 structure->set(i + 1, *type); |
342 } | 303 } |
343 | 304 |
344 | 305 |
345 // static | 306 // static |
346 int HeapTypeConfig::lub_bitset(Type* type) { | 307 template<class V> |
347 return 0; // kNone, which causes recomputation. | 308 i::Handle<V> HeapTypeConfig::struct_get_value( |
| 309 i::Handle<Struct> structure, int i) { |
| 310 V* x = static_cast<V*>(structure->get(i + 1)); |
| 311 return i::handle(x, structure->GetIsolate()); |
| 312 } |
| 313 |
| 314 |
| 315 // static |
| 316 template<class V> |
| 317 void HeapTypeConfig::struct_set_value( |
| 318 i::Handle<Struct> structure, int i, i::Handle<V> x) { |
| 319 structure->set(i + 1, *x); |
348 } | 320 } |
349 | 321 |
350 } } // namespace v8::internal | 322 } } // namespace v8::internal |
351 | 323 |
352 #endif // V8_TYPES_INL_H_ | 324 #endif // V8_TYPES_INL_H_ |
OLD | NEW |