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

Side by Side Diff: src/objects.cc

Issue 1145183004: Debugger: use weak cells to implement ScriptCache. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 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 16393 matching lines...) Expand 10 before | Expand all | Expand 10 after
16404 16404
16405 void WeakHashTable::AddEntry(int entry, Handle<WeakCell> key_cell, 16405 void WeakHashTable::AddEntry(int entry, Handle<WeakCell> key_cell,
16406 Handle<HeapObject> value) { 16406 Handle<HeapObject> value) {
16407 DisallowHeapAllocation no_allocation; 16407 DisallowHeapAllocation no_allocation;
16408 set(EntryToIndex(entry), *key_cell); 16408 set(EntryToIndex(entry), *key_cell);
16409 set(EntryToValueIndex(entry), *value); 16409 set(EntryToValueIndex(entry), *value);
16410 ElementAdded(); 16410 ElementAdded();
16411 } 16411 }
16412 16412
16413 16413
16414 #ifdef DEBUG
16415 Object* WeakValueHashTable::LookupWeak(Handle<Object> key) {
16416 Object* value = Lookup(key);
16417 if (value->IsWeakCell() && !WeakCell::cast(value)->cleared()) {
16418 value = WeakCell::cast(value)->value();
16419 }
16420 return value;
16421 }
16422 #endif // DEBUG
16423
16424
16425 Handle<WeakValueHashTable> WeakValueHashTable::PutWeak(
16426 Handle<WeakValueHashTable> table, Handle<Object> key,
16427 Handle<HeapObject> value) {
16428 Handle<WeakCell> cell = value->GetIsolate()->factory()->NewWeakCell(value);
16429 return Handle<WeakValueHashTable>::cast(
16430 Put(Handle<ObjectHashTable>::cast(table), key, cell));
16431 }
16432
16433
16434 Handle<FixedArray> WeakValueHashTable::GetWeakValues(
16435 Handle<WeakValueHashTable> table) {
16436 Isolate* isolate = table->GetIsolate();
16437 uint32_t capacity = table->Capacity();
16438 Handle<FixedArray> results = isolate->factory()->NewFixedArray(capacity);
16439 int length = 0;
16440 for (uint32_t i = 0; i < capacity; i++) {
16441 uint32_t key_index = table->EntryToIndex(i);
16442 Object* key = table->get(key_index);
16443 if (!table->IsKey(key)) continue;
16444 uint32_t value_index = table->EntryToValueIndex(i);
16445 WeakCell* value_cell = WeakCell::cast(table->get(value_index));
16446 if (value_cell->cleared()) {
16447 table->RemoveEntry(i);
16448 } else {
16449 results->set(length++, value_cell->value());
16450 }
16451 }
16452 results->Shrink(length);
16453 return results;
16454 }
16455
16456
16414 template<class Derived, class Iterator, int entrysize> 16457 template<class Derived, class Iterator, int entrysize>
16415 Handle<Derived> OrderedHashTable<Derived, Iterator, entrysize>::Allocate( 16458 Handle<Derived> OrderedHashTable<Derived, Iterator, entrysize>::Allocate(
16416 Isolate* isolate, int capacity, PretenureFlag pretenure) { 16459 Isolate* isolate, int capacity, PretenureFlag pretenure) {
16417 // Capacity must be a power of two, since we depend on being able 16460 // Capacity must be a power of two, since we depend on being able
16418 // to divide and multiple by 2 (kLoadFactor) to derive capacity 16461 // to divide and multiple by 2 (kLoadFactor) to derive capacity
16419 // from number of buckets. If we decide to change kLoadFactor 16462 // from number of buckets. If we decide to change kLoadFactor
16420 // to something other than 2, capacity should be stored as another 16463 // to something other than 2, capacity should be stored as another
16421 // field of this object. 16464 // field of this object.
16422 capacity = base::bits::RoundUpToPowerOfTwo32(Max(kMinCapacity, capacity)); 16465 capacity = base::bits::RoundUpToPowerOfTwo32(Max(kMinCapacity, capacity));
16423 if (capacity > kMaxCapacity) { 16466 if (capacity > kMaxCapacity) {
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after
17253 void PropertyCell::SetValueWithInvalidation(Handle<PropertyCell> cell, 17296 void PropertyCell::SetValueWithInvalidation(Handle<PropertyCell> cell,
17254 Handle<Object> new_value) { 17297 Handle<Object> new_value) {
17255 if (cell->value() != *new_value) { 17298 if (cell->value() != *new_value) {
17256 cell->set_value(*new_value); 17299 cell->set_value(*new_value);
17257 Isolate* isolate = cell->GetIsolate(); 17300 Isolate* isolate = cell->GetIsolate();
17258 cell->dependent_code()->DeoptimizeDependentCodeGroup( 17301 cell->dependent_code()->DeoptimizeDependentCodeGroup(
17259 isolate, DependentCode::kPropertyCellChangedGroup); 17302 isolate, DependentCode::kPropertyCellChangedGroup);
17260 } 17303 }
17261 } 17304 }
17262 } } // namespace v8::internal 17305 } } // 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