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.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 | « no previous file | src/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_H_ 5 #ifndef V8_TYPES_H_
6 #define V8_TYPES_H_ 6 #define V8_TYPES_H_
7 7
8 #include "handles.h" 8 #include "handles.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 V(Any, kNumber | kNonNumber) 158 V(Any, kNumber | kNonNumber)
159 159
160 #define BITSET_TYPE_LIST(V) \ 160 #define BITSET_TYPE_LIST(V) \
161 MASK_BITSET_TYPE_LIST(V) \ 161 MASK_BITSET_TYPE_LIST(V) \
162 REPRESENTATION_BITSET_TYPE_LIST(V) \ 162 REPRESENTATION_BITSET_TYPE_LIST(V) \
163 SEMANTIC_BITSET_TYPE_LIST(V) 163 SEMANTIC_BITSET_TYPE_LIST(V)
164 164
165 165
166 // struct Config { 166 // struct Config {
167 // typedef Base; 167 // typedef Base;
168 // typedef Unioned; 168 // typedef Struct;
169 // typedef Region; 169 // typedef Region;
170 // template<class> struct Handle { typedef type; } // No template typedefs... 170 // template<class> struct Handle { typedef type; } // No template typedefs...
171 // static Handle<Type>::type handle(Type* type); // !is_bitset(type) 171 // static Handle<Type>::type handle(Type* type); // !is_bitset(type)
172 // static bool is_bitset(Type*); 172 // static bool is_bitset(Type*);
173 // static bool is_class(Type*); 173 // static bool is_class(Type*);
174 // static bool is_constant(Type*); 174 // static bool is_constant(Type*);
175 // static bool is_union(Type*); 175 // static bool is_struct(Type*);
176 // static int as_bitset(Type*); 176 // static int as_bitset(Type*);
177 // static i::Handle<i::Map> as_class(Type*); 177 // static i::Handle<i::Map> as_class(Type*);
178 // static i::Handle<i::Object> as_constant(Type*); 178 // static i::Handle<i::Object> as_constant(Type*);
179 // static Handle<Unioned>::type as_union(Type*); 179 // static Handle<Struct>::type as_struct(Type*);
180 // static Type* from_bitset(int bitset); 180 // static Type* from_bitset(int bitset);
181 // static Handle<Type>::type from_bitset(int bitset, Region*); 181 // static Handle<Type>::type from_bitset(int bitset, Region*);
182 // static Handle<Type>::type from_class(i::Handle<Map>, int lub, Region*); 182 // static Handle<Type>::type from_class(i::Handle<Map>, int lub, Region*);
183 // static Handle<Type>::type from_constant(i::Handle<Object>, int, Region*); 183 // static Handle<Type>::type from_constant(i::Handle<Object>, int, Region*);
184 // static Handle<Type>::type from_union(Handle<Unioned>::type); 184 // static Handle<Type>::type from_struct(Handle<Struct>::type);
185 // static Handle<Unioned>::type union_create(int size, Region*); 185 // static Handle<Struct>::type struct_create(int tag, int length, Region*);
186 // static void union_shrink(Handle<Unioned>::type, int size); 186 // static void struct_shrink(Handle<Struct>::type, int length);
187 // static Handle<Type>::type union_get(Handle<Unioned>::type, int); 187 // static int struct_tag(Handle<Struct>::type);
188 // static void union_set(Handle<Unioned>::type, int, Handle<Type>::type); 188 // static Handle<Type>::type struct_get(Handle<Struct>::type, int);
189 // static int union_length(Handle<Unioned>::type); 189 // static void struct_set(Handle<Struct>::type, int, Handle<Type>::type);
190 // static int struct_length(Handle<Struct>::type);
190 // static int lub_bitset(Type*); 191 // static int lub_bitset(Type*);
191 // } 192 // }
192 template<class Config> 193 template<class Config>
193 class TypeImpl : public Config::Base { 194 class TypeImpl : public Config::Base {
194 public: 195 public:
195 typedef typename Config::template Handle<TypeImpl>::type TypeHandle; 196 typedef typename Config::template Handle<TypeImpl>::type TypeHandle;
196 typedef typename Config::Region Region; 197 typedef typename Config::Region Region;
197 198
198 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \ 199 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \
199 static TypeImpl* type() { return Config::from_bitset(k##type); } \ 200 static TypeImpl* type() { return Config::from_bitset(k##type); } \
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 296
296 #ifdef OBJECT_PRINT 297 #ifdef OBJECT_PRINT
297 enum PrintDimension { BOTH_DIMS, SEMANTIC_DIM, REPRESENTATION_DIM }; 298 enum PrintDimension { BOTH_DIMS, SEMANTIC_DIM, REPRESENTATION_DIM };
298 void TypePrint(PrintDimension = BOTH_DIMS); 299 void TypePrint(PrintDimension = BOTH_DIMS);
299 void TypePrint(FILE* out, PrintDimension = BOTH_DIMS); 300 void TypePrint(FILE* out, PrintDimension = BOTH_DIMS);
300 #endif 301 #endif
301 302
302 private: 303 private:
303 template<class> friend class Iterator; 304 template<class> friend class Iterator;
304 template<class> friend class TypeImpl; 305 template<class> friend class TypeImpl;
306 friend struct ZoneTypeConfig;
307 friend struct HeapTypeConfig;
305 308
306 // A union is a fixed array containing types. Invariants: 309 enum Tag {
310 kClassTag,
311 kConstantTag,
312 kUnionTag
313 };
314
315 // A structured type contains a tag an a variable number of type fields.
316 // A union is a structured type with the following invariants:
307 // - its length is at least 2 317 // - its length is at least 2
308 // - at most one field is a bitset, and it must go into index 0 318 // - at most one field is a bitset, and it must go into index 0
309 // - no field is a union 319 // - no field is a union
310 typedef typename Config::Unioned Unioned; 320 typedef typename Config::Struct Struct;
311 typedef typename Config::template Handle<Unioned>::type UnionedHandle; 321 typedef typename Config::template Handle<Struct>::type StructHandle;
312 322
313 enum { 323 enum {
314 #define DECLARE_TYPE(type, value) k##type = (value), 324 #define DECLARE_TYPE(type, value) k##type = (value),
315 BITSET_TYPE_LIST(DECLARE_TYPE) 325 BITSET_TYPE_LIST(DECLARE_TYPE)
316 #undef DECLARE_TYPE 326 #undef DECLARE_TYPE
317 kUnusedEOL = 0 327 kUnusedEOL = 0
318 }; 328 };
319 329
320 bool IsNone() { return this == None(); } 330 bool IsNone() { return this == None(); }
321 bool IsAny() { return this == Any(); } 331 bool IsAny() { return this == Any(); }
322 bool IsBitset() { return Config::is_bitset(this); } 332 bool IsBitset() { return Config::is_bitset(this); }
323 bool IsUnion() { return Config::is_union(this); } 333 bool IsStruct(Tag tag) {
334 return Config::is_struct(this)
335 && Config::struct_tag(Config::as_struct(this)) == tag;
336 }
337 bool IsUnion() { return IsStruct(kUnionTag); }
338
324 int AsBitset() { return Config::as_bitset(this); } 339 int AsBitset() { return Config::as_bitset(this); }
325 UnionedHandle AsUnion() { return Config::as_union(this); } 340 StructHandle AsStruct(Tag tag) {
341 ASSERT(IsStruct(tag));
342 return Config::as_struct(this);
343 }
344 StructHandle AsUnion() { return AsStruct(kUnionTag); }
326 345
327 static int UnionLength(UnionedHandle unioned) { 346 static int StructLength(StructHandle structured) {
328 return Config::union_length(unioned); 347 return Config::struct_length(structured);
329 } 348 }
330 static TypeHandle UnionGet(UnionedHandle unioned, int i) { 349 static TypeHandle StructGet(StructHandle structured, int i) {
331 return Config::union_get(unioned, i); 350 return Config::struct_get(structured, i);
332 } 351 }
333 352
334 bool SlowIs(TypeImpl* that); 353 bool SlowIs(TypeImpl* that);
335 354
336 static bool IsInhabited(int bitset) { 355 static bool IsInhabited(int bitset) {
337 return (bitset & kRepresentation) && (bitset & kSemantic); 356 return (bitset & kRepresentation) && (bitset & kSemantic);
338 } 357 }
339 358
340 int LubBitset(); // least upper bound that's a bitset 359 int LubBitset(); // least upper bound that's a bitset
341 int GlbBitset(); // greatest lower bound that's a bitset 360 int GlbBitset(); // greatest lower bound that's a bitset
342 361
343 static int LubBitset(i::Object* value); 362 static int LubBitset(i::Object* value);
344 static int LubBitset(i::Map* map); 363 static int LubBitset(i::Map* map);
345 364
346 bool InUnion(UnionedHandle unioned, int current_size); 365 bool InUnion(StructHandle unioned, int current_size);
347 static int ExtendUnion( 366 static int ExtendUnion(
348 UnionedHandle unioned, TypeHandle t, int current_size); 367 StructHandle unioned, TypeHandle t, int current_size);
349 static int ExtendIntersection( 368 static int ExtendIntersection(
350 UnionedHandle unioned, TypeHandle t, TypeHandle other, int current_size); 369 StructHandle unioned, TypeHandle t, TypeHandle other, int current_size);
351 370
352 #ifdef OBJECT_PRINT 371 #ifdef OBJECT_PRINT
353 static const char* bitset_name(int bitset); 372 static const char* bitset_name(int bitset);
354 static void BitsetTypePrint(FILE* out, int bitset); 373 static void BitsetTypePrint(FILE* out, int bitset);
355 #endif 374 #endif
356 }; 375 };
357 376
358 377
359 // Zone-allocated types are either (odd) integers to represent bitsets, or 378 // Zone-allocated types are either (odd) integers to represent bitsets, or
360 // (even) pointers to zone lists for everything else. The first slot of every 379 // (even) pointers to structures for everything else.
361 // list is an explicit tag value to distinguish representation.
362 struct ZoneTypeConfig { 380 struct ZoneTypeConfig {
363 private:
364 typedef i::ZoneList<void*> Tagged;
365
366 enum Tag {
367 kClassTag,
368 kConstantTag,
369 kUnionTag
370 };
371
372 static inline Tagged* tagged_create(Tag tag, int size, Zone* zone);
373 static inline void tagged_shrink(Tagged* tagged, int size);
374 static inline Tag tagged_tag(Tagged* tagged);
375 template<class T> static inline T tagged_get(Tagged* tagged, int i);
376 template<class T> static inline void tagged_set(Tagged* tagged, int i, T val);
377 static inline int tagged_length(Tagged* tagged);
378
379 public:
380 typedef TypeImpl<ZoneTypeConfig> Type; 381 typedef TypeImpl<ZoneTypeConfig> Type;
381 class Base {}; 382 class Base {};
382 typedef i::ZoneList<Type*> Unioned; 383 struct Struct { int tag; int length; void* args[1]; };
383 typedef i::Zone Region; 384 typedef i::Zone Region;
384 template<class T> struct Handle { typedef T* type; }; 385 template<class T> struct Handle { typedef T* type; };
385 386
386 static inline Type* handle(Type* type); 387 static inline Type* handle(Type* type);
387 static inline bool is(Type* type, Tag tag);
388 static inline bool is_bitset(Type* type); 388 static inline bool is_bitset(Type* type);
389 static inline bool is_tagged(Type* type);
390 static inline bool is_class(Type* type); 389 static inline bool is_class(Type* type);
391 static inline bool is_constant(Type* type); 390 static inline bool is_constant(Type* type);
392 static inline bool is_union(Type* type); 391 static inline bool is_struct(Type* type);
393 static inline bool tagged_is_union(Tagged* tagged);
394 static inline int as_bitset(Type* type); 392 static inline int as_bitset(Type* type);
395 static inline Tagged* as_tagged(Type* type); 393 static inline Struct* as_struct(Type* type);
396 static inline i::Handle<i::Map> as_class(Type* type); 394 static inline i::Handle<i::Map> as_class(Type* type);
397 static inline i::Handle<i::Object> as_constant(Type* type); 395 static inline i::Handle<i::Object> as_constant(Type* type);
398 static inline Unioned* as_union(Type* type);
399 static inline Unioned* tagged_as_union(Tagged* tagged);
400 static inline Type* from_bitset(int bitset); 396 static inline Type* from_bitset(int bitset);
401 static inline Type* from_bitset(int bitset, Zone* zone); 397 static inline Type* from_bitset(int bitset, Zone* zone);
402 static inline Type* from_tagged(Tagged* tagged); 398 static inline Type* from_struct(Struct* structured);
403 static inline Type* from_class(i::Handle<i::Map> map, int lub, Zone* zone); 399 static inline Type* from_class(i::Handle<i::Map> map, int lub, Zone* zone);
404 static inline Type* from_constant( 400 static inline Type* from_constant(
405 i::Handle<i::Object> value, int lub, Zone* zone); 401 i::Handle<i::Object> value, int lub, Zone* zone);
406 static inline Type* from_union(Unioned* unioned); 402 static inline Struct* struct_create(int tag, int length, Zone* zone);
407 static inline Tagged* tagged_from_union(Unioned* unioned); 403 static inline void struct_shrink(Struct* structured, int length);
408 static inline Unioned* union_create(int size, Zone* zone); 404 static inline int struct_tag(Struct* structured);
409 static inline void union_shrink(Unioned* unioned, int size); 405 static inline Type* struct_get(Struct* structured, int i);
410 static inline Type* union_get(Unioned* unioned, int i); 406 static inline void struct_set(Struct* structured, int i, Type* type);
411 static inline void union_set(Unioned* unioned, int i, Type* type); 407 static inline int struct_length(Struct* structured);
412 static inline int union_length(Unioned* unioned);
413 static inline int lub_bitset(Type* type); 408 static inline int lub_bitset(Type* type);
414 }; 409 };
415 410
416 typedef TypeImpl<ZoneTypeConfig> Type; 411 typedef TypeImpl<ZoneTypeConfig> Type;
417 412
418 413
419 // Heap-allocated types are either smis for bitsets, maps for classes, boxes for 414 // Heap-allocated types are either smis for bitsets, maps for classes, boxes for
420 // constants, or fixed arrays for unions. 415 // constants, or fixed arrays for unions.
421 struct HeapTypeConfig { 416 struct HeapTypeConfig {
422 typedef TypeImpl<HeapTypeConfig> Type; 417 typedef TypeImpl<HeapTypeConfig> Type;
423 typedef i::Object Base; 418 typedef i::Object Base;
424 typedef i::FixedArray Unioned; 419 typedef i::FixedArray Struct;
425 typedef i::Isolate Region; 420 typedef i::Isolate Region;
426 template<class T> struct Handle { typedef i::Handle<T> type; }; 421 template<class T> struct Handle { typedef i::Handle<T> type; };
427 422
428 static inline i::Handle<Type> handle(Type* type); 423 static inline i::Handle<Type> handle(Type* type);
429 static inline bool is_bitset(Type* type); 424 static inline bool is_bitset(Type* type);
430 static inline bool is_class(Type* type); 425 static inline bool is_class(Type* type);
431 static inline bool is_constant(Type* type); 426 static inline bool is_constant(Type* type);
432 static inline bool is_union(Type* type); 427 static inline bool is_struct(Type* type);
433 static inline int as_bitset(Type* type); 428 static inline int as_bitset(Type* type);
434 static inline i::Handle<i::Map> as_class(Type* type); 429 static inline i::Handle<i::Map> as_class(Type* type);
435 static inline i::Handle<i::Object> as_constant(Type* type); 430 static inline i::Handle<i::Object> as_constant(Type* type);
436 static inline i::Handle<Unioned> as_union(Type* type); 431 static inline i::Handle<Struct> as_struct(Type* type);
437 static inline Type* from_bitset(int bitset); 432 static inline Type* from_bitset(int bitset);
438 static inline i::Handle<Type> from_bitset(int bitset, Isolate* isolate); 433 static inline i::Handle<Type> from_bitset(int bitset, Isolate* isolate);
439 static inline i::Handle<Type> from_class( 434 static inline i::Handle<Type> from_class(
440 i::Handle<i::Map> map, int lub, Isolate* isolate); 435 i::Handle<i::Map> map, int lub, Isolate* isolate);
441 static inline i::Handle<Type> from_constant( 436 static inline i::Handle<Type> from_constant(
442 i::Handle<i::Object> value, int lub, Isolate* isolate); 437 i::Handle<i::Object> value, int lub, Isolate* isolate);
443 static inline i::Handle<Type> from_union(i::Handle<Unioned> unioned); 438 static inline i::Handle<Type> from_struct(i::Handle<Struct> structured);
444 static inline i::Handle<Unioned> union_create(int size, Isolate* isolate); 439 static inline i::Handle<Struct> struct_create(
445 static inline void union_shrink(i::Handle<Unioned> unioned, int size); 440 int tag, int length, Isolate* isolate);
446 static inline i::Handle<Type> union_get(i::Handle<Unioned> unioned, int i); 441 static inline void struct_shrink(i::Handle<Struct> structured, int length);
447 static inline void union_set( 442 static inline int struct_tag(i::Handle<Struct> structured);
448 i::Handle<Unioned> unioned, int i, i::Handle<Type> type); 443 static inline i::Handle<Type> struct_get(i::Handle<Struct> structured, int i);
449 static inline int union_length(i::Handle<Unioned> unioned); 444 static inline void struct_set(
445 i::Handle<Struct> structured, int i, i::Handle<Type> type);
446 static inline int struct_length(i::Handle<Struct> structured);
450 static inline int lub_bitset(Type* type); 447 static inline int lub_bitset(Type* type);
451 }; 448 };
452 449
453 typedef TypeImpl<HeapTypeConfig> HeapType; 450 typedef TypeImpl<HeapTypeConfig> HeapType;
454 451
455 452
456 // A simple struct to represent a pair of lower/upper type bounds. 453 // A simple struct to represent a pair of lower/upper type bounds.
457 template<class Config> 454 template<class Config>
458 struct BoundsImpl { 455 struct BoundsImpl {
459 typedef TypeImpl<Config> Type; 456 typedef TypeImpl<Config> Type;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 bool Narrows(BoundsImpl that) { 502 bool Narrows(BoundsImpl that) {
506 return that.lower->Is(this->lower) && this->upper->Is(that.upper); 503 return that.lower->Is(this->lower) && this->upper->Is(that.upper);
507 } 504 }
508 }; 505 };
509 506
510 typedef BoundsImpl<ZoneTypeConfig> Bounds; 507 typedef BoundsImpl<ZoneTypeConfig> Bounds;
511 508
512 } } // namespace v8::internal 509 } } // namespace v8::internal
513 510
514 #endif // V8_TYPES_H_ 511 #endif // V8_TYPES_H_
OLDNEW
« no previous file with comments | « no previous file | src/types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698