| 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 "vm/dart_api_impl.h" | 5 #include "vm/dart_api_impl.h" |
| 6 #include "bin/builtin.h" | 6 #include "bin/builtin.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 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1224 EXPECT_EQ(expected[i], utf8_encoded_reversed[i]); | 1224 EXPECT_EQ(expected[i], utf8_encoded_reversed[i]); |
| 1225 } | 1225 } |
| 1226 } | 1226 } |
| 1227 | 1227 |
| 1228 // Helper class to ensure new gen GC is triggered without any side effects. | 1228 // Helper class to ensure new gen GC is triggered without any side effects. |
| 1229 // The normal call to CollectGarbage(Heap::kNew) could potentially trigger | 1229 // The normal call to CollectGarbage(Heap::kNew) could potentially trigger |
| 1230 // an old gen collection if there is a promotion failure and this could | 1230 // an old gen collection if there is a promotion failure and this could |
| 1231 // perturb the test. | 1231 // perturb the test. |
| 1232 class GCTestHelper : public AllStatic { | 1232 class GCTestHelper : public AllStatic { |
| 1233 public: | 1233 public: |
| 1234 static void CollectNewSpace(Heap::ApiCallbacks api_callbacks) { | 1234 static void CollectNewSpace() { |
| 1235 bool invoke_api_callbacks = (api_callbacks == Heap::kInvokeApiCallbacks); | 1235 Isolate::Current()->heap()->new_space()->Scavenge(); |
| 1236 Isolate::Current()->heap()->new_space()->Scavenge(invoke_api_callbacks); | |
| 1237 } | 1236 } |
| 1238 | 1237 |
| 1239 static void WaitForGCTasks() { | 1238 static void WaitForGCTasks() { |
| 1240 Thread* thread = Thread::Current(); | 1239 Thread* thread = Thread::Current(); |
| 1241 PageSpace* old_space = thread->isolate()->heap()->old_space(); | 1240 PageSpace* old_space = thread->isolate()->heap()->old_space(); |
| 1242 MonitorLocker ml(old_space->tasks_lock()); | 1241 MonitorLocker ml(old_space->tasks_lock()); |
| 1243 while (old_space->tasks() > 0) { | 1242 while (old_space->tasks() > 0) { |
| 1244 ml.WaitWithSafepointCheck(thread); | 1243 ml.WaitWithSafepointCheck(thread); |
| 1245 } | 1244 } |
| 1246 } | 1245 } |
| (...skipping 1431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2678 | 2677 |
| 2679 // Create a weak ref to the old space object. | 2678 // Create a weak ref to the old space object. |
| 2680 weak_old_ref = Dart_NewWeakPersistentHandle(old_ref, NULL, 0, | 2679 weak_old_ref = Dart_NewWeakPersistentHandle(old_ref, NULL, 0, |
| 2681 WeakPersistentHandleCallback); | 2680 WeakPersistentHandleCallback); |
| 2682 EXPECT_VALID(AsHandle(weak_old_ref)); | 2681 EXPECT_VALID(AsHandle(weak_old_ref)); |
| 2683 EXPECT(!Dart_IsNull(AsHandle(weak_old_ref))); | 2682 EXPECT(!Dart_IsNull(AsHandle(weak_old_ref))); |
| 2684 | 2683 |
| 2685 { | 2684 { |
| 2686 TransitionNativeToVM transition(thread); | 2685 TransitionNativeToVM transition(thread); |
| 2687 // Garbage collect new space. | 2686 // Garbage collect new space. |
| 2688 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2687 GCTestHelper::CollectNewSpace(); |
| 2689 } | 2688 } |
| 2690 | 2689 |
| 2691 // Nothing should be invalidated or cleared. | 2690 // Nothing should be invalidated or cleared. |
| 2692 EXPECT_VALID(new_ref); | 2691 EXPECT_VALID(new_ref); |
| 2693 EXPECT(!Dart_IsNull(new_ref)); | 2692 EXPECT(!Dart_IsNull(new_ref)); |
| 2694 EXPECT_VALID(old_ref); | 2693 EXPECT_VALID(old_ref); |
| 2695 EXPECT(!Dart_IsNull(old_ref)); | 2694 EXPECT(!Dart_IsNull(old_ref)); |
| 2696 | 2695 |
| 2697 EXPECT_VALID(AsHandle(weak_new_ref)); | 2696 EXPECT_VALID(AsHandle(weak_new_ref)); |
| 2698 EXPECT(!Dart_IsNull(AsHandle(weak_new_ref))); | 2697 EXPECT(!Dart_IsNull(AsHandle(weak_new_ref))); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2722 EXPECT(!Dart_IsNull(AsHandle(weak_old_ref))); | 2721 EXPECT(!Dart_IsNull(AsHandle(weak_old_ref))); |
| 2723 EXPECT(Dart_IdentityEquals(old_ref, AsHandle(weak_old_ref))); | 2722 EXPECT(Dart_IdentityEquals(old_ref, AsHandle(weak_old_ref))); |
| 2724 | 2723 |
| 2725 // Delete local (strong) references. | 2724 // Delete local (strong) references. |
| 2726 Dart_ExitScope(); | 2725 Dart_ExitScope(); |
| 2727 } | 2726 } |
| 2728 | 2727 |
| 2729 { | 2728 { |
| 2730 TransitionNativeToVM transition(thread); | 2729 TransitionNativeToVM transition(thread); |
| 2731 // Garbage collect new space again. | 2730 // Garbage collect new space again. |
| 2732 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2731 GCTestHelper::CollectNewSpace(); |
| 2733 GCTestHelper::WaitForGCTasks(); | 2732 GCTestHelper::WaitForGCTasks(); |
| 2734 } | 2733 } |
| 2735 | 2734 |
| 2736 { | 2735 { |
| 2737 Dart_EnterScope(); | 2736 Dart_EnterScope(); |
| 2738 // Weak ref to new space object should now be cleared. | 2737 // Weak ref to new space object should now be cleared. |
| 2739 EXPECT(weak_new_ref == NULL); | 2738 EXPECT(weak_new_ref == NULL); |
| 2740 EXPECT_VALID(AsHandle(weak_old_ref)); | 2739 EXPECT_VALID(AsHandle(weak_old_ref)); |
| 2741 EXPECT(!Dart_IsNull(AsHandle(weak_old_ref))); | 2740 EXPECT(!Dart_IsNull(AsHandle(weak_old_ref))); |
| 2742 Dart_ExitScope(); | 2741 Dart_ExitScope(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2801 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, 0, | 2800 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, 0, |
| 2802 WeakPersistentHandlePeerFinalizer); | 2801 WeakPersistentHandlePeerFinalizer); |
| 2803 EXPECT_VALID(AsHandle(weak_ref)); | 2802 EXPECT_VALID(AsHandle(weak_ref)); |
| 2804 EXPECT(peer == 0); | 2803 EXPECT(peer == 0); |
| 2805 Dart_ExitScope(); | 2804 Dart_ExitScope(); |
| 2806 } | 2805 } |
| 2807 { | 2806 { |
| 2808 TransitionNativeToVM transition(thread); | 2807 TransitionNativeToVM transition(thread); |
| 2809 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2808 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2810 EXPECT(peer == 0); | 2809 EXPECT(peer == 0); |
| 2811 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2810 GCTestHelper::CollectNewSpace(); |
| 2812 GCTestHelper::WaitForGCTasks(); | 2811 GCTestHelper::WaitForGCTasks(); |
| 2813 EXPECT(peer == 42); | 2812 EXPECT(peer == 42); |
| 2814 } | 2813 } |
| 2815 } | 2814 } |
| 2816 | 2815 |
| 2817 TEST_CASE(DartAPI_WeakPersistentHandleNoCallback) { | 2816 TEST_CASE(DartAPI_WeakPersistentHandleNoCallback) { |
| 2818 Dart_WeakPersistentHandle weak_ref = NULL; | 2817 Dart_WeakPersistentHandle weak_ref = NULL; |
| 2819 int peer = 0; | 2818 int peer = 0; |
| 2820 { | 2819 { |
| 2821 Dart_EnterScope(); | 2820 Dart_EnterScope(); |
| 2822 Dart_Handle obj = NewString("new string"); | 2821 Dart_Handle obj = NewString("new string"); |
| 2823 EXPECT_VALID(obj); | 2822 EXPECT_VALID(obj); |
| 2824 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, 0, | 2823 weak_ref = Dart_NewWeakPersistentHandle(obj, &peer, 0, |
| 2825 WeakPersistentHandlePeerFinalizer); | 2824 WeakPersistentHandlePeerFinalizer); |
| 2826 Dart_ExitScope(); | 2825 Dart_ExitScope(); |
| 2827 } | 2826 } |
| 2828 // A finalizer is not invoked on a deleted handle. Therefore, the | 2827 // A finalizer is not invoked on a deleted handle. Therefore, the |
| 2829 // peer value should not change after the referent is collected. | 2828 // peer value should not change after the referent is collected. |
| 2830 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); | 2829 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); |
| 2831 Dart_DeleteWeakPersistentHandle(isolate, weak_ref); | 2830 Dart_DeleteWeakPersistentHandle(isolate, weak_ref); |
| 2832 EXPECT(peer == 0); | 2831 EXPECT(peer == 0); |
| 2833 { | 2832 { |
| 2834 TransitionNativeToVM transition(thread); | 2833 TransitionNativeToVM transition(thread); |
| 2835 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2834 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2836 EXPECT(peer == 0); | 2835 EXPECT(peer == 0); |
| 2837 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2836 GCTestHelper::CollectNewSpace(); |
| 2838 GCTestHelper::WaitForGCTasks(); | 2837 GCTestHelper::WaitForGCTasks(); |
| 2839 EXPECT(peer == 0); | 2838 EXPECT(peer == 0); |
| 2840 } | 2839 } |
| 2841 } | 2840 } |
| 2842 | 2841 |
| 2843 VM_UNIT_TEST_CASE(DartAPI_WeakPersistentHandlesCallbackShutdown) { | 2842 VM_UNIT_TEST_CASE(DartAPI_WeakPersistentHandlesCallbackShutdown) { |
| 2844 TestCase::CreateTestIsolate(); | 2843 TestCase::CreateTestIsolate(); |
| 2845 Dart_EnterScope(); | 2844 Dart_EnterScope(); |
| 2846 Dart_Handle ref = Dart_True(); | 2845 Dart_Handle ref = Dart_True(); |
| 2847 int peer = 1234; | 2846 int peer = 1234; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2879 NopCallback); | 2878 NopCallback); |
| 2880 EXPECT_VALID(AsHandle(strong_ref)); | 2879 EXPECT_VALID(AsHandle(strong_ref)); |
| 2881 Dart_ExitScope(); | 2880 Dart_ExitScope(); |
| 2882 } | 2881 } |
| 2883 { | 2882 { |
| 2884 TransitionNativeToVM transition(thread); | 2883 TransitionNativeToVM transition(thread); |
| 2885 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2884 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 2886 EXPECT(heap->ExternalInWords(Heap::kNew) == | 2885 EXPECT(heap->ExternalInWords(Heap::kNew) == |
| 2887 (kWeak1ExternalSize + kWeak2ExternalSize) / kWordSize); | 2886 (kWeak1ExternalSize + kWeak2ExternalSize) / kWordSize); |
| 2888 // Collect weakly referenced string, and promote strongly referenced string. | 2887 // Collect weakly referenced string, and promote strongly referenced string. |
| 2889 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2888 GCTestHelper::CollectNewSpace(); |
| 2890 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 2889 GCTestHelper::CollectNewSpace(); |
| 2891 GCTestHelper::WaitForGCTasks(); | 2890 GCTestHelper::WaitForGCTasks(); |
| 2892 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); | 2891 EXPECT(heap->ExternalInWords(Heap::kNew) == 0); |
| 2893 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak2ExternalSize / kWordSize); | 2892 EXPECT(heap->ExternalInWords(Heap::kOld) == kWeak2ExternalSize / kWordSize); |
| 2894 } | 2893 } |
| 2895 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); | 2894 Dart_Isolate isolate = reinterpret_cast<Dart_Isolate>(Isolate::Current()); |
| 2896 Dart_DeleteWeakPersistentHandle(isolate, weak1); | 2895 Dart_DeleteWeakPersistentHandle(isolate, weak1); |
| 2897 Dart_DeleteWeakPersistentHandle(isolate, weak2); | 2896 Dart_DeleteWeakPersistentHandle(isolate, weak2); |
| 2898 Dart_DeletePersistentHandle(strong_ref); | 2897 Dart_DeletePersistentHandle(strong_ref); |
| 2899 { | 2898 { |
| 2900 TransitionNativeToVM transition(thread); | 2899 TransitionNativeToVM transition(thread); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3071 Dart_EnterScope(); | 3070 Dart_EnterScope(); |
| 3072 EXPECT_VALID(AsHandle(strong_weak)); | 3071 EXPECT_VALID(AsHandle(strong_weak)); |
| 3073 EXPECT_VALID(AsHandle(weak1)); | 3072 EXPECT_VALID(AsHandle(weak1)); |
| 3074 EXPECT_VALID(AsHandle(weak2)); | 3073 EXPECT_VALID(AsHandle(weak2)); |
| 3075 EXPECT_VALID(AsHandle(weak3)); | 3074 EXPECT_VALID(AsHandle(weak3)); |
| 3076 Dart_ExitScope(); | 3075 Dart_ExitScope(); |
| 3077 } | 3076 } |
| 3078 | 3077 |
| 3079 { | 3078 { |
| 3080 TransitionNativeToVM transition(thread); | 3079 TransitionNativeToVM transition(thread); |
| 3081 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | 3080 GCTestHelper::CollectNewSpace(); |
| 3082 } | 3081 } |
| 3083 | 3082 |
| 3084 { | 3083 { |
| 3085 Dart_EnterScope(); | 3084 Dart_EnterScope(); |
| 3086 // New space collection should not affect old space objects | 3085 // New space collection should not affect old space objects |
| 3087 EXPECT_VALID(AsHandle(strong_weak)); | 3086 EXPECT_VALID(AsHandle(strong_weak)); |
| 3088 EXPECT(!Dart_IsNull(AsHandle(weak1))); | 3087 EXPECT(!Dart_IsNull(AsHandle(weak1))); |
| 3089 EXPECT(!Dart_IsNull(AsHandle(weak2))); | 3088 EXPECT(!Dart_IsNull(AsHandle(weak2))); |
| 3090 EXPECT(!Dart_IsNull(AsHandle(weak3))); | 3089 EXPECT(!Dart_IsNull(AsHandle(weak3))); |
| 3091 Dart_ExitScope(); | 3090 Dart_ExitScope(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3149 { | 3148 { |
| 3150 Dart_EnterScope(); | 3149 Dart_EnterScope(); |
| 3151 // Old space collection should not affect old space objects. | 3150 // Old space collection should not affect old space objects. |
| 3152 EXPECT(!Dart_IsNull(AsHandle(weak1))); | 3151 EXPECT(!Dart_IsNull(AsHandle(weak1))); |
| 3153 EXPECT(!Dart_IsNull(AsHandle(weak2))); | 3152 EXPECT(!Dart_IsNull(AsHandle(weak2))); |
| 3154 EXPECT(!Dart_IsNull(AsHandle(weak3))); | 3153 EXPECT(!Dart_IsNull(AsHandle(weak3))); |
| 3155 Dart_ExitScope(); | 3154 Dart_ExitScope(); |
| 3156 } | 3155 } |
| 3157 } | 3156 } |
| 3158 | 3157 |
| 3159 static int global_prologue_callback_status; | |
| 3160 | |
| 3161 static void PrologueCallbackTimes2() { | |
| 3162 global_prologue_callback_status *= 2; | |
| 3163 } | |
| 3164 | |
| 3165 static void PrologueCallbackTimes3() { | |
| 3166 global_prologue_callback_status *= 3; | |
| 3167 } | |
| 3168 | |
| 3169 static int global_epilogue_callback_status; | |
| 3170 | |
| 3171 static void EpilogueCallbackNOP() {} | |
| 3172 | |
| 3173 static void EpilogueCallbackTimes4() { | |
| 3174 global_epilogue_callback_status *= 4; | |
| 3175 } | |
| 3176 | |
| 3177 static void EpilogueCallbackTimes5() { | |
| 3178 global_epilogue_callback_status *= 5; | |
| 3179 } | |
| 3180 | |
| 3181 TEST_CASE(DartAPI_SetGarbageCollectionCallbacks) { | |
| 3182 // GC callback addition testing. | |
| 3183 | |
| 3184 // Add GC callbacks. | |
| 3185 EXPECT_VALID( | |
| 3186 Dart_SetGcCallbacks(&PrologueCallbackTimes2, &EpilogueCallbackTimes4)); | |
| 3187 | |
| 3188 // Add the same callbacks again. This is an error. | |
| 3189 EXPECT(Dart_IsError( | |
| 3190 Dart_SetGcCallbacks(&PrologueCallbackTimes2, &EpilogueCallbackTimes4))); | |
| 3191 | |
| 3192 // Add another callback. This is an error. | |
| 3193 EXPECT(Dart_IsError( | |
| 3194 Dart_SetGcCallbacks(&PrologueCallbackTimes3, &EpilogueCallbackTimes5))); | |
| 3195 | |
| 3196 // GC callback removal testing. | |
| 3197 | |
| 3198 // Remove GC callbacks. | |
| 3199 EXPECT_VALID(Dart_SetGcCallbacks(NULL, NULL)); | |
| 3200 | |
| 3201 // Remove GC callbacks whennone exist. This is an error. | |
| 3202 EXPECT(Dart_IsError(Dart_SetGcCallbacks(NULL, NULL))); | |
| 3203 | |
| 3204 EXPECT_VALID( | |
| 3205 Dart_SetGcCallbacks(&PrologueCallbackTimes2, &EpilogueCallbackTimes4)); | |
| 3206 EXPECT(Dart_IsError(Dart_SetGcCallbacks(&PrologueCallbackTimes2, NULL))); | |
| 3207 EXPECT(Dart_IsError(Dart_SetGcCallbacks(NULL, &EpilogueCallbackTimes4))); | |
| 3208 } | |
| 3209 | |
| 3210 TEST_CASE(DartAPI_SingleGarbageCollectionCallback) { | |
| 3211 // Add a prologue callback. | |
| 3212 EXPECT_VALID( | |
| 3213 Dart_SetGcCallbacks(&PrologueCallbackTimes2, &EpilogueCallbackNOP)); | |
| 3214 | |
| 3215 { | |
| 3216 TransitionNativeToVM transition(thread); | |
| 3217 | |
| 3218 // Garbage collect new space ignoring callbacks. This should not | |
| 3219 // invoke the prologue callback. No status values should change. | |
| 3220 global_prologue_callback_status = 3; | |
| 3221 global_epilogue_callback_status = 7; | |
| 3222 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | |
| 3223 EXPECT_EQ(3, global_prologue_callback_status); | |
| 3224 EXPECT_EQ(7, global_epilogue_callback_status); | |
| 3225 | |
| 3226 // Garbage collect new space invoking callbacks. This should | |
| 3227 // invoke the prologue callback. No status values should change. | |
| 3228 global_prologue_callback_status = 3; | |
| 3229 global_epilogue_callback_status = 7; | |
| 3230 GCTestHelper::CollectNewSpace(Heap::kInvokeApiCallbacks); | |
| 3231 EXPECT_EQ(6, global_prologue_callback_status); | |
| 3232 EXPECT_EQ(7, global_epilogue_callback_status); | |
| 3233 | |
| 3234 // Garbage collect old space ignoring callbacks. This should invoke | |
| 3235 // the prologue callback. The prologue status value should change. | |
| 3236 global_prologue_callback_status = 3; | |
| 3237 global_epilogue_callback_status = 7; | |
| 3238 Isolate::Current()->heap()->CollectGarbage( | |
| 3239 Heap::kOld, Heap::kIgnoreApiCallbacks, Heap::kGCTestCase); | |
| 3240 EXPECT_EQ(3, global_prologue_callback_status); | |
| 3241 EXPECT_EQ(7, global_epilogue_callback_status); | |
| 3242 | |
| 3243 // Garbage collect old space. This should invoke the prologue | |
| 3244 // callback. The prologue status value should change. | |
| 3245 global_prologue_callback_status = 3; | |
| 3246 global_epilogue_callback_status = 7; | |
| 3247 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | |
| 3248 EXPECT_EQ(6, global_prologue_callback_status); | |
| 3249 EXPECT_EQ(7, global_epilogue_callback_status); | |
| 3250 | |
| 3251 // Garbage collect old space again. Callbacks are persistent so the | |
| 3252 // prologue status value should change again. | |
| 3253 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | |
| 3254 EXPECT_EQ(12, global_prologue_callback_status); | |
| 3255 EXPECT_EQ(7, global_epilogue_callback_status); | |
| 3256 } | |
| 3257 | |
| 3258 // Add an epilogue callback. | |
| 3259 EXPECT_VALID(Dart_SetGcCallbacks(NULL, NULL)); | |
| 3260 EXPECT_VALID( | |
| 3261 Dart_SetGcCallbacks(&PrologueCallbackTimes2, &EpilogueCallbackTimes4)); | |
| 3262 | |
| 3263 { | |
| 3264 TransitionNativeToVM transition(thread); | |
| 3265 // Garbage collect new space. This should not invoke the prologue | |
| 3266 // or the epilogue callback. No status values should change. | |
| 3267 global_prologue_callback_status = 3; | |
| 3268 global_epilogue_callback_status = 7; | |
| 3269 GCTestHelper::CollectNewSpace(Heap::kIgnoreApiCallbacks); | |
| 3270 EXPECT_EQ(3, global_prologue_callback_status); | |
| 3271 EXPECT_EQ(7, global_epilogue_callback_status); | |
| 3272 | |
| 3273 // Garbage collect new space. This should invoke the prologue and | |
| 3274 // the epilogue callback. The prologue and epilogue status values | |
| 3275 // should change. | |
| 3276 GCTestHelper::CollectNewSpace(Heap::kInvokeApiCallbacks); | |
| 3277 EXPECT_EQ(6, global_prologue_callback_status); | |
| 3278 EXPECT_EQ(28, global_epilogue_callback_status); | |
| 3279 | |
| 3280 // Garbage collect old space. This should invoke the prologue and | |
| 3281 // the epilogue callbacks. The prologue and epilogue status values | |
| 3282 // should change. | |
| 3283 global_prologue_callback_status = 3; | |
| 3284 global_epilogue_callback_status = 7; | |
| 3285 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | |
| 3286 EXPECT_EQ(6, global_prologue_callback_status); | |
| 3287 EXPECT_EQ(28, global_epilogue_callback_status); | |
| 3288 | |
| 3289 // Garbage collect old space again without invoking callbacks. | |
| 3290 // Nothing should change. | |
| 3291 Isolate::Current()->heap()->CollectGarbage( | |
| 3292 Heap::kOld, Heap::kIgnoreApiCallbacks, Heap::kGCTestCase); | |
| 3293 EXPECT_EQ(6, global_prologue_callback_status); | |
| 3294 EXPECT_EQ(28, global_epilogue_callback_status); | |
| 3295 | |
| 3296 // Garbage collect old space again. Callbacks are persistent so the | |
| 3297 // prologue and epilogue status values should change again. | |
| 3298 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | |
| 3299 EXPECT_EQ(12, global_prologue_callback_status); | |
| 3300 EXPECT_EQ(112, global_epilogue_callback_status); | |
| 3301 } | |
| 3302 | |
| 3303 // Remove the prologue and epilogue callbacks | |
| 3304 EXPECT_VALID(Dart_SetGcCallbacks(NULL, NULL)); | |
| 3305 | |
| 3306 { | |
| 3307 TransitionNativeToVM transition(thread); | |
| 3308 // Garbage collect old space. No callbacks should be invoked. No | |
| 3309 // status values should change. | |
| 3310 global_prologue_callback_status = 3; | |
| 3311 global_epilogue_callback_status = 7; | |
| 3312 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | |
| 3313 EXPECT_EQ(3, global_prologue_callback_status); | |
| 3314 EXPECT_EQ(7, global_epilogue_callback_status); | |
| 3315 } | |
| 3316 } | |
| 3317 | |
| 3318 // Unit test for creating multiple scopes and local handles within them. | 3158 // Unit test for creating multiple scopes and local handles within them. |
| 3319 // Ensure that the local handles get all cleaned out when exiting the | 3159 // Ensure that the local handles get all cleaned out when exiting the |
| 3320 // scope. | 3160 // scope. |
| 3321 VM_UNIT_TEST_CASE(DartAPI_LocalHandles) { | 3161 VM_UNIT_TEST_CASE(DartAPI_LocalHandles) { |
| 3322 TestCase::CreateTestIsolate(); | 3162 TestCase::CreateTestIsolate(); |
| 3323 Thread* thread = Thread::Current(); | 3163 Thread* thread = Thread::Current(); |
| 3324 Isolate* isolate = thread->isolate(); | 3164 Isolate* isolate = thread->isolate(); |
| 3325 EXPECT(isolate != NULL); | 3165 EXPECT(isolate != NULL); |
| 3326 ApiLocalScope* scope = thread->api_top_scope(); | 3166 ApiLocalScope* scope = thread->api_top_scope(); |
| 3327 Dart_Handle handles[300]; | 3167 Dart_Handle handles[300]; |
| (...skipping 5848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9176 EXPECT_VALID(result); | 9016 EXPECT_VALID(result); |
| 9177 result = Dart_FinalizeLoading(false); | 9017 result = Dart_FinalizeLoading(false); |
| 9178 EXPECT_VALID(result); | 9018 EXPECT_VALID(result); |
| 9179 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); | 9019 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); |
| 9180 EXPECT(Dart_IsError(result)); | 9020 EXPECT(Dart_IsError(result)); |
| 9181 } | 9021 } |
| 9182 | 9022 |
| 9183 #endif // !PRODUCT | 9023 #endif // !PRODUCT |
| 9184 | 9024 |
| 9185 } // namespace dart | 9025 } // namespace dart |
| OLD | NEW |