OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 | 2 |
3 #include <stdlib.h> | 3 #include <stdlib.h> |
4 | 4 |
5 #include "v8.h" | 5 #include "v8.h" |
6 | 6 |
7 #include "execution.h" | 7 #include "execution.h" |
8 #include "factory.h" | 8 #include "factory.h" |
9 #include "macro-assembler.h" | 9 #include "macro-assembler.h" |
10 #include "global-handles.h" | 10 #include "global-handles.h" |
(...skipping 2059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2070 marking->Step(MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); | 2070 marking->Step(MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); |
2071 } | 2071 } |
2072 CHECK(marking->IsComplete()); | 2072 CHECK(marking->IsComplete()); |
2073 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | 2073 HEAP->CollectAllGarbage(Heap::kNoGCFlags); |
2074 CHECK(marking->IsStopped()); | 2074 CHECK(marking->IsStopped()); |
2075 | 2075 |
2076 CHECK_EQ(2, cells->CellCount()); | 2076 CHECK_EQ(2, cells->CellCount()); |
2077 CHECK(cells->Cell(0)->value()->IsTheHole()); | 2077 CHECK(cells->Cell(0)->value()->IsTheHole()); |
2078 CHECK(cells->Cell(1)->value()->IsTheHole()); | 2078 CHECK(cells->Cell(1)->value()->IsTheHole()); |
2079 } | 2079 } |
2080 | |
2081 | |
2082 static Code* FindFirstIC(Code* code, Code::Kind kind) { | |
2083 int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET) | | |
2084 RelocInfo::ModeMask(RelocInfo::CONSTRUCT_CALL) | | |
2085 RelocInfo::ModeMask(RelocInfo::CODE_TARGET_WITH_ID) | | |
2086 RelocInfo::ModeMask(RelocInfo::CODE_TARGET_CONTEXT); | |
2087 for (RelocIterator it(code, mask); !it.done(); it.next()) { | |
2088 RelocInfo* info = it.rinfo(); | |
2089 Code* target = Code::GetCodeFromTargetAddress(info->target_address()); | |
2090 if (target->is_inline_cache_stub() && target->kind() == kind) { | |
2091 return target; | |
2092 } | |
2093 } | |
2094 return NULL; | |
2095 } | |
2096 | |
2097 | |
2098 TEST(IncrementalMarkingClearsMonomorhpicIC) { | |
Erik Corry
2012/08/03 08:41:25
Should we have a test that marking does _not_ clea
Michael Starzinger
2012/08/06 09:57:34
Done.
| |
2099 if (i::FLAG_always_opt) return; | |
2100 InitializeVM(); | |
2101 v8::HandleScope scope; | |
2102 v8::Local<v8::Value> obj1; | |
2103 | |
2104 { | |
2105 LocalContext env; | |
2106 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); | |
2107 obj1 = env->Global()->Get(v8_str("obj")); | |
2108 } | |
2109 | |
2110 // Prepare function f that contains a polymorphic IC for object | |
2111 // originating from a different global context. | |
2112 v8::Context::GetCurrent()->Global()->Set(v8_str("obj1"), obj1); | |
2113 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1);"); | |
2114 Handle<JSFunction> f = | |
2115 v8::Utils::OpenHandle( | |
2116 *v8::Handle<v8::Function>::Cast( | |
2117 v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); | |
2118 | |
2119 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | |
2120 CHECK(ic_before->ic_state() == MONOMORPHIC); | |
2121 | |
2122 // Fire context dispose notification. | |
2123 v8::V8::ContextDisposedNotification(); | |
2124 | |
2125 // Go through all incremental marking steps in one swoop. | |
2126 IncrementalMarking* marking = HEAP->incremental_marking(); | |
2127 CHECK(marking->IsStopped()); | |
2128 marking->Start(); | |
2129 CHECK(marking->IsMarking()); | |
2130 while (!marking->IsComplete()) { | |
2131 marking->Step(MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); | |
2132 } | |
2133 CHECK(marking->IsComplete()); | |
2134 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | |
2135 CHECK(marking->IsStopped()); | |
2136 | |
2137 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | |
2138 CHECK(ic_after->ic_state() == UNINITIALIZED); | |
2139 } | |
2140 | |
2141 | |
2142 TEST(IncrementalMarkingClearsPolymorhpicIC) { | |
2143 if (i::FLAG_always_opt) return; | |
2144 InitializeVM(); | |
2145 v8::HandleScope scope; | |
2146 v8::Local<v8::Value> obj1, obj2; | |
2147 | |
2148 { | |
2149 LocalContext env; | |
2150 CompileRun("function fun() { this.x = 1; }; var obj = new fun();"); | |
2151 obj1 = env->Global()->Get(v8_str("obj")); | |
2152 } | |
2153 | |
2154 { | |
2155 LocalContext env; | |
2156 CompileRun("function fun() { this.x = 2; }; var obj = new fun();"); | |
2157 obj2 = env->Global()->Get(v8_str("obj")); | |
2158 } | |
2159 | |
2160 // Prepare function f that contains a polymorphic IC for objects | |
2161 // originating from two different global contexts. | |
2162 v8::Context::GetCurrent()->Global()->Set(v8_str("obj1"), obj1); | |
2163 v8::Context::GetCurrent()->Global()->Set(v8_str("obj2"), obj2); | |
2164 CompileRun("function f(o) { return o.x; } f(obj1); f(obj1); f(obj2);"); | |
2165 Handle<JSFunction> f = | |
2166 v8::Utils::OpenHandle( | |
2167 *v8::Handle<v8::Function>::Cast( | |
2168 v8::Context::GetCurrent()->Global()->Get(v8_str("f")))); | |
2169 | |
2170 Code* ic_before = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | |
2171 CHECK(ic_before->ic_state() == MEGAMORPHIC); | |
2172 | |
2173 // Fire context dispose notification. | |
2174 v8::V8::ContextDisposedNotification(); | |
2175 | |
2176 // Go through all incremental marking steps in one swoop. | |
2177 IncrementalMarking* marking = HEAP->incremental_marking(); | |
2178 CHECK(marking->IsStopped()); | |
2179 marking->Start(); | |
2180 CHECK(marking->IsMarking()); | |
2181 while (!marking->IsComplete()) { | |
2182 marking->Step(MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); | |
2183 } | |
2184 CHECK(marking->IsComplete()); | |
2185 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | |
2186 CHECK(marking->IsStopped()); | |
2187 | |
2188 Code* ic_after = FindFirstIC(f->shared()->code(), Code::LOAD_IC); | |
2189 CHECK(ic_after->ic_state() == UNINITIALIZED); | |
2190 } | |
OLD | NEW |