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

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

Issue 1419003002: [Interpreter] Unify global and unallocated variable access. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix unallocated variable error Created 5 years, 2 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
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 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 Handle<i::TypeFeedbackVector> vector = 773 Handle<i::TypeFeedbackVector> vector =
774 i::NewTypeFeedbackVector(isolate, &feedback_spec); 774 i::NewTypeFeedbackVector(isolate, &feedback_spec);
775 775
776 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); 776 Handle<i::String> name = factory->NewStringFromAsciiChecked("val");
777 name = factory->string_table()->LookupString(isolate, name); 777 name = factory->string_table()->LookupString(isolate, name);
778 778
779 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); 779 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
780 builder.set_locals_count(0); 780 builder.set_locals_count(0);
781 builder.set_context_count(0); 781 builder.set_context_count(0);
782 builder.set_parameter_count(1); 782 builder.set_parameter_count(1);
783 builder.LoadLiteral(name) 783 size_t name_index = builder.GetConstantPoolEntry(name);
784 .LoadNamedProperty(builder.Parameter(0), vector->GetIndex(slot), 784 builder.LoadNamedProperty(builder.Parameter(0), name_index,
785 i::SLOPPY) 785 vector->GetIndex(slot), i::SLOPPY)
786 .Return(); 786 .Return();
787 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 787 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
788 788
789 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); 789 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector);
790 auto callable = tester.GetCallable<Handle<Object>>(); 790 auto callable = tester.GetCallable<Handle<Object>>();
791 791
792 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); 792 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })");
793 // Test IC miss. 793 // Test IC miss.
794 Handle<Object> return_val = callable(object).ToHandleChecked(); 794 Handle<Object> return_val = callable(object).ToHandleChecked();
795 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123)); 795 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(123));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 i::FeedbackVectorSpec feedback_spec(&zone); 872 i::FeedbackVectorSpec feedback_spec(&zone);
873 i::FeedbackVectorSlot slot = feedback_spec.AddStoreICSlot(); 873 i::FeedbackVectorSlot slot = feedback_spec.AddStoreICSlot();
874 874
875 Handle<i::TypeFeedbackVector> vector = 875 Handle<i::TypeFeedbackVector> vector =
876 i::NewTypeFeedbackVector(isolate, &feedback_spec); 876 i::NewTypeFeedbackVector(isolate, &feedback_spec);
877 877
878 Handle<i::String> name = factory->NewStringFromAsciiChecked("val"); 878 Handle<i::String> name = factory->NewStringFromAsciiChecked("val");
879 name = factory->string_table()->LookupString(isolate, name); 879 name = factory->string_table()->LookupString(isolate, name);
880 880
881 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); 881 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
882 builder.set_locals_count(1); 882 builder.set_locals_count(0);
883 builder.set_context_count(0); 883 builder.set_context_count(0);
884 builder.set_parameter_count(1); 884 builder.set_parameter_count(1);
885 builder.LoadLiteral(name) 885 size_t name_index = builder.GetConstantPoolEntry(name);
886 .StoreAccumulatorInRegister(Register(0)) 886 builder.LoadLiteral(Smi::FromInt(999))
887 .LoadLiteral(Smi::FromInt(999)) 887 .StoreNamedProperty(builder.Parameter(0), name_index,
888 .StoreNamedProperty(builder.Parameter(0), Register(0),
889 vector->GetIndex(slot), i::STRICT) 888 vector->GetIndex(slot), i::STRICT)
890 .Return(); 889 .Return();
891 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 890 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
892 891
893 InterpreterTester tester(isolate, bytecode_array, vector); 892 InterpreterTester tester(isolate, bytecode_array, vector);
894 auto callable = tester.GetCallable<Handle<Object>>(); 893 auto callable = tester.GetCallable<Handle<Object>>();
895 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })"); 894 Handle<Object> object = InterpreterTester::NewObject("({ val : 123 })");
896 // Test IC miss. 895 // Test IC miss.
897 Handle<Object> result; 896 Handle<Object> result;
898 callable(object).ToHandleChecked(); 897 callable(object).ToHandleChecked();
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 990
992 Handle<i::String> name = factory->NewStringFromAsciiChecked("func"); 991 Handle<i::String> name = factory->NewStringFromAsciiChecked("func");
993 name = factory->string_table()->LookupString(isolate, name); 992 name = factory->string_table()->LookupString(isolate, name);
994 993
995 // Check with no args. 994 // Check with no args.
996 { 995 {
997 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); 996 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
998 builder.set_locals_count(1); 997 builder.set_locals_count(1);
999 builder.set_context_count(0); 998 builder.set_context_count(0);
1000 builder.set_parameter_count(1); 999 builder.set_parameter_count(1);
1001 builder.LoadLiteral(name) 1000 size_t name_index = builder.GetConstantPoolEntry(name);
1002 .LoadNamedProperty(builder.Parameter(0), slot_index, i::SLOPPY) 1001 builder.LoadNamedProperty(builder.Parameter(0), name_index, slot_index,
1002 i::SLOPPY)
1003 .StoreAccumulatorInRegister(Register(0)) 1003 .StoreAccumulatorInRegister(Register(0))
1004 .Call(Register(0), builder.Parameter(0), 0) 1004 .Call(Register(0), builder.Parameter(0), 0)
1005 .Return(); 1005 .Return();
1006 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 1006 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
1007 1007
1008 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); 1008 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector);
1009 auto callable = tester.GetCallable<Handle<Object>>(); 1009 auto callable = tester.GetCallable<Handle<Object>>();
1010 1010
1011 Handle<Object> object = InterpreterTester::NewObject( 1011 Handle<Object> object = InterpreterTester::NewObject(
1012 "new (function Obj() { this.func = function() { return 0x265; }})()"); 1012 "new (function Obj() { this.func = function() { return 0x265; }})()");
1013 Handle<Object> return_val = callable(object).ToHandleChecked(); 1013 Handle<Object> return_val = callable(object).ToHandleChecked();
1014 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0x265)); 1014 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0x265));
1015 } 1015 }
1016 1016
1017 // Check that receiver is passed properly. 1017 // Check that receiver is passed properly.
1018 { 1018 {
1019 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); 1019 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
1020 builder.set_locals_count(1); 1020 builder.set_locals_count(1);
1021 builder.set_context_count(0); 1021 builder.set_context_count(0);
1022 builder.set_parameter_count(1); 1022 builder.set_parameter_count(1);
1023 builder.LoadLiteral(name) 1023 size_t name_index = builder.GetConstantPoolEntry(name);
1024 .LoadNamedProperty(builder.Parameter(0), slot_index, i::SLOPPY) 1024 builder.LoadNamedProperty(builder.Parameter(0), name_index, slot_index,
1025 i::SLOPPY)
1025 .StoreAccumulatorInRegister(Register(0)) 1026 .StoreAccumulatorInRegister(Register(0))
1026 .Call(Register(0), builder.Parameter(0), 0) 1027 .Call(Register(0), builder.Parameter(0), 0)
1027 .Return(); 1028 .Return();
1028 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 1029 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
1029 1030
1030 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); 1031 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector);
1031 auto callable = tester.GetCallable<Handle<Object>>(); 1032 auto callable = tester.GetCallable<Handle<Object>>();
1032 1033
1033 Handle<Object> object = InterpreterTester::NewObject( 1034 Handle<Object> object = InterpreterTester::NewObject(
1034 "new (function Obj() {" 1035 "new (function Obj() {"
1035 " this.val = 1234;" 1036 " this.val = 1234;"
1036 " this.func = function() { return this.val; };" 1037 " this.func = function() { return this.val; };"
1037 "})()"); 1038 "})()");
1038 Handle<Object> return_val = callable(object).ToHandleChecked(); 1039 Handle<Object> return_val = callable(object).ToHandleChecked();
1039 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(1234)); 1040 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(1234));
1040 } 1041 }
1041 1042
1042 // Check with two parameters (+ receiver). 1043 // Check with two parameters (+ receiver).
1043 { 1044 {
1044 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); 1045 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
1045 builder.set_locals_count(4); 1046 builder.set_locals_count(4);
1046 builder.set_context_count(0); 1047 builder.set_context_count(0);
1047 builder.set_parameter_count(1); 1048 builder.set_parameter_count(1);
1048 builder.LoadLiteral(name) 1049 size_t name_index = builder.GetConstantPoolEntry(name);
1049 .LoadNamedProperty(builder.Parameter(0), slot_index, i::SLOPPY) 1050 builder.LoadNamedProperty(builder.Parameter(0), name_index, slot_index,
1051 i::SLOPPY)
1050 .StoreAccumulatorInRegister(Register(0)) 1052 .StoreAccumulatorInRegister(Register(0))
1051 .LoadAccumulatorWithRegister(builder.Parameter(0)) 1053 .LoadAccumulatorWithRegister(builder.Parameter(0))
1052 .StoreAccumulatorInRegister(Register(1)) 1054 .StoreAccumulatorInRegister(Register(1))
1053 .LoadLiteral(Smi::FromInt(51)) 1055 .LoadLiteral(Smi::FromInt(51))
1054 .StoreAccumulatorInRegister(Register(2)) 1056 .StoreAccumulatorInRegister(Register(2))
1055 .LoadLiteral(Smi::FromInt(11)) 1057 .LoadLiteral(Smi::FromInt(11))
1056 .StoreAccumulatorInRegister(Register(3)) 1058 .StoreAccumulatorInRegister(Register(3))
1057 .Call(Register(0), Register(1), 2) 1059 .Call(Register(0), Register(1), 2)
1058 .Return(); 1060 .Return();
1059 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 1061 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
1060 1062
1061 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector); 1063 InterpreterTester tester(handles.main_isolate(), bytecode_array, vector);
1062 auto callable = tester.GetCallable<Handle<Object>>(); 1064 auto callable = tester.GetCallable<Handle<Object>>();
1063 1065
1064 Handle<Object> object = InterpreterTester::NewObject( 1066 Handle<Object> object = InterpreterTester::NewObject(
1065 "new (function Obj() { " 1067 "new (function Obj() { "
1066 " this.func = function(a, b) { return a - b; }" 1068 " this.func = function(a, b) { return a - b; }"
1067 "})()"); 1069 "})()");
1068 Handle<Object> return_val = callable(object).ToHandleChecked(); 1070 Handle<Object> return_val = callable(object).ToHandleChecked();
1069 CHECK(return_val->SameValue(Smi::FromInt(40))); 1071 CHECK(return_val->SameValue(Smi::FromInt(40)));
1070 } 1072 }
1071 1073
1072 // Check with 10 parameters (+ receiver). 1074 // Check with 10 parameters (+ receiver).
1073 { 1075 {
1074 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); 1076 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
1075 builder.set_locals_count(12); 1077 builder.set_locals_count(12);
1076 builder.set_context_count(0); 1078 builder.set_context_count(0);
1077 builder.set_parameter_count(1); 1079 builder.set_parameter_count(1);
1078 builder.LoadLiteral(name) 1080 size_t name_index = builder.GetConstantPoolEntry(name);
1079 .LoadNamedProperty(builder.Parameter(0), slot_index, i::SLOPPY) 1081 builder.LoadNamedProperty(builder.Parameter(0), name_index, slot_index,
1082 i::SLOPPY)
1080 .StoreAccumulatorInRegister(Register(0)) 1083 .StoreAccumulatorInRegister(Register(0))
1081 .LoadAccumulatorWithRegister(builder.Parameter(0)) 1084 .LoadAccumulatorWithRegister(builder.Parameter(0))
1082 .StoreAccumulatorInRegister(Register(1)) 1085 .StoreAccumulatorInRegister(Register(1))
1083 .LoadLiteral(factory->NewStringFromAsciiChecked("a")) 1086 .LoadLiteral(factory->NewStringFromAsciiChecked("a"))
1084 .StoreAccumulatorInRegister(Register(2)) 1087 .StoreAccumulatorInRegister(Register(2))
1085 .LoadLiteral(factory->NewStringFromAsciiChecked("b")) 1088 .LoadLiteral(factory->NewStringFromAsciiChecked("b"))
1086 .StoreAccumulatorInRegister(Register(3)) 1089 .StoreAccumulatorInRegister(Register(3))
1087 .LoadLiteral(factory->NewStringFromAsciiChecked("c")) 1090 .LoadLiteral(factory->NewStringFromAsciiChecked("c"))
1088 .StoreAccumulatorInRegister(Register(4)) 1091 .StoreAccumulatorInRegister(Register(4))
1089 .LoadLiteral(factory->NewStringFromAsciiChecked("d")) 1092 .LoadLiteral(factory->NewStringFromAsciiChecked("d"))
(...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after
2055 "(function() { try { f(); } catch(e) { return e; }})()"; 2058 "(function() { try { f(); } catch(e) { return e; }})()";
2056 2059
2057 for (size_t i = 0; i < arraysize(throws); i++) { 2060 for (size_t i = 0; i < arraysize(throws); i++) {
2058 std::string source(InterpreterTester::SourceForBody(throws[i].first)); 2061 std::string source(InterpreterTester::SourceForBody(throws[i].first));
2059 InterpreterTester tester(handles.main_isolate(), source.c_str()); 2062 InterpreterTester tester(handles.main_isolate(), source.c_str());
2060 tester.GetCallable<>(); 2063 tester.GetCallable<>();
2061 Handle<Object> thrown_obj = v8::Utils::OpenHandle(*CompileRun(try_wrapper)); 2064 Handle<Object> thrown_obj = v8::Utils::OpenHandle(*CompileRun(try_wrapper));
2062 CHECK(thrown_obj->SameValue(*throws[i].second)); 2065 CHECK(thrown_obj->SameValue(*throws[i].second));
2063 } 2066 }
2064 } 2067 }
OLDNEW
« no previous file with comments | « test/cctest/interpreter/test-bytecode-generator.cc ('k') | test/unittests/interpreter/bytecode-array-builder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698