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

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

Issue 1670813005: Revert of Type Feedback Vector lives in the closure (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « test/cctest/interpreter/test-interpreter.cc ('k') | test/cctest/test-feedback-vector.cc » ('j') | 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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
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->feedback_vector()); 309 Handle<TypeFeedbackVector> feedback_vector(f->shared()->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->feedback_vector()->Get(slot_for_a); 324 object = f->shared()->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
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->feedback_vector()->is_empty()); 355 CHECK(f->shared()->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->feedback_vector()->is_empty()); 361 CHECK(!f->shared()->feedback_vector()->is_empty());
362 } 362 }
363 363
364 // Test that optimized code for different closures is actually shared. 364
365 // Test that optimized code for different closures is actually shared
366 // immediately by the FastNewClosureStub when run in the same context.
365 TEST(OptimizedCodeSharing1) { 367 TEST(OptimizedCodeSharing1) {
366 FLAG_stress_compaction = false; 368 FLAG_stress_compaction = false;
367 FLAG_allow_natives_syntax = true; 369 FLAG_allow_natives_syntax = true;
368 CcTest::InitializeVM(); 370 CcTest::InitializeVM();
369 v8::HandleScope scope(CcTest::isolate()); 371 v8::HandleScope scope(CcTest::isolate());
370 for (int i = 0; i < 3; i++) { 372 for (int i = 0; i < 3; i++) {
371 LocalContext env; 373 LocalContext env;
372 env->Global() 374 env->Global()
373 ->Set(env.local(), v8_str("x"), v8::Integer::New(CcTest::isolate(), i)) 375 ->Set(env.local(), v8_str("x"), v8::Integer::New(CcTest::isolate(), i))
374 .FromJust(); 376 .FromJust();
375 CompileRun( 377 CompileRun(
376 "function MakeClosure() {" 378 "function MakeClosure() {"
377 " return function() { return x; };" 379 " return function() { return x; };"
378 "}" 380 "}"
379 "var closure0 = MakeClosure();" 381 "var closure0 = MakeClosure();"
380 "%DebugPrint(closure0());" 382 "%DebugPrint(closure0());"
381 "%OptimizeFunctionOnNextCall(closure0);" 383 "%OptimizeFunctionOnNextCall(closure0);"
382 "%DebugPrint(closure0());" 384 "%DebugPrint(closure0());"
383 "var closure1 = MakeClosure(); closure1();" 385 "var closure1 = MakeClosure();"
384 "var closure2 = MakeClosure(); closure2();"); 386 "var closure2 = MakeClosure();");
385 Handle<JSFunction> fun1 = Handle<JSFunction>::cast( 387 Handle<JSFunction> fun1 = Handle<JSFunction>::cast(
386 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( 388 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
387 env->Global() 389 env->Global()
388 ->Get(env.local(), v8_str("closure1")) 390 ->Get(env.local(), v8_str("closure1"))
389 .ToLocalChecked()))); 391 .ToLocalChecked())));
390 Handle<JSFunction> fun2 = Handle<JSFunction>::cast( 392 Handle<JSFunction> fun2 = Handle<JSFunction>::cast(
391 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( 393 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
392 env->Global() 394 env->Global()
393 ->Get(env.local(), v8_str("closure2")) 395 ->Get(env.local(), v8_str("closure2"))
394 .ToLocalChecked()))); 396 .ToLocalChecked())));
395 CHECK(fun1->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); 397 CHECK(fun1->IsOptimized() || !CcTest::i_isolate()->use_crankshaft());
396 CHECK(fun2->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); 398 CHECK(fun2->IsOptimized() || !CcTest::i_isolate()->use_crankshaft());
397 CHECK_EQ(fun1->code(), fun2->code()); 399 CHECK_EQ(fun1->code(), fun2->code());
398 } 400 }
399 } 401 }
400 402
401 // Test that optimized code for different closures is actually shared. 403
404 // Test that optimized code for different closures is actually shared
405 // immediately by the FastNewClosureStub when run different contexts.
402 TEST(OptimizedCodeSharing2) { 406 TEST(OptimizedCodeSharing2) {
403 if (FLAG_stress_compaction) return; 407 if (FLAG_stress_compaction) return;
404 FLAG_allow_natives_syntax = true; 408 FLAG_allow_natives_syntax = true;
405 FLAG_native_context_specialization = false; 409 FLAG_native_context_specialization = false;
406 FLAG_turbo_cache_shared_code = true; 410 FLAG_turbo_cache_shared_code = true;
407 const char* flag = "--turbo-filter=*"; 411 const char* flag = "--turbo-filter=*";
408 FlagList::SetFlagsFromString(flag, StrLength(flag)); 412 FlagList::SetFlagsFromString(flag, StrLength(flag));
409 CcTest::InitializeVM(); 413 CcTest::InitializeVM();
410 v8::HandleScope scope(CcTest::isolate()); 414 v8::HandleScope scope(CcTest::isolate());
411 v8::Local<v8::Script> script = v8_compile( 415 v8::Local<v8::Script> script = v8_compile(
(...skipping 30 matching lines...) Expand all
442 .FromJust(); 446 .FromJust();
443 script->GetUnboundScript() 447 script->GetUnboundScript()
444 ->BindToCurrentContext() 448 ->BindToCurrentContext()
445 ->Run(env.local()) 449 ->Run(env.local())
446 .ToLocalChecked(); 450 .ToLocalChecked();
447 CompileRun( 451 CompileRun(
448 "var closure0 = MakeClosure();" 452 "var closure0 = MakeClosure();"
449 "%DebugPrint(closure0());" 453 "%DebugPrint(closure0());"
450 "%OptimizeFunctionOnNextCall(closure0);" 454 "%OptimizeFunctionOnNextCall(closure0);"
451 "%DebugPrint(closure0());" 455 "%DebugPrint(closure0());"
452 "var closure1 = MakeClosure(); closure1();" 456 "var closure1 = MakeClosure();"
453 "var closure2 = MakeClosure(); closure2();"); 457 "var closure2 = MakeClosure();");
454 Handle<JSFunction> fun1 = Handle<JSFunction>::cast( 458 Handle<JSFunction> fun1 = Handle<JSFunction>::cast(
455 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( 459 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
456 env->Global() 460 env->Global()
457 ->Get(env.local(), v8_str("closure1")) 461 ->Get(env.local(), v8_str("closure1"))
458 .ToLocalChecked()))); 462 .ToLocalChecked())));
459 Handle<JSFunction> fun2 = Handle<JSFunction>::cast( 463 Handle<JSFunction> fun2 = Handle<JSFunction>::cast(
460 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( 464 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
461 env->Global() 465 env->Global()
462 ->Get(env.local(), v8_str("closure2")) 466 ->Get(env.local(), v8_str("closure2"))
463 .ToLocalChecked()))); 467 .ToLocalChecked())));
464 CHECK(fun1->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); 468 CHECK(fun1->IsOptimized() || !CcTest::i_isolate()->use_crankshaft());
465 CHECK(fun2->IsOptimized() || !CcTest::i_isolate()->use_crankshaft()); 469 CHECK(fun2->IsOptimized() || !CcTest::i_isolate()->use_crankshaft());
466 CHECK_EQ(*reference_code, fun1->code()); 470 CHECK_EQ(*reference_code, fun1->code());
467 CHECK_EQ(*reference_code, fun2->code()); 471 CHECK_EQ(*reference_code, fun2->code());
468 } 472 }
469 } 473 }
470 474
471 // Test that optimized code for different closures is actually shared. 475
476 // Test that optimized code for different closures is actually shared
477 // immediately by the FastNewClosureStub without context-dependent entries.
472 TEST(OptimizedCodeSharing3) { 478 TEST(OptimizedCodeSharing3) {
473 if (FLAG_stress_compaction) return; 479 if (FLAG_stress_compaction) return;
474 FLAG_allow_natives_syntax = true; 480 FLAG_allow_natives_syntax = true;
475 FLAG_native_context_specialization = false; 481 FLAG_native_context_specialization = false;
476 FLAG_turbo_cache_shared_code = true; 482 FLAG_turbo_cache_shared_code = true;
477 const char* flag = "--turbo-filter=*"; 483 const char* flag = "--turbo-filter=*";
478 FlagList::SetFlagsFromString(flag, StrLength(flag)); 484 FlagList::SetFlagsFromString(flag, StrLength(flag));
479 CcTest::InitializeVM(); 485 CcTest::InitializeVM();
480 v8::HandleScope scope(CcTest::isolate()); 486 v8::HandleScope scope(CcTest::isolate());
481 v8::Local<v8::Script> script = v8_compile( 487 v8::Local<v8::Script> script = v8_compile(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 .FromJust(); 521 .FromJust();
516 script->GetUnboundScript() 522 script->GetUnboundScript()
517 ->BindToCurrentContext() 523 ->BindToCurrentContext()
518 ->Run(env.local()) 524 ->Run(env.local())
519 .ToLocalChecked(); 525 .ToLocalChecked();
520 CompileRun( 526 CompileRun(
521 "var closure0 = MakeClosure();" 527 "var closure0 = MakeClosure();"
522 "%DebugPrint(closure0());" 528 "%DebugPrint(closure0());"
523 "%OptimizeFunctionOnNextCall(closure0);" 529 "%OptimizeFunctionOnNextCall(closure0);"
524 "%DebugPrint(closure0());" 530 "%DebugPrint(closure0());"
525 "var closure1 = MakeClosure(); closure1();" 531 "var closure1 = MakeClosure();"
526 "var closure2 = MakeClosure(); closure2();"); 532 "var closure2 = MakeClosure();");
527 Handle<JSFunction> fun1 = Handle<JSFunction>::cast( 533 Handle<JSFunction> fun1 = Handle<JSFunction>::cast(
528 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( 534 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
529 env->Global() 535 env->Global()
530 ->Get(env.local(), v8_str("closure1")) 536 ->Get(env.local(), v8_str("closure1"))
531 .ToLocalChecked()))); 537 .ToLocalChecked())));
532 Handle<JSFunction> fun2 = Handle<JSFunction>::cast( 538 Handle<JSFunction> fun2 = Handle<JSFunction>::cast(
533 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( 539 v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
534 env->Global() 540 env->Global()
535 ->Get(env.local(), v8_str("closure2")) 541 ->Get(env.local(), v8_str("closure2"))
536 .ToLocalChecked()))); 542 .ToLocalChecked())));
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 CompileRun("function f() { a = 12345678 }; f();"); 753 CompileRun("function f() { a = 12345678 }; f();");
748 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 754 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
749 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); 755 CompileRun("function f(x) { a = 12345678 + x}; f(1);");
750 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 756 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
751 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); 757 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);");
752 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 758 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
753 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); 759 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);");
754 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f")); 760 CheckCodeForUnsafeLiteral(GetJSFunction(context->Global(), "f"));
755 } 761 }
756 #endif 762 #endif
OLDNEW
« no previous file with comments | « test/cctest/interpreter/test-interpreter.cc ('k') | test/cctest/test-feedback-vector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698