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/compiler.h" | 7 #include "src/compiler.h" |
8 #include "src/interpreter/bytecode-array-iterator.h" | 8 #include "src/interpreter/bytecode-array-iterator.h" |
9 #include "src/interpreter/bytecode-generator.h" | 9 #include "src/interpreter/bytecode-generator.h" |
10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 Handle<BytecodeArray> bytecode_array = | 1012 Handle<BytecodeArray> bytecode_array = |
1013 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); | 1013 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); |
1014 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 1014 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
1015 } | 1015 } |
1016 } | 1016 } |
1017 | 1017 |
1018 | 1018 |
1019 TEST(LoadGlobal) { | 1019 TEST(LoadGlobal) { |
1020 InitializedHandleScope handle_scope; | 1020 InitializedHandleScope handle_scope; |
1021 BytecodeGeneratorHelper helper; | 1021 BytecodeGeneratorHelper helper; |
| 1022 Zone zone; |
1022 | 1023 |
1023 if (!FLAG_global_var_shortcuts) return; | 1024 int context_reg = Register::function_context().index(); |
| 1025 int global_index = Context::GLOBAL_OBJECT_INDEX; |
1024 | 1026 |
1025 ExpectedSnippet<int> snippets[] = { | 1027 FeedbackVectorSpec feedback_spec(&zone); |
| 1028 FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot(); |
| 1029 |
| 1030 Handle<i::TypeFeedbackVector> vector = |
| 1031 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 1032 |
| 1033 ExpectedSnippet<InstanceType> snippets[] = { |
1026 { | 1034 { |
1027 "var a = 1;\nfunction f() { return a; }\nf()", | 1035 "var a = 1;\nfunction f() { return a; }\nf()", |
1028 0, | 1036 kPointerSize, |
1029 1, | 1037 1, |
1030 3, | 1038 11, |
1031 { | 1039 { |
1032 B(LdaGlobal), _, // | 1040 B(LdaContextSlot), R(context_reg), U8(global_index), // |
1033 B(Return) // | 1041 B(Star), R(0), // |
| 1042 B(LdaConstant), U8(0), // |
| 1043 B(LoadICSloppy), R(0), U8(vector->GetIndex(slot1)), // |
| 1044 B(Return) // |
1034 }, | 1045 }, |
| 1046 1, |
| 1047 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}, |
1035 }, | 1048 }, |
1036 { | 1049 { |
1037 "function t() { }\nfunction f() { return t; }\nf()", | 1050 "function t() { }\nfunction f() { return t; }\nf()", |
1038 0, | 1051 kPointerSize, |
1039 1, | 1052 1, |
1040 3, | 1053 11, |
1041 { | 1054 { |
1042 B(LdaGlobal), _, // | 1055 B(LdaContextSlot), R(context_reg), U8(global_index), // |
1043 B(Return) // | 1056 B(Star), R(0), // |
| 1057 B(LdaConstant), U8(0), // |
| 1058 B(LoadICSloppy), R(0), U8(vector->GetIndex(slot1)), // |
| 1059 B(Return) // |
1044 }, | 1060 }, |
| 1061 1, |
| 1062 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}, |
1045 }, | 1063 }, |
1046 }; | 1064 }; |
1047 | 1065 |
1048 for (size_t i = 0; i < arraysize(snippets); i++) { | 1066 for (size_t i = 0; i < arraysize(snippets); i++) { |
1049 Handle<BytecodeArray> bytecode_array = | 1067 Handle<BytecodeArray> bytecode_array = |
1050 helper.MakeBytecode(snippets[i].code_snippet, "f"); | 1068 helper.MakeBytecode(snippets[i].code_snippet, "f"); |
1051 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); | 1069 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); |
1052 } | 1070 } |
1053 } | 1071 } |
1054 | 1072 |
1055 | 1073 |
1056 TEST(StoreGlobal) { | 1074 TEST(StoreGlobal) { |
1057 InitializedHandleScope handle_scope; | 1075 InitializedHandleScope handle_scope; |
1058 BytecodeGeneratorHelper helper; | 1076 BytecodeGeneratorHelper helper; |
| 1077 Zone zone; |
1059 | 1078 |
1060 if (!FLAG_global_var_shortcuts) return; | 1079 int context_reg = Register::function_context().index(); |
| 1080 int global_index = Context::GLOBAL_OBJECT_INDEX; |
| 1081 |
| 1082 FeedbackVectorSpec feedback_spec(&zone); |
| 1083 FeedbackVectorSlot slot1 = feedback_spec.AddStoreICSlot(); |
| 1084 |
| 1085 Handle<i::TypeFeedbackVector> vector = |
| 1086 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
1061 | 1087 |
1062 ExpectedSnippet<InstanceType> snippets[] = { | 1088 ExpectedSnippet<InstanceType> snippets[] = { |
1063 { | 1089 { |
1064 "var a = 1;\nfunction f() { a = 2; }\nf()", | 1090 "var a = 1;\nfunction f() { a = 2; }\nf()", |
1065 0, | 1091 3 * kPointerSize, |
1066 1, | 1092 1, |
1067 6, | 1093 21, |
1068 { | 1094 { |
1069 B(LdaSmi8), U8(2), // | 1095 B(LdaSmi8), U8(2), // |
1070 B(StaGlobalSloppy), _, // | 1096 B(Star), R(0), // |
1071 B(LdaUndefined), // | 1097 B(LdaContextSlot), R(context_reg), U8(global_index), // |
1072 B(Return) // | 1098 B(Star), R(1), // |
| 1099 B(LdaConstant), U8(0), // |
| 1100 B(Star), R(2), // |
| 1101 B(Ldar), R(0), // |
| 1102 B(StoreICSloppy), R(1), R(2), U8(vector->GetIndex(slot1)), // |
| 1103 B(LdaUndefined), // |
| 1104 B(Return) // |
1073 }, | 1105 }, |
| 1106 1, |
| 1107 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}, |
1074 }, | 1108 }, |
1075 { | 1109 { |
1076 "var a = \"test\"; function f(b) { a = b; }\nf(\"global\")", | 1110 "var a = \"test\"; function f(b) { a = b; }\nf(\"global\")", |
1077 0, | 1111 3 * kPointerSize, |
1078 2, | 1112 2, |
1079 6, | 1113 21, |
1080 { | 1114 { |
1081 B(Ldar), R(helper.kLastParamIndex), // | 1115 B(Ldar), R(helper.kLastParamIndex), // |
1082 B(StaGlobalSloppy), _, // | 1116 B(Star), R(0), // |
1083 B(LdaUndefined), // | 1117 B(LdaContextSlot), R(context_reg), U8(global_index), // |
1084 B(Return) // | 1118 B(Star), R(1), // |
| 1119 B(LdaConstant), U8(0), // |
| 1120 B(Star), R(2), // |
| 1121 B(Ldar), R(0), // |
| 1122 B(StoreICSloppy), R(1), R(2), U8(vector->GetIndex(slot1)), // |
| 1123 B(LdaUndefined), // |
| 1124 B(Return) // |
1085 }, | 1125 }, |
| 1126 1, |
| 1127 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}, |
1086 }, | 1128 }, |
1087 { | 1129 { |
1088 "'use strict'; var a = 1;\nfunction f() { a = 2; }\nf()", | 1130 "'use strict'; var a = 1;\nfunction f() { a = 2; }\nf()", |
1089 0, | 1131 3 * kPointerSize, |
1090 1, | 1132 1, |
1091 6, | 1133 21, |
1092 { | 1134 { |
1093 B(LdaSmi8), U8(2), // | 1135 B(LdaSmi8), U8(2), // |
1094 B(StaGlobalStrict), _, // | 1136 B(Star), R(0), // |
1095 B(LdaUndefined), // | 1137 B(LdaContextSlot), R(context_reg), U8(global_index), // |
1096 B(Return) // | 1138 B(Star), R(1), // |
| 1139 B(LdaConstant), U8(0), // |
| 1140 B(Star), R(2), // |
| 1141 B(Ldar), R(0), // |
| 1142 B(StoreICStrict), R(1), R(2), U8(vector->GetIndex(slot1)), // |
| 1143 B(LdaUndefined), // |
| 1144 B(Return) // |
1097 }, | 1145 }, |
| 1146 1, |
| 1147 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}, |
1098 }, | 1148 }, |
1099 }; | 1149 }; |
1100 | 1150 |
1101 for (size_t i = 0; i < arraysize(snippets); i++) { | 1151 for (size_t i = 0; i < arraysize(snippets); i++) { |
1102 Handle<BytecodeArray> bytecode_array = | 1152 Handle<BytecodeArray> bytecode_array = |
1103 helper.MakeBytecode(snippets[i].code_snippet, "f"); | 1153 helper.MakeBytecode(snippets[i].code_snippet, "f"); |
1104 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); | 1154 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); |
1105 } | 1155 } |
1106 } | 1156 } |
1107 | 1157 |
1108 | 1158 |
1109 TEST(CallGlobal) { | 1159 TEST(CallGlobal) { |
1110 InitializedHandleScope handle_scope; | 1160 InitializedHandleScope handle_scope; |
1111 BytecodeGeneratorHelper helper; | 1161 BytecodeGeneratorHelper helper; |
| 1162 Zone zone; |
1112 | 1163 |
1113 if (!FLAG_global_var_shortcuts) return; | 1164 int context_reg = Register::function_context().index(); |
| 1165 int global_index = Context::GLOBAL_OBJECT_INDEX; |
1114 | 1166 |
1115 ExpectedSnippet<int> snippets[] = { | 1167 FeedbackVectorSpec feedback_spec(&zone); |
| 1168 FeedbackVectorSlot slot1 = feedback_spec.AddCallICSlot(); |
| 1169 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot(); |
| 1170 USE(slot1); |
| 1171 |
| 1172 Handle<i::TypeFeedbackVector> vector = |
| 1173 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 1174 |
| 1175 ExpectedSnippet<InstanceType> snippets[] = { |
1116 { | 1176 { |
1117 "function t() { }\nfunction f() { return t(); }\nf()", | 1177 "function t() { }\nfunction f() { return t(); }\nf()", |
1118 2 * kPointerSize, | 1178 3 * kPointerSize, |
1119 1, | 1179 1, |
1120 12, | 1180 20, |
1121 { | 1181 { |
1122 B(LdaUndefined), // | 1182 B(LdaUndefined), // |
1123 B(Star), R(1), // | 1183 B(Star), R(1), // |
1124 B(LdaGlobal), _, // | 1184 B(LdaContextSlot), R(context_reg), U8(global_index), // |
1125 B(Star), R(0), // | 1185 B(Star), R(2), // |
1126 B(Call), R(0), R(1), U8(0), // | 1186 B(LdaConstant), U8(0), // |
1127 B(Return) // | 1187 B(LoadICSloppy), R(2), U8(vector->GetIndex(slot2)), // |
| 1188 B(Star), R(0), // |
| 1189 B(Call), R(0), R(1), U8(0), // |
| 1190 B(Return) // |
1128 }, | 1191 }, |
| 1192 1, |
| 1193 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}, |
1129 }, | 1194 }, |
1130 { | 1195 { |
1131 "function t(a, b, c) { }\nfunction f() { return t(1, 2, 3); }\nf()", | 1196 "function t(a, b, c) { }\nfunction f() { return t(1, 2, 3); }\nf()", |
1132 5 * kPointerSize, | 1197 5 * kPointerSize, |
1133 1, | 1198 1, |
1134 24, | 1199 32, |
1135 { | 1200 { |
1136 B(LdaUndefined), // | 1201 B(LdaUndefined), // |
1137 B(Star), R(1), // | 1202 B(Star), R(1), // |
1138 B(LdaGlobal), _, // | 1203 B(LdaContextSlot), R(context_reg), U8(global_index), // |
1139 B(Star), R(0), // | 1204 B(Star), R(2), // |
1140 B(LdaSmi8), U8(1), // | 1205 B(LdaConstant), U8(0), // |
1141 B(Star), R(2), // | 1206 B(LoadICSloppy), R(2), U8(vector->GetIndex(slot2)), // |
1142 B(LdaSmi8), U8(2), // | 1207 B(Star), R(0), // |
1143 B(Star), R(3), // | 1208 B(LdaSmi8), U8(1), // |
1144 B(LdaSmi8), U8(3), // | 1209 B(Star), R(2), // |
1145 B(Star), R(4), // | 1210 B(LdaSmi8), U8(2), // |
1146 B(Call), R(0), R(1), U8(3), // | 1211 B(Star), R(3), // |
1147 B(Return) // | 1212 B(LdaSmi8), U8(3), // |
| 1213 B(Star), R(4), // |
| 1214 B(Call), R(0), R(1), U8(3), // |
| 1215 B(Return) // |
1148 }, | 1216 }, |
| 1217 1, |
| 1218 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}, |
1149 }, | 1219 }, |
1150 }; | 1220 }; |
1151 | 1221 |
1152 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); | 1222 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); |
1153 for (size_t i = 0; i < num_snippets; i++) { | 1223 for (size_t i = 0; i < num_snippets; i++) { |
1154 Handle<BytecodeArray> bytecode_array = | 1224 Handle<BytecodeArray> bytecode_array = |
1155 helper.MakeBytecode(snippets[i].code_snippet, "f"); | 1225 helper.MakeBytecode(snippets[i].code_snippet, "f"); |
1156 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); | 1226 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); |
1157 } | 1227 } |
1158 } | 1228 } |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1473 }; | 1543 }; |
1474 | 1544 |
1475 for (size_t i = 0; i < arraysize(snippets); i++) { | 1545 for (size_t i = 0; i < arraysize(snippets); i++) { |
1476 Handle<BytecodeArray> bytecode_array = | 1546 Handle<BytecodeArray> bytecode_array = |
1477 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); | 1547 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); |
1478 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 1548 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
1479 } | 1549 } |
1480 } | 1550 } |
1481 | 1551 |
1482 | 1552 |
1483 // Tests !FLAG_global_var_shortcuts mode. | |
1484 TEST(DeclareGlobals) { | 1553 TEST(DeclareGlobals) { |
1485 InitializedHandleScope handle_scope; | 1554 InitializedHandleScope handle_scope; |
1486 BytecodeGeneratorHelper helper; | 1555 BytecodeGeneratorHelper helper; |
1487 Zone zone; | 1556 Zone zone; |
1488 | 1557 |
1489 if (FLAG_global_var_shortcuts) return; | |
1490 | |
1491 int context_reg = Register::function_context().index(); | 1558 int context_reg = Register::function_context().index(); |
1492 int global_index = Context::GLOBAL_OBJECT_INDEX; | 1559 int global_index = Context::GLOBAL_OBJECT_INDEX; |
1493 | 1560 |
1494 // Create different feedback vector specs to be precise on slot numbering. | 1561 // Create different feedback vector specs to be precise on slot numbering. |
1495 FeedbackVectorSpec feedback_spec_ss(&zone); | 1562 FeedbackVectorSpec feedback_spec_ss(&zone); |
1496 FeedbackVectorSlot slot_ss_1 = feedback_spec_ss.AddStoreICSlot(); | 1563 FeedbackVectorSlot slot_ss_1 = feedback_spec_ss.AddStoreICSlot(); |
1497 FeedbackVectorSlot slot_ss_2 = feedback_spec_ss.AddStoreICSlot(); | 1564 FeedbackVectorSlot slot_ss_2 = feedback_spec_ss.AddStoreICSlot(); |
1498 USE(slot_ss_1); | 1565 USE(slot_ss_1); |
1499 | 1566 |
1500 Handle<i::TypeFeedbackVector> vector_ss = | 1567 Handle<i::TypeFeedbackVector> vector_ss = |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1608 }; | 1675 }; |
1609 | 1676 |
1610 for (size_t i = 0; i < arraysize(snippets); i++) { | 1677 for (size_t i = 0; i < arraysize(snippets); i++) { |
1611 Handle<BytecodeArray> bytecode_array = | 1678 Handle<BytecodeArray> bytecode_array = |
1612 helper.MakeTopLevelBytecode(snippets[i].code_snippet); | 1679 helper.MakeTopLevelBytecode(snippets[i].code_snippet); |
1613 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); | 1680 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); |
1614 } | 1681 } |
1615 } | 1682 } |
1616 | 1683 |
1617 | 1684 |
1618 // Tests FLAG_global_var_shortcuts mode. | |
1619 // TODO(ishell): remove when FLAG_global_var_shortcuts is removed. | |
1620 TEST(DeclareGlobals2) { | |
1621 InitializedHandleScope handle_scope; | |
1622 BytecodeGeneratorHelper helper; | |
1623 | |
1624 if (!FLAG_global_var_shortcuts) return; | |
1625 | |
1626 ExpectedSnippet<InstanceType> snippets[] = { | |
1627 {"var a = 1;", | |
1628 5 * kPointerSize, | |
1629 1, | |
1630 45, | |
1631 { | |
1632 B(Ldar), R(Register::function_closure().index()), // | |
1633 B(Star), R(2), // | |
1634 B(LdaConstant), U8(0), // | |
1635 B(Star), R(3), // | |
1636 B(CallRuntime), U16(Runtime::kNewScriptContext), R(2), U8(2), // | |
1637 B(PushContext), R(1), // | |
1638 B(LdaConstant), U8(1), // | |
1639 B(Star), R(2), // | |
1640 B(LdaZero), // | |
1641 B(Star), R(3), // | |
1642 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(2), U8(2), // | |
1643 B(LdaConstant), U8(2), // | |
1644 B(Star), R(2), // | |
1645 B(LdaZero), // | |
1646 B(Star), R(3), // | |
1647 B(LdaSmi8), U8(1), // | |
1648 B(Star), R(4), // | |
1649 B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(2), U8(3), // | |
1650 B(LdaUndefined), // | |
1651 B(Return), // | |
1652 }, | |
1653 3, | |
1654 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE, | |
1655 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | |
1656 {"function f() {}", | |
1657 3 * kPointerSize, | |
1658 1, | |
1659 29, | |
1660 { | |
1661 B(Ldar), R(Register::function_closure().index()), // | |
1662 B(Star), R(1), // | |
1663 B(LdaConstant), U8(0), // | |
1664 B(Star), R(2), // | |
1665 B(CallRuntime), U16(Runtime::kNewScriptContext), R(1), U8(2), // | |
1666 B(PushContext), R(0), // | |
1667 B(LdaConstant), U8(1), // | |
1668 B(Star), R(1), // | |
1669 B(LdaZero), // | |
1670 B(Star), R(2), // | |
1671 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2), // | |
1672 B(LdaUndefined), // | |
1673 B(Return) // | |
1674 }, | |
1675 2, | |
1676 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE}}, | |
1677 {"var a = 1;\na=2;", | |
1678 5 * kPointerSize, | |
1679 1, | |
1680 52, | |
1681 { | |
1682 B(Ldar), R(Register::function_closure().index()), // | |
1683 B(Star), R(2), // | |
1684 B(LdaConstant), U8(0), // | |
1685 B(Star), R(3), // | |
1686 B(CallRuntime), U16(Runtime::kNewScriptContext), R(2), U8(2), // | |
1687 B(PushContext), R(1), // | |
1688 B(LdaConstant), U8(1), // | |
1689 B(Star), R(2), // | |
1690 B(LdaZero), // | |
1691 B(Star), R(3), // | |
1692 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(2), U8(2), // | |
1693 B(LdaConstant), U8(2), // | |
1694 B(Star), R(2), // | |
1695 B(LdaZero), // | |
1696 B(Star), R(3), // | |
1697 B(LdaSmi8), U8(1), // | |
1698 B(Star), R(4), // | |
1699 B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(2), // | |
1700 U8(3), // | |
1701 B(LdaSmi8), U8(2), // | |
1702 B(StaGlobalSloppy), _, // | |
1703 B(Star), R(0), // | |
1704 B(Ldar), R(0), // | |
1705 B(Return) // | |
1706 }, | |
1707 3, | |
1708 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE, | |
1709 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | |
1710 {"function f() {}\nf();", | |
1711 4 * kPointerSize, | |
1712 1, | |
1713 43, | |
1714 { | |
1715 B(Ldar), R(Register::function_closure().index()), // | |
1716 B(Star), R(2), // | |
1717 B(LdaConstant), U8(0), // | |
1718 B(Star), R(3), // | |
1719 B(CallRuntime), U16(Runtime::kNewScriptContext), R(2), U8(2), // | |
1720 B(PushContext), R(1), // | |
1721 B(LdaConstant), U8(1), // | |
1722 B(Star), R(2), // | |
1723 B(LdaZero), // | |
1724 B(Star), R(3), // | |
1725 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(2), U8(2), // | |
1726 B(LdaUndefined), // | |
1727 B(Star), R(3), // | |
1728 B(LdaGlobal), _, // | |
1729 B(Star), R(2), // | |
1730 B(Call), R(2), R(3), U8(0), // | |
1731 B(Star), R(0), // | |
1732 B(Ldar), R(0), // | |
1733 B(Return) // | |
1734 }, | |
1735 2, | |
1736 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE}}, | |
1737 }; | |
1738 | |
1739 for (size_t i = 0; i < arraysize(snippets); i++) { | |
1740 Handle<BytecodeArray> bytecode_array = | |
1741 helper.MakeTopLevelBytecode(snippets[i].code_snippet); | |
1742 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); | |
1743 } | |
1744 } | |
1745 | |
1746 | |
1747 TEST(BasicLoops) { | 1685 TEST(BasicLoops) { |
1748 InitializedHandleScope handle_scope; | 1686 InitializedHandleScope handle_scope; |
1749 BytecodeGeneratorHelper helper; | 1687 BytecodeGeneratorHelper helper; |
1750 | 1688 |
1751 ExpectedSnippet<int> snippets[] = { | 1689 ExpectedSnippet<int> snippets[] = { |
1752 {"var x = 0;" | 1690 {"var x = 0;" |
1753 "var y = 1;" | 1691 "var y = 1;" |
1754 "while (x < 10) {" | 1692 "while (x < 10) {" |
1755 " y = y * 12;" | 1693 " y = y * 12;" |
1756 " x = x + 1;" | 1694 " x = x + 1;" |
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2672 }; | 2610 }; |
2673 | 2611 |
2674 for (size_t i = 0; i < arraysize(snippets); i++) { | 2612 for (size_t i = 0; i < arraysize(snippets); i++) { |
2675 Handle<BytecodeArray> bytecode_array = | 2613 Handle<BytecodeArray> bytecode_array = |
2676 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 2614 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
2677 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 2615 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
2678 } | 2616 } |
2679 } | 2617 } |
2680 | 2618 |
2681 | 2619 |
2682 // Tests !FLAG_global_var_shortcuts mode. | |
2683 TEST(TopLevelObjectLiterals) { | 2620 TEST(TopLevelObjectLiterals) { |
2684 InitializedHandleScope handle_scope; | 2621 InitializedHandleScope handle_scope; |
2685 BytecodeGeneratorHelper helper; | 2622 BytecodeGeneratorHelper helper; |
2686 | 2623 |
2687 if (FLAG_global_var_shortcuts) return; | |
2688 | |
2689 int has_function_flags = ObjectLiteral::kFastElements | | 2624 int has_function_flags = ObjectLiteral::kFastElements | |
2690 ObjectLiteral::kHasFunction | | 2625 ObjectLiteral::kHasFunction | |
2691 ObjectLiteral::kDisableMementos; | 2626 ObjectLiteral::kDisableMementos; |
2692 ExpectedSnippet<InstanceType> snippets[] = { | 2627 ExpectedSnippet<InstanceType> snippets[] = { |
2693 {"var a = { func: function() { } };", | 2628 {"var a = { func: function() { } };", |
2694 6 * kPointerSize, | 2629 6 * kPointerSize, |
2695 1, | 2630 1, |
2696 54, | 2631 54, |
2697 { | 2632 { |
2698 B(LdaConstant), U8(0), // | 2633 B(LdaConstant), U8(0), // |
(...skipping 29 matching lines...) Expand all Loading... |
2728 }; | 2663 }; |
2729 | 2664 |
2730 for (size_t i = 0; i < arraysize(snippets); i++) { | 2665 for (size_t i = 0; i < arraysize(snippets); i++) { |
2731 Handle<BytecodeArray> bytecode_array = | 2666 Handle<BytecodeArray> bytecode_array = |
2732 helper.MakeTopLevelBytecode(snippets[i].code_snippet); | 2667 helper.MakeTopLevelBytecode(snippets[i].code_snippet); |
2733 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 2668 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
2734 } | 2669 } |
2735 } | 2670 } |
2736 | 2671 |
2737 | 2672 |
2738 // Tests FLAG_global_var_shortcuts mode. | |
2739 // TODO(ishell): remove when FLAG_global_var_shortcuts is removed. | |
2740 TEST(TopLevelObjectLiterals2) { | |
2741 InitializedHandleScope handle_scope; | |
2742 BytecodeGeneratorHelper helper; | |
2743 | |
2744 if (!FLAG_global_var_shortcuts) return; | |
2745 | |
2746 int has_function_flags = ObjectLiteral::kFastElements | | |
2747 ObjectLiteral::kHasFunction | | |
2748 ObjectLiteral::kDisableMementos; | |
2749 ExpectedSnippet<InstanceType> snippets[] = { | |
2750 {"var a = { func: function() { } };", | |
2751 7 * kPointerSize, | |
2752 1, | |
2753 69, | |
2754 { | |
2755 B(Ldar), R(Register::function_closure().index()), // | |
2756 B(Star), R(2), // | |
2757 B(LdaConstant), U8(0), // | |
2758 B(Star), R(3), // | |
2759 B(CallRuntime), U16(Runtime::kNewScriptContext), R(2), U8(2), // | |
2760 B(PushContext), R(1), // | |
2761 B(LdaConstant), U8(1), // | |
2762 B(Star), R(2), // | |
2763 B(LdaZero), // | |
2764 B(Star), R(3), // | |
2765 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(2), U8(2), // | |
2766 B(LdaConstant), U8(2), // | |
2767 B(Star), R(2), // | |
2768 B(LdaZero), // | |
2769 B(Star), R(3), // | |
2770 B(LdaConstant), U8(3), // | |
2771 B(CreateObjectLiteral), U8(0), U8(has_function_flags), // | |
2772 B(Star), R(5), // | |
2773 B(LdaConstant), U8(4), // | |
2774 B(Star), R(6), // | |
2775 B(LdaConstant), U8(5), // | |
2776 B(CreateClosure), U8(1), // | |
2777 B(StoreICSloppy), R(5), R(6), U8(3), // | |
2778 B(CallRuntime), U16(Runtime::kToFastProperties), R(5), U8(1), // | |
2779 B(Ldar), R(5), // | |
2780 B(Star), R(4), // | |
2781 B(CallRuntime), U16(Runtime::kInitializeVarGlobal), R(2), U8(3), // | |
2782 B(LdaUndefined), // | |
2783 B(Return), | |
2784 }, | |
2785 6, | |
2786 {InstanceType::FIXED_ARRAY_TYPE, | |
2787 InstanceType::FIXED_ARRAY_TYPE, | |
2788 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | |
2789 InstanceType::FIXED_ARRAY_TYPE, | |
2790 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, | |
2791 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | |
2792 }; | |
2793 | |
2794 for (size_t i = 0; i < arraysize(snippets); i++) { | |
2795 Handle<BytecodeArray> bytecode_array = | |
2796 helper.MakeTopLevelBytecode(snippets[i].code_snippet); | |
2797 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | |
2798 } | |
2799 } | |
2800 | |
2801 | |
2802 TEST(TryCatch) { | 2673 TEST(TryCatch) { |
2803 InitializedHandleScope handle_scope; | 2674 InitializedHandleScope handle_scope; |
2804 BytecodeGeneratorHelper helper; | 2675 BytecodeGeneratorHelper helper; |
2805 | 2676 |
2806 // TODO(rmcilroy): modify tests when we have real try catch support. | 2677 // TODO(rmcilroy): modify tests when we have real try catch support. |
2807 ExpectedSnippet<int> snippets[] = { | 2678 ExpectedSnippet<int> snippets[] = { |
2808 {"try { return 1; } catch(e) { return 2; }", | 2679 {"try { return 1; } catch(e) { return 2; }", |
2809 kPointerSize, | 2680 kPointerSize, |
2810 1, | 2681 1, |
2811 5, | 2682 5, |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2915 }; | 2786 }; |
2916 | 2787 |
2917 for (size_t i = 0; i < arraysize(snippets); i++) { | 2788 for (size_t i = 0; i < arraysize(snippets); i++) { |
2918 Handle<BytecodeArray> bytecode_array = | 2789 Handle<BytecodeArray> bytecode_array = |
2919 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 2790 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
2920 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 2791 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
2921 } | 2792 } |
2922 } | 2793 } |
2923 | 2794 |
2924 | 2795 |
2925 // Tests !FLAG_global_var_shortcuts mode. | |
2926 TEST(CallNew) { | 2796 TEST(CallNew) { |
2927 InitializedHandleScope handle_scope; | 2797 InitializedHandleScope handle_scope; |
2928 BytecodeGeneratorHelper helper; | 2798 BytecodeGeneratorHelper helper; |
2929 Zone zone; | 2799 Zone zone; |
2930 | 2800 |
2931 if (FLAG_global_var_shortcuts) return; | |
2932 | |
2933 int context_reg = Register::function_context().index(); | 2801 int context_reg = Register::function_context().index(); |
2934 int global_index = Context::GLOBAL_OBJECT_INDEX; | 2802 int global_index = Context::GLOBAL_OBJECT_INDEX; |
2935 | 2803 |
2936 FeedbackVectorSpec feedback_spec(&zone); | 2804 FeedbackVectorSpec feedback_spec(&zone); |
2937 FeedbackVectorSlot slot1 = feedback_spec.AddGeneralSlot(); | 2805 FeedbackVectorSlot slot1 = feedback_spec.AddGeneralSlot(); |
2938 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot(); | 2806 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot(); |
2939 USE(slot1); | 2807 USE(slot1); |
2940 | 2808 |
2941 Handle<i::TypeFeedbackVector> vector = | 2809 Handle<i::TypeFeedbackVector> vector = |
2942 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 2810 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3009 }; | 2877 }; |
3010 | 2878 |
3011 for (size_t i = 0; i < arraysize(snippets); i++) { | 2879 for (size_t i = 0; i < arraysize(snippets); i++) { |
3012 Handle<BytecodeArray> bytecode_array = | 2880 Handle<BytecodeArray> bytecode_array = |
3013 helper.MakeBytecode(snippets[i].code_snippet, "f"); | 2881 helper.MakeBytecode(snippets[i].code_snippet, "f"); |
3014 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); | 2882 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); |
3015 } | 2883 } |
3016 } | 2884 } |
3017 | 2885 |
3018 | 2886 |
3019 // Tests FLAG_global_var_shortcuts mode. | |
3020 // TODO(ishell): remove when FLAG_global_var_shortcuts is removed. | |
3021 TEST(CallNew2) { | |
3022 InitializedHandleScope handle_scope; | |
3023 BytecodeGeneratorHelper helper; | |
3024 | |
3025 if (!FLAG_global_var_shortcuts) return; | |
3026 | |
3027 ExpectedSnippet<InstanceType> snippets[] = { | |
3028 {"function bar() { this.value = 0; }\n" | |
3029 "function f() { return new bar(); }\n" | |
3030 "f()", | |
3031 kPointerSize, | |
3032 1, | |
3033 9, | |
3034 { | |
3035 B(LdaGlobal), _, // | |
3036 B(Star), R(0), // | |
3037 B(New), R(0), R(0), U8(0), // | |
3038 B(Return), // | |
3039 }, | |
3040 0}, | |
3041 {"function bar(x) { this.value = 18; this.x = x;}\n" | |
3042 "function f() { return new bar(3); }\n" | |
3043 "f()", | |
3044 2 * kPointerSize, | |
3045 1, | |
3046 13, | |
3047 { | |
3048 B(LdaGlobal), _, // | |
3049 B(Star), R(0), // | |
3050 B(LdaSmi8), U8(3), // | |
3051 B(Star), R(1), // | |
3052 B(New), R(0), R(1), U8(1), // | |
3053 B(Return), // | |
3054 }, | |
3055 0}, | |
3056 {"function bar(w, x, y, z) {\n" | |
3057 " this.value = 18;\n" | |
3058 " this.x = x;\n" | |
3059 " this.y = y;\n" | |
3060 " this.z = z;\n" | |
3061 "}\n" | |
3062 "function f() { return new bar(3, 4, 5); }\n" | |
3063 "f()", | |
3064 4 * kPointerSize, | |
3065 1, | |
3066 21, | |
3067 { | |
3068 B(LdaGlobal), _, // | |
3069 B(Star), R(0), // | |
3070 B(LdaSmi8), U8(3), // | |
3071 B(Star), R(1), // | |
3072 B(LdaSmi8), U8(4), // | |
3073 B(Star), R(2), // | |
3074 B(LdaSmi8), U8(5), // | |
3075 B(Star), R(3), // | |
3076 B(New), R(0), R(1), U8(3), // | |
3077 B(Return), // | |
3078 }, | |
3079 0}}; | |
3080 | |
3081 for (size_t i = 0; i < arraysize(snippets); i++) { | |
3082 Handle<BytecodeArray> bytecode_array = | |
3083 helper.MakeBytecode(snippets[i].code_snippet, "f"); | |
3084 CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); | |
3085 } | |
3086 } | |
3087 | |
3088 | |
3089 TEST(ContextVariables) { | 2887 TEST(ContextVariables) { |
3090 InitializedHandleScope handle_scope; | 2888 InitializedHandleScope handle_scope; |
3091 BytecodeGeneratorHelper helper; | 2889 BytecodeGeneratorHelper helper; |
3092 | 2890 |
3093 int closure = Register::function_closure().index(); | 2891 int closure = Register::function_closure().index(); |
3094 int first_context_slot = Context::MIN_CONTEXT_SLOTS; | 2892 int first_context_slot = Context::MIN_CONTEXT_SLOTS; |
3095 ExpectedSnippet<InstanceType> snippets[] = { | 2893 ExpectedSnippet<InstanceType> snippets[] = { |
3096 {"var a; return function() { a = 1; };", | 2894 {"var a; return function() { a = 1; };", |
3097 1 * kPointerSize, | 2895 1 * kPointerSize, |
3098 1, | 2896 1, |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3284 for (size_t i = 0; i < arraysize(snippets); i++) { | 3082 for (size_t i = 0; i < arraysize(snippets); i++) { |
3285 Handle<BytecodeArray> bytecode_array = | 3083 Handle<BytecodeArray> bytecode_array = |
3286 helper.MakeBytecodeForFunction(snippets[i].code_snippet); | 3084 helper.MakeBytecodeForFunction(snippets[i].code_snippet); |
3287 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 3085 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
3288 } | 3086 } |
3289 } | 3087 } |
3290 | 3088 |
3291 } // namespace interpreter | 3089 } // namespace interpreter |
3292 } // namespace internal | 3090 } // namespace internal |
3293 } // namespace v8 | 3091 } // namespace v8 |
OLD | NEW |