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 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
14 | 14 |
15 Handle<TransitionArray> TransitionArray::Allocate(Isolate* isolate, | 15 Handle<TransitionArray> TransitionArray::Allocate(Isolate* isolate, |
16 int number_of_transitions) { | 16 int number_of_transitions, |
17 Handle<FixedArray> array = | 17 int slack) { |
18 isolate->factory()->NewFixedArray(ToKeyIndex(number_of_transitions)); | 18 Handle<FixedArray> array = isolate->factory()->NewFixedArray( |
19 LengthFor(number_of_transitions + slack)); | |
19 array->set(kPrototypeTransitionsIndex, Smi::FromInt(0)); | 20 array->set(kPrototypeTransitionsIndex, Smi::FromInt(0)); |
21 array->set(kTransitionLengthIndex, Smi::FromInt(number_of_transitions)); | |
20 return Handle<TransitionArray>::cast(array); | 22 return Handle<TransitionArray>::cast(array); |
21 } | 23 } |
22 | 24 |
23 | 25 |
24 Handle<TransitionArray> TransitionArray::AllocateSimple(Isolate* isolate, | 26 Handle<TransitionArray> TransitionArray::AllocateSimple(Isolate* isolate, |
25 Handle<Map> target) { | 27 Handle<Map> target) { |
26 Handle<FixedArray> array = | 28 Handle<FixedArray> array = |
27 isolate->factory()->NewFixedArray(kSimpleTransitionSize); | 29 isolate->factory()->NewFixedArray(kSimpleTransitionSize); |
28 array->set(kSimpleTransitionTarget, *target); | 30 array->set(kSimpleTransitionTarget, *target); |
29 return Handle<TransitionArray>::cast(array); | 31 return Handle<TransitionArray>::cast(array); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 result->NoIncrementalWriteBarrierCopyFrom( | 80 result->NoIncrementalWriteBarrierCopyFrom( |
79 containing_map->transitions(), kSimpleTransitionIndex, 0); | 81 containing_map->transitions(), kSimpleTransitionIndex, 0); |
80 } | 82 } |
81 | 83 |
82 result->set_back_pointer_storage( | 84 result->set_back_pointer_storage( |
83 containing_map->transitions()->back_pointer_storage()); | 85 containing_map->transitions()->back_pointer_storage()); |
84 return result; | 86 return result; |
85 } | 87 } |
86 | 88 |
87 | 89 |
88 Handle<TransitionArray> TransitionArray::CopyInsert(Handle<Map> map, | 90 Handle<TransitionArray> TransitionArray::Insert(Handle<Map> map, |
89 Handle<Name> name, | 91 Handle<Name> name, |
90 Handle<Map> target, | 92 Handle<Map> target, |
91 SimpleTransitionFlag flag) { | 93 SimpleTransitionFlag flag) { |
92 if (!map->HasTransitionArray()) { | 94 if (!map->HasTransitionArray()) { |
93 return TransitionArray::NewWith(map, name, target, flag); | 95 return TransitionArray::NewWith(map, name, target, flag); |
94 } | 96 } |
95 | 97 |
96 int number_of_transitions = map->transitions()->number_of_transitions(); | 98 int number_of_transitions = map->transitions()->number_of_transitions(); |
97 int new_size = number_of_transitions; | 99 int new_nof = number_of_transitions; |
98 | 100 |
99 int insertion_index = map->transitions()->Search(*name); | 101 int insertion_index = map->transitions()->Search(*name); |
100 if (insertion_index == kNotFound) ++new_size; | 102 if (insertion_index == kNotFound) ++new_nof; |
101 | 103 |
102 Handle<TransitionArray> result = Allocate(map->GetIsolate(), new_size); | 104 if (new_nof <= map->transitions()->number_of_transitions_storage()) { |
105 DisallowHeapAllocation no_gc; | |
106 TransitionArray* array = map->transitions(); | |
107 | |
108 if (insertion_index != kNotFound) { | |
109 if (array->IsSimpleTransition()) { | |
110 DCHECK(insertion_index == kSimpleTransitionIndex); | |
111 array->set(kSimpleTransitionTarget, *target); | |
112 } else { | |
113 array->NoIncrementalWriteBarrierSet(insertion_index, *name, *target); | |
Toon Verwaest
2014/10/23 09:44:34
You can't omit the incremental write barrier if yo
mckev
2014/10/24 02:18:51
Ah.. SetTarget seems more appropriate then.
| |
114 } | |
115 return handle(array); | |
116 } | |
117 | |
118 array->SetNumberOfTransitions(new_nof); | |
119 uint32_t hash = name->Hash(); | |
120 for (insertion_index = number_of_transitions; insertion_index > 0; | |
121 --insertion_index) { | |
122 Name* key = array->GetKey(insertion_index - 1); | |
123 if (key->Hash() <= hash) break; | |
124 array->NoIncrementalWriteBarrierSet( | |
125 insertion_index, key, array->GetTarget(insertion_index - 1)); | |
Toon Verwaest
2014/10/23 09:44:33
Same here.
| |
126 } | |
127 array->NoIncrementalWriteBarrierSet(insertion_index, *name, *target); | |
Toon Verwaest
2014/10/23 09:44:33
Same here.
| |
128 return handle(array); | |
129 } | |
130 | |
131 Handle<TransitionArray> result = | |
132 Allocate(map->GetIsolate(), new_nof, | |
133 number_of_transitions < 4 ? 1 : number_of_transitions / 2); | |
Toon Verwaest
2014/10/23 09:44:33
Please add a helper function to calculate the actu
mckev
2014/10/24 02:18:51
Done.
| |
103 | 134 |
104 // The map's transition array may grown smaller during the allocation above as | 135 // The map's transition array may grown smaller during the allocation above as |
105 // it was weakly traversed, though it is guaranteed not to disappear. Trim the | 136 // it was weakly traversed, though it is guaranteed not to disappear. Trim the |
106 // result copy if needed, and recompute variables. | 137 // result copy if needed, and recompute variables. |
107 DCHECK(map->HasTransitionArray()); | 138 DCHECK(map->HasTransitionArray()); |
108 DisallowHeapAllocation no_gc; | 139 DisallowHeapAllocation no_gc; |
109 TransitionArray* array = map->transitions(); | 140 TransitionArray* array = map->transitions(); |
110 if (array->number_of_transitions() != number_of_transitions) { | 141 if (array->number_of_transitions() != number_of_transitions) { |
111 DCHECK(array->number_of_transitions() < number_of_transitions); | 142 DCHECK(array->number_of_transitions() < number_of_transitions); |
112 | 143 |
113 number_of_transitions = array->number_of_transitions(); | 144 number_of_transitions = array->number_of_transitions(); |
114 new_size = number_of_transitions; | 145 new_nof = number_of_transitions; |
115 | 146 |
116 insertion_index = array->Search(*name); | 147 insertion_index = array->Search(*name); |
117 if (insertion_index == kNotFound) ++new_size; | 148 if (insertion_index == kNotFound) ++new_nof; |
118 | 149 |
119 result->Shrink(ToKeyIndex(new_size)); | 150 result->Shrink(ToKeyIndex(new_nof)); |
120 } | 151 } |
121 | 152 |
122 if (array->HasPrototypeTransitions()) { | 153 if (array->HasPrototypeTransitions()) { |
123 result->SetPrototypeTransitions(array->GetPrototypeTransitions()); | 154 result->SetPrototypeTransitions(array->GetPrototypeTransitions()); |
124 } | 155 } |
125 | 156 |
126 if (insertion_index != kNotFound) { | |
127 for (int i = 0; i < number_of_transitions; ++i) { | |
128 if (i != insertion_index) { | |
129 result->NoIncrementalWriteBarrierCopyFrom(array, i, i); | |
130 } | |
131 } | |
132 result->NoIncrementalWriteBarrierSet(insertion_index, *name, *target); | |
133 result->set_back_pointer_storage(array->back_pointer_storage()); | |
134 return result; | |
135 } | |
136 | |
137 insertion_index = 0; | 157 insertion_index = 0; |
138 for (; insertion_index < number_of_transitions; ++insertion_index) { | 158 for (; insertion_index < number_of_transitions; ++insertion_index) { |
139 if (InsertionPointFound(array->GetKey(insertion_index), *name)) break; | 159 if (InsertionPointFound(array->GetKey(insertion_index), *name)) break; |
140 result->NoIncrementalWriteBarrierCopyFrom( | 160 result->NoIncrementalWriteBarrierCopyFrom( |
141 array, insertion_index, insertion_index); | 161 array, insertion_index, insertion_index); |
142 } | 162 } |
143 | 163 |
144 result->NoIncrementalWriteBarrierSet(insertion_index, *name, *target); | 164 result->NoIncrementalWriteBarrierSet(insertion_index, *name, *target); |
145 | 165 |
146 for (; insertion_index < number_of_transitions; ++insertion_index) { | 166 for (; insertion_index < number_of_transitions; ++insertion_index) { |
147 result->NoIncrementalWriteBarrierCopyFrom( | 167 result->NoIncrementalWriteBarrierCopyFrom( |
148 array, insertion_index, insertion_index + 1); | 168 array, insertion_index, insertion_index + 1); |
149 } | 169 } |
150 | 170 |
151 result->set_back_pointer_storage(array->back_pointer_storage()); | 171 result->set_back_pointer_storage(array->back_pointer_storage()); |
152 return result; | 172 return result; |
153 } | 173 } |
154 | 174 |
155 | 175 |
156 } } // namespace v8::internal | 176 } } // namespace v8::internal |
OLD | NEW |