| 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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 "fun1 = fun;" | 299 "fun1 = fun;" |
| 300 "function f(a) { a(); } f(fun1);"); | 300 "function f(a) { a(); } f(fun1);"); |
| 301 | 301 |
| 302 Handle<JSFunction> f = Handle<JSFunction>::cast( | 302 Handle<JSFunction> f = Handle<JSFunction>::cast( |
| 303 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 303 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 304 CcTest::global()->Get(context, v8_str("f")).ToLocalChecked()))); | 304 CcTest::global()->Get(context, v8_str("f")).ToLocalChecked()))); |
| 305 | 305 |
| 306 // We shouldn't have deoptimization support. We want to recompile and | 306 // We shouldn't have deoptimization support. We want to recompile and |
| 307 // verify that our feedback vector preserves information. | 307 // verify that our feedback vector preserves information. |
| 308 CHECK(!f->shared()->has_deoptimization_support()); | 308 CHECK(!f->shared()->has_deoptimization_support()); |
| 309 Handle<TypeFeedbackVector> feedback_vector(f->shared()->feedback_vector()); | 309 Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector()); |
| 310 | 310 |
| 311 // Verify that we gathered feedback. | 311 // Verify that we gathered feedback. |
| 312 CHECK(!feedback_vector->is_empty()); | 312 CHECK(!feedback_vector->is_empty()); |
| 313 FeedbackVectorSlot slot_for_a(0); | 313 FeedbackVectorSlot slot_for_a(0); |
| 314 Object* object = feedback_vector->Get(slot_for_a); | 314 Object* object = feedback_vector->Get(slot_for_a); |
| 315 CHECK(object->IsWeakCell() && | 315 CHECK(object->IsWeakCell() && |
| 316 WeakCell::cast(object)->value()->IsJSFunction()); | 316 WeakCell::cast(object)->value()->IsJSFunction()); |
| 317 | 317 |
| 318 CompileRun("%OptimizeFunctionOnNextCall(f); f(fun1);"); | 318 CompileRun("%OptimizeFunctionOnNextCall(f); f(fun1);"); |
| 319 | 319 |
| 320 // Verify that the feedback is still "gathered" despite a recompilation | 320 // Verify that the feedback is still "gathered" despite a recompilation |
| 321 // of the full code. | 321 // of the full code. |
| 322 CHECK(f->IsOptimized()); | 322 CHECK(f->IsOptimized()); |
| 323 CHECK(f->shared()->has_deoptimization_support()); | 323 CHECK(f->shared()->has_deoptimization_support()); |
| 324 object = f->shared()->feedback_vector()->Get(slot_for_a); | 324 object = f->feedback_vector()->Get(slot_for_a); |
| 325 CHECK(object->IsWeakCell() && | 325 CHECK(object->IsWeakCell() && |
| 326 WeakCell::cast(object)->value()->IsJSFunction()); | 326 WeakCell::cast(object)->value()->IsJSFunction()); |
| 327 } | 327 } |
| 328 | 328 |
| 329 | 329 |
| 330 TEST(FeedbackVectorUnaffectedByScopeChanges) { | 330 TEST(FeedbackVectorUnaffectedByScopeChanges) { |
| 331 if (i::FLAG_always_opt || !i::FLAG_lazy) return; | 331 if (i::FLAG_always_opt || !i::FLAG_lazy) return; |
| 332 CcTest::InitializeVM(); | 332 CcTest::InitializeVM(); |
| 333 v8::HandleScope scope(CcTest::isolate()); | 333 v8::HandleScope scope(CcTest::isolate()); |
| 334 v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext(); | 334 v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 345 "}" | 345 "}" |
| 346 "morphing_call = builder();"); | 346 "morphing_call = builder();"); |
| 347 | 347 |
| 348 Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle( | 348 Handle<JSFunction> f = Handle<JSFunction>::cast(v8::Utils::OpenHandle( |
| 349 *v8::Local<v8::Function>::Cast(CcTest::global() | 349 *v8::Local<v8::Function>::Cast(CcTest::global() |
| 350 ->Get(context, v8_str("morphing_call")) | 350 ->Get(context, v8_str("morphing_call")) |
| 351 .ToLocalChecked()))); | 351 .ToLocalChecked()))); |
| 352 | 352 |
| 353 // Not compiled, and so no feedback vector allocated yet. | 353 // Not compiled, and so no feedback vector allocated yet. |
| 354 CHECK(!f->shared()->is_compiled()); | 354 CHECK(!f->shared()->is_compiled()); |
| 355 CHECK(f->shared()->feedback_vector()->is_empty()); | 355 CHECK(f->feedback_vector()->is_empty()); |
| 356 | 356 |
| 357 CompileRun("morphing_call();"); | 357 CompileRun("morphing_call();"); |
| 358 | 358 |
| 359 // Now a feedback vector is allocated. | 359 // Now a feedback vector is allocated. |
| 360 CHECK(f->shared()->is_compiled()); | 360 CHECK(f->shared()->is_compiled()); |
| 361 CHECK(!f->shared()->feedback_vector()->is_empty()); | 361 CHECK(!f->feedback_vector()->is_empty()); |
| 362 } | 362 } |
| 363 | 363 |
| 364 | 364 // Test that optimized code for different closures is actually shared. |
| 365 // Test that optimized code for different closures is actually shared | |
| 366 // immediately by the FastNewClosureStub when run in the same context. | |
| 367 TEST(OptimizedCodeSharing1) { | 365 TEST(OptimizedCodeSharing1) { |
| 368 FLAG_stress_compaction = false; | 366 FLAG_stress_compaction = false; |
| 369 FLAG_allow_natives_syntax = true; | 367 FLAG_allow_natives_syntax = true; |
| 370 CcTest::InitializeVM(); | 368 CcTest::InitializeVM(); |
| 371 v8::HandleScope scope(CcTest::isolate()); | 369 v8::HandleScope scope(CcTest::isolate()); |
| 372 for (int i = 0; i < 3; i++) { | 370 for (int i = 0; i < 3; i++) { |
| 373 LocalContext env; | 371 LocalContext env; |
| 374 env->Global() | 372 env->Global() |
| 375 ->Set(env.local(), v8_str("x"), v8::Integer::New(CcTest::isolate(), i)) | 373 ->Set(env.local(), v8_str("x"), v8::Integer::New(CcTest::isolate(), i)) |
| 376 .FromJust(); | 374 .FromJust(); |
| 377 CompileRun( | 375 CompileRun( |
| 378 "function MakeClosure() {" | 376 "function MakeClosure() {" |
| 379 " return function() { return x; };" | 377 " return function() { return x; };" |
| 380 "}" | 378 "}" |
| 381 "var closure0 = MakeClosure();" | 379 "var closure0 = MakeClosure();" |
| 382 "%DebugPrint(closure0());" | 380 "%DebugPrint(closure0());" |
| 383 "%OptimizeFunctionOnNextCall(closure0);" | 381 "%OptimizeFunctionOnNextCall(closure0);" |
| 384 "%DebugPrint(closure0());" | 382 "%DebugPrint(closure0());" |
| 385 "var closure1 = MakeClosure();" | 383 "var closure1 = MakeClosure(); closure1();" |
| 386 "var closure2 = MakeClosure();"); | 384 "var closure2 = MakeClosure(); closure2();"); |
| 387 Handle<JSFunction> fun1 = Handle<JSFunction>::cast( | 385 Handle<JSFunction> fun1 = Handle<JSFunction>::cast( |
| 388 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 386 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 389 env->Global() | 387 env->Global() |
| 390 ->Get(env.local(), v8_str("closure1")) | 388 ->Get(env.local(), v8_str("closure1")) |
| 391 .ToLocalChecked()))); | 389 .ToLocalChecked()))); |
| 392 Handle<JSFunction> fun2 = Handle<JSFunction>::cast( | 390 Handle<JSFunction> fun2 = Handle<JSFunction>::cast( |
| 393 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 391 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 394 env->Global() | 392 env->Global() |
| 395 ->Get(env.local(), v8_str("closure2")) | 393 ->Get(env.local(), v8_str("closure2")) |
| 396 .ToLocalChecked()))); | 394 .ToLocalChecked()))); |
| 397 CHECK(fun1->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); | 395 CHECK(fun1->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); |
| 398 CHECK(fun2->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); | 396 CHECK(fun2->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); |
| 399 CHECK_EQ(fun1->code(), fun2->code()); | 397 CHECK_EQ(fun1->code(), fun2->code()); |
| 400 } | 398 } |
| 401 } | 399 } |
| 402 | 400 |
| 403 | 401 // Test that optimized code for different closures is actually shared. |
| 404 // Test that optimized code for different closures is actually shared | |
| 405 // immediately by the FastNewClosureStub when run different contexts. | |
| 406 TEST(OptimizedCodeSharing2) { | 402 TEST(OptimizedCodeSharing2) { |
| 407 if (FLAG_stress_compaction) return; | 403 if (FLAG_stress_compaction) return; |
| 408 FLAG_allow_natives_syntax = true; | 404 FLAG_allow_natives_syntax = true; |
| 409 FLAG_native_context_specialization = false; | 405 FLAG_native_context_specialization = false; |
| 410 FLAG_turbo_cache_shared_code = true; | 406 FLAG_turbo_cache_shared_code = true; |
| 411 const char* flag = "--turbo-filter=*"; | 407 const char* flag = "--turbo-filter=*"; |
| 412 FlagList::SetFlagsFromString(flag, StrLength(flag)); | 408 FlagList::SetFlagsFromString(flag, StrLength(flag)); |
| 413 CcTest::InitializeVM(); | 409 CcTest::InitializeVM(); |
| 414 v8::HandleScope scope(CcTest::isolate()); | 410 v8::HandleScope scope(CcTest::isolate()); |
| 415 v8::Local<v8::Script> script = v8_compile( | 411 v8::Local<v8::Script> script = v8_compile( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 446 .FromJust(); | 442 .FromJust(); |
| 447 script->GetUnboundScript() | 443 script->GetUnboundScript() |
| 448 ->BindToCurrentContext() | 444 ->BindToCurrentContext() |
| 449 ->Run(env.local()) | 445 ->Run(env.local()) |
| 450 .ToLocalChecked(); | 446 .ToLocalChecked(); |
| 451 CompileRun( | 447 CompileRun( |
| 452 "var closure0 = MakeClosure();" | 448 "var closure0 = MakeClosure();" |
| 453 "%DebugPrint(closure0());" | 449 "%DebugPrint(closure0());" |
| 454 "%OptimizeFunctionOnNextCall(closure0);" | 450 "%OptimizeFunctionOnNextCall(closure0);" |
| 455 "%DebugPrint(closure0());" | 451 "%DebugPrint(closure0());" |
| 456 "var closure1 = MakeClosure();" | 452 "var closure1 = MakeClosure(); closure1();" |
| 457 "var closure2 = MakeClosure();"); | 453 "var closure2 = MakeClosure(); closure2();"); |
| 458 Handle<JSFunction> fun1 = Handle<JSFunction>::cast( | 454 Handle<JSFunction> fun1 = Handle<JSFunction>::cast( |
| 459 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 455 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 460 env->Global() | 456 env->Global() |
| 461 ->Get(env.local(), v8_str("closure1")) | 457 ->Get(env.local(), v8_str("closure1")) |
| 462 .ToLocalChecked()))); | 458 .ToLocalChecked()))); |
| 463 Handle<JSFunction> fun2 = Handle<JSFunction>::cast( | 459 Handle<JSFunction> fun2 = Handle<JSFunction>::cast( |
| 464 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 460 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 465 env->Global() | 461 env->Global() |
| 466 ->Get(env.local(), v8_str("closure2")) | 462 ->Get(env.local(), v8_str("closure2")) |
| 467 .ToLocalChecked()))); | 463 .ToLocalChecked()))); |
| 468 CHECK(fun1->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); | 464 CHECK(fun1->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); |
| 469 CHECK(fun2->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); | 465 CHECK(fun2->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); |
| 470 CHECK_EQ(*reference_code, fun1->code()); | 466 CHECK_EQ(*reference_code, fun1->code()); |
| 471 CHECK_EQ(*reference_code, fun2->code()); | 467 CHECK_EQ(*reference_code, fun2->code()); |
| 472 } | 468 } |
| 473 } | 469 } |
| 474 | 470 |
| 475 | 471 // Test that optimized code for different closures is actually shared. |
| 476 // Test that optimized code for different closures is actually shared | |
| 477 // immediately by the FastNewClosureStub without context-dependent entries. | |
| 478 TEST(OptimizedCodeSharing3) { | 472 TEST(OptimizedCodeSharing3) { |
| 479 if (FLAG_stress_compaction) return; | 473 if (FLAG_stress_compaction) return; |
| 480 FLAG_allow_natives_syntax = true; | 474 FLAG_allow_natives_syntax = true; |
| 481 FLAG_native_context_specialization = false; | 475 FLAG_native_context_specialization = false; |
| 482 FLAG_turbo_cache_shared_code = true; | 476 FLAG_turbo_cache_shared_code = true; |
| 483 const char* flag = "--turbo-filter=*"; | 477 const char* flag = "--turbo-filter=*"; |
| 484 FlagList::SetFlagsFromString(flag, StrLength(flag)); | 478 FlagList::SetFlagsFromString(flag, StrLength(flag)); |
| 485 CcTest::InitializeVM(); | 479 CcTest::InitializeVM(); |
| 486 v8::HandleScope scope(CcTest::isolate()); | 480 v8::HandleScope scope(CcTest::isolate()); |
| 487 v8::Local<v8::Script> script = v8_compile( | 481 v8::Local<v8::Script> script = v8_compile( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 .FromJust(); | 515 .FromJust(); |
| 522 script->GetUnboundScript() | 516 script->GetUnboundScript() |
| 523 ->BindToCurrentContext() | 517 ->BindToCurrentContext() |
| 524 ->Run(env.local()) | 518 ->Run(env.local()) |
| 525 .ToLocalChecked(); | 519 .ToLocalChecked(); |
| 526 CompileRun( | 520 CompileRun( |
| 527 "var closure0 = MakeClosure();" | 521 "var closure0 = MakeClosure();" |
| 528 "%DebugPrint(closure0());" | 522 "%DebugPrint(closure0());" |
| 529 "%OptimizeFunctionOnNextCall(closure0);" | 523 "%OptimizeFunctionOnNextCall(closure0);" |
| 530 "%DebugPrint(closure0());" | 524 "%DebugPrint(closure0());" |
| 531 "var closure1 = MakeClosure();" | 525 "var closure1 = MakeClosure(); closure1();" |
| 532 "var closure2 = MakeClosure();"); | 526 "var closure2 = MakeClosure(); closure2();"); |
| 533 Handle<JSFunction> fun1 = Handle<JSFunction>::cast( | 527 Handle<JSFunction> fun1 = Handle<JSFunction>::cast( |
| 534 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 528 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 535 env->Global() | 529 env->Global() |
| 536 ->Get(env.local(), v8_str("closure1")) | 530 ->Get(env.local(), v8_str("closure1")) |
| 537 .ToLocalChecked()))); | 531 .ToLocalChecked()))); |
| 538 Handle<JSFunction> fun2 = Handle<JSFunction>::cast( | 532 Handle<JSFunction> fun2 = Handle<JSFunction>::cast( |
| 539 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( | 533 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( |
| 540 env->Global() | 534 env->Global() |
| 541 ->Get(env.local(), v8_str("closure2")) | 535 ->Get(env.local(), v8_str("closure2")) |
| 542 .ToLocalChecked()))); | 536 .ToLocalChecked()))); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 CompileRun("function f() { a = 12345678 }; f();"); | 747 CompileRun("function f() { a = 12345678 }; f();"); |
| 754 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 748 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 755 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); | 749 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); |
| 756 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 750 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 757 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); | 751 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); |
| 758 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 752 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 759 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); | 753 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); |
| 760 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); | 754 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); |
| 761 } | 755 } |
| 762 #endif | 756 #endif |
| OLD | NEW |