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 "compilation-cache.h" | |
8 #include "execution.h" | 7 #include "execution.h" |
9 #include "factory.h" | 8 #include "factory.h" |
10 #include "macro-assembler.h" | 9 #include "macro-assembler.h" |
11 #include "global-handles.h" | 10 #include "global-handles.h" |
12 #include "stub-cache.h" | |
13 #include "cctest.h" | 11 #include "cctest.h" |
14 | 12 |
15 using namespace v8::internal; | 13 using namespace v8::internal; |
16 | 14 |
17 static v8::Persistent<v8::Context> env; | 15 static v8::Persistent<v8::Context> env; |
18 | 16 |
19 static void InitializeVM() { | 17 static void InitializeVM() { |
20 if (env.IsEmpty()) env = v8::Context::New(); | 18 if (env.IsEmpty()) env = v8::Context::New(); |
21 v8::HandleScope scope; | 19 v8::HandleScope scope; |
22 env->Enter(); | 20 env->Enter(); |
(...skipping 2216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2239 // External source is being retained by the stack trace. | 2237 // External source is being retained by the stack trace. |
2240 CHECK(!resource->IsDisposed()); | 2238 CHECK(!resource->IsDisposed()); |
2241 | 2239 |
2242 CompileRun("error.stack; error.stack;"); | 2240 CompileRun("error.stack; error.stack;"); |
2243 HEAP->CollectAllAvailableGarbage(); | 2241 HEAP->CollectAllAvailableGarbage(); |
2244 // External source has been released. | 2242 // External source has been released. |
2245 CHECK(resource->IsDisposed()); | 2243 CHECK(resource->IsDisposed()); |
2246 | 2244 |
2247 delete resource; | 2245 delete resource; |
2248 } | 2246 } |
2249 | |
2250 | |
2251 TEST(Regression144230) { | |
2252 InitializeVM(); | |
2253 v8::HandleScope scope; | |
2254 | |
2255 // First make sure that the uninitialized CallIC stub is on a single page | |
2256 // that will later be selected as an evacuation candidate. | |
2257 { | |
2258 v8::HandleScope inner_scope; | |
2259 AlwaysAllocateScope always_allocate; | |
2260 SimulateFullSpace(HEAP->code_space()); | |
2261 ISOLATE->stub_cache()->ComputeCallInitialize(9, RelocInfo::CODE_TARGET); | |
2262 } | |
2263 | |
2264 // Second compile a CallIC and execute it once so that it gets patched to | |
2265 // the pre-monomorphic stub. These code objects are on yet another page. | |
2266 { | |
2267 v8::HandleScope inner_scope; | |
2268 AlwaysAllocateScope always_allocate; | |
2269 SimulateFullSpace(HEAP->code_space()); | |
2270 CompileRun("var o = { f:function(a,b,c,d,e,f,g,h,i) {}};" | |
2271 "function call() { o.f(1,2,3,4,5,6,7,8,9); };" | |
2272 "call();"); | |
2273 } | |
2274 | |
2275 // Third we fill up the last page of the code space so that it does not get | |
2276 // chosen as an evacuation candidate. | |
2277 { | |
2278 v8::HandleScope inner_scope; | |
2279 AlwaysAllocateScope always_allocate; | |
2280 CompileRun("for (var i = 0; i < 2000; i++) {" | |
2281 " eval('function f' + i + '() { return ' + i +'; };' +" | |
2282 " 'f' + i + '();');" | |
2283 "}"); | |
2284 } | |
2285 HEAP->CollectAllGarbage(Heap::kNoGCFlags); | |
2286 | |
2287 // Fourth is the tricky part. Make sure the code containing the CallIC is | |
2288 // visited first without clearing the IC. The shared function info is then | |
2289 // visited later, causing the CallIC to be cleared. | |
2290 Handle<String> name = FACTORY->LookupAsciiSymbol("call"); | |
2291 Handle<GlobalObject> global(ISOLATE->context()->global_object()); | |
2292 MaybeObject* maybe_call = global->GetProperty(*name); | |
2293 JSFunction* call = JSFunction::cast(maybe_call->ToObjectChecked()); | |
2294 USE(global->SetProperty(*name, Smi::FromInt(0), NONE, kNonStrictMode)); | |
2295 ISOLATE->compilation_cache()->Clear(); | |
2296 call->shared()->set_ic_age(HEAP->global_ic_age() + 1); | |
2297 Handle<Object> call_code(call->code()); | |
2298 Handle<Object> call_function(call); | |
2299 | |
2300 // Now we are ready to mess up the heap. | |
2301 HEAP->CollectAllGarbage(Heap::kReduceMemoryFootprintMask); | |
2302 | |
2303 // Either heap verification caught the problem already or we go kaboom once | |
2304 // the CallIC is executed the next time. | |
2305 USE(global->SetProperty(*name, *call_function, NONE, kNonStrictMode)); | |
2306 CompileRun("call();"); | |
2307 } | |
OLD | NEW |