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

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

Issue 224733023: Reland "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)[3]));
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)[3]));
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[2] = from_bitset(lub);
171 tagged_set(tagged, 1, map.location()); 98 structured[3] = 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[2] = from_bitset(lub);
181 tagged_set(tagged, 1, value.location()); 108 structured[3] = 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(void*) * (length + 2))); // NOLINT
118 structured[0] = reinterpret_cast<void*>(tag);
119 structured[1] = reinterpret_cast<void*>(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 <= struct_length(structured));
127 structured[1] = reinterpret_cast<void*>(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 int tag = reinterpret_cast<intptr_t>(structured[0]);
134 return tag;
201 } 135 }
202 136
203 137
204 // static 138 // static
205 void ZoneTypeConfig::union_shrink(Unioned* unioned, int size) { 139 int ZoneTypeConfig::struct_length(Struct* structured) {
206 tagged_shrink(tagged_from_union(unioned), size); 140 int length = reinterpret_cast<intptr_t>(structured[1]);
141 return length;
207 } 142 }
208 143
209 144
210 // static 145 // static
211 ZoneTypeConfig::Type* ZoneTypeConfig::union_get(Unioned* unioned, int i) { 146 Type* ZoneTypeConfig::struct_get(Struct* structured, int i) {
212 Type* type = tagged_get<Type*>(tagged_from_union(unioned), i); 147 ASSERT(0 <= i && i <= struct_length(structured));
213 ASSERT(!is_union(type)); 148 return static_cast<Type*>(structured[2 + i]);
214 return type;
215 } 149 }
216 150
217 151
218 // static 152 // static
219 void ZoneTypeConfig::union_set(Unioned* unioned, int i, Type* type) { 153 void ZoneTypeConfig::struct_set(Struct* structured, int i, Type* type) {
220 ASSERT(!is_union(type)); 154 ASSERT(0 <= i && i <= struct_length(structured));
221 tagged_set(tagged_from_union(unioned), i, type); 155 structured[2 + i] = type;
222 }
223
224
225 // static
226 int ZoneTypeConfig::union_length(Unioned* unioned) {
227 return tagged_length(tagged_from_union(unioned));
228 } 156 }
229 157
230 158
231 // static 159 // static
232 int ZoneTypeConfig::lub_bitset(Type* type) { 160 int ZoneTypeConfig::lub_bitset(Type* type) {
233 ASSERT(is_class(type) || is_constant(type)); 161 ASSERT(is_class(type) || is_constant(type));
234 return static_cast<int>(tagged_get<intptr_t>(as_tagged(type), 0)); 162 return as_bitset(struct_get(as_struct(type), 0));
235 } 163 }
236 164
237 // -------------------------------------------------------------------------- // 165 // -------------------------------------------------------------------------- //
238 166
239 // static 167 // static
240 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::handle(Type* type) { 168 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::handle(Type* type) {
241 return i::handle(type, i::HeapObject::cast(type)->GetIsolate()); 169 return i::handle(type, i::HeapObject::cast(type)->GetIsolate());
242 } 170 }
243 171
244 172
245 // static 173 // static
246 bool HeapTypeConfig::is_bitset(Type* type) { 174 bool HeapTypeConfig::is_bitset(Type* type) {
247 return type->IsSmi(); 175 return type->IsSmi();
248 } 176 }
249 177
250 178
251 // static 179 // static
252 bool HeapTypeConfig::is_class(Type* type) { 180 bool HeapTypeConfig::is_class(Type* type) {
253 return type->IsMap(); 181 return type->IsMap();
254 } 182 }
255 183
256 184
257 // static 185 // static
258 bool HeapTypeConfig::is_constant(Type* type) { 186 bool HeapTypeConfig::is_constant(Type* type) {
259 return type->IsBox(); 187 return type->IsBox();
260 } 188 }
261 189
262 190
263 // static 191 // static
264 bool HeapTypeConfig::is_union(Type* type) { 192 bool HeapTypeConfig::is_struct(Type* type) {
265 return type->IsFixedArray(); 193 return type->IsFixedArray();
266 } 194 }
267 195
268 196
269 // static 197 // static
270 int HeapTypeConfig::as_bitset(Type* type) { 198 int HeapTypeConfig::as_bitset(Type* type) {
271 return Smi::cast(type)->value(); 199 return Smi::cast(type)->value();
272 } 200 }
273 201
274 202
275 // static 203 // static
276 i::Handle<i::Map> HeapTypeConfig::as_class(Type* type) { 204 i::Handle<i::Map> HeapTypeConfig::as_class(Type* type) {
277 return i::handle(i::Map::cast(type)); 205 return i::handle(i::Map::cast(type));
278 } 206 }
279 207
280 208
281 // static 209 // static
282 i::Handle<i::Object> HeapTypeConfig::as_constant(Type* type) { 210 i::Handle<i::Object> HeapTypeConfig::as_constant(Type* type) {
283 i::Box* box = i::Box::cast(type); 211 i::Box* box = i::Box::cast(type);
284 return i::handle(box->value(), box->GetIsolate()); 212 return i::handle(box->value(), box->GetIsolate());
285 } 213 }
286 214
287 215
288 // static 216 // static
289 i::Handle<HeapTypeConfig::Unioned> HeapTypeConfig::as_union(Type* type) { 217 i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::as_struct(Type* type) {
290 return i::handle(i::FixedArray::cast(type)); 218 return i::handle(Struct::cast(type));
291 } 219 }
292 220
293 221
294 // static 222 // static
295 HeapTypeConfig::Type* HeapTypeConfig::from_bitset(int bitset) { 223 HeapTypeConfig::Type* HeapTypeConfig::from_bitset(int bitset) {
296 return Type::cast(i::Smi::FromInt(bitset)); 224 return Type::cast(i::Smi::FromInt(bitset));
297 } 225 }
298 226
299 227
300 // static 228 // static
(...skipping 12 matching lines...) Expand all
313 241
314 // static 242 // static
315 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_constant( 243 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_constant(
316 i::Handle<i::Object> value, int lub, Isolate* isolate) { 244 i::Handle<i::Object> value, int lub, Isolate* isolate) {
317 i::Handle<Box> box = isolate->factory()->NewBox(value); 245 i::Handle<Box> box = isolate->factory()->NewBox(value);
318 return i::Handle<Type>::cast(i::Handle<Object>::cast(box)); 246 return i::Handle<Type>::cast(i::Handle<Object>::cast(box));
319 } 247 }
320 248
321 249
322 // static 250 // static
323 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_union( 251 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_struct(
324 i::Handle<Unioned> unioned) { 252 i::Handle<Struct> structured) {
325 return i::Handle<Type>::cast(i::Handle<Object>::cast(unioned)); 253 return i::Handle<Type>::cast(i::Handle<Object>::cast(structured));
326 } 254 }
327 255
328 256
329 // static 257 // static
330 i::Handle<HeapTypeConfig::Unioned> HeapTypeConfig::union_create( 258 i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::struct_create(
331 int size, Isolate* isolate) { 259 int tag, int length, Isolate* isolate) {
332 return isolate->factory()->NewFixedArray(size); 260 i::Handle<Struct> structured = isolate->factory()->NewFixedArray(length + 1);
261 structured->set(0, i::Smi::FromInt(tag));
262 return structured;
333 } 263 }
334 264
335 265
336 // static 266 // static
337 void HeapTypeConfig::union_shrink(i::Handle<Unioned> unioned, int size) { 267 void HeapTypeConfig::struct_shrink(i::Handle<Struct> structured, int length) {
338 unioned->Shrink(size); 268 structured->Shrink(length + 1);
339 } 269 }
340 270
341 271
342 // static 272 // static
343 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::union_get( 273 int HeapTypeConfig::struct_tag(i::Handle<Struct> structured) {
344 i::Handle<Unioned> unioned, int i) { 274 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 } 275 }
349 276
350 277
351 // static 278 // static
352 void HeapTypeConfig::union_set( 279 int HeapTypeConfig::struct_length(i::Handle<Struct> structured) {
353 i::Handle<Unioned> unioned, int i, i::Handle<Type> type) { 280 return structured->length() - 1;
354 ASSERT(!is_union(*type));
355 unioned->set(i, *type);
356 } 281 }
357 282
358 283
359 // static 284 // static
360 int HeapTypeConfig::union_length(i::Handle<Unioned> unioned) { 285 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::struct_get(
361 return unioned->length(); 286 i::Handle<Struct> structured, int i) {
287 Type* type = static_cast<Type*>(structured->get(i + 1));
288 return i::handle(type, structured->GetIsolate());
362 } 289 }
363 290
364 291
292 // static
293 void HeapTypeConfig::struct_set(
294 i::Handle<Struct> structured, int i, i::Handle<Type> type) {
295 structured->set(i + 1, *type);
296 }
297
298
365 // static 299 // static
366 int HeapTypeConfig::lub_bitset(Type* type) { 300 int HeapTypeConfig::lub_bitset(Type* type) {
367 return 0; // kNone, which causes recomputation. 301 return 0; // kNone, which causes recomputation.
368 } 302 }
369 303
370 } } // namespace v8::internal 304 } } // namespace v8::internal
371 305
372 #endif // V8_TYPES_INL_H_ 306 #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