OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/objects.h" | 7 #include "src/objects.h" |
8 #include "src/transitions-inl.h" | 8 #include "src/transitions-inl.h" |
9 #include "src/utils.h" | 9 #include "src/utils.h" |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 void TransitionArray::NoIncrementalWriteBarrierCopyFrom(TransitionArray* origin, | 35 void TransitionArray::NoIncrementalWriteBarrierCopyFrom(TransitionArray* origin, |
36 int origin_transition, | 36 int origin_transition, |
37 int target_transition) { | 37 int target_transition) { |
38 NoIncrementalWriteBarrierSet(target_transition, | 38 NoIncrementalWriteBarrierSet(target_transition, |
39 origin->GetKey(origin_transition), | 39 origin->GetKey(origin_transition), |
40 origin->GetTarget(origin_transition)); | 40 origin->GetTarget(origin_transition)); |
41 } | 41 } |
42 | 42 |
43 | 43 |
| 44 static bool InsertionPointFound(Name* key1, Name* key2) { |
| 45 return key1->Hash() > key2->Hash(); |
| 46 } |
| 47 |
| 48 |
44 Handle<TransitionArray> TransitionArray::NewWith(Handle<Map> map, | 49 Handle<TransitionArray> TransitionArray::NewWith(Handle<Map> map, |
45 Handle<Name> name, | 50 Handle<Name> name, |
46 Handle<Map> target, | 51 Handle<Map> target, |
47 SimpleTransitionFlag flag) { | 52 SimpleTransitionFlag flag) { |
48 Handle<TransitionArray> result; | 53 Handle<TransitionArray> result; |
49 Isolate* isolate = name->GetIsolate(); | 54 Isolate* isolate = name->GetIsolate(); |
50 | 55 |
51 if (flag == SIMPLE_TRANSITION) { | 56 if (flag == SIMPLE_TRANSITION) { |
52 result = AllocateSimple(isolate, target); | 57 result = AllocateSimple(isolate, target); |
53 } else { | 58 } else { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 Handle<Name> name, | 92 Handle<Name> name, |
88 Handle<Map> target, | 93 Handle<Map> target, |
89 SimpleTransitionFlag flag) { | 94 SimpleTransitionFlag flag) { |
90 if (!map->HasTransitionArray()) { | 95 if (!map->HasTransitionArray()) { |
91 return TransitionArray::NewWith(map, name, target, flag); | 96 return TransitionArray::NewWith(map, name, target, flag); |
92 } | 97 } |
93 | 98 |
94 int number_of_transitions = map->transitions()->number_of_transitions(); | 99 int number_of_transitions = map->transitions()->number_of_transitions(); |
95 int new_nof = number_of_transitions; | 100 int new_nof = number_of_transitions; |
96 | 101 |
97 int insertion_index = kNotFound; | 102 int insertion_index = map->transitions()->Search(*name); |
98 int index = map->transitions()->Search(*name, &insertion_index); | 103 if (insertion_index == kNotFound) ++new_nof; |
99 | |
100 if (index == kNotFound) { | |
101 ++new_nof; | |
102 } else { | |
103 insertion_index = index; | |
104 } | |
105 DCHECK(insertion_index >= 0 && insertion_index <= number_of_transitions); | |
106 | |
107 CHECK(new_nof <= kMaxNumberOfTransitions); | 104 CHECK(new_nof <= kMaxNumberOfTransitions); |
108 | 105 |
109 if (new_nof <= map->transitions()->number_of_transitions_storage()) { | 106 if (new_nof <= map->transitions()->number_of_transitions_storage()) { |
110 DisallowHeapAllocation no_gc; | 107 DisallowHeapAllocation no_gc; |
111 TransitionArray* array = map->transitions(); | 108 TransitionArray* array = map->transitions(); |
112 | 109 |
113 if (index != kNotFound) { | 110 if (insertion_index != kNotFound) { |
114 array->SetTarget(index, *target); | 111 array->SetTarget(insertion_index, *target); |
115 return handle(array); | 112 return handle(array); |
116 } | 113 } |
117 | 114 |
118 array->SetNumberOfTransitions(new_nof); | 115 array->SetNumberOfTransitions(new_nof); |
119 for (index = number_of_transitions; index > insertion_index; --index) { | 116 uint32_t hash = name->Hash(); |
120 Name* key = array->GetKey(index - 1); | 117 for (insertion_index = number_of_transitions; insertion_index > 0; |
121 DCHECK(key->Hash() > name->Hash()); | 118 --insertion_index) { |
122 array->SetKey(index, key); | 119 Name* key = array->GetKey(insertion_index - 1); |
123 array->SetTarget(index, array->GetTarget(index - 1)); | 120 if (key->Hash() <= hash) break; |
| 121 array->SetKey(insertion_index, key); |
| 122 array->SetTarget(insertion_index, array->GetTarget(insertion_index - 1)); |
124 } | 123 } |
125 array->SetKey(index, *name); | 124 array->SetKey(insertion_index, *name); |
126 array->SetTarget(index, *target); | 125 array->SetTarget(insertion_index, *target); |
127 return handle(array); | 126 return handle(array); |
128 } | 127 } |
129 | 128 |
130 Handle<TransitionArray> result = Allocate( | 129 Handle<TransitionArray> result = Allocate( |
131 map->GetIsolate(), new_nof, | 130 map->GetIsolate(), new_nof, |
132 Map::SlackForArraySize(number_of_transitions, kMaxNumberOfTransitions)); | 131 Map::SlackForArraySize(number_of_transitions, kMaxNumberOfTransitions)); |
133 | 132 |
134 // The map's transition array may grown smaller during the allocation above as | 133 // The map's transition array may grown smaller during the allocation above as |
135 // it was weakly traversed, though it is guaranteed not to disappear. Trim the | 134 // it was weakly traversed, though it is guaranteed not to disappear. Trim the |
136 // result copy if needed, and recompute variables. | 135 // result copy if needed, and recompute variables. |
137 DCHECK(map->HasTransitionArray()); | 136 DCHECK(map->HasTransitionArray()); |
138 DisallowHeapAllocation no_gc; | 137 DisallowHeapAllocation no_gc; |
139 TransitionArray* array = map->transitions(); | 138 TransitionArray* array = map->transitions(); |
140 if (array->number_of_transitions() != number_of_transitions) { | 139 if (array->number_of_transitions() != number_of_transitions) { |
141 DCHECK(array->number_of_transitions() < number_of_transitions); | 140 DCHECK(array->number_of_transitions() < number_of_transitions); |
142 | 141 |
143 number_of_transitions = array->number_of_transitions(); | 142 number_of_transitions = array->number_of_transitions(); |
144 new_nof = number_of_transitions; | 143 new_nof = number_of_transitions; |
145 | 144 |
146 insertion_index = kNotFound; | 145 insertion_index = array->Search(*name); |
147 index = array->Search(*name, &insertion_index); | 146 if (insertion_index == kNotFound) ++new_nof; |
148 if (index == kNotFound) { | |
149 ++new_nof; | |
150 } else { | |
151 insertion_index = index; | |
152 } | |
153 DCHECK(insertion_index >= 0 && insertion_index <= number_of_transitions); | |
154 | 147 |
155 result->Shrink(ToKeyIndex(new_nof)); | 148 result->Shrink(ToKeyIndex(new_nof)); |
156 result->SetNumberOfTransitions(new_nof); | 149 result->SetNumberOfTransitions(new_nof); |
157 } | 150 } |
158 | 151 |
159 if (array->HasPrototypeTransitions()) { | 152 if (array->HasPrototypeTransitions()) { |
160 result->SetPrototypeTransitions(array->GetPrototypeTransitions()); | 153 result->SetPrototypeTransitions(array->GetPrototypeTransitions()); |
161 } | 154 } |
162 | 155 |
163 DCHECK_NE(kNotFound, insertion_index); | 156 insertion_index = 0; |
164 for (int i = 0; i < insertion_index; ++i) { | 157 for (; insertion_index < number_of_transitions; ++insertion_index) { |
165 result->NoIncrementalWriteBarrierCopyFrom(array, i, i); | 158 if (InsertionPointFound(array->GetKey(insertion_index), *name)) break; |
| 159 result->NoIncrementalWriteBarrierCopyFrom( |
| 160 array, insertion_index, insertion_index); |
166 } | 161 } |
| 162 |
167 result->NoIncrementalWriteBarrierSet(insertion_index, *name, *target); | 163 result->NoIncrementalWriteBarrierSet(insertion_index, *name, *target); |
168 for (int i = insertion_index; i < number_of_transitions; ++i) { | 164 |
169 result->NoIncrementalWriteBarrierCopyFrom(array, i, i + 1); | 165 for (; insertion_index < number_of_transitions; ++insertion_index) { |
| 166 result->NoIncrementalWriteBarrierCopyFrom( |
| 167 array, insertion_index, insertion_index + 1); |
170 } | 168 } |
171 | 169 |
172 result->set_back_pointer_storage(array->back_pointer_storage()); | 170 result->set_back_pointer_storage(array->back_pointer_storage()); |
173 return result; | 171 return result; |
174 } | 172 } |
175 | 173 |
176 | 174 |
177 } } // namespace v8::internal | 175 } } // namespace v8::internal |
OLD | NEW |