OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 | 6 |
7 #include "src/execution.h" | 7 #include "src/execution.h" |
8 #include "src/handles.h" | 8 #include "src/handles.h" |
9 #include "src/interpreter/bytecode-array-builder.h" | 9 #include "src/interpreter/bytecode-array-builder.h" |
10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 MaybeHandle<Object> operator()(A... args) { | 43 MaybeHandle<Object> operator()(A... args) { |
44 return CallInterpreter(isolate_, function_, args...); | 44 return CallInterpreter(isolate_, function_, args...); |
45 } | 45 } |
46 | 46 |
47 private: | 47 private: |
48 Isolate* isolate_; | 48 Isolate* isolate_; |
49 Handle<JSFunction> function_; | 49 Handle<JSFunction> function_; |
50 }; | 50 }; |
51 | 51 |
52 | 52 |
| 53 static const char* kFunctionName = "f"; |
| 54 |
| 55 |
53 class InterpreterTester { | 56 class InterpreterTester { |
54 public: | 57 public: |
55 InterpreterTester(Isolate* isolate, Handle<BytecodeArray> bytecode, | 58 InterpreterTester(Isolate* isolate, const char* source, |
56 MaybeHandle<TypeFeedbackVector> feedback_vector = | 59 MaybeHandle<BytecodeArray> bytecode, |
57 MaybeHandle<TypeFeedbackVector>()) | 60 MaybeHandle<TypeFeedbackVector> feedback_vector) |
58 : isolate_(isolate), | 61 : isolate_(isolate), |
| 62 source_(source), |
59 bytecode_(bytecode), | 63 bytecode_(bytecode), |
60 feedback_vector_(feedback_vector) { | 64 feedback_vector_(feedback_vector) { |
61 i::FLAG_vector_stores = true; | 65 i::FLAG_vector_stores = true; |
62 i::FLAG_ignition = true; | 66 i::FLAG_ignition = true; |
| 67 i::FLAG_ignition_filter = StrDup(kFunctionName); |
| 68 i::FLAG_always_opt = false; |
63 // Ensure handler table is generated. | 69 // Ensure handler table is generated. |
64 isolate->interpreter()->Initialize(); | 70 isolate->interpreter()->Initialize(); |
65 } | 71 } |
| 72 |
| 73 InterpreterTester(Isolate* isolate, Handle<BytecodeArray> bytecode, |
| 74 MaybeHandle<TypeFeedbackVector> feedback_vector = |
| 75 MaybeHandle<TypeFeedbackVector>()) |
| 76 : InterpreterTester(isolate, nullptr, bytecode, feedback_vector) {} |
| 77 |
| 78 |
| 79 InterpreterTester(Isolate* isolate, const char* source) |
| 80 : InterpreterTester(isolate, source, MaybeHandle<BytecodeArray>(), |
| 81 MaybeHandle<TypeFeedbackVector>()) {} |
| 82 |
66 virtual ~InterpreterTester() {} | 83 virtual ~InterpreterTester() {} |
67 | 84 |
68 template <class... A> | 85 template <class... A> |
69 InterpreterCallable<A...> GetCallable() { | 86 InterpreterCallable<A...> GetCallable() { |
70 return InterpreterCallable<A...>(isolate_, GetBytecodeFunction<A...>()); | 87 return InterpreterCallable<A...>(isolate_, GetBytecodeFunction<A...>()); |
71 } | 88 } |
72 | 89 |
73 Handle<Object> NewObject(const char* script) { | 90 static Handle<Object> NewObject(const char* script) { |
74 return v8::Utils::OpenHandle(*CompileRun(script)); | 91 return v8::Utils::OpenHandle(*CompileRun(script)); |
75 } | 92 } |
76 | 93 |
| 94 static Handle<String> GetName(Isolate* isolate, const char* name) { |
| 95 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(name); |
| 96 return isolate->factory()->string_table()->LookupString(isolate, result); |
| 97 } |
| 98 |
| 99 static std::string function_name() { |
| 100 return std::string(kFunctionName); |
| 101 } |
| 102 |
77 private: | 103 private: |
78 Isolate* isolate_; | 104 Isolate* isolate_; |
79 Handle<BytecodeArray> bytecode_; | 105 const char* source_; |
| 106 MaybeHandle<BytecodeArray> bytecode_; |
80 MaybeHandle<TypeFeedbackVector> feedback_vector_; | 107 MaybeHandle<TypeFeedbackVector> feedback_vector_; |
81 | 108 |
82 template <class... A> | 109 template <class... A> |
83 Handle<JSFunction> GetBytecodeFunction() { | 110 Handle<JSFunction> GetBytecodeFunction() { |
84 int arg_count = sizeof...(A); | 111 Handle<JSFunction> function; |
85 std::string function_text("(function("); | 112 if (source_) { |
86 for (int i = 0; i < arg_count; i++) { | 113 CompileRun(source_); |
87 function_text += i == 0 ? "a" : ", a"; | 114 Local<Function> api_function = |
| 115 Local<Function>::Cast(CcTest::global()->Get(v8_str(kFunctionName))); |
| 116 function = v8::Utils::OpenHandle(*api_function); |
| 117 } else { |
| 118 int arg_count = sizeof...(A); |
| 119 std::string source("(function " + function_name() + "("); |
| 120 for (int i = 0; i < arg_count; i++) { |
| 121 source += i == 0 ? "a" : ", a"; |
| 122 } |
| 123 source += "){})"; |
| 124 function = v8::Utils::OpenHandle( |
| 125 *v8::Handle<v8::Function>::Cast(CompileRun(source.c_str()))); |
| 126 function->ReplaceCode( |
| 127 *isolate_->builtins()->InterpreterEntryTrampoline()); |
88 } | 128 } |
89 function_text += "){})"; | |
90 | 129 |
91 Handle<JSFunction> function = v8::Utils::OpenHandle( | 130 if (!bytecode_.is_null()) { |
92 *v8::Handle<v8::Function>::Cast(CompileRun(function_text.c_str()))); | 131 function->shared()->set_function_data(*bytecode_.ToHandleChecked()); |
93 function->ReplaceCode(*isolate_->builtins()->InterpreterEntryTrampoline()); | 132 } |
94 function->shared()->set_function_data(*bytecode_); | |
95 if (!feedback_vector_.is_null()) { | 133 if (!feedback_vector_.is_null()) { |
96 function->shared()->set_feedback_vector( | 134 function->shared()->set_feedback_vector( |
97 *feedback_vector_.ToHandleChecked()); | 135 *feedback_vector_.ToHandleChecked()); |
98 } | 136 } |
99 return function; | 137 return function; |
100 } | 138 } |
101 | 139 |
102 DISALLOW_COPY_AND_ASSIGN(InterpreterTester); | 140 DISALLOW_COPY_AND_ASSIGN(InterpreterTester); |
103 }; | 141 }; |
104 | 142 |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 Handle<Smi> arg7 = Handle<Smi>(Smi::FromInt(7), handles.main_isolate()); | 501 Handle<Smi> arg7 = Handle<Smi>(Smi::FromInt(7), handles.main_isolate()); |
464 Handle<Smi> arg8 = Handle<Smi>(Smi::FromInt(8), handles.main_isolate()); | 502 Handle<Smi> arg8 = Handle<Smi>(Smi::FromInt(8), handles.main_isolate()); |
465 // Check for Smis. | 503 // Check for Smis. |
466 Handle<Object> return_val = | 504 Handle<Object> return_val = |
467 callable(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) | 505 callable(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) |
468 .ToHandleChecked(); | 506 .ToHandleChecked(); |
469 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(36)); | 507 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(36)); |
470 } | 508 } |
471 | 509 |
472 | 510 |
| 511 TEST(InterpreterLoadGlobal) { |
| 512 HandleAndZoneScope handles; |
| 513 |
| 514 // Test loading a global. |
| 515 std::string source( |
| 516 "var global = 321;\n" |
| 517 "function " + InterpreterTester::function_name() + "() {\n" |
| 518 " return global;\n" |
| 519 "}"); |
| 520 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 521 auto callable = tester.GetCallable<>(); |
| 522 |
| 523 Handle<Object> return_val = callable().ToHandleChecked(); |
| 524 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(321)); |
| 525 } |
| 526 |
| 527 |
| 528 TEST(InterpreterCallGlobal) { |
| 529 HandleAndZoneScope handles; |
| 530 |
| 531 // Test calling a global function. |
| 532 std::string source( |
| 533 "function g_add(a, b) { return a + b; }\n" |
| 534 "function " + InterpreterTester::function_name() + "() {\n" |
| 535 " return g_add(5, 10);\n" |
| 536 "}"); |
| 537 InterpreterTester tester(handles.main_isolate(), source.c_str()); |
| 538 auto callable = tester.GetCallable<>(); |
| 539 |
| 540 Handle<Object> return_val = callable().ToHandleChecked(); |
| 541 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(15)); |
| 542 } |
| 543 |
| 544 |
473 TEST(InterpreterLoadNamedProperty) { | 545 TEST(InterpreterLoadNamedProperty) { |
474 HandleAndZoneScope handles; | 546 HandleAndZoneScope handles; |
475 i::Isolate* isolate = handles.main_isolate(); | 547 i::Isolate* isolate = handles.main_isolate(); |
476 i::Factory* factory = isolate->factory(); | 548 i::Factory* factory = isolate->factory(); |
477 | 549 |
478 i::Code::Kind ic_kinds[] = {i::Code::LOAD_IC}; | 550 i::Code::Kind ic_kinds[] = {i::Code::LOAD_IC}; |
479 i::FeedbackVectorSpec feedback_spec(0, 1, ic_kinds); | 551 i::FeedbackVectorSpec feedback_spec(0, 1, ic_kinds); |
480 Handle<i::TypeFeedbackVector> vector = | 552 Handle<i::TypeFeedbackVector> vector = |
481 factory->NewTypeFeedbackVector(&feedback_spec); | 553 factory->NewTypeFeedbackVector(&feedback_spec); |
482 | 554 |
483 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); | 555 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); |
484 name = factory->string_table()->LookupString(isolate, name); | 556 name = factory->string_table()->LookupString(isolate, name); |
485 | 557 |
486 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); | 558 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
487 builder.set_locals_count(0); | 559 builder.set_locals_count(0); |
488 builder.set_parameter_count(1); | 560 builder.set_parameter_count(1); |
489 builder.LoadLiteral(name) | 561 builder.LoadLiteral(name) |
490 .LoadNamedProperty(builder.Parameter(0), vector->first_ic_slot_index(), | 562 .LoadNamedProperty(builder.Parameter(0), vector->first_ic_slot_index(), |
491 i::SLOPPY) | 563 i::SLOPPY) |
492 .Return(); | 564 .Return(); |
493 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 565 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
494 | 566 |
495 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 567 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); |
496 auto callable = tester.GetCallable<Handle<Object>>(); | 568 auto callable = tester.GetCallable<Handle<Object>>(); |
497 | 569 |
498 Handle<Object> object = tester.NewObject("({ val : 123 })"); | 570 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); |
499 // Test IC miss. | 571 // Test IC miss. |
500 Handle<Object> return_val = callable(object).ToHandleChecked(); | 572 Handle<Object> return_val = callable(object).ToHandleChecked(); |
501 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); | 573 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); |
502 | 574 |
503 // Test transition to monomorphic IC. | 575 // Test transition to monomorphic IC. |
504 return_val = callable(object).ToHandleChecked(); | 576 return_val = callable(object).ToHandleChecked(); |
505 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); | 577 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); |
506 | 578 |
507 // Test transition to polymorphic IC. | 579 // Test transition to polymorphic IC. |
508 Handle<Object> object2 = tester.NewObject("({ val : 456, other : 123 })"); | 580 Handle<Object> object2 = |
| 581 InterpreterTester::NewObject("({ val : 456, other : 123 })"); |
509 return_val = callable(object2).ToHandleChecked(); | 582 return_val = callable(object2).ToHandleChecked(); |
510 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(456)); | 583 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(456)); |
511 | 584 |
512 // Test transition to megamorphic IC. | 585 // Test transition to megamorphic IC. |
513 Handle<Object> object3 = tester.NewObject("({ val : 789, val2 : 123 })"); | 586 Handle<Object> object3 = |
| 587 InterpreterTester::NewObject("({ val : 789, val2 : 123 })"); |
514 callable(object3).ToHandleChecked(); | 588 callable(object3).ToHandleChecked(); |
515 Handle<Object> object4 = tester.NewObject("({ val : 789, val3 : 123 })"); | 589 Handle<Object> object4 = |
| 590 InterpreterTester::NewObject("({ val : 789, val3 : 123 })"); |
516 callable(object4).ToHandleChecked(); | 591 callable(object4).ToHandleChecked(); |
517 Handle<Object> object5 = tester.NewObject("({ val : 789, val4 : 123 })"); | 592 Handle<Object> object5 = |
| 593 InterpreterTester::NewObject("({ val : 789, val4 : 123 })"); |
518 return_val = callable(object5).ToHandleChecked(); | 594 return_val = callable(object5).ToHandleChecked(); |
519 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(789)); | 595 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(789)); |
520 } | 596 } |
521 | 597 |
522 | 598 |
523 TEST(InterpreterLoadKeyedProperty) { | 599 TEST(InterpreterLoadKeyedProperty) { |
524 HandleAndZoneScope handles; | 600 HandleAndZoneScope handles; |
525 i::Isolate* isolate = handles.main_isolate(); | 601 i::Isolate* isolate = handles.main_isolate(); |
526 i::Factory* factory = isolate->factory(); | 602 i::Factory* factory = isolate->factory(); |
527 | 603 |
(...skipping 10 matching lines...) Expand all Loading... |
538 builder.set_parameter_count(1); | 614 builder.set_parameter_count(1); |
539 builder.LoadLiteral(key) | 615 builder.LoadLiteral(key) |
540 .LoadKeyedProperty(builder.Parameter(0), vector->first_ic_slot_index(), | 616 .LoadKeyedProperty(builder.Parameter(0), vector->first_ic_slot_index(), |
541 i::SLOPPY) | 617 i::SLOPPY) |
542 .Return(); | 618 .Return(); |
543 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 619 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
544 | 620 |
545 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 621 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); |
546 auto callable = tester.GetCallable<Handle<Object>>(); | 622 auto callable = tester.GetCallable<Handle<Object>>(); |
547 | 623 |
548 Handle<Object> object = tester.NewObject("({ key : 123 })"); | 624 Handle<Object> object = InterpreterTester::NewObject("({ key : 123 })"); |
549 // Test IC miss. | 625 // Test IC miss. |
550 Handle<Object> return_val = callable(object).ToHandleChecked(); | 626 Handle<Object> return_val = callable(object).ToHandleChecked(); |
551 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); | 627 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); |
552 | 628 |
553 // Test transition to monomorphic IC. | 629 // Test transition to monomorphic IC. |
554 return_val = callable(object).ToHandleChecked(); | 630 return_val = callable(object).ToHandleChecked(); |
555 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); | 631 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); |
556 | 632 |
557 // Test transition to megamorphic IC. | 633 // Test transition to megamorphic IC. |
558 Handle<Object> object3 = tester.NewObject("({ key : 789, val2 : 123 })"); | 634 Handle<Object> object3 = |
| 635 InterpreterTester::NewObject("({ key : 789, val2 : 123 })"); |
559 return_val = callable(object3).ToHandleChecked(); | 636 return_val = callable(object3).ToHandleChecked(); |
560 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(789)); | 637 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(789)); |
561 } | 638 } |
562 | 639 |
563 | 640 |
564 TEST(InterpreterStoreNamedProperty) { | 641 TEST(InterpreterStoreNamedProperty) { |
565 HandleAndZoneScope handles; | 642 HandleAndZoneScope handles; |
566 i::Isolate* isolate = handles.main_isolate(); | 643 i::Isolate* isolate = handles.main_isolate(); |
567 i::Factory* factory = isolate->factory(); | 644 i::Factory* factory = isolate->factory(); |
568 | 645 |
(...skipping 11 matching lines...) Expand all Loading... |
580 builder.LoadLiteral(name) | 657 builder.LoadLiteral(name) |
581 .StoreAccumulatorInRegister(Register(0)) | 658 .StoreAccumulatorInRegister(Register(0)) |
582 .LoadLiteral(Smi::FromInt(999)) | 659 .LoadLiteral(Smi::FromInt(999)) |
583 .StoreNamedProperty(builder.Parameter(0), Register(0), | 660 .StoreNamedProperty(builder.Parameter(0), Register(0), |
584 vector->first_ic_slot_index(), i::SLOPPY) | 661 vector->first_ic_slot_index(), i::SLOPPY) |
585 .Return(); | 662 .Return(); |
586 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 663 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
587 | 664 |
588 InterpreterTester tester(isolate, bytecode_array, vector); | 665 InterpreterTester tester(isolate, bytecode_array, vector); |
589 auto callable = tester.GetCallable<Handle<Object>>(); | 666 auto callable = tester.GetCallable<Handle<Object>>(); |
590 Handle<Object> object = tester.NewObject("({ val : 123 })"); | 667 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); |
591 // Test IC miss. | 668 // Test IC miss. |
592 Handle<Object> result; | 669 Handle<Object> result; |
593 callable(object).ToHandleChecked(); | 670 callable(object).ToHandleChecked(); |
594 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); | 671 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); |
595 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 672 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
596 | 673 |
597 // Test transition to monomorphic IC. | 674 // Test transition to monomorphic IC. |
598 callable(object).ToHandleChecked(); | 675 callable(object).ToHandleChecked(); |
599 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); | 676 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); |
600 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 677 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
601 | 678 |
602 // Test transition to polymorphic IC. | 679 // Test transition to polymorphic IC. |
603 Handle<Object> object2 = tester.NewObject("({ val : 456, other : 123 })"); | 680 Handle<Object> object2 = |
| 681 InterpreterTester::NewObject("({ val : 456, other : 123 })"); |
604 callable(object2).ToHandleChecked(); | 682 callable(object2).ToHandleChecked(); |
605 CHECK(Runtime::GetObjectProperty(isolate, object2, name).ToHandle(&result)); | 683 CHECK(Runtime::GetObjectProperty(isolate, object2, name).ToHandle(&result)); |
606 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 684 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
607 | 685 |
608 // Test transition to megamorphic IC. | 686 // Test transition to megamorphic IC. |
609 Handle<Object> object3 = tester.NewObject("({ val : 789, val2 : 123 })"); | 687 Handle<Object> object3 = |
| 688 InterpreterTester::NewObject("({ val : 789, val2 : 123 })"); |
610 callable(object3).ToHandleChecked(); | 689 callable(object3).ToHandleChecked(); |
611 Handle<Object> object4 = tester.NewObject("({ val : 789, val3 : 123 })"); | 690 Handle<Object> object4 = |
| 691 InterpreterTester::NewObject("({ val : 789, val3 : 123 })"); |
612 callable(object4).ToHandleChecked(); | 692 callable(object4).ToHandleChecked(); |
613 Handle<Object> object5 = tester.NewObject("({ val : 789, val4 : 123 })"); | 693 Handle<Object> object5 = |
| 694 InterpreterTester::NewObject("({ val : 789, val4 : 123 })"); |
614 callable(object5).ToHandleChecked(); | 695 callable(object5).ToHandleChecked(); |
615 CHECK(Runtime::GetObjectProperty(isolate, object5, name).ToHandle(&result)); | 696 CHECK(Runtime::GetObjectProperty(isolate, object5, name).ToHandle(&result)); |
616 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 697 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
617 } | 698 } |
618 | 699 |
619 | 700 |
620 TEST(InterpreterStoreKeyedProperty) { | 701 TEST(InterpreterStoreKeyedProperty) { |
621 HandleAndZoneScope handles; | 702 HandleAndZoneScope handles; |
622 i::Isolate* isolate = handles.main_isolate(); | 703 i::Isolate* isolate = handles.main_isolate(); |
623 i::Factory* factory = isolate->factory(); | 704 i::Factory* factory = isolate->factory(); |
(...skipping 12 matching lines...) Expand all Loading... |
636 builder.LoadLiteral(name) | 717 builder.LoadLiteral(name) |
637 .StoreAccumulatorInRegister(Register(0)) | 718 .StoreAccumulatorInRegister(Register(0)) |
638 .LoadLiteral(Smi::FromInt(999)) | 719 .LoadLiteral(Smi::FromInt(999)) |
639 .StoreKeyedProperty(builder.Parameter(0), Register(0), | 720 .StoreKeyedProperty(builder.Parameter(0), Register(0), |
640 vector->first_ic_slot_index(), i::SLOPPY) | 721 vector->first_ic_slot_index(), i::SLOPPY) |
641 .Return(); | 722 .Return(); |
642 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 723 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
643 | 724 |
644 InterpreterTester tester(isolate, bytecode_array, vector); | 725 InterpreterTester tester(isolate, bytecode_array, vector); |
645 auto callable = tester.GetCallable<Handle<Object>>(); | 726 auto callable = tester.GetCallable<Handle<Object>>(); |
646 Handle<Object> object = tester.NewObject("({ val : 123 })"); | 727 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); |
647 // Test IC miss. | 728 // Test IC miss. |
648 Handle<Object> result; | 729 Handle<Object> result; |
649 callable(object).ToHandleChecked(); | 730 callable(object).ToHandleChecked(); |
650 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); | 731 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); |
651 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 732 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
652 | 733 |
653 // Test transition to monomorphic IC. | 734 // Test transition to monomorphic IC. |
654 callable(object).ToHandleChecked(); | 735 callable(object).ToHandleChecked(); |
655 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); | 736 CHECK(Runtime::GetObjectProperty(isolate, object, name).ToHandle(&result)); |
656 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 737 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
657 | 738 |
658 // Test transition to megamorphic IC. | 739 // Test transition to megamorphic IC. |
659 Handle<Object> object2 = tester.NewObject("({ val : 456, other : 123 })"); | 740 Handle<Object> object2 = |
| 741 InterpreterTester::NewObject("({ val : 456, other : 123 })"); |
660 callable(object2).ToHandleChecked(); | 742 callable(object2).ToHandleChecked(); |
661 CHECK(Runtime::GetObjectProperty(isolate, object2, name).ToHandle(&result)); | 743 CHECK(Runtime::GetObjectProperty(isolate, object2, name).ToHandle(&result)); |
662 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); | 744 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); |
663 } | 745 } |
664 | 746 |
665 | 747 |
666 TEST(InterpreterCall) { | 748 TEST(InterpreterCall) { |
667 HandleAndZoneScope handles; | 749 HandleAndZoneScope handles; |
668 i::Isolate* isolate = handles.main_isolate(); | 750 i::Isolate* isolate = handles.main_isolate(); |
669 i::Factory* factory = isolate->factory(); | 751 i::Factory* factory = isolate->factory(); |
(...skipping 15 matching lines...) Expand all Loading... |
685 .LoadNamedProperty(builder.Parameter(0), vector->first_ic_slot_index(), | 767 .LoadNamedProperty(builder.Parameter(0), vector->first_ic_slot_index(), |
686 i::SLOPPY) | 768 i::SLOPPY) |
687 .StoreAccumulatorInRegister(Register(0)) | 769 .StoreAccumulatorInRegister(Register(0)) |
688 .Call(Register(0), builder.Parameter(0), 0) | 770 .Call(Register(0), builder.Parameter(0), 0) |
689 .Return(); | 771 .Return(); |
690 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 772 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
691 | 773 |
692 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 774 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); |
693 auto callable = tester.GetCallable<Handle<Object>>(); | 775 auto callable = tester.GetCallable<Handle<Object>>(); |
694 | 776 |
695 Handle<Object> object = tester.NewObject( | 777 Handle<Object> object = InterpreterTester::NewObject( |
696 "new (function Obj() { this.func = function() { return 0x265; }})()"); | 778 "new (function Obj() { this.func = function() { return 0x265; }})()"); |
697 Handle<Object> return_val = callable(object).ToHandleChecked(); | 779 Handle<Object> return_val = callable(object).ToHandleChecked(); |
698 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0x265)); | 780 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0x265)); |
699 } | 781 } |
700 | 782 |
701 // Check that receiver is passed properly. | 783 // Check that receiver is passed properly. |
702 { | 784 { |
703 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); | 785 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
704 builder.set_locals_count(1); | 786 builder.set_locals_count(1); |
705 builder.set_parameter_count(1); | 787 builder.set_parameter_count(1); |
706 builder.LoadLiteral(name) | 788 builder.LoadLiteral(name) |
707 .LoadNamedProperty(builder.Parameter(0), vector->first_ic_slot_index(), | 789 .LoadNamedProperty(builder.Parameter(0), vector->first_ic_slot_index(), |
708 i::SLOPPY) | 790 i::SLOPPY) |
709 .StoreAccumulatorInRegister(Register(0)) | 791 .StoreAccumulatorInRegister(Register(0)) |
710 .Call(Register(0), builder.Parameter(0), 0) | 792 .Call(Register(0), builder.Parameter(0), 0) |
711 .Return(); | 793 .Return(); |
712 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 794 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
713 | 795 |
714 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 796 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); |
715 auto callable = tester.GetCallable<Handle<Object>>(); | 797 auto callable = tester.GetCallable<Handle<Object>>(); |
716 | 798 |
717 Handle<Object> object = tester.NewObject( | 799 Handle<Object> object = InterpreterTester::NewObject( |
718 "new (function Obj() {" | 800 "new (function Obj() {" |
719 " this.val = 1234;" | 801 " this.val = 1234;" |
720 " this.func = function() { return this.val; };" | 802 " this.func = function() { return this.val; };" |
721 "})()"); | 803 "})()"); |
722 Handle<Object> return_val = callable(object).ToHandleChecked(); | 804 Handle<Object> return_val = callable(object).ToHandleChecked(); |
723 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(1234)); | 805 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(1234)); |
724 } | 806 } |
725 | 807 |
726 // Check with two parameters (+ receiver). | 808 // Check with two parameters (+ receiver). |
727 { | 809 { |
(...skipping 10 matching lines...) Expand all Loading... |
738 .StoreAccumulatorInRegister(Register(2)) | 820 .StoreAccumulatorInRegister(Register(2)) |
739 .LoadLiteral(Smi::FromInt(11)) | 821 .LoadLiteral(Smi::FromInt(11)) |
740 .StoreAccumulatorInRegister(Register(3)) | 822 .StoreAccumulatorInRegister(Register(3)) |
741 .Call(Register(0), Register(1), 2) | 823 .Call(Register(0), Register(1), 2) |
742 .Return(); | 824 .Return(); |
743 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 825 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
744 | 826 |
745 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 827 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); |
746 auto callable = tester.GetCallable<Handle<Object>>(); | 828 auto callable = tester.GetCallable<Handle<Object>>(); |
747 | 829 |
748 Handle<Object> object = tester.NewObject( | 830 Handle<Object> object = InterpreterTester::NewObject( |
749 "new (function Obj() { " | 831 "new (function Obj() { " |
750 " this.func = function(a, b) { return a - b; }" | 832 " this.func = function(a, b) { return a - b; }" |
751 "})()"); | 833 "})()"); |
752 Handle<Object> return_val = callable(object).ToHandleChecked(); | 834 Handle<Object> return_val = callable(object).ToHandleChecked(); |
753 CHECK(return_val->SameValue(Smi::FromInt(40))); | 835 CHECK(return_val->SameValue(Smi::FromInt(40))); |
754 } | 836 } |
755 | 837 |
756 // Check with 10 parameters (+ receiver). | 838 // Check with 10 parameters (+ receiver). |
757 { | 839 { |
758 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); | 840 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
(...skipping 25 matching lines...) Expand all Loading... |
784 .StoreAccumulatorInRegister(Register(10)) | 866 .StoreAccumulatorInRegister(Register(10)) |
785 .LoadLiteral(factory->NewStringFromAsciiChecked("j")) | 867 .LoadLiteral(factory->NewStringFromAsciiChecked("j")) |
786 .StoreAccumulatorInRegister(Register(11)) | 868 .StoreAccumulatorInRegister(Register(11)) |
787 .Call(Register(0), Register(1), 10) | 869 .Call(Register(0), Register(1), 10) |
788 .Return(); | 870 .Return(); |
789 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 871 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
790 | 872 |
791 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); | 873 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); |
792 auto callable = tester.GetCallable<Handle<Object>>(); | 874 auto callable = tester.GetCallable<Handle<Object>>(); |
793 | 875 |
794 Handle<Object> object = tester.NewObject( | 876 Handle<Object> object = InterpreterTester::NewObject( |
795 "new (function Obj() { " | 877 "new (function Obj() { " |
796 " this.prefix = \"prefix_\";" | 878 " this.prefix = \"prefix_\";" |
797 " this.func = function(a, b, c, d, e, f, g, h, i, j) {" | 879 " this.func = function(a, b, c, d, e, f, g, h, i, j) {" |
798 " return this.prefix + a + b + c + d + e + f + g + h + i + j;" | 880 " return this.prefix + a + b + c + d + e + f + g + h + i + j;" |
799 " }" | 881 " }" |
800 "})()"); | 882 "})()"); |
801 Handle<Object> return_val = callable(object).ToHandleChecked(); | 883 Handle<Object> return_val = callable(object).ToHandleChecked(); |
802 Handle<i::String> expected = | 884 Handle<i::String> expected = |
803 factory->NewStringFromAsciiChecked("prefix_abcdefghij"); | 885 factory->NewStringFromAsciiChecked("prefix_abcdefghij"); |
804 CHECK(i::String::cast(*return_val)->Equals(*expected)); | 886 CHECK(i::String::cast(*return_val)->Equals(*expected)); |
805 } | 887 } |
806 } | 888 } |
OLD | NEW |