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

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

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