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

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

Issue 1731253003: Revert of [Interpreter] Implements calls through CallICStub in the interpreter. (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-bytecode-generator.cc ('k') | test/mjsunit/mjsunit.status » ('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 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 910 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); 921 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999));
922 922
923 // Test transition to megamorphic IC. 923 // Test transition to megamorphic IC.
924 Handle<Object> object2 = 924 Handle<Object> object2 =
925 InterpreterTester::NewObject("({ val : 456, other : 123 })"); 925 InterpreterTester::NewObject("({ val : 456, other : 123 })");
926 callable(object2).ToHandleChecked(); 926 callable(object2).ToHandleChecked();
927 CHECK(Runtime::GetObjectProperty(isolate, object2, name).ToHandle(&result)); 927 CHECK(Runtime::GetObjectProperty(isolate, object2, name).ToHandle(&result));
928 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999)); 928 CHECK_EQ(Smi::cast(*result), Smi::FromInt(999));
929 } 929 }
930 930
931 static void TestInterpreterCall(TailCallMode tail_call_mode, 931 static void TestInterpreterCall(TailCallMode tail_call_mode) {
932 bool has_feedback_slot) {
933 HandleAndZoneScope handles; 932 HandleAndZoneScope handles;
934 i::Isolate* isolate = handles.main_isolate(); 933 i::Isolate* isolate = handles.main_isolate();
935 i::Factory* factory = isolate->factory(); 934 i::Factory* factory = isolate->factory();
936 i::Zone zone; 935 i::Zone zone;
937 936
938 i::FeedbackVectorSpec feedback_spec(&zone); 937 i::FeedbackVectorSpec feedback_spec(&zone);
939 i::FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); 938 i::FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot();
940 i::FeedbackVectorSlot call_slot = feedback_spec.AddCallICSlot();
941 939
942 Handle<i::TypeFeedbackVector> vector = 940 Handle<i::TypeFeedbackVector> vector =
943 i::NewTypeFeedbackVector(isolate, &feedback_spec); 941 i::NewTypeFeedbackVector(isolate, &feedback_spec);
944 int slot_index = vector->GetIndex(slot); 942 int slot_index = vector->GetIndex(slot);
945 int call_slot_index = -1;
946 if (has_feedback_slot) {
947 call_slot_index = vector->GetIndex(call_slot);
948 }
949 943
950 Handle<i::String> name = factory->NewStringFromAsciiChecked("func"); 944 Handle<i::String> name = factory->NewStringFromAsciiChecked("func");
951 name = factory->string_table()->LookupString(isolate, name); 945 name = factory->string_table()->LookupString(isolate, name);
952 946
953 // Check with no args. 947 // Check with no args.
954 { 948 {
955 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, 949 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1,
956 0, 1); 950 0, 1);
957 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) 951 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index)
958 .StoreAccumulatorInRegister(Register(0)); 952 .StoreAccumulatorInRegister(Register(0))
959 953 .Call(Register(0), builder.Parameter(0), 1, 0, tail_call_mode)
960 if (has_feedback_slot) { 954 .Return();
961 builder.CallIC(Register(0), builder.Parameter(0), 1, call_slot_index,
962 tail_call_mode);
963 } else {
964 builder.Call(Register(0), builder.Parameter(0), 1, tail_call_mode);
965 }
966
967 builder.Return();
968 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 955 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
969 956
970 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); 957 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector);
971 auto callable = tester.GetCallable<Handle<Object>>(); 958 auto callable = tester.GetCallable<Handle<Object>>();
972 959
973 Handle<Object> object = InterpreterTester::NewObject( 960 Handle<Object> object = InterpreterTester::NewObject(
974 "new (function Obj() { this.func = function() { return 0x265; }})()"); 961 "new (function Obj() { this.func = function() { return 0x265; }})()");
975 Handle<Object> return_val = callable(object).ToHandleChecked(); 962 Handle<Object> return_val = callable(object).ToHandleChecked();
976 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0x265)); 963 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0x265));
977 } 964 }
978 965
979 // Check that receiver is passed properly. 966 // Check that receiver is passed properly.
980 { 967 {
981 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, 968 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1,
982 0, 1); 969 0, 1);
983 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) 970 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index)
984 .StoreAccumulatorInRegister(Register(0)); 971 .StoreAccumulatorInRegister(Register(0))
985 if (has_feedback_slot) { 972 .Call(Register(0), builder.Parameter(0), 1, 0, tail_call_mode)
986 builder.CallIC(Register(0), builder.Parameter(0), 1, call_slot_index, 973 .Return();
987 tail_call_mode);
988 } else {
989 builder.Call(Register(0), builder.Parameter(0), 1, tail_call_mode);
990 }
991 builder.Return();
992 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 974 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
993 975
994 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); 976 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector);
995 auto callable = tester.GetCallable<Handle<Object>>(); 977 auto callable = tester.GetCallable<Handle<Object>>();
996 978
997 Handle<Object> object = InterpreterTester::NewObject( 979 Handle<Object> object = InterpreterTester::NewObject(
998 "new (function Obj() {" 980 "new (function Obj() {"
999 " this.val = 1234;" 981 " this.val = 1234;"
1000 " this.func = function() { return this.val; };" 982 " this.func = function() { return this.val; };"
1001 "})()"); 983 "})()");
1002 Handle<Object> return_val = callable(object).ToHandleChecked(); 984 Handle<Object> return_val = callable(object).ToHandleChecked();
1003 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(1234)); 985 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(1234));
1004 } 986 }
1005 987
1006 // Check with two parameters (+ receiver). 988 // Check with two parameters (+ receiver).
1007 { 989 {
1008 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1, 990 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone(), 1,
1009 0, 4); 991 0, 4);
1010 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index) 992 builder.LoadNamedProperty(builder.Parameter(0), name, slot_index)
1011 .StoreAccumulatorInRegister(Register(0)) 993 .StoreAccumulatorInRegister(Register(0))
1012 .LoadAccumulatorWithRegister(builder.Parameter(0)) 994 .LoadAccumulatorWithRegister(builder.Parameter(0))
1013 .StoreAccumulatorInRegister(Register(1)) 995 .StoreAccumulatorInRegister(Register(1))
1014 .LoadLiteral(Smi::FromInt(51)) 996 .LoadLiteral(Smi::FromInt(51))
1015 .StoreAccumulatorInRegister(Register(2)) 997 .StoreAccumulatorInRegister(Register(2))
1016 .LoadLiteral(Smi::FromInt(11)) 998 .LoadLiteral(Smi::FromInt(11))
1017 .StoreAccumulatorInRegister(Register(3)); 999 .StoreAccumulatorInRegister(Register(3))
1018 1000 .Call(Register(0), Register(1), 3, 0, tail_call_mode)
1019 if (has_feedback_slot) { 1001 .Return();
1020 builder.CallIC(Register(0), Register(1), 3, call_slot_index,
1021 tail_call_mode);
1022 } else {
1023 builder.Call(Register(0), Register(1), 3, tail_call_mode);
1024 }
1025
1026 builder.Return();
1027
1028 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 1002 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
1029 1003
1030 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); 1004 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector);
1031 auto callable = tester.GetCallable<Handle<Object>>(); 1005 auto callable = tester.GetCallable<Handle<Object>>();
1032 1006
1033 Handle<Object> object = InterpreterTester::NewObject( 1007 Handle<Object> object = InterpreterTester::NewObject(
1034 "new (function Obj() { " 1008 "new (function Obj() { "
1035 " this.func = function(a, b) { return a - b; }" 1009 " this.func = function(a, b) { return a - b; }"
1036 "})()"); 1010 "})()");
1037 Handle<Object> return_val = callable(object).ToHandleChecked(); 1011 Handle<Object> return_val = callable(object).ToHandleChecked();
(...skipping 20 matching lines...) Expand all
1058 .StoreAccumulatorInRegister(Register(6)) 1032 .StoreAccumulatorInRegister(Register(6))
1059 .LoadLiteral(factory->NewStringFromAsciiChecked("f")) 1033 .LoadLiteral(factory->NewStringFromAsciiChecked("f"))
1060 .StoreAccumulatorInRegister(Register(7)) 1034 .StoreAccumulatorInRegister(Register(7))
1061 .LoadLiteral(factory->NewStringFromAsciiChecked("g")) 1035 .LoadLiteral(factory->NewStringFromAsciiChecked("g"))
1062 .StoreAccumulatorInRegister(Register(8)) 1036 .StoreAccumulatorInRegister(Register(8))
1063 .LoadLiteral(factory->NewStringFromAsciiChecked("h")) 1037 .LoadLiteral(factory->NewStringFromAsciiChecked("h"))
1064 .StoreAccumulatorInRegister(Register(9)) 1038 .StoreAccumulatorInRegister(Register(9))
1065 .LoadLiteral(factory->NewStringFromAsciiChecked("i")) 1039 .LoadLiteral(factory->NewStringFromAsciiChecked("i"))
1066 .StoreAccumulatorInRegister(Register(10)) 1040 .StoreAccumulatorInRegister(Register(10))
1067 .LoadLiteral(factory->NewStringFromAsciiChecked("j")) 1041 .LoadLiteral(factory->NewStringFromAsciiChecked("j"))
1068 .StoreAccumulatorInRegister(Register(11)); 1042 .StoreAccumulatorInRegister(Register(11))
1069 1043 .Call(Register(0), Register(1), 11, 0, tail_call_mode)
1070 if (has_feedback_slot) { 1044 .Return();
1071 builder.CallIC(Register(0), Register(1), 11, call_slot_index,
1072 tail_call_mode);
1073 } else {
1074 builder.Call(Register(0), Register(1), 11, tail_call_mode);
1075 }
1076
1077 builder.Return();
1078
1079 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 1045 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
1080 1046
1081 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); 1047 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector);
1082 auto callable = tester.GetCallable<Handle<Object>>(); 1048 auto callable = tester.GetCallable<Handle<Object>>();
1083 1049
1084 Handle<Object> object = InterpreterTester::NewObject( 1050 Handle<Object> object = InterpreterTester::NewObject(
1085 "new (function Obj() { " 1051 "new (function Obj() { "
1086 " this.prefix = \"prefix_\";" 1052 " this.prefix = \"prefix_\";"
1087 " this.func = function(a, b, c, d, e, f, g, h, i, j) {" 1053 " this.func = function(a, b, c, d, e, f, g, h, i, j) {"
1088 " return this.prefix + a + b + c + d + e + f + g + h + i + j;" 1054 " return this.prefix + a + b + c + d + e + f + g + h + i + j;"
1089 " }" 1055 " }"
1090 "})()"); 1056 "})()");
1091 Handle<Object> return_val = callable(object).ToHandleChecked(); 1057 Handle<Object> return_val = callable(object).ToHandleChecked();
1092 Handle<i::String> expected = 1058 Handle<i::String> expected =
1093 factory->NewStringFromAsciiChecked("prefix_abcdefghij"); 1059 factory->NewStringFromAsciiChecked("prefix_abcdefghij");
1094 CHECK(i::String::cast(*return_val)->Equals(*expected)); 1060 CHECK(i::String::cast(*return_val)->Equals(*expected));
1095 } 1061 }
1096 } 1062 }
1097 1063
1098 TEST(InterpreterCall) { TestInterpreterCall(TailCallMode::kDisallow, false); } 1064 TEST(InterpreterCall) { TestInterpreterCall(TailCallMode::kDisallow); }
1099 1065
1100 TEST(InterpreterTailCall) { TestInterpreterCall(TailCallMode::kAllow, false); } 1066 TEST(InterpreterTailCall) { TestInterpreterCall(TailCallMode::kAllow); }
1101
1102 TEST(InterpreterCallIC) { TestInterpreterCall(TailCallMode::kDisallow, true); }
1103
1104 TEST(InterpreterTailCallIC) { TestInterpreterCall(TailCallMode::kAllow, true); }
1105 1067
1106 static BytecodeArrayBuilder& SetRegister(BytecodeArrayBuilder& builder, 1068 static BytecodeArrayBuilder& SetRegister(BytecodeArrayBuilder& builder,
1107 Register reg, int value, 1069 Register reg, int value,
1108 Register scratch) { 1070 Register scratch) {
1109 return builder.StoreAccumulatorInRegister(scratch) 1071 return builder.StoreAccumulatorInRegister(scratch)
1110 .LoadLiteral(Smi::FromInt(value)) 1072 .LoadLiteral(Smi::FromInt(value))
1111 .StoreAccumulatorInRegister(reg) 1073 .StoreAccumulatorInRegister(reg)
1112 .LoadAccumulatorWithRegister(scratch); 1074 .LoadAccumulatorWithRegister(scratch);
1113 } 1075 }
1114 1076
(...skipping 3081 matching lines...) Expand 10 before | Expand all | Expand 10 after
4196 Handle<i::Object> return_value = callable().ToHandleChecked(); 4158 Handle<i::Object> return_value = callable().ToHandleChecked();
4197 CHECK(return_value->SameValue(*const_decl[i].second)); 4159 CHECK(return_value->SameValue(*const_decl[i].second));
4198 } 4160 }
4199 4161
4200 FLAG_legacy_const = old_flag_legacy_const; 4162 FLAG_legacy_const = old_flag_legacy_const;
4201 } 4163 }
4202 4164
4203 } // namespace interpreter 4165 } // namespace interpreter
4204 } // namespace internal 4166 } // namespace internal
4205 } // namespace v8 4167 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | test/mjsunit/mjsunit.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698