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 | |
49 Handle<TransitionArray> TransitionArray::NewWith(Handle<Map> map, | 44 Handle<TransitionArray> TransitionArray::NewWith(Handle<Map> map, |
50 Handle<Name> name, | 45 Handle<Name> name, |
51 Handle<Map> target, | 46 Handle<Map> target, |
52 SimpleTransitionFlag flag) { | 47 SimpleTransitionFlag flag) { |
53 Handle<TransitionArray> result; | 48 Handle<TransitionArray> result; |
54 Isolate* isolate = name->GetIsolate(); | 49 Isolate* isolate = name->GetIsolate(); |
55 | 50 |
56 if (flag == SIMPLE_TRANSITION) { | 51 if (flag == SIMPLE_TRANSITION) { |
57 result = AllocateSimple(isolate, target); | 52 result = AllocateSimple(isolate, target); |
58 } else { | 53 } else { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 Handle<Name> name, | 87 Handle<Name> name, |
93 Handle<Map> target, | 88 Handle<Map> target, |
94 SimpleTransitionFlag flag) { | 89 SimpleTransitionFlag flag) { |
95 if (!map->HasTransitionArray()) { | 90 if (!map->HasTransitionArray()) { |
96 return TransitionArray::NewWith(map, name, target, flag); | 91 return TransitionArray::NewWith(map, name, target, flag); |
97 } | 92 } |
98 | 93 |
99 int number_of_transitions = map->transitions()->number_of_transitions(); | 94 int number_of_transitions = map->transitions()->number_of_transitions(); |
100 int new_nof = number_of_transitions; | 95 int new_nof = number_of_transitions; |
101 | 96 |
102 int insertion_index = map->transitions()->Search(*name); | 97 int insertion_index = kNotFound; |
103 if (insertion_index == kNotFound) ++new_nof; | 98 int index = map->transitions()->Search(*name, &insertion_index); |
| 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 |
104 CHECK(new_nof <= kMaxNumberOfTransitions); | 107 CHECK(new_nof <= kMaxNumberOfTransitions); |
105 | 108 |
106 if (new_nof <= map->transitions()->number_of_transitions_storage()) { | 109 if (new_nof <= map->transitions()->number_of_transitions_storage()) { |
107 DisallowHeapAllocation no_gc; | 110 DisallowHeapAllocation no_gc; |
108 TransitionArray* array = map->transitions(); | 111 TransitionArray* array = map->transitions(); |
109 | 112 |
110 if (insertion_index != kNotFound) { | 113 if (index != kNotFound) { |
111 array->SetTarget(insertion_index, *target); | 114 array->SetTarget(index, *target); |
112 return handle(array); | 115 return handle(array); |
113 } | 116 } |
114 | 117 |
115 array->SetNumberOfTransitions(new_nof); | 118 array->SetNumberOfTransitions(new_nof); |
116 uint32_t hash = name->Hash(); | 119 for (index = number_of_transitions; index > insertion_index; --index) { |
117 for (insertion_index = number_of_transitions; insertion_index > 0; | 120 Name* key = array->GetKey(index - 1); |
118 --insertion_index) { | 121 DCHECK(key->Hash() > name->Hash()); |
119 Name* key = array->GetKey(insertion_index - 1); | 122 array->SetKey(index, key); |
120 if (key->Hash() <= hash) break; | 123 array->SetTarget(index, array->GetTarget(index - 1)); |
121 array->SetKey(insertion_index, key); | |
122 array->SetTarget(insertion_index, array->GetTarget(insertion_index - 1)); | |
123 } | 124 } |
124 array->SetKey(insertion_index, *name); | 125 array->SetKey(index, *name); |
125 array->SetTarget(insertion_index, *target); | 126 array->SetTarget(index, *target); |
126 return handle(array); | 127 return handle(array); |
127 } | 128 } |
128 | 129 |
129 Handle<TransitionArray> result = Allocate( | 130 Handle<TransitionArray> result = Allocate( |
130 map->GetIsolate(), new_nof, | 131 map->GetIsolate(), new_nof, |
131 Map::SlackForArraySize(number_of_transitions, kMaxNumberOfTransitions)); | 132 Map::SlackForArraySize(number_of_transitions, kMaxNumberOfTransitions)); |
132 | 133 |
133 // The map's transition array may grown smaller during the allocation above as | 134 // The map's transition array may grown smaller during the allocation above as |
134 // it was weakly traversed, though it is guaranteed not to disappear. Trim the | 135 // it was weakly traversed, though it is guaranteed not to disappear. Trim the |
135 // result copy if needed, and recompute variables. | 136 // result copy if needed, and recompute variables. |
136 DCHECK(map->HasTransitionArray()); | 137 DCHECK(map->HasTransitionArray()); |
137 DisallowHeapAllocation no_gc; | 138 DisallowHeapAllocation no_gc; |
138 TransitionArray* array = map->transitions(); | 139 TransitionArray* array = map->transitions(); |
139 if (array->number_of_transitions() != number_of_transitions) { | 140 if (array->number_of_transitions() != number_of_transitions) { |
140 DCHECK(array->number_of_transitions() < number_of_transitions); | 141 DCHECK(array->number_of_transitions() < number_of_transitions); |
141 | 142 |
142 number_of_transitions = array->number_of_transitions(); | 143 number_of_transitions = array->number_of_transitions(); |
143 new_nof = number_of_transitions; | 144 new_nof = number_of_transitions; |
144 | 145 |
145 insertion_index = array->Search(*name); | 146 insertion_index = kNotFound; |
146 if (insertion_index == kNotFound) ++new_nof; | 147 index = array->Search(*name, &insertion_index); |
| 148 if (index == kNotFound) { |
| 149 ++new_nof; |
| 150 } else { |
| 151 insertion_index = index; |
| 152 } |
| 153 DCHECK(insertion_index >= 0 && insertion_index <= number_of_transitions); |
147 | 154 |
148 result->Shrink(ToKeyIndex(new_nof)); | 155 result->Shrink(ToKeyIndex(new_nof)); |
149 result->SetNumberOfTransitions(new_nof); | 156 result->SetNumberOfTransitions(new_nof); |
150 } | 157 } |
151 | 158 |
152 if (array->HasPrototypeTransitions()) { | 159 if (array->HasPrototypeTransitions()) { |
153 result->SetPrototypeTransitions(array->GetPrototypeTransitions()); | 160 result->SetPrototypeTransitions(array->GetPrototypeTransitions()); |
154 } | 161 } |
155 | 162 |
156 insertion_index = 0; | 163 DCHECK_NE(kNotFound, insertion_index); |
157 for (; insertion_index < number_of_transitions; ++insertion_index) { | 164 for (int i = 0; i < insertion_index; ++i) { |
158 if (InsertionPointFound(array->GetKey(insertion_index), *name)) break; | 165 result->NoIncrementalWriteBarrierCopyFrom(array, i, i); |
159 result->NoIncrementalWriteBarrierCopyFrom( | |
160 array, insertion_index, insertion_index); | |
161 } | 166 } |
162 | |
163 result->NoIncrementalWriteBarrierSet(insertion_index, *name, *target); | 167 result->NoIncrementalWriteBarrierSet(insertion_index, *name, *target); |
164 | 168 for (int i = insertion_index; i < number_of_transitions; ++i) { |
165 for (; insertion_index < number_of_transitions; ++insertion_index) { | 169 result->NoIncrementalWriteBarrierCopyFrom(array, i, i + 1); |
166 result->NoIncrementalWriteBarrierCopyFrom( | |
167 array, insertion_index, insertion_index + 1); | |
168 } | 170 } |
169 | 171 |
170 result->set_back_pointer_storage(array->back_pointer_storage()); | 172 result->set_back_pointer_storage(array->back_pointer_storage()); |
171 return result; | 173 return result; |
172 } | 174 } |
173 | 175 |
174 | 176 |
175 } } // namespace v8::internal | 177 } } // namespace v8::internal |
OLD | NEW |