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

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 9956138: Process weak reference sets when a scavenge invokes the API callbacks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 | « no previous file | runtime/vm/scavenger.h » ('j') | runtime/vm/scavenger.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1601 matching lines...) Expand 10 before | Expand all | Expand 10 after
1612 EXPECT(!Dart_IsNull(old_pwph)); 1612 EXPECT(!Dart_IsNull(old_pwph));
1613 Isolate::Current()->heap()->CollectGarbage(Heap::kOld, 1613 Isolate::Current()->heap()->CollectGarbage(Heap::kOld,
1614 Heap::kInvokeApiCallbacks); 1614 Heap::kInvokeApiCallbacks);
1615 // The prologue weak handle with an old space referent should now be 1615 // The prologue weak handle with an old space referent should now be
1616 // cleared. The new space referent should remain cleared. 1616 // cleared. The new space referent should remain cleared.
1617 EXPECT(Dart_IsNull(new_pwph)); 1617 EXPECT(Dart_IsNull(new_pwph));
1618 EXPECT(Dart_IsNull(old_pwph)); 1618 EXPECT(Dart_IsNull(old_pwph));
1619 } 1619 }
1620 1620
1621 1621
1622 TEST_CASE(ImplicitReferences) { 1622 TEST_CASE(OldSpaceImplicitReferences) {
1623 Dart_Handle strong = Dart_Null(); 1623 Dart_Handle strong = Dart_Null();
1624 EXPECT(Dart_IsNull(strong)); 1624 EXPECT(Dart_IsNull(strong));
1625 1625
1626 Dart_Handle weak1 = Dart_Null(); 1626 Dart_Handle weak1 = Dart_Null();
1627 EXPECT(Dart_IsNull(weak1)); 1627 EXPECT(Dart_IsNull(weak1));
1628 1628
1629 Dart_Handle weak2 = Dart_Null(); 1629 Dart_Handle weak2 = Dart_Null();
1630 EXPECT(Dart_IsNull(weak2)); 1630 EXPECT(Dart_IsNull(weak2));
1631 1631
1632 Dart_Handle weak3 = Dart_Null(); 1632 Dart_Handle weak3 = Dart_Null();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); 1698 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
1699 } 1699 }
1700 1700
1701 // All weak references except weak3 should be preserved. 1701 // All weak references except weak3 should be preserved.
1702 EXPECT(!Dart_IsNull(weak1)); 1702 EXPECT(!Dart_IsNull(weak1));
1703 EXPECT(!Dart_IsNull(weak2)); 1703 EXPECT(!Dart_IsNull(weak2));
1704 EXPECT(Dart_IsNull(weak3)); 1704 EXPECT(Dart_IsNull(weak3));
1705 } 1705 }
1706 1706
1707 1707
1708 TEST_CASE(NewSpaceImplicitReferences) {
1709 Dart_Handle strong = Dart_Null();
1710 EXPECT(Dart_IsNull(strong));
1711
1712 Dart_Handle weak1 = Dart_Null();
1713 EXPECT(Dart_IsNull(weak1));
1714
1715 Dart_Handle weak2 = Dart_Null();
1716 EXPECT(Dart_IsNull(weak2));
1717
1718 Dart_Handle weak3 = Dart_Null();
1719 EXPECT(Dart_IsNull(weak3));
1720
1721
1722 Dart_EnterScope();
1723 {
1724 DARTSCOPE(Isolate::Current());
1725 String& str = String::Handle();
1726
1727 str ^= String::New("strongly reachable", Heap::kNew);
1728 strong = Dart_NewPersistentHandle(Api::NewLocalHandle(str));
1729 EXPECT(!Dart_IsNull(strong));
1730 EXPECT_VALID(strong);
1731
1732 str ^= String::New("weakly reachable 1", Heap::kNew);
1733 weak1 = Dart_NewWeakPersistentHandle(Api::NewLocalHandle(str), NULL, NULL);
1734 EXPECT(!Dart_IsNull(weak1));
1735 EXPECT_VALID(weak1);
1736
1737 str ^= String::New("weakly reachable 2", Heap::kNew);
1738 weak2 = Dart_NewWeakPersistentHandle(Api::NewLocalHandle(str), NULL, NULL);
1739 EXPECT(!Dart_IsNull(weak2));
1740 EXPECT_VALID(weak2);
1741
1742 str ^= String::New("weakly reachable 3", Heap::kNew);
1743 weak3 = Dart_NewWeakPersistentHandle(Api::NewLocalHandle(str), NULL, NULL);
1744 EXPECT(!Dart_IsNull(weak3));
1745 EXPECT_VALID(weak3);
1746 }
1747 Dart_ExitScope();
1748
1749 EXPECT_VALID(strong);
1750
1751 EXPECT_VALID(weak1);
1752 EXPECT_VALID(weak2);
1753 EXPECT_VALID(weak3);
1754
1755 Isolate::Current()->heap()->CollectGarbage(Heap::kOld);
1756
1757 // Old space collection should not affect old space objects.
1758 EXPECT(!Dart_IsNull(weak1));
1759 EXPECT(!Dart_IsNull(weak2));
1760 EXPECT(!Dart_IsNull(weak3));
1761
1762 // A strongly referenced key should preserve all the values.
1763 {
1764 Dart_Handle keys[] = { strong };
1765 Dart_Handle values[] = { weak1, weak2, weak3 };
1766 EXPECT_VALID(Dart_NewWeakReferenceSet(keys, ARRAY_SIZE(keys),
1767 values, ARRAY_SIZE(values)));
1768
1769 Isolate::Current()->heap()->CollectGarbage(Heap::kNew,
1770 Heap::kInvokeApiCallbacks);
1771 }
1772
1773 // All weak references should be preserved.
1774 EXPECT(!Dart_IsNull(weak1));
1775 EXPECT(!Dart_IsNull(weak2));
1776 EXPECT(!Dart_IsNull(weak3));
1777
1778 Isolate::Current()->heap()->CollectGarbage(Heap::kNew,
1779 Heap::kIgnoreApiCallbacks);
1780
1781 // No weak references should be preserved.
1782 EXPECT(Dart_IsNull(weak1));
1783 EXPECT(Dart_IsNull(weak2));
1784 EXPECT(Dart_IsNull(weak3));
1785 }
1786
1787
1708 static int global_prologue_callback_status; 1788 static int global_prologue_callback_status;
1709 1789
1710 1790
1711 static void PrologueCallbackTimes2() { 1791 static void PrologueCallbackTimes2() {
1712 global_prologue_callback_status *= 2; 1792 global_prologue_callback_status *= 2;
1713 } 1793 }
1714 1794
1715 1795
1716 static void PrologueCallbackTimes3() { 1796 static void PrologueCallbackTimes3() {
1717 global_prologue_callback_status *= 3; 1797 global_prologue_callback_status *= 3;
(...skipping 3018 matching lines...) Expand 10 before | Expand all | Expand 10 after
4736 // We should have received the expected number of interrupts. 4816 // We should have received the expected number of interrupts.
4737 EXPECT_EQ(kInterruptCount, interrupt_count); 4817 EXPECT_EQ(kInterruptCount, interrupt_count);
4738 4818
4739 // Give the spawned thread enough time to properly exit. 4819 // Give the spawned thread enough time to properly exit.
4740 Isolate::SetInterruptCallback(saved); 4820 Isolate::SetInterruptCallback(saved);
4741 } 4821 }
4742 4822
4743 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 4823 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
4744 4824
4745 } // namespace dart 4825 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/scavenger.h » ('j') | runtime/vm/scavenger.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698