OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 if (function == NULL || !function->is_compiled()) return; | 542 if (function == NULL || !function->is_compiled()) return; |
543 | 543 |
544 constant_function_ = function; | 544 constant_function_ = function; |
545 AnalyzePossibleApiFunction(function); | 545 AnalyzePossibleApiFunction(function); |
546 } | 546 } |
547 | 547 |
548 // Determines whether the given function can be called using the | 548 // Determines whether the given function can be called using the |
549 // fast api call builtin. | 549 // fast api call builtin. |
550 void AnalyzePossibleApiFunction(JSFunction* function) { | 550 void AnalyzePossibleApiFunction(JSFunction* function) { |
551 SharedFunctionInfo* sfi = function->shared(); | 551 SharedFunctionInfo* sfi = function->shared(); |
552 if (sfi->function_data()->IsUndefined()) return; | 552 if (!sfi->IsApiFunction()) return; |
553 FunctionTemplateInfo* info = | 553 FunctionTemplateInfo* info = sfi->get_api_func_data(); |
554 FunctionTemplateInfo::cast(sfi->function_data()); | |
555 | 554 |
556 // Require a C++ callback. | 555 // Require a C++ callback. |
557 if (info->call_code()->IsUndefined()) return; | 556 if (info->call_code()->IsUndefined()) return; |
558 api_call_info_ = CallHandlerInfo::cast(info->call_code()); | 557 api_call_info_ = CallHandlerInfo::cast(info->call_code()); |
559 | 558 |
560 // Accept signatures that either have no restrictions at all or | 559 // Accept signatures that either have no restrictions at all or |
561 // only have restrictions on the receiver. | 560 // only have restrictions on the receiver. |
562 if (!info->signature()->IsUndefined()) { | 561 if (!info->signature()->IsUndefined()) { |
563 SignatureInfo* signature = SignatureInfo::cast(info->signature()); | 562 SignatureInfo* signature = SignatureInfo::cast(info->signature()); |
564 if (!signature->args()->IsUndefined()) return; | 563 if (!signature->args()->IsUndefined()) return; |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1203 // Handle call cache miss. | 1202 // Handle call cache miss. |
1204 __ bind(&miss); | 1203 __ bind(&miss); |
1205 Handle<Code> ic = ComputeCallMiss(arguments().immediate()); | 1204 Handle<Code> ic = ComputeCallMiss(arguments().immediate()); |
1206 __ jmp(ic, RelocInfo::CODE_TARGET); | 1205 __ jmp(ic, RelocInfo::CODE_TARGET); |
1207 | 1206 |
1208 // Return the generated code. | 1207 // Return the generated code. |
1209 return GetCode(FIELD, name); | 1208 return GetCode(FIELD, name); |
1210 } | 1209 } |
1211 | 1210 |
1212 | 1211 |
| 1212 Object* CallStubCompiler::CompileArrayPushCall(Object* object, |
| 1213 JSObject* holder, |
| 1214 JSFunction* function, |
| 1215 String* name, |
| 1216 CheckType check) { |
| 1217 // ----------- S t a t e ------------- |
| 1218 // -- ecx : name |
| 1219 // -- esp[0] : return address |
| 1220 // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
| 1221 // -- ... |
| 1222 // -- esp[(argc + 1) * 4] : receiver |
| 1223 // ----------------------------------- |
| 1224 Label miss; |
| 1225 |
| 1226 // Get the receiver from the stack. |
| 1227 const int argc = arguments().immediate(); |
| 1228 __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 1229 |
| 1230 // Check that the receiver isn't a smi. |
| 1231 __ test(edx, Immediate(kSmiTagMask)); |
| 1232 __ j(zero, &miss, not_taken); |
| 1233 |
| 1234 CheckPrototypes(JSObject::cast(object), edx, |
| 1235 holder, ebx, |
| 1236 eax, name, &miss); |
| 1237 |
| 1238 if (argc == 0) { |
| 1239 // Noop, return the length. |
| 1240 __ mov(eax, FieldOperand(edx, JSArray::kLengthOffset)); |
| 1241 __ ret((argc + 1) * kPointerSize); |
| 1242 } else { |
| 1243 // Get the elements array of the object. |
| 1244 __ mov(ebx, FieldOperand(edx, JSArray::kElementsOffset)); |
| 1245 |
| 1246 // Check that the elements are in fast mode (not dictionary). |
| 1247 __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
| 1248 Immediate(Factory::fixed_array_map())); |
| 1249 __ j(not_equal, &miss, not_taken); |
| 1250 |
| 1251 if (argc == 1) { // Otherwise fall through to call builtin. |
| 1252 Label call_builtin, exit, with_rset_update; |
| 1253 |
| 1254 // Get the array's length into eax and calculate new length. |
| 1255 __ mov(eax, FieldOperand(edx, JSArray::kLengthOffset)); |
| 1256 __ add(Operand(eax), Immediate(argc << 1)); |
| 1257 |
| 1258 // Get the element's length into ecx. |
| 1259 __ mov(ecx, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 1260 __ SmiTag(ecx); |
| 1261 |
| 1262 // Check if we could survive without allocation, go to builtin otherwise. |
| 1263 __ cmp(eax, Operand(ecx)); |
| 1264 __ j(greater, &call_builtin); |
| 1265 |
| 1266 // Save new length. |
| 1267 __ mov(FieldOperand(edx, JSArray::kLengthOffset), eax); |
| 1268 |
| 1269 // Push the element. |
| 1270 __ lea(edx, FieldOperand(ebx, |
| 1271 eax, times_half_pointer_size, |
| 1272 FixedArray::kHeaderSize - argc * kPointerSize)); |
| 1273 __ mov(ecx, Operand(esp, argc * kPointerSize)); |
| 1274 __ mov(Operand(edx, 0), ecx); |
| 1275 |
| 1276 // Check if wrote not a smi. |
| 1277 __ test(ecx, Immediate(kSmiTagMask)); |
| 1278 __ j(not_zero, &with_rset_update); |
| 1279 |
| 1280 __ bind(&exit); |
| 1281 __ ret((argc + 1) * kPointerSize); |
| 1282 |
| 1283 __ bind(&with_rset_update); |
| 1284 |
| 1285 __ InNewSpace(ebx, ecx, equal, &exit); |
| 1286 |
| 1287 RecordWriteStub stub(ebx, edx, ecx); |
| 1288 __ CallStub(&stub); |
| 1289 __ ret((argc + 1) * kPointerSize); |
| 1290 |
| 1291 __ bind(&call_builtin); |
| 1292 } |
| 1293 |
| 1294 __ TailCallExternalReference(ExternalReference(Builtins::c_ArrayPush), |
| 1295 argc + 1, |
| 1296 1); |
| 1297 } |
| 1298 |
| 1299 __ bind(&miss); |
| 1300 |
| 1301 Handle<Code> ic = ComputeCallMiss(arguments().immediate()); |
| 1302 __ jmp(ic, RelocInfo::CODE_TARGET); |
| 1303 |
| 1304 // Return the generated code. |
| 1305 String* function_name = NULL; |
| 1306 if (function->shared()->name()->IsString()) { |
| 1307 function_name = String::cast(function->shared()->name()); |
| 1308 } |
| 1309 return GetCode(CONSTANT_FUNCTION, function_name); |
| 1310 } |
| 1311 |
| 1312 |
1213 Object* CallStubCompiler::CompileCallConstant(Object* object, | 1313 Object* CallStubCompiler::CompileCallConstant(Object* object, |
1214 JSObject* holder, | 1314 JSObject* holder, |
1215 JSFunction* function, | 1315 JSFunction* function, |
1216 String* name, | 1316 String* name, |
1217 CheckType check) { | 1317 CheckType check) { |
1218 // ----------- S t a t e ------------- | 1318 // ----------- S t a t e ------------- |
1219 // -- ecx : name | 1319 // -- ecx : name |
1220 // -- esp[0] : return address | 1320 // -- esp[0] : return address |
1221 // -- esp[(argc - n) * 4] : arg[n] (zero-based) | 1321 // -- esp[(argc - n) * 4] : arg[n] (zero-based) |
1222 // -- ... | 1322 // -- ... |
1223 // -- esp[(argc + 1) * 4] : receiver | 1323 // -- esp[(argc + 1) * 4] : receiver |
1224 // ----------------------------------- | 1324 // ----------------------------------- |
| 1325 |
| 1326 SharedFunctionInfo* function_info = function->shared(); |
| 1327 if (function_info->HasCustomCallGenerator()) { |
| 1328 CustomCallGenerator generator = |
| 1329 ToCData<CustomCallGenerator>(function_info->function_data()); |
| 1330 return generator(this, object, holder, function, name, check); |
| 1331 } |
| 1332 |
1225 Label miss_in_smi_check; | 1333 Label miss_in_smi_check; |
1226 | 1334 |
1227 // Get the receiver from the stack. | 1335 // Get the receiver from the stack. |
1228 const int argc = arguments().immediate(); | 1336 const int argc = arguments().immediate(); |
1229 __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); | 1337 __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
1230 | 1338 |
1231 // Check that the receiver isn't a smi. | 1339 // Check that the receiver isn't a smi. |
1232 if (check != NUMBER_CHECK) { | 1340 if (check != NUMBER_CHECK) { |
1233 __ test(edx, Immediate(kSmiTagMask)); | 1341 __ test(edx, Immediate(kSmiTagMask)); |
1234 __ j(zero, &miss_in_smi_check, not_taken); | 1342 __ j(zero, &miss_in_smi_check, not_taken); |
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2186 __ jmp(generic_construct_stub, RelocInfo::CODE_TARGET); | 2294 __ jmp(generic_construct_stub, RelocInfo::CODE_TARGET); |
2187 | 2295 |
2188 // Return the generated code. | 2296 // Return the generated code. |
2189 return GetCode(); | 2297 return GetCode(); |
2190 } | 2298 } |
2191 | 2299 |
2192 | 2300 |
2193 #undef __ | 2301 #undef __ |
2194 | 2302 |
2195 } } // namespace v8::internal | 2303 } } // namespace v8::internal |
OLD | NEW |