Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: test/cctest/test-compiler.cc

Issue 10544205: Fix optimized code caching in FastNewClosureStub. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/mips/code-stubs-mips.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 memcpy(&buffer[i], function_f, sizeof(function_f) - 1); 345 memcpy(&buffer[i], function_f, sizeof(function_f) - 1);
346 v8::Handle<v8::String> script_body = v8::String::New(buffer.start()); 346 v8::Handle<v8::String> script_body = v8::String::New(buffer.start());
347 v8::Script::Compile(script_body, &origin)->Run(); 347 v8::Script::Compile(script_body, &origin)->Run();
348 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 348 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
349 env->Global()->Get(v8::String::New("f"))); 349 env->Global()->Get(v8::String::New("f")));
350 CHECK_EQ(i, f->GetScriptLineNumber()); 350 CHECK_EQ(i, f->GetScriptLineNumber());
351 } 351 }
352 } 352 }
353 353
354 354
355 // Test that optimized code for different closures is actually shared
356 // immediately by the FastNewClosureStub when run in the same context.
357 TEST(OptimizedCodeSharing) {
358 FLAG_allow_natives_syntax = true;
359 InitializeVM();
360 v8::HandleScope scope;
361 for (int i = 0; i < 10; i++) {
362 LocalContext env;
363 env->Global()->Set(v8::String::New("x"), v8::Integer::New(i));
364 CompileRun("function MakeClosure() {"
365 " return function() { return x; };"
366 "}"
367 "var closure0 = MakeClosure();"
368 "%DebugPrint(closure0());"
369 "%OptimizeFunctionOnNextCall(closure0);"
370 "%DebugPrint(closure0());"
371 "var closure1 = MakeClosure();"
372 "var closure2 = MakeClosure();");
373 Handle<JSFunction> fun1 = v8::Utils::OpenHandle(
374 *v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("closure1"))));
375 Handle<JSFunction> fun2 = v8::Utils::OpenHandle(
376 *v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("closure2"))));
377 CHECK(fun1->IsOptimized() || !FLAG_crankshaft);
378 CHECK(fun2->IsOptimized() || !FLAG_crankshaft);
379 CHECK_EQ(fun1->code(), fun2->code());
380 }
381 }
382
383
355 #ifdef ENABLE_DISASSEMBLER 384 #ifdef ENABLE_DISASSEMBLER
356 static Handle<JSFunction> GetJSFunction(v8::Handle<v8::Object> obj, 385 static Handle<JSFunction> GetJSFunction(v8::Handle<v8::Object> obj,
357 const char* property_name) { 386 const char* property_name) {
358 v8::Local<v8::Function> fun = 387 v8::Local<v8::Function> fun =
359 v8::Local<v8::Function>::Cast(obj->Get(v8_str(property_name))); 388 v8::Local<v8::Function>::Cast(obj->Get(v8_str(property_name)));
360 return v8::Utils::OpenHandle(*fun); 389 return v8::Utils::OpenHandle(*fun);
361 } 390 }
362 391
363 392
364 static void CheckCodeForUnsafeLiteral(Handle<JSFunction> f) { 393 static void CheckCodeForUnsafeLiteral(Handle<JSFunction> f) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 CompileRun("function f() { a = 12345678 }; f();"); 425 CompileRun("function f() { a = 12345678 }; f();");
397 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); 426 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f"));
398 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); 427 CompileRun("function f(x) { a = 12345678 + x}; f(1);");
399 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); 428 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f"));
400 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); 429 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);");
401 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); 430 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f"));
402 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); 431 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);");
403 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f")); 432 CheckCodeForUnsafeLiteral(GetJSFunction(env->Global(), "f"));
404 } 433 }
405 #endif 434 #endif
OLDNEW
« no previous file with comments | « src/mips/code-stubs-mips.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698