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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 | 369 |
370 | 370 |
371 // Test that optimized code for different closures is actually shared | 371 // Test that optimized code for different closures is actually shared |
372 // immediately by the FastNewClosureStub when run in the same context. | 372 // immediately by the FastNewClosureStub when run in the same context. |
373 TEST(OptimizedCodeSharing1) { | 373 TEST(OptimizedCodeSharing1) { |
374 FLAG_stress_compaction = false; | 374 FLAG_stress_compaction = false; |
375 FLAG_allow_natives_syntax = true; | 375 FLAG_allow_natives_syntax = true; |
376 FLAG_cache_optimized_code = true; | 376 FLAG_cache_optimized_code = true; |
377 CcTest::InitializeVM(); | 377 CcTest::InitializeVM(); |
378 v8::HandleScope scope(CcTest::isolate()); | 378 v8::HandleScope scope(CcTest::isolate()); |
379 for (int i = 0; i < 10; i++) { | 379 for (int i = 0; i < 3; i++) { |
380 LocalContext env; | 380 LocalContext env; |
381 env->Global()->Set(v8::String::NewFromUtf8(CcTest::isolate(), "x"), | 381 env->Global()->Set(v8::String::NewFromUtf8(CcTest::isolate(), "x"), |
382 v8::Integer::New(CcTest::isolate(), i)); | 382 v8::Integer::New(CcTest::isolate(), i)); |
383 CompileRun( | 383 CompileRun( |
384 "function MakeClosure() {" | 384 "function MakeClosure() {" |
385 " return function() { return x; };" | 385 " return function() { return x; };" |
386 "}" | 386 "}" |
387 "var closure0 = MakeClosure();" | 387 "var closure0 = MakeClosure();" |
388 "%DebugPrint(closure0());" | 388 "%DebugPrint(closure0());" |
389 "%OptimizeFunctionOnNextCall(closure0);" | 389 "%OptimizeFunctionOnNextCall(closure0);" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 CompileRun( | 425 CompileRun( |
426 "var closure0 = MakeClosure();" | 426 "var closure0 = MakeClosure();" |
427 "%DebugPrint(closure0());" | 427 "%DebugPrint(closure0());" |
428 "%OptimizeFunctionOnNextCall(closure0);" | 428 "%OptimizeFunctionOnNextCall(closure0);" |
429 "%DebugPrint(closure0());"); | 429 "%DebugPrint(closure0());"); |
430 Handle<JSFunction> fun0 = v8::Utils::OpenHandle( | 430 Handle<JSFunction> fun0 = v8::Utils::OpenHandle( |
431 *v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("closure0")))); | 431 *v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("closure0")))); |
432 CHECK(fun0->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); | 432 CHECK(fun0->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); |
433 reference_code = handle(fun0->code()); | 433 reference_code = handle(fun0->code()); |
434 } | 434 } |
435 for (int i = 0; i < 10; i++) { | 435 for (int i = 0; i < 3; i++) { |
436 LocalContext env; | 436 LocalContext env; |
437 env->Global()->Set(v8::String::NewFromUtf8(CcTest::isolate(), "x"), | 437 env->Global()->Set(v8::String::NewFromUtf8(CcTest::isolate(), "x"), |
438 v8::Integer::New(CcTest::isolate(), i)); | 438 v8::Integer::New(CcTest::isolate(), i)); |
439 script->GetUnboundScript()->BindToCurrentContext()->Run(); | 439 script->GetUnboundScript()->BindToCurrentContext()->Run(); |
440 CompileRun( | 440 CompileRun( |
441 "var closure0 = MakeClosure();" | 441 "var closure0 = MakeClosure();" |
442 "%DebugPrint(closure0());" | 442 "%DebugPrint(closure0());" |
443 "%OptimizeFunctionOnNextCall(closure0);" | 443 "%OptimizeFunctionOnNextCall(closure0);" |
444 "%DebugPrint(closure0());" | 444 "%DebugPrint(closure0());" |
445 "var closure1 = MakeClosure();" | 445 "var closure1 = MakeClosure();" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 "%OptimizeFunctionOnNextCall(closure0);" | 483 "%OptimizeFunctionOnNextCall(closure0);" |
484 "%DebugPrint(closure0());"); | 484 "%DebugPrint(closure0());"); |
485 Handle<JSFunction> fun0 = v8::Utils::OpenHandle( | 485 Handle<JSFunction> fun0 = v8::Utils::OpenHandle( |
486 *v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("closure0")))); | 486 *v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("closure0")))); |
487 CHECK(fun0->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); | 487 CHECK(fun0->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); |
488 reference_code = handle(fun0->code()); | 488 reference_code = handle(fun0->code()); |
489 // Evict only the context-dependent entry from the optimized code map. This | 489 // Evict only the context-dependent entry from the optimized code map. This |
490 // leaves it in a state where only the context-independent entry exists. | 490 // leaves it in a state where only the context-independent entry exists. |
491 fun0->shared()->TrimOptimizedCodeMap(SharedFunctionInfo::kEntryLength); | 491 fun0->shared()->TrimOptimizedCodeMap(SharedFunctionInfo::kEntryLength); |
492 } | 492 } |
493 for (int i = 0; i < 10; i++) { | 493 for (int i = 0; i < 3; i++) { |
494 LocalContext env; | 494 LocalContext env; |
495 env->Global()->Set(v8::String::NewFromUtf8(CcTest::isolate(), "x"), | 495 env->Global()->Set(v8::String::NewFromUtf8(CcTest::isolate(), "x"), |
496 v8::Integer::New(CcTest::isolate(), i)); | 496 v8::Integer::New(CcTest::isolate(), i)); |
497 script->GetUnboundScript()->BindToCurrentContext()->Run(); | 497 script->GetUnboundScript()->BindToCurrentContext()->Run(); |
498 CompileRun( | 498 CompileRun( |
499 "var closure0 = MakeClosure();" | 499 "var closure0 = MakeClosure();" |
500 "%DebugPrint(closure0());" | 500 "%DebugPrint(closure0());" |
501 "%OptimizeFunctionOnNextCall(closure0);" | 501 "%OptimizeFunctionOnNextCall(closure0);" |
502 "%DebugPrint(closure0());" | 502 "%DebugPrint(closure0());" |
503 "var closure1 = MakeClosure();" | 503 "var closure1 = MakeClosure();" |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 CompileRun("function f() { a = 12345678 }; f();"); | 698 CompileRun("function f() { a = 12345678 }; f();"); |
699 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 699 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
700 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); | 700 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); |
701 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 701 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
702 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); | 702 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); |
703 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 703 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
704 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); | 704 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); |
705 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 705 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
706 } | 706 } |
707 #endif | 707 #endif |
OLD | NEW |