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

Side by Side Diff: src/objects.cc

Issue 7112007: Fix traversal of the map transition tree to take the prototype (Closed) Base URL: http://v8.googlecode.com/svn/branches/3.3/
Patch Set: Created 9 years, 6 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
« no previous file with comments | « no previous file | src/version.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 3753 matching lines...) Expand 10 before | Expand all | Expand 10 after
3764 3764
3765 void Map::RemoveFromCodeCache(String* name, Code* code, int index) { 3765 void Map::RemoveFromCodeCache(String* name, Code* code, int index) {
3766 // No GC is supposed to happen between a call to IndexInCodeCache and 3766 // No GC is supposed to happen between a call to IndexInCodeCache and
3767 // RemoveFromCodeCache so the code cache must be there. 3767 // RemoveFromCodeCache so the code cache must be there.
3768 ASSERT(!code_cache()->IsFixedArray()); 3768 ASSERT(!code_cache()->IsFixedArray());
3769 CodeCache::cast(code_cache())->RemoveByIndex(name, code, index); 3769 CodeCache::cast(code_cache())->RemoveByIndex(name, code, index);
3770 } 3770 }
3771 3771
3772 3772
3773 void Map::TraverseTransitionTree(TraverseCallback callback, void* data) { 3773 void Map::TraverseTransitionTree(TraverseCallback callback, void* data) {
3774 // Traverse the transition tree without using a stack. We do this by
3775 // reversing the pointers in the maps and descriptor arrays.
3774 Map* current = this; 3776 Map* current = this;
3775 Map* meta_map = heap()->meta_map(); 3777 Map* meta_map = heap()->meta_map();
3778 Object** map_or_index_field = NULL;
3776 while (current != meta_map) { 3779 while (current != meta_map) {
3777 DescriptorArray* d = reinterpret_cast<DescriptorArray*>( 3780 DescriptorArray* d = reinterpret_cast<DescriptorArray*>(
3778 *RawField(current, Map::kInstanceDescriptorsOrBitField3Offset)); 3781 *RawField(current, Map::kInstanceDescriptorsOrBitField3Offset));
3779 if (d->IsEmpty()) { 3782 if (!d->IsEmpty()) {
3780 Map* prev = current->map(); 3783 FixedArray* contents = reinterpret_cast<FixedArray*>(
3781 current->set_map(meta_map); 3784 d->get(DescriptorArray::kContentArrayIndex));
3782 callback(current, data); 3785 map_or_index_field = RawField(contents, HeapObject::kMapOffset);
3783 current = prev; 3786 Object* map_or_index = *map_or_index_field;
3784 continue; 3787 bool map_done = true; // Controls a nested continue statement.
3788 for (int i = map_or_index->IsSmi() ? Smi::cast(map_or_index)->value() : 0;
3789 i < contents->length();
3790 i += 2) {
3791 PropertyDetails details(Smi::cast(contents->get(i + 1)));
3792 if (details.IsTransition()) {
3793 // Found a map in the transition array. We record our progress in
3794 // the transition array by recording the current map in the map field
3795 // of the next map and recording the index in the transition array in
3796 // the map field of the array.
3797 Map* next = Map::cast(contents->get(i));
3798 next->set_map(current);
3799 *map_or_index_field = Smi::FromInt(i + 2);
3800 current = next;
3801 map_done = false;
3802 break;
3803 }
3804 }
3805 if (!map_done) continue;
3806 }
3807 // That was the regular transitions, now for the prototype transitions.
3808 FixedArray* prototype_transitions =
3809 current->unchecked_prototype_transitions();
3810 Object** proto_map_or_index_field =
3811 RawField(prototype_transitions, HeapObject::kMapOffset);
3812 Object* map_or_index = *proto_map_or_index_field;
3813 const int start = 2;
3814 int i = map_or_index->IsSmi() ? Smi::cast(map_or_index)->value() : start;
3815 if (i < prototype_transitions->length()) {
3816 // Found a map in the prototype transition array. Record progress in
3817 // an analogous way to the regular transitions array above.
3818 Object* perhaps_map = prototype_transitions->get(i);
3819 if (perhaps_map->IsMap()) {
3820 Map* next = Map::cast(perhaps_map);
3821 next->set_map(current);
3822 *proto_map_or_index_field =
3823 Smi::FromInt(i + 2);
3824 current = next;
3825 continue;
3826 }
3827 }
3828 *proto_map_or_index_field = heap()->fixed_array_map();
3829 if (map_or_index_field != NULL) {
3830 *map_or_index_field = heap()->fixed_array_map();
3785 } 3831 }
3786 3832
3787 FixedArray* contents = reinterpret_cast<FixedArray*>( 3833 // The callback expects a map to have a real map as its map, so we save
3788 d->get(DescriptorArray::kContentArrayIndex)); 3834 // the map field, which is being used to track the traversal and put the
3789 Object** map_or_index_field = RawField(contents, HeapObject::kMapOffset); 3835 // correct map (the meta_map) in place while we do the callback.
3790 Object* map_or_index = *map_or_index_field;
3791 bool map_done = true;
3792 for (int i = map_or_index->IsSmi() ? Smi::cast(map_or_index)->value() : 0;
3793 i < contents->length();
3794 i += 2) {
3795 PropertyDetails details(Smi::cast(contents->get(i + 1)));
3796 if (details.IsTransition()) {
3797 Map* next = reinterpret_cast<Map*>(contents->get(i));
3798 next->set_map(current);
3799 *map_or_index_field = Smi::FromInt(i + 2);
3800 current = next;
3801 map_done = false;
3802 break;
3803 }
3804 }
3805 if (!map_done) continue;
3806 *map_or_index_field = heap()->fixed_array_map();
3807 Map* prev = current->map(); 3836 Map* prev = current->map();
3808 current->set_map(meta_map); 3837 current->set_map(meta_map);
3809 callback(current, data); 3838 callback(current, data);
3810 current = prev; 3839 current = prev;
3811 } 3840 }
3812 } 3841 }
3813 3842
3814 3843
3815 MaybeObject* CodeCache::Update(String* name, Code* code) { 3844 MaybeObject* CodeCache::Update(String* name, Code* code) {
3816 // The number of monomorphic stubs for normal load/store/call IC's can grow to 3845 // The number of monomorphic stubs for normal load/store/call IC's can grow to
(...skipping 6759 matching lines...) Expand 10 before | Expand all | Expand 10 after
10576 if (break_point_objects()->IsUndefined()) return 0; 10605 if (break_point_objects()->IsUndefined()) return 0;
10577 // Single beak point. 10606 // Single beak point.
10578 if (!break_point_objects()->IsFixedArray()) return 1; 10607 if (!break_point_objects()->IsFixedArray()) return 1;
10579 // Multiple break points. 10608 // Multiple break points.
10580 return FixedArray::cast(break_point_objects())->length(); 10609 return FixedArray::cast(break_point_objects())->length();
10581 } 10610 }
10582 #endif 10611 #endif
10583 10612
10584 10613
10585 } } // namespace v8::internal 10614 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/version.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698