| 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 21 matching lines...) Expand all Loading... |
| 32 #include "heap.h" | 32 #include "heap.h" |
| 33 #include "isolate.h" | 33 #include "isolate.h" |
| 34 #include "objects.h" | 34 #include "objects.h" |
| 35 #include "v8checks.h" | 35 #include "v8checks.h" |
| 36 | 36 |
| 37 namespace v8 { | 37 namespace v8 { |
| 38 namespace internal { | 38 namespace internal { |
| 39 | 39 |
| 40 | 40 |
| 41 // TransitionArrays are fixed arrays used to hold map transitions for property, | 41 // TransitionArrays are fixed arrays used to hold map transitions for property, |
| 42 // constant, and element changes. | 42 // constant, and element changes. They can either be simple transition arrays |
| 43 // The format of the these objects is: | 43 // that store a single property transition, or a full transition array that has |
| 44 // [0] Descriptor array | 44 // space for elements transitions, prototype transitions and multiple property |
| 45 // [1] Undefined or back pointer map | 45 // transitons. The details related to property transitions are accessed in the |
| 46 // [2] Smi(0) or elements transition map | 46 // descriptor array of the target map. In the case of a simple transition, the |
| 47 // [3] Smi(0) or fixed array of prototype transitions | 47 // key is also read from the descriptor array of the target map. |
| 48 // [4] First transition | 48 // |
| 49 // The simple format of the these objects is: |
| 50 // [0] Undefined or back pointer map |
| 51 // [1] Single transition |
| 52 // |
| 53 // The full format is: |
| 54 // [0] Undefined or back pointer map |
| 55 // [1] Smi(0) or elements transition map |
| 56 // [2] Smi(0) or fixed array of prototype transitions |
| 57 // [3] First transition |
| 49 // [length() - kTransitionSize] Last transition | 58 // [length() - kTransitionSize] Last transition |
| 50 class TransitionArray: public FixedArray { | 59 class TransitionArray: public FixedArray { |
| 51 public: | 60 public: |
| 52 // Accessors for fetching instance transition at transition number. | 61 // Accessors for fetching instance transition at transition number. |
| 53 inline String* GetKey(int transition_number); | 62 inline String* GetKey(int transition_number); |
| 54 inline void SetKey(int transition_number, String* value); | 63 inline void SetKey(int transition_number, String* value); |
| 55 inline Object** GetKeySlot(int transition_number); | 64 inline Object** GetKeySlot(int transition_number); |
| 56 int GetSortedKeyIndex(int transition_number) { return transition_number; } | 65 int GetSortedKeyIndex(int transition_number) { return transition_number; } |
| 57 | 66 |
| 58 String* GetSortedKey(int transition_number) { | 67 String* GetSortedKey(int transition_number) { |
| 59 return GetKey(transition_number); | 68 return GetKey(transition_number); |
| 60 } | 69 } |
| 61 | 70 |
| 62 inline Map* GetTarget(int transition_number); | 71 inline Map* GetTarget(int transition_number); |
| 63 inline void SetTarget(int transition_number, Map* target); | 72 inline void SetTarget(int transition_number, Map* target); |
| 64 | 73 |
| 65 inline PropertyDetails GetTargetDetails(int transition_number); | 74 inline PropertyDetails GetTargetDetails(int transition_number); |
| 66 | 75 |
| 67 inline Map* elements_transition(); | 76 inline Map* elements_transition(); |
| 68 inline void set_elements_transition( | 77 inline void set_elements_transition( |
| 69 Map* target, | 78 Map* target, |
| 70 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); | 79 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 71 inline bool HasElementsTransition(); | 80 inline bool HasElementsTransition(); |
| 72 inline void ClearElementsTransition(); | 81 inline void ClearElementsTransition(); |
| 73 | 82 |
| 74 inline Object** GetDescriptorsSlot(); | |
| 75 inline DescriptorArray* descriptors(); | |
| 76 inline void set_descriptors(DescriptorArray* descriptors); | |
| 77 | |
| 78 inline Object* back_pointer_storage(); | 83 inline Object* back_pointer_storage(); |
| 79 inline void set_back_pointer_storage( | 84 inline void set_back_pointer_storage( |
| 80 Object* back_pointer, | 85 Object* back_pointer, |
| 81 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); | 86 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 82 | 87 |
| 83 inline FixedArray* GetPrototypeTransitions(); | 88 inline FixedArray* GetPrototypeTransitions(); |
| 84 inline void SetPrototypeTransitions( | 89 inline void SetPrototypeTransitions( |
| 85 FixedArray* prototype_transitions, | 90 FixedArray* prototype_transitions, |
| 86 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); | 91 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 87 inline Object** GetPrototypeTransitionsSlot(); | 92 inline Object** GetPrototypeTransitionsSlot(); |
| 88 inline bool HasPrototypeTransitions(); | 93 inline bool HasPrototypeTransitions(); |
| 89 inline HeapObject* UncheckedPrototypeTransitions(); | 94 inline HeapObject* UncheckedPrototypeTransitions(); |
| 90 | 95 |
| 91 // Returns the number of transitions in the array. | 96 // Returns the number of transitions in the array. |
| 92 int number_of_transitions() { | 97 int number_of_transitions() { |
| 93 if (IsSimpleTransition()) return 1; | 98 if (IsSimpleTransition()) return 1; |
| 94 int len = length(); | 99 int len = length(); |
| 95 return len <= kFirstIndex ? 0 : (len - kFirstIndex) / kTransitionSize; | 100 return len <= kFirstIndex ? 0 : (len - kFirstIndex) / kTransitionSize; |
| 96 } | 101 } |
| 97 | 102 |
| 98 inline int number_of_entries() { return number_of_transitions(); } | 103 inline int number_of_entries() { return number_of_transitions(); } |
| 99 | 104 |
| 100 // Allocate a new transition array with a single entry. | 105 // Allocate a new transition array with a single entry. |
| 101 static MUST_USE_RESULT MaybeObject* NewWith( | 106 static MUST_USE_RESULT MaybeObject* NewWith( |
| 102 SimpleTransitionFlag flag, | 107 SimpleTransitionFlag flag, |
| 103 String* key, | 108 String* key, |
| 104 Map* target, | 109 Map* target, |
| 105 DescriptorArray* descriptors, | |
| 106 Object* back_pointer); | 110 Object* back_pointer); |
| 107 | 111 |
| 108 static MUST_USE_RESULT MaybeObject* AllocateDescriptorsHolder(); | |
| 109 | |
| 110 MUST_USE_RESULT MaybeObject* ExtendToFullTransitionArray(); | 112 MUST_USE_RESULT MaybeObject* ExtendToFullTransitionArray(); |
| 111 | 113 |
| 112 // Copy the transition array, inserting a new transition. | 114 // Copy the transition array, inserting a new transition. |
| 113 // TODO(verwaest): This should not cause an existing transition to be | 115 // TODO(verwaest): This should not cause an existing transition to be |
| 114 // overwritten. | 116 // overwritten. |
| 115 MUST_USE_RESULT MaybeObject* CopyInsert(String* name, Map* target); | 117 MUST_USE_RESULT MaybeObject* CopyInsert(String* name, Map* target); |
| 116 | 118 |
| 117 // Copy a single transition from the origin array. | 119 // Copy a single transition from the origin array. |
| 118 inline void NoIncrementalWriteBarrierCopyFrom(TransitionArray* origin, | 120 inline void NoIncrementalWriteBarrierCopyFrom(TransitionArray* origin, |
| 119 int origin_transition, | 121 int origin_transition, |
| 120 int target_transition); | 122 int target_transition); |
| 121 | 123 |
| 122 // Search a transition for a given property name. | 124 // Search a transition for a given property name. |
| 123 inline int Search(String* name); | 125 inline int Search(String* name); |
| 124 | 126 |
| 125 // Allocates a TransitionArray. | 127 // Allocates a TransitionArray. |
| 126 MUST_USE_RESULT static MaybeObject* Allocate(int number_of_transitions); | 128 MUST_USE_RESULT static MaybeObject* Allocate(int number_of_transitions); |
| 127 | 129 |
| 128 bool IsDescriptorsHolder() { return length() == kDescriptorsHolderSize; } | |
| 129 bool IsSimpleTransition() { return length() == kSimpleTransitionSize; } | 130 bool IsSimpleTransition() { return length() == kSimpleTransitionSize; } |
| 130 bool IsFullTransitionArray() { return length() >= kFirstIndex; } | 131 bool IsFullTransitionArray() { return length() >= kFirstIndex; } |
| 131 | 132 |
| 132 // Casting. | 133 // Casting. |
| 133 static inline TransitionArray* cast(Object* obj); | 134 static inline TransitionArray* cast(Object* obj); |
| 134 | 135 |
| 135 // Constant for denoting key was not found. | 136 // Constant for denoting key was not found. |
| 136 static const int kNotFound = -1; | 137 static const int kNotFound = -1; |
| 137 | 138 |
| 138 static const int kDescriptorsIndex = 0; | 139 static const int kBackPointerStorageIndex = 0; |
| 139 static const int kBackPointerStorageIndex = 1; | |
| 140 static const int kDescriptorsHolderSize = 2; | |
| 141 | 140 |
| 142 // Layout for full transition arrays. | 141 // Layout for full transition arrays. |
| 143 static const int kElementsTransitionIndex = 2; | 142 static const int kElementsTransitionIndex = 1; |
| 144 static const int kPrototypeTransitionsIndex = 3; | 143 static const int kPrototypeTransitionsIndex = 2; |
| 145 static const int kFirstIndex = 4; | 144 static const int kFirstIndex = 3; |
| 146 | 145 |
| 147 // Layout for simple transition arrays. | 146 // Layout for simple transition arrays. |
| 148 static const int kSimpleTransitionTarget = 2; | 147 static const int kSimpleTransitionTarget = 1; |
| 149 static const int kSimpleTransitionSize = 3; | 148 static const int kSimpleTransitionSize = 2; |
| 150 static const int kSimpleTransitionIndex = 0; | 149 static const int kSimpleTransitionIndex = 0; |
| 151 STATIC_ASSERT(kSimpleTransitionIndex != kNotFound); | 150 STATIC_ASSERT(kSimpleTransitionIndex != kNotFound); |
| 152 | 151 |
| 153 static const int kDescriptorsOffset = FixedArray::kHeaderSize; | 152 static const int kBackPointerStorageOffset = FixedArray::kHeaderSize; |
| 154 static const int kBackPointerStorageOffset = kDescriptorsOffset + | |
| 155 kPointerSize; | |
| 156 | 153 |
| 157 // Layout for the full transition array header. | 154 // Layout for the full transition array header. |
| 158 static const int kElementsTransitionOffset = kBackPointerStorageOffset + | 155 static const int kElementsTransitionOffset = kBackPointerStorageOffset + |
| 159 kPointerSize; | 156 kPointerSize; |
| 160 static const int kPrototypeTransitionsOffset = kElementsTransitionOffset + | 157 static const int kPrototypeTransitionsOffset = kElementsTransitionOffset + |
| 161 kPointerSize; | 158 kPointerSize; |
| 162 | 159 |
| 163 // Layout of map transition entries in full transition arrays. | 160 // Layout of map transition entries in full transition arrays. |
| 164 static const int kTransitionKey = 0; | 161 static const int kTransitionKey = 0; |
| 165 static const int kTransitionTarget = 1; | 162 static const int kTransitionTarget = 1; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 String* key, | 198 String* key, |
| 202 Map* target); | 199 Map* target); |
| 203 | 200 |
| 204 DISALLOW_IMPLICIT_CONSTRUCTORS(TransitionArray); | 201 DISALLOW_IMPLICIT_CONSTRUCTORS(TransitionArray); |
| 205 }; | 202 }; |
| 206 | 203 |
| 207 | 204 |
| 208 } } // namespace v8::internal | 205 } } // namespace v8::internal |
| 209 | 206 |
| 210 #endif // V8_TRANSITIONS_H_ | 207 #endif // V8_TRANSITIONS_H_ |
| OLD | NEW |