Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: src/types-inl.h

Issue 225923002: Refactoring to allow adding new structured types (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/types.cc ('k') | test/cctest/test-types.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "handles-inl.h" 11 #include "handles-inl.h"
12 12
13 namespace v8 { 13 namespace v8 {
14 namespace internal { 14 namespace internal {
15 15
16 // static 16 // static
17 ZoneTypeConfig::Tagged* ZoneTypeConfig::tagged_create(
18 Tag tag, int size, Zone* zone) {
19 Tagged* tagged = new(zone) Tagged(size + 1, zone);
20 tagged->Add(reinterpret_cast<void*>(tag), zone);
21 tagged->AddBlock(NULL, size, zone);
22 return tagged;
23 }
24
25
26 // static
27 void ZoneTypeConfig::tagged_shrink(Tagged* tagged, int size) {
28 tagged->Rewind(size + 1);
29 }
30
31
32 // static
33 ZoneTypeConfig::Tag ZoneTypeConfig::tagged_tag(Tagged* tagged) {
34 return static_cast<Tag>(reinterpret_cast<intptr_t>(tagged->at(0)));
35 }
36
37
38 // static
39 template<class T>
40 T ZoneTypeConfig::tagged_get(Tagged* tagged, int i) {
41 return reinterpret_cast<T>(tagged->at(i + 1));
42 }
43
44
45 // static
46 template<class T>
47 void ZoneTypeConfig::tagged_set(Tagged* tagged, int i, T value) {
48 tagged->at(i + 1) = reinterpret_cast<void*>(value);
49 }
50
51
52 // static
53 int ZoneTypeConfig::tagged_length(Tagged* tagged) {
54 return tagged->length() - 1;
55 }
56
57
58 // static
59 Type* ZoneTypeConfig::handle(Type* type) { 17 Type* ZoneTypeConfig::handle(Type* type) {
60 return type; 18 return type;
61 } 19 }
62 20
63 21
64 // static 22 // static
65 bool ZoneTypeConfig::is(Type* type, Tag tag) {
66 return is_tagged(type) && tagged_tag(as_tagged(type)) == tag;
67 }
68
69
70 // static
71 bool ZoneTypeConfig::is_bitset(Type* type) { 23 bool ZoneTypeConfig::is_bitset(Type* type) {
72 return reinterpret_cast<intptr_t>(type) & 1; 24 return reinterpret_cast<intptr_t>(type) & 1;
73 } 25 }
74 26
75 27
76 // static 28 // static
77 bool ZoneTypeConfig::is_tagged(Type* type) { 29 bool ZoneTypeConfig::is_struct(Type* type) {
78 return !is_bitset(type); 30 return !is_bitset(type);
79 } 31 }
80 32
81 33
82 // static 34 // static
83 bool ZoneTypeConfig::is_class(Type* type) { 35 bool ZoneTypeConfig::is_class(Type* type) {
84 return is(type, kClassTag); 36 return is_struct(type) && struct_tag(as_struct(type)) == Type::kClassTag;
85 } 37 }
86 38
87 39
88 // static 40 // static
89 bool ZoneTypeConfig::is_constant(Type* type) { 41 bool ZoneTypeConfig::is_constant(Type* type) {
90 return is(type, kConstantTag); 42 return is_struct(type) && struct_tag(as_struct(type)) == Type::kConstantTag;
91 } 43 }
92 44
93 45
94 // static
95 bool ZoneTypeConfig::is_union(Type* type) {
96 return is(type, kUnionTag);
97 }
98
99
100 // static
101 bool ZoneTypeConfig::tagged_is_union(Tagged* tagged) {
102 return is(from_tagged(tagged), kUnionTag);
103 }
104
105
106 // static 46 // static
107 int ZoneTypeConfig::as_bitset(Type* type) { 47 int ZoneTypeConfig::as_bitset(Type* type) {
108 ASSERT(is_bitset(type)); 48 ASSERT(is_bitset(type));
109 return static_cast<int>(reinterpret_cast<intptr_t>(type) >> 1); 49 return static_cast<int>(reinterpret_cast<intptr_t>(type) >> 1);
110 } 50 }
111 51
112 52
113 // static 53 // static
114 ZoneTypeConfig::Tagged* ZoneTypeConfig::as_tagged(Type* type) { 54 ZoneTypeConfig::Struct* ZoneTypeConfig::as_struct(Type* type) {
115 ASSERT(is_tagged(type)); 55 ASSERT(is_struct(type));
116 return reinterpret_cast<Tagged*>(type); 56 return reinterpret_cast<Struct*>(type);
117 } 57 }
118 58
119 59
120 // static 60 // static
121 i::Handle<i::Map> ZoneTypeConfig::as_class(Type* type) { 61 i::Handle<i::Map> ZoneTypeConfig::as_class(Type* type) {
122 ASSERT(is_class(type)); 62 ASSERT(is_class(type));
123 return i::Handle<i::Map>(tagged_get<i::Map**>(as_tagged(type), 1)); 63 return i::Handle<i::Map>(static_cast<i::Map**>(as_struct(type)->args[1]));
124 } 64 }
125 65
126 66
127 // static 67 // static
128 i::Handle<i::Object> ZoneTypeConfig::as_constant(Type* type) { 68 i::Handle<i::Object> ZoneTypeConfig::as_constant(Type* type) {
129 ASSERT(is_constant(type)); 69 ASSERT(is_constant(type));
130 return i::Handle<i::Object>(tagged_get<i::Object**>(as_tagged(type), 1)); 70 return i::Handle<i::Object>(
71 static_cast<i::Object**>(as_struct(type)->args[1]));
131 } 72 }
132 73
133 74
134 // static
135 ZoneTypeConfig::Unioned* ZoneTypeConfig::as_union(Type* type) {
136 ASSERT(is_union(type));
137 return tagged_as_union(as_tagged(type));
138 }
139
140
141 // static
142 ZoneTypeConfig::Unioned* ZoneTypeConfig::tagged_as_union(Tagged* tagged) {
143 ASSERT(tagged_is_union(tagged));
144 return reinterpret_cast<Unioned*>(tagged);
145 }
146
147
148 // static 75 // static
149 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset) { 76 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset) {
150 return reinterpret_cast<Type*>((bitset << 1) | 1); 77 return reinterpret_cast<Type*>((bitset << 1) | 1);
151 } 78 }
152 79
153 80
154 // static 81 // static
155 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset, Zone* Zone) { 82 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset, Zone* Zone) {
156 return from_bitset(bitset); 83 return from_bitset(bitset);
157 } 84 }
158 85
159 86
160 // static 87 // static
161 ZoneTypeConfig::Type* ZoneTypeConfig::from_tagged(Tagged* tagged) { 88 ZoneTypeConfig::Type* ZoneTypeConfig::from_struct(Struct* structured) {
162 return reinterpret_cast<Type*>(tagged); 89 return reinterpret_cast<Type*>(structured);
163 } 90 }
164 91
165 92
166 // static 93 // static
167 ZoneTypeConfig::Type* ZoneTypeConfig::from_class( 94 ZoneTypeConfig::Type* ZoneTypeConfig::from_class(
168 i::Handle<i::Map> map, int lub, Zone* zone) { 95 i::Handle<i::Map> map, int lub, Zone* zone) {
169 Tagged* tagged = tagged_create(kClassTag, 2, zone); 96 Struct* structured = struct_create(Type::kClassTag, 2, zone);
170 tagged_set(tagged, 0, lub); 97 structured->args[0] = from_bitset(lub);
171 tagged_set(tagged, 1, map.location()); 98 structured->args[1] = map.location();
172 return from_tagged(tagged); 99 return from_struct(structured);
173 } 100 }
174 101
175 102
176 // static 103 // static
177 ZoneTypeConfig::Type* ZoneTypeConfig::from_constant( 104 ZoneTypeConfig::Type* ZoneTypeConfig::from_constant(
178 i::Handle<i::Object> value, int lub, Zone* zone) { 105 i::Handle<i::Object> value, int lub, Zone* zone) {
179 Tagged* tagged = tagged_create(kConstantTag, 2, zone); 106 Struct* structured = struct_create(Type::kConstantTag, 2, zone);
180 tagged_set(tagged, 0, lub); 107 structured->args[0] = from_bitset(lub);
181 tagged_set(tagged, 1, value.location()); 108 structured->args[1] = value.location();
182 return from_tagged(tagged); 109 return from_struct(structured);
183 } 110 }
184 111
185 112
186 // static 113 // static
187 ZoneTypeConfig::Type* ZoneTypeConfig::from_union(Unioned* unioned) { 114 ZoneTypeConfig::Struct* ZoneTypeConfig::struct_create(
188 return from_tagged(tagged_from_union(unioned)); 115 int tag, int length, Zone* zone) {
116 Struct* structured = reinterpret_cast<Struct*>(
117 zone->New(sizeof(Struct) + sizeof(void*) * (length - 1))); // NOLINT
118 structured->tag = tag;
119 structured->length = length;
120 return structured;
189 } 121 }
190 122
191 123
192 // static 124 // static
193 ZoneTypeConfig::Tagged* ZoneTypeConfig::tagged_from_union(Unioned* unioned) { 125 void ZoneTypeConfig::struct_shrink(Struct* structured, int length) {
194 return reinterpret_cast<Tagged*>(unioned); 126 ASSERT(0 <= length && length <= structured->length);
127 structured->length = length;
195 } 128 }
196 129
197 130
198 // static 131 // static
199 ZoneTypeConfig::Unioned* ZoneTypeConfig::union_create(int size, Zone* zone) { 132 int ZoneTypeConfig::struct_tag(Struct* structured) {
200 return tagged_as_union(tagged_create(kUnionTag, size, zone)); 133 return structured->tag;
201 } 134 }
202 135
203 136
204 // static 137 // static
205 void ZoneTypeConfig::union_shrink(Unioned* unioned, int size) { 138 Type* ZoneTypeConfig::struct_get(Struct* structured, int i) {
206 tagged_shrink(tagged_from_union(unioned), size); 139 ASSERT(0 <= i && i < structured->length);
140 return static_cast<Type*>(structured->args[i]);
207 } 141 }
208 142
209 143
210 // static 144 // static
211 ZoneTypeConfig::Type* ZoneTypeConfig::union_get(Unioned* unioned, int i) { 145 void ZoneTypeConfig::struct_set(Struct* structured, int i, Type* type) {
212 Type* type = tagged_get<Type*>(tagged_from_union(unioned), i); 146 ASSERT(0 <= i && i < structured->length);
213 ASSERT(!is_union(type)); 147 structured->args[i] = type;
214 return type;
215 } 148 }
216 149
217 150
218 // static 151 // static
219 void ZoneTypeConfig::union_set(Unioned* unioned, int i, Type* type) { 152 int ZoneTypeConfig::struct_length(Struct* structured) {
220 ASSERT(!is_union(type)); 153 return structured->length;
221 tagged_set(tagged_from_union(unioned), i, type);
222 }
223
224
225 // static
226 int ZoneTypeConfig::union_length(Unioned* unioned) {
227 return tagged_length(tagged_from_union(unioned));
228 } 154 }
229 155
230 156
231 // static 157 // static
232 int ZoneTypeConfig::lub_bitset(Type* type) { 158 int ZoneTypeConfig::lub_bitset(Type* type) {
233 ASSERT(is_class(type) || is_constant(type)); 159 ASSERT(is_class(type) || is_constant(type));
234 return static_cast<int>(tagged_get<intptr_t>(as_tagged(type), 0)); 160 return as_bitset(struct_get(as_struct(type), 0));
235 } 161 }
236 162
237 // -------------------------------------------------------------------------- // 163 // -------------------------------------------------------------------------- //
238 164
239 // static 165 // static
240 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::handle(Type* type) { 166 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::handle(Type* type) {
241 return i::handle(type, i::HeapObject::cast(type)->GetIsolate()); 167 return i::handle(type, i::HeapObject::cast(type)->GetIsolate());
242 } 168 }
243 169
244 170
245 // static 171 // static
246 bool HeapTypeConfig::is_bitset(Type* type) { 172 bool HeapTypeConfig::is_bitset(Type* type) {
247 return type->IsSmi(); 173 return type->IsSmi();
248 } 174 }
249 175
250 176
251 // static 177 // static
252 bool HeapTypeConfig::is_class(Type* type) { 178 bool HeapTypeConfig::is_class(Type* type) {
253 return type->IsMap(); 179 return type->IsMap();
254 } 180 }
255 181
256 182
257 // static 183 // static
258 bool HeapTypeConfig::is_constant(Type* type) { 184 bool HeapTypeConfig::is_constant(Type* type) {
259 return type->IsBox(); 185 return type->IsBox();
260 } 186 }
261 187
262 188
263 // static 189 // static
264 bool HeapTypeConfig::is_union(Type* type) { 190 bool HeapTypeConfig::is_struct(Type* type) {
265 return type->IsFixedArray(); 191 return type->IsFixedArray();
266 } 192 }
267 193
268 194
269 // static 195 // static
270 int HeapTypeConfig::as_bitset(Type* type) { 196 int HeapTypeConfig::as_bitset(Type* type) {
271 return Smi::cast(type)->value(); 197 return Smi::cast(type)->value();
272 } 198 }
273 199
274 200
275 // static 201 // static
276 i::Handle<i::Map> HeapTypeConfig::as_class(Type* type) { 202 i::Handle<i::Map> HeapTypeConfig::as_class(Type* type) {
277 return i::handle(i::Map::cast(type)); 203 return i::handle(i::Map::cast(type));
278 } 204 }
279 205
280 206
281 // static 207 // static
282 i::Handle<i::Object> HeapTypeConfig::as_constant(Type* type) { 208 i::Handle<i::Object> HeapTypeConfig::as_constant(Type* type) {
283 i::Box* box = i::Box::cast(type); 209 i::Box* box = i::Box::cast(type);
284 return i::handle(box->value(), box->GetIsolate()); 210 return i::handle(box->value(), box->GetIsolate());
285 } 211 }
286 212
287 213
288 // static 214 // static
289 i::Handle<HeapTypeConfig::Unioned> HeapTypeConfig::as_union(Type* type) { 215 i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::as_struct(Type* type) {
290 return i::handle(i::FixedArray::cast(type)); 216 return i::handle(Struct::cast(type));
291 } 217 }
292 218
293 219
294 // static 220 // static
295 HeapTypeConfig::Type* HeapTypeConfig::from_bitset(int bitset) { 221 HeapTypeConfig::Type* HeapTypeConfig::from_bitset(int bitset) {
296 return Type::cast(i::Smi::FromInt(bitset)); 222 return Type::cast(i::Smi::FromInt(bitset));
297 } 223 }
298 224
299 225
300 // static 226 // static
(...skipping 12 matching lines...) Expand all
313 239
314 // static 240 // static
315 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_constant( 241 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_constant(
316 i::Handle<i::Object> value, int lub, Isolate* isolate) { 242 i::Handle<i::Object> value, int lub, Isolate* isolate) {
317 i::Handle<Box> box = isolate->factory()->NewBox(value); 243 i::Handle<Box> box = isolate->factory()->NewBox(value);
318 return i::Handle<Type>::cast(i::Handle<Object>::cast(box)); 244 return i::Handle<Type>::cast(i::Handle<Object>::cast(box));
319 } 245 }
320 246
321 247
322 // static 248 // static
323 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_union( 249 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_struct(
324 i::Handle<Unioned> unioned) { 250 i::Handle<Struct> structured) {
325 return i::Handle<Type>::cast(i::Handle<Object>::cast(unioned)); 251 return i::Handle<Type>::cast(i::Handle<Object>::cast(structured));
326 } 252 }
327 253
328 254
329 // static 255 // static
330 i::Handle<HeapTypeConfig::Unioned> HeapTypeConfig::union_create( 256 i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::struct_create(
331 int size, Isolate* isolate) { 257 int tag, int length, Isolate* isolate) {
332 return isolate->factory()->NewFixedArray(size); 258 i::Handle<Struct> structured = isolate->factory()->NewFixedArray(length + 1);
259 structured->set(0, i::Smi::FromInt(tag));
260 return structured;
333 } 261 }
334 262
335 263
336 // static 264 // static
337 void HeapTypeConfig::union_shrink(i::Handle<Unioned> unioned, int size) { 265 void HeapTypeConfig::struct_shrink(i::Handle<Struct> structured, int length) {
338 unioned->Shrink(size); 266 structured->Shrink(length + 1);
339 } 267 }
340 268
341 269
342 // static 270 // static
343 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::union_get( 271 int HeapTypeConfig::struct_tag(i::Handle<Struct> structured) {
344 i::Handle<Unioned> unioned, int i) { 272 return static_cast<i::Smi*>(structured->get(0))->value();
345 Type* type = static_cast<Type*>(unioned->get(i));
346 ASSERT(!is_union(type));
347 return i::handle(type, unioned->GetIsolate());
348 } 273 }
349 274
350 275
351 // static 276 // static
352 void HeapTypeConfig::union_set( 277 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::struct_get(
353 i::Handle<Unioned> unioned, int i, i::Handle<Type> type) { 278 i::Handle<Struct> structured, int i) {
354 ASSERT(!is_union(*type)); 279 Type* type = static_cast<Type*>(structured->get(i + 1));
355 unioned->set(i, *type); 280 return i::handle(type, structured->GetIsolate());
356 } 281 }
357 282
358 283
359 // static 284 // static
360 int HeapTypeConfig::union_length(i::Handle<Unioned> unioned) { 285 void HeapTypeConfig::struct_set(
361 return unioned->length(); 286 i::Handle<Struct> structured, int i, i::Handle<Type> type) {
287 structured->set(i + 1, *type);
362 } 288 }
363 289
364 290
291 // static
292 int HeapTypeConfig::struct_length(i::Handle<Struct> structured) {
293 return structured->length() - 1;
294 }
295
296
365 // static 297 // static
366 int HeapTypeConfig::lub_bitset(Type* type) { 298 int HeapTypeConfig::lub_bitset(Type* type) {
367 return 0; // kNone, which causes recomputation. 299 return 0; // kNone, which causes recomputation.
368 } 300 }
369 301
370 } } // namespace v8::internal 302 } } // namespace v8::internal
371 303
372 #endif // V8_TYPES_INL_H_ 304 #endif // V8_TYPES_INL_H_
OLDNEW
« no previous file with comments | « src/types.cc ('k') | test/cctest/test-types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698