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

Side by Side Diff: test/cctest/test-heap.cc

Issue 14908004: add weakcallback without persistent copying (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: missed some instances Created 7 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 | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/cctest/test-heap-profiler.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 389
390 CHECK_EQ(*h4, *h2); 390 CHECK_EQ(*h4, *h2);
391 global_handles->Destroy(h2.location()); 391 global_handles->Destroy(h2.location());
392 global_handles->Destroy(h4.location()); 392 global_handles->Destroy(h4.location());
393 } 393 }
394 394
395 395
396 static bool WeakPointerCleared = false; 396 static bool WeakPointerCleared = false;
397 397
398 static void TestWeakGlobalHandleCallback(v8::Isolate* isolate, 398 static void TestWeakGlobalHandleCallback(v8::Isolate* isolate,
399 v8::Persistent<v8::Value> handle, 399 v8::Persistent<v8::Value>* handle,
400 void* id) { 400 void* id) {
401 if (1234 == reinterpret_cast<intptr_t>(id)) WeakPointerCleared = true; 401 if (1234 == reinterpret_cast<intptr_t>(id)) WeakPointerCleared = true;
402 handle.Dispose(isolate); 402 handle->Dispose(isolate);
403 } 403 }
404 404
405 405
406 TEST(WeakGlobalHandlesScavenge) { 406 TEST(WeakGlobalHandlesScavenge) {
407 CcTest::InitializeVM(); 407 CcTest::InitializeVM();
408 Isolate* isolate = Isolate::Current(); 408 Isolate* isolate = Isolate::Current();
409 Heap* heap = isolate->heap(); 409 Heap* heap = isolate->heap();
410 Factory* factory = isolate->factory(); 410 Factory* factory = isolate->factory();
411 GlobalHandles* global_handles = isolate->global_handles(); 411 GlobalHandles* global_handles = isolate->global_handles();
412 412
413 WeakPointerCleared = false; 413 WeakPointerCleared = false;
414 414
415 Handle<Object> h1; 415 Handle<Object> h1;
416 Handle<Object> h2; 416 Handle<Object> h2;
417 417
418 { 418 {
419 HandleScope scope(isolate); 419 HandleScope scope(isolate);
420 420
421 Handle<Object> i = factory->NewStringFromAscii(CStrVector("fisk")); 421 Handle<Object> i = factory->NewStringFromAscii(CStrVector("fisk"));
422 Handle<Object> u = factory->NewNumber(1.12344); 422 Handle<Object> u = factory->NewNumber(1.12344);
423 423
424 h1 = global_handles->Create(*i); 424 h1 = global_handles->Create(*i);
425 h2 = global_handles->Create(*u); 425 h2 = global_handles->Create(*u);
426 } 426 }
427 427
428 global_handles->MakeWeak(h2.location(), 428 global_handles->MakeWeak(h2.location(),
429 reinterpret_cast<void*>(1234), 429 reinterpret_cast<void*>(1234),
430 NULL, 430 &TestWeakGlobalHandleCallback,
431 &TestWeakGlobalHandleCallback); 431 NULL);
432 432
433 // Scavenge treats weak pointers as normal roots. 433 // Scavenge treats weak pointers as normal roots.
434 heap->PerformScavenge(); 434 heap->PerformScavenge();
435 435
436 CHECK((*h1)->IsString()); 436 CHECK((*h1)->IsString());
437 CHECK((*h2)->IsHeapNumber()); 437 CHECK((*h2)->IsHeapNumber());
438 438
439 CHECK(!WeakPointerCleared); 439 CHECK(!WeakPointerCleared);
440 CHECK(!global_handles->IsNearDeath(h2.location())); 440 CHECK(!global_handles->IsNearDeath(h2.location()));
441 CHECK(!global_handles->IsNearDeath(h1.location())); 441 CHECK(!global_handles->IsNearDeath(h1.location()));
(...skipping 25 matching lines...) Expand all
467 h2 = global_handles->Create(*u); 467 h2 = global_handles->Create(*u);
468 } 468 }
469 469
470 // Make sure the objects are promoted. 470 // Make sure the objects are promoted.
471 heap->CollectGarbage(OLD_POINTER_SPACE); 471 heap->CollectGarbage(OLD_POINTER_SPACE);
472 heap->CollectGarbage(NEW_SPACE); 472 heap->CollectGarbage(NEW_SPACE);
473 CHECK(!heap->InNewSpace(*h1) && !heap->InNewSpace(*h2)); 473 CHECK(!heap->InNewSpace(*h1) && !heap->InNewSpace(*h2));
474 474
475 global_handles->MakeWeak(h2.location(), 475 global_handles->MakeWeak(h2.location(),
476 reinterpret_cast<void*>(1234), 476 reinterpret_cast<void*>(1234),
477 NULL, 477 &TestWeakGlobalHandleCallback,
478 &TestWeakGlobalHandleCallback); 478 NULL);
479 CHECK(!GlobalHandles::IsNearDeath(h1.location())); 479 CHECK(!GlobalHandles::IsNearDeath(h1.location()));
480 CHECK(!GlobalHandles::IsNearDeath(h2.location())); 480 CHECK(!GlobalHandles::IsNearDeath(h2.location()));
481 481
482 // Incremental marking potentially marked handles before they turned weak. 482 // Incremental marking potentially marked handles before they turned weak.
483 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); 483 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
484 484
485 CHECK((*h1)->IsString()); 485 CHECK((*h1)->IsString());
486 486
487 CHECK(WeakPointerCleared); 487 CHECK(WeakPointerCleared);
488 CHECK(!GlobalHandles::IsNearDeath(h1.location())); 488 CHECK(!GlobalHandles::IsNearDeath(h1.location()));
(...skipping 15 matching lines...) Expand all
504 504
505 { 505 {
506 HandleScope scope(isolate); 506 HandleScope scope(isolate);
507 507
508 Handle<Object> i = factory->NewStringFromAscii(CStrVector("fisk")); 508 Handle<Object> i = factory->NewStringFromAscii(CStrVector("fisk"));
509 h = global_handles->Create(*i); 509 h = global_handles->Create(*i);
510 } 510 }
511 511
512 global_handles->MakeWeak(h.location(), 512 global_handles->MakeWeak(h.location(),
513 reinterpret_cast<void*>(1234), 513 reinterpret_cast<void*>(1234),
514 NULL, 514 &TestWeakGlobalHandleCallback,
515 &TestWeakGlobalHandleCallback); 515 NULL);
516 516
517 // Scanvenge does not recognize weak reference. 517 // Scanvenge does not recognize weak reference.
518 heap->PerformScavenge(); 518 heap->PerformScavenge();
519 519
520 CHECK(!WeakPointerCleared); 520 CHECK(!WeakPointerCleared);
521 521
522 // Mark-compact treats weak reference properly. 522 // Mark-compact treats weak reference properly.
523 heap->CollectGarbage(OLD_POINTER_SPACE); 523 heap->CollectGarbage(OLD_POINTER_SPACE);
524 524
525 CHECK(WeakPointerCleared); 525 CHECK(WeakPointerCleared);
(...skipping 2539 matching lines...) Expand 10 before | Expand all | Expand 10 after
3065 } 3065 }
3066 // An entire block of handles has been filled. 3066 // An entire block of handles has been filled.
3067 // Next handle would require a new block. 3067 // Next handle would require a new block.
3068 ASSERT(data->next == data->limit); 3068 ASSERT(data->next == data->limit);
3069 3069
3070 DeferredHandleScope deferred(isolate); 3070 DeferredHandleScope deferred(isolate);
3071 DummyVisitor visitor; 3071 DummyVisitor visitor;
3072 isolate->handle_scope_implementer()->Iterate(&visitor); 3072 isolate->handle_scope_implementer()->Iterate(&visitor);
3073 deferred.Detach(); 3073 deferred.Detach();
3074 } 3074 }
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/cctest/test-heap-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698