| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #if V8_TARGET_ARCH_ARM | 5 #if V8_TARGET_ARCH_ARM |
| 6 | 6 |
| 7 #include "src/code-stubs.h" | 7 #include "src/code-stubs.h" |
| 8 #include "src/api-arguments.h" | 8 #include "src/api-arguments.h" |
| 9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 1301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1312 } | 1312 } |
| 1313 #endif | 1313 #endif |
| 1314 | 1314 |
| 1315 // Restore callee-saved vfp registers. | 1315 // Restore callee-saved vfp registers. |
| 1316 __ vldm(ia_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg); | 1316 __ vldm(ia_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg); |
| 1317 | 1317 |
| 1318 __ ldm(ia_w, sp, kCalleeSaved | pc.bit()); | 1318 __ ldm(ia_w, sp, kCalleeSaved | pc.bit()); |
| 1319 } | 1319 } |
| 1320 | 1320 |
| 1321 | 1321 |
| 1322 void InstanceOfStub::Generate(MacroAssembler* masm) { | |
| 1323 Register const object = r1; // Object (lhs). | |
| 1324 Register const function = r0; // Function (rhs). | |
| 1325 Register const object_map = r2; // Map of {object}. | |
| 1326 Register const function_map = r3; // Map of {function}. | |
| 1327 Register const function_prototype = r4; // Prototype of {function}. | |
| 1328 Register const scratch = r5; | |
| 1329 | |
| 1330 DCHECK(object.is(InstanceOfDescriptor::LeftRegister())); | |
| 1331 DCHECK(function.is(InstanceOfDescriptor::RightRegister())); | |
| 1332 | |
| 1333 // Check if {object} is a smi. | |
| 1334 Label object_is_smi; | |
| 1335 __ JumpIfSmi(object, &object_is_smi); | |
| 1336 | |
| 1337 // Lookup the {function} and the {object} map in the global instanceof cache. | |
| 1338 // Note: This is safe because we clear the global instanceof cache whenever | |
| 1339 // we change the prototype of any object. | |
| 1340 Label fast_case, slow_case; | |
| 1341 __ ldr(object_map, FieldMemOperand(object, HeapObject::kMapOffset)); | |
| 1342 __ CompareRoot(function, Heap::kInstanceofCacheFunctionRootIndex); | |
| 1343 __ b(ne, &fast_case); | |
| 1344 __ CompareRoot(object_map, Heap::kInstanceofCacheMapRootIndex); | |
| 1345 __ b(ne, &fast_case); | |
| 1346 __ LoadRoot(r0, Heap::kInstanceofCacheAnswerRootIndex); | |
| 1347 __ Ret(); | |
| 1348 | |
| 1349 // If {object} is a smi we can safely return false if {function} is a JS | |
| 1350 // function, otherwise we have to miss to the runtime and throw an exception. | |
| 1351 __ bind(&object_is_smi); | |
| 1352 __ JumpIfSmi(function, &slow_case); | |
| 1353 __ CompareObjectType(function, function_map, scratch, JS_FUNCTION_TYPE); | |
| 1354 __ b(ne, &slow_case); | |
| 1355 __ LoadRoot(r0, Heap::kFalseValueRootIndex); | |
| 1356 __ Ret(); | |
| 1357 | |
| 1358 // Fast-case: The {function} must be a valid JSFunction. | |
| 1359 __ bind(&fast_case); | |
| 1360 __ JumpIfSmi(function, &slow_case); | |
| 1361 __ CompareObjectType(function, function_map, scratch, JS_FUNCTION_TYPE); | |
| 1362 __ b(ne, &slow_case); | |
| 1363 | |
| 1364 // Go to the runtime if the function is not a constructor. | |
| 1365 __ ldrb(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset)); | |
| 1366 __ tst(scratch, Operand(1 << Map::kIsConstructor)); | |
| 1367 __ b(eq, &slow_case); | |
| 1368 | |
| 1369 // Ensure that {function} has an instance prototype. | |
| 1370 __ tst(scratch, Operand(1 << Map::kHasNonInstancePrototype)); | |
| 1371 __ b(ne, &slow_case); | |
| 1372 | |
| 1373 // Get the "prototype" (or initial map) of the {function}. | |
| 1374 __ ldr(function_prototype, | |
| 1375 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); | |
| 1376 __ AssertNotSmi(function_prototype); | |
| 1377 | |
| 1378 // Resolve the prototype if the {function} has an initial map. Afterwards the | |
| 1379 // {function_prototype} will be either the JSReceiver prototype object or the | |
| 1380 // hole value, which means that no instances of the {function} were created so | |
| 1381 // far and hence we should return false. | |
| 1382 Label function_prototype_valid; | |
| 1383 __ CompareObjectType(function_prototype, scratch, scratch, MAP_TYPE); | |
| 1384 __ b(ne, &function_prototype_valid); | |
| 1385 __ ldr(function_prototype, | |
| 1386 FieldMemOperand(function_prototype, Map::kPrototypeOffset)); | |
| 1387 __ bind(&function_prototype_valid); | |
| 1388 __ AssertNotSmi(function_prototype); | |
| 1389 | |
| 1390 // Update the global instanceof cache with the current {object} map and | |
| 1391 // {function}. The cached answer will be set when it is known below. | |
| 1392 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex); | |
| 1393 __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex); | |
| 1394 | |
| 1395 // Loop through the prototype chain looking for the {function} prototype. | |
| 1396 // Assume true, and change to false if not found. | |
| 1397 Register const object_instance_type = function_map; | |
| 1398 Register const map_bit_field = function_map; | |
| 1399 Register const null = scratch; | |
| 1400 Register const result = r0; | |
| 1401 | |
| 1402 Label done, loop, fast_runtime_fallback; | |
| 1403 __ LoadRoot(result, Heap::kTrueValueRootIndex); | |
| 1404 __ LoadRoot(null, Heap::kNullValueRootIndex); | |
| 1405 __ bind(&loop); | |
| 1406 | |
| 1407 // Check if the object needs to be access checked. | |
| 1408 __ ldrb(map_bit_field, FieldMemOperand(object_map, Map::kBitFieldOffset)); | |
| 1409 __ tst(map_bit_field, Operand(1 << Map::kIsAccessCheckNeeded)); | |
| 1410 __ b(ne, &fast_runtime_fallback); | |
| 1411 // Check if the current object is a Proxy. | |
| 1412 __ CompareInstanceType(object_map, object_instance_type, JS_PROXY_TYPE); | |
| 1413 __ b(eq, &fast_runtime_fallback); | |
| 1414 | |
| 1415 __ ldr(object, FieldMemOperand(object_map, Map::kPrototypeOffset)); | |
| 1416 __ cmp(object, function_prototype); | |
| 1417 __ b(eq, &done); | |
| 1418 __ cmp(object, null); | |
| 1419 __ ldr(object_map, FieldMemOperand(object, HeapObject::kMapOffset)); | |
| 1420 __ b(ne, &loop); | |
| 1421 __ LoadRoot(result, Heap::kFalseValueRootIndex); | |
| 1422 __ bind(&done); | |
| 1423 __ StoreRoot(result, Heap::kInstanceofCacheAnswerRootIndex); | |
| 1424 __ Ret(); | |
| 1425 | |
| 1426 // Found Proxy or access check needed: Call the runtime | |
| 1427 __ bind(&fast_runtime_fallback); | |
| 1428 __ Push(object, function_prototype); | |
| 1429 // Invalidate the instanceof cache. | |
| 1430 __ Move(scratch, Smi::FromInt(0)); | |
| 1431 __ StoreRoot(scratch, Heap::kInstanceofCacheFunctionRootIndex); | |
| 1432 __ TailCallRuntime(Runtime::kHasInPrototypeChain); | |
| 1433 | |
| 1434 // Slow-case: Call the %InstanceOf runtime function. | |
| 1435 __ bind(&slow_case); | |
| 1436 __ Push(object, function); | |
| 1437 __ TailCallRuntime(is_es6_instanceof() ? Runtime::kOrdinaryHasInstance | |
| 1438 : Runtime::kInstanceOf); | |
| 1439 } | |
| 1440 | |
| 1441 | |
| 1442 void FunctionPrototypeStub::Generate(MacroAssembler* masm) { | 1322 void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 1443 Label miss; | 1323 Label miss; |
| 1444 Register receiver = LoadDescriptor::ReceiverRegister(); | 1324 Register receiver = LoadDescriptor::ReceiverRegister(); |
| 1445 // Ensure that the vector and slot registers won't be clobbered before | 1325 // Ensure that the vector and slot registers won't be clobbered before |
| 1446 // calling the miss handler. | 1326 // calling the miss handler. |
| 1447 DCHECK(!AreAliased(r4, r5, LoadWithVectorDescriptor::VectorRegister(), | 1327 DCHECK(!AreAliased(r4, r5, LoadWithVectorDescriptor::VectorRegister(), |
| 1448 LoadWithVectorDescriptor::SlotRegister())); | 1328 LoadWithVectorDescriptor::SlotRegister())); |
| 1449 | 1329 |
| 1450 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, r4, | 1330 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, r4, |
| 1451 r5, &miss); | 1331 r5, &miss); |
| (...skipping 4107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5559 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, | 5439 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, |
| 5560 kStackUnwindSpace, NULL, return_value_operand, NULL); | 5440 kStackUnwindSpace, NULL, return_value_operand, NULL); |
| 5561 } | 5441 } |
| 5562 | 5442 |
| 5563 #undef __ | 5443 #undef __ |
| 5564 | 5444 |
| 5565 } // namespace internal | 5445 } // namespace internal |
| 5566 } // namespace v8 | 5446 } // namespace v8 |
| 5567 | 5447 |
| 5568 #endif // V8_TARGET_ARCH_ARM | 5448 #endif // V8_TARGET_ARCH_ARM |
| OLD | NEW |