OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 2887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2898 | 2898 |
2899 static void WeakPointerCallback(v8::Isolate* isolate, | 2899 static void WeakPointerCallback(v8::Isolate* isolate, |
2900 Persistent<Object>* handle, | 2900 Persistent<Object>* handle, |
2901 WeakCallCounter* counter) { | 2901 WeakCallCounter* counter) { |
2902 CHECK_EQ(1234, counter->id()); | 2902 CHECK_EQ(1234, counter->id()); |
2903 counter->increment(); | 2903 counter->increment(); |
2904 handle->Dispose(isolate); | 2904 handle->Dispose(isolate); |
2905 } | 2905 } |
2906 | 2906 |
2907 | 2907 |
2908 THREADED_TEST(OldApiObjectGroups) { | |
2909 LocalContext env; | |
2910 v8::Isolate* iso = env->GetIsolate(); | |
2911 HandleScope scope(iso); | |
2912 | |
2913 Persistent<Object> g1s1; | |
2914 Persistent<Object> g1s2; | |
2915 Persistent<Object> g1c1; | |
2916 Persistent<Object> g2s1; | |
2917 Persistent<Object> g2s2; | |
2918 Persistent<Object> g2c1; | |
2919 | |
2920 WeakCallCounter counter(1234); | |
2921 | |
2922 { | |
2923 HandleScope scope(iso); | |
2924 g1s1 = Persistent<Object>::New(iso, Object::New()); | |
2925 g1s2 = Persistent<Object>::New(iso, Object::New()); | |
2926 g1c1 = Persistent<Object>::New(iso, Object::New()); | |
2927 g1s1.MakeWeak(iso, &counter, &WeakPointerCallback); | |
2928 g1s2.MakeWeak(iso, &counter, &WeakPointerCallback); | |
2929 g1c1.MakeWeak(iso, &counter, &WeakPointerCallback); | |
2930 | |
2931 g2s1 = Persistent<Object>::New(iso, Object::New()); | |
2932 g2s2 = Persistent<Object>::New(iso, Object::New()); | |
2933 g2c1 = Persistent<Object>::New(iso, Object::New()); | |
2934 g2s1.MakeWeak(iso, &counter, &WeakPointerCallback); | |
2935 g2s2.MakeWeak(iso, &counter, &WeakPointerCallback); | |
2936 g2c1.MakeWeak(iso, &counter, &WeakPointerCallback); | |
2937 } | |
2938 | |
2939 Persistent<Object> root = Persistent<Object>::New(iso, g1s1); // make a root. | |
2940 | |
2941 // Connect group 1 and 2, make a cycle. | |
2942 CHECK(g1s2->Set(0, Handle<Object>(*g2s2))); | |
2943 CHECK(g2s1->Set(0, Handle<Object>(*g1s1))); | |
2944 | |
2945 { | |
2946 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; | |
2947 Persistent<Value> g1_children[] = { g1c1 }; | |
2948 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; | |
2949 Persistent<Value> g2_children[] = { g2c1 }; | |
2950 V8::AddObjectGroup(g1_objects, 2); | |
2951 V8::AddImplicitReferences(g1s1, g1_children, 1); | |
2952 V8::AddObjectGroup(g2_objects, 2); | |
2953 V8::AddImplicitReferences(g2s1, g2_children, 1); | |
2954 } | |
2955 // Do a single full GC, ensure incremental marking is stopped. | |
2956 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | |
2957 | |
2958 // All object should be alive. | |
2959 CHECK_EQ(0, counter.NumberOfWeakCalls()); | |
2960 | |
2961 // Weaken the root. | |
2962 root.MakeWeak(iso, &counter, &WeakPointerCallback); | |
2963 // But make children strong roots---all the objects (except for children) | |
2964 // should be collectable now. | |
2965 g1c1.ClearWeak(iso); | |
2966 g2c1.ClearWeak(iso); | |
2967 | |
2968 // Groups are deleted, rebuild groups. | |
2969 { | |
2970 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; | |
2971 Persistent<Value> g1_children[] = { g1c1 }; | |
2972 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; | |
2973 Persistent<Value> g2_children[] = { g2c1 }; | |
2974 V8::AddObjectGroup(g1_objects, 2); | |
2975 V8::AddImplicitReferences(g1s1, g1_children, 1); | |
2976 V8::AddObjectGroup(g2_objects, 2); | |
2977 V8::AddImplicitReferences(g2s1, g2_children, 1); | |
2978 } | |
2979 | |
2980 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | |
2981 | |
2982 // All objects should be gone. 5 global handles in total. | |
2983 CHECK_EQ(5, counter.NumberOfWeakCalls()); | |
2984 | |
2985 // And now make children weak again and collect them. | |
2986 g1c1.MakeWeak(iso, &counter, &WeakPointerCallback); | |
2987 g2c1.MakeWeak(iso, &counter, &WeakPointerCallback); | |
2988 | |
2989 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | |
2990 CHECK_EQ(7, counter.NumberOfWeakCalls()); | |
2991 } | |
2992 | |
2993 | |
2994 THREADED_TEST(ApiObjectGroups) { | 2908 THREADED_TEST(ApiObjectGroups) { |
2995 LocalContext env; | 2909 LocalContext env; |
2996 v8::Isolate* iso = env->GetIsolate(); | 2910 v8::Isolate* iso = env->GetIsolate(); |
2997 HandleScope scope(iso); | 2911 HandleScope scope(iso); |
2998 | 2912 |
2999 Persistent<Object> g1s1; | 2913 Persistent<Object> g1s1; |
3000 Persistent<Object> g1s2; | 2914 Persistent<Object> g1s2; |
3001 Persistent<Object> g1c1; | 2915 Persistent<Object> g1c1; |
3002 Persistent<Object> g2s1; | 2916 Persistent<Object> g2s1; |
3003 Persistent<Object> g2s2; | 2917 Persistent<Object> g2s2; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3072 | 2986 |
3073 // And now make children weak again and collect them. | 2987 // And now make children weak again and collect them. |
3074 g1c1.MakeWeak(iso, &counter, &WeakPointerCallback); | 2988 g1c1.MakeWeak(iso, &counter, &WeakPointerCallback); |
3075 g2c1.MakeWeak(iso, &counter, &WeakPointerCallback); | 2989 g2c1.MakeWeak(iso, &counter, &WeakPointerCallback); |
3076 | 2990 |
3077 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 2991 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
3078 CHECK_EQ(7, counter.NumberOfWeakCalls()); | 2992 CHECK_EQ(7, counter.NumberOfWeakCalls()); |
3079 } | 2993 } |
3080 | 2994 |
3081 | 2995 |
3082 THREADED_TEST(OldApiObjectGroupsCycle) { | |
3083 LocalContext env; | |
3084 v8::Isolate* iso = env->GetIsolate(); | |
3085 HandleScope scope(iso); | |
3086 | |
3087 WeakCallCounter counter(1234); | |
3088 | |
3089 Persistent<Object> g1s1; | |
3090 Persistent<Object> g1s2; | |
3091 Persistent<Object> g2s1; | |
3092 Persistent<Object> g2s2; | |
3093 Persistent<Object> g3s1; | |
3094 Persistent<Object> g3s2; | |
3095 Persistent<Object> g4s1; | |
3096 Persistent<Object> g4s2; | |
3097 | |
3098 { | |
3099 HandleScope scope(iso); | |
3100 g1s1 = Persistent<Object>::New(iso, Object::New()); | |
3101 g1s2 = Persistent<Object>::New(iso, Object::New()); | |
3102 g1s1.MakeWeak(iso, &counter, &WeakPointerCallback); | |
3103 g1s2.MakeWeak(iso, &counter, &WeakPointerCallback); | |
3104 CHECK(g1s1.IsWeak(iso)); | |
3105 CHECK(g1s2.IsWeak(iso)); | |
3106 | |
3107 g2s1 = Persistent<Object>::New(iso, Object::New()); | |
3108 g2s2 = Persistent<Object>::New(iso, Object::New()); | |
3109 g2s1.MakeWeak(iso, &counter, &WeakPointerCallback); | |
3110 g2s2.MakeWeak(iso, &counter, &WeakPointerCallback); | |
3111 CHECK(g2s1.IsWeak(iso)); | |
3112 CHECK(g2s2.IsWeak(iso)); | |
3113 | |
3114 g3s1 = Persistent<Object>::New(iso, Object::New()); | |
3115 g3s2 = Persistent<Object>::New(iso, Object::New()); | |
3116 g3s1.MakeWeak(iso, &counter, &WeakPointerCallback); | |
3117 g3s2.MakeWeak(iso, &counter, &WeakPointerCallback); | |
3118 CHECK(g3s1.IsWeak(iso)); | |
3119 CHECK(g3s2.IsWeak(iso)); | |
3120 | |
3121 g4s1 = Persistent<Object>::New(iso, Object::New()); | |
3122 g4s2 = Persistent<Object>::New(iso, Object::New()); | |
3123 g4s1.MakeWeak(iso, &counter, &WeakPointerCallback); | |
3124 g4s2.MakeWeak(iso, &counter, &WeakPointerCallback); | |
3125 CHECK(g4s1.IsWeak(iso)); | |
3126 CHECK(g4s2.IsWeak(iso)); | |
3127 } | |
3128 | |
3129 Persistent<Object> root = Persistent<Object>::New(iso, g1s1); // make a root. | |
3130 | |
3131 // Connect groups. We're building the following cycle: | |
3132 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other | |
3133 // groups. | |
3134 { | |
3135 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; | |
3136 Persistent<Value> g1_children[] = { g2s1 }; | |
3137 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; | |
3138 Persistent<Value> g2_children[] = { g3s1 }; | |
3139 Persistent<Value> g3_objects[] = { g3s1, g3s2 }; | |
3140 Persistent<Value> g3_children[] = { g4s1 }; | |
3141 Persistent<Value> g4_objects[] = { g4s1, g4s2 }; | |
3142 Persistent<Value> g4_children[] = { g1s1 }; | |
3143 V8::AddObjectGroup(g1_objects, 2); | |
3144 V8::AddImplicitReferences(g1s1, g1_children, 1); | |
3145 V8::AddObjectGroup(g2_objects, 2); | |
3146 V8::AddImplicitReferences(g2s1, g2_children, 1); | |
3147 V8::AddObjectGroup(g3_objects, 2); | |
3148 V8::AddImplicitReferences(g3s1, g3_children, 1); | |
3149 V8::AddObjectGroup(iso, g4_objects, 2); | |
3150 V8::AddImplicitReferences(g4s1, g4_children, 1); | |
3151 } | |
3152 // Do a single full GC | |
3153 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | |
3154 | |
3155 // All object should be alive. | |
3156 CHECK_EQ(0, counter.NumberOfWeakCalls()); | |
3157 | |
3158 // Weaken the root. | |
3159 root.MakeWeak(iso, &counter, &WeakPointerCallback); | |
3160 | |
3161 // Groups are deleted, rebuild groups. | |
3162 { | |
3163 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; | |
3164 Persistent<Value> g1_children[] = { g2s1 }; | |
3165 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; | |
3166 Persistent<Value> g2_children[] = { g3s1 }; | |
3167 Persistent<Value> g3_objects[] = { g3s1, g3s2 }; | |
3168 Persistent<Value> g3_children[] = { g4s1 }; | |
3169 Persistent<Value> g4_objects[] = { g4s1, g4s2 }; | |
3170 Persistent<Value> g4_children[] = { g1s1 }; | |
3171 V8::AddObjectGroup(g1_objects, 2); | |
3172 V8::AddImplicitReferences(g1s1, g1_children, 1); | |
3173 V8::AddObjectGroup(g2_objects, 2); | |
3174 V8::AddImplicitReferences(g2s1, g2_children, 1); | |
3175 V8::AddObjectGroup(g3_objects, 2); | |
3176 V8::AddImplicitReferences(g3s1, g3_children, 1); | |
3177 V8::AddObjectGroup(g4_objects, 2); | |
3178 V8::AddImplicitReferences(g4s1, g4_children, 1); | |
3179 } | |
3180 | |
3181 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | |
3182 | |
3183 // All objects should be gone. 9 global handles in total. | |
3184 CHECK_EQ(9, counter.NumberOfWeakCalls()); | |
3185 } | |
3186 | |
3187 | |
3188 THREADED_TEST(ApiObjectGroupsCycle) { | 2996 THREADED_TEST(ApiObjectGroupsCycle) { |
3189 LocalContext env; | 2997 LocalContext env; |
3190 v8::Isolate* iso = env->GetIsolate(); | 2998 v8::Isolate* iso = env->GetIsolate(); |
3191 HandleScope scope(iso); | 2999 HandleScope scope(iso); |
3192 | 3000 |
3193 WeakCallCounter counter(1234); | 3001 WeakCallCounter counter(1234); |
3194 | 3002 |
3195 Persistent<Object> g1s1; | 3003 Persistent<Object> g1s1; |
3196 Persistent<Object> g1s2; | 3004 Persistent<Object> g1s2; |
3197 Persistent<Object> g2s1; | 3005 Persistent<Object> g2s1; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3288 | 3096 |
3289 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 3097 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
3290 | 3098 |
3291 // All objects should be gone. 9 global handles in total. | 3099 // All objects should be gone. 9 global handles in total. |
3292 CHECK_EQ(9, counter.NumberOfWeakCalls()); | 3100 CHECK_EQ(9, counter.NumberOfWeakCalls()); |
3293 } | 3101 } |
3294 | 3102 |
3295 | 3103 |
3296 // TODO(mstarzinger): This should be a THREADED_TEST but causes failures | 3104 // TODO(mstarzinger): This should be a THREADED_TEST but causes failures |
3297 // on the buildbots, so was made non-threaded for the time being. | 3105 // on the buildbots, so was made non-threaded for the time being. |
3298 TEST(OldApiObjectGroupsCycleForScavenger) { | |
3299 i::FLAG_stress_compaction = false; | |
3300 i::FLAG_gc_global = false; | |
3301 LocalContext env; | |
3302 v8::Isolate* iso = env->GetIsolate(); | |
3303 HandleScope scope(iso); | |
3304 | |
3305 WeakCallCounter counter(1234); | |
3306 | |
3307 Persistent<Object> g1s1; | |
3308 Persistent<Object> g1s2; | |
3309 Persistent<Object> g2s1; | |
3310 Persistent<Object> g2s2; | |
3311 Persistent<Object> g3s1; | |
3312 Persistent<Object> g3s2; | |
3313 | |
3314 { | |
3315 HandleScope scope(iso); | |
3316 g1s1 = Persistent<Object>::New(iso, Object::New()); | |
3317 g1s2 = Persistent<Object>::New(iso, Object::New()); | |
3318 g1s1.MakeWeak(iso, &counter, &WeakPointerCallback); | |
3319 g1s2.MakeWeak(iso, &counter, &WeakPointerCallback); | |
3320 | |
3321 g2s1 = Persistent<Object>::New(iso, Object::New()); | |
3322 g2s2 = Persistent<Object>::New(iso, Object::New()); | |
3323 g2s1.MakeWeak(iso, &counter, &WeakPointerCallback); | |
3324 g2s2.MakeWeak(iso, &counter, &WeakPointerCallback); | |
3325 | |
3326 g3s1 = Persistent<Object>::New(iso, Object::New()); | |
3327 g3s2 = Persistent<Object>::New(iso, Object::New()); | |
3328 g3s1.MakeWeak(iso, &counter, &WeakPointerCallback); | |
3329 g3s2.MakeWeak(iso, &counter, &WeakPointerCallback); | |
3330 } | |
3331 | |
3332 // Make a root. | |
3333 Persistent<Object> root = Persistent<Object>::New(iso, g1s1); | |
3334 root.MarkPartiallyDependent(iso); | |
3335 | |
3336 // Connect groups. We're building the following cycle: | |
3337 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other | |
3338 // groups. | |
3339 { | |
3340 g1s1.MarkPartiallyDependent(iso); | |
3341 g1s2.MarkPartiallyDependent(iso); | |
3342 g2s1.MarkPartiallyDependent(iso); | |
3343 g2s2.MarkPartiallyDependent(iso); | |
3344 g3s1.MarkPartiallyDependent(iso); | |
3345 g3s2.MarkPartiallyDependent(iso); | |
3346 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; | |
3347 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; | |
3348 Persistent<Value> g3_objects[] = { g3s1, g3s2 }; | |
3349 V8::AddObjectGroup(g1_objects, 2); | |
3350 g1s1->Set(v8_str("x"), Handle<Object>(*g2s1)); | |
3351 V8::AddObjectGroup(g2_objects, 2); | |
3352 g2s1->Set(v8_str("x"), Handle<Object>(*g3s1)); | |
3353 V8::AddObjectGroup(g3_objects, 2); | |
3354 g3s1->Set(v8_str("x"), Handle<Object>(*g1s1)); | |
3355 } | |
3356 | |
3357 HEAP->CollectGarbage(i::NEW_SPACE); | |
3358 | |
3359 // All objects should be alive. | |
3360 CHECK_EQ(0, counter.NumberOfWeakCalls()); | |
3361 | |
3362 // Weaken the root. | |
3363 root.MakeWeak(iso, &counter, &WeakPointerCallback); | |
3364 root.MarkPartiallyDependent(iso); | |
3365 | |
3366 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
3367 // Groups are deleted, rebuild groups. | |
3368 { | |
3369 g1s1.MarkPartiallyDependent(isolate); | |
3370 g1s2.MarkPartiallyDependent(isolate); | |
3371 g2s1.MarkPartiallyDependent(isolate); | |
3372 g2s2.MarkPartiallyDependent(isolate); | |
3373 g3s1.MarkPartiallyDependent(isolate); | |
3374 g3s2.MarkPartiallyDependent(isolate); | |
3375 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; | |
3376 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; | |
3377 Persistent<Value> g3_objects[] = { g3s1, g3s2 }; | |
3378 V8::AddObjectGroup(g1_objects, 2); | |
3379 g1s1->Set(v8_str("x"), Handle<Object>(*g2s1)); | |
3380 V8::AddObjectGroup(g2_objects, 2); | |
3381 g2s1->Set(v8_str("x"), Handle<Object>(*g3s1)); | |
3382 V8::AddObjectGroup(g3_objects, 2); | |
3383 g3s1->Set(v8_str("x"), Handle<Object>(*g1s1)); | |
3384 } | |
3385 | |
3386 HEAP->CollectGarbage(i::NEW_SPACE); | |
3387 | |
3388 // All objects should be gone. 7 global handles in total. | |
3389 CHECK_EQ(7, counter.NumberOfWeakCalls()); | |
3390 } | |
3391 | |
3392 | |
3393 // TODO(mstarzinger): This should be a THREADED_TEST but causes failures | |
3394 // on the buildbots, so was made non-threaded for the time being. | |
3395 TEST(ApiObjectGroupsCycleForScavenger) { | 3106 TEST(ApiObjectGroupsCycleForScavenger) { |
3396 i::FLAG_stress_compaction = false; | 3107 i::FLAG_stress_compaction = false; |
3397 i::FLAG_gc_global = false; | 3108 i::FLAG_gc_global = false; |
3398 LocalContext env; | 3109 LocalContext env; |
3399 v8::Isolate* iso = env->GetIsolate(); | 3110 v8::Isolate* iso = env->GetIsolate(); |
3400 HandleScope scope(iso); | 3111 HandleScope scope(iso); |
3401 | 3112 |
3402 WeakCallCounter counter(1234); | 3113 WeakCallCounter counter(1234); |
3403 | 3114 |
3404 Persistent<Object> g1s1; | 3115 Persistent<Object> g1s1; |
(...skipping 15937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19342 i::Semaphore* sem_; | 19053 i::Semaphore* sem_; |
19343 volatile int sem_value_; | 19054 volatile int sem_value_; |
19344 }; | 19055 }; |
19345 | 19056 |
19346 | 19057 |
19347 THREADED_TEST(SemaphoreInterruption) { | 19058 THREADED_TEST(SemaphoreInterruption) { |
19348 ThreadInterruptTest().RunTest(); | 19059 ThreadInterruptTest().RunTest(); |
19349 } | 19060 } |
19350 | 19061 |
19351 #endif // WIN32 | 19062 #endif // WIN32 |
OLD | NEW |