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

Side by Side Diff: src/objects.cc

Issue 1297273005: Keep track of script objects in a weak fixed array. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: do not remove gc. Created 5 years, 4 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
« 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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <iomanip> 5 #include <iomanip>
6 #include <sstream> 6 #include <sstream>
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/accessors.h" 10 #include "src/accessors.h"
(...skipping 14825 matching lines...) Expand 10 before | Expand all | Expand 10 after
14836 14836
14837 void WeakHashTable::AddEntry(int entry, Handle<WeakCell> key_cell, 14837 void WeakHashTable::AddEntry(int entry, Handle<WeakCell> key_cell,
14838 Handle<HeapObject> value) { 14838 Handle<HeapObject> value) {
14839 DisallowHeapAllocation no_allocation; 14839 DisallowHeapAllocation no_allocation;
14840 set(EntryToIndex(entry), *key_cell); 14840 set(EntryToIndex(entry), *key_cell);
14841 set(EntryToValueIndex(entry), *value); 14841 set(EntryToValueIndex(entry), *value);
14842 ElementAdded(); 14842 ElementAdded();
14843 } 14843 }
14844 14844
14845 14845
14846 #ifdef DEBUG
14847 Object* WeakValueHashTable::LookupWeak(Handle<Object> key) {
14848 Object* value = Lookup(key);
14849 if (value->IsWeakCell() && !WeakCell::cast(value)->cleared()) {
14850 value = WeakCell::cast(value)->value();
14851 }
14852 return value;
14853 }
14854 #endif // DEBUG
14855
14856
14857 Handle<WeakValueHashTable> WeakValueHashTable::PutWeak(
14858 Handle<WeakValueHashTable> table, Handle<Object> key,
14859 Handle<HeapObject> value) {
14860 Handle<WeakCell> cell = value->GetIsolate()->factory()->NewWeakCell(value);
14861 return Handle<WeakValueHashTable>::cast(
14862 Put(Handle<ObjectHashTable>::cast(table), key, cell));
14863 }
14864
14865
14866 Handle<FixedArray> WeakValueHashTable::GetWeakValues(
14867 Handle<WeakValueHashTable> table) {
14868 Isolate* isolate = table->GetIsolate();
14869 uint32_t capacity = table->Capacity();
14870 Handle<FixedArray> results = isolate->factory()->NewFixedArray(capacity);
14871 int length = 0;
14872 for (uint32_t i = 0; i < capacity; i++) {
14873 uint32_t key_index = table->EntryToIndex(i);
14874 Object* key = table->get(key_index);
14875 if (!table->IsKey(key)) continue;
14876 uint32_t value_index = table->EntryToValueIndex(i);
14877 WeakCell* value_cell = WeakCell::cast(table->get(value_index));
14878 if (value_cell->cleared()) {
14879 table->RemoveEntry(i);
14880 } else {
14881 results->set(length++, value_cell->value());
14882 }
14883 }
14884 results->Shrink(length);
14885 return results;
14886 }
14887
14888
14889 template<class Derived, class Iterator, int entrysize> 14846 template<class Derived, class Iterator, int entrysize>
14890 Handle<Derived> OrderedHashTable<Derived, Iterator, entrysize>::Allocate( 14847 Handle<Derived> OrderedHashTable<Derived, Iterator, entrysize>::Allocate(
14891 Isolate* isolate, int capacity, PretenureFlag pretenure) { 14848 Isolate* isolate, int capacity, PretenureFlag pretenure) {
14892 // Capacity must be a power of two, since we depend on being able 14849 // Capacity must be a power of two, since we depend on being able
14893 // to divide and multiple by 2 (kLoadFactor) to derive capacity 14850 // to divide and multiple by 2 (kLoadFactor) to derive capacity
14894 // from number of buckets. If we decide to change kLoadFactor 14851 // from number of buckets. If we decide to change kLoadFactor
14895 // to something other than 2, capacity should be stored as another 14852 // to something other than 2, capacity should be stored as another
14896 // field of this object. 14853 // field of this object.
14897 capacity = base::bits::RoundUpToPowerOfTwo32(Max(kMinCapacity, capacity)); 14854 capacity = base::bits::RoundUpToPowerOfTwo32(Max(kMinCapacity, capacity));
14898 if (capacity > kMaxCapacity) { 14855 if (capacity > kMaxCapacity) {
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
15717 if (cell->value() != *new_value) { 15674 if (cell->value() != *new_value) {
15718 cell->set_value(*new_value); 15675 cell->set_value(*new_value);
15719 Isolate* isolate = cell->GetIsolate(); 15676 Isolate* isolate = cell->GetIsolate();
15720 cell->dependent_code()->DeoptimizeDependentCodeGroup( 15677 cell->dependent_code()->DeoptimizeDependentCodeGroup(
15721 isolate, DependentCode::kPropertyCellChangedGroup); 15678 isolate, DependentCode::kPropertyCellChangedGroup);
15722 } 15679 }
15723 } 15680 }
15724 15681
15725 } // namespace internal 15682 } // namespace internal
15726 } // namespace v8 15683 } // namespace v8
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