OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 origin->GetKey(origin_transition), | 73 origin->GetKey(origin_transition), |
74 origin->GetTarget(origin_transition)); | 74 origin->GetTarget(origin_transition)); |
75 } | 75 } |
76 | 76 |
77 | 77 |
78 static bool InsertionPointFound(Name* key1, Name* key2) { | 78 static bool InsertionPointFound(Name* key1, Name* key2) { |
79 return key1->Hash() > key2->Hash(); | 79 return key1->Hash() > key2->Hash(); |
80 } | 80 } |
81 | 81 |
82 | 82 |
83 Handle<TransitionArray> TransitionArray::NewWith(SimpleTransitionFlag flag, | 83 Handle<TransitionArray> TransitionArray::NewWith(Handle<Map> map, |
84 Handle<Name> key, | 84 Handle<Name> name, |
85 Handle<Map> target, | 85 Handle<Map> target, |
86 Handle<Object> back_pointer) { | 86 SimpleTransitionFlag flag) { |
87 Handle<TransitionArray> result; | 87 Handle<TransitionArray> result; |
88 Factory* factory = key->GetIsolate()->factory(); | 88 Factory* factory = name->GetIsolate()->factory(); |
89 | 89 |
90 if (flag == SIMPLE_TRANSITION) { | 90 if (flag == SIMPLE_TRANSITION) { |
91 result = factory->NewSimpleTransitionArray(target); | 91 result = factory->NewSimpleTransitionArray(target); |
92 } else { | 92 } else { |
93 result = factory->NewTransitionArray(1); | 93 result = factory->NewTransitionArray(1); |
94 result->NoIncrementalWriteBarrierSet(0, *key, *target); | 94 result->NoIncrementalWriteBarrierSet(0, *name, *target); |
95 } | 95 } |
96 result->set_back_pointer_storage(*back_pointer); | 96 result->set_back_pointer_storage(map->GetBackPointer()); |
97 return result; | 97 return result; |
98 } | 98 } |
99 | 99 |
100 | 100 |
101 MaybeObject* TransitionArray::ExtendToFullTransitionArray() { | 101 MaybeObject* TransitionArray::ExtendToFullTransitionArray() { |
102 ASSERT(!IsFullTransitionArray()); | 102 ASSERT(!IsFullTransitionArray()); |
103 int nof = number_of_transitions(); | 103 int nof = number_of_transitions(); |
104 TransitionArray* result; | 104 TransitionArray* result; |
105 MaybeObject* maybe_result = Allocate(GetIsolate(), nof); | 105 MaybeObject* maybe_result = Allocate(GetIsolate(), nof); |
106 if (!maybe_result->To(&result)) return maybe_result; | 106 if (!maybe_result->To(&result)) return maybe_result; |
107 | 107 |
108 if (nof == 1) { | 108 if (nof == 1) { |
109 result->NoIncrementalWriteBarrierCopyFrom(this, kSimpleTransitionIndex, 0); | 109 result->NoIncrementalWriteBarrierCopyFrom(this, kSimpleTransitionIndex, 0); |
110 } | 110 } |
111 | 111 |
112 result->set_back_pointer_storage(back_pointer_storage()); | 112 result->set_back_pointer_storage(back_pointer_storage()); |
113 return result; | 113 return result; |
114 } | 114 } |
115 | 115 |
116 | 116 |
117 Handle<TransitionArray> TransitionArray::CopyInsert(Handle<Map> map, | 117 Handle<TransitionArray> TransitionArray::AddTransition( |
Toon Verwaest
2014/04/10 11:49:28
I actually prefer CopyInsert since that's what it
mvstanton
2014/04/10 13:10:45
Done.
| |
118 Handle<Name> name, | 118 Handle<Map> map, |
119 Handle<Map> target) { | 119 Handle<Name> name, |
120 ASSERT(map->HasTransitionArray()); | 120 Handle<Map> target, |
121 Handle<TransitionArray> result; | 121 SimpleTransitionFlag flag) { |
122 if (!map->HasTransitionArray()) { | |
123 return TransitionArray::NewWith(map, name, target, flag); | |
124 } | |
122 | 125 |
123 int number_of_transitions = map->transitions()->number_of_transitions(); | 126 int number_of_transitions = map->transitions()->number_of_transitions(); |
124 int new_size = number_of_transitions; | 127 int new_size = number_of_transitions; |
125 | 128 |
126 int insertion_index = map->transitions()->Search(*name); | 129 int insertion_index = map->transitions()->Search(*name); |
127 if (insertion_index == kNotFound) ++new_size; | 130 if (insertion_index == kNotFound) ++new_size; |
128 | 131 |
129 result = map->GetIsolate()->factory()->NewTransitionArray(new_size); | 132 Handle<TransitionArray> result = |
133 map->GetIsolate()->factory()->NewTransitionArray(new_size); | |
130 | 134 |
131 // The map's transition array may have grown smaller during the allocation | 135 // The map's transition array may have disappeared or grown smaller during |
132 // above as it was weakly traversed. Trim the result copy if needed, and | 136 // the allocation above as it was weakly traversed. Trim the result copy if |
133 // recompute variables. | 137 // needed, and recompute variables. |
134 DisallowHeapAllocation no_gc; | 138 DisallowHeapAllocation no_gc; |
139 if (!map->HasTransitionArray()) { | |
140 if (flag == SIMPLE_TRANSITION) { | |
141 ASSERT(result->length() >= kSimpleTransitionSize); | |
142 result->Shrink(kSimpleTransitionSize); | |
143 result->set(kSimpleTransitionTarget, *target); | |
144 } else { | |
145 ASSERT(result->length() >= ToKeyIndex(1)); | |
146 result->Shrink(ToKeyIndex(1)); | |
147 result->set(kPrototypeTransitionsIndex, Smi::FromInt(0)); | |
148 result->NoIncrementalWriteBarrierSet(0, *name, *target); | |
149 } | |
150 result->set_back_pointer_storage(map->GetBackPointer()); | |
151 | |
152 return result; | |
153 } | |
154 | |
135 TransitionArray* array = map->transitions(); | 155 TransitionArray* array = map->transitions(); |
136 if (array->number_of_transitions() != number_of_transitions) { | 156 if (array->number_of_transitions() != number_of_transitions) { |
137 ASSERT(array->number_of_transitions() < number_of_transitions); | 157 ASSERT(array->number_of_transitions() < number_of_transitions); |
138 | 158 |
139 number_of_transitions = array->number_of_transitions(); | 159 number_of_transitions = array->number_of_transitions(); |
140 new_size = number_of_transitions; | 160 new_size = number_of_transitions; |
141 | 161 |
142 insertion_index = array->Search(*name); | 162 insertion_index = array->Search(*name); |
143 if (insertion_index == kNotFound) ++new_size; | 163 if (insertion_index == kNotFound) ++new_size; |
144 | 164 |
(...skipping 28 matching lines...) Expand all Loading... | |
173 result->NoIncrementalWriteBarrierCopyFrom( | 193 result->NoIncrementalWriteBarrierCopyFrom( |
174 array, insertion_index, insertion_index + 1); | 194 array, insertion_index, insertion_index + 1); |
175 } | 195 } |
176 | 196 |
177 result->set_back_pointer_storage(array->back_pointer_storage()); | 197 result->set_back_pointer_storage(array->back_pointer_storage()); |
178 return result; | 198 return result; |
179 } | 199 } |
180 | 200 |
181 | 201 |
182 } } // namespace v8::internal | 202 } } // namespace v8::internal |
OLD | NEW |