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

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

Issue 10916336: Preallocate space in descriptor arrays. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: u Created 8 years, 3 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-debug.cc ('k') | test/cctest/test-alloc.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 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 1888 matching lines...) Expand 10 before | Expand all | Expand 10 after
1899 } 1899 }
1900 1900
1901 1901
1902 bool DescriptorArray::IsEmpty() { 1902 bool DescriptorArray::IsEmpty() {
1903 ASSERT(length() >= kFirstIndex || 1903 ASSERT(length() >= kFirstIndex ||
1904 this == HEAP->empty_descriptor_array()); 1904 this == HEAP->empty_descriptor_array());
1905 return length() < kFirstIndex; 1905 return length() < kFirstIndex;
1906 } 1906 }
1907 1907
1908 1908
1909 void DescriptorArray::SetNumberOfDescriptors(int number_of_descriptors) {
1910 WRITE_FIELD(
1911 this, kDescriptorLengthOffset, Smi::FromInt(number_of_descriptors));
1912 }
1913
1914
1909 // Perform a binary search in a fixed array. Low and high are entry indices. If 1915 // Perform a binary search in a fixed array. Low and high are entry indices. If
1910 // there are three entries in this array it should be called with low=0 and 1916 // there are three entries in this array it should be called with low=0 and
1911 // high=2. 1917 // high=2.
1912 template<typename T> 1918 template<typename T>
1913 int BinarySearch(T* array, String* name, int low, int high) { 1919 int BinarySearch(T* array, String* name, int low, int high) {
1914 uint32_t hash = name->Hash(); 1920 uint32_t hash = name->Hash();
1915 int limit = high; 1921 int limit = high;
1916 1922
1917 ASSERT(low <= high); 1923 ASSERT(low <= high);
1918 1924
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
2131 desc->GetKey()); 2137 desc->GetKey());
2132 NoIncrementalWriteBarrierSet(this, 2138 NoIncrementalWriteBarrierSet(this,
2133 ToValueIndex(descriptor_number), 2139 ToValueIndex(descriptor_number),
2134 desc->GetValue()); 2140 desc->GetValue());
2135 NoIncrementalWriteBarrierSet(this, 2141 NoIncrementalWriteBarrierSet(this,
2136 ToDetailsIndex(descriptor_number), 2142 ToDetailsIndex(descriptor_number),
2137 desc->GetDetails().AsSmi()); 2143 desc->GetDetails().AsSmi());
2138 } 2144 }
2139 2145
2140 2146
2147 void DescriptorArray::Set(int descriptor_number, Descriptor* desc) {
2148 // Range check.
2149 ASSERT(descriptor_number < number_of_descriptors());
2150 ASSERT(desc->GetDetails().descriptor_index() <=
2151 number_of_descriptors());
2152 ASSERT(desc->GetDetails().descriptor_index() > 0);
2153
2154 set(ToKeyIndex(descriptor_number), desc->GetKey());
2155 set(ToValueIndex(descriptor_number), desc->GetValue());
2156 set(ToDetailsIndex(descriptor_number), desc->GetDetails().AsSmi());
2157 }
2158
2159
2160 void DescriptorArray::EraseDescriptor(Heap* heap, int descriptor_number) {
2161 set_null_unchecked(heap, ToKeyIndex(descriptor_number));
2162 set_null_unchecked(heap, ToValueIndex(descriptor_number));
2163 }
2164
2165
2141 void DescriptorArray::Append(Descriptor* desc, 2166 void DescriptorArray::Append(Descriptor* desc,
2142 const WhitenessWitness& witness, 2167 const WhitenessWitness& witness) {
2143 int number_of_set_descriptors) { 2168 int descriptor_number = number_of_descriptors();
2144 int descriptor_number = number_of_set_descriptors;
2145 int enumeration_index = descriptor_number + 1; 2169 int enumeration_index = descriptor_number + 1;
2170 SetNumberOfDescriptors(descriptor_number + 1);
2146 desc->SetEnumerationIndex(enumeration_index); 2171 desc->SetEnumerationIndex(enumeration_index);
2147 Set(descriptor_number, desc, witness); 2172 Set(descriptor_number, desc, witness);
2148 2173
2149 uint32_t hash = desc->GetKey()->Hash(); 2174 uint32_t hash = desc->GetKey()->Hash();
2150 2175
2151 int insertion; 2176 int insertion;
2152 2177
2153 for (insertion = descriptor_number; insertion > 0; --insertion) { 2178 for (insertion = descriptor_number; insertion > 0; --insertion) {
2154 String* key = GetSortedKey(insertion - 1); 2179 String* key = GetSortedKey(insertion - 1);
2155 if (key->Hash() <= hash) break; 2180 if (key->Hash() <= hash) break;
2156 SetSortedKey(insertion, GetSortedKeyIndex(insertion - 1)); 2181 SetSortedKey(insertion, GetSortedKeyIndex(insertion - 1));
2157 } 2182 }
2158 2183
2159 SetSortedKey(insertion, descriptor_number); 2184 SetSortedKey(insertion, descriptor_number);
2160 } 2185 }
2161 2186
2162 2187
2188 void DescriptorArray::Append(Descriptor* desc) {
2189 int descriptor_number = number_of_descriptors();
2190 int enumeration_index = descriptor_number + 1;
2191 SetNumberOfDescriptors(descriptor_number + 1);
2192 desc->SetEnumerationIndex(enumeration_index);
2193 Set(descriptor_number, desc);
2194
2195 uint32_t hash = desc->GetKey()->Hash();
2196
2197 int insertion;
2198
2199 for (insertion = descriptor_number; insertion > 0; --insertion) {
2200 String* key = GetSortedKey(insertion - 1);
2201 if (key->Hash() <= hash) break;
2202 SetSortedKey(insertion, GetSortedKeyIndex(insertion - 1));
2203 }
2204
2205 SetSortedKey(insertion, descriptor_number);
2206 }
2207
2208
2163 void DescriptorArray::SwapSortedKeys(int first, int second) { 2209 void DescriptorArray::SwapSortedKeys(int first, int second) {
2164 int first_key = GetSortedKeyIndex(first); 2210 int first_key = GetSortedKeyIndex(first);
2165 SetSortedKey(first, GetSortedKeyIndex(second)); 2211 SetSortedKey(first, GetSortedKeyIndex(second));
2166 SetSortedKey(second, first_key); 2212 SetSortedKey(second, first_key);
2167 } 2213 }
2168 2214
2169 2215
2170 DescriptorArray::WhitenessWitness::WhitenessWitness(FixedArray* array) 2216 DescriptorArray::WhitenessWitness::WhitenessWitness(FixedArray* array)
2171 : marking_(array->GetHeap()->incremental_marking()) { 2217 : marking_(array->GetHeap()->incremental_marking()) {
2172 marking_->EnterNoMarkingScope(); 2218 marking_->EnterNoMarkingScope();
(...skipping 1426 matching lines...) Expand 10 before | Expand all | Expand 10 after
3599 WRITE_FIELD(this, kTransitionsOrBackPointerOffset, back_pointer); 3645 WRITE_FIELD(this, kTransitionsOrBackPointerOffset, back_pointer);
3600 CONDITIONAL_WRITE_BARRIER( 3646 CONDITIONAL_WRITE_BARRIER(
3601 heap, this, kTransitionsOrBackPointerOffset, back_pointer, mode); 3647 heap, this, kTransitionsOrBackPointerOffset, back_pointer, mode);
3602 } 3648 }
3603 3649
3604 3650
3605 void Map::AppendDescriptor(Descriptor* desc, 3651 void Map::AppendDescriptor(Descriptor* desc,
3606 const DescriptorArray::WhitenessWitness& witness) { 3652 const DescriptorArray::WhitenessWitness& witness) {
3607 DescriptorArray* descriptors = instance_descriptors(); 3653 DescriptorArray* descriptors = instance_descriptors();
3608 int number_of_own_descriptors = NumberOfOwnDescriptors(); 3654 int number_of_own_descriptors = NumberOfOwnDescriptors();
3609 ASSERT(number_of_own_descriptors < descriptors->number_of_descriptors()); 3655 ASSERT(descriptors->number_of_descriptors() == number_of_own_descriptors);
3610 descriptors->Append(desc, witness, number_of_own_descriptors); 3656 descriptors->Append(desc, witness);
3611 SetNumberOfOwnDescriptors(number_of_own_descriptors + 1); 3657 SetNumberOfOwnDescriptors(number_of_own_descriptors + 1);
3612 } 3658 }
3613 3659
3614 3660
3615 Object* Map::GetBackPointer() { 3661 Object* Map::GetBackPointer() {
3616 Object* object = READ_FIELD(this, kTransitionsOrBackPointerOffset); 3662 Object* object = READ_FIELD(this, kTransitionsOrBackPointerOffset);
3617 if (object->IsDescriptorArray()) { 3663 if (object->IsDescriptorArray()) {
3618 return TransitionArray::cast(object)->back_pointer_storage(); 3664 return TransitionArray::cast(object)->back_pointer_storage();
3619 } else { 3665 } else {
3620 ASSERT(object->IsMap() || object->IsUndefined()); 3666 ASSERT(object->IsMap() || object->IsUndefined());
(...skipping 1883 matching lines...) Expand 10 before | Expand all | Expand 10 after
5504 #undef WRITE_UINT32_FIELD 5550 #undef WRITE_UINT32_FIELD
5505 #undef READ_SHORT_FIELD 5551 #undef READ_SHORT_FIELD
5506 #undef WRITE_SHORT_FIELD 5552 #undef WRITE_SHORT_FIELD
5507 #undef READ_BYTE_FIELD 5553 #undef READ_BYTE_FIELD
5508 #undef WRITE_BYTE_FIELD 5554 #undef WRITE_BYTE_FIELD
5509 5555
5510 5556
5511 } } // namespace v8::internal 5557 } } // namespace v8::internal
5512 5558
5513 #endif // V8_OBJECTS_INL_H_ 5559 #endif // V8_OBJECTS_INL_H_
OLDNEW
« no previous file with comments | « src/objects-debug.cc ('k') | test/cctest/test-alloc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698