| 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 2619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2630 // Test that map transitions are cleared and maps are collected with | 2630 // Test that map transitions are cleared and maps are collected with |
| 2631 // incremental marking as well. | 2631 // incremental marking as well. |
| 2632 TEST(Regress1465) { | 2632 TEST(Regress1465) { |
| 2633 i::FLAG_stress_compaction = false; | 2633 i::FLAG_stress_compaction = false; |
| 2634 i::FLAG_allow_natives_syntax = true; | 2634 i::FLAG_allow_natives_syntax = true; |
| 2635 i::FLAG_trace_incremental_marking = true; | 2635 i::FLAG_trace_incremental_marking = true; |
| 2636 CcTest::InitializeVM(); | 2636 CcTest::InitializeVM(); |
| 2637 v8::HandleScope scope(CcTest::isolate()); | 2637 v8::HandleScope scope(CcTest::isolate()); |
| 2638 static const int transitions_count = 256; | 2638 static const int transitions_count = 256; |
| 2639 | 2639 |
| 2640 CompileRun("function F() {}"); |
| 2640 { | 2641 { |
| 2641 AlwaysAllocateScope always_allocate(CcTest::i_isolate()); | 2642 AlwaysAllocateScope always_allocate(CcTest::i_isolate()); |
| 2642 for (int i = 0; i < transitions_count; i++) { | 2643 for (int i = 0; i < transitions_count; i++) { |
| 2643 EmbeddedVector<char, 64> buffer; | 2644 EmbeddedVector<char, 64> buffer; |
| 2644 OS::SNPrintF(buffer, "var o = new Object; o.prop%d = %d;", i, i); | 2645 OS::SNPrintF(buffer, "var o = new F; o.prop%d = %d;", i, i); |
| 2645 CompileRun(buffer.start()); | 2646 CompileRun(buffer.start()); |
| 2646 } | 2647 } |
| 2647 CompileRun("var root = new Object;"); | 2648 CompileRun("var root = new F;"); |
| 2648 } | 2649 } |
| 2649 | 2650 |
| 2650 Handle<JSObject> root = | 2651 Handle<JSObject> root = |
| 2651 v8::Utils::OpenHandle( | 2652 v8::Utils::OpenHandle( |
| 2652 *v8::Handle<v8::Object>::Cast( | 2653 *v8::Handle<v8::Object>::Cast( |
| 2653 CcTest::global()->Get(v8_str("root")))); | 2654 CcTest::global()->Get(v8_str("root")))); |
| 2654 | 2655 |
| 2655 // Count number of live transitions before marking. | 2656 // Count number of live transitions before marking. |
| 2656 int transitions_before = CountMapTransitions(root->map()); | 2657 int transitions_before = CountMapTransitions(root->map()); |
| 2657 CompileRun("%DebugPrint(root);"); | 2658 CompileRun("%DebugPrint(root);"); |
| 2658 CHECK_EQ(transitions_count, transitions_before); | 2659 CHECK_EQ(transitions_count, transitions_before); |
| 2659 | 2660 |
| 2660 SimulateIncrementalMarking(); | 2661 SimulateIncrementalMarking(); |
| 2661 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 2662 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 2662 | 2663 |
| 2663 // Count number of live transitions after marking. Note that one transition | 2664 // Count number of live transitions after marking. Note that one transition |
| 2664 // is left, because 'o' still holds an instance of one transition target. | 2665 // is left, because 'o' still holds an instance of one transition target. |
| 2665 int transitions_after = CountMapTransitions(root->map()); | 2666 int transitions_after = CountMapTransitions(root->map()); |
| 2666 CompileRun("%DebugPrint(root);"); | 2667 CompileRun("%DebugPrint(root);"); |
| 2667 CHECK_EQ(1, transitions_after); | 2668 CHECK_EQ(1, transitions_after); |
| 2668 } | 2669 } |
| 2669 | 2670 |
| 2670 | 2671 |
| 2671 #ifdef DEBUG | 2672 #ifdef DEBUG |
| 2672 static void AddTransitions(int transitions_count) { | 2673 static void AddTransitions(int transitions_count) { |
| 2673 AlwaysAllocateScope always_allocate(CcTest::i_isolate()); | 2674 AlwaysAllocateScope always_allocate(CcTest::i_isolate()); |
| 2674 for (int i = 0; i < transitions_count; i++) { | 2675 for (int i = 0; i < transitions_count; i++) { |
| 2675 EmbeddedVector<char, 64> buffer; | 2676 EmbeddedVector<char, 64> buffer; |
| 2676 OS::SNPrintF(buffer, "var o = new Object; o.prop%d = %d;", i, i); | 2677 OS::SNPrintF(buffer, "var o = new F; o.prop%d = %d;", i, i); |
| 2677 CompileRun(buffer.start()); | 2678 CompileRun(buffer.start()); |
| 2678 } | 2679 } |
| 2679 } | 2680 } |
| 2680 | 2681 |
| 2681 | 2682 |
| 2682 static Handle<JSObject> GetByName(const char* name) { | 2683 static Handle<JSObject> GetByName(const char* name) { |
| 2683 return v8::Utils::OpenHandle( | 2684 return v8::Utils::OpenHandle( |
| 2684 *v8::Handle<v8::Object>::Cast( | 2685 *v8::Handle<v8::Object>::Cast( |
| 2685 CcTest::global()->Get(v8_str(name)))); | 2686 CcTest::global()->Get(v8_str(name)))); |
| 2686 } | 2687 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2699 object, prop_name, twenty_three, NONE, SLOPPY).Check(); | 2700 object, prop_name, twenty_three, NONE, SLOPPY).Check(); |
| 2700 } | 2701 } |
| 2701 | 2702 |
| 2702 | 2703 |
| 2703 TEST(TransitionArrayShrinksDuringAllocToZero) { | 2704 TEST(TransitionArrayShrinksDuringAllocToZero) { |
| 2704 i::FLAG_stress_compaction = false; | 2705 i::FLAG_stress_compaction = false; |
| 2705 i::FLAG_allow_natives_syntax = true; | 2706 i::FLAG_allow_natives_syntax = true; |
| 2706 CcTest::InitializeVM(); | 2707 CcTest::InitializeVM(); |
| 2707 v8::HandleScope scope(CcTest::isolate()); | 2708 v8::HandleScope scope(CcTest::isolate()); |
| 2708 static const int transitions_count = 10; | 2709 static const int transitions_count = 10; |
| 2710 CompileRun("function F() { }"); |
| 2709 AddTransitions(transitions_count); | 2711 AddTransitions(transitions_count); |
| 2710 CompileRun("var root = new Object;"); | 2712 CompileRun("var root = new F;"); |
| 2711 Handle<JSObject> root = GetByName("root"); | 2713 Handle<JSObject> root = GetByName("root"); |
| 2712 | 2714 |
| 2713 // Count number of live transitions before marking. | 2715 // Count number of live transitions before marking. |
| 2714 int transitions_before = CountMapTransitions(root->map()); | 2716 int transitions_before = CountMapTransitions(root->map()); |
| 2715 CHECK_EQ(transitions_count, transitions_before); | 2717 CHECK_EQ(transitions_count, transitions_before); |
| 2716 | 2718 |
| 2717 // Get rid of o | 2719 // Get rid of o |
| 2718 CompileRun("o = new Object;" | 2720 CompileRun("o = new F;" |
| 2719 "root = new Object"); | 2721 "root = new F"); |
| 2720 root = GetByName("root"); | 2722 root = GetByName("root"); |
| 2721 AddPropertyTo(2, root, "funny"); | 2723 AddPropertyTo(2, root, "funny"); |
| 2722 | 2724 |
| 2723 // Count number of live transitions after marking. Note that one transition | 2725 // Count number of live transitions after marking. Note that one transition |
| 2724 // is left, because 'o' still holds an instance of one transition target. | 2726 // is left, because 'o' still holds an instance of one transition target. |
| 2725 int transitions_after = CountMapTransitions( | 2727 int transitions_after = CountMapTransitions( |
| 2726 Map::cast(root->map()->GetBackPointer())); | 2728 Map::cast(root->map()->GetBackPointer())); |
| 2727 CHECK_EQ(1, transitions_after); | 2729 CHECK_EQ(1, transitions_after); |
| 2728 } | 2730 } |
| 2729 | 2731 |
| 2730 | 2732 |
| 2731 TEST(TransitionArrayShrinksDuringAllocToOne) { | 2733 TEST(TransitionArrayShrinksDuringAllocToOne) { |
| 2732 i::FLAG_stress_compaction = false; | 2734 i::FLAG_stress_compaction = false; |
| 2733 i::FLAG_allow_natives_syntax = true; | 2735 i::FLAG_allow_natives_syntax = true; |
| 2734 CcTest::InitializeVM(); | 2736 CcTest::InitializeVM(); |
| 2735 v8::HandleScope scope(CcTest::isolate()); | 2737 v8::HandleScope scope(CcTest::isolate()); |
| 2736 static const int transitions_count = 10; | 2738 static const int transitions_count = 10; |
| 2739 CompileRun("function F() {}"); |
| 2737 AddTransitions(transitions_count); | 2740 AddTransitions(transitions_count); |
| 2738 CompileRun("var root = new Object;"); | 2741 CompileRun("var root = new F;"); |
| 2739 Handle<JSObject> root = GetByName("root"); | 2742 Handle<JSObject> root = GetByName("root"); |
| 2740 | 2743 |
| 2741 // Count number of live transitions before marking. | 2744 // Count number of live transitions before marking. |
| 2742 int transitions_before = CountMapTransitions(root->map()); | 2745 int transitions_before = CountMapTransitions(root->map()); |
| 2743 CHECK_EQ(transitions_count, transitions_before); | 2746 CHECK_EQ(transitions_count, transitions_before); |
| 2744 | 2747 |
| 2745 root = GetByName("root"); | 2748 root = GetByName("root"); |
| 2746 AddPropertyTo(2, root, "funny"); | 2749 AddPropertyTo(2, root, "funny"); |
| 2747 | 2750 |
| 2748 // Count number of live transitions after marking. Note that one transition | 2751 // Count number of live transitions after marking. Note that one transition |
| 2749 // is left, because 'o' still holds an instance of one transition target. | 2752 // is left, because 'o' still holds an instance of one transition target. |
| 2750 int transitions_after = CountMapTransitions( | 2753 int transitions_after = CountMapTransitions( |
| 2751 Map::cast(root->map()->GetBackPointer())); | 2754 Map::cast(root->map()->GetBackPointer())); |
| 2752 CHECK_EQ(2, transitions_after); | 2755 CHECK_EQ(2, transitions_after); |
| 2753 } | 2756 } |
| 2754 | 2757 |
| 2755 | 2758 |
| 2756 TEST(TransitionArrayShrinksDuringAllocToOnePropertyFound) { | 2759 TEST(TransitionArrayShrinksDuringAllocToOnePropertyFound) { |
| 2757 i::FLAG_stress_compaction = false; | 2760 i::FLAG_stress_compaction = false; |
| 2758 i::FLAG_allow_natives_syntax = true; | 2761 i::FLAG_allow_natives_syntax = true; |
| 2759 CcTest::InitializeVM(); | 2762 CcTest::InitializeVM(); |
| 2760 v8::HandleScope scope(CcTest::isolate()); | 2763 v8::HandleScope scope(CcTest::isolate()); |
| 2761 static const int transitions_count = 10; | 2764 static const int transitions_count = 10; |
| 2765 CompileRun("function F() {}"); |
| 2762 AddTransitions(transitions_count); | 2766 AddTransitions(transitions_count); |
| 2763 CompileRun("var root = new Object;"); | 2767 CompileRun("var root = new F;"); |
| 2764 Handle<JSObject> root = GetByName("root"); | 2768 Handle<JSObject> root = GetByName("root"); |
| 2765 | 2769 |
| 2766 // Count number of live transitions before marking. | 2770 // Count number of live transitions before marking. |
| 2767 int transitions_before = CountMapTransitions(root->map()); | 2771 int transitions_before = CountMapTransitions(root->map()); |
| 2768 CHECK_EQ(transitions_count, transitions_before); | 2772 CHECK_EQ(transitions_count, transitions_before); |
| 2769 | 2773 |
| 2770 root = GetByName("root"); | 2774 root = GetByName("root"); |
| 2771 AddPropertyTo(0, root, "prop9"); | 2775 AddPropertyTo(0, root, "prop9"); |
| 2772 | 2776 |
| 2773 // Count number of live transitions after marking. Note that one transition | 2777 // Count number of live transitions after marking. Note that one transition |
| 2774 // is left, because 'o' still holds an instance of one transition target. | 2778 // is left, because 'o' still holds an instance of one transition target. |
| 2775 int transitions_after = CountMapTransitions( | 2779 int transitions_after = CountMapTransitions( |
| 2776 Map::cast(root->map()->GetBackPointer())); | 2780 Map::cast(root->map()->GetBackPointer())); |
| 2777 CHECK_EQ(1, transitions_after); | 2781 CHECK_EQ(1, transitions_after); |
| 2778 } | 2782 } |
| 2779 | 2783 |
| 2780 | 2784 |
| 2781 TEST(TransitionArraySimpleToFull) { | 2785 TEST(TransitionArraySimpleToFull) { |
| 2782 i::FLAG_stress_compaction = false; | 2786 i::FLAG_stress_compaction = false; |
| 2783 i::FLAG_allow_natives_syntax = true; | 2787 i::FLAG_allow_natives_syntax = true; |
| 2784 CcTest::InitializeVM(); | 2788 CcTest::InitializeVM(); |
| 2785 v8::HandleScope scope(CcTest::isolate()); | 2789 v8::HandleScope scope(CcTest::isolate()); |
| 2786 static const int transitions_count = 1; | 2790 static const int transitions_count = 1; |
| 2791 CompileRun("function F() {}"); |
| 2787 AddTransitions(transitions_count); | 2792 AddTransitions(transitions_count); |
| 2788 CompileRun("var root = new Object;"); | 2793 CompileRun("var root = new F;"); |
| 2789 Handle<JSObject> root = GetByName("root"); | 2794 Handle<JSObject> root = GetByName("root"); |
| 2790 | 2795 |
| 2791 // Count number of live transitions before marking. | 2796 // Count number of live transitions before marking. |
| 2792 int transitions_before = CountMapTransitions(root->map()); | 2797 int transitions_before = CountMapTransitions(root->map()); |
| 2793 CHECK_EQ(transitions_count, transitions_before); | 2798 CHECK_EQ(transitions_count, transitions_before); |
| 2794 | 2799 |
| 2795 CompileRun("o = new Object;" | 2800 CompileRun("o = new F;" |
| 2796 "root = new Object"); | 2801 "root = new F"); |
| 2797 root = GetByName("root"); | 2802 root = GetByName("root"); |
| 2798 ASSERT(root->map()->transitions()->IsSimpleTransition()); | 2803 ASSERT(root->map()->transitions()->IsSimpleTransition()); |
| 2799 AddPropertyTo(2, root, "happy"); | 2804 AddPropertyTo(2, root, "happy"); |
| 2800 | 2805 |
| 2801 // Count number of live transitions after marking. Note that one transition | 2806 // Count number of live transitions after marking. Note that one transition |
| 2802 // is left, because 'o' still holds an instance of one transition target. | 2807 // is left, because 'o' still holds an instance of one transition target. |
| 2803 int transitions_after = CountMapTransitions( | 2808 int transitions_after = CountMapTransitions( |
| 2804 Map::cast(root->map()->GetBackPointer())); | 2809 Map::cast(root->map()->GetBackPointer())); |
| 2805 CHECK_EQ(1, transitions_after); | 2810 CHECK_EQ(1, transitions_after); |
| 2806 } | 2811 } |
| (...skipping 1380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4187 v8::Context::Scope cscope(context); | 4192 v8::Context::Scope cscope(context); |
| 4188 | 4193 |
| 4189 v8::Local<v8::Value> result = CompileRun( | 4194 v8::Local<v8::Value> result = CompileRun( |
| 4190 "var locals = '';" | 4195 "var locals = '';" |
| 4191 "for (var i = 0; i < 512; i++) locals += 'var v' + i + '= 42;';" | 4196 "for (var i = 0; i < 512; i++) locals += 'var v' + i + '= 42;';" |
| 4192 "eval('function f() {' + locals + 'return function() { return v0; }; }');" | 4197 "eval('function f() {' + locals + 'return function() { return v0; }; }');" |
| 4193 "interrupt();" // This triggers a fake stack overflow in f. | 4198 "interrupt();" // This triggers a fake stack overflow in f. |
| 4194 "f()()"); | 4199 "f()()"); |
| 4195 CHECK_EQ(42.0, result->ToNumber()->Value()); | 4200 CHECK_EQ(42.0, result->ToNumber()->Value()); |
| 4196 } | 4201 } |
| OLD | NEW |