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

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

Issue 1149863005: Move hash code from hidden string to a private symbol (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix merge 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/runtime/runtime.h ('k') | src/runtime/runtime-symbol.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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 HandleScope scope(isolate); 289 HandleScope scope(isolate);
290 DCHECK(args.length() == 1); 290 DCHECK(args.length() == 1);
291 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); 291 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
292 Runtime::WeakCollectionInitialize(isolate, weak_collection); 292 Runtime::WeakCollectionInitialize(isolate, weak_collection);
293 return *weak_collection; 293 return *weak_collection;
294 } 294 }
295 295
296 296
297 RUNTIME_FUNCTION(Runtime_WeakCollectionGet) { 297 RUNTIME_FUNCTION(Runtime_WeakCollectionGet) {
298 HandleScope scope(isolate); 298 HandleScope scope(isolate);
299 DCHECK(args.length() == 2); 299 DCHECK(args.length() == 3);
300 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); 300 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
301 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 301 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
302 CONVERT_SMI_ARG_CHECKED(hash, 2)
302 RUNTIME_ASSERT(key->IsJSReceiver() || key->IsSymbol()); 303 RUNTIME_ASSERT(key->IsJSReceiver() || key->IsSymbol());
303 Handle<ObjectHashTable> table( 304 Handle<ObjectHashTable> table(
304 ObjectHashTable::cast(weak_collection->table())); 305 ObjectHashTable::cast(weak_collection->table()));
305 RUNTIME_ASSERT(table->IsKey(*key)); 306 RUNTIME_ASSERT(table->IsKey(*key));
306 Handle<Object> lookup(table->Lookup(key), isolate); 307 Handle<Object> lookup(table->Lookup(key, hash), isolate);
307 return lookup->IsTheHole() ? isolate->heap()->undefined_value() : *lookup; 308 return lookup->IsTheHole() ? isolate->heap()->undefined_value() : *lookup;
308 } 309 }
309 310
310 311
311 RUNTIME_FUNCTION(Runtime_WeakCollectionHas) { 312 RUNTIME_FUNCTION(Runtime_WeakCollectionHas) {
312 HandleScope scope(isolate); 313 HandleScope scope(isolate);
313 DCHECK(args.length() == 2); 314 DCHECK(args.length() == 3);
314 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); 315 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
315 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 316 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
317 CONVERT_SMI_ARG_CHECKED(hash, 2)
316 RUNTIME_ASSERT(key->IsJSReceiver() || key->IsSymbol()); 318 RUNTIME_ASSERT(key->IsJSReceiver() || key->IsSymbol());
317 Handle<ObjectHashTable> table( 319 Handle<ObjectHashTable> table(
318 ObjectHashTable::cast(weak_collection->table())); 320 ObjectHashTable::cast(weak_collection->table()));
319 RUNTIME_ASSERT(table->IsKey(*key)); 321 RUNTIME_ASSERT(table->IsKey(*key));
320 Handle<Object> lookup(table->Lookup(key), isolate); 322 Handle<Object> lookup(table->Lookup(key, hash), isolate);
321 return isolate->heap()->ToBoolean(!lookup->IsTheHole()); 323 return isolate->heap()->ToBoolean(!lookup->IsTheHole());
322 } 324 }
323 325
324 326
325 bool Runtime::WeakCollectionDelete(Handle<JSWeakCollection> weak_collection, 327 bool Runtime::WeakCollectionDelete(Handle<JSWeakCollection> weak_collection,
326 Handle<Object> key) { 328 Handle<Object> key) {
329 int32_t hash =
330 Object::GetOrCreateHash(weak_collection->GetIsolate(), key)->value();
331 return WeakCollectionDelete(weak_collection, key, hash);
332 }
333
334
335 bool Runtime::WeakCollectionDelete(Handle<JSWeakCollection> weak_collection,
336 Handle<Object> key, int32_t hash) {
327 DCHECK(key->IsJSReceiver() || key->IsSymbol()); 337 DCHECK(key->IsJSReceiver() || key->IsSymbol());
328 Handle<ObjectHashTable> table( 338 Handle<ObjectHashTable> table(
329 ObjectHashTable::cast(weak_collection->table())); 339 ObjectHashTable::cast(weak_collection->table()));
330 DCHECK(table->IsKey(*key)); 340 DCHECK(table->IsKey(*key));
331 bool was_present = false; 341 bool was_present = false;
332 Handle<ObjectHashTable> new_table = 342 Handle<ObjectHashTable> new_table =
333 ObjectHashTable::Remove(table, key, &was_present); 343 ObjectHashTable::Remove(table, key, &was_present, hash);
334 weak_collection->set_table(*new_table); 344 weak_collection->set_table(*new_table);
335 if (*table != *new_table) { 345 if (*table != *new_table) {
336 // Zap the old table since we didn't record slots for its elements. 346 // Zap the old table since we didn't record slots for its elements.
337 table->FillWithHoles(0, table->length()); 347 table->FillWithHoles(0, table->length());
338 } 348 }
339 return was_present; 349 return was_present;
340 } 350 }
341 351
342 352
343 RUNTIME_FUNCTION(Runtime_WeakCollectionDelete) { 353 RUNTIME_FUNCTION(Runtime_WeakCollectionDelete) {
344 HandleScope scope(isolate); 354 HandleScope scope(isolate);
345 DCHECK(args.length() == 2); 355 DCHECK(args.length() == 3);
346 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); 356 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
347 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 357 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
358 CONVERT_SMI_ARG_CHECKED(hash, 2)
348 RUNTIME_ASSERT(key->IsJSReceiver() || key->IsSymbol()); 359 RUNTIME_ASSERT(key->IsJSReceiver() || key->IsSymbol());
349 Handle<ObjectHashTable> table( 360 Handle<ObjectHashTable> table(
350 ObjectHashTable::cast(weak_collection->table())); 361 ObjectHashTable::cast(weak_collection->table()));
351 RUNTIME_ASSERT(table->IsKey(*key)); 362 RUNTIME_ASSERT(table->IsKey(*key));
352 bool was_present = Runtime::WeakCollectionDelete(weak_collection, key); 363 bool was_present = Runtime::WeakCollectionDelete(weak_collection, key, hash);
353 return isolate->heap()->ToBoolean(was_present); 364 return isolate->heap()->ToBoolean(was_present);
354 } 365 }
355 366
356 367
357 void Runtime::WeakCollectionSet(Handle<JSWeakCollection> weak_collection, 368 void Runtime::WeakCollectionSet(Handle<JSWeakCollection> weak_collection,
358 Handle<Object> key, Handle<Object> value) { 369 Handle<Object> key, Handle<Object> value,
370 int32_t hash) {
359 DCHECK(key->IsJSReceiver() || key->IsSymbol()); 371 DCHECK(key->IsJSReceiver() || key->IsSymbol());
360 Handle<ObjectHashTable> table( 372 Handle<ObjectHashTable> table(
361 ObjectHashTable::cast(weak_collection->table())); 373 ObjectHashTable::cast(weak_collection->table()));
362 DCHECK(table->IsKey(*key)); 374 DCHECK(table->IsKey(*key));
363 Handle<ObjectHashTable> new_table = ObjectHashTable::Put(table, key, value); 375 Handle<ObjectHashTable> new_table =
376 ObjectHashTable::Put(table, key, value, hash);
364 weak_collection->set_table(*new_table); 377 weak_collection->set_table(*new_table);
365 if (*table != *new_table) { 378 if (*table != *new_table) {
366 // Zap the old table since we didn't record slots for its elements. 379 // Zap the old table since we didn't record slots for its elements.
367 table->FillWithHoles(0, table->length()); 380 table->FillWithHoles(0, table->length());
368 } 381 }
369 } 382 }
370 383
371 384
372 RUNTIME_FUNCTION(Runtime_WeakCollectionSet) { 385 RUNTIME_FUNCTION(Runtime_WeakCollectionSet) {
373 HandleScope scope(isolate); 386 HandleScope scope(isolate);
374 DCHECK(args.length() == 3); 387 DCHECK(args.length() == 4);
375 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0); 388 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
376 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); 389 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
377 RUNTIME_ASSERT(key->IsJSReceiver() || key->IsSymbol()); 390 RUNTIME_ASSERT(key->IsJSReceiver() || key->IsSymbol());
378 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); 391 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
392 CONVERT_SMI_ARG_CHECKED(hash, 3)
379 Handle<ObjectHashTable> table( 393 Handle<ObjectHashTable> table(
380 ObjectHashTable::cast(weak_collection->table())); 394 ObjectHashTable::cast(weak_collection->table()));
381 RUNTIME_ASSERT(table->IsKey(*key)); 395 RUNTIME_ASSERT(table->IsKey(*key));
382 Runtime::WeakCollectionSet(weak_collection, key, value); 396 Runtime::WeakCollectionSet(weak_collection, key, value, hash);
383 return *weak_collection; 397 return *weak_collection;
384 } 398 }
385 399
386 400
387 RUNTIME_FUNCTION(Runtime_GetWeakSetValues) { 401 RUNTIME_FUNCTION(Runtime_GetWeakSetValues) {
388 HandleScope scope(isolate); 402 HandleScope scope(isolate);
389 DCHECK(args.length() == 2); 403 DCHECK(args.length() == 2);
390 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, holder, 0); 404 CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, holder, 0);
391 CONVERT_NUMBER_CHECKED(int, max_values, Int32, args[1]); 405 CONVERT_NUMBER_CHECKED(int, max_values, Int32, args[1]);
392 RUNTIME_ASSERT(max_values >= 0); 406 RUNTIME_ASSERT(max_values >= 0);
(...skipping 22 matching lines...) Expand all
415 429
416 RUNTIME_FUNCTION(Runtime_ObservationWeakMapCreate) { 430 RUNTIME_FUNCTION(Runtime_ObservationWeakMapCreate) {
417 HandleScope scope(isolate); 431 HandleScope scope(isolate);
418 DCHECK(args.length() == 0); 432 DCHECK(args.length() == 0);
419 Handle<JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap(); 433 Handle<JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap();
420 Runtime::WeakCollectionInitialize(isolate, weakmap); 434 Runtime::WeakCollectionInitialize(isolate, weakmap);
421 return *weakmap; 435 return *weakmap;
422 } 436 }
423 } // namespace internal 437 } // namespace internal
424 } // namespace v8 438 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | src/runtime/runtime-symbol.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698