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

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

Issue 3011009: Add a check that weak object handle is not in NEAR_DEATH state after weak callback invocation. (Closed)
Patch Set: Addressing Mads' comments Created 10 years, 5 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 | « test/cctest/test-api.cc ('k') | test/cctest/test-mark-compact.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 2
3 #include <stdlib.h> 3 #include <stdlib.h>
4 4
5 #include "v8.h" 5 #include "v8.h"
6 6
7 #include "execution.h" 7 #include "execution.h"
8 #include "factory.h" 8 #include "factory.h"
9 #include "macro-assembler.h" 9 #include "macro-assembler.h"
10 #include "global-handles.h" 10 #include "global-handles.h"
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 CHECK_EQ(*h4, *h2); 315 CHECK_EQ(*h4, *h2);
316 GlobalHandles::Destroy(h2.location()); 316 GlobalHandles::Destroy(h2.location());
317 GlobalHandles::Destroy(h4.location()); 317 GlobalHandles::Destroy(h4.location());
318 } 318 }
319 319
320 320
321 static bool WeakPointerCleared = false; 321 static bool WeakPointerCleared = false;
322 322
323 static void TestWeakGlobalHandleCallback(v8::Persistent<v8::Value> handle, 323 static void TestWeakGlobalHandleCallback(v8::Persistent<v8::Value> handle,
324 void* id) { 324 void* id) {
325 USE(handle);
326 if (1234 == reinterpret_cast<intptr_t>(id)) WeakPointerCleared = true; 325 if (1234 == reinterpret_cast<intptr_t>(id)) WeakPointerCleared = true;
326 handle.Dispose();
327 } 327 }
328 328
329 329
330 TEST(WeakGlobalHandlesScavenge) { 330 TEST(WeakGlobalHandlesScavenge) {
331 InitializeVM(); 331 InitializeVM();
332 332
333 WeakPointerCleared = false; 333 WeakPointerCleared = false;
334 334
335 Handle<Object> h1; 335 Handle<Object> h1;
336 Handle<Object> h2; 336 Handle<Object> h2;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 &TestWeakGlobalHandleCallback); 391 &TestWeakGlobalHandleCallback);
392 CHECK(!GlobalHandles::IsNearDeath(h1.location())); 392 CHECK(!GlobalHandles::IsNearDeath(h1.location()));
393 CHECK(!GlobalHandles::IsNearDeath(h2.location())); 393 CHECK(!GlobalHandles::IsNearDeath(h2.location()));
394 394
395 CHECK(Heap::CollectGarbage(0, OLD_POINTER_SPACE)); 395 CHECK(Heap::CollectGarbage(0, OLD_POINTER_SPACE));
396 396
397 CHECK((*h1)->IsString()); 397 CHECK((*h1)->IsString());
398 398
399 CHECK(WeakPointerCleared); 399 CHECK(WeakPointerCleared);
400 CHECK(!GlobalHandles::IsNearDeath(h1.location())); 400 CHECK(!GlobalHandles::IsNearDeath(h1.location()));
401 CHECK(GlobalHandles::IsNearDeath(h2.location()));
402 401
403 GlobalHandles::Destroy(h1.location()); 402 GlobalHandles::Destroy(h1.location());
404 GlobalHandles::Destroy(h2.location());
405 }
406
407 static void TestDeleteWeakGlobalHandleCallback(
408 v8::Persistent<v8::Value> handle,
409 void* id) {
410 if (1234 == reinterpret_cast<intptr_t>(id)) WeakPointerCleared = true;
411 handle.Dispose();
412 } 403 }
413 404
414 TEST(DeleteWeakGlobalHandle) { 405 TEST(DeleteWeakGlobalHandle) {
415 InitializeVM(); 406 InitializeVM();
416 407
417 WeakPointerCleared = false; 408 WeakPointerCleared = false;
418 409
419 Handle<Object> h; 410 Handle<Object> h;
420 411
421 { 412 {
422 HandleScope scope; 413 HandleScope scope;
423 414
424 Handle<Object> i = Factory::NewStringFromAscii(CStrVector("fisk")); 415 Handle<Object> i = Factory::NewStringFromAscii(CStrVector("fisk"));
425 h = GlobalHandles::Create(*i); 416 h = GlobalHandles::Create(*i);
426 } 417 }
427 418
428 GlobalHandles::MakeWeak(h.location(), 419 GlobalHandles::MakeWeak(h.location(),
429 reinterpret_cast<void*>(1234), 420 reinterpret_cast<void*>(1234),
430 &TestDeleteWeakGlobalHandleCallback); 421 &TestWeakGlobalHandleCallback);
431 422
432 // Scanvenge does not recognize weak reference. 423 // Scanvenge does not recognize weak reference.
433 Heap::PerformScavenge(); 424 Heap::PerformScavenge();
434 425
435 CHECK(!WeakPointerCleared); 426 CHECK(!WeakPointerCleared);
436 427
437 // Mark-compact treats weak reference properly. 428 // Mark-compact treats weak reference properly.
438 CHECK(Heap::CollectGarbage(0, OLD_POINTER_SPACE)); 429 CHECK(Heap::CollectGarbage(0, OLD_POINTER_SPACE));
439 430
440 CHECK(WeakPointerCleared); 431 CHECK(WeakPointerCleared);
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 Heap::CollectAllGarbage(true); 980 Heap::CollectAllGarbage(true);
990 Heap::CollectAllGarbage(true); 981 Heap::CollectAllGarbage(true);
991 Heap::CollectAllGarbage(true); 982 Heap::CollectAllGarbage(true);
992 983
993 // foo should no longer be in the compilation cache 984 // foo should no longer be in the compilation cache
994 CHECK(!function->shared()->is_compiled()); 985 CHECK(!function->shared()->is_compiled());
995 // Call foo to get it recompiled. 986 // Call foo to get it recompiled.
996 CompileRun("foo()"); 987 CompileRun("foo()");
997 CHECK(function->shared()->is_compiled()); 988 CHECK(function->shared()->is_compiled());
998 } 989 }
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698