| 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/json.h" | 7 #include "platform/json.h" |
| 8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
| 10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
| (...skipping 1277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1288 | 1288 |
| 1289 // Make sure that the value transferred. | 1289 // Make sure that the value transferred. |
| 1290 EXPECT(Dart_IsBoolean(obj2)); | 1290 EXPECT(Dart_IsBoolean(obj2)); |
| 1291 bool value = false; | 1291 bool value = false; |
| 1292 Dart_Handle result = Dart_BooleanValue(obj2, &value); | 1292 Dart_Handle result = Dart_BooleanValue(obj2, &value); |
| 1293 EXPECT_VALID(result); | 1293 EXPECT_VALID(result); |
| 1294 EXPECT(value); | 1294 EXPECT(value); |
| 1295 } | 1295 } |
| 1296 | 1296 |
| 1297 | 1297 |
| 1298 // Helper class to ensure new gen GC is triggered without any side effects. |
| 1299 // The normal call to CollectGarbage(Heap::kNew) could potentially trigger |
| 1300 // an old gen collection if there is a promotion failure and this could |
| 1301 // perturb the test. |
| 1302 class GCTestHelper : public AllStatic { |
| 1303 public: |
| 1304 static void CollectNewSpace(Heap::ApiCallbacks api_callbacks) { |
| 1305 bool invoke_api_callbacks = (api_callbacks == Heap::kInvokeApiCallbacks); |
| 1306 Isolate::Current()->heap()->new_space_->Scavenge(invoke_api_callbacks); |
| 1307 } |
| 1308 }; |
| 1309 |
| 1310 |
| 1298 // Only ia32 and x64 can run execution tests. | 1311 // Only ia32 and x64 can run execution tests. |
| 1299 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 1312 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 1300 | 1313 |
| 1301 TEST_CASE(WeakPersistentHandle) { | 1314 TEST_CASE(WeakPersistentHandle) { |
| 1302 Dart_Handle weak_new_ref = Dart_Null(); | 1315 Dart_Handle weak_new_ref = Dart_Null(); |
| 1303 EXPECT(Dart_IsNull(weak_new_ref)); | 1316 EXPECT(Dart_IsNull(weak_new_ref)); |
| 1304 | 1317 |
| 1305 Dart_Handle weak_old_ref = Dart_Null(); | 1318 Dart_Handle weak_old_ref = Dart_Null(); |
| 1306 EXPECT(Dart_IsNull(weak_old_ref)); | 1319 EXPECT(Dart_IsNull(weak_old_ref)); |
| 1307 | 1320 |
| 1308 { | 1321 { |
| 1309 Dart_EnterScope(); | 1322 Dart_EnterScope(); |
| 1310 | 1323 |
| 1311 // create an object in new space | 1324 // Create an object in new space. |
| 1312 Dart_Handle new_ref = Dart_NewString("new string"); | 1325 Dart_Handle new_ref = Dart_NewString("new string"); |
| 1313 EXPECT_VALID(new_ref); | 1326 EXPECT_VALID(new_ref); |
| 1314 | 1327 |
| 1315 // create an object in old space | 1328 // Create an object in old space. |
| 1316 Dart_Handle old_ref; | 1329 Dart_Handle old_ref; |
| 1317 { | 1330 { |
| 1318 Isolate* isolate = Isolate::Current(); | 1331 Isolate* isolate = Isolate::Current(); |
| 1319 DARTSCOPE(isolate); | 1332 DARTSCOPE(isolate); |
| 1320 old_ref = Api::NewHandle(isolate, String::New("old string", Heap::kOld)); | 1333 old_ref = Api::NewHandle(isolate, String::New("old string", Heap::kOld)); |
| 1321 EXPECT_VALID(old_ref); | 1334 EXPECT_VALID(old_ref); |
| 1322 } | 1335 } |
| 1323 | 1336 |
| 1324 // create a weak ref to the new space object | 1337 // Create a weak ref to the new space object. |
| 1325 weak_new_ref = Dart_NewWeakPersistentHandle(new_ref, NULL, NULL); | 1338 weak_new_ref = Dart_NewWeakPersistentHandle(new_ref, NULL, NULL); |
| 1326 EXPECT_VALID(weak_new_ref); | 1339 EXPECT_VALID(weak_new_ref); |
| 1327 EXPECT(!Dart_IsNull(weak_new_ref)); | 1340 EXPECT(!Dart_IsNull(weak_new_ref)); |
| 1328 | 1341 |
| 1329 // create a weak ref to the old space object | 1342 // Create a weak ref to the old space object. |
| 1330 weak_old_ref = Dart_NewWeakPersistentHandle(old_ref, NULL, NULL); | 1343 weak_old_ref = Dart_NewWeakPersistentHandle(old_ref, NULL, NULL); |
| 1331 EXPECT_VALID(weak_old_ref); | 1344 EXPECT_VALID(weak_old_ref); |
| 1332 EXPECT(!Dart_IsNull(weak_old_ref)); | 1345 EXPECT(!Dart_IsNull(weak_old_ref)); |
| 1333 | 1346 |
| 1334 // garbage collect new space | 1347 // Garbage collect new space. |
| 1335 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 1348 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 1336 | 1349 |
| 1337 // nothing should be invalidated or cleared | 1350 // Nothing should be invalidated or cleared. |
| 1338 EXPECT_VALID(new_ref); | 1351 EXPECT_VALID(new_ref); |
| 1339 EXPECT(!Dart_IsNull(new_ref)); | 1352 EXPECT(!Dart_IsNull(new_ref)); |
| 1340 EXPECT_VALID(old_ref); | 1353 EXPECT_VALID(old_ref); |
| 1341 EXPECT(!Dart_IsNull(old_ref)); | 1354 EXPECT(!Dart_IsNull(old_ref)); |
| 1342 | 1355 |
| 1343 EXPECT_VALID(weak_new_ref); | 1356 EXPECT_VALID(weak_new_ref); |
| 1344 EXPECT(!Dart_IsNull(weak_new_ref)); | 1357 EXPECT(!Dart_IsNull(weak_new_ref)); |
| 1345 EXPECT(Dart_IdentityEquals(new_ref, weak_new_ref)); | 1358 EXPECT(Dart_IdentityEquals(new_ref, weak_new_ref)); |
| 1346 | 1359 |
| 1347 EXPECT_VALID(weak_old_ref); | 1360 EXPECT_VALID(weak_old_ref); |
| 1348 EXPECT(!Dart_IsNull(weak_old_ref)); | 1361 EXPECT(!Dart_IsNull(weak_old_ref)); |
| 1349 EXPECT(Dart_IdentityEquals(old_ref, weak_old_ref)); | 1362 EXPECT(Dart_IdentityEquals(old_ref, weak_old_ref)); |
| 1350 | 1363 |
| 1351 // garbage collect old space | 1364 // Garbage collect old space. |
| 1352 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 1365 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 1353 | 1366 |
| 1354 // nothing should be invalidated or cleared | 1367 // Nothing should be invalidated or cleared. |
| 1355 EXPECT_VALID(new_ref); | 1368 EXPECT_VALID(new_ref); |
| 1356 EXPECT(!Dart_IsNull(new_ref)); | 1369 EXPECT(!Dart_IsNull(new_ref)); |
| 1357 EXPECT_VALID(old_ref); | 1370 EXPECT_VALID(old_ref); |
| 1358 EXPECT(!Dart_IsNull(old_ref)); | 1371 EXPECT(!Dart_IsNull(old_ref)); |
| 1359 | 1372 |
| 1360 EXPECT_VALID(weak_new_ref); | 1373 EXPECT_VALID(weak_new_ref); |
| 1361 EXPECT(!Dart_IsNull(weak_new_ref)); | 1374 EXPECT(!Dart_IsNull(weak_new_ref)); |
| 1362 EXPECT(Dart_IdentityEquals(new_ref, weak_new_ref)); | 1375 EXPECT(Dart_IdentityEquals(new_ref, weak_new_ref)); |
| 1363 | 1376 |
| 1364 EXPECT_VALID(weak_old_ref); | 1377 EXPECT_VALID(weak_old_ref); |
| 1365 EXPECT(!Dart_IsNull(weak_old_ref)); | 1378 EXPECT(!Dart_IsNull(weak_old_ref)); |
| 1366 EXPECT(Dart_IdentityEquals(old_ref, weak_old_ref)); | 1379 EXPECT(Dart_IdentityEquals(old_ref, weak_old_ref)); |
| 1367 | 1380 |
| 1368 // delete local (strong) references | 1381 // Delete local (strong) references. |
| 1369 Dart_ExitScope(); | 1382 Dart_ExitScope(); |
| 1370 } | 1383 } |
| 1371 | 1384 |
| 1372 // garbage collect new space again | 1385 // Garbage collect new space again. |
| 1373 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 1386 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 1374 | 1387 |
| 1375 // weak ref to new space object should now be cleared | 1388 // Weak ref to new space object should now be cleared. |
| 1376 EXPECT_VALID(weak_new_ref); | 1389 EXPECT_VALID(weak_new_ref); |
| 1377 EXPECT(Dart_IsNull(weak_new_ref)); | 1390 EXPECT(Dart_IsNull(weak_new_ref)); |
| 1378 EXPECT_VALID(weak_old_ref); | 1391 EXPECT_VALID(weak_old_ref); |
| 1379 EXPECT(!Dart_IsNull(weak_old_ref)); | 1392 EXPECT(!Dart_IsNull(weak_old_ref)); |
| 1380 | 1393 |
| 1381 // garbage collect old space again | 1394 // Garbage collect old space again. |
| 1382 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 1395 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 1383 | 1396 |
| 1384 // weak ref to old space object should now be cleared | 1397 // Weak ref to old space object should now be cleared. |
| 1385 EXPECT_VALID(weak_new_ref); | 1398 EXPECT_VALID(weak_new_ref); |
| 1386 EXPECT(Dart_IsNull(weak_new_ref)); | 1399 EXPECT(Dart_IsNull(weak_new_ref)); |
| 1387 EXPECT_VALID(weak_old_ref); | 1400 EXPECT_VALID(weak_old_ref); |
| 1388 EXPECT(Dart_IsNull(weak_old_ref)); | 1401 EXPECT(Dart_IsNull(weak_old_ref)); |
| 1389 | 1402 |
| 1390 Dart_DeletePersistentHandle(weak_new_ref); | 1403 Dart_DeletePersistentHandle(weak_new_ref); |
| 1391 Dart_DeletePersistentHandle(weak_old_ref); | 1404 Dart_DeletePersistentHandle(weak_old_ref); |
| 1392 | 1405 |
| 1393 // garbage collect one last time to revisit deleted handles | 1406 // Garbage collect one last time to revisit deleted handles. |
| 1394 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 1407 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); |
| 1395 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 1408 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 1396 } | 1409 } |
| 1397 | 1410 |
| 1398 | 1411 |
| 1399 static void WeakPersistentHandlePeerFinalizer(Dart_Handle handle, void* peer) { | 1412 static void WeakPersistentHandlePeerFinalizer(Dart_Handle handle, void* peer) { |
| 1400 *static_cast<int*>(peer) = 42; | 1413 *static_cast<int*>(peer) = 42; |
| 1401 } | 1414 } |
| 1402 | 1415 |
| 1403 | 1416 |
| 1404 TEST_CASE(WeakPersistentHandleCallback) { | 1417 TEST_CASE(WeakPersistentHandleCallback) { |
| 1405 Dart_Handle weak_ref = Dart_Null(); | 1418 Dart_Handle weak_ref = Dart_Null(); |
| 1406 EXPECT(Dart_IsNull(weak_ref)); | 1419 EXPECT(Dart_IsNull(weak_ref)); |
| 1407 int* peer = new int(); | 1420 int* peer = new int(); |
| 1408 { | 1421 { |
| 1409 Dart_EnterScope(); | 1422 Dart_EnterScope(); |
| 1410 Dart_Handle obj = Dart_NewString("new string"); | 1423 Dart_Handle obj = Dart_NewString("new string"); |
| 1411 EXPECT_VALID(obj); | 1424 EXPECT_VALID(obj); |
| 1412 weak_ref = Dart_NewWeakPersistentHandle(obj, peer, | 1425 weak_ref = Dart_NewWeakPersistentHandle(obj, peer, |
| 1413 WeakPersistentHandlePeerFinalizer); | 1426 WeakPersistentHandlePeerFinalizer); |
| 1414 Dart_ExitScope(); | 1427 Dart_ExitScope(); |
| 1415 } | 1428 } |
| 1416 EXPECT_VALID(weak_ref); | 1429 EXPECT_VALID(weak_ref); |
| 1417 EXPECT(*peer == 0); | 1430 EXPECT(*peer == 0); |
| 1418 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 1431 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 1419 EXPECT(*peer == 0); | 1432 EXPECT(*peer == 0); |
| 1420 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 1433 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 1421 EXPECT(*peer == 42); | 1434 EXPECT(*peer == 42); |
| 1422 delete peer; | 1435 delete peer; |
| 1423 Dart_DeletePersistentHandle(weak_ref); | 1436 Dart_DeletePersistentHandle(weak_ref); |
| 1424 } | 1437 } |
| 1425 | 1438 |
| 1426 | 1439 |
| 1427 TEST_CASE(ObjectGroups) { | 1440 TEST_CASE(ObjectGroups) { |
| 1428 Dart_Handle strong = Dart_Null(); | 1441 Dart_Handle strong = Dart_Null(); |
| 1429 EXPECT(Dart_IsNull(strong)); | 1442 EXPECT(Dart_IsNull(strong)); |
| 1430 | 1443 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1476 } | 1489 } |
| 1477 Dart_ExitScope(); | 1490 Dart_ExitScope(); |
| 1478 | 1491 |
| 1479 EXPECT_VALID(strong); | 1492 EXPECT_VALID(strong); |
| 1480 | 1493 |
| 1481 EXPECT_VALID(weak1); | 1494 EXPECT_VALID(weak1); |
| 1482 EXPECT_VALID(weak2); | 1495 EXPECT_VALID(weak2); |
| 1483 EXPECT_VALID(weak3); | 1496 EXPECT_VALID(weak3); |
| 1484 EXPECT_VALID(weak4); | 1497 EXPECT_VALID(weak4); |
| 1485 | 1498 |
| 1486 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 1499 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 1487 | 1500 |
| 1488 // New space collection should not affect old space objects | 1501 // New space collection should not affect old space objects |
| 1489 EXPECT(!Dart_IsNull(weak1)); | 1502 EXPECT(!Dart_IsNull(weak1)); |
| 1490 EXPECT(!Dart_IsNull(weak2)); | 1503 EXPECT(!Dart_IsNull(weak2)); |
| 1491 EXPECT(!Dart_IsNull(weak3)); | 1504 EXPECT(!Dart_IsNull(weak3)); |
| 1492 EXPECT(!Dart_IsNull(weak4)); | 1505 EXPECT(!Dart_IsNull(weak4)); |
| 1493 | 1506 |
| 1494 { | 1507 { |
| 1495 Dart_Handle array1[] = { weak1, strong }; | 1508 Dart_Handle array1[] = { weak1, strong }; |
| 1496 EXPECT_VALID(Dart_NewWeakReferenceSet(array1, ARRAY_SIZE(array1), | 1509 EXPECT_VALID(Dart_NewWeakReferenceSet(array1, ARRAY_SIZE(array1), |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1640 EXPECT(!Dart_IsNull(old_pwph)); | 1653 EXPECT(!Dart_IsNull(old_pwph)); |
| 1641 } | 1654 } |
| 1642 Dart_ExitScope(); | 1655 Dart_ExitScope(); |
| 1643 EXPECT_VALID(new_pwph); | 1656 EXPECT_VALID(new_pwph); |
| 1644 EXPECT(!Dart_IsNull(new_pwph)); | 1657 EXPECT(!Dart_IsNull(new_pwph)); |
| 1645 EXPECT(Dart_IsPrologueWeakPersistentHandle(new_pwph)); | 1658 EXPECT(Dart_IsPrologueWeakPersistentHandle(new_pwph)); |
| 1646 EXPECT_VALID(old_pwph); | 1659 EXPECT_VALID(old_pwph); |
| 1647 EXPECT(!Dart_IsNull(old_pwph)); | 1660 EXPECT(!Dart_IsNull(old_pwph)); |
| 1648 EXPECT(Dart_IsPrologueWeakPersistentHandle(old_pwph)); | 1661 EXPECT(Dart_IsPrologueWeakPersistentHandle(old_pwph)); |
| 1649 // Garbage collect new space without invoking API callbacks. | 1662 // Garbage collect new space without invoking API callbacks. |
| 1650 Isolate::Current()->heap()->CollectGarbage(Heap::kNew, | 1663 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 1651 Heap::kIgnoreApiCallbacks); | 1664 |
| 1652 // Both prologue weak handles should be preserved. | 1665 // Both prologue weak handles should be preserved. |
| 1653 EXPECT(!Dart_IsNull(new_pwph)); | 1666 EXPECT(!Dart_IsNull(new_pwph)); |
| 1654 EXPECT(!Dart_IsNull(old_pwph)); | 1667 EXPECT(!Dart_IsNull(old_pwph)); |
| 1655 // Garbage collect old space without invoking API callbacks. | 1668 // Garbage collect old space without invoking API callbacks. |
| 1656 Isolate::Current()->heap()->CollectGarbage(Heap::kOld, | 1669 Isolate::Current()->heap()->CollectGarbage(Heap::kOld, |
| 1657 Heap::kIgnoreApiCallbacks); | 1670 Heap::kIgnoreApiCallbacks); |
| 1658 // Both prologue weak handles should be preserved. | 1671 // Both prologue weak handles should be preserved. |
| 1659 EXPECT(!Dart_IsNull(new_pwph)); | 1672 EXPECT(!Dart_IsNull(new_pwph)); |
| 1660 EXPECT(!Dart_IsNull(old_pwph)); | 1673 EXPECT(!Dart_IsNull(old_pwph)); |
| 1661 // Garbage collect new space invoking API callbacks. | 1674 // Garbage collect new space invoking API callbacks. |
| 1662 Isolate::Current()->heap()->CollectGarbage(Heap::kNew, | 1675 GCTestHelper::CollectNewSpace(Heap::kInvokeApiCallbacks); |
| 1663 Heap::kInvokeApiCallbacks); | 1676 |
| 1664 // The prologue weak handle with a new space referent should now be | 1677 // The prologue weak handle with a new space referent should now be |
| 1665 // cleared. The old space referent should be preserved. | 1678 // cleared. The old space referent should be preserved. |
| 1666 EXPECT(Dart_IsNull(new_pwph)); | 1679 EXPECT(Dart_IsNull(new_pwph)); |
| 1667 EXPECT(!Dart_IsNull(old_pwph)); | 1680 EXPECT(!Dart_IsNull(old_pwph)); |
| 1668 Isolate::Current()->heap()->CollectGarbage(Heap::kOld, | 1681 Isolate::Current()->heap()->CollectGarbage(Heap::kOld, |
| 1669 Heap::kInvokeApiCallbacks); | 1682 Heap::kInvokeApiCallbacks); |
| 1670 // The prologue weak handle with an old space referent should now be | 1683 // The prologue weak handle with an old space referent should now be |
| 1671 // cleared. The new space referent should remain cleared. | 1684 // cleared. The new space referent should remain cleared. |
| 1672 EXPECT(Dart_IsNull(new_pwph)); | 1685 EXPECT(Dart_IsNull(new_pwph)); |
| 1673 EXPECT(Dart_IsNull(old_pwph)); | 1686 EXPECT(Dart_IsNull(old_pwph)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1716 EXPECT_VALID(weak3); | 1729 EXPECT_VALID(weak3); |
| 1717 } | 1730 } |
| 1718 Dart_ExitScope(); | 1731 Dart_ExitScope(); |
| 1719 | 1732 |
| 1720 EXPECT_VALID(strong); | 1733 EXPECT_VALID(strong); |
| 1721 | 1734 |
| 1722 EXPECT_VALID(weak1); | 1735 EXPECT_VALID(weak1); |
| 1723 EXPECT_VALID(weak2); | 1736 EXPECT_VALID(weak2); |
| 1724 EXPECT_VALID(weak3); | 1737 EXPECT_VALID(weak3); |
| 1725 | 1738 |
| 1726 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 1739 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 1727 | 1740 |
| 1728 // New space collection should not affect old space objects | 1741 // New space collection should not affect old space objects |
| 1729 EXPECT(!Dart_IsNull(weak1)); | 1742 EXPECT(!Dart_IsNull(weak1)); |
| 1730 EXPECT(!Dart_IsNull(weak2)); | 1743 EXPECT(!Dart_IsNull(weak2)); |
| 1731 EXPECT(!Dart_IsNull(weak3)); | 1744 EXPECT(!Dart_IsNull(weak3)); |
| 1732 | 1745 |
| 1733 // A strongly referenced key should preserve all the values. | 1746 // A strongly referenced key should preserve all the values. |
| 1734 { | 1747 { |
| 1735 Dart_Handle keys[] = { strong }; | 1748 Dart_Handle keys[] = { strong }; |
| 1736 Dart_Handle values[] = { weak1, weak2, weak3 }; | 1749 Dart_Handle values[] = { weak1, weak2, weak3 }; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1818 EXPECT(!Dart_IsNull(weak2)); | 1831 EXPECT(!Dart_IsNull(weak2)); |
| 1819 EXPECT(!Dart_IsNull(weak3)); | 1832 EXPECT(!Dart_IsNull(weak3)); |
| 1820 | 1833 |
| 1821 // A strongly referenced key should preserve all the values. | 1834 // A strongly referenced key should preserve all the values. |
| 1822 { | 1835 { |
| 1823 Dart_Handle keys[] = { strong }; | 1836 Dart_Handle keys[] = { strong }; |
| 1824 Dart_Handle values[] = { weak1, weak2, weak3 }; | 1837 Dart_Handle values[] = { weak1, weak2, weak3 }; |
| 1825 EXPECT_VALID(Dart_NewWeakReferenceSet(keys, ARRAY_SIZE(keys), | 1838 EXPECT_VALID(Dart_NewWeakReferenceSet(keys, ARRAY_SIZE(keys), |
| 1826 values, ARRAY_SIZE(values))); | 1839 values, ARRAY_SIZE(values))); |
| 1827 | 1840 |
| 1828 Isolate::Current()->heap()->CollectGarbage(Heap::kNew, | 1841 GCTestHelper::CollectNewSpace(Heap::kInvokeApiCallbacks); |
| 1829 Heap::kInvokeApiCallbacks); | |
| 1830 } | 1842 } |
| 1831 | 1843 |
| 1832 // All weak references should be preserved. | 1844 // All weak references should be preserved. |
| 1833 EXPECT(!Dart_IsNull(weak1)); | 1845 EXPECT(!Dart_IsNull(weak1)); |
| 1834 EXPECT(!Dart_IsNull(weak2)); | 1846 EXPECT(!Dart_IsNull(weak2)); |
| 1835 EXPECT(!Dart_IsNull(weak3)); | 1847 EXPECT(!Dart_IsNull(weak3)); |
| 1836 | 1848 |
| 1837 Isolate::Current()->heap()->CollectGarbage(Heap::kNew, | 1849 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 1838 Heap::kIgnoreApiCallbacks); | |
| 1839 | 1850 |
| 1840 // No weak references should be preserved. | 1851 // No weak references should be preserved. |
| 1841 EXPECT(Dart_IsNull(weak1)); | 1852 EXPECT(Dart_IsNull(weak1)); |
| 1842 EXPECT(Dart_IsNull(weak2)); | 1853 EXPECT(Dart_IsNull(weak2)); |
| 1843 EXPECT(Dart_IsNull(weak3)); | 1854 EXPECT(Dart_IsNull(weak3)); |
| 1844 } | 1855 } |
| 1845 | 1856 |
| 1846 | 1857 |
| 1847 static int global_prologue_callback_status; | 1858 static int global_prologue_callback_status; |
| 1848 | 1859 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1949 | 1960 |
| 1950 | 1961 |
| 1951 TEST_CASE(SingleGarbageCollectionCallback) { | 1962 TEST_CASE(SingleGarbageCollectionCallback) { |
| 1952 // Add a prologue callback. | 1963 // Add a prologue callback. |
| 1953 EXPECT_VALID(Dart_AddGcPrologueCallback(&PrologueCallbackTimes2)); | 1964 EXPECT_VALID(Dart_AddGcPrologueCallback(&PrologueCallbackTimes2)); |
| 1954 | 1965 |
| 1955 // Garbage collect new space ignoring callbacks. This should not | 1966 // Garbage collect new space ignoring callbacks. This should not |
| 1956 // invoke the prologue callback. No status values should change. | 1967 // invoke the prologue callback. No status values should change. |
| 1957 global_prologue_callback_status = 3; | 1968 global_prologue_callback_status = 3; |
| 1958 global_epilogue_callback_status = 7; | 1969 global_epilogue_callback_status = 7; |
| 1959 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 1970 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 1960 EXPECT_EQ(3, global_prologue_callback_status); | 1971 EXPECT_EQ(3, global_prologue_callback_status); |
| 1961 EXPECT_EQ(7, global_epilogue_callback_status); | 1972 EXPECT_EQ(7, global_epilogue_callback_status); |
| 1962 | 1973 |
| 1963 // Garbage collect new space invoking callbacks. This should | 1974 // Garbage collect new space invoking callbacks. This should |
| 1964 // invoke the prologue callback. No status values should change. | 1975 // invoke the prologue callback. No status values should change. |
| 1965 global_prologue_callback_status = 3; | 1976 global_prologue_callback_status = 3; |
| 1966 global_epilogue_callback_status = 7; | 1977 global_epilogue_callback_status = 7; |
| 1967 Isolate::Current()->heap()->CollectGarbage(Heap::kNew, | 1978 GCTestHelper::CollectNewSpace(Heap::kInvokeApiCallbacks); |
| 1968 Heap::kInvokeApiCallbacks); | |
| 1969 EXPECT_EQ(6, global_prologue_callback_status); | 1979 EXPECT_EQ(6, global_prologue_callback_status); |
| 1970 EXPECT_EQ(7, global_epilogue_callback_status); | 1980 EXPECT_EQ(7, global_epilogue_callback_status); |
| 1971 | 1981 |
| 1972 // Garbage collect old space ignoring callbacks. This should invoke | 1982 // Garbage collect old space ignoring callbacks. This should invoke |
| 1973 // the prologue callback. The prologue status value should change. | 1983 // the prologue callback. The prologue status value should change. |
| 1974 global_prologue_callback_status = 3; | 1984 global_prologue_callback_status = 3; |
| 1975 global_epilogue_callback_status = 7; | 1985 global_epilogue_callback_status = 7; |
| 1976 Isolate::Current()->heap()->CollectGarbage(Heap::kOld, | 1986 Isolate::Current()->heap()->CollectGarbage(Heap::kOld, |
| 1977 Heap::kIgnoreApiCallbacks); | 1987 Heap::kIgnoreApiCallbacks); |
| 1978 EXPECT_EQ(3, global_prologue_callback_status); | 1988 EXPECT_EQ(3, global_prologue_callback_status); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1992 EXPECT_EQ(12, global_prologue_callback_status); | 2002 EXPECT_EQ(12, global_prologue_callback_status); |
| 1993 EXPECT_EQ(7, global_epilogue_callback_status); | 2003 EXPECT_EQ(7, global_epilogue_callback_status); |
| 1994 | 2004 |
| 1995 // Add an epilogue callback. | 2005 // Add an epilogue callback. |
| 1996 EXPECT_VALID(Dart_AddGcEpilogueCallback(&EpilogueCallbackTimes4)); | 2006 EXPECT_VALID(Dart_AddGcEpilogueCallback(&EpilogueCallbackTimes4)); |
| 1997 | 2007 |
| 1998 // Garbage collect new space. This should not invoke the prologue | 2008 // Garbage collect new space. This should not invoke the prologue |
| 1999 // or the epilogue callback. No status values should change. | 2009 // or the epilogue callback. No status values should change. |
| 2000 global_prologue_callback_status = 3; | 2010 global_prologue_callback_status = 3; |
| 2001 global_epilogue_callback_status = 7; | 2011 global_epilogue_callback_status = 7; |
| 2002 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 2012 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 2003 EXPECT_EQ(3, global_prologue_callback_status); | 2013 EXPECT_EQ(3, global_prologue_callback_status); |
| 2004 EXPECT_EQ(7, global_epilogue_callback_status); | 2014 EXPECT_EQ(7, global_epilogue_callback_status); |
| 2005 | 2015 |
| 2006 // Garbage collect new space. This should invoke the prologue and | 2016 // Garbage collect new space. This should invoke the prologue and |
| 2007 // the epilogue callback. The prologue and epilogue status values | 2017 // the epilogue callback. The prologue and epilogue status values |
| 2008 // should change. | 2018 // should change. |
| 2009 Isolate::Current()->heap()->CollectGarbage(Heap::kNew, | 2019 GCTestHelper::CollectNewSpace(Heap::kInvokeApiCallbacks); |
| 2010 Heap::kInvokeApiCallbacks); | |
| 2011 EXPECT_EQ(6, global_prologue_callback_status); | 2020 EXPECT_EQ(6, global_prologue_callback_status); |
| 2012 EXPECT_EQ(28, global_epilogue_callback_status); | 2021 EXPECT_EQ(28, global_epilogue_callback_status); |
| 2013 | 2022 |
| 2014 // Garbage collect old space. This should invoke the prologue and | 2023 // Garbage collect old space. This should invoke the prologue and |
| 2015 // the epilogue callbacks. The prologue and epilogue status values | 2024 // the epilogue callbacks. The prologue and epilogue status values |
| 2016 // should change. | 2025 // should change. |
| 2017 global_prologue_callback_status = 3; | 2026 global_prologue_callback_status = 3; |
| 2018 global_epilogue_callback_status = 7; | 2027 global_epilogue_callback_status = 7; |
| 2019 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2028 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2020 EXPECT_EQ(6, global_prologue_callback_status); | 2029 EXPECT_EQ(6, global_prologue_callback_status); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2051 EXPECT_VALID(Dart_AddGcPrologueCallback(&PrologueCallbackTimes2)); | 2060 EXPECT_VALID(Dart_AddGcPrologueCallback(&PrologueCallbackTimes2)); |
| 2052 EXPECT_VALID(Dart_AddGcPrologueCallback(&PrologueCallbackTimes3)); | 2061 EXPECT_VALID(Dart_AddGcPrologueCallback(&PrologueCallbackTimes3)); |
| 2053 | 2062 |
| 2054 // Add an epilogue callback. | 2063 // Add an epilogue callback. |
| 2055 EXPECT_VALID(Dart_AddGcEpilogueCallback(&EpilogueCallbackTimes4)); | 2064 EXPECT_VALID(Dart_AddGcEpilogueCallback(&EpilogueCallbackTimes4)); |
| 2056 | 2065 |
| 2057 // Garbage collect new space. This should not invoke the prologue | 2066 // Garbage collect new space. This should not invoke the prologue |
| 2058 // or epilogue callbacks. No status values should change. | 2067 // or epilogue callbacks. No status values should change. |
| 2059 global_prologue_callback_status = 3; | 2068 global_prologue_callback_status = 3; |
| 2060 global_epilogue_callback_status = 7; | 2069 global_epilogue_callback_status = 7; |
| 2061 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 2070 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 2062 EXPECT_EQ(3, global_prologue_callback_status); | 2071 EXPECT_EQ(3, global_prologue_callback_status); |
| 2063 EXPECT_EQ(7, global_epilogue_callback_status); | 2072 EXPECT_EQ(7, global_epilogue_callback_status); |
| 2064 | 2073 |
| 2065 // Garbage collect old space. This should invoke both prologue | 2074 // Garbage collect old space. This should invoke both prologue |
| 2066 // callbacks and the epilogue callback. The prologue and epilogue | 2075 // callbacks and the epilogue callback. The prologue and epilogue |
| 2067 // status values should change. | 2076 // status values should change. |
| 2068 global_prologue_callback_status = 3; | 2077 global_prologue_callback_status = 3; |
| 2069 global_epilogue_callback_status = 7; | 2078 global_epilogue_callback_status = 7; |
| 2070 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2079 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2071 EXPECT_EQ(18, global_prologue_callback_status); | 2080 EXPECT_EQ(18, global_prologue_callback_status); |
| (...skipping 4078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6150 EXPECT_VALID(result); | 6159 EXPECT_VALID(result); |
| 6151 EXPECT(Dart_IsInteger(result)); | 6160 EXPECT(Dart_IsInteger(result)); |
| 6152 int64_t value = 0; | 6161 int64_t value = 0; |
| 6153 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 6162 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 6154 EXPECT_EQ(0, value); | 6163 EXPECT_EQ(0, value); |
| 6155 } | 6164 } |
| 6156 | 6165 |
| 6157 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 6166 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 6158 | 6167 |
| 6159 } // namespace dart | 6168 } // namespace dart |
| OLD | NEW |