OLD | NEW |
(Empty) | |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
| 28 #ifndef V8_TRANSITIONS_H_ |
| 29 #define V8_TRANSITIONS_H_ |
| 30 |
| 31 #include "elements-kind.h" |
| 32 #include "heap.h" |
| 33 #include "isolate.h" |
| 34 #include "objects.h" |
| 35 #include "v8checks.h" |
| 36 |
| 37 namespace v8 { |
| 38 namespace internal { |
| 39 |
| 40 |
| 41 // TransitionArrays are fixed arrays used to hold map transitions for property, |
| 42 // constant, and element changes. |
| 43 // The format of the these objects is: |
| 44 // [0] Elements transition |
| 45 // [1] First transition |
| 46 // [length() - 2] Last transition |
| 47 class TransitionArray: public FixedArray { |
| 48 public: |
| 49 inline Map* elements_transition(); |
| 50 inline void set_elements_transition( |
| 51 Map* value, |
| 52 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 53 inline void ClearElementsTransition(); |
| 54 inline bool HasElementsTransition(); |
| 55 // Accessors for fetching instance transition at transition number. |
| 56 inline String* GetKey(int transition_number); |
| 57 inline Object** GetKeySlot(int transition_number); |
| 58 inline void SetKeyUnchecked(Heap* heap, int transition_number, String* value); |
| 59 inline Object* GetValue(int transition_number); |
| 60 inline Object** GetValueSlot(int transition_number); |
| 61 inline void SetValueUnchecked(Heap* heap, |
| 62 int transition_number, |
| 63 Object* value); |
| 64 inline Map* GetTargetMap(int transition_number); |
| 65 inline PropertyDetails GetTargetDetails(int transition_number); |
| 66 inline Object** GetElementsSlot(); |
| 67 |
| 68 // Returns the number of transitions in the array. |
| 69 int number_of_transitions() { |
| 70 ASSERT(length() >= kFirstIndex); |
| 71 int len = length(); |
| 72 return len <= kFirstIndex ? 0 : (len - kFirstIndex) / kTransitionSize; |
| 73 } |
| 74 |
| 75 inline int number_of_entries() { return number_of_transitions(); } |
| 76 |
| 77 // Allocate a new transition array with a single entry. |
| 78 static MUST_USE_RESULT MaybeObject* NewWith(String* name, Object* map); |
| 79 |
| 80 // Copy the transition array, inserting a new transition. While adding, they |
| 81 // must not be removed. |
| 82 MUST_USE_RESULT MaybeObject* CopyInsert(String* name, Object* map); |
| 83 |
| 84 // Copy a single transition from the origin array. |
| 85 inline void CopyFrom(TransitionArray* origin, |
| 86 int origin_transition, |
| 87 int target_transition); |
| 88 |
| 89 // Search a transition for a given property name. |
| 90 inline int Search(String* name); |
| 91 |
| 92 // Allocates a TransitionArray. |
| 93 MUST_USE_RESULT static MaybeObject* Allocate(int number_of_transitions); |
| 94 |
| 95 // Casting. |
| 96 static inline TransitionArray* cast(Object* obj); |
| 97 |
| 98 // Constant for denoting key was not found. |
| 99 static const int kNotFound = -1; |
| 100 |
| 101 static const int kElementsTransitionIndex = 0; |
| 102 static const int kFirstIndex = 1; |
| 103 |
| 104 // Layout transition array header. |
| 105 static const int kElementsTransitionOffset = FixedArray::kHeaderSize; |
| 106 static const int kFirstOffset = kElementsTransitionOffset + kPointerSize; |
| 107 |
| 108 // Layout of map transition. |
| 109 static const int kTransitionKey = 0; |
| 110 static const int kTransitionValue = 1; |
| 111 static const int kTransitionSize = 2; |
| 112 |
| 113 #ifdef OBJECT_PRINT |
| 114 // Print all the transitions. |
| 115 inline void PrintTransitions() { |
| 116 PrintTransitions(stdout); |
| 117 } |
| 118 void PrintTransitions(FILE* out); |
| 119 #endif |
| 120 |
| 121 #ifdef DEBUG |
| 122 // Is the transition array sorted and without duplicates? |
| 123 bool IsSortedNoDuplicates(); |
| 124 |
| 125 // Is the transition array consistent with the back pointers in targets? |
| 126 bool IsConsistentWithBackPointers(Map* current_map); |
| 127 |
| 128 // Are two TransitionArrays equal? |
| 129 bool IsEqualTo(TransitionArray* other); |
| 130 #endif |
| 131 |
| 132 // The maximum number of transitions we want in a transition array (should |
| 133 // fit in a page). |
| 134 static const int kMaxNumberOfTransitions = 1024 + 512; |
| 135 |
| 136 private: |
| 137 // Conversion from transition number to array indices. |
| 138 static int ToKeyIndex(int transition_number) { |
| 139 return kFirstIndex + |
| 140 (transition_number * kTransitionSize) + |
| 141 kTransitionKey; |
| 142 } |
| 143 |
| 144 static int ToValueIndex(int transition_number) { |
| 145 return kFirstIndex + |
| 146 (transition_number * kTransitionSize) + |
| 147 kTransitionValue; |
| 148 } |
| 149 |
| 150 inline void Set(int transition_number, String* key, Object* value); |
| 151 |
| 152 // Swap operation on FixedArray without using write barriers. |
| 153 static inline void NoIncrementalWriteBarrierSwap( |
| 154 FixedArray* array, int first, int second); |
| 155 |
| 156 // Swap first and second transition. |
| 157 inline void NoIncrementalWriteBarrierSwapTransitions( |
| 158 int first, int second); |
| 159 |
| 160 DISALLOW_IMPLICIT_CONSTRUCTORS(TransitionArray); |
| 161 }; |
| 162 |
| 163 |
| 164 } } // namespace v8::internal |
| 165 |
| 166 #endif // V8_TRANSITIONS_H_ |
OLD | NEW |