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 1543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1554 } | 1554 } |
1555 | 1555 |
1556 // All weak references should now be cleared. | 1556 // All weak references should now be cleared. |
1557 EXPECT(Dart_IsNull(weak1)); | 1557 EXPECT(Dart_IsNull(weak1)); |
1558 EXPECT(Dart_IsNull(weak2)); | 1558 EXPECT(Dart_IsNull(weak2)); |
1559 EXPECT(Dart_IsNull(weak3)); | 1559 EXPECT(Dart_IsNull(weak3)); |
1560 EXPECT(Dart_IsNull(weak4)); | 1560 EXPECT(Dart_IsNull(weak4)); |
1561 } | 1561 } |
1562 | 1562 |
1563 | 1563 |
| 1564 TEST_CASE(PrologueWeakPersistentHandles) { |
| 1565 Dart_Handle old_pwph = Dart_Null(); |
| 1566 EXPECT(Dart_IsNull(old_pwph)); |
| 1567 Dart_Handle new_pwph = Dart_Null(); |
| 1568 EXPECT(Dart_IsNull(new_pwph)); |
| 1569 Dart_EnterScope(); |
| 1570 { |
| 1571 DARTSCOPE(Isolate::Current()); |
| 1572 String& str = String::Handle(); |
| 1573 str ^= String::New("new space prologue weak", Heap::kNew); |
| 1574 new_pwph = Dart_NewPrologueWeakPersistentHandle(Api::NewLocalHandle(str), |
| 1575 NULL, |
| 1576 NULL); |
| 1577 EXPECT_VALID(new_pwph); |
| 1578 EXPECT(!Dart_IsNull(new_pwph)); |
| 1579 str ^= String::New("old space prologue weak", Heap::kOld); |
| 1580 old_pwph = Dart_NewPrologueWeakPersistentHandle(Api::NewLocalHandle(str), |
| 1581 NULL, |
| 1582 NULL); |
| 1583 EXPECT_VALID(old_pwph); |
| 1584 EXPECT(!Dart_IsNull(old_pwph)); |
| 1585 str ^= String::null(); |
| 1586 } |
| 1587 Dart_ExitScope(); |
| 1588 EXPECT_VALID(new_pwph); |
| 1589 EXPECT(!Dart_IsNull(new_pwph)); |
| 1590 EXPECT(Dart_IsPrologueWeakPersistentHandle(new_pwph)); |
| 1591 EXPECT_VALID(old_pwph); |
| 1592 EXPECT(!Dart_IsNull(old_pwph)); |
| 1593 EXPECT(Dart_IsPrologueWeakPersistentHandle(old_pwph)); |
| 1594 // Garbage collect new space without invoking API callbacks. |
| 1595 Isolate::Current()->heap()->CollectGarbage(Heap::kNew, |
| 1596 Heap::kIgnoreApiCallbacks); |
| 1597 // Both prologue weak handles should be preserved. |
| 1598 EXPECT(!Dart_IsNull(new_pwph)); |
| 1599 EXPECT(!Dart_IsNull(old_pwph)); |
| 1600 // Garbage collect old space without invoking API callbacks. |
| 1601 Isolate::Current()->heap()->CollectGarbage(Heap::kOld, |
| 1602 Heap::kIgnoreApiCallbacks); |
| 1603 // Both prologue weak handles should be preserved. |
| 1604 EXPECT(!Dart_IsNull(new_pwph)); |
| 1605 EXPECT(!Dart_IsNull(old_pwph)); |
| 1606 // Garbage collect new space invoking API callbacks. |
| 1607 Isolate::Current()->heap()->CollectGarbage(Heap::kNew, |
| 1608 Heap::kInvokeApiCallbacks); |
| 1609 // The prologue weak handle with a new space referent should now be |
| 1610 // cleared. The old space referent should be preserved. |
| 1611 EXPECT(Dart_IsNull(new_pwph)); |
| 1612 EXPECT(!Dart_IsNull(old_pwph)); |
| 1613 Isolate::Current()->heap()->CollectGarbage(Heap::kOld, |
| 1614 Heap::kInvokeApiCallbacks); |
| 1615 // The prologue weak handle with an old space referent should now be |
| 1616 // cleared. The new space referent should remain cleared. |
| 1617 EXPECT(Dart_IsNull(new_pwph)); |
| 1618 EXPECT(Dart_IsNull(old_pwph)); |
| 1619 } |
| 1620 |
| 1621 |
1564 TEST_CASE(ImplicitReferences) { | 1622 TEST_CASE(ImplicitReferences) { |
1565 Dart_Handle strong = Dart_Null(); | 1623 Dart_Handle strong = Dart_Null(); |
1566 EXPECT(Dart_IsNull(strong)); | 1624 EXPECT(Dart_IsNull(strong)); |
1567 | 1625 |
1568 Dart_Handle weak1 = Dart_Null(); | 1626 Dart_Handle weak1 = Dart_Null(); |
1569 EXPECT(Dart_IsNull(weak1)); | 1627 EXPECT(Dart_IsNull(weak1)); |
1570 | 1628 |
1571 Dart_Handle weak2 = Dart_Null(); | 1629 Dart_Handle weak2 = Dart_Null(); |
1572 EXPECT(Dart_IsNull(weak2)); | 1630 EXPECT(Dart_IsNull(weak2)); |
1573 | 1631 |
(...skipping 3104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4678 // We should have received the expected number of interrupts. | 4736 // We should have received the expected number of interrupts. |
4679 EXPECT_EQ(kInterruptCount, interrupt_count); | 4737 EXPECT_EQ(kInterruptCount, interrupt_count); |
4680 | 4738 |
4681 // Give the spawned thread enough time to properly exit. | 4739 // Give the spawned thread enough time to properly exit. |
4682 Isolate::SetInterruptCallback(saved); | 4740 Isolate::SetInterruptCallback(saved); |
4683 } | 4741 } |
4684 | 4742 |
4685 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 4743 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
4686 | 4744 |
4687 } // namespace dart | 4745 } // namespace dart |
OLD | NEW |