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

Side by Side Diff: src/elements.cc

Issue 9618003: Automatically determine ElementsKind name for debug printing (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 9 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // ... 97 // ...
98 // } 98 // }
99 // 99 //
100 // This is an example of the Curiously Recurring Template Pattern (see 100 // This is an example of the Curiously Recurring Template Pattern (see
101 // http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern). We use 101 // http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern). We use
102 // CRTP to guarantee aggressive compile time optimizations (i.e. inlining and 102 // CRTP to guarantee aggressive compile time optimizations (i.e. inlining and
103 // specialization of SomeElementsAccessor methods). 103 // specialization of SomeElementsAccessor methods).
104 template <typename ElementsAccessorSubclass, typename BackingStoreClass> 104 template <typename ElementsAccessorSubclass, typename BackingStoreClass>
105 class ElementsAccessorBase : public ElementsAccessor { 105 class ElementsAccessorBase : public ElementsAccessor {
106 protected: 106 protected:
107 ElementsAccessorBase() { } 107 ElementsAccessorBase(const char* name) : ElementsAccessor(name) { }
108 virtual MaybeObject* Get(FixedArrayBase* backing_store, 108 virtual MaybeObject* Get(FixedArrayBase* backing_store,
109 uint32_t key, 109 uint32_t key,
110 JSObject* obj, 110 JSObject* obj,
111 Object* receiver) { 111 Object* receiver) {
112 return ElementsAccessorSubclass::GetImpl( 112 return ElementsAccessorSubclass::GetImpl(
113 BackingStoreClass::cast(backing_store), key, obj, receiver); 113 BackingStoreClass::cast(backing_store), key, obj, receiver);
114 } 114 }
115 115
116 static MaybeObject* GetImpl(BackingStoreClass* backing_store, 116 static MaybeObject* GetImpl(BackingStoreClass* backing_store,
117 uint32_t key, 117 uint32_t key,
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 DISALLOW_COPY_AND_ASSIGN(ElementsAccessorBase); 273 DISALLOW_COPY_AND_ASSIGN(ElementsAccessorBase);
274 }; 274 };
275 275
276 276
277 // Super class for all fast element arrays. 277 // Super class for all fast element arrays.
278 template<typename FastElementsAccessorSubclass, 278 template<typename FastElementsAccessorSubclass,
279 typename BackingStore, 279 typename BackingStore,
280 int ElementSize> 280 int ElementSize>
281 class FastElementsAccessor 281 class FastElementsAccessor
282 : public ElementsAccessorBase<FastElementsAccessorSubclass, BackingStore> { 282 : public ElementsAccessorBase<FastElementsAccessorSubclass, BackingStore> {
283 public:
284 explicit FastElementsAccessor(const char* name)
285 : ElementsAccessorBase<FastElementsAccessorSubclass, BackingStore>(name) { }
283 protected: 286 protected:
284 friend class ElementsAccessorBase<FastElementsAccessorSubclass, BackingStore>; 287 friend class ElementsAccessorBase<FastElementsAccessorSubclass, BackingStore>;
285 288
286 // Adjusts the length of the fast backing store or returns the new length or 289 // Adjusts the length of the fast backing store or returns the new length or
287 // undefined in case conversion to a slow backing store should be performed. 290 // undefined in case conversion to a slow backing store should be performed.
288 static MaybeObject* SetLengthWithoutNormalize(BackingStore* backing_store, 291 static MaybeObject* SetLengthWithoutNormalize(BackingStore* backing_store,
289 JSArray* array, 292 JSArray* array,
290 Object* length_object, 293 Object* length_object,
291 uint32_t length) { 294 uint32_t length) {
292 uint32_t old_capacity = backing_store->length(); 295 uint32_t old_capacity = backing_store->length();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 return array->GetHeap()->undefined_value(); 335 return array->GetHeap()->undefined_value();
333 } 336 }
334 }; 337 };
335 338
336 339
337 class FastObjectElementsAccessor 340 class FastObjectElementsAccessor
338 : public FastElementsAccessor<FastObjectElementsAccessor, 341 : public FastElementsAccessor<FastObjectElementsAccessor,
339 FixedArray, 342 FixedArray,
340 kPointerSize> { 343 kPointerSize> {
341 public: 344 public:
345 FastObjectElementsAccessor(const char* name)
Jakob Kummerow 2012/03/06 10:07:42 explicit
346 : FastElementsAccessor<FastObjectElementsAccessor,
347 FixedArray,
348 kPointerSize>(name) {}
349
342 static MaybeObject* DeleteCommon(JSObject* obj, 350 static MaybeObject* DeleteCommon(JSObject* obj,
343 uint32_t key) { 351 uint32_t key) {
344 ASSERT(obj->HasFastElements() || 352 ASSERT(obj->HasFastElements() ||
345 obj->HasFastSmiOnlyElements() || 353 obj->HasFastSmiOnlyElements() ||
346 obj->HasFastArgumentsElements()); 354 obj->HasFastArgumentsElements());
347 Heap* heap = obj->GetHeap(); 355 Heap* heap = obj->GetHeap();
348 FixedArray* backing_store = FixedArray::cast(obj->elements()); 356 FixedArray* backing_store = FixedArray::cast(obj->elements());
349 if (backing_store->map() == heap->non_strict_arguments_elements_map()) { 357 if (backing_store->map() == heap->non_strict_arguments_elements_map()) {
350 backing_store = FixedArray::cast(backing_store->get(1)); 358 backing_store = FixedArray::cast(backing_store->get(1));
351 } else { 359 } else {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 JSReceiver::DeleteMode mode) { 415 JSReceiver::DeleteMode mode) {
408 return DeleteCommon(obj, key); 416 return DeleteCommon(obj, key);
409 } 417 }
410 }; 418 };
411 419
412 420
413 class FastDoubleElementsAccessor 421 class FastDoubleElementsAccessor
414 : public FastElementsAccessor<FastDoubleElementsAccessor, 422 : public FastElementsAccessor<FastDoubleElementsAccessor,
415 FixedDoubleArray, 423 FixedDoubleArray,
416 kDoubleSize> { 424 kDoubleSize> {
425 public:
426 FastDoubleElementsAccessor(const char* name)
Jakob Kummerow 2012/03/06 10:07:42 explicit
427 : FastElementsAccessor<FastDoubleElementsAccessor,
428 FixedDoubleArray,
429 kDoubleSize>(name) {}
430
417 static MaybeObject* SetFastElementsCapacityAndLength(JSObject* obj, 431 static MaybeObject* SetFastElementsCapacityAndLength(JSObject* obj,
418 uint32_t capacity, 432 uint32_t capacity,
419 uint32_t length) { 433 uint32_t length) {
420 return obj->SetFastDoubleElementsCapacityAndLength(capacity, length); 434 return obj->SetFastDoubleElementsCapacityAndLength(capacity, length);
421 } 435 }
422 436
423 protected: 437 protected:
424 friend class ElementsAccessorBase<FastDoubleElementsAccessor, 438 friend class ElementsAccessorBase<FastDoubleElementsAccessor,
425 FixedDoubleArray>; 439 FixedDoubleArray>;
426 friend class FastElementsAccessor<FastDoubleElementsAccessor, 440 friend class FastElementsAccessor<FastDoubleElementsAccessor,
(...skipping 20 matching lines...) Expand all
447 } 461 }
448 }; 462 };
449 463
450 464
451 // Super class for all external element arrays. 465 // Super class for all external element arrays.
452 template<typename ExternalElementsAccessorSubclass, 466 template<typename ExternalElementsAccessorSubclass,
453 typename ExternalArray> 467 typename ExternalArray>
454 class ExternalElementsAccessor 468 class ExternalElementsAccessor
455 : public ElementsAccessorBase<ExternalElementsAccessorSubclass, 469 : public ElementsAccessorBase<ExternalElementsAccessorSubclass,
456 ExternalArray> { 470 ExternalArray> {
471 public:
472 ExternalElementsAccessor(const char* name)
Jakob Kummerow 2012/03/06 10:07:42 explicit
473 : ElementsAccessorBase<ExternalElementsAccessorSubclass,
474 ExternalArray>(name) {}
475
457 protected: 476 protected:
458 friend class ElementsAccessorBase<ExternalElementsAccessorSubclass, 477 friend class ElementsAccessorBase<ExternalElementsAccessorSubclass,
459 ExternalArray>; 478 ExternalArray>;
460 479
461 static MaybeObject* GetImpl(ExternalArray* backing_store, 480 static MaybeObject* GetImpl(ExternalArray* backing_store,
462 uint32_t key, 481 uint32_t key,
463 JSObject* obj, 482 JSObject* obj,
464 Object* receiver) { 483 Object* receiver) {
465 return 484 return
466 key < ExternalElementsAccessorSubclass::GetCapacityImpl(backing_store) 485 key < ExternalElementsAccessorSubclass::GetCapacityImpl(backing_store)
(...skipping 23 matching lines...) Expand all
490 uint32_t capacity = 509 uint32_t capacity =
491 ExternalElementsAccessorSubclass::GetCapacityImpl(backing_store); 510 ExternalElementsAccessorSubclass::GetCapacityImpl(backing_store);
492 return key < capacity; 511 return key < capacity;
493 } 512 }
494 }; 513 };
495 514
496 515
497 class ExternalByteElementsAccessor 516 class ExternalByteElementsAccessor
498 : public ExternalElementsAccessor<ExternalByteElementsAccessor, 517 : public ExternalElementsAccessor<ExternalByteElementsAccessor,
499 ExternalByteArray> { 518 ExternalByteArray> {
519 public:
520 ExternalByteElementsAccessor(const char* name)
Jakob Kummerow 2012/03/06 10:07:42 make ALL the ctors explicit! (more below)
521 : ExternalElementsAccessor<ExternalByteElementsAccessor,
522 ExternalByteArray>(name) {}
500 }; 523 };
501 524
502 525
503 class ExternalUnsignedByteElementsAccessor 526 class ExternalUnsignedByteElementsAccessor
504 : public ExternalElementsAccessor<ExternalUnsignedByteElementsAccessor, 527 : public ExternalElementsAccessor<ExternalUnsignedByteElementsAccessor,
505 ExternalUnsignedByteArray> { 528 ExternalUnsignedByteArray> {
529 public:
530 ExternalUnsignedByteElementsAccessor(const char* name)
531 : ExternalElementsAccessor<ExternalUnsignedByteElementsAccessor,
532 ExternalUnsignedByteArray>(name) {}
506 }; 533 };
507 534
508 535
509 class ExternalShortElementsAccessor 536 class ExternalShortElementsAccessor
510 : public ExternalElementsAccessor<ExternalShortElementsAccessor, 537 : public ExternalElementsAccessor<ExternalShortElementsAccessor,
511 ExternalShortArray> { 538 ExternalShortArray> {
539 public:
540 ExternalShortElementsAccessor(const char* name)
541 : ExternalElementsAccessor<ExternalShortElementsAccessor,
542 ExternalShortArray>(name) {}
512 }; 543 };
513 544
514 545
515 class ExternalUnsignedShortElementsAccessor 546 class ExternalUnsignedShortElementsAccessor
516 : public ExternalElementsAccessor<ExternalUnsignedShortElementsAccessor, 547 : public ExternalElementsAccessor<ExternalUnsignedShortElementsAccessor,
517 ExternalUnsignedShortArray> { 548 ExternalUnsignedShortArray> {
549 public:
550 ExternalUnsignedShortElementsAccessor(const char* name)
551 : ExternalElementsAccessor<ExternalUnsignedShortElementsAccessor,
552 ExternalUnsignedShortArray>(name) {}
518 }; 553 };
519 554
520 555
521 class ExternalIntElementsAccessor 556 class ExternalIntElementsAccessor
522 : public ExternalElementsAccessor<ExternalIntElementsAccessor, 557 : public ExternalElementsAccessor<ExternalIntElementsAccessor,
523 ExternalIntArray> { 558 ExternalIntArray> {
559 public:
560 ExternalIntElementsAccessor(const char* name)
561 : ExternalElementsAccessor<ExternalIntElementsAccessor,
562 ExternalIntArray>(name) {}
524 }; 563 };
525 564
526 565
527 class ExternalUnsignedIntElementsAccessor 566 class ExternalUnsignedIntElementsAccessor
528 : public ExternalElementsAccessor<ExternalUnsignedIntElementsAccessor, 567 : public ExternalElementsAccessor<ExternalUnsignedIntElementsAccessor,
529 ExternalUnsignedIntArray> { 568 ExternalUnsignedIntArray> {
569 public:
570 ExternalUnsignedIntElementsAccessor(const char* name)
571 : ExternalElementsAccessor<ExternalUnsignedIntElementsAccessor,
572 ExternalUnsignedIntArray>(name) {}
573
530 }; 574 };
531 575
532 576
533 class ExternalFloatElementsAccessor 577 class ExternalFloatElementsAccessor
534 : public ExternalElementsAccessor<ExternalFloatElementsAccessor, 578 : public ExternalElementsAccessor<ExternalFloatElementsAccessor,
535 ExternalFloatArray> { 579 ExternalFloatArray> {
580 public:
581 ExternalFloatElementsAccessor(const char* name)
582 : ExternalElementsAccessor<ExternalFloatElementsAccessor,
583 ExternalFloatArray>(name) {}
536 }; 584 };
537 585
538 586
539 class ExternalDoubleElementsAccessor 587 class ExternalDoubleElementsAccessor
540 : public ExternalElementsAccessor<ExternalDoubleElementsAccessor, 588 : public ExternalElementsAccessor<ExternalDoubleElementsAccessor,
541 ExternalDoubleArray> { 589 ExternalDoubleArray> {
590 public:
591 ExternalDoubleElementsAccessor(const char* name)
592 : ExternalElementsAccessor<ExternalDoubleElementsAccessor,
593 ExternalDoubleArray>(name) {}
542 }; 594 };
543 595
544 596
545 class PixelElementsAccessor 597 class PixelElementsAccessor
546 : public ExternalElementsAccessor<PixelElementsAccessor, 598 : public ExternalElementsAccessor<PixelElementsAccessor,
547 ExternalPixelArray> { 599 ExternalPixelArray> {
600 public:
601 PixelElementsAccessor(const char* name)
602 : ExternalElementsAccessor<PixelElementsAccessor,
603 ExternalPixelArray>(name) {}
548 }; 604 };
549 605
550 606
551 class DictionaryElementsAccessor 607 class DictionaryElementsAccessor
552 : public ElementsAccessorBase<DictionaryElementsAccessor, 608 : public ElementsAccessorBase<DictionaryElementsAccessor,
553 SeededNumberDictionary> { 609 SeededNumberDictionary> {
554 public: 610 public:
611 DictionaryElementsAccessor(const char* name)
612 : ElementsAccessorBase<DictionaryElementsAccessor,
613 SeededNumberDictionary>(name) {}
614
555 // Adjusts the length of the dictionary backing store and returns the new 615 // Adjusts the length of the dictionary backing store and returns the new
556 // length according to ES5 section 15.4.5.2 behavior. 616 // length according to ES5 section 15.4.5.2 behavior.
557 static MaybeObject* SetLengthWithoutNormalize(SeededNumberDictionary* dict, 617 static MaybeObject* SetLengthWithoutNormalize(SeededNumberDictionary* dict,
558 JSArray* array, 618 JSArray* array,
559 Object* length_object, 619 Object* length_object,
560 uint32_t length) { 620 uint32_t length) {
561 if (length == 0) { 621 if (length == 0) {
562 // If the length of a slow array is reset to zero, we clear 622 // If the length of a slow array is reset to zero, we clear
563 // the array and flush backing storage. This has the added 623 // the array and flush backing storage. This has the added
564 // benefit that the array returns to fast mode. 624 // benefit that the array returns to fast mode.
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 uint32_t index) { 756 uint32_t index) {
697 Object* key = dict->KeyAt(index); 757 Object* key = dict->KeyAt(index);
698 return Smi::cast(key)->value(); 758 return Smi::cast(key)->value();
699 } 759 }
700 }; 760 };
701 761
702 762
703 class NonStrictArgumentsElementsAccessor 763 class NonStrictArgumentsElementsAccessor
704 : public ElementsAccessorBase<NonStrictArgumentsElementsAccessor, 764 : public ElementsAccessorBase<NonStrictArgumentsElementsAccessor,
705 FixedArray> { 765 FixedArray> {
766 public:
767 NonStrictArgumentsElementsAccessor(const char* name)
768 : ElementsAccessorBase<NonStrictArgumentsElementsAccessor,
769 FixedArray>(name) {}
706 protected: 770 protected:
707 friend class ElementsAccessorBase<NonStrictArgumentsElementsAccessor, 771 friend class ElementsAccessorBase<NonStrictArgumentsElementsAccessor,
708 FixedArray>; 772 FixedArray>;
709 773
710 static MaybeObject* GetImpl(FixedArray* parameter_map, 774 static MaybeObject* GetImpl(FixedArray* parameter_map,
711 uint32_t key, 775 uint32_t key,
712 JSObject* obj, 776 JSObject* obj,
713 Object* receiver) { 777 Object* receiver) {
714 Object* probe = GetParameterMapArg(obj, parameter_map, key); 778 Object* probe = GetParameterMapArg(obj, parameter_map, key);
715 if (!probe->IsTheHole()) { 779 if (!probe->IsTheHole()) {
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 V(ExternalUnsignedIntElementsAccessor, EXTERNAL_UNSIGNED_INT_ELEMENTS) \ 923 V(ExternalUnsignedIntElementsAccessor, EXTERNAL_UNSIGNED_INT_ELEMENTS) \
860 V(ExternalFloatElementsAccessor, EXTERNAL_FLOAT_ELEMENTS) \ 924 V(ExternalFloatElementsAccessor, EXTERNAL_FLOAT_ELEMENTS) \
861 V(ExternalDoubleElementsAccessor, EXTERNAL_DOUBLE_ELEMENTS) \ 925 V(ExternalDoubleElementsAccessor, EXTERNAL_DOUBLE_ELEMENTS) \
862 V(PixelElementsAccessor, EXTERNAL_PIXEL_ELEMENTS) 926 V(PixelElementsAccessor, EXTERNAL_PIXEL_ELEMENTS)
863 927
864 static struct ConcreteElementsAccessors { 928 static struct ConcreteElementsAccessors {
865 #define ACCESSOR_STRUCT(Class, Name) Class* Name##_handler; 929 #define ACCESSOR_STRUCT(Class, Name) Class* Name##_handler;
866 ELEMENTS_LIST(ACCESSOR_STRUCT) 930 ELEMENTS_LIST(ACCESSOR_STRUCT)
867 #undef ACCESSOR_STRUCT 931 #undef ACCESSOR_STRUCT
868 } element_accessors = { 932 } element_accessors = {
869 #define ACCESSOR_INIT(Class, Name) new Class(), 933 #define ACCESSOR_INIT(Class, Name) new Class(#Name),
870 ELEMENTS_LIST(ACCESSOR_INIT) 934 ELEMENTS_LIST(ACCESSOR_INIT)
871 #undef ACCESSOR_INIT 935 #undef ACCESSOR_INIT
872 }; 936 };
873 937
874 static ElementsAccessor* accessor_array[] = { 938 static ElementsAccessor* accessor_array[] = {
875 #define ACCESSOR_ARRAY(Class, Name) element_accessors.Name##_handler, 939 #define ACCESSOR_ARRAY(Class, Name) element_accessors.Name##_handler,
876 ELEMENTS_LIST(ACCESSOR_ARRAY) 940 ELEMENTS_LIST(ACCESSOR_ARRAY)
877 #undef ACCESSOR_ARRAY 941 #undef ACCESSOR_ARRAY
878 }; 942 };
879 943
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 if (!maybe_obj->To(&new_backing_store)) return maybe_obj; 1004 if (!maybe_obj->To(&new_backing_store)) return maybe_obj;
941 new_backing_store->set(0, length); 1005 new_backing_store->set(0, length);
942 { MaybeObject* result = array->SetContent(new_backing_store); 1006 { MaybeObject* result = array->SetContent(new_backing_store);
943 if (result->IsFailure()) return result; 1007 if (result->IsFailure()) return result;
944 } 1008 }
945 return array; 1009 return array;
946 } 1010 }
947 1011
948 1012
949 } } // namespace v8::internal 1013 } } // namespace v8::internal
OLDNEW
« src/elements.h ('K') | « src/elements.h ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698