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