Chromium Code Reviews| 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 26 matching lines...) Expand all Loading... | |
| 37 | 37 |
| 38 static MaybeObject* AllocateRaw(Isolate* isolate, int length) { | 38 static MaybeObject* AllocateRaw(Isolate* isolate, int length) { |
| 39 // Use FixedArray to not use TransitionArray::cast on incomplete object. | 39 // Use FixedArray to not use TransitionArray::cast on incomplete object. |
| 40 FixedArray* array; | 40 FixedArray* array; |
| 41 MaybeObject* maybe_array = isolate->heap()->AllocateFixedArray(length); | 41 MaybeObject* maybe_array = isolate->heap()->AllocateFixedArray(length); |
| 42 if (!maybe_array->To(&array)) return maybe_array; | 42 if (!maybe_array->To(&array)) return maybe_array; |
| 43 return array; | 43 return array; |
| 44 } | 44 } |
| 45 | 45 |
| 46 | 46 |
| 47 static Handle<TransitionArray> AllocateRawHandle(Isolate* isolate, int length) { | |
| 48 // Use FixedArray to not use TransitionArray::cast on incomplete object. | |
| 49 Handle<FixedArray> array = isolate->factory()->NewFixedArray(length); | |
| 50 return Handle<TransitionArray>::cast(array); | |
| 51 } | |
| 52 | |
| 53 | |
| 54 | |
| 47 MaybeObject* TransitionArray::Allocate(Isolate* isolate, | 55 MaybeObject* TransitionArray::Allocate(Isolate* isolate, |
| 48 int number_of_transitions) { | 56 int number_of_transitions) { |
| 49 FixedArray* array; | 57 FixedArray* array; |
| 50 MaybeObject* maybe_array = | 58 MaybeObject* maybe_array = |
| 51 AllocateRaw(isolate, ToKeyIndex(number_of_transitions)); | 59 AllocateRaw(isolate, ToKeyIndex(number_of_transitions)); |
| 52 if (!maybe_array->To(&array)) return maybe_array; | 60 if (!maybe_array->To(&array)) return maybe_array; |
| 53 array->set(kPrototypeTransitionsIndex, Smi::FromInt(0)); | 61 array->set(kPrototypeTransitionsIndex, Smi::FromInt(0)); |
| 54 return array; | 62 return array; |
| 55 } | 63 } |
| 56 | 64 |
| 57 | 65 |
| 58 void TransitionArray::NoIncrementalWriteBarrierCopyFrom(TransitionArray* origin, | 66 void TransitionArray::NoIncrementalWriteBarrierCopyFrom(TransitionArray* origin, |
| 59 int origin_transition, | 67 int origin_transition, |
| 60 int target_transition) { | 68 int target_transition) { |
| 61 NoIncrementalWriteBarrierSet(target_transition, | 69 NoIncrementalWriteBarrierSet(target_transition, |
| 62 origin->GetKey(origin_transition), | 70 origin->GetKey(origin_transition), |
| 63 origin->GetTarget(origin_transition)); | 71 origin->GetTarget(origin_transition)); |
| 64 } | 72 } |
| 65 | 73 |
| 66 | 74 |
| 67 static bool InsertionPointFound(Name* key1, Name* key2) { | 75 static bool InsertionPointFound(Name* key1, Name* key2) { |
| 68 return key1->Hash() > key2->Hash(); | 76 return key1->Hash() > key2->Hash(); |
| 69 } | 77 } |
| 70 | 78 |
| 71 | 79 |
| 80 Handle<TransitionArray> TransitionArray::NewWithHandle( | |
| 81 SimpleTransitionFlag flag, | |
| 82 Handle<Name> key, | |
| 83 Handle<Map> target, | |
| 84 Handle<Object> back_pointer) { | |
| 85 Handle<TransitionArray> result; | |
| 86 | |
| 87 if (flag == SIMPLE_TRANSITION) { | |
| 88 result = AllocateRawHandle(target->GetIsolate(), kSimpleTransitionSize); | |
| 89 result->set(kSimpleTransitionTarget, *target); | |
| 90 } else { | |
| 91 result = AllocateHandle(target->GetIsolate(), 1); | |
| 92 result->NoIncrementalWriteBarrierSet(0, *key, *target); | |
| 93 } | |
| 94 result->set_back_pointer_storage(*back_pointer); | |
| 95 return result; | |
| 96 } | |
| 97 | |
| 98 | |
| 72 MaybeObject* TransitionArray::NewWith(SimpleTransitionFlag flag, | 99 MaybeObject* TransitionArray::NewWith(SimpleTransitionFlag flag, |
| 73 Name* key, | 100 Name* key, |
| 74 Map* target, | 101 Map* target, |
| 75 Object* back_pointer) { | 102 Object* back_pointer) { |
| 76 TransitionArray* result; | 103 TransitionArray* result; |
| 77 MaybeObject* maybe_result; | 104 MaybeObject* maybe_result; |
| 78 | 105 |
| 79 if (flag == SIMPLE_TRANSITION) { | 106 if (flag == SIMPLE_TRANSITION) { |
| 80 maybe_result = AllocateRaw(target->GetIsolate(), kSimpleTransitionSize); | 107 maybe_result = AllocateRaw(target->GetIsolate(), kSimpleTransitionSize); |
| 81 if (!maybe_result->To(&result)) return maybe_result; | 108 if (!maybe_result->To(&result)) return maybe_result; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 99 | 126 |
| 100 if (nof == 1) { | 127 if (nof == 1) { |
| 101 result->NoIncrementalWriteBarrierCopyFrom(this, kSimpleTransitionIndex, 0); | 128 result->NoIncrementalWriteBarrierCopyFrom(this, kSimpleTransitionIndex, 0); |
| 102 } | 129 } |
| 103 | 130 |
| 104 result->set_back_pointer_storage(back_pointer_storage()); | 131 result->set_back_pointer_storage(back_pointer_storage()); |
| 105 return result; | 132 return result; |
| 106 } | 133 } |
| 107 | 134 |
| 108 | 135 |
| 136 Handle<TransitionArray> TransitionArray::AllocateHandle( | |
| 137 Isolate* isolate, int number_of_transitions) { | |
| 138 Handle<FixedArray> array = | |
| 139 isolate->factory()->NewFixedArray(ToKeyIndex(number_of_transitions)); | |
| 140 array->set(kPrototypeTransitionsIndex, Smi::FromInt(0)); | |
| 141 return Handle<TransitionArray>::cast(array); | |
| 142 } | |
| 143 | |
| 144 | |
| 109 MaybeObject* TransitionArray::CopyInsert(Name* name, Map* target) { | 145 MaybeObject* TransitionArray::CopyInsert(Name* name, Map* target) { |
| 110 TransitionArray* result; | 146 TransitionArray* result; |
| 111 | |
| 112 int number_of_transitions = this->number_of_transitions(); | 147 int number_of_transitions = this->number_of_transitions(); |
| 113 int new_size = number_of_transitions; | 148 int new_size = number_of_transitions; |
| 114 | |
| 115 int insertion_index = this->Search(name); | 149 int insertion_index = this->Search(name); |
| 116 if (insertion_index == kNotFound) ++new_size; | 150 if (insertion_index == kNotFound) ++new_size; |
| 117 | 151 |
| 118 MaybeObject* maybe_array; | 152 MaybeObject* maybe_array; |
| 119 maybe_array = TransitionArray::Allocate(GetIsolate(), new_size); | 153 maybe_array = TransitionArray::Allocate(GetIsolate(), new_size); |
| 120 if (!maybe_array->To(&result)) return maybe_array; | 154 if (!maybe_array->To(&result)) return maybe_array; |
| 121 | 155 |
| 122 if (HasPrototypeTransitions()) { | 156 if (HasPrototypeTransitions()) { |
| 123 result->SetPrototypeTransitions(GetPrototypeTransitions()); | 157 result->SetPrototypeTransitions(GetPrototypeTransitions()); |
| 124 } | 158 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 146 for (; insertion_index < number_of_transitions; ++insertion_index) { | 180 for (; insertion_index < number_of_transitions; ++insertion_index) { |
| 147 result->NoIncrementalWriteBarrierCopyFrom( | 181 result->NoIncrementalWriteBarrierCopyFrom( |
| 148 this, insertion_index, insertion_index + 1); | 182 this, insertion_index, insertion_index + 1); |
| 149 } | 183 } |
| 150 | 184 |
| 151 result->set_back_pointer_storage(back_pointer_storage()); | 185 result->set_back_pointer_storage(back_pointer_storage()); |
| 152 return result; | 186 return result; |
| 153 } | 187 } |
| 154 | 188 |
| 155 | 189 |
| 190 Handle<TransitionArray> TransitionArray::CopyInsert( | |
| 191 Handle<TransitionArray> array, | |
| 192 Handle<Name> name, | |
| 193 Handle<Map> target) { | |
| 194 Handle<TransitionArray> result; | |
| 195 | |
| 196 int number_of_transitions = array->number_of_transitions(); | |
| 197 int new_size = number_of_transitions; | |
| 198 | |
| 199 int insertion_index = array->Search(*name); | |
| 200 if (insertion_index == kNotFound) ++new_size; | |
| 201 | |
| 202 result = TransitionArray::AllocateHandle(array->GetIsolate(), new_size); | |
| 203 | |
| 204 if (array->HasPrototypeTransitions()) { | |
| 205 result->SetPrototypeTransitions(array->GetPrototypeTransitions()); | |
| 206 } | |
| 207 | |
| 208 if (insertion_index != kNotFound) { | |
| 209 for (int i = 0; i < number_of_transitions; ++i) { | |
|
Toon Verwaest
2014/04/08 12:58:55
Wrong. number_of_transitions can change because of
mvstanton
2014/04/09 09:43:20
Done.
| |
| 210 if (i != insertion_index) { | |
| 211 result->NoIncrementalWriteBarrierCopyFrom(*array, i, i); | |
| 212 } | |
| 213 } | |
| 214 result->NoIncrementalWriteBarrierSet(insertion_index, *name, *target); | |
| 215 result->set_back_pointer_storage(array->back_pointer_storage()); | |
| 216 return result; | |
| 217 } | |
| 218 | |
| 219 insertion_index = 0; | |
| 220 for (; insertion_index < number_of_transitions; ++insertion_index) { | |
| 221 if (InsertionPointFound(array->GetKey(insertion_index), *name)) break; | |
| 222 result->NoIncrementalWriteBarrierCopyFrom( | |
| 223 *array, insertion_index, insertion_index); | |
| 224 } | |
| 225 | |
| 226 result->NoIncrementalWriteBarrierSet(insertion_index, *name, *target); | |
| 227 | |
| 228 for (; insertion_index < number_of_transitions; ++insertion_index) { | |
| 229 result->NoIncrementalWriteBarrierCopyFrom( | |
| 230 *array, insertion_index, insertion_index + 1); | |
| 231 } | |
| 232 | |
| 233 result->set_back_pointer_storage(array->back_pointer_storage()); | |
| 234 return result; | |
| 235 } | |
| 236 | |
| 237 | |
| 156 } } // namespace v8::internal | 238 } } // namespace v8::internal |
| OLD | NEW |