Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
| 6 #include "platform/assert.h" | 6 #include "platform/assert.h" |
| 7 #include "platform/utils.h" | 7 #include "platform/utils.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
| 10 #include "vm/dart_api_state.h" | 10 #include "vm/dart_api_state.h" |
| (...skipping 1628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1639 | 1639 |
| 1640 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 1640 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 1641 } | 1641 } |
| 1642 | 1642 |
| 1643 // All weak references except weak3 should be preserved. | 1643 // All weak references except weak3 should be preserved. |
| 1644 EXPECT(!Dart_IsNull(weak1)); | 1644 EXPECT(!Dart_IsNull(weak1)); |
| 1645 EXPECT(!Dart_IsNull(weak2)); | 1645 EXPECT(!Dart_IsNull(weak2)); |
| 1646 EXPECT(Dart_IsNull(weak3)); | 1646 EXPECT(Dart_IsNull(weak3)); |
| 1647 } | 1647 } |
| 1648 | 1648 |
| 1649 | |
| 1650 static int global_prologue_callback_status = 0; | |
| 1651 | |
| 1652 | |
| 1653 static void PrologueCallbackTimes2() { | |
| 1654 global_prologue_callback_status *= 2; | |
| 1655 } | |
| 1656 | |
| 1657 | |
| 1658 static void PrologueCallbackTimes3() { | |
| 1659 global_prologue_callback_status *= 3; | |
| 1660 } | |
| 1661 | |
| 1662 | |
| 1663 static int global_epilogue_callback_status = 0; | |
| 1664 | |
| 1665 | |
| 1666 static void EpilogueCallbackTimes4() { | |
| 1667 global_epilogue_callback_status *= 4; | |
|
turnidge
2012/03/07 00:25:16
How about relatively prime numbers? 4 -> 5, 5 ->
cshapiro
2012/03/07 03:06:10
I think I avoid this case by separating the value
| |
| 1668 } | |
| 1669 | |
| 1670 | |
| 1671 static void EpilogueCallbackTimes5() { | |
| 1672 global_epilogue_callback_status *= 5; | |
| 1673 } | |
| 1674 | |
| 1675 | |
| 1676 TEST_CASE(GarbageCollectionCallbacks) { | |
|
turnidge
2012/03/07 00:25:16
Consider splitting into a few smaller tests.
I li
cshapiro
2012/03/07 03:06:10
Done.
| |
| 1677 // Add a prologue callback. | |
| 1678 EXPECT_VALID(Dart_NewGcPrologueCallback(&PrologueCallbackTimes2)); | |
| 1679 | |
| 1680 // Add the same prologue callback again. This is an error. | |
| 1681 EXPECT(Dart_IsError(Dart_NewGcPrologueCallback(&PrologueCallbackTimes2))); | |
| 1682 | |
| 1683 // Garbage collect new space. This should not invoke the prologue | |
| 1684 // callback. No status values should change. | |
| 1685 global_prologue_callback_status = 3; | |
| 1686 global_epilogue_callback_status = 7; | |
| 1687 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | |
| 1688 EXPECT_EQ(3, global_prologue_callback_status); | |
| 1689 EXPECT_EQ(7, global_epilogue_callback_status); | |
| 1690 | |
| 1691 // Garbage collect old space. This should invoke the prologue | |
| 1692 // callback. The prologue status value should change. | |
| 1693 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | |
| 1694 EXPECT_EQ(6, global_prologue_callback_status); | |
| 1695 EXPECT_EQ(7, global_epilogue_callback_status); | |
| 1696 | |
| 1697 // Garbage collect old space again. Callbacks are persistent so the | |
| 1698 // prolog status value should change again. | |
| 1699 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | |
| 1700 EXPECT_EQ(12, global_prologue_callback_status); | |
| 1701 EXPECT_EQ(7, global_epilogue_callback_status); | |
| 1702 | |
| 1703 // Add an GC epilogue callback. | |
| 1704 EXPECT_VALID(Dart_NewGcEpilogueCallback(&EpilogueCallbackTimes4)); | |
| 1705 | |
| 1706 // Add the same epilogue callback again. This is an error. | |
| 1707 EXPECT(Dart_IsError(Dart_NewGcEpilogueCallback(&EpilogueCallbackTimes4))); | |
| 1708 | |
| 1709 // Garbage collect new space. This should not invoke the prologue | |
| 1710 // or the epilogue callback. No status values should change. | |
| 1711 global_prologue_callback_status = 3; | |
| 1712 global_epilogue_callback_status = 7; | |
| 1713 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | |
| 1714 EXPECT_EQ(3, global_prologue_callback_status); | |
| 1715 EXPECT_EQ(7, global_epilogue_callback_status); | |
| 1716 | |
| 1717 // Garbage collect old space. This should invoke the prologue and | |
| 1718 // the epilogue callbacks. The prologue and epilogue status values | |
| 1719 // should change. | |
| 1720 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | |
| 1721 EXPECT_EQ(6, global_prologue_callback_status); | |
| 1722 EXPECT_EQ(28, global_epilogue_callback_status); | |
| 1723 | |
| 1724 // Garbage collect old space again. Callbacks are persistent so the | |
| 1725 // prologue and epilogue status values should change again. | |
| 1726 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | |
| 1727 EXPECT_EQ(12, global_prologue_callback_status); | |
| 1728 EXPECT_EQ(112, global_epilogue_callback_status); | |
| 1729 | |
| 1730 // Add another GC prologue callback. | |
| 1731 EXPECT_VALID(Dart_NewGcPrologueCallback(&PrologueCallbackTimes3)); | |
| 1732 | |
| 1733 // Garbage collect old space. This should invoke both prologue | |
| 1734 // callbacks and the epilogue callback. The prologue and epilogue | |
| 1735 // status values should change. | |
| 1736 global_prologue_callback_status = 3; | |
| 1737 global_epilogue_callback_status = 7; | |
| 1738 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | |
| 1739 EXPECT_EQ(18, global_prologue_callback_status); | |
| 1740 EXPECT_EQ(28, global_epilogue_callback_status); | |
| 1741 | |
| 1742 // Add another GC epilogue callback. | |
| 1743 EXPECT_VALID(Dart_NewGcEpilogueCallback(&EpilogueCallbackTimes5)); | |
| 1744 | |
| 1745 // Garbage collect old space. This should invoke both prologue | |
| 1746 // callbacks and both epilogue callbacks. The prologue and epilogue | |
| 1747 // status values should change. | |
| 1748 global_prologue_callback_status = 3; | |
| 1749 global_epilogue_callback_status = 7; | |
| 1750 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | |
| 1751 EXPECT_EQ(18, global_prologue_callback_status); | |
| 1752 EXPECT_EQ(140, global_epilogue_callback_status); | |
| 1753 | |
| 1754 // Remove an epilogue callback. | |
| 1755 EXPECT_VALID(Dart_DeleteGcEpilogueCallback(&EpilogueCallbackTimes4)); | |
| 1756 | |
| 1757 // Garbage collect old space. This should invoke both prologue | |
| 1758 // callbacks and the remaining epilogue callback. The prologue and | |
| 1759 // epilogue status values should change. | |
| 1760 global_prologue_callback_status = 3; | |
| 1761 global_epilogue_callback_status = 7; | |
| 1762 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | |
| 1763 EXPECT_EQ(18, global_prologue_callback_status); | |
| 1764 EXPECT_EQ(35, global_epilogue_callback_status); | |
| 1765 | |
| 1766 // Try removing the epilogue callback again. This is an error. | |
| 1767 EXPECT(Dart_IsError(Dart_DeleteGcEpilogueCallback(&EpilogueCallbackTimes4))); | |
| 1768 | |
| 1769 // Remove the remaining epilogue callback. | |
| 1770 EXPECT_VALID(Dart_DeleteGcEpilogueCallback(&EpilogueCallbackTimes5)); | |
| 1771 | |
| 1772 // Try removing the remaining epilogue callback again. This is an | |
| 1773 // error. | |
| 1774 EXPECT(Dart_IsError(Dart_DeleteGcEpilogueCallback(&EpilogueCallbackTimes5))); | |
| 1775 | |
| 1776 // Garbage collect old space. This should invoke both prologue | |
| 1777 // callbacks. The prologue status value should change. | |
| 1778 global_prologue_callback_status = 3; | |
| 1779 global_epilogue_callback_status = 7; | |
| 1780 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | |
| 1781 EXPECT_EQ(18, global_prologue_callback_status); | |
| 1782 EXPECT_EQ(7, global_epilogue_callback_status); | |
| 1783 | |
| 1784 // Remove a prologue callback. | |
| 1785 EXPECT_VALID(Dart_DeleteGcPrologueCallback(&PrologueCallbackTimes3)); | |
| 1786 | |
| 1787 // Try removing the prologue callback again. This is an error. | |
| 1788 EXPECT(Dart_IsError(Dart_DeleteGcPrologueCallback(&PrologueCallbackTimes3))); | |
| 1789 | |
| 1790 // Garbage collect old space. This should invoke the remaining | |
| 1791 // prologue callback. The prologue status value should change. | |
| 1792 global_prologue_callback_status = 3; | |
| 1793 global_epilogue_callback_status = 7; | |
| 1794 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | |
| 1795 EXPECT_EQ(6, global_prologue_callback_status); | |
| 1796 EXPECT_EQ(7, global_epilogue_callback_status); | |
| 1797 | |
| 1798 // Remove the remaining prologue callback. | |
| 1799 EXPECT_VALID(Dart_DeleteGcPrologueCallback(&PrologueCallbackTimes2)); | |
| 1800 | |
| 1801 // Try removing the remaining prologue callback again. This is an | |
| 1802 // error. | |
| 1803 EXPECT(Dart_IsError(Dart_DeleteGcPrologueCallback(&PrologueCallbackTimes2))); | |
| 1804 | |
| 1805 // Garbage collect old space. No callbacks should be invoked. No | |
| 1806 // status values should change. | |
| 1807 global_prologue_callback_status = 3; | |
| 1808 global_epilogue_callback_status = 7; | |
| 1809 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | |
| 1810 EXPECT_EQ(3, global_prologue_callback_status); | |
| 1811 EXPECT_EQ(7, global_epilogue_callback_status); | |
| 1812 } | |
| 1813 | |
| 1649 #endif | 1814 #endif |
| 1650 | 1815 |
| 1651 | 1816 |
| 1652 // Unit test for creating multiple scopes and local handles within them. | 1817 // Unit test for creating multiple scopes and local handles within them. |
| 1653 // Ensure that the local handles get all cleaned out when exiting the | 1818 // Ensure that the local handles get all cleaned out when exiting the |
| 1654 // scope. | 1819 // scope. |
| 1655 UNIT_TEST_CASE(LocalHandles) { | 1820 UNIT_TEST_CASE(LocalHandles) { |
| 1656 TestCase::CreateTestIsolate(); | 1821 TestCase::CreateTestIsolate(); |
| 1657 Isolate* isolate = Isolate::Current(); | 1822 Isolate* isolate = Isolate::Current(); |
| 1658 EXPECT(isolate != NULL); | 1823 EXPECT(isolate != NULL); |
| (...skipping 2343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4002 // We should have received the expected number of interrupts. | 4167 // We should have received the expected number of interrupts. |
| 4003 EXPECT_EQ(kInterruptCount, interrupt_count); | 4168 EXPECT_EQ(kInterruptCount, interrupt_count); |
| 4004 | 4169 |
| 4005 // Give the spawned thread enough time to properly exit. | 4170 // Give the spawned thread enough time to properly exit. |
| 4006 Isolate::SetInterruptCallback(saved); | 4171 Isolate::SetInterruptCallback(saved); |
| 4007 } | 4172 } |
| 4008 | 4173 |
| 4009 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 4174 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 4010 | 4175 |
| 4011 } // namespace dart | 4176 } // namespace dart |
| OLD | NEW |