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

Side by Side Diff: src/objects.cc

Issue 523122: Merge r3536 and r3538 to branches/1.3 to fix performance issue... (Closed) Base URL: http://v8.googlecode.com/svn/branches/1.3/
Patch Set: Created 10 years, 11 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/runtime.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 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 6920 matching lines...) Expand 10 before | Expand all | Expand 10 after
6931 6931
6932 6932
6933 template<typename Shape, typename Key> 6933 template<typename Shape, typename Key>
6934 Object* HashTable<Shape, Key>::Allocate( 6934 Object* HashTable<Shape, Key>::Allocate(
6935 int at_least_space_for) { 6935 int at_least_space_for) {
6936 int capacity = RoundUpToPowerOf2(at_least_space_for); 6936 int capacity = RoundUpToPowerOf2(at_least_space_for);
6937 if (capacity < 4) capacity = 4; // Guarantee min capacity. 6937 if (capacity < 4) capacity = 4; // Guarantee min capacity.
6938 Object* obj = Heap::AllocateHashTable(EntryToIndex(capacity)); 6938 Object* obj = Heap::AllocateHashTable(EntryToIndex(capacity));
6939 if (!obj->IsFailure()) { 6939 if (!obj->IsFailure()) {
6940 HashTable::cast(obj)->SetNumberOfElements(0); 6940 HashTable::cast(obj)->SetNumberOfElements(0);
6941 HashTable::cast(obj)->SetNumberOfDeletedElements(0);
6941 HashTable::cast(obj)->SetCapacity(capacity); 6942 HashTable::cast(obj)->SetCapacity(capacity);
6942 } 6943 }
6943 return obj; 6944 return obj;
6944 } 6945 }
6945 6946
6946 6947
6947 6948
6948 // Find entry for key otherwise return -1. 6949 // Find entry for key otherwise return -1.
6949 template<typename Shape, typename Key> 6950 template<typename Shape, typename Key>
6950 int HashTable<Shape, Key>::FindEntry(Key key) { 6951 int HashTable<Shape, Key>::FindEntry(Key key) {
(...skipping 19 matching lines...) Expand all
6970 } 6971 }
6971 } 6972 }
6972 return kNotFound; 6973 return kNotFound;
6973 } 6974 }
6974 6975
6975 6976
6976 template<typename Shape, typename Key> 6977 template<typename Shape, typename Key>
6977 Object* HashTable<Shape, Key>::EnsureCapacity(int n, Key key) { 6978 Object* HashTable<Shape, Key>::EnsureCapacity(int n, Key key) {
6978 int capacity = Capacity(); 6979 int capacity = Capacity();
6979 int nof = NumberOfElements() + n; 6980 int nof = NumberOfElements() + n;
6980 // Make sure 50% is free 6981 int nod = NumberOfDeletedElements();
6981 if (nof + (nof >> 1) <= capacity) return this; 6982 // Return if:
6983 // 50% is still free after adding n elements and
6984 // at most 50% of the free elements are deleted elements.
6985 if ((nof + (nof >> 1) <= capacity) &&
6986 (nod <= (capacity - nof) >> 1)) return this;
6982 6987
6983 Object* obj = Allocate(nof * 2); 6988 Object* obj = Allocate(nof * 2);
6984 if (obj->IsFailure()) return obj; 6989 if (obj->IsFailure()) return obj;
6985 HashTable* table = HashTable::cast(obj); 6990 HashTable* table = HashTable::cast(obj);
6986 WriteBarrierMode mode = table->GetWriteBarrierMode(); 6991 WriteBarrierMode mode = table->GetWriteBarrierMode();
6987 6992
6988 // Copy prefix to new array. 6993 // Copy prefix to new array.
6989 for (int i = kPrefixStartIndex; 6994 for (int i = kPrefixStartIndex;
6990 i < kPrefixStartIndex + Shape::kPrefixSize; 6995 i < kPrefixStartIndex + Shape::kPrefixSize;
6991 i++) { 6996 i++) {
6992 table->set(i, get(i), mode); 6997 table->set(i, get(i), mode);
6993 } 6998 }
6994 // Rehash the elements. 6999 // Rehash the elements.
6995 for (int i = 0; i < capacity; i++) { 7000 for (int i = 0; i < capacity; i++) {
6996 uint32_t from_index = EntryToIndex(i); 7001 uint32_t from_index = EntryToIndex(i);
6997 Object* k = get(from_index); 7002 Object* k = get(from_index);
6998 if (IsKey(k)) { 7003 if (IsKey(k)) {
6999 uint32_t hash = Shape::HashForObject(key, k); 7004 uint32_t hash = Shape::HashForObject(key, k);
7000 uint32_t insertion_index = 7005 uint32_t insertion_index =
7001 EntryToIndex(table->FindInsertionEntry(hash)); 7006 EntryToIndex(table->FindInsertionEntry(hash));
7002 for (int j = 0; j < Shape::kEntrySize; j++) { 7007 for (int j = 0; j < Shape::kEntrySize; j++) {
7003 table->set(insertion_index + j, get(from_index + j), mode); 7008 table->set(insertion_index + j, get(from_index + j), mode);
7004 } 7009 }
7005 } 7010 }
7006 } 7011 }
7007 table->SetNumberOfElements(NumberOfElements()); 7012 table->SetNumberOfElements(NumberOfElements());
7013 table->SetNumberOfDeletedElements(0);
7008 return table; 7014 return table;
7009 } 7015 }
7010 7016
7011 7017
7012 template<typename Shape, typename Key> 7018 template<typename Shape, typename Key>
7013 uint32_t HashTable<Shape, Key>::FindInsertionEntry(uint32_t hash) { 7019 uint32_t HashTable<Shape, Key>::FindInsertionEntry(uint32_t hash) {
7014 uint32_t capacity = Capacity(); 7020 uint32_t capacity = Capacity();
7015 uint32_t entry = GetProbe(hash, 0, capacity); 7021 uint32_t entry = GetProbe(hash, 0, capacity);
7016 Object* element = KeyAt(entry); 7022 Object* element = KeyAt(entry);
7017 7023
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
7716 if (key->IsNumber()) { 7722 if (key->IsNumber()) {
7717 uint32_t number = static_cast<uint32_t>(key->Number()); 7723 uint32_t number = static_cast<uint32_t>(key->Number());
7718 if (from <= number && number < to) { 7724 if (from <= number && number < to) {
7719 SetEntry(i, sentinel, sentinel, Smi::FromInt(0)); 7725 SetEntry(i, sentinel, sentinel, Smi::FromInt(0));
7720 removed_entries++; 7726 removed_entries++;
7721 } 7727 }
7722 } 7728 }
7723 } 7729 }
7724 7730
7725 // Update the number of elements. 7731 // Update the number of elements.
7726 SetNumberOfElements(NumberOfElements() - removed_entries); 7732 ElementsRemoved(removed_entries);
7727 } 7733 }
7728 7734
7729 7735
7730 template<typename Shape, typename Key> 7736 template<typename Shape, typename Key>
7731 Object* Dictionary<Shape, Key>::DeleteProperty(int entry, 7737 Object* Dictionary<Shape, Key>::DeleteProperty(int entry,
7732 JSObject::DeleteMode mode) { 7738 JSObject::DeleteMode mode) {
7733 PropertyDetails details = DetailsAt(entry); 7739 PropertyDetails details = DetailsAt(entry);
7734 // Ignore attributes if forcing a deletion. 7740 // Ignore attributes if forcing a deletion.
7735 if (details.IsDontDelete() && mode == JSObject::NORMAL_DELETION) { 7741 if (details.IsDontDelete() && mode == JSObject::NORMAL_DELETION) {
7736 return Heap::false_value(); 7742 return Heap::false_value();
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
8311 if (break_point_objects()->IsUndefined()) return 0; 8317 if (break_point_objects()->IsUndefined()) return 0;
8312 // Single beak point. 8318 // Single beak point.
8313 if (!break_point_objects()->IsFixedArray()) return 1; 8319 if (!break_point_objects()->IsFixedArray()) return 1;
8314 // Multiple break points. 8320 // Multiple break points.
8315 return FixedArray::cast(break_point_objects())->length(); 8321 return FixedArray::cast(break_point_objects())->length();
8316 } 8322 }
8317 #endif 8323 #endif
8318 8324
8319 8325
8320 } } // namespace v8::internal 8326 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698