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 22 matching lines...) Expand all Loading... | |
33 #include "execution.h" | 33 #include "execution.h" |
34 #include "factory.h" | 34 #include "factory.h" |
35 #include "macro-assembler.h" | 35 #include "macro-assembler.h" |
36 #include "global-handles.h" | 36 #include "global-handles.h" |
37 #include "stub-cache.h" | 37 #include "stub-cache.h" |
38 #include "cctest.h" | 38 #include "cctest.h" |
39 | 39 |
40 using namespace v8::internal; | 40 using namespace v8::internal; |
41 | 41 |
42 | 42 |
43 static v8::Local<v8::Object> GetGlobal() { | |
Michael Starzinger
2013/09/23 09:24:47
Can we move that onto the CcTest class, maybe as a
| |
44 return CcTest::isolate()->GetCurrentContext()->Global(); | |
45 } | |
46 | |
47 | |
43 // Go through all incremental marking steps in one swoop. | 48 // Go through all incremental marking steps in one swoop. |
44 static void SimulateIncrementalMarking() { | 49 static void SimulateIncrementalMarking() { |
45 MarkCompactCollector* collector = CcTest::heap()->mark_compact_collector(); | 50 MarkCompactCollector* collector = CcTest::heap()->mark_compact_collector(); |
46 IncrementalMarking* marking = CcTest::heap()->incremental_marking(); | 51 IncrementalMarking* marking = CcTest::heap()->incremental_marking(); |
47 if (collector->IsConcurrentSweepingInProgress()) { | 52 if (collector->IsConcurrentSweepingInProgress()) { |
48 collector->WaitUntilSweepingCompleted(); | 53 collector->WaitUntilSweepingCompleted(); |
49 } | 54 } |
50 CHECK(marking->IsMarking() || marking->IsStopped()); | 55 CHECK(marking->IsMarking() || marking->IsStopped()); |
51 if (marking->IsStopped()) { | 56 if (marking->IsStopped()) { |
52 marking->Start(); | 57 marking->Start(); |
(...skipping 1837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1890 "f(new foo()); g();"); | 1895 "f(new foo()); g();"); |
1891 } | 1896 } |
1892 | 1897 |
1893 IncrementalMarking* marking = CcTest::heap()->incremental_marking(); | 1898 IncrementalMarking* marking = CcTest::heap()->incremental_marking(); |
1894 marking->Abort(); | 1899 marking->Abort(); |
1895 marking->Start(); | 1900 marking->Start(); |
1896 | 1901 |
1897 Handle<JSFunction> f = | 1902 Handle<JSFunction> f = |
1898 v8::Utils::OpenHandle( | 1903 v8::Utils::OpenHandle( |
1899 *v8::Handle<v8::Function>::Cast( | 1904 *v8::Handle<v8::Function>::Cast( |
1900 v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); | 1905 GetGlobal()->Get(v8_str("f")))); |
1901 | 1906 |
1902 CHECK(f->IsOptimized()); | 1907 CHECK(f->IsOptimized()); |
1903 | 1908 |
1904 while (!Marking::IsBlack(Marking::MarkBitFrom(f->code())) && | 1909 while (!Marking::IsBlack(Marking::MarkBitFrom(f->code())) && |
1905 !marking->IsStopped()) { | 1910 !marking->IsStopped()) { |
1906 // Discard any pending GC requests otherwise we will get GC when we enter | 1911 // Discard any pending GC requests otherwise we will get GC when we enter |
1907 // code below. | 1912 // code below. |
1908 marking->Step(MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); | 1913 marking->Step(MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); |
1909 } | 1914 } |
1910 | 1915 |
1911 CHECK(marking->IsMarking()); | 1916 CHECK(marking->IsMarking()); |
1912 | 1917 |
1913 { | 1918 { |
1914 v8::HandleScope scope(CcTest::isolate()); | 1919 v8::HandleScope scope(CcTest::isolate()); |
1915 v8::Handle<v8::Object> global = v8::Context::GetCurrent()->Global(); | 1920 v8::Handle<v8::Object> global = GetGlobal(); |
1916 v8::Handle<v8::Function> g = | 1921 v8::Handle<v8::Function> g = |
1917 v8::Handle<v8::Function>::Cast(global->Get(v8_str("g"))); | 1922 v8::Handle<v8::Function>::Cast(global->Get(v8_str("g"))); |
1918 g->Call(global, 0, NULL); | 1923 g->Call(global, 0, NULL); |
1919 } | 1924 } |
1920 | 1925 |
1921 CcTest::heap()->incremental_marking()->set_should_hurry(true); | 1926 CcTest::heap()->incremental_marking()->set_should_hurry(true); |
1922 CcTest::heap()->CollectGarbage(OLD_POINTER_SPACE); | 1927 CcTest::heap()->CollectGarbage(OLD_POINTER_SPACE); |
1923 } | 1928 } |
1924 | 1929 |
1925 | 1930 |
1926 TEST(PrototypeTransitionClearing) { | 1931 TEST(PrototypeTransitionClearing) { |
1927 CcTest::InitializeVM(); | 1932 CcTest::InitializeVM(); |
1928 Isolate* isolate = CcTest::i_isolate(); | 1933 Isolate* isolate = CcTest::i_isolate(); |
1929 Factory* factory = isolate->factory(); | 1934 Factory* factory = isolate->factory(); |
1930 v8::HandleScope scope(CcTest::isolate()); | 1935 v8::HandleScope scope(CcTest::isolate()); |
1931 | 1936 |
1932 CompileRun( | 1937 CompileRun( |
1933 "var base = {};" | 1938 "var base = {};" |
1934 "var live = [];" | 1939 "var live = [];" |
1935 "for (var i = 0; i < 10; i++) {" | 1940 "for (var i = 0; i < 10; i++) {" |
1936 " var object = {};" | 1941 " var object = {};" |
1937 " var prototype = {};" | 1942 " var prototype = {};" |
1938 " object.__proto__ = prototype;" | 1943 " object.__proto__ = prototype;" |
1939 " if (i >= 3) live.push(object, prototype);" | 1944 " if (i >= 3) live.push(object, prototype);" |
1940 "}"); | 1945 "}"); |
1941 | 1946 |
1942 Handle<JSObject> baseObject = | 1947 Handle<JSObject> baseObject = |
1943 v8::Utils::OpenHandle( | 1948 v8::Utils::OpenHandle( |
1944 *v8::Handle<v8::Object>::Cast( | 1949 *v8::Handle<v8::Object>::Cast( |
1945 v8::Context::GetCurrent()->Global()->Get(v8_str("base")))); | 1950 GetGlobal()->Get(v8_str("base")))); |
1946 | 1951 |
1947 // Verify that only dead prototype transitions are cleared. | 1952 // Verify that only dead prototype transitions are cleared. |
1948 CHECK_EQ(10, baseObject->map()->NumberOfProtoTransitions()); | 1953 CHECK_EQ(10, baseObject->map()->NumberOfProtoTransitions()); |
1949 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 1954 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
1950 const int transitions = 10 - 3; | 1955 const int transitions = 10 - 3; |
1951 CHECK_EQ(transitions, baseObject->map()->NumberOfProtoTransitions()); | 1956 CHECK_EQ(transitions, baseObject->map()->NumberOfProtoTransitions()); |
1952 | 1957 |
1953 // Verify that prototype transitions array was compacted. | 1958 // Verify that prototype transitions array was compacted. |
1954 FixedArray* trans = baseObject->map()->GetPrototypeTransitions(); | 1959 FixedArray* trans = baseObject->map()->GetPrototypeTransitions(); |
1955 for (int i = 0; i < transitions; i++) { | 1960 for (int i = 0; i < transitions; i++) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2002 " for (var i = 0; i < 100; i++) s += i;" | 2007 " for (var i = 0; i < 100; i++) s += i;" |
2003 " return s;" | 2008 " return s;" |
2004 "}" | 2009 "}" |
2005 "f(); f();" | 2010 "f(); f();" |
2006 "%OptimizeFunctionOnNextCall(f);" | 2011 "%OptimizeFunctionOnNextCall(f);" |
2007 "f();"); | 2012 "f();"); |
2008 } | 2013 } |
2009 Handle<JSFunction> f = | 2014 Handle<JSFunction> f = |
2010 v8::Utils::OpenHandle( | 2015 v8::Utils::OpenHandle( |
2011 *v8::Handle<v8::Function>::Cast( | 2016 *v8::Handle<v8::Function>::Cast( |
2012 v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); | 2017 GetGlobal()->Get(v8_str("f")))); |
2013 CHECK(f->IsOptimized()); | 2018 CHECK(f->IsOptimized()); |
2014 | 2019 |
2015 IncrementalMarking* marking = CcTest::heap()->incremental_marking(); | 2020 IncrementalMarking* marking = CcTest::heap()->incremental_marking(); |
2016 marking->Abort(); | 2021 marking->Abort(); |
2017 marking->Start(); | 2022 marking->Start(); |
2018 | 2023 |
2019 // The following two calls will increment CcTest::heap()->global_ic_age(). | 2024 // The following two calls will increment CcTest::heap()->global_ic_age(). |
2020 const int kLongIdlePauseInMs = 1000; | 2025 const int kLongIdlePauseInMs = 1000; |
2021 v8::V8::ContextDisposedNotification(); | 2026 v8::V8::ContextDisposedNotification(); |
2022 v8::V8::IdleNotification(kLongIdlePauseInMs); | 2027 v8::V8::IdleNotification(kLongIdlePauseInMs); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2059 " for (var i = 0; i < 100; i++) s += i;" | 2064 " for (var i = 0; i < 100; i++) s += i;" |
2060 " return s;" | 2065 " return s;" |
2061 "}" | 2066 "}" |
2062 "f(); f();" | 2067 "f(); f();" |
2063 "%OptimizeFunctionOnNextCall(f);" | 2068 "%OptimizeFunctionOnNextCall(f);" |
2064 "f();"); | 2069 "f();"); |
2065 } | 2070 } |
2066 Handle<JSFunction> f = | 2071 Handle<JSFunction> f = |
2067 v8::Utils::OpenHandle( | 2072 v8::Utils::OpenHandle( |
2068 *v8::Handle<v8::Function>::Cast( | 2073 *v8::Handle<v8::Function>::Cast( |
2069 v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); | 2074 GetGlobal()->Get(v8_str("f")))); |
2070 CHECK(f->IsOptimized()); | 2075 CHECK(f->IsOptimized()); |
2071 | 2076 |
2072 CcTest::heap()->incremental_marking()->Abort(); | 2077 CcTest::heap()->incremental_marking()->Abort(); |
2073 | 2078 |
2074 // The following two calls will increment CcTest::heap()->global_ic_age(). | 2079 // The following two calls will increment CcTest::heap()->global_ic_age(). |
2075 // Since incremental marking is off, IdleNotification will do full GC. | 2080 // Since incremental marking is off, IdleNotification will do full GC. |
2076 const int kLongIdlePauseInMs = 1000; | 2081 const int kLongIdlePauseInMs = 1000; |
2077 v8::V8::ContextDisposedNotification(); | 2082 v8::V8::ContextDisposedNotification(); |
2078 v8::V8::IdleNotification(kLongIdlePauseInMs); | 2083 v8::V8::IdleNotification(kLongIdlePauseInMs); |
2079 | 2084 |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2468 EmbeddedVector<char, 64> buffer; | 2473 EmbeddedVector<char, 64> buffer; |
2469 OS::SNPrintF(buffer, "var o = new Object; o.prop%d = %d;", i, i); | 2474 OS::SNPrintF(buffer, "var o = new Object; o.prop%d = %d;", i, i); |
2470 CompileRun(buffer.start()); | 2475 CompileRun(buffer.start()); |
2471 } | 2476 } |
2472 CompileRun("var root = new Object;"); | 2477 CompileRun("var root = new Object;"); |
2473 } | 2478 } |
2474 | 2479 |
2475 Handle<JSObject> root = | 2480 Handle<JSObject> root = |
2476 v8::Utils::OpenHandle( | 2481 v8::Utils::OpenHandle( |
2477 *v8::Handle<v8::Object>::Cast( | 2482 *v8::Handle<v8::Object>::Cast( |
2478 v8::Context::GetCurrent()->Global()->Get(v8_str("root")))); | 2483 GetGlobal()->Get(v8_str("root")))); |
2479 | 2484 |
2480 // Count number of live transitions before marking. | 2485 // Count number of live transitions before marking. |
2481 int transitions_before = CountMapTransitions(root->map()); | 2486 int transitions_before = CountMapTransitions(root->map()); |
2482 CompileRun("%DebugPrint(root);"); | 2487 CompileRun("%DebugPrint(root);"); |
2483 CHECK_EQ(transitions_count, transitions_before); | 2488 CHECK_EQ(transitions_count, transitions_before); |
2484 | 2489 |
2485 SimulateIncrementalMarking(); | 2490 SimulateIncrementalMarking(); |
2486 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 2491 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
2487 | 2492 |
2488 // Count number of live transitions after marking. Note that one transition | 2493 // Count number of live transitions after marking. Note that one transition |
(...skipping 29 matching lines...) Expand all Loading... | |
2518 | 2523 |
2519 // This bug only triggers with aggressive IC clearing. | 2524 // This bug only triggers with aggressive IC clearing. |
2520 CcTest::heap()->AgeInlineCaches(); | 2525 CcTest::heap()->AgeInlineCaches(); |
2521 | 2526 |
2522 // Explicitly request GC to perform final marking step and sweeping. | 2527 // Explicitly request GC to perform final marking step and sweeping. |
2523 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 2528 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
2524 | 2529 |
2525 Handle<JSObject> root = | 2530 Handle<JSObject> root = |
2526 v8::Utils::OpenHandle( | 2531 v8::Utils::OpenHandle( |
2527 *v8::Handle<v8::Object>::Cast( | 2532 *v8::Handle<v8::Object>::Cast( |
2528 v8::Context::GetCurrent()->Global()->Get(v8_str("root")))); | 2533 GetGlobal()->Get(v8_str("root")))); |
2529 | 2534 |
2530 // The root object should be in a sane state. | 2535 // The root object should be in a sane state. |
2531 CHECK(root->IsJSObject()); | 2536 CHECK(root->IsJSObject()); |
2532 CHECK(root->map()->IsMap()); | 2537 CHECK(root->map()->IsMap()); |
2533 } | 2538 } |
2534 | 2539 |
2535 | 2540 |
2536 TEST(Regress2143b) { | 2541 TEST(Regress2143b) { |
2537 i::FLAG_collect_maps = true; | 2542 i::FLAG_collect_maps = true; |
2538 i::FLAG_incremental_marking = true; | 2543 i::FLAG_incremental_marking = true; |
(...skipping 23 matching lines...) Expand all Loading... | |
2562 | 2567 |
2563 // This bug only triggers with aggressive IC clearing. | 2568 // This bug only triggers with aggressive IC clearing. |
2564 CcTest::heap()->AgeInlineCaches(); | 2569 CcTest::heap()->AgeInlineCaches(); |
2565 | 2570 |
2566 // Explicitly request GC to perform final marking step and sweeping. | 2571 // Explicitly request GC to perform final marking step and sweeping. |
2567 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 2572 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
2568 | 2573 |
2569 Handle<JSObject> root = | 2574 Handle<JSObject> root = |
2570 v8::Utils::OpenHandle( | 2575 v8::Utils::OpenHandle( |
2571 *v8::Handle<v8::Object>::Cast( | 2576 *v8::Handle<v8::Object>::Cast( |
2572 v8::Context::GetCurrent()->Global()->Get(v8_str("root")))); | 2577 GetGlobal()->Get(v8_str("root")))); |
2573 | 2578 |
2574 // The root object should be in a sane state. | 2579 // The root object should be in a sane state. |
2575 CHECK(root->IsJSObject()); | 2580 CHECK(root->IsJSObject()); |
2576 CHECK(root->map()->IsMap()); | 2581 CHECK(root->map()->IsMap()); |
2577 } | 2582 } |
2578 | 2583 |
2579 | 2584 |
2580 TEST(ReleaseOverReservedPages) { | 2585 TEST(ReleaseOverReservedPages) { |
2581 i::FLAG_trace_gc = true; | 2586 i::FLAG_trace_gc = true; |
2582 // The optimizer can allocate stuff, messing up the test. | 2587 // The optimizer can allocate stuff, messing up the test. |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2658 #ifdef OBJECT_PRINT | 2663 #ifdef OBJECT_PRINT |
2659 TEST(PrintSharedFunctionInfo) { | 2664 TEST(PrintSharedFunctionInfo) { |
2660 CcTest::InitializeVM(); | 2665 CcTest::InitializeVM(); |
2661 v8::HandleScope scope(CcTest::isolate()); | 2666 v8::HandleScope scope(CcTest::isolate()); |
2662 const char* source = "f = function() { return 987654321; }\n" | 2667 const char* source = "f = function() { return 987654321; }\n" |
2663 "g = function() { return 123456789; }\n"; | 2668 "g = function() { return 123456789; }\n"; |
2664 CompileRun(source); | 2669 CompileRun(source); |
2665 Handle<JSFunction> g = | 2670 Handle<JSFunction> g = |
2666 v8::Utils::OpenHandle( | 2671 v8::Utils::OpenHandle( |
2667 *v8::Handle<v8::Function>::Cast( | 2672 *v8::Handle<v8::Function>::Cast( |
2668 v8::Context::GetCurrent()->Global()->Get(v8_str("g")))); | 2673 GetGlobal()->Get(v8_str("g")))); |
2669 | 2674 |
2670 DisallowHeapAllocation no_allocation; | 2675 DisallowHeapAllocation no_allocation; |
2671 g->shared()->PrintLn(); | 2676 g->shared()->PrintLn(); |
2672 } | 2677 } |
2673 #endif // OBJECT_PRINT | 2678 #endif // OBJECT_PRINT |
2674 | 2679 |
2675 | 2680 |
2676 TEST(Regress2211) { | 2681 TEST(Regress2211) { |
2677 CcTest::InitializeVM(); | 2682 CcTest::InitializeVM(); |
2678 v8::HandleScope scope(CcTest::isolate()); | 2683 v8::HandleScope scope(CcTest::isolate()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2721 } | 2726 } |
2722 | 2727 |
2723 { | 2728 { |
2724 LocalContext env; | 2729 LocalContext env; |
2725 CompileRun("function fun() {};"); | 2730 CompileRun("function fun() {};"); |
2726 fun2 = env->Global()->Get(v8_str("fun")); | 2731 fun2 = env->Global()->Get(v8_str("fun")); |
2727 } | 2732 } |
2728 | 2733 |
2729 // Prepare function f that contains type feedback for closures | 2734 // Prepare function f that contains type feedback for closures |
2730 // originating from two different native contexts. | 2735 // originating from two different native contexts. |
2731 v8::Context::GetCurrent()->Global()->Set(v8_str("fun1"), fun1); | 2736 GetGlobal()->Set(v8_str("fun1"), fun1); |
2732 v8::Context::GetCurrent()->Global()->Set(v8_str("fun2"), fun2); | 2737 GetGlobal()->Set(v8_str("fun2"), fun2); |
2733 CompileRun("function f(a, b) { a(); b(); } f(fun1, fun2);"); | 2738 CompileRun("function f(a, b) { a(); b(); } f(fun1, fun2);"); |
2734 Handle<JSFunction> f = | 2739 Handle<JSFunction> f = |
2735 v8::Utils::OpenHandle( | 2740 v8::Utils::OpenHandle( |
2736 *v8::Handle<v8::Function>::Cast( | 2741 *v8::Handle<v8::Function>::Cast( |
2737 v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); | 2742 GetGlobal()->Get(v8_str("f")))); |
2738 Handle<TypeFeedbackCells> cells(TypeFeedbackInfo::cast( | 2743 Handle<TypeFeedbackCells> cells(TypeFeedbackInfo::cast( |
2739 f->shared()->code()->type_feedback_info())->type_feedback_cells()); | 2744 f->shared()->code()->type_feedback_info())->type_feedback_cells()); |
2740 | 2745 |
2741 CHECK_EQ(2, cells->CellCount()); | 2746 CHECK_EQ(2, cells->CellCount()); |
2742 CHECK(cells->GetCell(0)->value()->IsJSFunction()); | 2747 CHECK(cells->GetCell(0)->value()->IsJSFunction()); |
2743 CHECK(cells->GetCell(1)->value()->IsJSFunction()); | 2748 CHECK(cells->GetCell(1)->value()->IsJSFunction()); |
2744 | 2749 |
2745 SimulateIncrementalMarking(); | 2750 SimulateIncrementalMarking(); |
2746 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 2751 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
2747 | 2752 |
(...skipping 24 matching lines...) Expand all Loading... | |
2772 CcTest::InitializeVM(); | 2777 CcTest::InitializeVM(); |
2773 v8::HandleScope scope(CcTest::isolate()); | 2778 v8::HandleScope scope(CcTest::isolate()); |
2774 | 2779 |
2775 // Prepare function f that contains a monomorphic IC for object | 2780 // Prepare function f that contains a monomorphic IC for object |
2776 // originating from the same native context. | 2781 // originating from the same native context. |
2777 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" | 2782 CompileRun("function fun() { this.x = 1; }; var obj = new fun();" |
2778 "function f(o) { return o.x; } f(obj); f(obj);"); | 2783 "function f(o) { return o.x; } f(obj); f(obj);"); |
2779 Handle<JSFunction> f = | 2784 Handle<JSFunction> f = |
2780 v8::Utils::OpenHandle( | 2785 v8::Utils::OpenHandle( |
2781 *v8::Handle<v8::Function>::Cast( | 2786 *v8::Handle<v8::Function>::Cast( |
2782 v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); | 2787 GetGlobal()->Get(v8_str("f")))); |
2783 | 2788 |
2784 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 2789 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
2785 CHECK(ic_before->ic_state() == MONOMORPHIC); | 2790 CHECK(ic_before->ic_state() == MONOMORPHIC); |
2786 | 2791 |
2787 SimulateIncrementalMarking(); | 2792 SimulateIncrementalMarking(); |
2788 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 2793 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
2789 | 2794 |
2790 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 2795 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
2791 CHECK(ic_after->ic_state() == MONOMORPHIC); | 2796 CHECK(ic_after->ic_state() == MONOMORPHIC); |
2792 } | 2797 } |
2793 | 2798 |
2794 | 2799 |
2795 TEST(IncrementalMarkingClearsMonomorhpicIC) { | 2800 TEST(IncrementalMarkingClearsMonomorhpicIC) { |
2796 if (i::FLAG_always_opt) return; | 2801 if (i::FLAG_always_opt) return; |
2797 CcTest::InitializeVM(); | 2802 CcTest::InitializeVM(); |
2798 v8::HandleScope scope(CcTest::isolate()); | 2803 v8::HandleScope scope(CcTest::isolate()); |
2799 v8::Local<v8::Value> obj1; | 2804 v8::Local<v8::Value> obj1; |
2800 | 2805 |
2801 { | 2806 { |
2802 LocalContext env; | 2807 LocalContext env; |
2803 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); | 2808 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); |
2804 obj1 = env->Global()->Get(v8_str("obj")); | 2809 obj1 = env->Global()->Get(v8_str("obj")); |
2805 } | 2810 } |
2806 | 2811 |
2807 // Prepare function f that contains a monomorphic IC for object | 2812 // Prepare function f that contains a monomorphic IC for object |
2808 // originating from a different native context. | 2813 // originating from a different native context. |
2809 v8::Context::GetCurrent()->Global()->Set(v8_str("obj1"), obj1); | 2814 GetGlobal()->Set(v8_str("obj1"), obj1); |
2810 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1);"); | 2815 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1);"); |
2811 Handle<JSFunction> f = | 2816 Handle<JSFunction> f = |
2812 v8::Utils::OpenHandle( | 2817 v8::Utils::OpenHandle( |
2813 *v8::Handle<v8::Function>::Cast( | 2818 *v8::Handle<v8::Function>::Cast( |
2814 v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); | 2819 GetGlobal()->Get(v8_str("f")))); |
2815 | 2820 |
2816 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 2821 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
2817 CHECK(ic_before->ic_state() == MONOMORPHIC); | 2822 CHECK(ic_before->ic_state() == MONOMORPHIC); |
2818 | 2823 |
2819 // Fire context dispose notification. | 2824 // Fire context dispose notification. |
2820 v8::V8::ContextDisposedNotification(); | 2825 v8::V8::ContextDisposedNotification(); |
2821 SimulateIncrementalMarking(); | 2826 SimulateIncrementalMarking(); |
2822 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 2827 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
2823 | 2828 |
2824 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 2829 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
(...skipping 14 matching lines...) Expand all Loading... | |
2839 } | 2844 } |
2840 | 2845 |
2841 { | 2846 { |
2842 LocalContext env; | 2847 LocalContext env; |
2843 CompileRun("function fun() { this.x = 2; }; var obj = new fun();"); | 2848 CompileRun("function fun() { this.x = 2; }; var obj = new fun();"); |
2844 obj2 = env->Global()->Get(v8_str("obj")); | 2849 obj2 = env->Global()->Get(v8_str("obj")); |
2845 } | 2850 } |
2846 | 2851 |
2847 // Prepare function f that contains a polymorphic IC for objects | 2852 // Prepare function f that contains a polymorphic IC for objects |
2848 // originating from two different native contexts. | 2853 // originating from two different native contexts. |
2849 v8::Context::GetCurrent()->Global()->Set(v8_str("obj1"), obj1); | 2854 GetGlobal()->Set(v8_str("obj1"), obj1); |
2850 v8::Context::GetCurrent()->Global()->Set(v8_str("obj2"), obj2); | 2855 GetGlobal()->Set(v8_str("obj2"), obj2); |
2851 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); | 2856 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); |
2852 Handle<JSFunction> f = | 2857 Handle<JSFunction> f = |
2853 v8::Utils::OpenHandle( | 2858 v8::Utils::OpenHandle( |
2854 *v8::Handle<v8::Function>::Cast( | 2859 *v8::Handle<v8::Function>::Cast( |
2855 v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); | 2860 GetGlobal()->Get(v8_str("f")))); |
2856 | 2861 |
2857 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 2862 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
2858 CHECK(ic_before->ic_state() == POLYMORPHIC); | 2863 CHECK(ic_before->ic_state() == POLYMORPHIC); |
2859 | 2864 |
2860 // Fire context dispose notification. | 2865 // Fire context dispose notification. |
2861 v8::V8::ContextDisposedNotification(); | 2866 v8::V8::ContextDisposedNotification(); |
2862 SimulateIncrementalMarking(); | 2867 SimulateIncrementalMarking(); |
2863 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 2868 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
2864 | 2869 |
2865 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | 2870 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3050 "var g = mkClosure();" | 3055 "var g = mkClosure();" |
3051 "f(1); f(2);" | 3056 "f(1); f(2);" |
3052 "g(1); g(2);" | 3057 "g(1); g(2);" |
3053 "h(1); h(2);" | 3058 "h(1); h(2);" |
3054 "%OptimizeFunctionOnNextCall(f); f(3);" | 3059 "%OptimizeFunctionOnNextCall(f); f(3);" |
3055 "%OptimizeFunctionOnNextCall(h); h(3);"); | 3060 "%OptimizeFunctionOnNextCall(h); h(3);"); |
3056 | 3061 |
3057 Handle<JSFunction> f = | 3062 Handle<JSFunction> f = |
3058 v8::Utils::OpenHandle( | 3063 v8::Utils::OpenHandle( |
3059 *v8::Handle<v8::Function>::Cast( | 3064 *v8::Handle<v8::Function>::Cast( |
3060 v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); | 3065 GetGlobal()->Get(v8_str("f")))); |
3061 CHECK(f->is_compiled()); | 3066 CHECK(f->is_compiled()); |
3062 CompileRun("f = null;"); | 3067 CompileRun("f = null;"); |
3063 | 3068 |
3064 Handle<JSFunction> g = | 3069 Handle<JSFunction> g = |
3065 v8::Utils::OpenHandle( | 3070 v8::Utils::OpenHandle( |
3066 *v8::Handle<v8::Function>::Cast( | 3071 *v8::Handle<v8::Function>::Cast( |
3067 v8::Context::GetCurrent()->Global()->Get(v8_str("g")))); | 3072 GetGlobal()->Get(v8_str("g")))); |
3068 CHECK(g->is_compiled()); | 3073 CHECK(g->is_compiled()); |
3069 const int kAgingThreshold = 6; | 3074 const int kAgingThreshold = 6; |
3070 for (int i = 0; i < kAgingThreshold; i++) { | 3075 for (int i = 0; i < kAgingThreshold; i++) { |
3071 g->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); | 3076 g->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); |
3072 } | 3077 } |
3073 | 3078 |
3074 code = inner_scope.CloseAndEscape(Handle<Code>(f->code())); | 3079 code = inner_scope.CloseAndEscape(Handle<Code>(f->code())); |
3075 } | 3080 } |
3076 | 3081 |
3077 // Simulate incremental marking so that the functions are enqueued as | 3082 // Simulate incremental marking so that the functions are enqueued as |
(...skipping 27 matching lines...) Expand all Loading... | |
3105 CompileRun("function mkClosure() {" | 3110 CompileRun("function mkClosure() {" |
3106 " return function(x) { return x + 1; };" | 3111 " return function(x) { return x + 1; };" |
3107 "}" | 3112 "}" |
3108 "var f = mkClosure();" | 3113 "var f = mkClosure();" |
3109 "f(1); f(2);" | 3114 "f(1); f(2);" |
3110 "%OptimizeFunctionOnNextCall(f); f(3);"); | 3115 "%OptimizeFunctionOnNextCall(f); f(3);"); |
3111 | 3116 |
3112 Handle<JSFunction> f = | 3117 Handle<JSFunction> f = |
3113 v8::Utils::OpenHandle( | 3118 v8::Utils::OpenHandle( |
3114 *v8::Handle<v8::Function>::Cast( | 3119 *v8::Handle<v8::Function>::Cast( |
3115 v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); | 3120 GetGlobal()->Get(v8_str("f")))); |
3116 CHECK(f->is_compiled()); | 3121 CHECK(f->is_compiled()); |
3117 const int kAgingThreshold = 6; | 3122 const int kAgingThreshold = 6; |
3118 for (int i = 0; i < kAgingThreshold; i++) { | 3123 for (int i = 0; i < kAgingThreshold; i++) { |
3119 f->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); | 3124 f->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); |
3120 } | 3125 } |
3121 | 3126 |
3122 CompileRun("f = null;"); | 3127 CompileRun("f = null;"); |
3123 } | 3128 } |
3124 | 3129 |
3125 // Simulate incremental marking so that unoptimized code is flushed | 3130 // Simulate incremental marking so that unoptimized code is flushed |
(...skipping 27 matching lines...) Expand all Loading... | |
3153 HandleScope inner_scope(isolate); | 3158 HandleScope inner_scope(isolate); |
3154 CompileRun("function f() { return 'foobar'; }" | 3159 CompileRun("function f() { return 'foobar'; }" |
3155 "function g(x) { if (x) f(); }" | 3160 "function g(x) { if (x) f(); }" |
3156 "f();" | 3161 "f();" |
3157 "g(false);" | 3162 "g(false);" |
3158 "g(false);"); | 3163 "g(false);"); |
3159 | 3164 |
3160 Handle<JSFunction> f = | 3165 Handle<JSFunction> f = |
3161 v8::Utils::OpenHandle( | 3166 v8::Utils::OpenHandle( |
3162 *v8::Handle<v8::Function>::Cast( | 3167 *v8::Handle<v8::Function>::Cast( |
3163 v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); | 3168 GetGlobal()->Get(v8_str("f")))); |
3164 CHECK(f->is_compiled()); | 3169 CHECK(f->is_compiled()); |
3165 const int kAgingThreshold = 6; | 3170 const int kAgingThreshold = 6; |
3166 for (int i = 0; i < kAgingThreshold; i++) { | 3171 for (int i = 0; i < kAgingThreshold; i++) { |
3167 f->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); | 3172 f->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); |
3168 } | 3173 } |
3169 | 3174 |
3170 shared1 = inner_scope.CloseAndEscape(handle(f->shared(), isolate)); | 3175 shared1 = inner_scope.CloseAndEscape(handle(f->shared(), isolate)); |
3171 } | 3176 } |
3172 | 3177 |
3173 // Prepare a shared function info eligible for code flushing that will | 3178 // Prepare a shared function info eligible for code flushing that will |
3174 // represent the dangling tail of the candidate list. | 3179 // represent the dangling tail of the candidate list. |
3175 Handle<SharedFunctionInfo> shared2; | 3180 Handle<SharedFunctionInfo> shared2; |
3176 { | 3181 { |
3177 HandleScope inner_scope(isolate); | 3182 HandleScope inner_scope(isolate); |
3178 CompileRun("function flushMe() { return 0; }" | 3183 CompileRun("function flushMe() { return 0; }" |
3179 "flushMe(1);"); | 3184 "flushMe(1);"); |
3180 | 3185 |
3181 Handle<JSFunction> f = | 3186 Handle<JSFunction> f = |
3182 v8::Utils::OpenHandle( | 3187 v8::Utils::OpenHandle( |
3183 *v8::Handle<v8::Function>::Cast( | 3188 *v8::Handle<v8::Function>::Cast( |
3184 v8::Context::GetCurrent()->Global()->Get(v8_str("flushMe")))); | 3189 GetGlobal()->Get(v8_str("flushMe")))); |
3185 CHECK(f->is_compiled()); | 3190 CHECK(f->is_compiled()); |
3186 const int kAgingThreshold = 6; | 3191 const int kAgingThreshold = 6; |
3187 for (int i = 0; i < kAgingThreshold; i++) { | 3192 for (int i = 0; i < kAgingThreshold; i++) { |
3188 f->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); | 3193 f->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); |
3189 } | 3194 } |
3190 | 3195 |
3191 shared2 = inner_scope.CloseAndEscape(handle(f->shared(), isolate)); | 3196 shared2 = inner_scope.CloseAndEscape(handle(f->shared(), isolate)); |
3192 } | 3197 } |
3193 | 3198 |
3194 // Simulate incremental marking and collect code flushing candidates. | 3199 // Simulate incremental marking and collect code flushing candidates. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3244 "}" | 3249 "}" |
3245 "obj = fastliteralcase(get_standard_literal(), 1);" | 3250 "obj = fastliteralcase(get_standard_literal(), 1);" |
3246 "obj = fastliteralcase(get_standard_literal(), 1.5);" | 3251 "obj = fastliteralcase(get_standard_literal(), 1.5);" |
3247 "obj = fastliteralcase(get_standard_literal(), 2);"); | 3252 "obj = fastliteralcase(get_standard_literal(), 2);"); |
3248 | 3253 |
3249 // prepare the heap | 3254 // prepare the heap |
3250 v8::Local<v8::String> mote_code_string = | 3255 v8::Local<v8::String> mote_code_string = |
3251 v8_str("fastliteralcase(mote, 2.5);"); | 3256 v8_str("fastliteralcase(mote, 2.5);"); |
3252 | 3257 |
3253 v8::Local<v8::String> array_name = v8_str("mote"); | 3258 v8::Local<v8::String> array_name = v8_str("mote"); |
3254 v8::Context::GetCurrent()->Global()->Set(array_name, v8::Int32::New(0)); | 3259 GetGlobal()->Set(array_name, v8::Int32::New(0)); |
3255 | 3260 |
3256 // First make sure we flip spaces | 3261 // First make sure we flip spaces |
3257 CcTest::heap()->CollectGarbage(NEW_SPACE); | 3262 CcTest::heap()->CollectGarbage(NEW_SPACE); |
3258 | 3263 |
3259 // Allocate the object. | 3264 // Allocate the object. |
3260 Handle<FixedArray> array_data = factory->NewFixedArray(2, NOT_TENURED); | 3265 Handle<FixedArray> array_data = factory->NewFixedArray(2, NOT_TENURED); |
3261 array_data->set(0, Smi::FromInt(1)); | 3266 array_data->set(0, Smi::FromInt(1)); |
3262 array_data->set(1, Smi::FromInt(2)); | 3267 array_data->set(1, Smi::FromInt(2)); |
3263 | 3268 |
3264 AllocateAllButNBytes(CcTest::heap()->new_space(), | 3269 AllocateAllButNBytes(CcTest::heap()->new_space(), |
(...skipping 13 matching lines...) Expand all Loading... | |
3278 AllocationMemento::kSize + kPointerSize, NEW_SPACE, OLD_POINTER_SPACE); | 3283 AllocationMemento::kSize + kPointerSize, NEW_SPACE, OLD_POINTER_SPACE); |
3279 Object* obj = NULL; | 3284 Object* obj = NULL; |
3280 CHECK(maybe_object->ToObject(&obj)); | 3285 CHECK(maybe_object->ToObject(&obj)); |
3281 Address addr_obj = reinterpret_cast<Address>( | 3286 Address addr_obj = reinterpret_cast<Address>( |
3282 reinterpret_cast<byte*>(obj - kHeapObjectTag)); | 3287 reinterpret_cast<byte*>(obj - kHeapObjectTag)); |
3283 CcTest::heap()->CreateFillerObjectAt(addr_obj, | 3288 CcTest::heap()->CreateFillerObjectAt(addr_obj, |
3284 AllocationMemento::kSize + kPointerSize); | 3289 AllocationMemento::kSize + kPointerSize); |
3285 | 3290 |
3286 // Give the array a name, making sure not to allocate strings. | 3291 // Give the array a name, making sure not to allocate strings. |
3287 v8::Handle<v8::Object> array_obj = v8::Utils::ToLocal(array); | 3292 v8::Handle<v8::Object> array_obj = v8::Utils::ToLocal(array); |
3288 v8::Context::GetCurrent()->Global()->Set(array_name, array_obj); | 3293 GetGlobal()->Set(array_name, array_obj); |
3289 | 3294 |
3290 // This should crash with a protection violation if we are running a build | 3295 // This should crash with a protection violation if we are running a build |
3291 // with the bug. | 3296 // with the bug. |
3292 AlwaysAllocateScope aa_scope; | 3297 AlwaysAllocateScope aa_scope; |
3293 v8::Script::Compile(mote_code_string)->Run(); | 3298 v8::Script::Compile(mote_code_string)->Run(); |
3294 } | 3299 } |
3295 | 3300 |
3296 | 3301 |
3297 TEST(Regress168801) { | 3302 TEST(Regress168801) { |
3298 i::FLAG_always_compact = true; | 3303 i::FLAG_always_compact = true; |
(...skipping 17 matching lines...) Expand all Loading... | |
3316 HandleScope inner_scope(isolate); | 3321 HandleScope inner_scope(isolate); |
3317 CompileRun("function mkClosure() {" | 3322 CompileRun("function mkClosure() {" |
3318 " return function(x) { return x + 1; };" | 3323 " return function(x) { return x + 1; };" |
3319 "}" | 3324 "}" |
3320 "var f = mkClosure();" | 3325 "var f = mkClosure();" |
3321 "f(1); f(2);"); | 3326 "f(1); f(2);"); |
3322 | 3327 |
3323 Handle<JSFunction> f = | 3328 Handle<JSFunction> f = |
3324 v8::Utils::OpenHandle( | 3329 v8::Utils::OpenHandle( |
3325 *v8::Handle<v8::Function>::Cast( | 3330 *v8::Handle<v8::Function>::Cast( |
3326 v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); | 3331 GetGlobal()->Get(v8_str("f")))); |
3327 CHECK(f->is_compiled()); | 3332 CHECK(f->is_compiled()); |
3328 const int kAgingThreshold = 6; | 3333 const int kAgingThreshold = 6; |
3329 for (int i = 0; i < kAgingThreshold; i++) { | 3334 for (int i = 0; i < kAgingThreshold; i++) { |
3330 f->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); | 3335 f->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); |
3331 } | 3336 } |
3332 | 3337 |
3333 function = inner_scope.CloseAndEscape(handle(*f, isolate)); | 3338 function = inner_scope.CloseAndEscape(handle(*f, isolate)); |
3334 } | 3339 } |
3335 | 3340 |
3336 // Simulate incremental marking so that unoptimized function is enqueued as a | 3341 // Simulate incremental marking so that unoptimized function is enqueued as a |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3372 HandleScope inner_scope(isolate); | 3377 HandleScope inner_scope(isolate); |
3373 CompileRun("function mkClosure() {" | 3378 CompileRun("function mkClosure() {" |
3374 " return function(x) { return x + 1; };" | 3379 " return function(x) { return x + 1; };" |
3375 "}" | 3380 "}" |
3376 "var f = mkClosure();" | 3381 "var f = mkClosure();" |
3377 "f(1); f(2);"); | 3382 "f(1); f(2);"); |
3378 | 3383 |
3379 Handle<JSFunction> f = | 3384 Handle<JSFunction> f = |
3380 v8::Utils::OpenHandle( | 3385 v8::Utils::OpenHandle( |
3381 *v8::Handle<v8::Function>::Cast( | 3386 *v8::Handle<v8::Function>::Cast( |
3382 v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); | 3387 GetGlobal()->Get(v8_str("f")))); |
3383 CHECK(f->is_compiled()); | 3388 CHECK(f->is_compiled()); |
3384 const int kAgingThreshold = 6; | 3389 const int kAgingThreshold = 6; |
3385 for (int i = 0; i < kAgingThreshold; i++) { | 3390 for (int i = 0; i < kAgingThreshold; i++) { |
3386 f->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); | 3391 f->shared()->code()->MakeOlder(static_cast<MarkingParity>(i % 2)); |
3387 } | 3392 } |
3388 | 3393 |
3389 function = inner_scope.CloseAndEscape(handle(*f, isolate)); | 3394 function = inner_scope.CloseAndEscape(handle(*f, isolate)); |
3390 } | 3395 } |
3391 | 3396 |
3392 // Simulate incremental marking so that unoptimized function is enqueued as a | 3397 // Simulate incremental marking so that unoptimized function is enqueued as a |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3440 " var a = new Array(n);" | 3445 " var a = new Array(n);" |
3441 " for (var i = 0; i < n; i += 100) a[i] = i;" | 3446 " for (var i = 0; i < n; i += 100) a[i] = i;" |
3442 "};" | 3447 "};" |
3443 "f(10 * 1024 * 1024);"); | 3448 "f(10 * 1024 * 1024);"); |
3444 IncrementalMarking* marking = CcTest::heap()->incremental_marking(); | 3449 IncrementalMarking* marking = CcTest::heap()->incremental_marking(); |
3445 if (marking->IsStopped()) marking->Start(); | 3450 if (marking->IsStopped()) marking->Start(); |
3446 // This big step should be sufficient to mark the whole array. | 3451 // This big step should be sufficient to mark the whole array. |
3447 marking->Step(100 * MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); | 3452 marking->Step(100 * MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); |
3448 ASSERT(marking->IsComplete()); | 3453 ASSERT(marking->IsComplete()); |
3449 } | 3454 } |
OLD | NEW |