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

Side by Side Diff: src/runtime/runtime-collections.cc

Issue 686783003: Clear old backing store of WeakCollection on updates. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase Created 6 years, 1 month 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 | « no previous file | test/cctest/test-heap.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/runtime/runtime-utils.h" 8 #include "src/runtime/runtime-utils.h"
9 9
10 10
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); 281 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
282 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 282 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
283 RUNTIME_ASSERT(key->IsJSReceiver() || key->IsSymbol()); 283 RUNTIME_ASSERT(key->IsJSReceiver() || key->IsSymbol());
284 Handle<ObjectHashTable> table( 284 Handle<ObjectHashTable> table(
285 ObjectHashTable::cast(weak_collection->table())); 285 ObjectHashTable::cast(weak_collection->table()));
286 RUNTIME_ASSERT(table->IsKey(*key)); 286 RUNTIME_ASSERT(table->IsKey(*key));
287 bool was_present = false; 287 bool was_present = false;
288 Handle<ObjectHashTable> new_table = 288 Handle<ObjectHashTable> new_table =
289 ObjectHashTable::Remove(table, key, &was_present); 289 ObjectHashTable::Remove(table, key, &was_present);
290 weak_collection->set_table(*new_table); 290 weak_collection->set_table(*new_table);
291 if (*table != *new_table) {
292 // Zap the old table since we didn't record slots for its elements.
293 table->FillWithHoles(0, table->length());
294 }
291 return isolate->heap()->ToBoolean(was_present); 295 return isolate->heap()->ToBoolean(was_present);
292 } 296 }
293 297
294 298
295 RUNTIME_FUNCTION(Runtime_WeakCollectionSet) { 299 RUNTIME_FUNCTION(Runtime_WeakCollectionSet) {
296 HandleScope scope(isolate); 300 HandleScope scope(isolate);
297 DCHECK(args.length() == 3); 301 DCHECK(args.length() == 3);
298 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); 302 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
299 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 303 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
300 RUNTIME_ASSERT(key->IsJSReceiver() || key->IsSymbol()); 304 RUNTIME_ASSERT(key->IsJSReceiver() || key->IsSymbol());
301 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); 305 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
302 Handle<ObjectHashTable> table( 306 Handle<ObjectHashTable> table(
303 ObjectHashTable::cast(weak_collection->table())); 307 ObjectHashTable::cast(weak_collection->table()));
304 RUNTIME_ASSERT(table->IsKey(*key)); 308 RUNTIME_ASSERT(table->IsKey(*key));
305 Handle<ObjectHashTable> new_table = ObjectHashTable::Put(table, key, value); 309 Handle<ObjectHashTable> new_table = ObjectHashTable::Put(table, key, value);
306 weak_collection->set_table(*new_table); 310 weak_collection->set_table(*new_table);
311 if (*table != *new_table) {
312 // Zap the old table since we didn't record slots for its elements.
313 table->FillWithHoles(0, table->length());
314 }
307 return *weak_collection; 315 return *weak_collection;
308 } 316 }
309 317
310 318
311 RUNTIME_FUNCTION(Runtime_GetWeakSetValues) { 319 RUNTIME_FUNCTION(Runtime_GetWeakSetValues) {
312 HandleScope scope(isolate); 320 HandleScope scope(isolate);
313 DCHECK(args.length() == 1); 321 DCHECK(args.length() == 1);
314 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, holder, 0); 322 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, holder, 0);
315 Handle<ObjectHashTable> table(ObjectHashTable::cast(holder->table())); 323 Handle<ObjectHashTable> table(ObjectHashTable::cast(holder->table()));
316 Handle<FixedArray> values = 324 Handle<FixedArray> values =
(...skipping 20 matching lines...) Expand all
337 // isolate. If it's called more often, the map should be moved into the 345 // isolate. If it's called more often, the map should be moved into the
338 // strong root list. 346 // strong root list.
339 Handle<Map> map = 347 Handle<Map> map =
340 isolate->factory()->NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize); 348 isolate->factory()->NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize);
341 Handle<JSWeakMap> weakmap = 349 Handle<JSWeakMap> weakmap =
342 Handle<JSWeakMap>::cast(isolate->factory()->NewJSObjectFromMap(map)); 350 Handle<JSWeakMap>::cast(isolate->factory()->NewJSObjectFromMap(map));
343 return *WeakCollectionInitialize(isolate, weakmap); 351 return *WeakCollectionInitialize(isolate, weakmap);
344 } 352 }
345 } 353 }
346 } // namespace v8::internal 354 } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698