| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 #include "test/cctest/cctest.h" | 6 #include "test/cctest/cctest.h" |
| 7 | 7 |
| 8 #include "src/api.h" | 8 #include "src/api.h" |
| 9 #include "src/debug/debug.h" | 9 #include "src/debug/debug.h" |
| 10 #include "src/execution.h" | 10 #include "src/execution.h" |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 " return y;" | 409 " return y;" |
| 410 "}" | 410 "}" |
| 411 "a = 3;" | 411 "a = 3;" |
| 412 "testvar({});"); | 412 "testvar({});"); |
| 413 | 413 |
| 414 Handle<JSFunction> f = GetFunction("testvar"); | 414 Handle<JSFunction> f = GetFunction("testvar"); |
| 415 | 415 |
| 416 // There should be two LOAD_ICs, one for a and one for y at the end. | 416 // There should be two LOAD_ICs, one for a and one for y at the end. |
| 417 Handle<TypeFeedbackVector> feedback_vector = | 417 Handle<TypeFeedbackVector> feedback_vector = |
| 418 handle(f->shared()->feedback_vector(), isolate); | 418 handle(f->shared()->feedback_vector(), isolate); |
| 419 if (FLAG_vector_stores) { | 419 CHECK_EQ(2, feedback_vector->ICSlots()); |
| 420 CHECK_EQ(4, feedback_vector->ICSlots()); | 420 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(0)) == Code::LOAD_IC); |
| 421 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(0)) == Code::STORE_IC); | 421 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(1)) == Code::LOAD_IC); |
| 422 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(1)) == Code::LOAD_IC); | |
| 423 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(2)) == Code::STORE_IC); | |
| 424 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(3)) == Code::LOAD_IC); | |
| 425 } else { | |
| 426 CHECK_EQ(2, feedback_vector->ICSlots()); | |
| 427 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(0)) == Code::LOAD_IC); | |
| 428 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(1)) == Code::LOAD_IC); | |
| 429 } | |
| 430 | 422 |
| 431 CompileRun( | 423 CompileRun( |
| 432 "function testprop(x) {" | 424 "function testprop(x) {" |
| 433 " x.blue = a;" | 425 " x.blue = a;" |
| 434 "}" | 426 "}" |
| 435 "testprop({ blue: 3 });"); | 427 "testprop({ blue: 3 });"); |
| 436 | 428 |
| 437 f = GetFunction("testprop"); | 429 f = GetFunction("testprop"); |
| 438 | 430 |
| 439 // There should be one LOAD_IC, for the load of a. | 431 // There should be one LOAD_IC, for the load of a. |
| 440 feedback_vector = handle(f->shared()->feedback_vector(), isolate); | 432 feedback_vector = handle(f->shared()->feedback_vector(), isolate); |
| 441 if (FLAG_vector_stores) { | 433 CHECK_EQ(1, feedback_vector->ICSlots()); |
| 442 CHECK_EQ(2, feedback_vector->ICSlots()); | |
| 443 } else { | |
| 444 CHECK_EQ(1, feedback_vector->ICSlots()); | |
| 445 } | |
| 446 | 434 |
| 447 CompileRun( | 435 CompileRun( |
| 448 "function testpropfunc(x) {" | 436 "function testpropfunc(x) {" |
| 449 " x().blue = a;" | 437 " x().blue = a;" |
| 450 " return x().blue;" | 438 " return x().blue;" |
| 451 "}" | 439 "}" |
| 452 "function makeresult() { return { blue: 3 }; }" | 440 "function makeresult() { return { blue: 3 }; }" |
| 453 "testpropfunc(makeresult);"); | 441 "testpropfunc(makeresult);"); |
| 454 | 442 |
| 455 f = GetFunction("testpropfunc"); | 443 f = GetFunction("testpropfunc"); |
| 456 | 444 |
| 457 // There should be 2 LOAD_ICs and 2 CALL_ICs. | 445 // There should be 2 LOAD_ICs and 2 CALL_ICs. |
| 458 feedback_vector = handle(f->shared()->feedback_vector(), isolate); | 446 feedback_vector = handle(f->shared()->feedback_vector(), isolate); |
| 459 if (FLAG_vector_stores) { | 447 CHECK_EQ(4, feedback_vector->ICSlots()); |
| 460 CHECK_EQ(5, feedback_vector->ICSlots()); | 448 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(0)) == Code::CALL_IC); |
| 461 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(0)) == Code::CALL_IC); | 449 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(1)) == Code::LOAD_IC); |
| 462 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(1)) == Code::LOAD_IC); | 450 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(2)) == Code::CALL_IC); |
| 463 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(2)) == Code::STORE_IC); | 451 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(3)) == Code::LOAD_IC); |
| 464 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(3)) == Code::CALL_IC); | |
| 465 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(4)) == Code::LOAD_IC); | |
| 466 } else { | |
| 467 CHECK_EQ(4, feedback_vector->ICSlots()); | |
| 468 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(0)) == Code::CALL_IC); | |
| 469 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(1)) == Code::LOAD_IC); | |
| 470 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(2)) == Code::CALL_IC); | |
| 471 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(3)) == Code::LOAD_IC); | |
| 472 } | |
| 473 | 452 |
| 474 CompileRun( | 453 CompileRun( |
| 475 "function testkeyedprop(x) {" | 454 "function testkeyedprop(x) {" |
| 476 " x[0] = a;" | 455 " x[0] = a;" |
| 477 " return x[0];" | 456 " return x[0];" |
| 478 "}" | 457 "}" |
| 479 "testkeyedprop([0, 1, 2]);"); | 458 "testkeyedprop([0, 1, 2]);"); |
| 480 | 459 |
| 481 f = GetFunction("testkeyedprop"); | 460 f = GetFunction("testkeyedprop"); |
| 482 | 461 |
| 483 // There should be 1 LOAD_ICs for the load of a, and one KEYED_LOAD_IC for the | 462 // There should be 1 LOAD_ICs for the load of a, and one KEYED_LOAD_IC for the |
| 484 // load of x[0] in the return statement. | 463 // load of x[0] in the return statement. |
| 485 feedback_vector = handle(f->shared()->feedback_vector(), isolate); | 464 feedback_vector = handle(f->shared()->feedback_vector(), isolate); |
| 486 if (FLAG_vector_stores) { | 465 CHECK_EQ(2, feedback_vector->ICSlots()); |
| 487 CHECK_EQ(3, feedback_vector->ICSlots()); | 466 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(0)) == Code::LOAD_IC); |
| 488 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(0)) == Code::LOAD_IC); | 467 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(1)) == |
| 489 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(1)) == | 468 Code::KEYED_LOAD_IC); |
| 490 Code::KEYED_STORE_IC); | |
| 491 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(2)) == | |
| 492 Code::KEYED_LOAD_IC); | |
| 493 } else { | |
| 494 CHECK_EQ(2, feedback_vector->ICSlots()); | |
| 495 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(0)) == Code::LOAD_IC); | |
| 496 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(1)) == | |
| 497 Code::KEYED_LOAD_IC); | |
| 498 } | |
| 499 | 469 |
| 500 CompileRun( | 470 CompileRun( |
| 501 "function testcompound(x) {" | 471 "function testcompound(x) {" |
| 502 " x.old = x.young = x.in_between = a;" | 472 " x.old = x.young = x.in_between = a;" |
| 503 " return x.old + x.young;" | 473 " return x.old + x.young;" |
| 504 "}" | 474 "}" |
| 505 "testcompound({ old: 3, young: 3, in_between: 3 });"); | 475 "testcompound({ old: 3, young: 3, in_between: 3 });"); |
| 506 | 476 |
| 507 f = GetFunction("testcompound"); | 477 f = GetFunction("testcompound"); |
| 508 | 478 |
| 509 // There should be 3 LOAD_ICs, for load of a and load of x.old and x.young. | 479 // There should be 3 LOAD_ICs, for load of a and load of x.old and x.young. |
| 510 feedback_vector = handle(f->shared()->feedback_vector(), isolate); | 480 feedback_vector = handle(f->shared()->feedback_vector(), isolate); |
| 511 if (FLAG_vector_stores) { | 481 CHECK_EQ(3, feedback_vector->ICSlots()); |
| 512 CHECK_EQ(6, feedback_vector->ICSlots()); | 482 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(0)) == Code::LOAD_IC); |
| 513 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(0)) == Code::LOAD_IC); | 483 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(1)) == Code::LOAD_IC); |
| 514 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(1)) == Code::STORE_IC); | 484 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(2)) == Code::LOAD_IC); |
| 515 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(2)) == Code::STORE_IC); | |
| 516 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(3)) == Code::STORE_IC); | |
| 517 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(4)) == Code::LOAD_IC); | |
| 518 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(5)) == Code::LOAD_IC); | |
| 519 } else { | |
| 520 CHECK_EQ(3, feedback_vector->ICSlots()); | |
| 521 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(0)) == Code::LOAD_IC); | |
| 522 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(1)) == Code::LOAD_IC); | |
| 523 CHECK(feedback_vector->GetKind(FeedbackVectorICSlot(2)) == Code::LOAD_IC); | |
| 524 } | |
| 525 } | |
| 526 | |
| 527 | |
| 528 TEST(VectorStoreICBasic) { | |
| 529 if (i::FLAG_always_opt) return; | |
| 530 if (!i::FLAG_vector_stores) return; | |
| 531 | |
| 532 CcTest::InitializeVM(); | |
| 533 LocalContext context; | |
| 534 v8::HandleScope scope(context->GetIsolate()); | |
| 535 Isolate* isolate = CcTest::i_isolate(); | |
| 536 | |
| 537 CompileRun( | |
| 538 "function f(a) {" | |
| 539 " a.foo = 5;" | |
| 540 "}" | |
| 541 "var a = { foo: 3 };" | |
| 542 "f(a);" | |
| 543 "f(a);" | |
| 544 "f(a);"); | |
| 545 Handle<JSFunction> f = GetFunction("f"); | |
| 546 // There should be one IC slot. | |
| 547 Handle<TypeFeedbackVector> feedback_vector = | |
| 548 Handle<TypeFeedbackVector>(f->shared()->feedback_vector(), isolate); | |
| 549 CHECK_EQ(1, feedback_vector->ICSlots()); | |
| 550 FeedbackVectorICSlot slot(0); | |
| 551 StoreICNexus nexus(feedback_vector, slot); | |
| 552 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); | |
| 553 } | 485 } |
| 554 } | 486 } |
| OLD | NEW |