| 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 Monitor* slow_finalizers_monitor = NULL; |
| 2419 static intptr_t slow_finalizers_waiting = 0; |
| 2420 |
| 2421 |
| 2422 static void SlowFinalizer(void* isolate_callback_data, |
| 2423 Dart_WeakPersistentHandle handle, |
| 2424 void* peer) { |
| 2425 { |
| 2426 MonitorLocker ml(slow_finalizers_monitor); |
| 2427 slow_finalizers_waiting++; |
| 2428 while (slow_finalizers_waiting < 10) { |
| 2429 ml.Wait(); |
| 2430 } |
| 2431 ml.NotifyAll(); |
| 2432 } |
| 2433 |
| 2434 intptr_t* count = reinterpret_cast<intptr_t*>(peer); |
| 2435 AtomicOperations::IncrementBy(count, 1); |
| 2436 } |
| 2437 |
| 2438 |
| 2439 TEST_CASE(SlowFinalizer) { |
| 2440 slow_finalizers_monitor = new Monitor(); |
| 2441 |
| 2442 intptr_t count = 0; |
| 2443 for (intptr_t i = 0; i < 10; i++) { |
| 2444 Dart_EnterScope(); |
| 2445 Dart_Handle str1 = Dart_NewStringFromCString("Live fast"); |
| 2446 Dart_NewWeakPersistentHandle(str1, &count, 0, SlowFinalizer); |
| 2447 Dart_Handle str2 = Dart_NewStringFromCString("Die young"); |
| 2448 Dart_NewWeakPersistentHandle(str2, &count, 0, SlowFinalizer); |
| 2449 Dart_ExitScope(); |
| 2450 |
| 2451 { |
| 2452 TransitionNativeToVM transition(thread); |
| 2453 Isolate::Current()->heap()->CollectAllGarbage(); |
| 2454 } |
| 2455 } |
| 2456 |
| 2457 { |
| 2458 TransitionNativeToVM transition(thread); |
| 2459 GCTestHelper::WaitForFinalizationTasks(); |
| 2460 } |
| 2461 |
| 2462 EXPECT_EQ(20, count); |
| 2463 |
| 2464 delete slow_finalizers_monitor; |
| 2465 } |
| 2466 |
| 2467 |
| 2392 static void CheckFloat32x4Data(Dart_Handle obj) { | 2468 static void CheckFloat32x4Data(Dart_Handle obj) { |
| 2393 void* raw_data = NULL; | 2469 void* raw_data = NULL; |
| 2394 intptr_t len; | 2470 intptr_t len; |
| 2395 Dart_TypedData_Type type; | 2471 Dart_TypedData_Type type; |
| 2396 EXPECT_VALID(Dart_TypedDataAcquireData(obj, &type, &raw_data, &len)); | 2472 EXPECT_VALID(Dart_TypedDataAcquireData(obj, &type, &raw_data, &len)); |
| 2397 EXPECT_EQ(Dart_TypedData_kFloat32x4, type); | 2473 EXPECT_EQ(Dart_TypedData_kFloat32x4, type); |
| 2398 EXPECT_EQ(len, 10); | 2474 EXPECT_EQ(len, 10); |
| 2399 float* float_data = reinterpret_cast<float*>(raw_data); | 2475 float* float_data = reinterpret_cast<float*>(raw_data); |
| 2400 for (int i = 0; i < len * 4; i++) { | 2476 for (int i = 0; i < len * 4; i++) { |
| 2401 EXPECT_EQ(0.0, float_data[i]); | 2477 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( | 2509 Dart_Handle lcl = Dart_NewExternalTypedData( |
| 2434 Dart_TypedData_kFloat32x4, data, 10); | 2510 Dart_TypedData_kFloat32x4, data, 10); |
| 2435 Dart_NewWeakPersistentHandle( | 2511 Dart_NewWeakPersistentHandle( |
| 2436 lcl, &peer, sizeof(data), ExternalTypedDataFinalizer); | 2512 lcl, &peer, sizeof(data), ExternalTypedDataFinalizer); |
| 2437 CheckFloat32x4Data(lcl); | 2513 CheckFloat32x4Data(lcl); |
| 2438 } | 2514 } |
| 2439 Dart_ExitScope(); | 2515 Dart_ExitScope(); |
| 2440 { | 2516 { |
| 2441 TransitionNativeToVM transition(thread); | 2517 TransitionNativeToVM transition(thread); |
| 2442 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 2518 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); |
| 2519 GCTestHelper::WaitForFinalizationTasks(); |
| 2443 EXPECT(peer == 42); | 2520 EXPECT(peer == 42); |
| 2444 } | 2521 } |
| 2445 } | 2522 } |
| 2446 | 2523 |
| 2447 | 2524 |
| 2448 // Unit test for entering a scope, creating a local handle and exiting | 2525 // Unit test for entering a scope, creating a local handle and exiting |
| 2449 // the scope. | 2526 // the scope. |
| 2450 UNIT_TEST_CASE(EnterExitScope) { | 2527 UNIT_TEST_CASE(EnterExitScope) { |
| 2451 TestIsolateScope __test_isolate__; | 2528 TestIsolateScope __test_isolate__; |
| 2452 | 2529 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2595 Dart_SetPersistentHandle(obj, ref2); | 2672 Dart_SetPersistentHandle(obj, ref2); |
| 2596 str ^= PersistentHandle::Cast(obj)->raw(); | 2673 str ^= PersistentHandle::Cast(obj)->raw(); |
| 2597 EXPECT(str.Equals(kTestString2)); | 2674 EXPECT(str.Equals(kTestString2)); |
| 2598 | 2675 |
| 2599 // Now assign Null to the persistent handle and check. | 2676 // Now assign Null to the persistent handle and check. |
| 2600 Dart_SetPersistentHandle(obj, Dart_Null()); | 2677 Dart_SetPersistentHandle(obj, Dart_Null()); |
| 2601 EXPECT(Dart_IsNull(obj)); | 2678 EXPECT(Dart_IsNull(obj)); |
| 2602 } | 2679 } |
| 2603 | 2680 |
| 2604 | 2681 |
| 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) { | 2682 static Dart_Handle AsHandle(Dart_PersistentHandle weak) { |
| 2619 return Dart_HandleFromPersistent(weak); | 2683 return Dart_HandleFromPersistent(weak); |
| 2620 } | 2684 } |
| 2621 | 2685 |
| 2622 | 2686 |
| 2623 static Dart_Handle AsHandle(Dart_WeakPersistentHandle weak) { | 2687 static Dart_Handle AsHandle(Dart_WeakPersistentHandle weak) { |
| 2624 return Dart_HandleFromWeakPersistent(weak); | 2688 return Dart_HandleFromWeakPersistent(weak); |
| 2625 } | 2689 } |
| 2626 | 2690 |
| 2627 | 2691 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2722 EXPECT(Dart_IdentityEquals(old_ref, AsHandle(weak_old_ref))); | 2786 EXPECT(Dart_IdentityEquals(old_ref, AsHandle(weak_old_ref))); |
| 2723 | 2787 |
| 2724 // Delete local (strong) references. | 2788 // Delete local (strong) references. |
| 2725 Dart_ExitScope(); | 2789 Dart_ExitScope(); |
| 2726 } | 2790 } |
| 2727 | 2791 |
| 2728 { | 2792 { |
| 2729 TransitionNativeToVM transition(thread); | 2793 TransitionNativeToVM transition(thread); |
| 2730 // Garbage collect new space again. | 2794 // Garbage collect new space again. |
| 2731 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2795 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 2796 GCTestHelper::WaitForFinalizationTasks(); |
| 2732 } | 2797 } |
| 2733 | 2798 |
| 2734 { | 2799 { |
| 2735 Dart_EnterScope(); | 2800 Dart_EnterScope(); |
| 2736 // Weak ref to new space object should now be cleared. | 2801 // Weak ref to new space object should now be cleared. |
| 2737 EXPECT(weak_new_ref == NULL); | 2802 EXPECT(weak_new_ref == NULL); |
| 2738 EXPECT_VALID(AsHandle(weak_old_ref)); | 2803 EXPECT_VALID(AsHandle(weak_old_ref)); |
| 2739 EXPECT(!Dart_IsNull(AsHandle(weak_old_ref))); | 2804 EXPECT(!Dart_IsNull(AsHandle(weak_old_ref))); |
| 2740 Dart_ExitScope(); | 2805 Dart_ExitScope(); |
| 2741 } | 2806 } |
| 2742 | 2807 |
| 2743 { | 2808 { |
| 2744 TransitionNativeToVM transition(thread); | 2809 TransitionNativeToVM transition(thread); |
| 2745 // Garbage collect old space again. | 2810 // Garbage collect old space again. |
| 2746 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2811 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2812 GCTestHelper::WaitForFinalizationTasks(); |
| 2747 } | 2813 } |
| 2748 | 2814 |
| 2749 { | 2815 { |
| 2750 Dart_EnterScope(); | 2816 Dart_EnterScope(); |
| 2751 // Weak ref to old space object should now be cleared. | 2817 // Weak ref to old space object should now be cleared. |
| 2752 EXPECT(weak_new_ref == NULL); | 2818 EXPECT(weak_new_ref == NULL); |
| 2753 EXPECT(weak_old_ref == NULL); | 2819 EXPECT(weak_old_ref == NULL); |
| 2754 Dart_ExitScope(); | 2820 Dart_ExitScope(); |
| 2755 } | 2821 } |
| 2756 | 2822 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2781 WeakPersistentHandlePeerFinalizer); | 2847 WeakPersistentHandlePeerFinalizer); |
| 2782 EXPECT_VALID(AsHandle(weak_ref)); | 2848 EXPECT_VALID(AsHandle(weak_ref)); |
| 2783 EXPECT(peer == 0); | 2849 EXPECT(peer == 0); |
| 2784 Dart_ExitScope(); | 2850 Dart_ExitScope(); |
| 2785 } | 2851 } |
| 2786 { | 2852 { |
| 2787 TransitionNativeToVM transition(thread); | 2853 TransitionNativeToVM transition(thread); |
| 2788 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2854 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2789 EXPECT(peer == 0); | 2855 EXPECT(peer == 0); |
| 2790 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2856 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 2857 GCTestHelper::WaitForFinalizationTasks(); |
| 2791 EXPECT(peer == 42); | 2858 EXPECT(peer == 42); |
| 2792 } | 2859 } |
| 2793 } | 2860 } |
| 2794 | 2861 |
| 2795 | 2862 |
| 2796 TEST_CASE(WeakPersistentHandleNoCallback) { | 2863 TEST_CASE(WeakPersistentHandleNoCallback) { |
| 2797 Dart_WeakPersistentHandle weak_ref = NULL; | 2864 Dart_WeakPersistentHandle weak_ref = NULL; |
| 2798 int peer = 0; | 2865 int peer = 0; |
| 2799 { | 2866 { |
| 2800 Dart_EnterScope(); | 2867 Dart_EnterScope(); |
| 2801 Dart_Handle obj = NewString("new string"); | 2868 Dart_Handle obj = NewString("new string"); |
| 2802 EXPECT_VALID(obj); | 2869 EXPECT_VALID(obj); |
| 2803 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, 0, | 2870 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, 0, |
| 2804 WeakPersistentHandlePeerFinalizer); | 2871 WeakPersistentHandlePeerFinalizer); |
| 2805 Dart_ExitScope(); | 2872 Dart_ExitScope(); |
| 2806 } | 2873 } |
| 2807 // A finalizer is not invoked on a deleted handle. Therefore, the | 2874 // A finalizer is not invoked on a deleted handle. Therefore, the |
| 2808 // peer value should not change after the referent is collected. | 2875 // peer value should not change after the referent is collected. |
| 2809 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); | 2876 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); |
| 2810 Dart_DeleteWeakPersistentHandle(isolate, weak_ref); | 2877 Dart_DeleteWeakPersistentHandle(isolate, weak_ref); |
| 2811 EXPECT(peer == 0); | 2878 EXPECT(peer == 0); |
| 2812 { | 2879 { |
| 2813 TransitionNativeToVM transition(thread); | 2880 TransitionNativeToVM transition(thread); |
| 2814 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2881 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2815 EXPECT(peer == 0); | 2882 EXPECT(peer == 0); |
| 2816 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2883 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 2884 GCTestHelper::WaitForFinalizationTasks(); |
| 2817 EXPECT(peer == 0); | 2885 EXPECT(peer == 0); |
| 2818 } | 2886 } |
| 2819 } | 2887 } |
| 2820 | 2888 |
| 2821 | 2889 |
| 2822 UNIT_TEST_CASE(WeakPersistentHandlesCallbackShutdown) { | 2890 UNIT_TEST_CASE(WeakPersistentHandlesCallbackShutdown) { |
| 2823 TestCase::CreateTestIsolate(); | 2891 TestCase::CreateTestIsolate(); |
| 2824 Dart_EnterScope(); | 2892 Dart_EnterScope(); |
| 2825 Dart_Handle ref = Dart_True(); | 2893 Dart_Handle ref = Dart_True(); |
| 2826 int peer = 1234; | 2894 int peer = 1234; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2867 Dart_ExitScope(); | 2935 Dart_ExitScope(); |
| 2868 } | 2936 } |
| 2869 { | 2937 { |
| 2870 TransitionNativeToVM transition(thread); | 2938 TransitionNativeToVM transition(thread); |
| 2871 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2939 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2872 EXPECT(heap->ExternalInWords(Heap::kNew) == | 2940 EXPECT(heap->ExternalInWords(Heap::kNew) == |
| 2873 (kWeak1ExternalSize + kWeak2ExternalSize) / kWordSize); | 2941 (kWeak1ExternalSize + kWeak2ExternalSize) / kWordSize); |
| 2874 // Collect weakly referenced string, and promote strongly referenced string. | 2942 // Collect weakly referenced string, and promote strongly referenced string. |
| 2875 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2943 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 2876 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2944 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 2945 GCTestHelper::WaitForFinalizationTasks(); |
| 2877 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); | 2946 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); |
| 2878 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak2ExternalSize / kWordSize); | 2947 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak2ExternalSize / kWordSize); |
| 2879 } | 2948 } |
| 2880 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); | 2949 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); |
| 2881 Dart_DeleteWeakPersistentHandle(isolate, weak1); | 2950 Dart_DeleteWeakPersistentHandle(isolate, weak1); |
| 2882 Dart_DeleteWeakPersistentHandle(isolate, weak2); | 2951 Dart_DeleteWeakPersistentHandle(isolate, weak2); |
| 2883 Dart_DeletePersistentHandle(strong_ref); | 2952 Dart_DeletePersistentHandle(strong_ref); |
| 2884 { | 2953 { |
| 2885 TransitionNativeToVM transition(thread); | 2954 TransitionNativeToVM transition(thread); |
| 2886 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2955 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2956 GCTestHelper::WaitForFinalizationTasks(); |
| 2887 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); | 2957 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); |
| 2888 } | 2958 } |
| 2889 } | 2959 } |
| 2890 | 2960 |
| 2891 | 2961 |
| 2892 TEST_CASE(WeakPersistentHandleExternalAllocationSizeNewspaceGC) { | 2962 TEST_CASE(WeakPersistentHandleExternalAllocationSizeNewspaceGC) { |
| 2893 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); | 2963 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); |
| 2894 Heap* heap = Isolate::Current()->heap(); | 2964 Heap* heap = Isolate::Current()->heap(); |
| 2895 Dart_WeakPersistentHandle weak1 = NULL; | 2965 Dart_WeakPersistentHandle weak1 = NULL; |
| 2896 // Large enough to exceed any new space limit. Not actually allocated. | 2966 // Large enough to exceed any new space limit. Not actually allocated. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2922 EXPECT(handle.IsOld()); | 2992 EXPECT(handle.IsOld()); |
| 2923 } | 2993 } |
| 2924 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); | 2994 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); |
| 2925 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak1ExternalSize / kWordSize); | 2995 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak1ExternalSize / kWordSize); |
| 2926 Dart_ExitScope(); | 2996 Dart_ExitScope(); |
| 2927 } | 2997 } |
| 2928 Dart_DeleteWeakPersistentHandle(isolate, weak1); | 2998 Dart_DeleteWeakPersistentHandle(isolate, weak1); |
| 2929 { | 2999 { |
| 2930 TransitionNativeToVM transition(thread); | 3000 TransitionNativeToVM transition(thread); |
| 2931 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 3001 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 3002 GCTestHelper::WaitForFinalizationTasks(); |
| 2932 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); | 3003 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); |
| 2933 } | 3004 } |
| 2934 } | 3005 } |
| 2935 | 3006 |
| 2936 | 3007 |
| 2937 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOldspaceGC) { | 3008 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOldspaceGC) { |
| 2938 // Check that external allocation in old space can trigger GC. | 3009 // Check that external allocation in old space can trigger GC. |
| 2939 Isolate* isolate = Isolate::Current(); | 3010 Isolate* isolate = Isolate::Current(); |
| 2940 Dart_EnterScope(); | 3011 Dart_EnterScope(); |
| 2941 Dart_Handle live = Api::NewHandle(thread, String::New("live", Heap::kOld)); | 3012 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 } | 8771 } |
| 8701 | 8772 |
| 8702 Dart_ExitScope(); | 8773 Dart_ExitScope(); |
| 8703 } | 8774 } |
| 8704 EXPECT_EQ(40, peer8); | 8775 EXPECT_EQ(40, peer8); |
| 8705 EXPECT_EQ(41, peer16); | 8776 EXPECT_EQ(41, peer16); |
| 8706 EXPECT_EQ(42, canonical_str_peer); | 8777 EXPECT_EQ(42, canonical_str_peer); |
| 8707 { | 8778 { |
| 8708 TransitionNativeToVM transition(thread); | 8779 TransitionNativeToVM transition(thread); |
| 8709 Isolate::Current()->heap()->CollectAllGarbage(); | 8780 Isolate::Current()->heap()->CollectAllGarbage(); |
| 8781 GCTestHelper::WaitForFinalizationTasks(); |
| 8710 } | 8782 } |
| 8711 EXPECT_EQ(80, peer8); | 8783 EXPECT_EQ(80, peer8); |
| 8712 EXPECT_EQ(82, peer16); | 8784 EXPECT_EQ(82, peer16); |
| 8713 EXPECT_EQ(42, canonical_str_peer); // "*" Symbol is not removed on GC. | 8785 EXPECT_EQ(42, canonical_str_peer); // "*" Symbol is not removed on GC. |
| 8714 | 8786 |
| 8715 FLAG_support_externalizable_strings = saved_flag; | 8787 FLAG_support_externalizable_strings = saved_flag; |
| 8716 } | 8788 } |
| 8717 | 8789 |
| 8718 | 8790 |
| 8719 TEST_CASE(ExternalizeConstantStrings) { | 8791 TEST_CASE(ExternalizeConstantStrings) { |
| (...skipping 1362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10082 result = Dart_Invoke(lib, | 10154 result = Dart_Invoke(lib, |
| 10083 NewString("foozoo"), | 10155 NewString("foozoo"), |
| 10084 0, | 10156 0, |
| 10085 NULL); | 10157 NULL); |
| 10086 EXPECT(Dart_IsError(result)); | 10158 EXPECT(Dart_IsError(result)); |
| 10087 } | 10159 } |
| 10088 | 10160 |
| 10089 #endif // !PRODUCT | 10161 #endif // !PRODUCT |
| 10090 | 10162 |
| 10091 } // namespace dart | 10163 } // namespace dart |
| OLD | NEW |