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 3471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3482 WRITE_FIELD(this, | 3482 WRITE_FIELD(this, |
3483 kInstanceDescriptorsOrBitField3Offset, | 3483 kInstanceDescriptorsOrBitField3Offset, |
3484 Smi::FromInt(value)); | 3484 Smi::FromInt(value)); |
3485 } else { | 3485 } else { |
3486 DescriptorArray::cast(object)->set_bit_field3_storage(value); | 3486 DescriptorArray::cast(object)->set_bit_field3_storage(value); |
3487 } | 3487 } |
3488 } | 3488 } |
3489 | 3489 |
3490 | 3490 |
3491 Object* Map::GetBackPointer() { | 3491 Object* Map::GetBackPointer() { |
3492 Object* object = READ_FIELD(this, kPrototypeTransitionsOrBackPointerOffset); | 3492 return READ_FIELD(this, kBackPointerOffset); |
3493 if (object->IsFixedArray()) { | |
3494 return FixedArray::cast(object)->get(kProtoTransitionBackPointerOffset); | |
3495 } else { | |
3496 return object; | |
3497 } | |
3498 } | 3493 } |
3499 | 3494 |
3500 | 3495 |
3501 bool Map::HasElementsTransition() { | 3496 bool Map::HasElementsTransition() { |
3502 return HasTransitionArray() && transitions()->HasElementsTransition(); | 3497 return HasTransitionArray() && transitions()->HasElementsTransition(); |
3503 } | 3498 } |
3504 | 3499 |
3505 | 3500 |
3506 bool Map::HasTransitionArray() { | 3501 bool Map::HasTransitionArray() { |
3507 return instance_descriptors()->HasTransitionArray(); | 3502 return instance_descriptors()->HasTransitionArray(); |
(...skipping 17 matching lines...) Expand all Loading... | |
3525 if (map->instance_descriptors()->MayContainTransitions()) return map; | 3520 if (map->instance_descriptors()->MayContainTransitions()) return map; |
3526 DescriptorArray* descriptors; | 3521 DescriptorArray* descriptors; |
3527 MaybeObject* maybe_descriptors = | 3522 MaybeObject* maybe_descriptors = |
3528 DescriptorArray::Allocate(0, DescriptorArray::CANNOT_BE_SHARED); | 3523 DescriptorArray::Allocate(0, DescriptorArray::CANNOT_BE_SHARED); |
3529 if (!maybe_descriptors->To(&descriptors)) return maybe_descriptors; | 3524 if (!maybe_descriptors->To(&descriptors)) return maybe_descriptors; |
3530 map->set_instance_descriptors(descriptors); | 3525 map->set_instance_descriptors(descriptors); |
3531 return descriptors; | 3526 return descriptors; |
3532 } | 3527 } |
3533 | 3528 |
3534 | 3529 |
3535 // If the descriptor does not have a transition array, install a new | 3530 // If the descriptor is using the empty transition array, install a new empty |
3536 // transition array that has room for an element transition. | 3531 // transition array that will have place for an element transition. |
3537 static MaybeObject* AllowElementsTransition(Map* map) { | 3532 static MaybeObject* EnsureHasTransitionArray(Map* map) { |
3538 if (map->HasTransitionArray()) return map; | 3533 if (map->HasTransitionArray()) return map; |
3539 | 3534 |
3540 AllowTransitions(map); | 3535 AllowTransitions(map); |
3541 | 3536 |
3542 TransitionArray* transitions; | 3537 TransitionArray* transitions; |
3543 MaybeObject* maybe_transitions = TransitionArray::Allocate(0); | 3538 MaybeObject* maybe_transitions = TransitionArray::Allocate(0); |
3544 if (!maybe_transitions->To(&transitions)) return maybe_transitions; | 3539 if (!maybe_transitions->To(&transitions)) return maybe_transitions; |
3545 MaybeObject* added_transitions = map->set_transitions(transitions); | 3540 MaybeObject* added_transitions = map->set_transitions(transitions); |
3546 if (added_transitions->IsFailure()) return added_transitions; | 3541 if (added_transitions->IsFailure()) return added_transitions; |
3547 return transitions; | 3542 return transitions; |
3548 } | 3543 } |
3549 | 3544 |
3550 | 3545 |
3551 MaybeObject* Map::set_elements_transition_map(Map* transitioned_map) { | 3546 MaybeObject* Map::set_elements_transition_map(Map* transitioned_map) { |
3552 MaybeObject* allow_elements = AllowElementsTransition(this); | 3547 MaybeObject* allow_elements = EnsureHasTransitionArray(this); |
3553 if (allow_elements->IsFailure()) return allow_elements; | 3548 if (allow_elements->IsFailure()) return allow_elements; |
3554 transitions()->set_elements_transition(transitioned_map); | 3549 transitions()->set_elements_transition(transitioned_map); |
3555 return this; | 3550 return this; |
3556 } | 3551 } |
3557 | 3552 |
3558 | 3553 |
3554 FixedArray* Map::prototype_transitions() { | |
Michael Starzinger
2012/07/06 13:53:18
Since these methods are far more than generic acce
| |
3555 if (!HasTransitionArray()) return GetHeap()->empty_fixed_array(); | |
3556 if (!transitions()->HasPrototypeTransitions()) { | |
3557 return GetHeap()->empty_fixed_array(); | |
3558 } | |
3559 return transitions()->prototype_transitions(); | |
3560 } | |
3561 | |
3562 | |
3563 MaybeObject* Map::set_prototype_transitions(FixedArray* proto_transitions) { | |
Michael Starzinger
2012/07/06 13:53:18
Likewise.
Toon Verwaest
2012/07/09 12:45:27
Done.
| |
3564 MaybeObject* allow_prototype = EnsureHasTransitionArray(this); | |
3565 if (allow_prototype->IsFailure()) return allow_prototype; | |
3566 #ifdef DEBUG | |
3567 if (HasPrototypeTransitions() && | |
3568 prototype_transitions() == proto_transitions) { | |
Michael Starzinger
2012/07/06 13:53:18
I think this should actually be "!=" here. Maybe w
Toon Verwaest
2012/07/09 12:45:27
Done.
| |
3569 ZapPrototypeTransitions(); | |
3570 } | |
3571 #endif | |
3572 transitions()->set_prototype_transitions(proto_transitions); | |
3573 return this; | |
3574 } | |
3575 | |
3576 | |
3577 bool Map::HasPrototypeTransitions() { | |
3578 return HasTransitionArray() && transitions()->HasPrototypeTransitions(); | |
3579 } | |
3580 | |
3581 | |
3559 TransitionArray* Map::transitions() { | 3582 TransitionArray* Map::transitions() { |
3560 return instance_descriptors()->transitions(); | 3583 return instance_descriptors()->transitions(); |
3561 } | 3584 } |
3562 | 3585 |
3563 | 3586 |
3564 void Map::ClearTransitions() { | 3587 void Map::ClearTransitions() { |
3565 #ifdef DEBUG | 3588 #ifdef DEBUG |
3566 ZapTransitions(); | 3589 ZapTransitions(); |
3567 #endif | 3590 #endif |
3568 DescriptorArray* descriptors = instance_descriptors(); | 3591 DescriptorArray* descriptors = instance_descriptors(); |
(...skipping 12 matching lines...) Expand all Loading... | |
3581 if (HasTransitionArray()) { | 3604 if (HasTransitionArray()) { |
3582 ASSERT(transitions() != transitions_array); | 3605 ASSERT(transitions() != transitions_array); |
3583 ZapTransitions(); | 3606 ZapTransitions(); |
3584 } | 3607 } |
3585 #endif | 3608 #endif |
3586 instance_descriptors()->set_transitions(transitions_array); | 3609 instance_descriptors()->set_transitions(transitions_array); |
3587 return this; | 3610 return this; |
3588 } | 3611 } |
3589 | 3612 |
3590 | 3613 |
3614 void Map::init_back_pointer(Object* undefined) { | |
3615 ASSERT(undefined->IsUndefined()); | |
3616 WRITE_FIELD(this, kBackPointerOffset, undefined); | |
3617 } | |
3618 | |
3619 | |
3591 void Map::SetBackPointer(Object* value, WriteBarrierMode mode) { | 3620 void Map::SetBackPointer(Object* value, WriteBarrierMode mode) { |
3592 Heap* heap = GetHeap(); | 3621 Heap* heap = GetHeap(); |
3593 ASSERT(instance_type() >= FIRST_JS_RECEIVER_TYPE); | 3622 ASSERT(instance_type() >= FIRST_JS_RECEIVER_TYPE); |
3594 ASSERT((value->IsUndefined() && GetBackPointer()->IsMap()) || | 3623 ASSERT((value->IsUndefined() && GetBackPointer()->IsMap()) || |
3595 (value->IsMap() && GetBackPointer()->IsUndefined())); | 3624 (value->IsMap() && GetBackPointer()->IsUndefined())); |
3596 Object* object = READ_FIELD(this, kPrototypeTransitionsOrBackPointerOffset); | 3625 WRITE_FIELD(this, kBackPointerOffset, value); |
3597 if (object->IsFixedArray()) { | 3626 CONDITIONAL_WRITE_BARRIER( |
Michael Starzinger
2012/07/06 13:53:18
This should fit into one line now.
Toon Verwaest
2012/07/09 12:45:27
Done.
| |
3598 FixedArray::cast(object)->set( | 3627 heap, this, kBackPointerOffset, value, mode); |
3599 kProtoTransitionBackPointerOffset, value, mode); | |
3600 } else { | |
3601 WRITE_FIELD(this, kPrototypeTransitionsOrBackPointerOffset, value); | |
3602 CONDITIONAL_WRITE_BARRIER( | |
3603 heap, this, kPrototypeTransitionsOrBackPointerOffset, value, mode); | |
3604 } | |
3605 } | 3628 } |
3606 | 3629 |
3607 | 3630 |
3608 FixedArray* Map::prototype_transitions() { | 3631 // Can either be Smi (no transitions), normal transition array, or a transition |
3609 Object* object = READ_FIELD(this, kPrototypeTransitionsOrBackPointerOffset); | 3632 // array with the header overwritten as a Smi (thus iterating). |
3610 if (object->IsFixedArray()) { | 3633 TransitionArray* Map::unchecked_transition_array() { |
3611 return FixedArray::cast(object); | 3634 ASSERT(HasTransitionArray()); |
3612 } else { | 3635 Object* object = *HeapObject::RawField(instance_descriptors(), |
3613 return GetHeap()->empty_fixed_array(); | 3636 DescriptorArray::kTransitionsOffset); |
3614 } | 3637 ASSERT(!object->IsSmi()); |
3615 } | 3638 TransitionArray* transition_array = static_cast<TransitionArray*>(object); |
3616 | 3639 return transition_array; |
3617 | |
3618 void Map::set_prototype_transitions(FixedArray* value, WriteBarrierMode mode) { | |
3619 Heap* heap = GetHeap(); | |
3620 ASSERT(value != heap->empty_fixed_array()); | |
3621 value->set(kProtoTransitionBackPointerOffset, GetBackPointer()); | |
3622 #ifdef DEBUG | |
3623 if (value != prototype_transitions()) { | |
3624 ZapPrototypeTransitions(); | |
3625 } | |
3626 #endif | |
3627 WRITE_FIELD(this, kPrototypeTransitionsOrBackPointerOffset, value); | |
3628 CONDITIONAL_WRITE_BARRIER( | |
3629 heap, this, kPrototypeTransitionsOrBackPointerOffset, value, mode); | |
3630 } | |
3631 | |
3632 | |
3633 void Map::init_prototype_transitions(Object* undefined) { | |
3634 ASSERT(undefined->IsUndefined()); | |
3635 WRITE_FIELD(this, kPrototypeTransitionsOrBackPointerOffset, undefined); | |
3636 } | 3640 } |
3637 | 3641 |
3638 | 3642 |
3639 HeapObject* Map::unchecked_prototype_transitions() { | 3643 HeapObject* Map::unchecked_prototype_transitions() { |
3640 Object* object = READ_FIELD(this, kPrototypeTransitionsOrBackPointerOffset); | 3644 ASSERT(HasTransitionArray()); |
3641 return reinterpret_cast<HeapObject*>(object); | 3645 ASSERT(unchecked_transition_array()->HasPrototypeTransitions()); |
3646 return unchecked_transition_array()->unchecked_prototype_transitions(); | |
3642 } | 3647 } |
3643 | 3648 |
3644 | 3649 |
3645 ACCESSORS(Map, code_cache, Object, kCodeCacheOffset) | 3650 ACCESSORS(Map, code_cache, Object, kCodeCacheOffset) |
3646 ACCESSORS(Map, constructor, Object, kConstructorOffset) | 3651 ACCESSORS(Map, constructor, Object, kConstructorOffset) |
3647 | 3652 |
3648 ACCESSORS(JSFunction, shared, SharedFunctionInfo, kSharedFunctionInfoOffset) | 3653 ACCESSORS(JSFunction, shared, SharedFunctionInfo, kSharedFunctionInfoOffset) |
3649 ACCESSORS(JSFunction, literals_or_bindings, FixedArray, kLiteralsOffset) | 3654 ACCESSORS(JSFunction, literals_or_bindings, FixedArray, kLiteralsOffset) |
3650 ACCESSORS(JSFunction, next_function_link, Object, kNextFunctionLinkOffset) | 3655 ACCESSORS(JSFunction, next_function_link, Object, kNextFunctionLinkOffset) |
3651 | 3656 |
(...skipping 1628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5280 #undef WRITE_UINT32_FIELD | 5285 #undef WRITE_UINT32_FIELD |
5281 #undef READ_SHORT_FIELD | 5286 #undef READ_SHORT_FIELD |
5282 #undef WRITE_SHORT_FIELD | 5287 #undef WRITE_SHORT_FIELD |
5283 #undef READ_BYTE_FIELD | 5288 #undef READ_BYTE_FIELD |
5284 #undef WRITE_BYTE_FIELD | 5289 #undef WRITE_BYTE_FIELD |
5285 | 5290 |
5286 | 5291 |
5287 } } // namespace v8::internal | 5292 } } // namespace v8::internal |
5288 | 5293 |
5289 #endif // V8_OBJECTS_INL_H_ | 5294 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |