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

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

Issue 1091253002: Fix GC-induced DCHECK failure in Runtime_GetWeakMapEntries (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 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 | « no previous file | no next file » | 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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, holder, 0); 259 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, holder, 0);
260 CONVERT_NUMBER_CHECKED(int, max_entries, Int32, args[1]); 260 CONVERT_NUMBER_CHECKED(int, max_entries, Int32, args[1]);
261 RUNTIME_ASSERT(max_entries >= 0); 261 RUNTIME_ASSERT(max_entries >= 0);
262 262
263 Handle<ObjectHashTable> table(ObjectHashTable::cast(holder->table())); 263 Handle<ObjectHashTable> table(ObjectHashTable::cast(holder->table()));
264 if (max_entries == 0 || max_entries > table->NumberOfElements()) { 264 if (max_entries == 0 || max_entries > table->NumberOfElements()) {
265 max_entries = table->NumberOfElements(); 265 max_entries = table->NumberOfElements();
266 } 266 }
267 Handle<FixedArray> entries = 267 Handle<FixedArray> entries =
268 isolate->factory()->NewFixedArray(max_entries * 2); 268 isolate->factory()->NewFixedArray(max_entries * 2);
269 // Allocation can cause GC can delete weak elements. Reload.
270 if (max_entries > table->NumberOfElements()) {
271 max_entries = table->NumberOfElements();
272 }
273
269 { 274 {
270 DisallowHeapAllocation no_gc; 275 DisallowHeapAllocation no_gc;
271 int count = 0; 276 int count = 0;
272 for (int i = 0; count / 2 < max_entries && i < table->Capacity(); i++) { 277 for (int i = 0; count / 2 < max_entries && i < table->Capacity(); i++) {
273 Handle<Object> key(table->KeyAt(i), isolate); 278 Handle<Object> key(table->KeyAt(i), isolate);
274 if (table->IsKey(*key)) { 279 if (table->IsKey(*key)) {
275 entries->set(count++, *key); 280 entries->set(count++, *key);
276 Object* value = table->Lookup(key); 281 Object* value = table->Lookup(key);
277 entries->set(count++, value); 282 entries->set(count++, value);
278 } 283 }
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 435
431 RUNTIME_FUNCTION(Runtime_ObservationWeakMapCreate) { 436 RUNTIME_FUNCTION(Runtime_ObservationWeakMapCreate) {
432 HandleScope scope(isolate); 437 HandleScope scope(isolate);
433 DCHECK(args.length() == 0); 438 DCHECK(args.length() == 0);
434 Handle<JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap(); 439 Handle<JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap();
435 Runtime::WeakCollectionInitialize(isolate, weakmap); 440 Runtime::WeakCollectionInitialize(isolate, weakmap);
436 return *weakmap; 441 return *weakmap;
437 } 442 }
438 } 443 }
439 } // namespace v8::internal 444 } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698