Chromium Code Reviews| 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 | |
|
Jakob Kummerow
2012/06/29 16:31:36
Is that "length() - 2" because kTransitionSize ==
Toon Verwaest
2012/07/05 12:56:11
No, the comment was out of date. It's length() - 1
| |
| 47 class TransitionArray: public FixedArray { | |
| 48 public: | |
| 49 inline Map* elements(); | |
|
Michael Starzinger
2012/06/28 16:02:12
Can we call this elements_transition instead?
Toon Verwaest
2012/06/29 08:14:55
Done.
| |
| 50 inline void set_elements( | |
| 51 Map* value, | |
| 52 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); | |
| 53 inline void ClearElements(); | |
| 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); | |
|
Jakob Kummerow
2012/06/29 16:31:36
Set{Key,Value}Unchecked() -- what do we need these
Toon Verwaest
2012/07/05 12:56:11
Done.
| |
| 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 bool TransitionsTo(Object* target); | |
| 68 | |
| 69 // Returns the number of transitions in the array. | |
| 70 int number_of_transitions() { | |
| 71 ASSERT(length() >= kFirstIndex); | |
| 72 int len = length(); | |
| 73 return len <= kFirstIndex ? 0 : (len - kFirstIndex) / kTransitionSize; | |
| 74 } | |
| 75 | |
| 76 inline int number_of_entries() { return number_of_transitions(); } | |
| 77 | |
| 78 // Copy the transition array, inserting a new transition. While adding, they | |
|
Jakob Kummerow
2012/06/29 16:31:36
who's "they"?
Toon Verwaest
2012/07/05 12:56:11
Done.
| |
| 79 // must not be removed. All null transitions are removed. | |
| 80 MUST_USE_RESULT MaybeObject* CopyInsert(String* name, Object* map); | |
| 81 | |
| 82 // Copy a single transition from the origin array. | |
| 83 inline void CopyFrom(TransitionArray* origin, | |
| 84 int origin_transition, | |
| 85 int target_transition); | |
| 86 | |
| 87 // Search a transition for a given property name. | |
| 88 inline int Search(String* name); | |
| 89 | |
| 90 // Allocates a TransitionArray. | |
| 91 MUST_USE_RESULT static MaybeObject* Allocate(int number_of_transitions); | |
| 92 | |
| 93 // Casting. | |
| 94 static inline TransitionArray* cast(Object* obj); | |
| 95 | |
| 96 // Constant for denoting key was not found. | |
| 97 static const int kNotFound = -1; | |
| 98 | |
| 99 static const int kElementsTransitionIndex = 0; | |
| 100 static const int kFirstIndex = 1; | |
| 101 | |
| 102 // Layout transition array header. | |
| 103 static const int kElementsTransitionOffset = FixedArray::kHeaderSize; | |
| 104 static const int kFirstOffset = kElementsTransitionOffset + kPointerSize; | |
| 105 | |
| 106 // Layout of map transition. | |
| 107 static const int kTransitionKey = 0; | |
| 108 static const int kTransitionValue = 1; | |
| 109 static const int kTransitionSize = 2; | |
| 110 | |
| 111 #ifdef OBJECT_PRINT | |
| 112 // Print all the transitions. | |
| 113 inline void PrintTransitions() { | |
| 114 PrintTransitions(stdout); | |
| 115 } | |
| 116 void PrintTransitions(FILE* out); | |
| 117 #endif | |
| 118 | |
| 119 #ifdef DEBUG | |
| 120 // Is the transition array sorted and without duplicates? | |
|
Jakob Kummerow
2012/06/29 16:31:36
nit: this comment is kinda unnecessary, as it does
Toon Verwaest
2012/07/05 12:56:11
Done.
| |
| 121 bool IsSortedNoDuplicates(); | |
| 122 | |
| 123 // Is the transition array consistent with the back pointers in targets? | |
| 124 bool IsConsistentWithBackPointers(Map* current_map); | |
| 125 | |
| 126 // Are two TransitionArrays equal? | |
| 127 bool IsEqualTo(TransitionArray* other); | |
| 128 #endif | |
| 129 | |
| 130 // The maximum number of transitions we want in a transition array (should | |
| 131 // fit in a page). | |
| 132 static const int kMaxNumberOfTransitions = 1024 + 512; | |
| 133 | |
| 134 private: | |
| 135 // Conversion from transition number to array indices. | |
| 136 static int ToKeyIndex(int transition_number) { | |
| 137 return kFirstIndex + | |
| 138 (transition_number * kTransitionSize) + | |
| 139 kTransitionKey; | |
| 140 } | |
| 141 | |
| 142 static int ToValueIndex(int transition_number) { | |
| 143 return kFirstIndex + | |
| 144 (transition_number * kTransitionSize) + | |
| 145 kTransitionValue; | |
| 146 } | |
| 147 | |
| 148 inline void Set(int transition_number, String* key, Object* value); | |
| 149 | |
| 150 // Swap operation on FixedArray without using write barriers. | |
| 151 static inline void NoIncrementalWriteBarrierSwap( | |
|
Jakob Kummerow
2012/06/29 16:31:36
I don't see where this is used. If the intention w
Toon Verwaest
2012/07/05 12:56:11
Done.
| |
| 152 FixedArray* array, int first, int second); | |
| 153 | |
| 154 // Swap first and second transition. | |
| 155 inline void NoIncrementalWriteBarrierSwapTransitions( | |
|
Jakob Kummerow
2012/06/29 16:31:36
I don't see where this is used.
Toon Verwaest
2012/07/05 12:56:11
Done.
| |
| 156 int first, int second); | |
| 157 | |
| 158 DISALLOW_IMPLICIT_CONSTRUCTORS(TransitionArray); | |
| 159 }; | |
| 160 | |
| 161 | |
| 162 } } // namespace v8::internal | |
| 163 | |
| 164 #endif // V8_TRANSITIONS_H_ | |
| OLD | NEW |