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 Monitor* slow_finalizers_monitor = NULL; | |
| 2419 static volatile intptr_t slow_finalizers_waiting = 0; | |
| 2420 static volatile intptr_t slow_finalizers_done = 0; | |
| 2421 | |
| 2422 | |
| 2423 static void SlowFinalizer(void* isolate_callback_data, | |
| 2424 Dart_WeakPersistentHandle handle, | |
| 2425 void* peer) { | |
| 2426 { | |
| 2427 MonitorLocker ml(slow_finalizers_monitor); | |
| 2428 slow_finalizers_waiting++; | |
| 2429 while (slow_finalizers_waiting < 10) { | |
| 2430 OS::Print("wait"); | |
| 2431 ml.Wait(); | |
| 2432 } | |
|
siva
2016/06/22 22:55:31
See comment below:
Isn't it sufficient to do
whil
rmacnak
2016/06/22 23:13:48
Yes, that works too.
| |
| 2433 slow_finalizers_done++; | |
| 2434 } | |
| 2435 | |
| 2436 intptr_t* count = reinterpret_cast<intptr_t*>(peer); | |
| 2437 AtomicOperations::IncrementBy(count, 1); | |
| 2438 } | |
| 2439 | |
| 2440 | |
| 2441 TEST_CASE(SlowFinalizer) { | |
| 2442 slow_finalizers_monitor = new Monitor(); | |
| 2443 | |
| 2444 intptr_t count = 0; | |
| 2445 for (intptr_t i = 0; i < 10; i++) { | |
| 2446 Dart_EnterScope(); | |
| 2447 Dart_Handle str1 = Dart_NewStringFromCString("Live fast"); | |
| 2448 Dart_NewWeakPersistentHandle(str1, &count, 0, SlowFinalizer); | |
| 2449 Dart_Handle str2 = Dart_NewStringFromCString("Die young"); | |
| 2450 Dart_NewWeakPersistentHandle(str2, &count, 0, SlowFinalizer); | |
| 2451 Dart_ExitScope(); | |
| 2452 | |
| 2453 { | |
| 2454 TransitionNativeToVM transition(thread); | |
| 2455 Isolate::Current()->heap()->CollectAllGarbage(); | |
| 2456 } | |
| 2457 } | |
| 2458 | |
| 2459 { | |
| 2460 while (slow_finalizers_done < 20) { | |
| 2461 MonitorLocker ml(slow_finalizers_monitor); | |
| 2462 ml.NotifyAll(); | |
| 2463 } | |
| 2464 } | |
|
siva
2016/06/22 22:55:31
Why is this block needed here? Isn't it sufficient
| |
| 2465 | |
| 2466 { | |
| 2467 TransitionNativeToVM transition(thread); | |
| 2468 GCTestHelper::WaitForFinalizationTasks(); | |
| 2469 } | |
| 2470 | |
| 2471 EXPECT_EQ(20, count); | |
| 2472 | |
| 2473 delete slow_finalizers_monitor; | |
| 2474 } | |
| 2475 | |
| 2476 | |
| 2392 static void CheckFloat32x4Data(Dart_Handle obj) { | 2477 static void CheckFloat32x4Data(Dart_Handle obj) { |
| 2393 void* raw_data = NULL; | 2478 void* raw_data = NULL; |
| 2394 intptr_t len; | 2479 intptr_t len; |
| 2395 Dart_TypedData_Type type; | 2480 Dart_TypedData_Type type; |
| 2396 EXPECT_VALID(Dart_TypedDataAcquireData(obj, &type, &raw_data, &len)); | 2481 EXPECT_VALID(Dart_TypedDataAcquireData(obj, &type, &raw_data, &len)); |
| 2397 EXPECT_EQ(Dart_TypedData_kFloat32x4, type); | 2482 EXPECT_EQ(Dart_TypedData_kFloat32x4, type); |
| 2398 EXPECT_EQ(len, 10); | 2483 EXPECT_EQ(len, 10); |
| 2399 float* float_data = reinterpret_cast<float*>(raw_data); | 2484 float* float_data = reinterpret_cast<float*>(raw_data); |
| 2400 for (int i = 0; i < len * 4; i++) { | 2485 for (int i = 0; i < len * 4; i++) { |
| 2401 EXPECT_EQ(0.0, float_data[i]); | 2486 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( | 2518 Dart_Handle lcl = Dart_NewExternalTypedData( |
| 2434 Dart_TypedData_kFloat32x4, data, 10); | 2519 Dart_TypedData_kFloat32x4, data, 10); |
| 2435 Dart_NewWeakPersistentHandle( | 2520 Dart_NewWeakPersistentHandle( |
| 2436 lcl, &peer, sizeof(data), ExternalTypedDataFinalizer); | 2521 lcl, &peer, sizeof(data), ExternalTypedDataFinalizer); |
| 2437 CheckFloat32x4Data(lcl); | 2522 CheckFloat32x4Data(lcl); |
| 2438 } | 2523 } |
| 2439 Dart_ExitScope(); | 2524 Dart_ExitScope(); |
| 2440 { | 2525 { |
| 2441 TransitionNativeToVM transition(thread); | 2526 TransitionNativeToVM transition(thread); |
| 2442 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); | 2527 Isolate::Current()->heap()->CollectGarbage(Heap::kNew); |
| 2528 GCTestHelper::WaitForFinalizationTasks(); | |
| 2443 EXPECT(peer == 42); | 2529 EXPECT(peer == 42); |
| 2444 } | 2530 } |
| 2445 } | 2531 } |
| 2446 | 2532 |
| 2447 | 2533 |
| 2448 // Unit test for entering a scope, creating a local handle and exiting | 2534 // Unit test for entering a scope, creating a local handle and exiting |
| 2449 // the scope. | 2535 // the scope. |
| 2450 UNIT_TEST_CASE(EnterExitScope) { | 2536 UNIT_TEST_CASE(EnterExitScope) { |
| 2451 TestIsolateScope __test_isolate__; | 2537 TestIsolateScope __test_isolate__; |
| 2452 | 2538 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2595 Dart_SetPersistentHandle(obj, ref2); | 2681 Dart_SetPersistentHandle(obj, ref2); |
| 2596 str ^= PersistentHandle::Cast(obj)->raw(); | 2682 str ^= PersistentHandle::Cast(obj)->raw(); |
| 2597 EXPECT(str.Equals(kTestString2)); | 2683 EXPECT(str.Equals(kTestString2)); |
| 2598 | 2684 |
| 2599 // Now assign Null to the persistent handle and check. | 2685 // Now assign Null to the persistent handle and check. |
| 2600 Dart_SetPersistentHandle(obj, Dart_Null()); | 2686 Dart_SetPersistentHandle(obj, Dart_Null()); |
| 2601 EXPECT(Dart_IsNull(obj)); | 2687 EXPECT(Dart_IsNull(obj)); |
| 2602 } | 2688 } |
| 2603 | 2689 |
| 2604 | 2690 |
| 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) { | 2691 static Dart_Handle AsHandle(Dart_PersistentHandle weak) { |
| 2619 return Dart_HandleFromPersistent(weak); | 2692 return Dart_HandleFromPersistent(weak); |
| 2620 } | 2693 } |
| 2621 | 2694 |
| 2622 | 2695 |
| 2623 static Dart_Handle AsHandle(Dart_WeakPersistentHandle weak) { | 2696 static Dart_Handle AsHandle(Dart_WeakPersistentHandle weak) { |
| 2624 return Dart_HandleFromWeakPersistent(weak); | 2697 return Dart_HandleFromWeakPersistent(weak); |
| 2625 } | 2698 } |
| 2626 | 2699 |
| 2627 | 2700 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2722 EXPECT(Dart_IdentityEquals(old_ref, AsHandle(weak_old_ref))); | 2795 EXPECT(Dart_IdentityEquals(old_ref, AsHandle(weak_old_ref))); |
| 2723 | 2796 |
| 2724 // Delete local (strong) references. | 2797 // Delete local (strong) references. |
| 2725 Dart_ExitScope(); | 2798 Dart_ExitScope(); |
| 2726 } | 2799 } |
| 2727 | 2800 |
| 2728 { | 2801 { |
| 2729 TransitionNativeToVM transition(thread); | 2802 TransitionNativeToVM transition(thread); |
| 2730 // Garbage collect new space again. | 2803 // Garbage collect new space again. |
| 2731 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2804 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 2805 GCTestHelper::WaitForFinalizationTasks(); | |
| 2732 } | 2806 } |
| 2733 | 2807 |
| 2734 { | 2808 { |
| 2735 Dart_EnterScope(); | 2809 Dart_EnterScope(); |
| 2736 // Weak ref to new space object should now be cleared. | 2810 // Weak ref to new space object should now be cleared. |
| 2737 EXPECT(weak_new_ref == NULL); | 2811 EXPECT(weak_new_ref == NULL); |
| 2738 EXPECT_VALID(AsHandle(weak_old_ref)); | 2812 EXPECT_VALID(AsHandle(weak_old_ref)); |
| 2739 EXPECT(!Dart_IsNull(AsHandle(weak_old_ref))); | 2813 EXPECT(!Dart_IsNull(AsHandle(weak_old_ref))); |
| 2740 Dart_ExitScope(); | 2814 Dart_ExitScope(); |
| 2741 } | 2815 } |
| 2742 | 2816 |
| 2743 { | 2817 { |
| 2744 TransitionNativeToVM transition(thread); | 2818 TransitionNativeToVM transition(thread); |
| 2745 // Garbage collect old space again. | 2819 // Garbage collect old space again. |
| 2746 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2820 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2821 GCTestHelper::WaitForFinalizationTasks(); | |
| 2747 } | 2822 } |
| 2748 | 2823 |
| 2749 { | 2824 { |
| 2750 Dart_EnterScope(); | 2825 Dart_EnterScope(); |
| 2751 // Weak ref to old space object should now be cleared. | 2826 // Weak ref to old space object should now be cleared. |
| 2752 EXPECT(weak_new_ref == NULL); | 2827 EXPECT(weak_new_ref == NULL); |
| 2753 EXPECT(weak_old_ref == NULL); | 2828 EXPECT(weak_old_ref == NULL); |
| 2754 Dart_ExitScope(); | 2829 Dart_ExitScope(); |
| 2755 } | 2830 } |
| 2756 | 2831 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 2781 WeakPersistentHandlePeerFinalizer); | 2856 WeakPersistentHandlePeerFinalizer); |
| 2782 EXPECT_VALID(AsHandle(weak_ref)); | 2857 EXPECT_VALID(AsHandle(weak_ref)); |
| 2783 EXPECT(peer == 0); | 2858 EXPECT(peer == 0); |
| 2784 Dart_ExitScope(); | 2859 Dart_ExitScope(); |
| 2785 } | 2860 } |
| 2786 { | 2861 { |
| 2787 TransitionNativeToVM transition(thread); | 2862 TransitionNativeToVM transition(thread); |
| 2788 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2863 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2789 EXPECT(peer == 0); | 2864 EXPECT(peer == 0); |
| 2790 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2865 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 2866 GCTestHelper::WaitForFinalizationTasks(); | |
| 2791 EXPECT(peer == 42); | 2867 EXPECT(peer == 42); |
| 2792 } | 2868 } |
| 2793 } | 2869 } |
| 2794 | 2870 |
| 2795 | 2871 |
| 2796 TEST_CASE(WeakPersistentHandleNoCallback) { | 2872 TEST_CASE(WeakPersistentHandleNoCallback) { |
| 2797 Dart_WeakPersistentHandle weak_ref = NULL; | 2873 Dart_WeakPersistentHandle weak_ref = NULL; |
| 2798 int peer = 0; | 2874 int peer = 0; |
| 2799 { | 2875 { |
| 2800 Dart_EnterScope(); | 2876 Dart_EnterScope(); |
| 2801 Dart_Handle obj = NewString("new string"); | 2877 Dart_Handle obj = NewString("new string"); |
| 2802 EXPECT_VALID(obj); | 2878 EXPECT_VALID(obj); |
| 2803 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, 0, | 2879 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, 0, |
| 2804 WeakPersistentHandlePeerFinalizer); | 2880 WeakPersistentHandlePeerFinalizer); |
| 2805 Dart_ExitScope(); | 2881 Dart_ExitScope(); |
| 2806 } | 2882 } |
| 2807 // A finalizer is not invoked on a deleted handle. Therefore, the | 2883 // A finalizer is not invoked on a deleted handle. Therefore, the |
| 2808 // peer value should not change after the referent is collected. | 2884 // peer value should not change after the referent is collected. |
| 2809 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); | 2885 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); |
| 2810 Dart_DeleteWeakPersistentHandle(isolate, weak_ref); | 2886 Dart_DeleteWeakPersistentHandle(isolate, weak_ref); |
| 2811 EXPECT(peer == 0); | 2887 EXPECT(peer == 0); |
| 2812 { | 2888 { |
| 2813 TransitionNativeToVM transition(thread); | 2889 TransitionNativeToVM transition(thread); |
| 2814 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2890 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2815 EXPECT(peer == 0); | 2891 EXPECT(peer == 0); |
| 2816 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2892 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 2893 GCTestHelper::WaitForFinalizationTasks(); | |
| 2817 EXPECT(peer == 0); | 2894 EXPECT(peer == 0); |
| 2818 } | 2895 } |
| 2819 } | 2896 } |
| 2820 | 2897 |
| 2821 | 2898 |
| 2822 UNIT_TEST_CASE(WeakPersistentHandlesCallbackShutdown) { | 2899 UNIT_TEST_CASE(WeakPersistentHandlesCallbackShutdown) { |
| 2823 TestCase::CreateTestIsolate(); | 2900 TestCase::CreateTestIsolate(); |
| 2824 Dart_EnterScope(); | 2901 Dart_EnterScope(); |
| 2825 Dart_Handle ref = Dart_True(); | 2902 Dart_Handle ref = Dart_True(); |
| 2826 int peer = 1234; | 2903 int peer = 1234; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2867 Dart_ExitScope(); | 2944 Dart_ExitScope(); |
| 2868 } | 2945 } |
| 2869 { | 2946 { |
| 2870 TransitionNativeToVM transition(thread); | 2947 TransitionNativeToVM transition(thread); |
| 2871 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2948 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2872 EXPECT(heap->ExternalInWords(Heap::kNew) == | 2949 EXPECT(heap->ExternalInWords(Heap::kNew) == |
| 2873 (kWeak1ExternalSize + kWeak2ExternalSize) / kWordSize); | 2950 (kWeak1ExternalSize + kWeak2ExternalSize) / kWordSize); |
| 2874 // Collect weakly referenced string, and promote strongly referenced string. | 2951 // Collect weakly referenced string, and promote strongly referenced string. |
| 2875 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2952 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 2876 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2953 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); |
| 2954 GCTestHelper::WaitForFinalizationTasks(); | |
| 2877 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); | 2955 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); |
| 2878 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak2ExternalSize / kWordSize); | 2956 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak2ExternalSize / kWordSize); |
| 2879 } | 2957 } |
| 2880 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); | 2958 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); |
| 2881 Dart_DeleteWeakPersistentHandle(isolate, weak1); | 2959 Dart_DeleteWeakPersistentHandle(isolate, weak1); |
| 2882 Dart_DeleteWeakPersistentHandle(isolate, weak2); | 2960 Dart_DeleteWeakPersistentHandle(isolate, weak2); |
| 2883 Dart_DeletePersistentHandle(strong_ref); | 2961 Dart_DeletePersistentHandle(strong_ref); |
| 2884 { | 2962 { |
| 2885 TransitionNativeToVM transition(thread); | 2963 TransitionNativeToVM transition(thread); |
| 2886 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2964 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2965 GCTestHelper::WaitForFinalizationTasks(); | |
| 2887 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); | 2966 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); |
| 2888 } | 2967 } |
| 2889 } | 2968 } |
| 2890 | 2969 |
| 2891 | 2970 |
| 2892 TEST_CASE(WeakPersistentHandleExternalAllocationSizeNewspaceGC) { | 2971 TEST_CASE(WeakPersistentHandleExternalAllocationSizeNewspaceGC) { |
| 2893 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); | 2972 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); |
| 2894 Heap* heap = Isolate::Current()->heap(); | 2973 Heap* heap = Isolate::Current()->heap(); |
| 2895 Dart_WeakPersistentHandle weak1 = NULL; | 2974 Dart_WeakPersistentHandle weak1 = NULL; |
| 2896 // Large enough to exceed any new space limit. Not actually allocated. | 2975 // Large enough to exceed any new space limit. Not actually allocated. |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 2922 EXPECT(handle.IsOld()); | 3001 EXPECT(handle.IsOld()); |
| 2923 } | 3002 } |
| 2924 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); | 3003 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); |
| 2925 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak1ExternalSize / kWordSize); | 3004 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak1ExternalSize / kWordSize); |
| 2926 Dart_ExitScope(); | 3005 Dart_ExitScope(); |
| 2927 } | 3006 } |
| 2928 Dart_DeleteWeakPersistentHandle(isolate, weak1); | 3007 Dart_DeleteWeakPersistentHandle(isolate, weak1); |
| 2929 { | 3008 { |
| 2930 TransitionNativeToVM transition(thread); | 3009 TransitionNativeToVM transition(thread); |
| 2931 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 3010 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 3011 GCTestHelper::WaitForFinalizationTasks(); | |
| 2932 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); | 3012 EXPECT(heap->ExternalInWords(Heap::kOld) == 0); |
| 2933 } | 3013 } |
| 2934 } | 3014 } |
| 2935 | 3015 |
| 2936 | 3016 |
| 2937 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOldspaceGC) { | 3017 TEST_CASE(WeakPersistentHandleExternalAllocationSizeOldspaceGC) { |
| 2938 // Check that external allocation in old space can trigger GC. | 3018 // Check that external allocation in old space can trigger GC. |
| 2939 Isolate* isolate = Isolate::Current(); | 3019 Isolate* isolate = Isolate::Current(); |
| 2940 Dart_EnterScope(); | 3020 Dart_EnterScope(); |
| 2941 Dart_Handle live = Api::NewHandle(thread, String::New("live", Heap::kOld)); | 3021 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 } | 8780 } |
| 8701 | 8781 |
| 8702 Dart_ExitScope(); | 8782 Dart_ExitScope(); |
| 8703 } | 8783 } |
| 8704 EXPECT_EQ(40, peer8); | 8784 EXPECT_EQ(40, peer8); |
| 8705 EXPECT_EQ(41, peer16); | 8785 EXPECT_EQ(41, peer16); |
| 8706 EXPECT_EQ(42, canonical_str_peer); | 8786 EXPECT_EQ(42, canonical_str_peer); |
| 8707 { | 8787 { |
| 8708 TransitionNativeToVM transition(thread); | 8788 TransitionNativeToVM transition(thread); |
| 8709 Isolate::Current()->heap()->CollectAllGarbage(); | 8789 Isolate::Current()->heap()->CollectAllGarbage(); |
| 8790 GCTestHelper::WaitForFinalizationTasks(); | |
| 8710 } | 8791 } |
| 8711 EXPECT_EQ(80, peer8); | 8792 EXPECT_EQ(80, peer8); |
| 8712 EXPECT_EQ(82, peer16); | 8793 EXPECT_EQ(82, peer16); |
| 8713 EXPECT_EQ(42, canonical_str_peer); // "*" Symbol is not removed on GC. | 8794 EXPECT_EQ(42, canonical_str_peer); // "*" Symbol is not removed on GC. |
| 8714 | 8795 |
| 8715 FLAG_support_externalizable_strings = saved_flag; | 8796 FLAG_support_externalizable_strings = saved_flag; |
| 8716 } | 8797 } |
| 8717 | 8798 |
| 8718 | 8799 |
| 8719 TEST_CASE(ExternalizeConstantStrings) { | 8800 TEST_CASE(ExternalizeConstantStrings) { |
| (...skipping 1362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10082 result = Dart_Invoke(lib, | 10163 result = Dart_Invoke(lib, |
| 10083 NewString("foozoo"), | 10164 NewString("foozoo"), |
| 10084 0, | 10165 0, |
| 10085 NULL); | 10166 NULL); |
| 10086 EXPECT(Dart_IsError(result)); | 10167 EXPECT(Dart_IsError(result)); |
| 10087 } | 10168 } |
| 10088 | 10169 |
| 10089 #endif // !PRODUCT | 10170 #endif // !PRODUCT |
| 10090 | 10171 |
| 10091 } // namespace dart | 10172 } // namespace dart |
| OLD | NEW |