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

Side by Side Diff: test/cctest/test-mark-compact.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-heap-profiler.cc ('k') | test/cctest/test-weakmaps.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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 CHECK_EQ(gc_ends, gc_starts); 297 CHECK_EQ(gc_ends, gc_starts);
298 298
299 HEAP->CollectGarbage(OLD_POINTER_SPACE); 299 HEAP->CollectGarbage(OLD_POINTER_SPACE);
300 CHECK_EQ(1, gc_starts); 300 CHECK_EQ(1, gc_starts);
301 CHECK_EQ(gc_ends, gc_starts); 301 CHECK_EQ(gc_ends, gc_starts);
302 } 302 }
303 303
304 304
305 static int NumberOfWeakCalls = 0; 305 static int NumberOfWeakCalls = 0;
306 static void WeakPointerCallback(v8::Isolate* isolate, 306 static void WeakPointerCallback(v8::Isolate* isolate,
307 v8::Persistent<v8::Value> handle, 307 v8::Persistent<v8::Value>* handle,
308 void* id) { 308 void* id) {
309 ASSERT(id == reinterpret_cast<void*>(1234)); 309 ASSERT(id == reinterpret_cast<void*>(1234));
310 NumberOfWeakCalls++; 310 NumberOfWeakCalls++;
311 handle.Dispose(isolate); 311 handle->Dispose(isolate);
312 } 312 }
313 313
314 TEST(ObjectGroups) { 314 TEST(ObjectGroups) {
315 FLAG_incremental_marking = false; 315 FLAG_incremental_marking = false;
316 CcTest::InitializeVM(); 316 CcTest::InitializeVM();
317 GlobalHandles* global_handles = Isolate::Current()->global_handles(); 317 GlobalHandles* global_handles = Isolate::Current()->global_handles();
318 318
319 NumberOfWeakCalls = 0; 319 NumberOfWeakCalls = 0;
320 v8::HandleScope handle_scope(CcTest::isolate()); 320 v8::HandleScope handle_scope(CcTest::isolate());
321 321
322 Handle<Object> g1s1 = 322 Handle<Object> g1s1 =
323 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); 323 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
324 Handle<Object> g1s2 = 324 Handle<Object> g1s2 =
325 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); 325 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
326 Handle<Object> g1c1 = 326 Handle<Object> g1c1 =
327 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); 327 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
328 global_handles->MakeWeak(g1s1.location(), 328 global_handles->MakeWeak(g1s1.location(),
329 reinterpret_cast<void*>(1234), 329 reinterpret_cast<void*>(1234),
330 NULL, 330 &WeakPointerCallback,
331 &WeakPointerCallback); 331 NULL);
332 global_handles->MakeWeak(g1s2.location(), 332 global_handles->MakeWeak(g1s2.location(),
333 reinterpret_cast<void*>(1234), 333 reinterpret_cast<void*>(1234),
334 NULL, 334 &WeakPointerCallback,
335 &WeakPointerCallback); 335 NULL);
336 global_handles->MakeWeak(g1c1.location(), 336 global_handles->MakeWeak(g1c1.location(),
337 reinterpret_cast<void*>(1234), 337 reinterpret_cast<void*>(1234),
338 NULL, 338 &WeakPointerCallback,
339 &WeakPointerCallback); 339 NULL);
340 340
341 Handle<Object> g2s1 = 341 Handle<Object> g2s1 =
342 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); 342 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
343 Handle<Object> g2s2 = 343 Handle<Object> g2s2 =
344 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); 344 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
345 Handle<Object> g2c1 = 345 Handle<Object> g2c1 =
346 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); 346 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked());
347 global_handles->MakeWeak(g2s1.location(), 347 global_handles->MakeWeak(g2s1.location(),
348 reinterpret_cast<void*>(1234), 348 reinterpret_cast<void*>(1234),
349 NULL, 349 &WeakPointerCallback,
350 &WeakPointerCallback); 350 NULL);
351 global_handles->MakeWeak(g2s2.location(), 351 global_handles->MakeWeak(g2s2.location(),
352 reinterpret_cast<void*>(1234), 352 reinterpret_cast<void*>(1234),
353 NULL, 353 &WeakPointerCallback,
354 &WeakPointerCallback); 354 NULL);
355 global_handles->MakeWeak(g2c1.location(), 355 global_handles->MakeWeak(g2c1.location(),
356 reinterpret_cast<void*>(1234), 356 reinterpret_cast<void*>(1234),
357 NULL, 357 &WeakPointerCallback,
358 &WeakPointerCallback); 358 NULL);
359 359
360 Handle<Object> root = global_handles->Create(*g1s1); // make a root. 360 Handle<Object> root = global_handles->Create(*g1s1); // make a root.
361 361
362 // Connect group 1 and 2, make a cycle. 362 // Connect group 1 and 2, make a cycle.
363 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); 363 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2);
364 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); 364 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1);
365 365
366 { 366 {
367 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; 367 Object** g1_objects[] = { g1s1.location(), g1s2.location() };
368 Object** g1_children[] = { g1c1.location() }; 368 Object** g1_children[] = { g1c1.location() };
369 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; 369 Object** g2_objects[] = { g2s1.location(), g2s2.location() };
370 Object** g2_children[] = { g2c1.location() }; 370 Object** g2_children[] = { g2c1.location() };
371 global_handles->AddObjectGroup(g1_objects, 2, NULL); 371 global_handles->AddObjectGroup(g1_objects, 2, NULL);
372 global_handles->AddImplicitReferences( 372 global_handles->AddImplicitReferences(
373 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); 373 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1);
374 global_handles->AddObjectGroup(g2_objects, 2, NULL); 374 global_handles->AddObjectGroup(g2_objects, 2, NULL);
375 global_handles->AddImplicitReferences( 375 global_handles->AddImplicitReferences(
376 Handle<HeapObject>::cast(g2s1).location(), g2_children, 1); 376 Handle<HeapObject>::cast(g2s1).location(), g2_children, 1);
377 } 377 }
378 // Do a full GC 378 // Do a full GC
379 HEAP->CollectGarbage(OLD_POINTER_SPACE); 379 HEAP->CollectGarbage(OLD_POINTER_SPACE);
380 380
381 // All object should be alive. 381 // All object should be alive.
382 CHECK_EQ(0, NumberOfWeakCalls); 382 CHECK_EQ(0, NumberOfWeakCalls);
383 383
384 // Weaken the root. 384 // Weaken the root.
385 global_handles->MakeWeak(root.location(), 385 global_handles->MakeWeak(root.location(),
386 reinterpret_cast<void*>(1234), 386 reinterpret_cast<void*>(1234),
387 NULL, 387 &WeakPointerCallback,
388 &WeakPointerCallback); 388 NULL);
389 // But make children strong roots---all the objects (except for children) 389 // But make children strong roots---all the objects (except for children)
390 // should be collectable now. 390 // should be collectable now.
391 global_handles->ClearWeakness(g1c1.location()); 391 global_handles->ClearWeakness(g1c1.location());
392 global_handles->ClearWeakness(g2c1.location()); 392 global_handles->ClearWeakness(g2c1.location());
393 393
394 // Groups are deleted, rebuild groups. 394 // Groups are deleted, rebuild groups.
395 { 395 {
396 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; 396 Object** g1_objects[] = { g1s1.location(), g1s2.location() };
397 Object** g1_children[] = { g1c1.location() }; 397 Object** g1_children[] = { g1c1.location() };
398 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; 398 Object** g2_objects[] = { g2s1.location(), g2s2.location() };
399 Object** g2_children[] = { g2c1.location() }; 399 Object** g2_children[] = { g2c1.location() };
400 global_handles->AddObjectGroup(g1_objects, 2, NULL); 400 global_handles->AddObjectGroup(g1_objects, 2, NULL);
401 global_handles->AddImplicitReferences( 401 global_handles->AddImplicitReferences(
402 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); 402 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1);
403 global_handles->AddObjectGroup(g2_objects, 2, NULL); 403 global_handles->AddObjectGroup(g2_objects, 2, NULL);
404 global_handles->AddImplicitReferences( 404 global_handles->AddImplicitReferences(
405 Handle<HeapObject>::cast(g2s1).location(), g2_children, 1); 405 Handle<HeapObject>::cast(g2s1).location(), g2_children, 1);
406 } 406 }
407 407
408 HEAP->CollectGarbage(OLD_POINTER_SPACE); 408 HEAP->CollectGarbage(OLD_POINTER_SPACE);
409 409
410 // All objects should be gone. 5 global handles in total. 410 // All objects should be gone. 5 global handles in total.
411 CHECK_EQ(5, NumberOfWeakCalls); 411 CHECK_EQ(5, NumberOfWeakCalls);
412 412
413 // And now make children weak again and collect them. 413 // And now make children weak again and collect them.
414 global_handles->MakeWeak(g1c1.location(), 414 global_handles->MakeWeak(g1c1.location(),
415 reinterpret_cast<void*>(1234), 415 reinterpret_cast<void*>(1234),
416 NULL, 416 &WeakPointerCallback,
417 &WeakPointerCallback); 417 NULL);
418 global_handles->MakeWeak(g2c1.location(), 418 global_handles->MakeWeak(g2c1.location(),
419 reinterpret_cast<void*>(1234), 419 reinterpret_cast<void*>(1234),
420 NULL, 420 &WeakPointerCallback,
421 &WeakPointerCallback); 421 NULL);
422 422
423 HEAP->CollectGarbage(OLD_POINTER_SPACE); 423 HEAP->CollectGarbage(OLD_POINTER_SPACE);
424 CHECK_EQ(7, NumberOfWeakCalls); 424 CHECK_EQ(7, NumberOfWeakCalls);
425 } 425 }
426 426
427 427
428 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { 428 class TestRetainedObjectInfo : public v8::RetainedObjectInfo {
429 public: 429 public:
430 TestRetainedObjectInfo() : has_been_disposed_(false) {} 430 TestRetainedObjectInfo() : has_been_disposed_(false) {}
431 431
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 if (v8::internal::Snapshot::IsEnabled()) { 563 if (v8::internal::Snapshot::IsEnabled()) {
564 CHECK_LE(delta, 2900 * 1024); 564 CHECK_LE(delta, 2900 * 1024);
565 } else { 565 } else {
566 CHECK_LE(delta, 3400 * 1024); 566 CHECK_LE(delta, 3400 * 1024);
567 } 567 }
568 } 568 }
569 } 569 }
570 } 570 }
571 571
572 #endif // __linux__ and !USE_SIMULATOR 572 #endif // __linux__ and !USE_SIMULATOR
OLDNEW
« no previous file with comments | « test/cctest/test-heap-profiler.cc ('k') | test/cctest/test-weakmaps.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698