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() - 1] 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 SetKey(int transition_number, String* value); |
| 59 inline Object* GetValue(int transition_number); |
| 60 inline Object** GetValueSlot(int transition_number); |
| 61 inline void SetValue(int transition_number, Object* value); |
| 62 inline Map* GetTargetMap(int transition_number); |
| 63 inline PropertyDetails GetTargetDetails(int transition_number); |
| 64 inline Object** GetElementsSlot(); |
| 65 |
| 66 // Returns the number of transitions in the array. |
| 67 int number_of_transitions() { |
| 68 ASSERT(length() >= kFirstIndex); |
| 69 int len = length(); |
| 70 return len <= kFirstIndex ? 0 : (len - kFirstIndex) / kTransitionSize; |
| 71 } |
| 72 |
| 73 inline int number_of_entries() { return number_of_transitions(); } |
| 74 |
| 75 // Allocate a new transition array with a single entry. |
| 76 static MUST_USE_RESULT MaybeObject* NewWith(String* name, Object* map); |
| 77 |
| 78 // Copy the transition array, inserting a new transition. |
| 79 // TODO(verwaest): This should not cause an existing transition to be |
| 80 // overwritten. |
| 81 MUST_USE_RESULT MaybeObject* CopyInsert(String* name, Object* map); |
| 82 |
| 83 // Copy a single transition from the origin array. |
| 84 inline void CopyFrom(TransitionArray* origin, |
| 85 int origin_transition, |
| 86 int target_transition, |
| 87 const WhitenessWitness& witness); |
| 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 bool IsSortedNoDuplicates(); |
| 123 bool IsConsistentWithBackPointers(Map* current_map); |
| 124 bool IsEqualTo(TransitionArray* other); |
| 125 #endif |
| 126 |
| 127 // The maximum number of transitions we want in a transition array (should |
| 128 // fit in a page). |
| 129 static const int kMaxNumberOfTransitions = 1024 + 512; |
| 130 |
| 131 private: |
| 132 // Conversion from transition number to array indices. |
| 133 static int ToKeyIndex(int transition_number) { |
| 134 return kFirstIndex + |
| 135 (transition_number * kTransitionSize) + |
| 136 kTransitionKey; |
| 137 } |
| 138 |
| 139 static int ToValueIndex(int transition_number) { |
| 140 return kFirstIndex + |
| 141 (transition_number * kTransitionSize) + |
| 142 kTransitionValue; |
| 143 } |
| 144 |
| 145 inline void Set(int transition_number, |
| 146 String* key, |
| 147 Object* value, |
| 148 const WhitenessWitness&); |
| 149 |
| 150 DISALLOW_IMPLICIT_CONSTRUCTORS(TransitionArray); |
| 151 }; |
| 152 |
| 153 |
| 154 } } // namespace v8::internal |
| 155 |
| 156 #endif // V8_TRANSITIONS_H_ |
OLD | NEW |