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

Side by Side Diff: src/objects.cc

Issue 10692185: Couple the enumeration index of a property to the size of the descriptor array where it first appea… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Use the enumeration index of the LastAdded descriptor for appending. 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
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('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 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 5783 matching lines...) Expand 10 before | Expand all | Expand 10 after
5794 FixedArray* result; 5794 FixedArray* result;
5795 if (number_of_descriptors == 0 && shared_mode == MAY_BE_SHARED) { 5795 if (number_of_descriptors == 0 && shared_mode == MAY_BE_SHARED) {
5796 return heap->empty_descriptor_array(); 5796 return heap->empty_descriptor_array();
5797 } 5797 }
5798 // Allocate the array of keys. 5798 // Allocate the array of keys.
5799 { MaybeObject* maybe_array = 5799 { MaybeObject* maybe_array =
5800 heap->AllocateFixedArray(ToKeyIndex(number_of_descriptors)); 5800 heap->AllocateFixedArray(ToKeyIndex(number_of_descriptors));
5801 if (!maybe_array->To(&result)) return maybe_array; 5801 if (!maybe_array->To(&result)) return maybe_array;
5802 } 5802 }
5803 5803
5804 result->set(kLastAddedIndex, Smi::FromInt(-1)); 5804 result->set(kLastAddedIndex, Smi::FromInt(kNoneAdded));
5805 result->set(kTransitionsIndex, Smi::FromInt(0)); 5805 result->set(kTransitionsIndex, Smi::FromInt(0));
5806 return result; 5806 return result;
5807 } 5807 }
5808 5808
5809 5809
5810 void DescriptorArray::SetEnumCache(FixedArray* bridge_storage, 5810 void DescriptorArray::SetEnumCache(FixedArray* bridge_storage,
5811 FixedArray* new_cache, 5811 FixedArray* new_cache,
5812 Object* new_index_cache) { 5812 Object* new_index_cache) {
5813 ASSERT(bridge_storage->length() >= kEnumCacheBridgeLength); 5813 ASSERT(bridge_storage->length() >= kEnumCacheBridgeLength);
5814 ASSERT(new_index_cache->IsSmi() || new_index_cache->IsFixedArray()); 5814 ASSERT(new_index_cache->IsSmi() || new_index_cache->IsFixedArray());
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
5921 5921
5922 int new_size = number_of_descriptors() + 1; 5922 int new_size = number_of_descriptors() + 1;
5923 5923
5924 DescriptorArray* new_descriptors; 5924 DescriptorArray* new_descriptors;
5925 { MaybeObject* maybe_result = Allocate(new_size, MAY_BE_SHARED); 5925 { MaybeObject* maybe_result = Allocate(new_size, MAY_BE_SHARED);
5926 if (!maybe_result->To(&new_descriptors)) return maybe_result; 5926 if (!maybe_result->To(&new_descriptors)) return maybe_result;
5927 } 5927 }
5928 5928
5929 FixedArray::WhitenessWitness witness(new_descriptors); 5929 FixedArray::WhitenessWitness witness(new_descriptors);
5930 5930
5931 descriptor->SetEnumerationIndex(NextEnumerationIndex()); 5931 ASSERT(new_size == NextEnumerationIndex());
5932 descriptor->SetEnumerationIndex(new_size);
5932 5933
5933 // Copy the descriptors, inserting or replacing a descriptor. 5934 // Copy the descriptors, inserting or replacing a descriptor.
5934 int insertion_index = -1; 5935 int insertion_index = -1;
5935 int to = 0; 5936 int to = 0;
5936 for (int from = 0; from < number_of_descriptors(); ++from) { 5937 for (int from = 0; from < number_of_descriptors(); ++from) {
5937 if (insertion_index < 0 && InsertionPointFound(GetKey(from), key)) { 5938 if (insertion_index < 0 && InsertionPointFound(GetKey(from), key)) {
5938 insertion_index = to++; 5939 insertion_index = to++;
5939 } 5940 }
5940 MaybeObject* copy_result = 5941 MaybeObject* copy_result =
5941 new_descriptors->CopyFrom(to++, this, from, witness); 5942 new_descriptors->CopyFrom(to++, this, from, witness);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
5981 // We need the whiteness witness since sort will reshuffle the entries in the 5982 // We need the whiteness witness since sort will reshuffle the entries in the
5982 // descriptor array. If the descriptor array were to be black, the shuffling 5983 // descriptor array. If the descriptor array were to be black, the shuffling
5983 // would move a slot that was already recorded as pointing into an evacuation 5984 // would move a slot that was already recorded as pointing into an evacuation
5984 // candidate. This would result in missing updates upon evacuation. 5985 // candidate. This would result in missing updates upon evacuation.
5985 void DescriptorArray::SortUnchecked(const WhitenessWitness& witness) { 5986 void DescriptorArray::SortUnchecked(const WhitenessWitness& witness) {
5986 // In-place heap sort. 5987 // In-place heap sort.
5987 int len = number_of_descriptors(); 5988 int len = number_of_descriptors();
5988 // Nothing to sort. 5989 // Nothing to sort.
5989 if (len == 0) return; 5990 if (len == 0) return;
5990 5991
5992 ASSERT(LastAdded() == kNoneAdded ||
5993 GetDetails(LastAdded()).index() == number_of_descriptors());
5994
5991 // Bottom-up max-heap construction. 5995 // Bottom-up max-heap construction.
5992 // Index of the last node with children 5996 // Index of the last node with children
5993 const int max_parent_index = (len / 2) - 1; 5997 const int max_parent_index = (len / 2) - 1;
5994 for (int i = max_parent_index; i >= 0; --i) { 5998 for (int i = max_parent_index; i >= 0; --i) {
5995 int parent_index = i; 5999 int parent_index = i;
5996 const uint32_t parent_hash = GetKey(i)->Hash(); 6000 const uint32_t parent_hash = GetKey(i)->Hash();
5997 while (parent_index <= max_parent_index) { 6001 while (parent_index <= max_parent_index) {
5998 int child_index = 2 * parent_index + 1; 6002 int child_index = 2 * parent_index + 1;
5999 uint32_t child_hash = GetKey(child_index)->Hash(); 6003 uint32_t child_hash = GetKey(child_index)->Hash();
6000 if (child_index + 1 < len) { 6004 if (child_index + 1 < len) {
(...skipping 27 matching lines...) Expand all
6028 child_index++; 6032 child_index++;
6029 child_hash = right_child_hash; 6033 child_hash = right_child_hash;
6030 } 6034 }
6031 } 6035 }
6032 if (child_hash <= parent_hash) break; 6036 if (child_hash <= parent_hash) break;
6033 NoIncrementalWriteBarrierSwapDescriptors(parent_index, child_index); 6037 NoIncrementalWriteBarrierSwapDescriptors(parent_index, child_index);
6034 parent_index = child_index; 6038 parent_index = child_index;
6035 } 6039 }
6036 } 6040 }
6037 6041
6038 int last_enum_index = -1; 6042 #ifdef DEBUG
6039 int last_added = -1; 6043 // Ensure that all enumeration indexes between 1 and length occur uniquely in
6040 for (int i = 0; i < len; ++i) { 6044 // the descriptor array.
6041 int current_enum = GetDetails(i).index(); 6045 for (int i = 1; i <= len; ++i) {
6042 if (current_enum > last_enum_index) { 6046 int j;
6043 last_added = i; 6047 for (j = 0; j < len; ++j) {
6044 last_enum_index = current_enum; 6048 if (GetDetails(j).index() == i) break;
6049 }
6050 ASSERT(j != len);
6051 for (j++; j < len; ++j) {
6052 ASSERT(GetDetails(j).index() != i);
6045 } 6053 }
6046 } 6054 }
6047 SetLastAdded(last_added); 6055 #endif
6048 6056
6049 ASSERT(LastAdded() != -1); 6057 for (int i = 0; i < len; ++i) {
6058 if (GetDetails(i).index() == len) {
6059 SetLastAdded(i);
6060 return;
6061 }
6062 }
6063
6064 UNREACHABLE();
6050 } 6065 }
6051 6066
6052 6067
6053 void DescriptorArray::Sort(const WhitenessWitness& witness) { 6068 void DescriptorArray::Sort(const WhitenessWitness& witness) {
6054 SortUnchecked(witness); 6069 SortUnchecked(witness);
6055 SLOW_ASSERT(IsSortedNoDuplicates()); 6070 SLOW_ASSERT(IsSortedNoDuplicates());
6056 } 6071 }
6057 6072
6058 6073
6059 MaybeObject* AccessorPair::CopyWithoutTransitions() { 6074 MaybeObject* AccessorPair::CopyWithoutTransitions() {
(...skipping 7238 matching lines...) Expand 10 before | Expand all | Expand 10 after
13298 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); 13313 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER);
13299 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); 13314 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER);
13300 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); 13315 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER);
13301 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); 13316 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER);
13302 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); 13317 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER);
13303 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); 13318 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER);
13304 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); 13319 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER);
13305 } 13320 }
13306 13321
13307 } } // namespace v8::internal 13322 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698