Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: src/objects-inl.h

Issue 10692026: Moving prototype transitions into the header of the transition array. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressing comments Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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::GetPrototypeTransitions() {
3555 if (!HasTransitionArray()) return GetHeap()->empty_fixed_array();
3556 if (!transitions()->HasPrototypeTransitions()) {
3557 return GetHeap()->empty_fixed_array();
3558 }
3559 return transitions()->GetPrototypeTransitions();
3560 }
3561
3562
3563 MaybeObject* Map::SetPrototypeTransitions(FixedArray* proto_transitions) {
3564 MaybeObject* allow_prototype = EnsureHasTransitionArray(this);
3565 if (allow_prototype->IsFailure()) return allow_prototype;
3566 #ifdef DEBUG
3567 if (HasPrototypeTransitions()) {
3568 ASSERT(GetPrototypeTransitions() != proto_transitions);
3569 ZapPrototypeTransitions();
3570 }
3571 #endif
3572 transitions()->SetPrototypeTransitions(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
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(heap, this, kBackPointerOffset, value, mode);
3598 FixedArray::cast(object)->set(
3599 kProtoTransitionBackPointerOffset, value, mode);
3600 } else {
3601 WRITE_FIELD(this, kPrototypeTransitionsOrBackPointerOffset, value);
3602 CONDITIONAL_WRITE_BARRIER(
3603 heap, this, kPrototypeTransitionsOrBackPointerOffset, value, mode);
3604 }
3605 } 3627 }
3606 3628
3607 3629
3608 FixedArray* Map::prototype_transitions() { 3630 // Can either be Smi (no transitions), normal transition array, or a transition
3609 Object* object = READ_FIELD(this, kPrototypeTransitionsOrBackPointerOffset); 3631 // array with the header overwritten as a Smi (thus iterating).
3610 if (object->IsFixedArray()) { 3632 TransitionArray* Map::unchecked_transition_array() {
3611 return FixedArray::cast(object); 3633 ASSERT(HasTransitionArray());
3612 } else { 3634 Object* object = *HeapObject::RawField(instance_descriptors(),
3613 return GetHeap()->empty_fixed_array(); 3635 DescriptorArray::kTransitionsOffset);
3614 } 3636 ASSERT(!object->IsSmi());
3637 TransitionArray* transition_array = static_cast<TransitionArray*>(object);
3638 return transition_array;
3615 } 3639 }
3616 3640
3617 3641
3618 void Map::set_prototype_transitions(FixedArray* value, WriteBarrierMode mode) { 3642 HeapObject* Map::UncheckedPrototypeTransitions() {
3619 Heap* heap = GetHeap(); 3643 ASSERT(HasTransitionArray());
3620 ASSERT(value != heap->empty_fixed_array()); 3644 ASSERT(unchecked_transition_array()->HasPrototypeTransitions());
3621 value->set(kProtoTransitionBackPointerOffset, GetBackPointer()); 3645 return unchecked_transition_array()->UncheckedPrototypeTransitions();
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 } 3646 }
3631 3647
3632 3648
3633 void Map::init_prototype_transitions(Object* undefined) {
3634 ASSERT(undefined->IsUndefined());
3635 WRITE_FIELD(this, kPrototypeTransitionsOrBackPointerOffset, undefined);
3636 }
3637
3638
3639 HeapObject* Map::unchecked_prototype_transitions() {
3640 Object* object = READ_FIELD(this, kPrototypeTransitionsOrBackPointerOffset);
3641 return reinterpret_cast<HeapObject*>(object);
3642 }
3643
3644
3645 ACCESSORS(Map, code_cache, Object, kCodeCacheOffset) 3649 ACCESSORS(Map, code_cache, Object, kCodeCacheOffset)
3646 ACCESSORS(Map, constructor, Object, kConstructorOffset) 3650 ACCESSORS(Map, constructor, Object, kConstructorOffset)
3647 3651
3648 ACCESSORS(JSFunction, shared, SharedFunctionInfo, kSharedFunctionInfoOffset) 3652 ACCESSORS(JSFunction, shared, SharedFunctionInfo, kSharedFunctionInfoOffset)
3649 ACCESSORS(JSFunction, literals_or_bindings, FixedArray, kLiteralsOffset) 3653 ACCESSORS(JSFunction, literals_or_bindings, FixedArray, kLiteralsOffset)
3650 ACCESSORS(JSFunction, next_function_link, Object, kNextFunctionLinkOffset) 3654 ACCESSORS(JSFunction, next_function_link, Object, kNextFunctionLinkOffset)
3651 3655
3652 ACCESSORS(GlobalObject, builtins, JSBuiltinsObject, kBuiltinsOffset) 3656 ACCESSORS(GlobalObject, builtins, JSBuiltinsObject, kBuiltinsOffset)
3653 ACCESSORS(GlobalObject, global_context, Context, kGlobalContextOffset) 3657 ACCESSORS(GlobalObject, global_context, Context, kGlobalContextOffset)
3654 ACCESSORS(GlobalObject, global_receiver, JSObject, kGlobalReceiverOffset) 3658 ACCESSORS(GlobalObject, global_receiver, JSObject, kGlobalReceiverOffset)
(...skipping 1625 matching lines...) Expand 10 before | Expand all | Expand 10 after
5280 #undef WRITE_UINT32_FIELD 5284 #undef WRITE_UINT32_FIELD
5281 #undef READ_SHORT_FIELD 5285 #undef READ_SHORT_FIELD
5282 #undef WRITE_SHORT_FIELD 5286 #undef WRITE_SHORT_FIELD
5283 #undef READ_BYTE_FIELD 5287 #undef READ_BYTE_FIELD
5284 #undef WRITE_BYTE_FIELD 5288 #undef WRITE_BYTE_FIELD
5285 5289
5286 5290
5287 } } // namespace v8::internal 5291 } } // namespace v8::internal
5288 5292
5289 #endif // V8_OBJECTS_INL_H_ 5293 #endif // V8_OBJECTS_INL_H_
OLDNEW
« no previous file with comments | « src/objects-debug.cc ('k') | src/profile-generator.cc » ('j') | src/transitions.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698