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 3542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3553 | 3553 |
3554 | 3554 |
3555 DescriptorArray* Map::instance_descriptors() { | 3555 DescriptorArray* Map::instance_descriptors() { |
3556 if (HasTransitionArray()) return transitions()->descriptors(); | 3556 if (HasTransitionArray()) return transitions()->descriptors(); |
3557 Object* back_pointer = GetBackPointer(); | 3557 Object* back_pointer = GetBackPointer(); |
3558 if (!back_pointer->IsMap()) return GetHeap()->empty_descriptor_array(); | 3558 if (!back_pointer->IsMap()) return GetHeap()->empty_descriptor_array(); |
3559 return Map::cast(back_pointer)->instance_descriptors(); | 3559 return Map::cast(back_pointer)->instance_descriptors(); |
3560 } | 3560 } |
3561 | 3561 |
3562 | 3562 |
| 3563 enum TransitionsKind { DESCRIPTORS_HOLDER, FULL_TRANSITION_ARRAY }; |
| 3564 |
| 3565 |
3563 // If the descriptor is using the empty transition array, install a new empty | 3566 // If the descriptor is using the empty transition array, install a new empty |
3564 // transition array that will have place for an element transition. | 3567 // transition array that will have place for an element transition. |
3565 static MaybeObject* EnsureHasTransitionArray(Map* map) { | 3568 static MaybeObject* EnsureHasTransitionArray(Map* map, TransitionsKind kind) { |
3566 if (map->HasTransitionArray()) return map; | |
3567 | |
3568 TransitionArray* transitions; | 3569 TransitionArray* transitions; |
3569 JSGlobalPropertyCell* pointer = map->RetrieveDescriptorsPointer(); | 3570 MaybeObject* maybe_transitions; |
3570 MaybeObject* maybe_transitions = TransitionArray::Allocate(0, pointer); | 3571 if (map->HasTransitionArray()) { |
3571 if (!maybe_transitions->To(&transitions)) return maybe_transitions; | 3572 if (kind != FULL_TRANSITION_ARRAY || |
3572 | 3573 map->transitions()->IsFullTransitionArray()) { |
3573 transitions->set_back_pointer_storage(map->GetBackPointer()); | 3574 return map; |
| 3575 } |
| 3576 maybe_transitions = map->transitions()->ExtendToFullTransitionArray(); |
| 3577 if (!maybe_transitions->To(&transitions)) return maybe_transitions; |
| 3578 } else { |
| 3579 JSGlobalPropertyCell* pointer = map->RetrieveDescriptorsPointer(); |
| 3580 if (kind == FULL_TRANSITION_ARRAY) { |
| 3581 maybe_transitions = TransitionArray::Allocate(0, pointer); |
| 3582 } else { |
| 3583 maybe_transitions = TransitionArray::AllocateDescriptorsHolder(pointer); |
| 3584 } |
| 3585 if (!maybe_transitions->To(&transitions)) return maybe_transitions; |
| 3586 transitions->set_back_pointer_storage(map->GetBackPointer()); |
| 3587 } |
3574 map->set_transitions(transitions); | 3588 map->set_transitions(transitions); |
3575 return transitions; | 3589 return transitions; |
3576 } | 3590 } |
3577 | 3591 |
3578 | 3592 |
3579 MaybeObject* Map::SetDescriptors(DescriptorArray* value) { | 3593 MaybeObject* Map::SetDescriptors(DescriptorArray* value) { |
3580 ASSERT(!is_shared()); | 3594 ASSERT(!is_shared()); |
3581 MaybeObject* maybe_failure = EnsureHasTransitionArray(this); | 3595 MaybeObject* maybe_failure = |
| 3596 EnsureHasTransitionArray(this, DESCRIPTORS_HOLDER); |
3582 if (maybe_failure->IsFailure()) return maybe_failure; | 3597 if (maybe_failure->IsFailure()) return maybe_failure; |
3583 | 3598 |
3584 ASSERT(NumberOfOwnDescriptors() <= value->number_of_descriptors()); | 3599 ASSERT(NumberOfOwnDescriptors() <= value->number_of_descriptors()); |
3585 transitions()->set_descriptors(value); | 3600 transitions()->set_descriptors(value); |
3586 return this; | 3601 return this; |
3587 } | 3602 } |
3588 | 3603 |
3589 | 3604 |
3590 MaybeObject* Map::InitializeDescriptors(DescriptorArray* descriptors) { | 3605 MaybeObject* Map::InitializeDescriptors(DescriptorArray* descriptors) { |
3591 int len = descriptors->number_of_descriptors(); | 3606 int len = descriptors->number_of_descriptors(); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3681 JSGlobalPropertyCell* Map::RetrieveDescriptorsPointer() { | 3696 JSGlobalPropertyCell* Map::RetrieveDescriptorsPointer() { |
3682 if (!owns_descriptors()) return NULL; | 3697 if (!owns_descriptors()) return NULL; |
3683 Object* back_pointer = GetBackPointer(); | 3698 Object* back_pointer = GetBackPointer(); |
3684 if (back_pointer->IsUndefined()) return NULL; | 3699 if (back_pointer->IsUndefined()) return NULL; |
3685 Map* map = Map::cast(back_pointer); | 3700 Map* map = Map::cast(back_pointer); |
3686 ASSERT(map->HasTransitionArray()); | 3701 ASSERT(map->HasTransitionArray()); |
3687 return map->transitions()->descriptors_pointer(); | 3702 return map->transitions()->descriptors_pointer(); |
3688 } | 3703 } |
3689 | 3704 |
3690 | 3705 |
3691 MaybeObject* Map::AddTransition(String* key, Map* target) { | 3706 MaybeObject* Map::AddTransition(String* key, |
| 3707 Map* target, |
| 3708 SimpleTransitionFlag flag) { |
3692 if (HasTransitionArray()) return transitions()->CopyInsert(key, target); | 3709 if (HasTransitionArray()) return transitions()->CopyInsert(key, target); |
3693 JSGlobalPropertyCell* descriptors_pointer = RetrieveDescriptorsPointer(); | 3710 JSGlobalPropertyCell* descriptors_pointer = RetrieveDescriptorsPointer(); |
3694 return TransitionArray::NewWith( | 3711 return TransitionArray::NewWith( |
3695 key, target, descriptors_pointer, GetBackPointer()); | 3712 flag, key, target, descriptors_pointer, GetBackPointer()); |
3696 } | 3713 } |
3697 | 3714 |
3698 | 3715 |
3699 void Map::SetTransition(int transition_index, Map* target) { | 3716 void Map::SetTransition(int transition_index, Map* target) { |
3700 transitions()->SetTarget(transition_index, target); | 3717 transitions()->SetTarget(transition_index, target); |
3701 } | 3718 } |
3702 | 3719 |
3703 | 3720 |
3704 Map* Map::GetTransition(int transition_index) { | 3721 Map* Map::GetTransition(int transition_index) { |
3705 return transitions()->GetTarget(transition_index); | 3722 return transitions()->GetTarget(transition_index); |
3706 } | 3723 } |
3707 | 3724 |
3708 | 3725 |
3709 MaybeObject* Map::set_elements_transition_map(Map* transitioned_map) { | 3726 MaybeObject* Map::set_elements_transition_map(Map* transitioned_map) { |
3710 MaybeObject* allow_elements = EnsureHasTransitionArray(this); | 3727 MaybeObject* allow_elements = |
| 3728 EnsureHasTransitionArray(this, FULL_TRANSITION_ARRAY); |
3711 if (allow_elements->IsFailure()) return allow_elements; | 3729 if (allow_elements->IsFailure()) return allow_elements; |
3712 transitions()->set_elements_transition(transitioned_map); | 3730 transitions()->set_elements_transition(transitioned_map); |
3713 return this; | 3731 return this; |
3714 } | 3732 } |
3715 | 3733 |
3716 | 3734 |
3717 FixedArray* Map::GetPrototypeTransitions() { | 3735 FixedArray* Map::GetPrototypeTransitions() { |
3718 if (!HasTransitionArray()) return GetHeap()->empty_fixed_array(); | 3736 if (!HasTransitionArray()) return GetHeap()->empty_fixed_array(); |
3719 if (!transitions()->HasPrototypeTransitions()) { | 3737 if (!transitions()->HasPrototypeTransitions()) { |
3720 return GetHeap()->empty_fixed_array(); | 3738 return GetHeap()->empty_fixed_array(); |
3721 } | 3739 } |
3722 return transitions()->GetPrototypeTransitions(); | 3740 return transitions()->GetPrototypeTransitions(); |
3723 } | 3741 } |
3724 | 3742 |
3725 | 3743 |
3726 MaybeObject* Map::SetPrototypeTransitions(FixedArray* proto_transitions) { | 3744 MaybeObject* Map::SetPrototypeTransitions(FixedArray* proto_transitions) { |
3727 MaybeObject* allow_prototype = EnsureHasTransitionArray(this); | 3745 MaybeObject* allow_prototype = |
| 3746 EnsureHasTransitionArray(this, FULL_TRANSITION_ARRAY); |
3728 if (allow_prototype->IsFailure()) return allow_prototype; | 3747 if (allow_prototype->IsFailure()) return allow_prototype; |
3729 #ifdef DEBUG | 3748 #ifdef DEBUG |
3730 if (HasPrototypeTransitions()) { | 3749 if (HasPrototypeTransitions()) { |
3731 ASSERT(GetPrototypeTransitions() != proto_transitions); | 3750 ASSERT(GetPrototypeTransitions() != proto_transitions); |
3732 ZapPrototypeTransitions(); | 3751 ZapPrototypeTransitions(); |
3733 } | 3752 } |
3734 #endif | 3753 #endif |
3735 transitions()->SetPrototypeTransitions(proto_transitions); | 3754 transitions()->SetPrototypeTransitions(proto_transitions); |
3736 return this; | 3755 return this; |
3737 } | 3756 } |
(...skipping 1793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5531 #undef WRITE_UINT32_FIELD | 5550 #undef WRITE_UINT32_FIELD |
5532 #undef READ_SHORT_FIELD | 5551 #undef READ_SHORT_FIELD |
5533 #undef WRITE_SHORT_FIELD | 5552 #undef WRITE_SHORT_FIELD |
5534 #undef READ_BYTE_FIELD | 5553 #undef READ_BYTE_FIELD |
5535 #undef WRITE_BYTE_FIELD | 5554 #undef WRITE_BYTE_FIELD |
5536 | 5555 |
5537 | 5556 |
5538 } } // namespace v8::internal | 5557 } } // namespace v8::internal |
5539 | 5558 |
5540 #endif // V8_OBJECTS_INL_H_ | 5559 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |