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

Side by Side Diff: src/ia32/ic-ia32.cc

Issue 2280007: Extend CallIC to support non-constant names.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « src/ia32/full-codegen-ia32.cc ('k') | src/ia32/stub-cache-ia32.cc » ('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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 1039
1040 // Slow case: call runtime. 1040 // Slow case: call runtime.
1041 __ bind(&slow); 1041 __ bind(&slow);
1042 GenerateRuntimeSetProperty(masm); 1042 GenerateRuntimeSetProperty(masm);
1043 } 1043 }
1044 1044
1045 1045
1046 // Defined in ic.cc. 1046 // Defined in ic.cc.
1047 Object* CallIC_Miss(Arguments args); 1047 Object* CallIC_Miss(Arguments args);
1048 1048
1049 void CallIC::GenerateMegamorphic(MacroAssembler* masm, int argc) { 1049 // The generated code does not accept smi keys.
1050 // The generated code falls through if both probes miss.
1051 static void GenerateMonomorphicCacheProbe(MacroAssembler* masm,
1052 int argc,
1053 Code::Kind kind,
1054 Label* miss) {
1050 // ----------- S t a t e ------------- 1055 // ----------- S t a t e -------------
1051 // -- ecx : name 1056 // -- ecx : name
1052 // -- esp[0] : return address 1057 // -- edx : receiver
1053 // -- esp[(argc - n) * 4] : arg[n] (zero-based)
1054 // -- ...
1055 // -- esp[(argc + 1) * 4] : receiver
1056 // ----------------------------------- 1058 // -----------------------------------
1057 Label number, non_number, non_string, boolean, probe, miss; 1059 Label number, non_number, non_string, boolean, probe;
1058
1059 // Get the receiver of the function from the stack; 1 ~ return address.
1060 __ mov(edx, Operand(esp, (argc + 1) * kPointerSize));
1061 1060
1062 // Probe the stub cache. 1061 // Probe the stub cache.
1063 Code::Flags flags = 1062 Code::Flags flags =
1064 Code::ComputeFlags(Code::CALL_IC, NOT_IN_LOOP, MONOMORPHIC, NORMAL, argc); 1063 Code::ComputeFlags(kind, NOT_IN_LOOP, MONOMORPHIC, NORMAL, argc);
1065 StubCache::GenerateProbe(masm, flags, edx, ecx, ebx, eax); 1064 StubCache::GenerateProbe(masm, flags, edx, ecx, ebx, eax);
1066 1065
1067 // If the stub cache probing failed, the receiver might be a value. 1066 // If the stub cache probing failed, the receiver might be a value.
1068 // For value objects, we use the map of the prototype objects for 1067 // For value objects, we use the map of the prototype objects for
1069 // the corresponding JSValue for the cache and that is what we need 1068 // the corresponding JSValue for the cache and that is what we need
1070 // to probe. 1069 // to probe.
1071 // 1070 //
1072 // Check for number. 1071 // Check for number.
1073 __ test(edx, Immediate(kSmiTagMask)); 1072 __ test(edx, Immediate(kSmiTagMask));
1074 __ j(zero, &number, not_taken); 1073 __ j(zero, &number, not_taken);
1075 __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ebx); 1074 __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ebx);
1076 __ j(not_equal, &non_number, taken); 1075 __ j(not_equal, &non_number, taken);
1077 __ bind(&number); 1076 __ bind(&number);
1078 StubCompiler::GenerateLoadGlobalFunctionPrototype( 1077 StubCompiler::GenerateLoadGlobalFunctionPrototype(
1079 masm, Context::NUMBER_FUNCTION_INDEX, edx); 1078 masm, Context::NUMBER_FUNCTION_INDEX, edx);
1080 __ jmp(&probe); 1079 __ jmp(&probe);
1081 1080
1082 // Check for string. 1081 // Check for string.
1083 __ bind(&non_number); 1082 __ bind(&non_number);
1084 __ cmp(ebx, FIRST_NONSTRING_TYPE); 1083 __ CmpInstanceType(ebx, FIRST_NONSTRING_TYPE);
1085 __ j(above_equal, &non_string, taken); 1084 __ j(above_equal, &non_string, taken);
1086 StubCompiler::GenerateLoadGlobalFunctionPrototype( 1085 StubCompiler::GenerateLoadGlobalFunctionPrototype(
1087 masm, Context::STRING_FUNCTION_INDEX, edx); 1086 masm, Context::STRING_FUNCTION_INDEX, edx);
1088 __ jmp(&probe); 1087 __ jmp(&probe);
1089 1088
1090 // Check for boolean. 1089 // Check for boolean.
1091 __ bind(&non_string); 1090 __ bind(&non_string);
1092 __ cmp(edx, Factory::true_value()); 1091 __ cmp(edx, Factory::true_value());
1093 __ j(equal, &boolean, not_taken); 1092 __ j(equal, &boolean, not_taken);
1094 __ cmp(edx, Factory::false_value()); 1093 __ cmp(edx, Factory::false_value());
1095 __ j(not_equal, &miss, taken); 1094 __ j(not_equal, miss, taken);
1096 __ bind(&boolean); 1095 __ bind(&boolean);
1097 StubCompiler::GenerateLoadGlobalFunctionPrototype( 1096 StubCompiler::GenerateLoadGlobalFunctionPrototype(
1098 masm, Context::BOOLEAN_FUNCTION_INDEX, edx); 1097 masm, Context::BOOLEAN_FUNCTION_INDEX, edx);
1099 1098
1100 // Probe the stub cache for the value object. 1099 // Probe the stub cache for the value object.
1101 __ bind(&probe); 1100 __ bind(&probe);
1102 StubCache::GenerateProbe(masm, flags, edx, ecx, ebx, no_reg); 1101 StubCache::GenerateProbe(masm, flags, edx, ecx, ebx, no_reg);
1103
1104 // Cache miss: Jump to runtime.
1105 __ bind(&miss);
1106 GenerateMiss(masm, argc);
1107 } 1102 }
1108 1103
1109 1104
1110 static void GenerateNormalHelper(MacroAssembler* masm, 1105 static void GenerateNormalHelper(MacroAssembler* masm,
1111 int argc, 1106 int argc,
1112 bool is_global_object, 1107 bool is_global_object,
1113 Label* miss) { 1108 Label* miss) {
1114 // ----------- S t a t e ------------- 1109 // ----------- S t a t e -------------
1115 // -- ecx : name 1110 // -- ecx : name
1116 // -- edx : receiver 1111 // -- edx : receiver
(...skipping 19 matching lines...) Expand all
1136 if (is_global_object) { 1131 if (is_global_object) {
1137 __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalReceiverOffset)); 1132 __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalReceiverOffset));
1138 __ mov(Operand(esp, (argc + 1) * kPointerSize), edx); 1133 __ mov(Operand(esp, (argc + 1) * kPointerSize), edx);
1139 } 1134 }
1140 1135
1141 // Invoke the function. 1136 // Invoke the function.
1142 ParameterCount actual(argc); 1137 ParameterCount actual(argc);
1143 __ InvokeFunction(edi, actual, JUMP_FUNCTION); 1138 __ InvokeFunction(edi, actual, JUMP_FUNCTION);
1144 } 1139 }
1145 1140
1146 1141 // The generated code never falls through.
1147 void CallIC::GenerateNormal(MacroAssembler* masm, int argc) { 1142 static void GenerateCallNormal(MacroAssembler* masm, int argc, Label* miss) {
1148 // ----------- S t a t e ------------- 1143 // ----------- S t a t e -------------
1149 // -- ecx : name 1144 // -- ecx : name
1150 // -- esp[0] : return address 1145 // -- esp[0] : return address
1151 // -- esp[(argc - n) * 4] : arg[n] (zero-based) 1146 // -- esp[(argc - n) * 4] : arg[n] (zero-based)
1152 // -- ... 1147 // -- ...
1153 // -- esp[(argc + 1) * 4] : receiver 1148 // -- esp[(argc + 1) * 4] : receiver
1154 // ----------------------------------- 1149 // -----------------------------------
1155 Label miss, global_object, non_global_object; 1150 Label global_object, non_global_object;
1156 1151
1157 // Get the receiver of the function from the stack; 1 ~ return address. 1152 // Get the receiver of the function from the stack; 1 ~ return address.
1158 __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); 1153 __ mov(edx, Operand(esp, (argc + 1) * kPointerSize));
1159 1154
1160 // Check that the receiver isn't a smi. 1155 // Check that the receiver isn't a smi.
1161 __ test(edx, Immediate(kSmiTagMask)); 1156 __ test(edx, Immediate(kSmiTagMask));
1162 __ j(zero, &miss, not_taken); 1157 __ j(zero, miss, not_taken);
1163 1158
1164 // Check that the receiver is a valid JS object. 1159 // Check that the receiver is a valid JS object.
1165 __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); 1160 __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset));
1166 __ movzx_b(eax, FieldOperand(ebx, Map::kInstanceTypeOffset)); 1161 __ movzx_b(eax, FieldOperand(ebx, Map::kInstanceTypeOffset));
1167 __ cmp(eax, FIRST_JS_OBJECT_TYPE); 1162 __ cmp(eax, FIRST_JS_OBJECT_TYPE);
1168 __ j(below, &miss, not_taken); 1163 __ j(below, miss, not_taken);
1169 1164
1170 // If this assert fails, we have to check upper bound too. 1165 // If this assert fails, we have to check upper bound too.
1171 ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); 1166 ASSERT(LAST_TYPE == JS_FUNCTION_TYPE);
1172 1167
1173 // Check for access to global object. 1168 // Check for access to global object.
1174 __ cmp(eax, JS_GLOBAL_OBJECT_TYPE); 1169 __ cmp(eax, JS_GLOBAL_OBJECT_TYPE);
1175 __ j(equal, &global_object); 1170 __ j(equal, &global_object);
1176 __ cmp(eax, JS_BUILTINS_OBJECT_TYPE); 1171 __ cmp(eax, JS_BUILTINS_OBJECT_TYPE);
1177 __ j(not_equal, &non_global_object); 1172 __ j(not_equal, &non_global_object);
1178 1173
1179 // Accessing global object: Load and invoke. 1174 // Accessing global object: Load and invoke.
1180 __ bind(&global_object); 1175 __ bind(&global_object);
1181 // Check that the global object does not require access checks. 1176 // Check that the global object does not require access checks.
1182 __ movzx_b(ebx, FieldOperand(ebx, Map::kBitFieldOffset)); 1177 __ movzx_b(ebx, FieldOperand(ebx, Map::kBitFieldOffset));
1183 __ test(ebx, Immediate(1 << Map::kIsAccessCheckNeeded)); 1178 __ test(ebx, Immediate(1 << Map::kIsAccessCheckNeeded));
1184 __ j(not_equal, &miss, not_taken); 1179 __ j(not_equal, miss, not_taken);
1185 GenerateNormalHelper(masm, argc, true, &miss); 1180 GenerateNormalHelper(masm, argc, true, miss);
1186 1181
1187 // Accessing non-global object: Check for access to global proxy. 1182 // Accessing non-global object: Check for access to global proxy.
1188 Label global_proxy, invoke; 1183 Label global_proxy, invoke;
1189 __ bind(&non_global_object); 1184 __ bind(&non_global_object);
1190 __ cmp(eax, JS_GLOBAL_PROXY_TYPE); 1185 __ cmp(eax, JS_GLOBAL_PROXY_TYPE);
1191 __ j(equal, &global_proxy, not_taken); 1186 __ j(equal, &global_proxy, not_taken);
1192 // Check that the non-global, non-global-proxy object does not 1187 // Check that the non-global, non-global-proxy object does not
1193 // require access checks. 1188 // require access checks.
1194 __ movzx_b(ebx, FieldOperand(ebx, Map::kBitFieldOffset)); 1189 __ movzx_b(ebx, FieldOperand(ebx, Map::kBitFieldOffset));
1195 __ test(ebx, Immediate(1 << Map::kIsAccessCheckNeeded)); 1190 __ test(ebx, Immediate(1 << Map::kIsAccessCheckNeeded));
1196 __ j(not_equal, &miss, not_taken); 1191 __ j(not_equal, miss, not_taken);
1197 __ bind(&invoke); 1192 __ bind(&invoke);
1198 GenerateNormalHelper(masm, argc, false, &miss); 1193 GenerateNormalHelper(masm, argc, false, miss);
1199 1194
1200 // Global object proxy access: Check access rights. 1195 // Global object proxy access: Check access rights.
1201 __ bind(&global_proxy); 1196 __ bind(&global_proxy);
1202 __ CheckAccessGlobalProxy(edx, eax, &miss); 1197 __ CheckAccessGlobalProxy(edx, eax, miss);
1203 __ jmp(&invoke); 1198 __ jmp(&invoke);
1204
1205 // Cache miss: Jump to runtime.
1206 __ bind(&miss);
1207 GenerateMiss(masm, argc);
1208 } 1199 }
1209 1200
1210 1201
1211 void CallIC::GenerateMiss(MacroAssembler* masm, int argc) { 1202 static void GenerateCallMiss(MacroAssembler* masm, int argc, IC::UtilityId id) {
1212 // ----------- S t a t e ------------- 1203 // ----------- S t a t e -------------
1213 // -- ecx : name 1204 // -- ecx : name
1214 // -- esp[0] : return address 1205 // -- esp[0] : return address
1215 // -- esp[(argc - n) * 4] : arg[n] (zero-based) 1206 // -- esp[(argc - n) * 4] : arg[n] (zero-based)
1216 // -- ... 1207 // -- ...
1217 // -- esp[(argc + 1) * 4] : receiver 1208 // -- esp[(argc + 1) * 4] : receiver
1218 // ----------------------------------- 1209 // -----------------------------------
1219 1210
1220 // Get the receiver of the function from the stack; 1 ~ return address. 1211 // Get the receiver of the function from the stack; 1 ~ return address.
1221 __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); 1212 __ mov(edx, Operand(esp, (argc + 1) * kPointerSize));
1222 1213
1223 // Enter an internal frame. 1214 // Enter an internal frame.
1224 __ EnterInternalFrame(); 1215 __ EnterInternalFrame();
1225 1216
1226 // Push the receiver and the name of the function. 1217 // Push the receiver and the name of the function.
1227 __ push(edx); 1218 __ push(edx);
1228 __ push(ecx); 1219 __ push(ecx);
1229 1220
1230 // Call the entry. 1221 // Call the entry.
1231 CEntryStub stub(1); 1222 CEntryStub stub(1);
1232 __ mov(eax, Immediate(2)); 1223 __ mov(eax, Immediate(2));
1233 __ mov(ebx, Immediate(ExternalReference(IC_Utility(kCallIC_Miss)))); 1224 __ mov(ebx, Immediate(ExternalReference(IC_Utility(id))));
1234 __ CallStub(&stub); 1225 __ CallStub(&stub);
1235 1226
1236 // Move result to edi and exit the internal frame. 1227 // Move result to edi and exit the internal frame.
1237 __ mov(edi, eax); 1228 __ mov(edi, eax);
1238 __ LeaveInternalFrame(); 1229 __ LeaveInternalFrame();
1239 1230
1240 // Check if the receiver is a global object of some sort. 1231 // Check if the receiver is a global object of some sort.
1241 Label invoke, global; 1232 Label invoke, global;
1242 __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); // receiver 1233 __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); // receiver
1243 __ test(edx, Immediate(kSmiTagMask)); 1234 __ test(edx, Immediate(kSmiTagMask));
(...skipping 10 matching lines...) Expand all
1254 __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalReceiverOffset)); 1245 __ mov(edx, FieldOperand(edx, GlobalObject::kGlobalReceiverOffset));
1255 __ mov(Operand(esp, (argc + 1) * kPointerSize), edx); 1246 __ mov(Operand(esp, (argc + 1) * kPointerSize), edx);
1256 1247
1257 // Invoke the function. 1248 // Invoke the function.
1258 ParameterCount actual(argc); 1249 ParameterCount actual(argc);
1259 __ bind(&invoke); 1250 __ bind(&invoke);
1260 __ InvokeFunction(edi, actual, JUMP_FUNCTION); 1251 __ InvokeFunction(edi, actual, JUMP_FUNCTION);
1261 } 1252 }
1262 1253
1263 1254
1255 void CallIC::GenerateMegamorphic(MacroAssembler* masm, int argc) {
1256 // ----------- S t a t e -------------
1257 // -- ecx : name
1258 // -- esp[0] : return address
1259 // -- esp[(argc - n) * 4] : arg[n] (zero-based)
1260 // -- ...
1261 // -- esp[(argc + 1) * 4] : receiver
1262 // -----------------------------------
1263
1264 Label miss;
1265 // Get the receiver of the function from the stack; 1 ~ return address.
1266 __ mov(edx, Operand(esp, (argc + 1) * kPointerSize));
1267 GenerateMonomorphicCacheProbe(masm, argc, Code::CALL_IC, &miss);
1268 __ bind(&miss);
1269 GenerateMiss(masm, argc);
1270 }
1271
1272
1273 void CallIC::GenerateNormal(MacroAssembler* masm, int argc) {
1274 Label miss;
1275 GenerateCallNormal(masm, argc, &miss);
1276 __ bind(&miss);
1277 GenerateMiss(masm, argc);
1278 }
1279
1280
1281 void CallIC::GenerateMiss(MacroAssembler* masm, int argc) {
1282 GenerateCallMiss(masm, argc, IC::kCallIC_Miss);
1283 }
1284
1285
1286 void KeyedCallIC::GenerateMegamorphic(MacroAssembler* masm, int argc) {
1287 // ----------- S t a t e -------------
1288 // -- ecx : name
1289 // -- esp[0] : return address
1290 // -- esp[(argc - n) * 4] : arg[n] (zero-based)
1291 // -- ...
1292 // -- esp[(argc + 1) * 4] : receiver
1293 // -----------------------------------
1294
1295 // Get the receiver of the function from the stack; 1 ~ return address.
1296 __ mov(edx, Operand(esp, (argc + 1) * kPointerSize));
1297
1298 Label miss, skip_probe;
1299
1300 // Do not probe monomorphic cache if a key is a smi.
1301 __ test(ecx, Immediate(kSmiTagMask));
1302 __ j(equal, &skip_probe, taken);
1303
1304 GenerateMonomorphicCacheProbe(masm, argc, Code::KEYED_CALL_IC, &skip_probe);
1305
1306 __ bind(&skip_probe);
1307
1308 __ mov(eax, ecx);
1309 __ EnterInternalFrame();
1310 __ push(ecx);
1311 __ call(Handle<Code>(Builtins::builtin(Builtins::KeyedLoadIC_Generic)),
1312 RelocInfo::CODE_TARGET);
1313 __ pop(ecx);
1314 __ LeaveInternalFrame();
1315 __ mov(edi, eax);
1316
1317 __ mov(edx, Operand(esp, (argc + 1) * kPointerSize));
1318
1319 // Check that the receiver isn't a smi.
1320 __ test(edx, Immediate(kSmiTagMask));
1321 __ j(zero, &miss, not_taken);
1322
1323 // Check that the receiver is a valid JS object.
1324 __ CmpObjectType(edx, FIRST_JS_OBJECT_TYPE, eax);
1325 __ j(below, &miss, not_taken);
1326
1327 // Check that the value is a JavaScript function.
1328 __ test(edi, Immediate(kSmiTagMask));
1329 __ j(zero, &miss, not_taken);
1330 __ CmpObjectType(edi, JS_FUNCTION_TYPE, eax);
1331 __ j(not_equal, &miss, not_taken);
1332
1333 // Invoke the function.
1334 ParameterCount actual(argc);
1335 __ InvokeFunction(edi, actual, JUMP_FUNCTION);
1336
1337 __ bind(&miss);
1338 GenerateMiss(masm, argc);
1339 }
1340
1341
1342 void KeyedCallIC::GenerateNormal(MacroAssembler* masm, int argc) {
1343 Label miss;
1344 GenerateCallNormal(masm, argc, &miss);
1345 __ bind(&miss);
1346 GenerateMiss(masm, argc);
1347 }
1348
1349
1350 void KeyedCallIC::GenerateMiss(MacroAssembler* masm, int argc) {
1351 GenerateCallMiss(masm, argc, IC::kKeyedCallIC_Miss);
1352 }
1353
1354
1264 // Defined in ic.cc. 1355 // Defined in ic.cc.
1265 Object* LoadIC_Miss(Arguments args); 1356 Object* LoadIC_Miss(Arguments args);
1266 1357
1267 void LoadIC::GenerateMegamorphic(MacroAssembler* masm) { 1358 void LoadIC::GenerateMegamorphic(MacroAssembler* masm) {
1268 // ----------- S t a t e ------------- 1359 // ----------- S t a t e -------------
1269 // -- eax : receiver 1360 // -- eax : receiver
1270 // -- ecx : name 1361 // -- ecx : name
1271 // -- esp[0] : return address 1362 // -- esp[0] : return address
1272 // ----------------------------------- 1363 // -----------------------------------
1273 1364
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
1617 ExternalReference ref = ExternalReference(IC_Utility(kKeyedStoreIC_Miss)); 1708 ExternalReference ref = ExternalReference(IC_Utility(kKeyedStoreIC_Miss));
1618 __ TailCallExternalReference(ref, 3, 1); 1709 __ TailCallExternalReference(ref, 3, 1);
1619 } 1710 }
1620 1711
1621 #undef __ 1712 #undef __
1622 1713
1623 1714
1624 } } // namespace v8::internal 1715 } } // namespace v8::internal
1625 1716
1626 #endif // V8_TARGET_ARCH_IA32 1717 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/ia32/full-codegen-ia32.cc ('k') | src/ia32/stub-cache-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698