OLD | NEW |
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 2458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2469 | 2469 |
2470 // Returns the number of descriptors in the array. | 2470 // Returns the number of descriptors in the array. |
2471 int number_of_descriptors() { | 2471 int number_of_descriptors() { |
2472 ASSERT(MayContainTransitions() || IsEmpty()); | 2472 ASSERT(MayContainTransitions() || IsEmpty()); |
2473 int len = length(); | 2473 int len = length(); |
2474 return len <= kFirstIndex ? 0 : (len - kFirstIndex) / kDescriptorSize; | 2474 return len <= kFirstIndex ? 0 : (len - kFirstIndex) / kDescriptorSize; |
2475 } | 2475 } |
2476 | 2476 |
2477 inline int number_of_entries() { return number_of_descriptors(); } | 2477 inline int number_of_entries() { return number_of_descriptors(); } |
2478 | 2478 |
2479 int NextEnumerationIndex() { | 2479 int LastAdded() { |
2480 if (IsEmpty()) return PropertyDetails::kInitialIndex; | 2480 ASSERT(!IsEmpty()); |
2481 Object* obj = get(kEnumerationIndexIndex); | 2481 Object* obj = get(kLastAddedIndex); |
2482 if (obj->IsSmi()) { | 2482 if (obj->IsSmi()) { |
2483 return Smi::cast(obj)->value(); | 2483 return Smi::cast(obj)->value(); |
2484 } else { | 2484 } else { |
2485 Object* index = FixedArray::cast(obj)->get(kEnumCacheBridgeEnumIndex); | 2485 Object* index = FixedArray::cast(obj)->get(kEnumCacheBridgeLastAdded); |
2486 return Smi::cast(index)->value(); | 2486 return Smi::cast(index)->value(); |
2487 } | 2487 } |
2488 } | 2488 } |
2489 | 2489 |
2490 // Set next enumeration index and flush any enum cache. | 2490 int NextEnumerationIndex() { |
2491 void SetNextEnumerationIndex(int value) { | 2491 if (number_of_descriptors() == 0) { |
2492 if (!IsEmpty()) { | 2492 return PropertyDetails::kInitialIndex; |
2493 set(kEnumerationIndexIndex, Smi::FromInt(value)); | |
2494 } | 2493 } |
| 2494 return GetDetails(LastAdded()).index() + 1; |
2495 } | 2495 } |
| 2496 |
| 2497 // Set index of the last added descriptor and flush any enum cache. |
| 2498 void SetLastAdded(int index) { |
| 2499 ASSERT(!IsEmpty() || index > 0); |
| 2500 set(kLastAddedIndex, Smi::FromInt(index)); |
| 2501 } |
| 2502 |
2496 bool HasEnumCache() { | 2503 bool HasEnumCache() { |
2497 return !IsEmpty() && !get(kEnumerationIndexIndex)->IsSmi(); | 2504 return !IsEmpty() && !get(kLastAddedIndex)->IsSmi(); |
2498 } | 2505 } |
2499 | 2506 |
2500 Object* GetEnumCache() { | 2507 Object* GetEnumCache() { |
2501 ASSERT(HasEnumCache()); | 2508 ASSERT(HasEnumCache()); |
2502 FixedArray* bridge = FixedArray::cast(get(kEnumerationIndexIndex)); | 2509 FixedArray* bridge = FixedArray::cast(get(kLastAddedIndex)); |
2503 return bridge->get(kEnumCacheBridgeCacheIndex); | 2510 return bridge->get(kEnumCacheBridgeCacheIndex); |
2504 } | 2511 } |
2505 | 2512 |
2506 Object** GetEnumCacheSlot() { | 2513 Object** GetEnumCacheSlot() { |
2507 ASSERT(HasEnumCache()); | 2514 ASSERT(HasEnumCache()); |
2508 return HeapObject::RawField(reinterpret_cast<HeapObject*>(this), | 2515 return HeapObject::RawField(reinterpret_cast<HeapObject*>(this), |
2509 kEnumerationIndexOffset); | 2516 kLastAddedOffset); |
2510 } | 2517 } |
2511 | 2518 |
2512 Object** GetTransitionsSlot() { | 2519 Object** GetTransitionsSlot() { |
2513 return HeapObject::RawField(reinterpret_cast<HeapObject*>(this), | 2520 return HeapObject::RawField(reinterpret_cast<HeapObject*>(this), |
2514 kTransitionsOffset); | 2521 kTransitionsOffset); |
2515 } | 2522 } |
2516 | 2523 |
2517 DECL_ACCESSORS(back_pointer_storage, Object) | 2524 DECL_ACCESSORS(back_pointer_storage, Object) |
2518 | 2525 |
2519 // Initialize or change the enum cache, | 2526 // Initialize or change the enum cache, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2597 MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors, | 2604 MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors, |
2598 SharedMode shared_mode); | 2605 SharedMode shared_mode); |
2599 | 2606 |
2600 // Casting. | 2607 // Casting. |
2601 static inline DescriptorArray* cast(Object* obj); | 2608 static inline DescriptorArray* cast(Object* obj); |
2602 | 2609 |
2603 // Constant for denoting key was not found. | 2610 // Constant for denoting key was not found. |
2604 static const int kNotFound = -1; | 2611 static const int kNotFound = -1; |
2605 | 2612 |
2606 static const int kBackPointerStorageIndex = 0; | 2613 static const int kBackPointerStorageIndex = 0; |
2607 static const int kEnumerationIndexIndex = 1; | 2614 static const int kLastAddedIndex = 1; |
2608 static const int kTransitionsIndex = 2; | 2615 static const int kTransitionsIndex = 2; |
2609 static const int kFirstIndex = 3; | 2616 static const int kFirstIndex = 3; |
2610 | 2617 |
2611 // The length of the "bridge" to the enum cache. | 2618 // The length of the "bridge" to the enum cache. |
2612 static const int kEnumCacheBridgeLength = 3; | 2619 static const int kEnumCacheBridgeLength = 3; |
2613 static const int kEnumCacheBridgeEnumIndex = 0; | 2620 static const int kEnumCacheBridgeLastAdded = 0; |
2614 static const int kEnumCacheBridgeCacheIndex = 1; | 2621 static const int kEnumCacheBridgeCacheIndex = 1; |
2615 static const int kEnumCacheBridgeIndicesCacheIndex = 2; | 2622 static const int kEnumCacheBridgeIndicesCacheIndex = 2; |
2616 | 2623 |
2617 // Layout description. | 2624 // Layout description. |
2618 static const int kBackPointerStorageOffset = FixedArray::kHeaderSize; | 2625 static const int kBackPointerStorageOffset = FixedArray::kHeaderSize; |
2619 static const int kEnumerationIndexOffset = kBackPointerStorageOffset + | 2626 static const int kLastAddedOffset = kBackPointerStorageOffset + |
2620 kPointerSize; | 2627 kPointerSize; |
2621 static const int kTransitionsOffset = kEnumerationIndexOffset + kPointerSize; | 2628 static const int kTransitionsOffset = kLastAddedOffset + kPointerSize; |
2622 static const int kFirstOffset = kTransitionsOffset + kPointerSize; | 2629 static const int kFirstOffset = kTransitionsOffset + kPointerSize; |
2623 | 2630 |
2624 // Layout description for the bridge array. | 2631 // Layout description for the bridge array. |
2625 static const int kEnumCacheBridgeEnumOffset = FixedArray::kHeaderSize; | 2632 static const int kEnumCacheBridgeLastAddedOffset = FixedArray::kHeaderSize; |
2626 static const int kEnumCacheBridgeCacheOffset = | 2633 static const int kEnumCacheBridgeCacheOffset = |
2627 kEnumCacheBridgeEnumOffset + kPointerSize; | 2634 kEnumCacheBridgeLastAddedOffset + kPointerSize; |
2628 | 2635 |
2629 // Layout of descriptor. | 2636 // Layout of descriptor. |
2630 static const int kDescriptorKey = 0; | 2637 static const int kDescriptorKey = 0; |
2631 static const int kDescriptorDetails = 1; | 2638 static const int kDescriptorDetails = 1; |
2632 static const int kDescriptorValue = 2; | 2639 static const int kDescriptorValue = 2; |
2633 static const int kDescriptorSize = 3; | 2640 static const int kDescriptorSize = 3; |
2634 | 2641 |
2635 #ifdef OBJECT_PRINT | 2642 #ifdef OBJECT_PRINT |
2636 // Print all the descriptors. | 2643 // Print all the descriptors. |
2637 inline void PrintDescriptors() { | 2644 inline void PrintDescriptors() { |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3083 enum SortMode { UNSORTED, SORTED }; | 3090 enum SortMode { UNSORTED, SORTED }; |
3084 // Copies keys to preallocated fixed array. | 3091 // Copies keys to preallocated fixed array. |
3085 void CopyKeysTo(FixedArray* storage, | 3092 void CopyKeysTo(FixedArray* storage, |
3086 PropertyAttributes filter, | 3093 PropertyAttributes filter, |
3087 SortMode sort_mode); | 3094 SortMode sort_mode); |
3088 // Fill in details for properties into storage. | 3095 // Fill in details for properties into storage. |
3089 void CopyKeysTo(FixedArray* storage, int index, SortMode sort_mode); | 3096 void CopyKeysTo(FixedArray* storage, int index, SortMode sort_mode); |
3090 | 3097 |
3091 // Accessors for next enumeration index. | 3098 // Accessors for next enumeration index. |
3092 void SetNextEnumerationIndex(int index) { | 3099 void SetNextEnumerationIndex(int index) { |
| 3100 ASSERT(index != 0); |
3093 this->set(kNextEnumerationIndexIndex, Smi::FromInt(index)); | 3101 this->set(kNextEnumerationIndexIndex, Smi::FromInt(index)); |
3094 } | 3102 } |
3095 | 3103 |
3096 int NextEnumerationIndex() { | 3104 int NextEnumerationIndex() { |
3097 return Smi::cast(FixedArray::get(kNextEnumerationIndexIndex))->value(); | 3105 return Smi::cast(FixedArray::get(kNextEnumerationIndexIndex))->value(); |
3098 } | 3106 } |
3099 | 3107 |
3100 // Returns a new array for dictionary usage. Might return Failure. | 3108 // Returns a new array for dictionary usage. Might return Failure. |
3101 MUST_USE_RESULT static MaybeObject* Allocate(int at_least_space_for); | 3109 MUST_USE_RESULT static MaybeObject* Allocate(int at_least_space_for); |
3102 | 3110 |
(...skipping 5767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8870 } else { | 8878 } else { |
8871 value &= ~(1 << bit_position); | 8879 value &= ~(1 << bit_position); |
8872 } | 8880 } |
8873 return value; | 8881 return value; |
8874 } | 8882 } |
8875 }; | 8883 }; |
8876 | 8884 |
8877 } } // namespace v8::internal | 8885 } } // namespace v8::internal |
8878 | 8886 |
8879 #endif // V8_OBJECTS_H_ | 8887 #endif // V8_OBJECTS_H_ |
OLD | NEW |