OLD | NEW |
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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 v8::HandleScope handle_scope(CcTest::isolate()); | 316 v8::HandleScope handle_scope(CcTest::isolate()); |
317 | 317 |
318 Handle<Object> g1s1 = | 318 Handle<Object> g1s1 = |
319 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 319 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
320 Handle<Object> g1s2 = | 320 Handle<Object> g1s2 = |
321 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 321 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
322 Handle<Object> g1c1 = | 322 Handle<Object> g1c1 = |
323 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 323 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
324 global_handles->MakeWeak(g1s1.location(), | 324 global_handles->MakeWeak(g1s1.location(), |
325 reinterpret_cast<void*>(1234), | 325 reinterpret_cast<void*>(1234), |
326 &WeakPointerCallback, | 326 &WeakPointerCallback); |
327 NULL); | |
328 global_handles->MakeWeak(g1s2.location(), | 327 global_handles->MakeWeak(g1s2.location(), |
329 reinterpret_cast<void*>(1234), | 328 reinterpret_cast<void*>(1234), |
330 &WeakPointerCallback, | 329 &WeakPointerCallback); |
331 NULL); | |
332 global_handles->MakeWeak(g1c1.location(), | 330 global_handles->MakeWeak(g1c1.location(), |
333 reinterpret_cast<void*>(1234), | 331 reinterpret_cast<void*>(1234), |
334 &WeakPointerCallback, | 332 &WeakPointerCallback); |
335 NULL); | |
336 | 333 |
337 Handle<Object> g2s1 = | 334 Handle<Object> g2s1 = |
338 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 335 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
339 Handle<Object> g2s2 = | 336 Handle<Object> g2s2 = |
340 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 337 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
341 Handle<Object> g2c1 = | 338 Handle<Object> g2c1 = |
342 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); | 339 global_handles->Create(HEAP->AllocateFixedArray(1)->ToObjectChecked()); |
343 global_handles->MakeWeak(g2s1.location(), | 340 global_handles->MakeWeak(g2s1.location(), |
344 reinterpret_cast<void*>(1234), | 341 reinterpret_cast<void*>(1234), |
345 &WeakPointerCallback, | 342 &WeakPointerCallback); |
346 NULL); | |
347 global_handles->MakeWeak(g2s2.location(), | 343 global_handles->MakeWeak(g2s2.location(), |
348 reinterpret_cast<void*>(1234), | 344 reinterpret_cast<void*>(1234), |
349 &WeakPointerCallback, | 345 &WeakPointerCallback); |
350 NULL); | |
351 global_handles->MakeWeak(g2c1.location(), | 346 global_handles->MakeWeak(g2c1.location(), |
352 reinterpret_cast<void*>(1234), | 347 reinterpret_cast<void*>(1234), |
353 &WeakPointerCallback, | 348 &WeakPointerCallback); |
354 NULL); | |
355 | 349 |
356 Handle<Object> root = global_handles->Create(*g1s1); // make a root. | 350 Handle<Object> root = global_handles->Create(*g1s1); // make a root. |
357 | 351 |
358 // Connect group 1 and 2, make a cycle. | 352 // Connect group 1 and 2, make a cycle. |
359 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); | 353 Handle<FixedArray>::cast(g1s2)->set(0, *g2s2); |
360 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); | 354 Handle<FixedArray>::cast(g2s1)->set(0, *g1s1); |
361 | 355 |
362 { | 356 { |
363 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; | 357 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; |
364 Object** g1_children[] = { g1c1.location() }; | 358 Object** g1_children[] = { g1c1.location() }; |
365 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; | 359 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; |
366 Object** g2_children[] = { g2c1.location() }; | 360 Object** g2_children[] = { g2c1.location() }; |
367 global_handles->AddObjectGroup(g1_objects, 2, NULL); | 361 global_handles->AddObjectGroup(g1_objects, 2, NULL); |
368 global_handles->AddImplicitReferences( | 362 global_handles->AddImplicitReferences( |
369 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); | 363 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); |
370 global_handles->AddObjectGroup(g2_objects, 2, NULL); | 364 global_handles->AddObjectGroup(g2_objects, 2, NULL); |
371 global_handles->AddImplicitReferences( | 365 global_handles->AddImplicitReferences( |
372 Handle<HeapObject>::cast(g2s1).location(), g2_children, 1); | 366 Handle<HeapObject>::cast(g2s1).location(), g2_children, 1); |
373 } | 367 } |
374 // Do a full GC | 368 // Do a full GC |
375 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 369 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
376 | 370 |
377 // All object should be alive. | 371 // All object should be alive. |
378 CHECK_EQ(0, NumberOfWeakCalls); | 372 CHECK_EQ(0, NumberOfWeakCalls); |
379 | 373 |
380 // Weaken the root. | 374 // Weaken the root. |
381 global_handles->MakeWeak(root.location(), | 375 global_handles->MakeWeak(root.location(), |
382 reinterpret_cast<void*>(1234), | 376 reinterpret_cast<void*>(1234), |
383 &WeakPointerCallback, | 377 &WeakPointerCallback); |
384 NULL); | |
385 // But make children strong roots---all the objects (except for children) | 378 // But make children strong roots---all the objects (except for children) |
386 // should be collectable now. | 379 // should be collectable now. |
387 global_handles->ClearWeakness(g1c1.location()); | 380 global_handles->ClearWeakness(g1c1.location()); |
388 global_handles->ClearWeakness(g2c1.location()); | 381 global_handles->ClearWeakness(g2c1.location()); |
389 | 382 |
390 // Groups are deleted, rebuild groups. | 383 // Groups are deleted, rebuild groups. |
391 { | 384 { |
392 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; | 385 Object** g1_objects[] = { g1s1.location(), g1s2.location() }; |
393 Object** g1_children[] = { g1c1.location() }; | 386 Object** g1_children[] = { g1c1.location() }; |
394 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; | 387 Object** g2_objects[] = { g2s1.location(), g2s2.location() }; |
395 Object** g2_children[] = { g2c1.location() }; | 388 Object** g2_children[] = { g2c1.location() }; |
396 global_handles->AddObjectGroup(g1_objects, 2, NULL); | 389 global_handles->AddObjectGroup(g1_objects, 2, NULL); |
397 global_handles->AddImplicitReferences( | 390 global_handles->AddImplicitReferences( |
398 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); | 391 Handle<HeapObject>::cast(g1s1).location(), g1_children, 1); |
399 global_handles->AddObjectGroup(g2_objects, 2, NULL); | 392 global_handles->AddObjectGroup(g2_objects, 2, NULL); |
400 global_handles->AddImplicitReferences( | 393 global_handles->AddImplicitReferences( |
401 Handle<HeapObject>::cast(g2s1).location(), g2_children, 1); | 394 Handle<HeapObject>::cast(g2s1).location(), g2_children, 1); |
402 } | 395 } |
403 | 396 |
404 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 397 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
405 | 398 |
406 // All objects should be gone. 5 global handles in total. | 399 // All objects should be gone. 5 global handles in total. |
407 CHECK_EQ(5, NumberOfWeakCalls); | 400 CHECK_EQ(5, NumberOfWeakCalls); |
408 | 401 |
409 // And now make children weak again and collect them. | 402 // And now make children weak again and collect them. |
410 global_handles->MakeWeak(g1c1.location(), | 403 global_handles->MakeWeak(g1c1.location(), |
411 reinterpret_cast<void*>(1234), | 404 reinterpret_cast<void*>(1234), |
412 &WeakPointerCallback, | 405 &WeakPointerCallback); |
413 NULL); | |
414 global_handles->MakeWeak(g2c1.location(), | 406 global_handles->MakeWeak(g2c1.location(), |
415 reinterpret_cast<void*>(1234), | 407 reinterpret_cast<void*>(1234), |
416 &WeakPointerCallback, | 408 &WeakPointerCallback); |
417 NULL); | |
418 | 409 |
419 HEAP->CollectGarbage(OLD_POINTER_SPACE); | 410 HEAP->CollectGarbage(OLD_POINTER_SPACE); |
420 CHECK_EQ(7, NumberOfWeakCalls); | 411 CHECK_EQ(7, NumberOfWeakCalls); |
421 } | 412 } |
422 | 413 |
423 | 414 |
424 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { | 415 class TestRetainedObjectInfo : public v8::RetainedObjectInfo { |
425 public: | 416 public: |
426 TestRetainedObjectInfo() : has_been_disposed_(false) {} | 417 TestRetainedObjectInfo() : has_been_disposed_(false) {} |
427 | 418 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 if (v8::internal::Snapshot::IsEnabled()) { | 557 if (v8::internal::Snapshot::IsEnabled()) { |
567 CHECK_LE(delta, 2900 * 1024); | 558 CHECK_LE(delta, 2900 * 1024); |
568 } else { | 559 } else { |
569 CHECK_LE(delta, 3400 * 1024); | 560 CHECK_LE(delta, 3400 * 1024); |
570 } | 561 } |
571 } | 562 } |
572 } | 563 } |
573 } | 564 } |
574 | 565 |
575 #endif // __linux__ and !USE_SIMULATOR | 566 #endif // __linux__ and !USE_SIMULATOR |
OLD | NEW |