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 "bin/builtin.h" | 5 #include "bin/builtin.h" |
| 6 #include "vm/compiler.h" | 6 #include "vm/compiler.h" |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "include/dart_mirrors_api.h" | 8 #include "include/dart_mirrors_api.h" |
| 9 #include "include/dart_native_api.h" | 9 #include "include/dart_native_api.h" |
| 10 #include "include/dart_tools_api.h" | 10 #include "include/dart_tools_api.h" |
| (...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1200 &utf8_encoded_reversed, &utf8_length_reversed); | 1200 &utf8_encoded_reversed, &utf8_length_reversed); |
| 1201 EXPECT_VALID(result); | 1201 EXPECT_VALID(result); |
| 1202 EXPECT_EQ(6, utf8_length_reversed); | 1202 EXPECT_EQ(6, utf8_length_reversed); |
| 1203 uint8_t expected[6] = {237, 180, 158, 237, 160, 180}; | 1203 uint8_t expected[6] = {237, 180, 158, 237, 160, 180}; |
| 1204 for (int i = 0; i < 6; i++) { | 1204 for (int i = 0; i < 6; i++) { |
| 1205 EXPECT_EQ(expected[i], utf8_encoded_reversed[i]); | 1205 EXPECT_EQ(expected[i], utf8_encoded_reversed[i]); |
| 1206 } | 1206 } |
| 1207 } | 1207 } |
| 1208 | 1208 |
| 1209 | 1209 |
| 1210 // Helper class to ensure new gen GC is triggered without any side effects. | |
| 1211 // The normal call to CollectGarbage(Heap::kNew) could potentially trigger | |
| 1212 // an old gen collection if there is a promotion failure and this could | |
| 1213 // perturb the test. | |
| 1214 class GCTestHelper : public AllStatic { | |
| 1215 public: | |
| 1216 static void CollectNewSpace(Heap::ApiCallbacks api_callbacks) { | |
| 1217 bool invoke_api_callbacks = (api_callbacks == Heap::kInvokeApiCallbacks); | |
| 1218 Isolate::Current()->heap()->new_space()->Scavenge(invoke_api_callbacks); | |
| 1219 } | |
| 1220 | |
| 1221 static void WaitForFinalizationTasks() { | |
| 1222 Thread* thread = Thread::Current(); | |
| 1223 Heap* heap = thread->isolate()->heap(); | |
| 1224 MonitorLocker ml(heap->finalization_tasks_lock()); | |
| 1225 while (heap->finalization_tasks() > 0) { | |
| 1226 ml.WaitWithSafepointCheck(thread); | |
| 1227 } | |
| 1228 } | |
| 1229 }; | |
| 1230 | |
| 1231 | |
| 1210 static void ExternalStringCallbackFinalizer(void* peer) { | 1232 static void ExternalStringCallbackFinalizer(void* peer) { |
| 1211 *static_cast<int*>(peer) *= 2; | 1233 *static_cast<int*>(peer) *= 2; |
| 1212 } | 1234 } |
| 1213 | 1235 |
| 1214 | 1236 |
| 1215 TEST_CASE(ExternalStringCallback) { | 1237 TEST_CASE(ExternalStringCallback) { |
| 1216 int peer8 = 40; | 1238 int peer8 = 40; |
| 1217 int peer16 = 41; | 1239 int peer16 = 41; |
| 1218 | 1240 |
| 1219 { | 1241 { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1236 EXPECT_VALID(obj16); | 1258 EXPECT_VALID(obj16); |
| 1237 | 1259 |
| 1238 Dart_ExitScope(); | 1260 Dart_ExitScope(); |
| 1239 } | 1261 } |
| 1240 | 1262 |
| 1241 { | 1263 { |
| 1242 TransitionNativeToVM transition(thread); | 1264 TransitionNativeToVM transition(thread); |
| 1243 EXPECT_EQ(40, peer8); | 1265 EXPECT_EQ(40, peer8); |
| 1244 EXPECT_EQ(41, peer16); | 1266 EXPECT_EQ(41, peer16); |
| 1245 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 1267 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 1268 GCTestHelper::WaitForFinalizationTasks(); | |
| 1246 EXPECT_EQ(40, peer8); | 1269 EXPECT_EQ(40, peer8); |
| 1247 EXPECT_EQ(41, peer16); | 1270 EXPECT_EQ(41, peer16); |
| 1248 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 1271 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); |
| 1272 GCTestHelper::WaitForFinalizationTasks(); | |
| 1249 EXPECT_EQ(80, peer8); | 1273 EXPECT_EQ(80, peer8); |
| 1250 EXPECT_EQ(82, peer16); | 1274 EXPECT_EQ(82, peer16); |
| 1251 } | 1275 } |
| 1252 } | 1276 } |
| 1253 | 1277 |
| 1254 | 1278 |
| 1255 TEST_CASE(ExternalStringPretenure) { | 1279 TEST_CASE(ExternalStringPretenure) { |
| 1256 { | 1280 { |
| 1257 Dart_EnterScope(); | 1281 Dart_EnterScope(); |
| 1258 static const uint8_t big_data8[16*MB] = {0, }; | 1282 static const uint8_t big_data8[16*MB] = {0, }; |
| (...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2375 ARRAY_SIZE(data)); | 2399 ARRAY_SIZE(data)); |
| 2376 Dart_NewWeakPersistentHandle( | 2400 Dart_NewWeakPersistentHandle( |
| 2377 obj, &peer, sizeof(data), ExternalTypedDataFinalizer); | 2401 obj, &peer, sizeof(data), ExternalTypedDataFinalizer); |
| 2378 EXPECT_VALID(obj); | 2402 EXPECT_VALID(obj); |
| 2379 Dart_ExitScope(); | 2403 Dart_ExitScope(); |
| 2380 } | 2404 } |
| 2381 { | 2405 { |
| 2382 TransitionNativeToVM transition(thread); | 2406 TransitionNativeToVM transition(thread); |
| 2383 EXPECT(peer == 0); | 2407 EXPECT(peer == 0); |
| 2384 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2408 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2409 GCTestHelper::WaitForFinalizationTasks(); | |
| 2385 EXPECT(peer == 0); | 2410 EXPECT(peer == 0); |
| 2386 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 2411 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); |
| 2412 GCTestHelper::WaitForFinalizationTasks(); | |
| 2387 EXPECT(peer == 42); | 2413 EXPECT(peer == 42); |
| 2388 } | 2414 } |
| 2389 } | 2415 } |
| 2390 | 2416 |
| 2391 | 2417 |
| 2418 static void SlowFinalizer(void* isolate_callback_data, | |
| 2419 Dart_WeakPersistentHandle handle, | |
| 2420 void* peer) { | |
| 2421 OS::Sleep(50); | |
|
siva
2016/06/22 04:43:29
I hope this sleep on every call won't cause timeou
rmacnak
2016/06/22 17:50:45
I like the monitor approach better. To make it wor
| |
| 2422 ++*reinterpret_cast<intptr_t*>(peer); | |
| 2423 } | |
| 2424 | |
| 2425 | |
| 2426 TEST_CASE(SlowFinalizer) { | |
| 2427 intptr_t peer = 0; | |
| 2428 for (intptr_t i = 0; i < 100; i++) { | |
| 2429 Dart_EnterScope(); | |
| 2430 Dart_Handle str1 = Dart_NewStringFromCString("Live fast"); | |
| 2431 Dart_NewWeakPersistentHandle(str1, &peer, 0, SlowFinalizer); | |
| 2432 Dart_Handle str2 = Dart_NewStringFromCString("Die young"); | |
| 2433 Dart_NewWeakPersistentHandle(str2, &peer, 0, SlowFinalizer); | |
| 2434 Dart_ExitScope(); | |
| 2435 | |
| 2436 { | |
| 2437 TransitionNativeToVM transition(thread); | |
| 2438 Isolate::Current()->heap()->CollectAllGarbage(); | |
| 2439 } | |
| 2440 } | |
| 2441 | |
| 2442 { | |
| 2443 TransitionNativeToVM transition(thread); | |
| 2444 GCTestHelper::WaitForFinalizationTasks(); | |
| 2445 } | |
| 2446 ASSERT(peer == 200); | |
| 2447 } | |
| 2448 | |
| 2449 | |
| 2392 static void CheckFloat32x4Data(Dart_Handle obj) { | 2450 static void CheckFloat32x4Data(Dart_Handle obj) { |
| 2393 void* raw_data = NULL; | 2451 void* raw_data = NULL; |
| 2394 intptr_t len; | 2452 intptr_t len; |
| 2395 Dart_TypedData_Type type; | 2453 Dart_TypedData_Type type; |
| 2396 EXPECT_VALID(Dart_TypedDataAcquireData(obj, &type, &raw_data, &len)); | 2454 EXPECT_VALID(Dart_TypedDataAcquireData(obj, &type, &raw_data, &len)); |
| 2397 EXPECT_EQ(Dart_TypedData_kFloat32x4, type); | 2455 EXPECT_EQ(Dart_TypedData_kFloat32x4, type); |
| 2398 EXPECT_EQ(len, 10); | 2456 EXPECT_EQ(len, 10); |
| 2399 float* float_data = reinterpret_cast<float*>(raw_data); | 2457 float* float_data = reinterpret_cast<float*>(raw_data); |
| 2400 for (int i = 0; i < len * 4; i++) { | 2458 for (int i = 0; i < len * 4; i++) { |
| 2401 EXPECT_EQ(0.0, float_data[i]); | 2459 EXPECT_EQ(0.0, float_data[i]); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2433 Dart_Handle lcl = Dart_NewExternalTypedData( | 2491 Dart_Handle lcl = Dart_NewExternalTypedData( |
| 2434 Dart_TypedData_kFloat32x4, data, 10); | 2492 Dart_TypedData_kFloat32x4, data, 10); |
| 2435 Dart_NewWeakPersistentHandle( | 2493 Dart_NewWeakPersistentHandle( |
| 2436 lcl, &peer, sizeof(data), ExternalTypedDataFinalizer); | 2494 lcl, &peer, sizeof(data), ExternalTypedDataFinalizer); |
| 2437 CheckFloat32x4Data(lcl); | 2495 CheckFloat32x4Data(lcl); |
| 2438 } | 2496 } |
| 2439 Dart_ExitScope(); | 2497 Dart_ExitScope(); |
| 2440 { | 2498 { |
| 2441 TransitionNativeToVM transition(thread); | 2499 TransitionNativeToVM transition(thread); |
| 2442 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 2500 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); |
| 2501 GCTestHelper::WaitForFinalizationTasks(); | |
| 2443 EXPECT(peer == 42); | 2502 EXPECT(peer == 42); |
| 2444 } | 2503 } |
| 2445 } | 2504 } |
| 2446 | 2505 |
| 2447 | 2506 |
| 2448 // Unit test for entering a scope, creating a local handle and exiting | 2507 // Unit test for entering a scope, creating a local handle and exiting |
| 2449 // the scope. | 2508 // the scope. |
| 2450 UNIT_TEST_CASE(EnterExitScope) { | 2509 UNIT_TEST_CASE(EnterExitScope) { |
| 2451 TestIsolateScope __test_isolate__; | 2510 TestIsolateScope __test_isolate__; |
| 2452 | 2511 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2595 Dart_SetPersistentHandle(obj, ref2); | 2654 Dart_SetPersistentHandle(obj, ref2); |
| 2596 str ^= PersistentHandle::Cast(obj)->raw(); | 2655 str ^= PersistentHandle::Cast(obj)->raw(); |
| 2597 EXPECT(str.Equals(kTestString2)); | 2656 EXPECT(str.Equals(kTestString2)); |
| 2598 | 2657 |
| 2599 // Now assign Null to the persistent handle and check. | 2658 // Now assign Null to the persistent handle and check. |
| 2600 Dart_SetPersistentHandle(obj, Dart_Null()); | 2659 Dart_SetPersistentHandle(obj, Dart_Null()); |
| 2601 EXPECT(Dart_IsNull(obj)); | 2660 EXPECT(Dart_IsNull(obj)); |
| 2602 } | 2661 } |
| 2603 | 2662 |
| 2604 | 2663 |
| 2605 // Helper class to ensure new gen GC is triggered without any side effects. | |
| 2606 // The normal call to CollectGarbage(Heap::kNew) could potentially trigger | |
| 2607 // an old gen collection if there is a promotion failure and this could | |
| 2608 // perturb the test. | |
| 2609 class GCTestHelper : public AllStatic { | |
| 2610 public: | |
| 2611 static void CollectNewSpace(Heap::ApiCallbacks api_callbacks) { | |
| 2612 bool invoke_api_callbacks = (api_callbacks == Heap::kInvokeApiCallbacks); | |
| 2613 Isolate::Current()->heap()->new_space()->Scavenge(invoke_api_callbacks); | |
| 2614 } | |
| 2615 }; | |
| 2616 | |
| 2617 | |
| 2618 static Dart_Handle AsHandle(Dart_PersistentHandle weak) { | 2664 static Dart_Handle AsHandle(Dart_PersistentHandle weak) { |
| 2619 return Dart_HandleFromPersistent(weak); | 2665 return Dart_HandleFromPersistent(weak); |
| 2620 } | 2666 } |
| 2621 | 2667 |
| 2622 | 2668 |
| 2623 static Dart_Handle AsHandle(Dart_WeakPersistentHandle weak) { | 2669 static Dart_Handle AsHandle(Dart_WeakPersistentHandle weak) { |
| 2624 return Dart_HandleFromWeakPersistent(weak); | 2670 return Dart_HandleFromWeakPersistent(weak); |
| 2625 } | 2671 } |
| 2626 | 2672 |
| 2627 | 2673 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2722 EXPECT(Dart_IdentityEquals(old_ref, AsHandle(weak_old_ref))); | 2768 EXPECT(Dart_IdentityEquals(old_ref, AsHandle(weak_old_ref))); |
| 2723 | 2769 |
| 2724 // Delete local (strong) references. | 2770 // Delete local (strong) references. |
| 2725 Dart_ExitScope(); | 2771 Dart_ExitScope(); |
| 2726 } | 2772 } |
| 2727 | 2773 |
| 2728 { | 2774 { |
| 2729 TransitionNativeToVM transition(thread); | 2775 TransitionNativeToVM transition(thread); |
| 2730 // Garbage collect new space again. | 2776 // Garbage collect new space again. |
| 2731 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2777 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 2778 GCTestHelper::WaitForFinalizationTasks(); | |
| 2732 } | 2779 } |
| 2733 | 2780 |
| 2734 { | 2781 { |
| 2735 Dart_EnterScope(); | 2782 Dart_EnterScope(); |
| 2736 // Weak ref to new space object should now be cleared. | 2783 // Weak ref to new space object should now be cleared. |
| 2737 EXPECT(weak_new_ref == NULL); | 2784 EXPECT(weak_new_ref == NULL); |
| 2738 EXPECT_VALID(AsHandle(weak_old_ref)); | 2785 EXPECT_VALID(AsHandle(weak_old_ref)); |
| 2739 EXPECT(!Dart_IsNull(AsHandle(weak_old_ref))); | 2786 EXPECT(!Dart_IsNull(AsHandle(weak_old_ref))); |
| 2740 Dart_ExitScope(); | 2787 Dart_ExitScope(); |
| 2741 } | 2788 } |
| 2742 | 2789 |
| 2743 { | 2790 { |
| 2744 TransitionNativeToVM transition(thread); | 2791 TransitionNativeToVM transition(thread); |
| 2745 // Garbage collect old space again. | 2792 // Garbage collect old space again. |
| 2746 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2793 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2794 GCTestHelper::WaitForFinalizationTasks(); | |
| 2747 } | 2795 } |
| 2748 | 2796 |
| 2749 { | 2797 { |
| 2750 Dart_EnterScope(); | 2798 Dart_EnterScope(); |
| 2751 // Weak ref to old space object should now be cleared. | 2799 // Weak ref to old space object should now be cleared. |
| 2752 EXPECT(weak_new_ref == NULL); | 2800 EXPECT(weak_new_ref == NULL); |
| 2753 EXPECT(weak_old_ref == NULL); | 2801 EXPECT(weak_old_ref == NULL); |
| 2754 Dart_ExitScope(); | 2802 Dart_ExitScope(); |
| 2755 } | 2803 } |
| 2756 | 2804 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 2781 WeakPersistentHandlePeerFinalizer); | 2829 WeakPersistentHandlePeerFinalizer); |
| 2782 EXPECT_VALID(AsHandle(weak_ref)); | 2830 EXPECT_VALID(AsHandle(weak_ref)); |
| 2783 EXPECT(peer == 0); | 2831 EXPECT(peer == 0); |
| 2784 Dart_ExitScope(); | 2832 Dart_ExitScope(); |
| 2785 } | 2833 } |
| 2786 { | 2834 { |
| 2787 TransitionNativeToVM transition(thread); | 2835 TransitionNativeToVM transition(thread); |
| 2788 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2836 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2789 EXPECT(peer == 0); | 2837 EXPECT(peer == 0); |
| 2790 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2838 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 2839 GCTestHelper::WaitForFinalizationTasks(); | |
| 2791 EXPECT(peer == 42); | 2840 EXPECT(peer == 42); |
| 2792 } | 2841 } |
| 2793 } | 2842 } |
| 2794 | 2843 |
| 2795 | 2844 |
| 2796 TEST_CASE(WeakPersistentHandleNoCallback) { | 2845 TEST_CASE(WeakPersistentHandleNoCallback) { |
| 2797 Dart_WeakPersistentHandle weak_ref = NULL; | 2846 Dart_WeakPersistentHandle weak_ref = NULL; |
| 2798 int peer = 0; | 2847 int peer = 0; |
| 2799 { | 2848 { |
| 2800 Dart_EnterScope(); | 2849 Dart_EnterScope(); |
| 2801 Dart_Handle obj = NewString("new string"); | 2850 Dart_Handle obj = NewString("new string"); |
| 2802 EXPECT_VALID(obj); | 2851 EXPECT_VALID(obj); |
| 2803 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, 0, | 2852 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, 0, |
| 2804 WeakPersistentHandlePeerFinalizer); | 2853 WeakPersistentHandlePeerFinalizer); |
| 2805 Dart_ExitScope(); | 2854 Dart_ExitScope(); |
| 2806 } | 2855 } |
| 2807 // A finalizer is not invoked on a deleted handle. Therefore, the | 2856 // A finalizer is not invoked on a deleted handle. Therefore, the |
| 2808 // peer value should not change after the referent is collected. | 2857 // peer value should not change after the referent is collected. |
| 2809 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); | 2858 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); |
| 2810 Dart_DeleteWeakPersistentHandle(isolate, weak_ref); | 2859 Dart_DeleteWeakPersistentHandle(isolate, weak_ref); |
| 2811 EXPECT(peer == 0); | 2860 EXPECT(peer == 0); |
| 2812 { | 2861 { |
| 2813 TransitionNativeToVM transition(thread); | 2862 TransitionNativeToVM transition(thread); |
| 2814 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2863 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2815 EXPECT(peer == 0); | 2864 EXPECT(peer == 0); |
| 2816 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2865 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 2866 GCTestHelper::WaitForFinalizationTasks(); | |
| 2817 EXPECT(peer == 0); | 2867 EXPECT(peer == 0); |
| 2818 } | 2868 } |
| 2819 } | 2869 } |
| 2820 | 2870 |
| 2821 | 2871 |
| 2822 UNIT_TEST_CASE(WeakPersistentHandlesCallbackShutdown) { | 2872 UNIT_TEST_CASE(WeakPersistentHandlesCallbackShutdown) { |
| 2823 TestCase::CreateTestIsolate(); | 2873 TestCase::CreateTestIsolate(); |
| 2824 Dart_EnterScope(); | 2874 Dart_EnterScope(); |
| 2825 Dart_Handle ref = Dart_True(); | 2875 Dart_Handle ref = Dart_True(); |
| 2826 int peer = 1234; | 2876 int peer = 1234; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2867 Dart_ExitScope(); | 2917 Dart_ExitScope(); |
| 2868 } | 2918 } |
| 2869 { | 2919 { |
| 2870 TransitionNativeToVM transition(thread); | 2920 TransitionNativeToVM transition(thread); |
| 2871 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2921 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2872 EXPECT(heap->ExternalInWords(Heap::kNew) == | 2922 EXPECT(heap->ExternalInWords(Heap::kNew) == |
| 2873 (kWeak1ExternalSize + kWeak2ExternalSize) / kWordSize); | 2923 (kWeak1ExternalSize + kWeak2ExternalSize) / kWordSize); |
| 2874 // Collect weakly referenced string, and promote strongly referenced string. | 2924 // Collect weakly referenced string, and promote strongly referenced string. |
| 2875 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2925 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 2876 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2926 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 2927 GCTestHelper::WaitForFinalizationTasks(); | |
| 2877 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); | 2928 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); |
| 2878 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak2ExternalSize / kWordSize); | 2929 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak2ExternalSize / kWordSize); |
| 2879 } | 2930 } |
| 2880 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); | 2931 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); |
| 2881 Dart_DeleteWeakPersistentHandle(isolate, weak1); | 2932 Dart_DeleteWeakPersistentHandle(isolate, weak1); |
| 2882 Dart_DeleteWeakPersistentHandle(isolate, weak2); | 2933 Dart_DeleteWeakPersistentHandle(isolate, weak2); |
| 2883 Dart_DeletePersistentHandle(strong_ref); | 2934 Dart_DeletePersistentHandle(strong_ref); |
| 2884 { | 2935 { |
| 2885 TransitionNativeToVM transition(thread); | 2936 TransitionNativeToVM transition(thread); |
| 2886 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2937 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2938 GCTestHelper::WaitForFinalizationTasks(); | |
| 2887 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); | 2939 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); |
| 2888 } | 2940 } |
| 2889 } | 2941 } |
| 2890 | 2942 |
| 2891 | 2943 |
| 2892 TEST_CASE(WeakPersistentHandleExternalAllocationSizeNewspaceGC) { | 2944 TEST_CASE(WeakPersistentHandleExternalAllocationSizeNewspaceGC) { |
| 2893 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); | 2945 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); |
| 2894 Heap* heap = Isolate::Current()->heap(); | 2946 Heap* heap = Isolate::Current()->heap(); |
| 2895 Dart_WeakPersistentHandle weak1 = NULL; | 2947 Dart_WeakPersistentHandle weak1 = NULL; |
| 2896 // Large enough to exceed any new space limit. Not actually allocated. | 2948 // Large enough to exceed any new space limit. Not actually allocated. |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 2922 EXPECT(handle.IsOld()); | 2974 EXPECT(handle.IsOld()); |
| 2923 } | 2975 } |
| 2924 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); | 2976 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); |
| 2925 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak1ExternalSize / kWordSize); | 2977 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak1ExternalSize / kWordSize); |
| 2926 Dart_ExitScope(); | 2978 Dart_ExitScope(); |
| 2927 } | 2979 } |
| 2928 Dart_DeleteWeakPersistentHandle(isolate, weak1); | 2980 Dart_DeleteWeakPersistentHandle(isolate, weak1); |
| 2929 { | 2981 { |
| 2930 TransitionNativeToVM transition(thread); | 2982 TransitionNativeToVM transition(thread); |
| 2931 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2983 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2984 GCTestHelper::WaitForFinalizationTasks(); | |
| 2932 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); | 2985 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); |
| 2933 } | 2986 } |
| 2934 } | 2987 } |
| 2935 | 2988 |
| 2936 | 2989 |
| 2937 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOldspaceGC) { | 2990 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOldspaceGC) { |
| 2938 // Check that external allocation in old space can trigger GC. | 2991 // Check that external allocation in old space can trigger GC. |
| 2939 Isolate* isolate = Isolate::Current(); | 2992 Isolate* isolate = Isolate::Current(); |
| 2940 Dart_EnterScope(); | 2993 Dart_EnterScope(); |
| 2941 Dart_Handle live = Api::NewHandle(thread, String::New("live", Heap::kOld)); | 2994 Dart_Handle live = Api::NewHandle(thread, String::New("live", Heap::kOld)); |
| (...skipping 5758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8700 } | 8753 } |
| 8701 | 8754 |
| 8702 Dart_ExitScope(); | 8755 Dart_ExitScope(); |
| 8703 } | 8756 } |
| 8704 EXPECT_EQ(40, peer8); | 8757 EXPECT_EQ(40, peer8); |
| 8705 EXPECT_EQ(41, peer16); | 8758 EXPECT_EQ(41, peer16); |
| 8706 EXPECT_EQ(42, canonical_str_peer); | 8759 EXPECT_EQ(42, canonical_str_peer); |
| 8707 { | 8760 { |
| 8708 TransitionNativeToVM transition(thread); | 8761 TransitionNativeToVM transition(thread); |
| 8709 Isolate::Current()->heap()->CollectAllGarbage(); | 8762 Isolate::Current()->heap()->CollectAllGarbage(); |
| 8763 GCTestHelper::WaitForFinalizationTasks(); | |
| 8710 } | 8764 } |
| 8711 EXPECT_EQ(80, peer8); | 8765 EXPECT_EQ(80, peer8); |
| 8712 EXPECT_EQ(82, peer16); | 8766 EXPECT_EQ(82, peer16); |
| 8713 EXPECT_EQ(42, canonical_str_peer); // "*" Symbol is not removed on GC. | 8767 EXPECT_EQ(42, canonical_str_peer); // "*" Symbol is not removed on GC. |
| 8714 | 8768 |
| 8715 FLAG_support_externalizable_strings = saved_flag; | 8769 FLAG_support_externalizable_strings = saved_flag; |
| 8716 } | 8770 } |
| 8717 | 8771 |
| 8718 | 8772 |
| 8719 TEST_CASE(ExternalizeConstantStrings) { | 8773 TEST_CASE(ExternalizeConstantStrings) { |
| (...skipping 1362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10082 result = Dart_Invoke(lib, | 10136 result = Dart_Invoke(lib, |
| 10083 NewString("foozoo"), | 10137 NewString("foozoo"), |
| 10084 0, | 10138 0, |
| 10085 NULL); | 10139 NULL); |
| 10086 EXPECT(Dart_IsError(result)); | 10140 EXPECT(Dart_IsError(result)); |
| 10087 } | 10141 } |
| 10088 | 10142 |
| 10089 #endif // !PRODUCT | 10143 #endif // !PRODUCT |
| 10090 | 10144 |
| 10091 } // namespace dart | 10145 } // namespace dart |
| OLD | NEW |