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 2481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2492 CHECK(g2s1->Set(0, g1s1)); | 2492 CHECK(g2s1->Set(0, g1s1)); |
2493 | 2493 |
2494 { | 2494 { |
2495 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; | 2495 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; |
2496 Persistent<Value> g1_children[] = { g1c1 }; | 2496 Persistent<Value> g1_children[] = { g1c1 }; |
2497 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; | 2497 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; |
2498 Persistent<Value> g2_children[] = { g2c1 }; | 2498 Persistent<Value> g2_children[] = { g2c1 }; |
2499 V8::AddObjectGroup(g1_objects, 2); | 2499 V8::AddObjectGroup(g1_objects, 2); |
2500 V8::AddImplicitReferences(g1s1, g1_children, 1); | 2500 V8::AddImplicitReferences(g1s1, g1_children, 1); |
2501 V8::AddObjectGroup(g2_objects, 2); | 2501 V8::AddObjectGroup(g2_objects, 2); |
2502 V8::AddImplicitReferences(g2s2, g2_children, 1); | 2502 V8::AddImplicitReferences(g2s1, g2_children, 1); |
2503 } | 2503 } |
2504 // Do a single full GC, ensure incremental marking is stopped. | 2504 // Do a single full GC, ensure incremental marking is stopped. |
2505 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 2505 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
2506 | 2506 |
2507 // All object should be alive. | 2507 // All object should be alive. |
2508 CHECK_EQ(0, counter.NumberOfWeakCalls()); | 2508 CHECK_EQ(0, counter.NumberOfWeakCalls()); |
2509 | 2509 |
2510 // Weaken the root. | 2510 // Weaken the root. |
2511 root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); | 2511 root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); |
2512 // But make children strong roots---all the objects (except for children) | 2512 // But make children strong roots---all the objects (except for children) |
2513 // should be collectable now. | 2513 // should be collectable now. |
2514 g1c1.ClearWeak(iso); | 2514 g1c1.ClearWeak(iso); |
2515 g2c1.ClearWeak(iso); | 2515 g2c1.ClearWeak(iso); |
2516 | 2516 |
2517 // Groups are deleted, rebuild groups. | 2517 // Groups are deleted, rebuild groups. |
2518 { | 2518 { |
2519 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; | 2519 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; |
2520 Persistent<Value> g1_children[] = { g1c1 }; | 2520 Persistent<Value> g1_children[] = { g1c1 }; |
2521 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; | 2521 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; |
2522 Persistent<Value> g2_children[] = { g2c1 }; | 2522 Persistent<Value> g2_children[] = { g2c1 }; |
2523 V8::AddObjectGroup(g1_objects, 2); | 2523 V8::AddObjectGroup(g1_objects, 2); |
2524 V8::AddImplicitReferences(g1s1, g1_children, 1); | 2524 V8::AddImplicitReferences(g1s1, g1_children, 1); |
2525 V8::AddObjectGroup(g2_objects, 2); | 2525 V8::AddObjectGroup(g2_objects, 2); |
2526 V8::AddImplicitReferences(g2s2, g2_children, 1); | 2526 V8::AddImplicitReferences(g2s1, g2_children, 1); |
2527 } | 2527 } |
2528 | 2528 |
2529 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 2529 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
2530 | 2530 |
2531 // All objects should be gone. 5 global handles in total. | 2531 // All objects should be gone. 5 global handles in total. |
2532 CHECK_EQ(5, counter.NumberOfWeakCalls()); | 2532 CHECK_EQ(5, counter.NumberOfWeakCalls()); |
2533 | 2533 |
2534 // And now make children weak again and collect them. | 2534 // And now make children weak again and collect them. |
2535 g1c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); | 2535 g1c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); |
2536 g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); | 2536 g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2571 g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); | 2571 g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); |
2572 } | 2572 } |
2573 | 2573 |
2574 Persistent<Object> root = Persistent<Object>::New(iso, g1s1); // make a root. | 2574 Persistent<Object> root = Persistent<Object>::New(iso, g1s1); // make a root. |
2575 | 2575 |
2576 // Connect group 1 and 2, make a cycle. | 2576 // Connect group 1 and 2, make a cycle. |
2577 CHECK(g1s2->Set(0, g2s2)); | 2577 CHECK(g1s2->Set(0, g2s2)); |
2578 CHECK(g2s1->Set(0, g1s1)); | 2578 CHECK(g2s1->Set(0, g1s1)); |
2579 | 2579 |
2580 { | 2580 { |
2581 Persistent<Value> g1_children[] = { g1c1 }; | 2581 UniqueId id1(reinterpret_cast<intptr_t>(*g1s1)); |
2582 Persistent<Value> g2_children[] = { g2c1 }; | 2582 UniqueId id2(reinterpret_cast<intptr_t>(*g2s2)); |
2583 V8::SetObjectGroupId(iso, g1s1, UniqueId(1)); | 2583 V8::SetObjectGroupId(iso, g1s1, id1); |
2584 V8::SetObjectGroupId(iso, g1s2, UniqueId(1)); | 2584 V8::SetObjectGroupId(iso, g1s2, id1); |
2585 V8::AddImplicitReferences(g1s1, g1_children, 1); | 2585 V8::SetObjectGroupRepresentative(iso, id1, g1s1); |
2586 V8::SetObjectGroupId(iso, g2s1, UniqueId(2)); | 2586 V8::AddImplicitReference(iso, id1, g1c1); |
2587 V8::SetObjectGroupId(iso, g2s2, UniqueId(2)); | 2587 V8::SetObjectGroupId(iso, g2s1, id2); |
2588 V8::AddImplicitReferences(g2s2, g2_children, 1); | 2588 V8::SetObjectGroupId(iso, g2s2, id2); |
| 2589 V8::SetObjectGroupRepresentative(iso, id2, g2s1); |
| 2590 V8::AddImplicitReference(iso, id2, g2c1); |
2589 } | 2591 } |
2590 // Do a single full GC, ensure incremental marking is stopped. | 2592 // Do a single full GC, ensure incremental marking is stopped. |
2591 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>( | 2593 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>( |
2592 iso)->heap(); | 2594 iso)->heap(); |
2593 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 2595 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
2594 | 2596 |
2595 // All object should be alive. | 2597 // All object should be alive. |
2596 CHECK_EQ(0, counter.NumberOfWeakCalls()); | 2598 CHECK_EQ(0, counter.NumberOfWeakCalls()); |
2597 | 2599 |
2598 // Weaken the root. | 2600 // Weaken the root. |
2599 root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); | 2601 root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); |
2600 // But make children strong roots---all the objects (except for children) | 2602 // But make children strong roots---all the objects (except for children) |
2601 // should be collectable now. | 2603 // should be collectable now. |
2602 g1c1.ClearWeak(iso); | 2604 g1c1.ClearWeak(iso); |
2603 g2c1.ClearWeak(iso); | 2605 g2c1.ClearWeak(iso); |
2604 | 2606 |
2605 // Groups are deleted, rebuild groups. | 2607 // Groups are deleted, rebuild groups. |
2606 { | 2608 { |
2607 Persistent<Value> g1_children[] = { g1c1 }; | 2609 UniqueId id1(reinterpret_cast<intptr_t>(*g1s1)); |
2608 Persistent<Value> g2_children[] = { g2c1 }; | 2610 UniqueId id2(reinterpret_cast<intptr_t>(*g2s2)); |
2609 V8::SetObjectGroupId(iso, g1s1, UniqueId(1)); | 2611 V8::SetObjectGroupId(iso, g1s1, id1); |
2610 V8::SetObjectGroupId(iso, g1s2, UniqueId(1)); | 2612 V8::SetObjectGroupId(iso, g1s2, id1); |
2611 V8::AddImplicitReferences(g1s1, g1_children, 1); | 2613 V8::SetObjectGroupRepresentative(iso, id1, g1s1); |
2612 V8::SetObjectGroupId(iso, g2s1, UniqueId(2)); | 2614 V8::AddImplicitReference(iso, id1, g1c1); |
2613 V8::SetObjectGroupId(iso, g2s2, UniqueId(2)); | 2615 V8::SetObjectGroupId(iso, g2s1, id2); |
2614 V8::AddImplicitReferences(g2s2, g2_children, 1); | 2616 V8::SetObjectGroupId(iso, g2s2, id2); |
| 2617 V8::SetObjectGroupRepresentative(iso, id2, g2s1); |
| 2618 V8::AddImplicitReference(iso, id2, g2c1); |
2615 } | 2619 } |
2616 | 2620 |
2617 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 2621 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
2618 | 2622 |
2619 // All objects should be gone. 5 global handles in total. | 2623 // All objects should be gone. 5 global handles in total. |
2620 CHECK_EQ(5, counter.NumberOfWeakCalls()); | 2624 CHECK_EQ(5, counter.NumberOfWeakCalls()); |
2621 | 2625 |
2622 // And now make children weak again and collect them. | 2626 // And now make children weak again and collect them. |
2623 g1c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); | 2627 g1c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); |
2624 g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); | 2628 g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2780 CHECK(g4s1.IsWeak(iso)); | 2784 CHECK(g4s1.IsWeak(iso)); |
2781 CHECK(g4s2.IsWeak(iso)); | 2785 CHECK(g4s2.IsWeak(iso)); |
2782 } | 2786 } |
2783 | 2787 |
2784 Persistent<Object> root = Persistent<Object>::New(iso, g1s1); // make a root. | 2788 Persistent<Object> root = Persistent<Object>::New(iso, g1s1); // make a root. |
2785 | 2789 |
2786 // Connect groups. We're building the following cycle: | 2790 // Connect groups. We're building the following cycle: |
2787 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other | 2791 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other |
2788 // groups. | 2792 // groups. |
2789 { | 2793 { |
2790 Persistent<Value> g1_children[] = { g2s1 }; | 2794 UniqueId id1(reinterpret_cast<intptr_t>(*g1s1)); |
2791 Persistent<Value> g2_children[] = { g3s1 }; | 2795 UniqueId id2(reinterpret_cast<intptr_t>(*g2s1)); |
2792 Persistent<Value> g3_children[] = { g4s1 }; | 2796 UniqueId id3(reinterpret_cast<intptr_t>(*g3s1)); |
2793 Persistent<Value> g4_children[] = { g1s1 }; | 2797 UniqueId id4(reinterpret_cast<intptr_t>(*g4s1)); |
2794 V8::SetObjectGroupId(iso, g1s1, UniqueId(1)); | 2798 V8::SetObjectGroupId(iso, g1s1, id1); |
2795 V8::SetObjectGroupId(iso, g1s2, UniqueId(1)); | 2799 V8::SetObjectGroupId(iso, g1s2, id1); |
2796 V8::AddImplicitReferences(g1s1, g1_children, 1); | 2800 V8::SetObjectGroupRepresentative(iso, id1, g1s1); |
2797 V8::SetObjectGroupId(iso, g2s1, UniqueId(2)); | 2801 V8::AddImplicitReference(iso, id1, g2s1); |
2798 V8::SetObjectGroupId(iso, g2s2, UniqueId(2)); | 2802 V8::SetObjectGroupId(iso, g2s1, id2); |
2799 V8::AddImplicitReferences(g2s1, g2_children, 1); | 2803 V8::SetObjectGroupId(iso, g2s2, id2); |
2800 V8::SetObjectGroupId(iso, g3s1, UniqueId(3)); | 2804 V8::SetObjectGroupRepresentative(iso, id2, g2s1); |
2801 V8::SetObjectGroupId(iso, g3s2, UniqueId(3)); | 2805 V8::AddImplicitReference(iso, id2, g3s1); |
2802 V8::AddImplicitReferences(g3s1, g3_children, 1); | 2806 V8::SetObjectGroupId(iso, g3s1, id3); |
2803 V8::SetObjectGroupId(iso, g4s1, UniqueId(4)); | 2807 V8::SetObjectGroupId(iso, g3s2, id3); |
2804 V8::SetObjectGroupId(iso, g4s2, UniqueId(4)); | 2808 V8::SetObjectGroupRepresentative(iso, id3, g3s1); |
2805 V8::AddImplicitReferences(g4s1, g4_children, 1); | 2809 V8::AddImplicitReference(iso, id3, g4s1); |
| 2810 V8::SetObjectGroupId(iso, g4s1, id4); |
| 2811 V8::SetObjectGroupId(iso, g4s2, id4); |
| 2812 V8::SetObjectGroupRepresentative(iso, id4, g4s1); |
| 2813 V8::AddImplicitReference(iso, id4, g1s1); |
2806 } | 2814 } |
2807 // Do a single full GC | 2815 // Do a single full GC |
2808 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>( | 2816 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>( |
2809 iso)->heap(); | 2817 iso)->heap(); |
2810 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 2818 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
2811 | 2819 |
2812 // All object should be alive. | 2820 // All object should be alive. |
2813 CHECK_EQ(0, counter.NumberOfWeakCalls()); | 2821 CHECK_EQ(0, counter.NumberOfWeakCalls()); |
2814 | 2822 |
2815 // Weaken the root. | 2823 // Weaken the root. |
2816 root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); | 2824 root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); |
2817 | 2825 |
2818 // Groups are deleted, rebuild groups. | 2826 // Groups are deleted, rebuild groups. |
2819 { | 2827 { |
2820 Persistent<Value> g1_children[] = { g2s1 }; | 2828 UniqueId id1(reinterpret_cast<intptr_t>(*g1s1)); |
2821 Persistent<Value> g2_children[] = { g3s1 }; | 2829 UniqueId id2(reinterpret_cast<intptr_t>(*g2s1)); |
2822 Persistent<Value> g3_children[] = { g4s1 }; | 2830 UniqueId id3(reinterpret_cast<intptr_t>(*g3s1)); |
2823 Persistent<Value> g4_children[] = { g1s1 }; | 2831 UniqueId id4(reinterpret_cast<intptr_t>(*g4s1)); |
2824 V8::SetObjectGroupId(iso, g1s1, UniqueId(1)); | 2832 V8::SetObjectGroupId(iso, g1s1, id1); |
2825 V8::SetObjectGroupId(iso, g1s2, UniqueId(1)); | 2833 V8::SetObjectGroupId(iso, g1s2, id1); |
2826 V8::AddImplicitReferences(g1s1, g1_children, 1); | 2834 V8::SetObjectGroupRepresentative(iso, id1, g1s1); |
2827 V8::SetObjectGroupId(iso, g2s1, UniqueId(2)); | 2835 V8::AddImplicitReference(iso, id1, g2s1); |
2828 V8::SetObjectGroupId(iso, g2s2, UniqueId(2)); | 2836 V8::SetObjectGroupId(iso, g2s1, id2); |
2829 V8::AddImplicitReferences(g2s1, g2_children, 1); | 2837 V8::SetObjectGroupId(iso, g2s2, id2); |
2830 V8::SetObjectGroupId(iso, g3s1, UniqueId(3)); | 2838 V8::SetObjectGroupRepresentative(iso, id2, g2s1); |
2831 V8::SetObjectGroupId(iso, g3s2, UniqueId(3)); | 2839 V8::AddImplicitReference(iso, id2, g3s1); |
2832 V8::AddImplicitReferences(g3s1, g3_children, 1); | 2840 V8::SetObjectGroupId(iso, g3s1, id3); |
2833 V8::SetObjectGroupId(iso, g4s1, UniqueId(4)); | 2841 V8::SetObjectGroupId(iso, g3s2, id3); |
2834 V8::SetObjectGroupId(iso, g4s2, UniqueId(4)); | 2842 V8::SetObjectGroupRepresentative(iso, id3, g3s1); |
2835 V8::AddImplicitReferences(g4s1, g4_children, 1); | 2843 V8::AddImplicitReference(iso, id3, g4s1); |
| 2844 V8::SetObjectGroupId(iso, g4s1, id4); |
| 2845 V8::SetObjectGroupId(iso, g4s2, id4); |
| 2846 V8::SetObjectGroupRepresentative(iso, id4, g4s1); |
| 2847 V8::AddImplicitReference(iso, id4, g1s1); |
2836 } | 2848 } |
2837 | 2849 |
2838 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 2850 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
2839 | 2851 |
2840 // All objects should be gone. 9 global handles in total. | 2852 // All objects should be gone. 9 global handles in total. |
2841 CHECK_EQ(9, counter.NumberOfWeakCalls()); | 2853 CHECK_EQ(9, counter.NumberOfWeakCalls()); |
2842 } | 2854 } |
2843 | 2855 |
2844 | 2856 |
2845 // TODO(mstarzinger): This should be a THREADED_TEST but causes failures | 2857 // TODO(mstarzinger): This should be a THREADED_TEST but causes failures |
(...skipping 15852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18698 i::Semaphore* sem_; | 18710 i::Semaphore* sem_; |
18699 volatile int sem_value_; | 18711 volatile int sem_value_; |
18700 }; | 18712 }; |
18701 | 18713 |
18702 | 18714 |
18703 THREADED_TEST(SemaphoreInterruption) { | 18715 THREADED_TEST(SemaphoreInterruption) { |
18704 ThreadInterruptTest().RunTest(); | 18716 ThreadInterruptTest().RunTest(); |
18705 } | 18717 } |
18706 | 18718 |
18707 #endif // WIN32 | 18719 #endif // WIN32 |
OLD | NEW |