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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 " return o + x + o;" | 340 " return o + x + o;" |
341 "}" | 341 "}" |
342 "f();"); | 342 "f();"); |
343 Handle<JSFunction> f = GetFunction("f"); | 343 Handle<JSFunction> f = GetFunction("f"); |
344 // There should be one IC slot. | 344 // There should be one IC slot. |
345 Handle<TypeFeedbackVector> feedback_vector = | 345 Handle<TypeFeedbackVector> feedback_vector = |
346 Handle<TypeFeedbackVector>(f->feedback_vector(), isolate); | 346 Handle<TypeFeedbackVector>(f->feedback_vector(), isolate); |
347 FeedbackVectorHelper helper(feedback_vector); | 347 FeedbackVectorHelper helper(feedback_vector); |
348 CHECK_EQ(1, helper.slot_count()); | 348 CHECK_EQ(1, helper.slot_count()); |
349 FeedbackVectorSlot slot(0); | 349 FeedbackVectorSlot slot(0); |
350 LoadICNexus nexus(feedback_vector, slot); | 350 LoadGlobalICNexus nexus(feedback_vector, slot); |
351 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); | 351 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); |
352 } | 352 } |
353 | 353 |
354 | 354 |
355 TEST(VectorLoadICOnSmi) { | 355 TEST(VectorLoadICOnSmi) { |
356 if (i::FLAG_always_opt) return; | 356 if (i::FLAG_always_opt) return; |
357 CcTest::InitializeVM(); | 357 CcTest::InitializeVM(); |
358 LocalContext context; | 358 LocalContext context; |
359 v8::HandleScope scope(context->GetIsolate()); | 359 v8::HandleScope scope(context->GetIsolate()); |
360 Isolate* isolate = CcTest::i_isolate(); | 360 Isolate* isolate = CcTest::i_isolate(); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 "testvar({});"); | 429 "testvar({});"); |
430 | 430 |
431 Handle<JSFunction> f = GetFunction("testvar"); | 431 Handle<JSFunction> f = GetFunction("testvar"); |
432 | 432 |
433 // There should be two LOAD_ICs, one for a and one for y at the end. | 433 // There should be two LOAD_ICs, one for a and one for y at the end. |
434 Handle<TypeFeedbackVector> feedback_vector = | 434 Handle<TypeFeedbackVector> feedback_vector = |
435 handle(f->feedback_vector(), isolate); | 435 handle(f->feedback_vector(), isolate); |
436 FeedbackVectorHelper helper(feedback_vector); | 436 FeedbackVectorHelper helper(feedback_vector); |
437 CHECK_EQ(4, helper.slot_count()); | 437 CHECK_EQ(4, helper.slot_count()); |
438 CHECK_SLOT_KIND(helper, 0, FeedbackVectorSlotKind::STORE_IC); | 438 CHECK_SLOT_KIND(helper, 0, FeedbackVectorSlotKind::STORE_IC); |
439 CHECK_SLOT_KIND(helper, 1, FeedbackVectorSlotKind::LOAD_IC); | 439 CHECK_SLOT_KIND(helper, 1, FeedbackVectorSlotKind::LOAD_GLOBAL_IC); |
440 CHECK_SLOT_KIND(helper, 2, FeedbackVectorSlotKind::STORE_IC); | 440 CHECK_SLOT_KIND(helper, 2, FeedbackVectorSlotKind::STORE_IC); |
441 CHECK_SLOT_KIND(helper, 3, FeedbackVectorSlotKind::LOAD_IC); | 441 CHECK_SLOT_KIND(helper, 3, FeedbackVectorSlotKind::LOAD_GLOBAL_IC); |
442 } | 442 } |
443 | 443 |
444 { | 444 { |
445 CompileRun( | 445 CompileRun( |
446 "function testprop(x) {" | 446 "function testprop(x) {" |
447 " x.blue = a;" | 447 " x.blue = a;" |
448 "}" | 448 "}" |
449 "testprop({ blue: 3 });"); | 449 "testprop({ blue: 3 });"); |
450 | 450 |
451 Handle<JSFunction> f = GetFunction("testprop"); | 451 Handle<JSFunction> f = GetFunction("testprop"); |
452 | 452 |
453 // There should be one LOAD_IC, for the load of a. | 453 // There should be one LOAD_IC, for the load of a. |
454 Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector()); | 454 Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector()); |
455 FeedbackVectorHelper helper(feedback_vector); | 455 FeedbackVectorHelper helper(feedback_vector); |
456 CHECK_EQ(2, helper.slot_count()); | 456 CHECK_EQ(2, helper.slot_count()); |
| 457 CHECK_SLOT_KIND(helper, 0, FeedbackVectorSlotKind::LOAD_GLOBAL_IC); |
| 458 CHECK_SLOT_KIND(helper, 1, FeedbackVectorSlotKind::STORE_IC); |
457 } | 459 } |
458 | 460 |
459 { | 461 { |
460 CompileRun( | 462 CompileRun( |
461 "function testpropfunc(x) {" | 463 "function testpropfunc(x) {" |
462 " x().blue = a;" | 464 " x().blue = a;" |
463 " return x().blue;" | 465 " return x().blue;" |
464 "}" | 466 "}" |
465 "function makeresult() { return { blue: 3 }; }" | 467 "function makeresult() { return { blue: 3 }; }" |
466 "testpropfunc(makeresult);"); | 468 "testpropfunc(makeresult);"); |
467 | 469 |
468 Handle<JSFunction> f = GetFunction("testpropfunc"); | 470 Handle<JSFunction> f = GetFunction("testpropfunc"); |
469 | 471 |
470 // There should be 2 LOAD_ICs and 2 CALL_ICs. | 472 // There should be 1 LOAD_GLOBAL_IC to load x (in both cases), 2 CALL_ICs |
| 473 // to call x and a LOAD_IC to load blue. |
471 Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector()); | 474 Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector()); |
472 FeedbackVectorHelper helper(feedback_vector); | 475 FeedbackVectorHelper helper(feedback_vector); |
473 CHECK_EQ(5, helper.slot_count()); | 476 CHECK_EQ(5, helper.slot_count()); |
474 CHECK_SLOT_KIND(helper, 0, FeedbackVectorSlotKind::CALL_IC); | 477 CHECK_SLOT_KIND(helper, 0, FeedbackVectorSlotKind::CALL_IC); |
475 CHECK_SLOT_KIND(helper, 1, FeedbackVectorSlotKind::LOAD_IC); | 478 CHECK_SLOT_KIND(helper, 1, FeedbackVectorSlotKind::LOAD_GLOBAL_IC); |
476 CHECK_SLOT_KIND(helper, 2, FeedbackVectorSlotKind::STORE_IC); | 479 CHECK_SLOT_KIND(helper, 2, FeedbackVectorSlotKind::STORE_IC); |
477 CHECK_SLOT_KIND(helper, 3, FeedbackVectorSlotKind::CALL_IC); | 480 CHECK_SLOT_KIND(helper, 3, FeedbackVectorSlotKind::CALL_IC); |
478 CHECK_SLOT_KIND(helper, 4, FeedbackVectorSlotKind::LOAD_IC); | 481 CHECK_SLOT_KIND(helper, 4, FeedbackVectorSlotKind::LOAD_IC); |
479 } | 482 } |
480 | 483 |
481 { | 484 { |
482 CompileRun( | 485 CompileRun( |
483 "function testkeyedprop(x) {" | 486 "function testkeyedprop(x) {" |
484 " x[0] = a;" | 487 " x[0] = a;" |
485 " return x[0];" | 488 " return x[0];" |
486 "}" | 489 "}" |
487 "testkeyedprop([0, 1, 2]);"); | 490 "testkeyedprop([0, 1, 2]);"); |
488 | 491 |
489 Handle<JSFunction> f = GetFunction("testkeyedprop"); | 492 Handle<JSFunction> f = GetFunction("testkeyedprop"); |
490 | 493 |
491 // There should be 1 LOAD_ICs for the load of a, and one KEYED_LOAD_IC for | 494 // There should be 1 LOAD_GLOBAL_ICs for the load of a, and one |
492 // the load of x[0] in the return statement. | 495 // KEYED_LOAD_IC for the load of x[0] in the return statement. |
493 Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector()); | 496 Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector()); |
494 FeedbackVectorHelper helper(feedback_vector); | 497 FeedbackVectorHelper helper(feedback_vector); |
495 CHECK_EQ(3, helper.slot_count()); | 498 CHECK_EQ(3, helper.slot_count()); |
496 CHECK_SLOT_KIND(helper, 0, FeedbackVectorSlotKind::LOAD_IC); | 499 CHECK_SLOT_KIND(helper, 0, FeedbackVectorSlotKind::LOAD_GLOBAL_IC); |
497 CHECK_SLOT_KIND(helper, 1, FeedbackVectorSlotKind::KEYED_STORE_IC); | 500 CHECK_SLOT_KIND(helper, 1, FeedbackVectorSlotKind::KEYED_STORE_IC); |
498 CHECK_SLOT_KIND(helper, 2, FeedbackVectorSlotKind::KEYED_LOAD_IC); | 501 CHECK_SLOT_KIND(helper, 2, FeedbackVectorSlotKind::KEYED_LOAD_IC); |
499 } | 502 } |
500 | 503 |
501 { | 504 { |
502 CompileRun( | 505 CompileRun( |
503 "function testcompound(x) {" | 506 "function testcompound(x) {" |
504 " x.old = x.young = x.in_between = a;" | 507 " x.old = x.young = x.in_between = a;" |
505 " return x.old + x.young;" | 508 " return x.old + x.young;" |
506 "}" | 509 "}" |
507 "testcompound({ old: 3, young: 3, in_between: 3 });"); | 510 "testcompound({ old: 3, young: 3, in_between: 3 });"); |
508 | 511 |
509 Handle<JSFunction> f = GetFunction("testcompound"); | 512 Handle<JSFunction> f = GetFunction("testcompound"); |
510 | 513 |
511 // There should be 3 LOAD_ICs, for load of a and load of x.old and x.young. | 514 // There should be 1 LOAD_GLOBAL_IC for load of a and 2 LOAD_ICs, for load |
| 515 // of x.old and x.young. |
512 Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector()); | 516 Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector()); |
513 FeedbackVectorHelper helper(feedback_vector); | 517 FeedbackVectorHelper helper(feedback_vector); |
514 CHECK_EQ(6, helper.slot_count()); | 518 CHECK_EQ(6, helper.slot_count()); |
515 CHECK_SLOT_KIND(helper, 0, FeedbackVectorSlotKind::LOAD_IC); | 519 CHECK_SLOT_KIND(helper, 0, FeedbackVectorSlotKind::LOAD_GLOBAL_IC); |
516 CHECK_SLOT_KIND(helper, 1, FeedbackVectorSlotKind::STORE_IC); | 520 CHECK_SLOT_KIND(helper, 1, FeedbackVectorSlotKind::STORE_IC); |
517 CHECK_SLOT_KIND(helper, 2, FeedbackVectorSlotKind::STORE_IC); | 521 CHECK_SLOT_KIND(helper, 2, FeedbackVectorSlotKind::STORE_IC); |
518 CHECK_SLOT_KIND(helper, 3, FeedbackVectorSlotKind::STORE_IC); | 522 CHECK_SLOT_KIND(helper, 3, FeedbackVectorSlotKind::STORE_IC); |
519 CHECK_SLOT_KIND(helper, 4, FeedbackVectorSlotKind::LOAD_IC); | 523 CHECK_SLOT_KIND(helper, 4, FeedbackVectorSlotKind::LOAD_IC); |
520 CHECK_SLOT_KIND(helper, 5, FeedbackVectorSlotKind::LOAD_IC); | 524 CHECK_SLOT_KIND(helper, 5, FeedbackVectorSlotKind::LOAD_IC); |
521 } | 525 } |
522 } | 526 } |
523 | 527 |
524 | 528 |
525 TEST(VectorStoreICBasic) { | 529 TEST(VectorStoreICBasic) { |
(...skipping 15 matching lines...) Expand all Loading... |
541 // There should be one IC slot. | 545 // There should be one IC slot. |
542 Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector()); | 546 Handle<TypeFeedbackVector> feedback_vector(f->feedback_vector()); |
543 FeedbackVectorHelper helper(feedback_vector); | 547 FeedbackVectorHelper helper(feedback_vector); |
544 CHECK_EQ(1, helper.slot_count()); | 548 CHECK_EQ(1, helper.slot_count()); |
545 FeedbackVectorSlot slot(0); | 549 FeedbackVectorSlot slot(0); |
546 StoreICNexus nexus(feedback_vector, slot); | 550 StoreICNexus nexus(feedback_vector, slot); |
547 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); | 551 CHECK_EQ(MONOMORPHIC, nexus.StateFromFeedback()); |
548 } | 552 } |
549 | 553 |
550 } // namespace | 554 } // namespace |
OLD | NEW |