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

Side by Side Diff: src/objects.cc

Issue 23477061: Make objects embedded in optimized code weak. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix names Created 7 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
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 7687 matching lines...) Expand 10 before | Expand all | Expand 10 after
7698 for (int i = 0; i < result->length(); i++) { 7698 for (int i = 0; i < result->length(); i++) {
7699 Object* current = result->get(i); 7699 Object* current = result->get(i);
7700 ASSERT(current->IsNumber() || current->IsName()); 7700 ASSERT(current->IsNumber() || current->IsName());
7701 } 7701 }
7702 } 7702 }
7703 #endif 7703 #endif
7704 return result; 7704 return result;
7705 } 7705 }
7706 7706
7707 7707
7708 MaybeObject* FixedArray::CopySize(int new_length) { 7708 MaybeObject* FixedArray::CopySize(int new_length, PretenureFlag pretenure) {
7709 Heap* heap = GetHeap(); 7709 Heap* heap = GetHeap();
7710 if (new_length == 0) return heap->empty_fixed_array(); 7710 if (new_length == 0) return heap->empty_fixed_array();
7711 Object* obj; 7711 Object* obj;
7712 { MaybeObject* maybe_obj = heap->AllocateFixedArray(new_length); 7712 { MaybeObject* maybe_obj = heap->AllocateFixedArray(new_length, pretenure);
7713 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 7713 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
7714 } 7714 }
7715 FixedArray* result = FixedArray::cast(obj); 7715 FixedArray* result = FixedArray::cast(obj);
7716 // Copy the content 7716 // Copy the content
7717 DisallowHeapAllocation no_gc; 7717 DisallowHeapAllocation no_gc;
7718 int len = length(); 7718 int len = length();
7719 if (new_length < len) len = new_length; 7719 if (new_length < len) len = new_length;
7720 // We are taking the map from the old fixed array so the map is sure to 7720 // We are taking the map from the old fixed array so the map is sure to
7721 // be an immortal immutable object. 7721 // be an immortal immutable object.
7722 result->set_map_no_write_barrier(map()); 7722 result->set_map_no_write_barrier(map());
(...skipping 3263 matching lines...) Expand 10 before | Expand all | Expand 10 after
10986 GetElementsKind(), new_elements); 10986 GetElementsKind(), new_elements);
10987 } 10987 }
10988 10988
10989 if (IsJSArray()) { 10989 if (IsJSArray()) {
10990 JSArray::cast(this)->set_length(Smi::FromInt(length)); 10990 JSArray::cast(this)->set_length(Smi::FromInt(length));
10991 } 10991 }
10992 return new_elements; 10992 return new_elements;
10993 } 10993 }
10994 10994
10995 10995
10996 bool Code::IsWeakEmbeddedObject(Kind kind, Object* object) {
10997 if (kind != Code::OPTIMIZED_FUNCTION) return false;
10998
10999 if (object->IsMap()) {
11000 return Map::cast(object)->CanTransition() &&
11001 FLAG_collect_maps &&
11002 FLAG_weak_embedded_maps_in_optimized_code;
11003 }
11004
11005 if (object->IsJSObject()) {
11006 return FLAG_weak_embedded_objects_in_optimized_code;
11007 }
11008
11009 return false;
11010 }
11011
10996 MaybeObject* JSObject::SetFastDoubleElementsCapacityAndLength( 11012 MaybeObject* JSObject::SetFastDoubleElementsCapacityAndLength(
10997 int capacity, 11013 int capacity,
10998 int length) { 11014 int length) {
10999 Heap* heap = GetHeap(); 11015 Heap* heap = GetHeap();
11000 // We should never end in here with a pixel or external array. 11016 // We should never end in here with a pixel or external array.
11001 ASSERT(!HasExternalArrayElements()); 11017 ASSERT(!HasExternalArrayElements());
11002 ASSERT(!map()->is_observed()); 11018 ASSERT(!map()->is_observed());
11003 11019
11004 FixedArrayBase* elems; 11020 FixedArrayBase* elems;
11005 { MaybeObject* maybe_obj = 11021 { MaybeObject* maybe_obj =
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
11346 // Do not append the compilation info if it is already in the array. 11362 // Do not append the compilation info if it is already in the array.
11347 // It is sufficient to just check only the last element because 11363 // It is sufficient to just check only the last element because
11348 // we process embedded maps of an optimized code in one batch. 11364 // we process embedded maps of an optimized code in one batch.
11349 return entries; 11365 return entries;
11350 } 11366 }
11351 if (entries->length() < kCodesStartIndex + number_of_entries + 1) { 11367 if (entries->length() < kCodesStartIndex + number_of_entries + 1) {
11352 Factory* factory = entries->GetIsolate()->factory(); 11368 Factory* factory = entries->GetIsolate()->factory();
11353 int capacity = kCodesStartIndex + number_of_entries + 1; 11369 int capacity = kCodesStartIndex + number_of_entries + 1;
11354 if (capacity > 5) capacity = capacity * 5 / 4; 11370 if (capacity > 5) capacity = capacity * 5 / 4;
11355 Handle<DependentCode> new_entries = Handle<DependentCode>::cast( 11371 Handle<DependentCode> new_entries = Handle<DependentCode>::cast(
11356 factory->CopySizeFixedArray(entries, capacity)); 11372 factory->CopySizeFixedArray(entries, capacity, TENURED));
11357 // The number of codes can change after GC. 11373 // The number of codes can change after GC.
11358 starts.Recompute(*entries); 11374 starts.Recompute(*entries);
11359 start = starts.at(group); 11375 start = starts.at(group);
11360 end = starts.at(group + 1); 11376 end = starts.at(group + 1);
11361 number_of_entries = starts.number_of_entries(); 11377 number_of_entries = starts.number_of_entries();
11362 for (int i = 0; i < number_of_entries; i++) { 11378 for (int i = 0; i < number_of_entries; i++) {
11363 entries->clear_at(i); 11379 entries->clear_at(i);
11364 } 11380 }
11365 // If the old fixed array was empty, we need to reset counters of the 11381 // If the old fixed array was empty, we need to reset counters of the
11366 // new array. 11382 // new array.
(...skipping 2500 matching lines...) Expand 10 before | Expand all | Expand 10 after
13867 // for the next probe. 13883 // for the next probe.
13868 done = false; 13884 done = false;
13869 } 13885 }
13870 } 13886 }
13871 } 13887 }
13872 } 13888 }
13873 } 13889 }
13874 13890
13875 13891
13876 template<typename Shape, typename Key> 13892 template<typename Shape, typename Key>
13877 MaybeObject* HashTable<Shape, Key>::EnsureCapacity(int n, Key key) { 13893 MaybeObject* HashTable<Shape, Key>::EnsureCapacity(int n,
13894 Key key,
13895 PretenureFlag pretenure) {
13878 int capacity = Capacity(); 13896 int capacity = Capacity();
13879 int nof = NumberOfElements() + n; 13897 int nof = NumberOfElements() + n;
13880 int nod = NumberOfDeletedElements(); 13898 int nod = NumberOfDeletedElements();
13881 // Return if: 13899 // Return if:
13882 // 50% is still free after adding n elements and 13900 // 50% is still free after adding n elements and
13883 // at most 50% of the free elements are deleted elements. 13901 // at most 50% of the free elements are deleted elements.
13884 if (nod <= (capacity - nof) >> 1) { 13902 if (nod <= (capacity - nof) >> 1) {
13885 int needed_free = nof >> 1; 13903 int needed_free = nof >> 1;
13886 if (nof + needed_free <= capacity) return this; 13904 if (nof + needed_free <= capacity) return this;
13887 } 13905 }
13888 13906
13889 const int kMinCapacityForPretenure = 256; 13907 const int kMinCapacityForPretenure = 256;
13890 bool pretenure = 13908 bool should_pretenure = pretenure == TENURED ||
13891 (capacity > kMinCapacityForPretenure) && !GetHeap()->InNewSpace(this); 13909 ((capacity > kMinCapacityForPretenure) && !GetHeap()->InNewSpace(this));
13892 Object* obj; 13910 Object* obj;
13893 { MaybeObject* maybe_obj = 13911 { MaybeObject* maybe_obj =
13894 Allocate(GetHeap(), 13912 Allocate(GetHeap(),
13895 nof * 2, 13913 nof * 2,
13896 USE_DEFAULT_MINIMUM_CAPACITY, 13914 USE_DEFAULT_MINIMUM_CAPACITY,
13897 pretenure ? TENURED : NOT_TENURED); 13915 should_pretenure ? TENURED : NOT_TENURED);
13898 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 13916 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
13899 } 13917 }
13900 13918
13901 return Rehash(HashTable::cast(obj), key); 13919 return Rehash(HashTable::cast(obj), key);
13902 } 13920 }
13903 13921
13904 13922
13905 template<typename Shape, typename Key> 13923 template<typename Shape, typename Key>
13906 MaybeObject* HashTable<Shape, Key>::Shrink(Key key) { 13924 MaybeObject* HashTable<Shape, Key>::Shrink(Key key) {
13907 int capacity = Capacity(); 13925 int capacity = Capacity();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
13955 template class HashTable<StringTableShape, HashTableKey*>; 13973 template class HashTable<StringTableShape, HashTableKey*>;
13956 13974
13957 template class HashTable<CompilationCacheShape, HashTableKey*>; 13975 template class HashTable<CompilationCacheShape, HashTableKey*>;
13958 13976
13959 template class HashTable<MapCacheShape, HashTableKey*>; 13977 template class HashTable<MapCacheShape, HashTableKey*>;
13960 13978
13961 template class HashTable<ObjectHashTableShape<1>, Object*>; 13979 template class HashTable<ObjectHashTableShape<1>, Object*>;
13962 13980
13963 template class HashTable<ObjectHashTableShape<2>, Object*>; 13981 template class HashTable<ObjectHashTableShape<2>, Object*>;
13964 13982
13983 template class HashTable<WeakHashTableShape<2>, Object*>;
13984
13965 template class Dictionary<NameDictionaryShape, Name*>; 13985 template class Dictionary<NameDictionaryShape, Name*>;
13966 13986
13967 template class Dictionary<SeededNumberDictionaryShape, uint32_t>; 13987 template class Dictionary<SeededNumberDictionaryShape, uint32_t>;
13968 13988
13969 template class Dictionary<UnseededNumberDictionaryShape, uint32_t>; 13989 template class Dictionary<UnseededNumberDictionaryShape, uint32_t>;
13970 13990
13971 template MaybeObject* Dictionary<SeededNumberDictionaryShape, uint32_t>:: 13991 template MaybeObject* Dictionary<SeededNumberDictionaryShape, uint32_t>::
13972 Allocate(Heap* heap, int at_least_space_for, PretenureFlag pretenure); 13992 Allocate(Heap* heap, int at_least_space_for, PretenureFlag pretenure);
13973 13993
13974 template MaybeObject* Dictionary<UnseededNumberDictionaryShape, uint32_t>:: 13994 template MaybeObject* Dictionary<UnseededNumberDictionaryShape, uint32_t>::
(...skipping 1633 matching lines...) Expand 10 before | Expand all | Expand 10 after
15608 } 15628 }
15609 15629
15610 15630
15611 void ObjectHashTable::RemoveEntry(int entry) { 15631 void ObjectHashTable::RemoveEntry(int entry) {
15612 set_the_hole(EntryToIndex(entry)); 15632 set_the_hole(EntryToIndex(entry));
15613 set_the_hole(EntryToIndex(entry) + 1); 15633 set_the_hole(EntryToIndex(entry) + 1);
15614 ElementRemoved(); 15634 ElementRemoved();
15615 } 15635 }
15616 15636
15617 15637
15638 Object* WeakHashTable::Lookup(Object* key) {
15639 ASSERT(IsKey(key));
15640 int entry = FindEntry(key);
15641 if (entry == kNotFound) return GetHeap()->the_hole_value();
15642 return get(EntryToValueIndex(entry));
15643 }
15644
15645
15646 MaybeObject* WeakHashTable::Put(Object* key, Object* value) {
15647 ASSERT(IsKey(key));
15648 int entry = FindEntry(key);
15649 // Key is already in table, just overwrite value.
15650 if (entry != kNotFound) {
15651 set(EntryToValueIndex(entry), value);
15652 return this;
15653 }
15654
15655 // Check whether the hash table should be extended.
15656 Object* obj;
15657 { MaybeObject* maybe_obj = EnsureCapacity(1, key, TENURED);
15658 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
15659 }
15660 WeakHashTable* table = WeakHashTable::cast(obj);
15661 table->AddEntry(table->FindInsertionEntry(Hash(key)), key, value);
15662 return table;
15663 }
15664
15665
15666 void WeakHashTable::AddEntry(int entry, Object* key, Object* value) {
15667 set(EntryToIndex(entry), key);
15668 set(EntryToValueIndex(entry), value);
15669 ElementAdded();
15670 }
15671
15672
15618 DeclaredAccessorDescriptorIterator::DeclaredAccessorDescriptorIterator( 15673 DeclaredAccessorDescriptorIterator::DeclaredAccessorDescriptorIterator(
15619 DeclaredAccessorDescriptor* descriptor) 15674 DeclaredAccessorDescriptor* descriptor)
15620 : array_(descriptor->serialized_data()->GetDataStartAddress()), 15675 : array_(descriptor->serialized_data()->GetDataStartAddress()),
15621 length_(descriptor->serialized_data()->length()), 15676 length_(descriptor->serialized_data()->length()),
15622 offset_(0) { 15677 offset_(0) {
15623 } 15678 }
15624 15679
15625 15680
15626 const DeclaredAccessorDescriptorData* 15681 const DeclaredAccessorDescriptorData*
15627 DeclaredAccessorDescriptorIterator::Next() { 15682 DeclaredAccessorDescriptorIterator::Next() {
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
16156 #define ERROR_MESSAGES_TEXTS(C, T) T, 16211 #define ERROR_MESSAGES_TEXTS(C, T) T,
16157 static const char* error_messages_[] = { 16212 static const char* error_messages_[] = {
16158 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 16213 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
16159 }; 16214 };
16160 #undef ERROR_MESSAGES_TEXTS 16215 #undef ERROR_MESSAGES_TEXTS
16161 return error_messages_[reason]; 16216 return error_messages_[reason];
16162 } 16217 }
16163 16218
16164 16219
16165 } } // namespace v8::internal 16220 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698