Chromium Code Reviews| 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 23 matching lines...) Expand all Loading... | |
| 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. They can either be simple transition arrays | 42 // constant, and element changes. They can either be simple transition arrays |
| 43 // that store a single property transition, or a full transition array that has | 43 // that store a single property transition, or a full transition array that has |
| 44 // space for elements transitions, prototype transitions and multiple property | 44 // prototype transitions and multiple property transitons. The details related |
| 45 // transitons. The details related to property transitions are accessed in the | 45 // to property transitions are accessed in the descriptor array of the target |
| 46 // descriptor array of the target map. In the case of a simple transition, the | 46 // map. In the case of a simple transition, the key is also read from the |
| 47 // key is also read from the descriptor array of the target map. | 47 // descriptor array of the target map. |
| 48 // | 48 // |
| 49 // The simple format of the these objects is: | 49 // The simple format of the these objects is: |
| 50 // [0] Undefined or back pointer map | 50 // [0] Undefined or back pointer map |
| 51 // [1] Single transition | 51 // [1] Single transition |
| 52 // | 52 // |
| 53 // The full format is: | 53 // The full format is: |
| 54 // [0] Undefined or back pointer map | 54 // [0] Undefined or back pointer map |
| 55 // [1] Smi(0) or elements transition map | 55 // [1] Smi(0) or fixed array of prototype transitions |
| 56 // [2] Smi(0) or fixed array of prototype transitions | 56 // [2] First transition |
| 57 // [3] First transition | |
| 58 // [length() - kTransitionSize] Last transition | 57 // [length() - kTransitionSize] Last transition |
| 59 class TransitionArray: public FixedArray { | 58 class TransitionArray: public FixedArray { |
| 60 public: | 59 public: |
| 61 // Accessors for fetching instance transition at transition number. | 60 // Accessors for fetching instance transition at transition number. |
| 62 inline Name* GetKey(int transition_number); | 61 inline Name* GetKey(int transition_number); |
| 63 inline void SetKey(int transition_number, Name* value); | 62 inline void SetKey(int transition_number, Name* value); |
| 64 inline Object** GetKeySlot(int transition_number); | 63 inline Object** GetKeySlot(int transition_number); |
| 65 int GetSortedKeyIndex(int transition_number) { return transition_number; } | 64 int GetSortedKeyIndex(int transition_number) { return transition_number; } |
| 66 | 65 |
| 67 Name* GetSortedKey(int transition_number) { | 66 Name* GetSortedKey(int transition_number) { |
| 68 return GetKey(transition_number); | 67 return GetKey(transition_number); |
| 69 } | 68 } |
| 70 | 69 |
| 71 inline Map* GetTarget(int transition_number); | 70 inline Map* GetTarget(int transition_number); |
| 72 inline void SetTarget(int transition_number, Map* target); | 71 inline void SetTarget(int transition_number, Map* target); |
| 73 | 72 |
| 74 inline PropertyDetails GetTargetDetails(int transition_number); | 73 inline PropertyDetails GetTargetDetails(int transition_number); |
| 75 | 74 |
| 76 inline Map* elements_transition(); | |
| 77 inline void set_elements_transition( | |
| 78 Map* target, | |
| 79 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); | |
| 80 inline bool HasElementsTransition(); | 75 inline bool HasElementsTransition(); |
| 81 inline void ClearElementsTransition(); | |
| 82 | 76 |
| 83 inline Object* back_pointer_storage(); | 77 inline Object* back_pointer_storage(); |
| 84 inline void set_back_pointer_storage( | 78 inline void set_back_pointer_storage( |
| 85 Object* back_pointer, | 79 Object* back_pointer, |
| 86 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); | 80 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 87 | 81 |
| 88 inline FixedArray* GetPrototypeTransitions(); | 82 inline FixedArray* GetPrototypeTransitions(); |
| 89 inline void SetPrototypeTransitions( | 83 inline void SetPrototypeTransitions( |
| 90 FixedArray* prototype_transitions, | 84 FixedArray* prototype_transitions, |
| 91 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); | 85 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 120 inline void NoIncrementalWriteBarrierCopyFrom(TransitionArray* origin, | 114 inline void NoIncrementalWriteBarrierCopyFrom(TransitionArray* origin, |
| 121 int origin_transition, | 115 int origin_transition, |
| 122 int target_transition); | 116 int target_transition); |
| 123 | 117 |
| 124 // Search a transition for a given property name. | 118 // Search a transition for a given property name. |
| 125 inline int Search(Name* name); | 119 inline int Search(Name* name); |
| 126 | 120 |
| 127 // Allocates a TransitionArray. | 121 // Allocates a TransitionArray. |
| 128 MUST_USE_RESULT static MaybeObject* Allocate(int number_of_transitions); | 122 MUST_USE_RESULT static MaybeObject* Allocate(int number_of_transitions); |
| 129 | 123 |
| 130 bool IsSimpleTransition() { return length() == kSimpleTransitionSize; } | 124 bool IsSimpleTransition() { |
| 131 bool IsFullTransitionArray() { return length() >= kFirstIndex; } | 125 return length() == kSimpleTransitionSize && |
| 126 get(kSimpleTransitionTarget)->IsHeapObject() && | |
| 127 // The IntrusivePrototypeTransitionIterator may have set the map of the | |
| 128 // prototype transitions array to a smi. In that case, there are | |
| 129 // prototype transitions, hence this transition array is a full | |
| 130 // transition array. | |
| 131 (*HeapObject::RawField(HeapObject::cast(get(kSimpleTransitionTarget)), | |
|
titzer
2013/07/31 13:55:46
Any reason to use a RawField as opposed to the map
Toon Verwaest
2013/07/31 15:05:23
Done.
| |
| 132 HeapObject::kMapOffset))->IsMap() && | |
| 133 get(kSimpleTransitionTarget)->IsMap(); | |
| 134 } | |
| 135 | |
| 136 bool IsFullTransitionArray() { | |
| 137 return length() > kFirstIndex || | |
| 138 (length() == kFirstIndex && !IsSimpleTransition()); | |
| 139 } | |
| 132 | 140 |
| 133 // Casting. | 141 // Casting. |
| 134 static inline TransitionArray* cast(Object* obj); | 142 static inline TransitionArray* cast(Object* obj); |
| 135 | 143 |
| 136 // Constant for denoting key was not found. | 144 // Constant for denoting key was not found. |
| 137 static const int kNotFound = -1; | 145 static const int kNotFound = -1; |
| 138 | 146 |
| 139 static const int kBackPointerStorageIndex = 0; | 147 static const int kBackPointerStorageIndex = 0; |
| 140 | 148 |
| 141 // Layout for full transition arrays. | 149 // Layout for full transition arrays. |
| 142 static const int kElementsTransitionIndex = 1; | 150 static const int kPrototypeTransitionsIndex = 1; |
| 143 static const int kPrototypeTransitionsIndex = 2; | 151 static const int kFirstIndex = 2; |
| 144 static const int kFirstIndex = 3; | |
| 145 | 152 |
| 146 // Layout for simple transition arrays. | 153 // Layout for simple transition arrays. |
| 147 static const int kSimpleTransitionTarget = 1; | 154 static const int kSimpleTransitionTarget = 1; |
| 148 static const int kSimpleTransitionSize = 2; | 155 static const int kSimpleTransitionSize = 2; |
| 149 static const int kSimpleTransitionIndex = 0; | 156 static const int kSimpleTransitionIndex = 0; |
| 150 STATIC_ASSERT(kSimpleTransitionIndex != kNotFound); | 157 STATIC_ASSERT(kSimpleTransitionIndex != kNotFound); |
| 151 | 158 |
| 152 static const int kBackPointerStorageOffset = FixedArray::kHeaderSize; | 159 static const int kBackPointerStorageOffset = FixedArray::kHeaderSize; |
| 153 | 160 |
| 154 // Layout for the full transition array header. | 161 // Layout for the full transition array header. |
| 155 static const int kElementsTransitionOffset = kBackPointerStorageOffset + | 162 static const int kPrototypeTransitionsOffset = kBackPointerStorageOffset + |
| 156 kPointerSize; | |
| 157 static const int kPrototypeTransitionsOffset = kElementsTransitionOffset + | |
| 158 kPointerSize; | 163 kPointerSize; |
| 159 | 164 |
| 160 // Layout of map transition entries in full transition arrays. | 165 // Layout of map transition entries in full transition arrays. |
| 161 static const int kTransitionKey = 0; | 166 static const int kTransitionKey = 0; |
| 162 static const int kTransitionTarget = 1; | 167 static const int kTransitionTarget = 1; |
| 163 static const int kTransitionSize = 2; | 168 static const int kTransitionSize = 2; |
| 164 | 169 |
| 165 #ifdef OBJECT_PRINT | 170 #ifdef OBJECT_PRINT |
| 166 // Print all the transitions. | 171 // Print all the transitions. |
| 167 inline void PrintTransitions() { | 172 inline void PrintTransitions() { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 198 Name* key, | 203 Name* key, |
| 199 Map* target); | 204 Map* target); |
| 200 | 205 |
| 201 DISALLOW_IMPLICIT_CONSTRUCTORS(TransitionArray); | 206 DISALLOW_IMPLICIT_CONSTRUCTORS(TransitionArray); |
| 202 }; | 207 }; |
| 203 | 208 |
| 204 | 209 |
| 205 } } // namespace v8::internal | 210 } } // namespace v8::internal |
| 206 | 211 |
| 207 #endif // V8_TRANSITIONS_H_ | 212 #endif // V8_TRANSITIONS_H_ |
| OLD | NEW |