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/transitions.h" | 5 #include "src/transitions.h" |
6 | 6 |
7 #include "src/objects-inl.h" | 7 #include "src/objects-inl.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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 old_details.attributes() == new_details.attributes()) { | 44 old_details.attributes() == new_details.attributes()) { |
45 Handle<WeakCell> cell = Map::WeakCellForMap(target); | 45 Handle<WeakCell> cell = Map::WeakCellForMap(target); |
46 ReplaceTransitions(map, *cell); | 46 ReplaceTransitions(map, *cell); |
47 return; | 47 return; |
48 } | 48 } |
49 // Otherwise allocate a full TransitionArray with slack for a new entry. | 49 // Otherwise allocate a full TransitionArray with slack for a new entry. |
50 Handle<TransitionArray> result = Allocate(isolate, 1, 1); | 50 Handle<TransitionArray> result = Allocate(isolate, 1, 1); |
51 // Re-read existing data; the allocation might have caused it to be cleared. | 51 // Re-read existing data; the allocation might have caused it to be cleared. |
52 if (IsSimpleTransition(map->raw_transitions())) { | 52 if (IsSimpleTransition(map->raw_transitions())) { |
53 old_target = GetSimpleTransition(map->raw_transitions()); | 53 old_target = GetSimpleTransition(map->raw_transitions()); |
54 result->NoIncrementalWriteBarrierSet( | 54 result->Set(0, GetSimpleTransitionKey(old_target), old_target); |
55 0, GetSimpleTransitionKey(old_target), old_target); | |
56 } else { | 55 } else { |
57 result->SetNumberOfTransitions(0); | 56 result->SetNumberOfTransitions(0); |
58 } | 57 } |
59 ReplaceTransitions(map, *result); | 58 ReplaceTransitions(map, *result); |
60 } | 59 } |
61 | 60 |
62 // At this point, we know that the map has a full TransitionArray. | 61 // At this point, we know that the map has a full TransitionArray. |
63 DCHECK(IsFullTransitionArray(map->raw_transitions())); | 62 DCHECK(IsFullTransitionArray(map->raw_transitions())); |
64 | 63 |
65 int number_of_transitions = 0; | 64 int number_of_transitions = 0; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 result->Shrink(ToKeyIndex(new_nof)); | 137 result->Shrink(ToKeyIndex(new_nof)); |
139 result->SetNumberOfTransitions(new_nof); | 138 result->SetNumberOfTransitions(new_nof); |
140 } | 139 } |
141 | 140 |
142 if (array->HasPrototypeTransitions()) { | 141 if (array->HasPrototypeTransitions()) { |
143 result->SetPrototypeTransitions(array->GetPrototypeTransitions()); | 142 result->SetPrototypeTransitions(array->GetPrototypeTransitions()); |
144 } | 143 } |
145 | 144 |
146 DCHECK_NE(kNotFound, insertion_index); | 145 DCHECK_NE(kNotFound, insertion_index); |
147 for (int i = 0; i < insertion_index; ++i) { | 146 for (int i = 0; i < insertion_index; ++i) { |
148 result->NoIncrementalWriteBarrierCopyFrom(array, i, i); | 147 result->Set(i, array->GetKey(i), array->GetTarget(i)); |
149 } | 148 } |
150 result->NoIncrementalWriteBarrierSet(insertion_index, *name, *target); | 149 result->Set(insertion_index, *name, *target); |
151 for (int i = insertion_index; i < number_of_transitions; ++i) { | 150 for (int i = insertion_index; i < number_of_transitions; ++i) { |
152 result->NoIncrementalWriteBarrierCopyFrom(array, i, i + 1); | 151 result->Set(i + 1, array->GetKey(i), array->GetTarget(i)); |
153 } | 152 } |
154 | 153 |
155 SLOW_DCHECK(result->IsSortedNoDuplicates()); | 154 SLOW_DCHECK(result->IsSortedNoDuplicates()); |
156 ReplaceTransitions(map, *result); | 155 ReplaceTransitions(map, *result); |
157 } | 156 } |
158 | 157 |
159 | 158 |
160 // static | 159 // static |
161 Map* TransitionArray::SearchTransition(Map* map, PropertyKind kind, Name* name, | 160 Map* TransitionArray::SearchTransition(Map* map, PropertyKind kind, Name* name, |
162 PropertyAttributes attributes) { | 161 PropertyAttributes attributes) { |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 int number_of_transitions, | 392 int number_of_transitions, |
394 int slack) { | 393 int slack) { |
395 Handle<FixedArray> array = isolate->factory()->NewFixedArray( | 394 Handle<FixedArray> array = isolate->factory()->NewFixedArray( |
396 LengthFor(number_of_transitions + slack)); | 395 LengthFor(number_of_transitions + slack)); |
397 array->set(kPrototypeTransitionsIndex, Smi::FromInt(0)); | 396 array->set(kPrototypeTransitionsIndex, Smi::FromInt(0)); |
398 array->set(kTransitionLengthIndex, Smi::FromInt(number_of_transitions)); | 397 array->set(kTransitionLengthIndex, Smi::FromInt(number_of_transitions)); |
399 return Handle<TransitionArray>::cast(array); | 398 return Handle<TransitionArray>::cast(array); |
400 } | 399 } |
401 | 400 |
402 | 401 |
403 void TransitionArray::NoIncrementalWriteBarrierCopyFrom(TransitionArray* origin, | |
404 int origin_transition, | |
405 int target_transition) { | |
406 NoIncrementalWriteBarrierSet(target_transition, | |
407 origin->GetKey(origin_transition), | |
408 origin->GetTarget(origin_transition)); | |
409 } | |
410 | |
411 | |
412 static void ZapTransitionArray(TransitionArray* transitions) { | 402 static void ZapTransitionArray(TransitionArray* transitions) { |
413 MemsetPointer(transitions->data_start(), | 403 MemsetPointer(transitions->data_start(), |
414 transitions->GetHeap()->the_hole_value(), | 404 transitions->GetHeap()->the_hole_value(), |
415 transitions->length()); | 405 transitions->length()); |
416 } | 406 } |
417 | 407 |
418 | 408 |
419 void TransitionArray::ReplaceTransitions(Handle<Map> map, | 409 void TransitionArray::ReplaceTransitions(Handle<Map> map, |
420 Object* new_transitions) { | 410 Object* new_transitions) { |
421 Object* raw_transitions = map->raw_transitions(); | 411 Object* raw_transitions = map->raw_transitions(); |
(...skipping 30 matching lines...) Expand all Loading... |
452 // Reload pointer after the allocation that just happened. | 442 // Reload pointer after the allocation that just happened. |
453 raw_transitions = map->raw_transitions(); | 443 raw_transitions = map->raw_transitions(); |
454 int new_nof = IsSimpleTransition(raw_transitions) ? 1 : 0; | 444 int new_nof = IsSimpleTransition(raw_transitions) ? 1 : 0; |
455 if (new_nof != nof) { | 445 if (new_nof != nof) { |
456 DCHECK(new_nof == 0); | 446 DCHECK(new_nof == 0); |
457 result->Shrink(ToKeyIndex(0)); | 447 result->Shrink(ToKeyIndex(0)); |
458 result->SetNumberOfTransitions(0); | 448 result->SetNumberOfTransitions(0); |
459 } else if (nof == 1) { | 449 } else if (nof == 1) { |
460 Map* target = GetSimpleTransition(raw_transitions); | 450 Map* target = GetSimpleTransition(raw_transitions); |
461 Name* key = GetSimpleTransitionKey(target); | 451 Name* key = GetSimpleTransitionKey(target); |
462 result->NoIncrementalWriteBarrierSet(0, key, target); | 452 result->Set(0, key, target); |
463 } | 453 } |
464 ReplaceTransitions(map, *result); | 454 ReplaceTransitions(map, *result); |
465 } | 455 } |
466 | 456 |
467 | 457 |
468 void TransitionArray::TraverseTransitionTreeInternal(Map* map, | 458 void TransitionArray::TraverseTransitionTreeInternal(Map* map, |
469 TraverseCallback callback, | 459 TraverseCallback callback, |
470 void* data) { | 460 void* data) { |
471 Object* raw_transitions = map->raw_transitions(); | 461 Object* raw_transitions = map->raw_transitions(); |
472 if (IsFullTransitionArray(raw_transitions)) { | 462 if (IsFullTransitionArray(raw_transitions)) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 PropertyAttributes attributes, | 540 PropertyAttributes attributes, |
551 int* out_insertion_index) { | 541 int* out_insertion_index) { |
552 int transition = SearchName(name, out_insertion_index); | 542 int transition = SearchName(name, out_insertion_index); |
553 if (transition == kNotFound) { | 543 if (transition == kNotFound) { |
554 return kNotFound; | 544 return kNotFound; |
555 } | 545 } |
556 return SearchDetails(transition, kind, attributes, out_insertion_index); | 546 return SearchDetails(transition, kind, attributes, out_insertion_index); |
557 } | 547 } |
558 } // namespace internal | 548 } // namespace internal |
559 } // namespace v8 | 549 } // namespace v8 |
OLD | NEW |