Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: test/cctest/test-api.cc

Issue 14294009: Revert the commits adding new GC-related APIs. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: remove test Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/mark-compact.cc ('k') | test/cctest/test-global-handles.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 using ::v8::Message; 60 using ::v8::Message;
61 using ::v8::MessageCallback; 61 using ::v8::MessageCallback;
62 using ::v8::Object; 62 using ::v8::Object;
63 using ::v8::ObjectTemplate; 63 using ::v8::ObjectTemplate;
64 using ::v8::Persistent; 64 using ::v8::Persistent;
65 using ::v8::Script; 65 using ::v8::Script;
66 using ::v8::StackTrace; 66 using ::v8::StackTrace;
67 using ::v8::String; 67 using ::v8::String;
68 using ::v8::TryCatch; 68 using ::v8::TryCatch;
69 using ::v8::Undefined; 69 using ::v8::Undefined;
70 using ::v8::UniqueId;
71 using ::v8::V8; 70 using ::v8::V8;
72 using ::v8::Value; 71 using ::v8::Value;
73 72
74 73
75 static void ExpectString(const char* code, const char* expected) { 74 static void ExpectString(const char* code, const char* expected) {
76 Local<Value> result = CompileRun(code); 75 Local<Value> result = CompileRun(code);
77 CHECK(result->IsString()); 76 CHECK(result->IsString());
78 String::AsciiValue ascii(result); 77 String::AsciiValue ascii(result);
79 CHECK_EQ(expected, *ascii); 78 CHECK_EQ(expected, *ascii);
80 } 79 }
(...skipping 2358 matching lines...) Expand 10 before | Expand all | Expand 10 after
2439 static void WeakPointerCallback(v8::Isolate* isolate, 2438 static void WeakPointerCallback(v8::Isolate* isolate,
2440 Persistent<Value> handle, 2439 Persistent<Value> handle,
2441 void* id) { 2440 void* id) {
2442 WeakCallCounter* counter = reinterpret_cast<WeakCallCounter*>(id); 2441 WeakCallCounter* counter = reinterpret_cast<WeakCallCounter*>(id);
2443 CHECK_EQ(1234, counter->id()); 2442 CHECK_EQ(1234, counter->id());
2444 counter->increment(); 2443 counter->increment();
2445 handle.Dispose(isolate); 2444 handle.Dispose(isolate);
2446 } 2445 }
2447 2446
2448 2447
2449 THREADED_TEST(OldApiObjectGroups) { 2448 THREADED_TEST(ApiObjectGroups) {
2450 LocalContext env; 2449 LocalContext env;
2451 v8::Isolate* iso = env->GetIsolate(); 2450 v8::Isolate* iso = env->GetIsolate();
2452 HandleScope scope(iso); 2451 HandleScope scope(iso);
2453 2452
2454 Persistent<Object> g1s1; 2453 Persistent<Object> g1s1;
2455 Persistent<Object> g1s2; 2454 Persistent<Object> g1s2;
2456 Persistent<Object> g1c1; 2455 Persistent<Object> g1c1;
2457 Persistent<Object> g2s1; 2456 Persistent<Object> g2s1;
2458 Persistent<Object> g2s2; 2457 Persistent<Object> g2s2;
2459 Persistent<Object> g2c1; 2458 Persistent<Object> g2c1;
(...skipping 24 matching lines...) Expand all
2484 CHECK(g2s1->Set(0, g1s1)); 2483 CHECK(g2s1->Set(0, g1s1));
2485 2484
2486 { 2485 {
2487 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; 2486 Persistent<Value> g1_objects[] = { g1s1, g1s2 };
2488 Persistent<Value> g1_children[] = { g1c1 }; 2487 Persistent<Value> g1_children[] = { g1c1 };
2489 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; 2488 Persistent<Value> g2_objects[] = { g2s1, g2s2 };
2490 Persistent<Value> g2_children[] = { g2c1 }; 2489 Persistent<Value> g2_children[] = { g2c1 };
2491 V8::AddObjectGroup(g1_objects, 2); 2490 V8::AddObjectGroup(g1_objects, 2);
2492 V8::AddImplicitReferences(g1s1, g1_children, 1); 2491 V8::AddImplicitReferences(g1s1, g1_children, 1);
2493 V8::AddObjectGroup(g2_objects, 2); 2492 V8::AddObjectGroup(g2_objects, 2);
2494 V8::AddImplicitReferences(g2s1, g2_children, 1); 2493 V8::AddImplicitReferences(g2s2, g2_children, 1);
2495 } 2494 }
2496 // Do a single full GC, ensure incremental marking is stopped. 2495 // Do a single full GC, ensure incremental marking is stopped.
2497 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 2496 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
2498 2497
2499 // All object should be alive. 2498 // All object should be alive.
2500 CHECK_EQ(0, counter.NumberOfWeakCalls()); 2499 CHECK_EQ(0, counter.NumberOfWeakCalls());
2501 2500
2502 // Weaken the root. 2501 // Weaken the root.
2503 root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2502 root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2504 // But make children strong roots---all the objects (except for children) 2503 // But make children strong roots---all the objects (except for children)
2505 // should be collectable now. 2504 // should be collectable now.
2506 g1c1.ClearWeak(iso); 2505 g1c1.ClearWeak(iso);
2507 g2c1.ClearWeak(iso); 2506 g2c1.ClearWeak(iso);
2508 2507
2509 // Groups are deleted, rebuild groups. 2508 // Groups are deleted, rebuild groups.
2510 { 2509 {
2511 Persistent<Value> g1_objects[] = { g1s1, g1s2 }; 2510 Persistent<Value> g1_objects[] = { g1s1, g1s2 };
2512 Persistent<Value> g1_children[] = { g1c1 }; 2511 Persistent<Value> g1_children[] = { g1c1 };
2513 Persistent<Value> g2_objects[] = { g2s1, g2s2 }; 2512 Persistent<Value> g2_objects[] = { g2s1, g2s2 };
2514 Persistent<Value> g2_children[] = { g2c1 }; 2513 Persistent<Value> g2_children[] = { g2c1 };
2515 V8::AddObjectGroup(g1_objects, 2); 2514 V8::AddObjectGroup(g1_objects, 2);
2516 V8::AddImplicitReferences(g1s1, g1_children, 1); 2515 V8::AddImplicitReferences(g1s1, g1_children, 1);
2517 V8::AddObjectGroup(g2_objects, 2); 2516 V8::AddObjectGroup(g2_objects, 2);
2518 V8::AddImplicitReferences(g2s1, g2_children, 1); 2517 V8::AddImplicitReferences(g2s2, g2_children, 1);
2519 } 2518 }
2520 2519
2521 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 2520 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
2522 2521
2523 // All objects should be gone. 5 global handles in total. 2522 // All objects should be gone. 5 global handles in total.
2524 CHECK_EQ(5, counter.NumberOfWeakCalls()); 2523 CHECK_EQ(5, counter.NumberOfWeakCalls());
2525 2524
2526 // And now make children weak again and collect them. 2525 // And now make children weak again and collect them.
2527 g1c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2526 g1c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2528 g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2527 g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2529 2528
2530 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 2529 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
2531 CHECK_EQ(7, counter.NumberOfWeakCalls()); 2530 CHECK_EQ(7, counter.NumberOfWeakCalls());
2532 } 2531 }
2533 2532
2534 2533
2535 THREADED_TEST(ApiObjectGroups) { 2534 THREADED_TEST(ApiObjectGroupsCycle) {
2536 LocalContext env; 2535 LocalContext env;
2537 v8::Isolate* iso = env->GetIsolate(); 2536 v8::Isolate* iso = env->GetIsolate();
2538 HandleScope scope(iso); 2537 HandleScope scope(iso);
2539
2540 Persistent<Object> g1s1;
2541 Persistent<Object> g1s2;
2542 Persistent<Object> g1c1;
2543 Persistent<Object> g2s1;
2544 Persistent<Object> g2s2;
2545 Persistent<Object> g2c1;
2546
2547 WeakCallCounter counter(1234);
2548
2549 {
2550 HandleScope scope(iso);
2551 g1s1 = Persistent<Object>::New(iso, Object::New());
2552 g1s2 = Persistent<Object>::New(iso, Object::New());
2553 g1c1 = Persistent<Object>::New(iso, Object::New());
2554 g1s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2555 g1s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2556 g1c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2557
2558 g2s1 = Persistent<Object>::New(iso, Object::New());
2559 g2s2 = Persistent<Object>::New(iso, Object::New());
2560 g2c1 = Persistent<Object>::New(iso, Object::New());
2561 g2s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2562 g2s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2563 g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2564 }
2565
2566 Persistent<Object> root = Persistent<Object>::New(iso, g1s1); // make a root.
2567
2568 // Connect group 1 and 2, make a cycle.
2569 CHECK(g1s2->Set(0, g2s2));
2570 CHECK(g2s1->Set(0, g1s1));
2571
2572 {
2573 UniqueId id1(reinterpret_cast<intptr_t>(*g1s1));
2574 UniqueId id2(reinterpret_cast<intptr_t>(*g2s2));
2575 V8::SetObjectGroupId(iso, g1s1, id1);
2576 V8::SetObjectGroupId(iso, g1s2, id1);
2577 V8::SetObjectGroupRepresentative(iso, id1, g1s1);
2578 V8::AddImplicitReference(iso, id1, g1c1);
2579 V8::SetObjectGroupId(iso, g2s1, id2);
2580 V8::SetObjectGroupId(iso, g2s2, id2);
2581 V8::SetObjectGroupRepresentative(iso, id2, g2s1);
2582 V8::AddImplicitReference(iso, id2, g2c1);
2583 }
2584 // Do a single full GC, ensure incremental marking is stopped.
2585 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>(
2586 iso)->heap();
2587 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
2588
2589 // All object should be alive.
2590 CHECK_EQ(0, counter.NumberOfWeakCalls());
2591
2592 // Weaken the root.
2593 root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2594 // But make children strong roots---all the objects (except for children)
2595 // should be collectable now.
2596 g1c1.ClearWeak(iso);
2597 g2c1.ClearWeak(iso);
2598
2599 // Groups are deleted, rebuild groups.
2600 {
2601 UniqueId id1(reinterpret_cast<intptr_t>(*g1s1));
2602 UniqueId id2(reinterpret_cast<intptr_t>(*g2s2));
2603 V8::SetObjectGroupId(iso, g1s1, id1);
2604 V8::SetObjectGroupId(iso, g1s2, id1);
2605 V8::SetObjectGroupRepresentative(iso, id1, g1s1);
2606 V8::AddImplicitReference(iso, id1, g1c1);
2607 V8::SetObjectGroupId(iso, g2s1, id2);
2608 V8::SetObjectGroupId(iso, g2s2, id2);
2609 V8::SetObjectGroupRepresentative(iso, id2, g2s1);
2610 V8::AddImplicitReference(iso, id2, g2c1);
2611 }
2612
2613 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
2614
2615 // All objects should be gone. 5 global handles in total.
2616 CHECK_EQ(5, counter.NumberOfWeakCalls());
2617
2618 // And now make children weak again and collect them.
2619 g1c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2620 g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2621
2622 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
2623 CHECK_EQ(7, counter.NumberOfWeakCalls());
2624 }
2625
2626
2627 THREADED_TEST(OldApiObjectGroupsCycle) {
2628 LocalContext env;
2629 v8::Isolate* iso = env->GetIsolate();
2630 HandleScope scope(iso);
2631 2538
2632 WeakCallCounter counter(1234); 2539 WeakCallCounter counter(1234);
2633 2540
2634 Persistent<Object> g1s1; 2541 Persistent<Object> g1s1;
2635 Persistent<Object> g1s2; 2542 Persistent<Object> g1s2;
2636 Persistent<Object> g2s1; 2543 Persistent<Object> g2s1;
2637 Persistent<Object> g2s2; 2544 Persistent<Object> g2s2;
2638 Persistent<Object> g3s1; 2545 Persistent<Object> g3s1;
2639 Persistent<Object> g3s2; 2546 Persistent<Object> g3s2;
2640 Persistent<Object> g4s1; 2547 Persistent<Object> g4s1;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
2723 V8::AddImplicitReferences(g4s1, g4_children, 1); 2630 V8::AddImplicitReferences(g4s1, g4_children, 1);
2724 } 2631 }
2725 2632
2726 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 2633 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
2727 2634
2728 // All objects should be gone. 9 global handles in total. 2635 // All objects should be gone. 9 global handles in total.
2729 CHECK_EQ(9, counter.NumberOfWeakCalls()); 2636 CHECK_EQ(9, counter.NumberOfWeakCalls());
2730 } 2637 }
2731 2638
2732 2639
2733 THREADED_TEST(ApiObjectGroupsCycle) {
2734 LocalContext env;
2735 v8::Isolate* iso = env->GetIsolate();
2736 HandleScope scope(iso);
2737
2738 WeakCallCounter counter(1234);
2739
2740 Persistent<Object> g1s1;
2741 Persistent<Object> g1s2;
2742 Persistent<Object> g2s1;
2743 Persistent<Object> g2s2;
2744 Persistent<Object> g3s1;
2745 Persistent<Object> g3s2;
2746 Persistent<Object> g4s1;
2747 Persistent<Object> g4s2;
2748
2749 {
2750 HandleScope scope(iso);
2751 g1s1 = Persistent<Object>::New(iso, Object::New());
2752 g1s2 = Persistent<Object>::New(iso, Object::New());
2753 g1s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2754 g1s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2755 CHECK(g1s1.IsWeak(iso));
2756 CHECK(g1s2.IsWeak(iso));
2757
2758 g2s1 = Persistent<Object>::New(iso, Object::New());
2759 g2s2 = Persistent<Object>::New(iso, Object::New());
2760 g2s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2761 g2s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2762 CHECK(g2s1.IsWeak(iso));
2763 CHECK(g2s2.IsWeak(iso));
2764
2765 g3s1 = Persistent<Object>::New(iso, Object::New());
2766 g3s2 = Persistent<Object>::New(iso, Object::New());
2767 g3s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2768 g3s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2769 CHECK(g3s1.IsWeak(iso));
2770 CHECK(g3s2.IsWeak(iso));
2771
2772 g4s1 = Persistent<Object>::New(iso, Object::New());
2773 g4s2 = Persistent<Object>::New(iso, Object::New());
2774 g4s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2775 g4s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2776 CHECK(g4s1.IsWeak(iso));
2777 CHECK(g4s2.IsWeak(iso));
2778 }
2779
2780 Persistent<Object> root = Persistent<Object>::New(iso, g1s1); // make a root.
2781
2782 // Connect groups. We're building the following cycle:
2783 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other
2784 // groups.
2785 {
2786 UniqueId id1(reinterpret_cast<intptr_t>(*g1s1));
2787 UniqueId id2(reinterpret_cast<intptr_t>(*g2s1));
2788 UniqueId id3(reinterpret_cast<intptr_t>(*g3s1));
2789 UniqueId id4(reinterpret_cast<intptr_t>(*g4s1));
2790 V8::SetObjectGroupId(iso, g1s1, id1);
2791 V8::SetObjectGroupId(iso, g1s2, id1);
2792 V8::SetObjectGroupRepresentative(iso, id1, g1s1);
2793 V8::AddImplicitReference(iso, id1, g2s1);
2794 V8::SetObjectGroupId(iso, g2s1, id2);
2795 V8::SetObjectGroupId(iso, g2s2, id2);
2796 V8::SetObjectGroupRepresentative(iso, id2, g2s1);
2797 V8::AddImplicitReference(iso, id2, g3s1);
2798 V8::SetObjectGroupId(iso, g3s1, id3);
2799 V8::SetObjectGroupId(iso, g3s2, id3);
2800 V8::SetObjectGroupRepresentative(iso, id3, g3s1);
2801 V8::AddImplicitReference(iso, id3, g4s1);
2802 V8::SetObjectGroupId(iso, g4s1, id4);
2803 V8::SetObjectGroupId(iso, g4s2, id4);
2804 V8::SetObjectGroupRepresentative(iso, id4, g4s1);
2805 V8::AddImplicitReference(iso, id4, g1s1);
2806 }
2807 // Do a single full GC
2808 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>(
2809 iso)->heap();
2810 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
2811
2812 // All object should be alive.
2813 CHECK_EQ(0, counter.NumberOfWeakCalls());
2814
2815 // Weaken the root.
2816 root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2817
2818 // Groups are deleted, rebuild groups.
2819 {
2820 UniqueId id1(reinterpret_cast<intptr_t>(*g1s1));
2821 UniqueId id2(reinterpret_cast<intptr_t>(*g2s1));
2822 UniqueId id3(reinterpret_cast<intptr_t>(*g3s1));
2823 UniqueId id4(reinterpret_cast<intptr_t>(*g4s1));
2824 V8::SetObjectGroupId(iso, g1s1, id1);
2825 V8::SetObjectGroupId(iso, g1s2, id1);
2826 V8::SetObjectGroupRepresentative(iso, id1, g1s1);
2827 V8::AddImplicitReference(iso, id1, g2s1);
2828 V8::SetObjectGroupId(iso, g2s1, id2);
2829 V8::SetObjectGroupId(iso, g2s2, id2);
2830 V8::SetObjectGroupRepresentative(iso, id2, g2s1);
2831 V8::AddImplicitReference(iso, id2, g3s1);
2832 V8::SetObjectGroupId(iso, g3s1, id3);
2833 V8::SetObjectGroupId(iso, g3s2, id3);
2834 V8::SetObjectGroupRepresentative(iso, id3, g3s1);
2835 V8::AddImplicitReference(iso, id3, g4s1);
2836 V8::SetObjectGroupId(iso, g4s1, id4);
2837 V8::SetObjectGroupId(iso, g4s2, id4);
2838 V8::SetObjectGroupRepresentative(iso, id4, g4s1);
2839 V8::AddImplicitReference(iso, id4, g1s1);
2840 }
2841
2842 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
2843
2844 // All objects should be gone. 9 global handles in total.
2845 CHECK_EQ(9, counter.NumberOfWeakCalls());
2846 }
2847
2848
2849 // TODO(mstarzinger): This should be a THREADED_TEST but causes failures 2640 // TODO(mstarzinger): This should be a THREADED_TEST but causes failures
2850 // on the buildbots, so was made non-threaded for the time being. 2641 // on the buildbots, so was made non-threaded for the time being.
2851 TEST(OldApiObjectGroupsCycleForScavenger) { 2642 TEST(ApiObjectGroupsCycleForScavenger) {
2852 i::FLAG_stress_compaction = false; 2643 i::FLAG_stress_compaction = false;
2853 i::FLAG_gc_global = false; 2644 i::FLAG_gc_global = false;
2854 LocalContext env; 2645 LocalContext env;
2855 v8::Isolate* iso = env->GetIsolate(); 2646 v8::Isolate* iso = env->GetIsolate();
2856 HandleScope scope(iso); 2647 HandleScope scope(iso);
2857 2648
2858 WeakCallCounter counter(1234); 2649 WeakCallCounter counter(1234);
2859 2650
2860 Persistent<Object> g1s1; 2651 Persistent<Object> g1s1;
2861 Persistent<Object> g1s2; 2652 Persistent<Object> g1s2;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
2936 g3s1->Set(v8_str("x"), g1s1); 2727 g3s1->Set(v8_str("x"), g1s1);
2937 } 2728 }
2938 2729
2939 HEAP->CollectGarbage(i::NEW_SPACE); 2730 HEAP->CollectGarbage(i::NEW_SPACE);
2940 2731
2941 // All objects should be gone. 7 global handles in total. 2732 // All objects should be gone. 7 global handles in total.
2942 CHECK_EQ(7, counter.NumberOfWeakCalls()); 2733 CHECK_EQ(7, counter.NumberOfWeakCalls());
2943 } 2734 }
2944 2735
2945 2736
2946 // TODO(mstarzinger): This should be a THREADED_TEST but causes failures
2947 // on the buildbots, so was made non-threaded for the time being.
2948 TEST(ApiObjectGroupsCycleForScavenger) {
2949 i::FLAG_stress_compaction = false;
2950 i::FLAG_gc_global = false;
2951 LocalContext env;
2952 v8::Isolate* iso = env->GetIsolate();
2953 HandleScope scope(iso);
2954
2955 WeakCallCounter counter(1234);
2956
2957 Persistent<Object> g1s1;
2958 Persistent<Object> g1s2;
2959 Persistent<Object> g2s1;
2960 Persistent<Object> g2s2;
2961 Persistent<Object> g3s1;
2962 Persistent<Object> g3s2;
2963
2964 {
2965 HandleScope scope(iso);
2966 g1s1 = Persistent<Object>::New(iso, Object::New());
2967 g1s2 = Persistent<Object>::New(iso, Object::New());
2968 g1s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2969 g1s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2970
2971 g2s1 = Persistent<Object>::New(iso, Object::New());
2972 g2s2 = Persistent<Object>::New(iso, Object::New());
2973 g2s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2974 g2s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2975
2976 g3s1 = Persistent<Object>::New(iso, Object::New());
2977 g3s2 = Persistent<Object>::New(iso, Object::New());
2978 g3s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2979 g3s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2980 }
2981
2982 // Make a root.
2983 Persistent<Object> root = Persistent<Object>::New(iso, g1s1);
2984 root.MarkPartiallyDependent(iso);
2985
2986 // Connect groups. We're building the following cycle:
2987 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other
2988 // groups.
2989 {
2990 g1s1.MarkPartiallyDependent(iso);
2991 g1s2.MarkPartiallyDependent(iso);
2992 g2s1.MarkPartiallyDependent(iso);
2993 g2s2.MarkPartiallyDependent(iso);
2994 g3s1.MarkPartiallyDependent(iso);
2995 g3s2.MarkPartiallyDependent(iso);
2996 V8::SetObjectGroupId(iso, g1s1, UniqueId(1));
2997 V8::SetObjectGroupId(iso, g1s2, UniqueId(1));
2998 g1s1->Set(v8_str("x"), g2s1);
2999 V8::SetObjectGroupId(iso, g2s1, UniqueId(2));
3000 V8::SetObjectGroupId(iso, g2s2, UniqueId(2));
3001 g2s1->Set(v8_str("x"), g3s1);
3002 V8::SetObjectGroupId(iso, g3s1, UniqueId(3));
3003 V8::SetObjectGroupId(iso, g3s2, UniqueId(3));
3004 g3s1->Set(v8_str("x"), g1s1);
3005 }
3006
3007 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>(
3008 iso)->heap();
3009 heap->CollectGarbage(i::NEW_SPACE);
3010
3011 // All objects should be alive.
3012 CHECK_EQ(0, counter.NumberOfWeakCalls());
3013
3014 // Weaken the root.
3015 root.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
3016 root.MarkPartiallyDependent(iso);
3017
3018 v8::Isolate* isolate = v8::Isolate::GetCurrent();
3019 // Groups are deleted, rebuild groups.
3020 {
3021 g1s1.MarkPartiallyDependent(isolate);
3022 g1s2.MarkPartiallyDependent(isolate);
3023 g2s1.MarkPartiallyDependent(isolate);
3024 g2s2.MarkPartiallyDependent(isolate);
3025 g3s1.MarkPartiallyDependent(isolate);
3026 g3s2.MarkPartiallyDependent(isolate);
3027 V8::SetObjectGroupId(iso, g1s1, UniqueId(1));
3028 V8::SetObjectGroupId(iso, g1s2, UniqueId(1));
3029 g1s1->Set(v8_str("x"), g2s1);
3030 V8::SetObjectGroupId(iso, g2s1, UniqueId(2));
3031 V8::SetObjectGroupId(iso, g2s2, UniqueId(2));
3032 g2s1->Set(v8_str("x"), g3s1);
3033 V8::SetObjectGroupId(iso, g3s1, UniqueId(3));
3034 V8::SetObjectGroupId(iso, g3s2, UniqueId(3));
3035 g3s1->Set(v8_str("x"), g1s1);
3036 }
3037
3038 heap->CollectGarbage(i::NEW_SPACE);
3039
3040 // All objects should be gone. 7 global handles in total.
3041 CHECK_EQ(7, counter.NumberOfWeakCalls());
3042 }
3043
3044
3045 THREADED_TEST(ScriptException) { 2737 THREADED_TEST(ScriptException) {
3046 LocalContext env; 2738 LocalContext env;
3047 v8::HandleScope scope(env->GetIsolate()); 2739 v8::HandleScope scope(env->GetIsolate());
3048 Local<Script> script = Script::Compile(v8_str("throw 'panama!';")); 2740 Local<Script> script = Script::Compile(v8_str("throw 'panama!';"));
3049 v8::TryCatch try_catch; 2741 v8::TryCatch try_catch;
3050 Local<Value> result = script->Run(); 2742 Local<Value> result = script->Run();
3051 CHECK(result.IsEmpty()); 2743 CHECK(result.IsEmpty());
3052 CHECK(try_catch.HasCaught()); 2744 CHECK(try_catch.HasCaught());
3053 String::AsciiValue exception_value(try_catch.Exception()); 2745 String::AsciiValue exception_value(try_catch.Exception());
3054 CHECK_EQ(*exception_value, "panama!"); 2746 CHECK_EQ(*exception_value, "panama!");
(...skipping 15647 matching lines...) Expand 10 before | Expand all | Expand 10 after
18702 i::Semaphore* sem_; 18394 i::Semaphore* sem_;
18703 volatile int sem_value_; 18395 volatile int sem_value_;
18704 }; 18396 };
18705 18397
18706 18398
18707 THREADED_TEST(SemaphoreInterruption) { 18399 THREADED_TEST(SemaphoreInterruption) {
18708 ThreadInterruptTest().RunTest(); 18400 ThreadInterruptTest().RunTest();
18709 } 18401 }
18710 18402
18711 #endif // WIN32 18403 #endif // WIN32
OLDNEW
« no previous file with comments | « src/mark-compact.cc ('k') | test/cctest/test-global-handles.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698