OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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_PPC | 5 #if V8_TARGET_ARCH_PPC |
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 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1365 // Restore callee-saved registers. | 1365 // Restore callee-saved registers. |
1366 __ MultiPop(kCalleeSaved); | 1366 __ MultiPop(kCalleeSaved); |
1367 | 1367 |
1368 // Return | 1368 // Return |
1369 __ LoadP(r0, MemOperand(sp, kStackFrameLRSlot * kPointerSize)); | 1369 __ LoadP(r0, MemOperand(sp, kStackFrameLRSlot * kPointerSize)); |
1370 __ mtlr(r0); | 1370 __ mtlr(r0); |
1371 __ blr(); | 1371 __ blr(); |
1372 } | 1372 } |
1373 | 1373 |
1374 | 1374 |
1375 void InstanceOfStub::Generate(MacroAssembler* masm) { | |
1376 Register const object = r4; // Object (lhs). | |
1377 Register const function = r3; // Function (rhs). | |
1378 Register const object_map = r5; // Map of {object}. | |
1379 Register const function_map = r6; // Map of {function}. | |
1380 Register const function_prototype = r7; // Prototype of {function}. | |
1381 Register const scratch = r8; | |
1382 | |
1383 DCHECK(object.is(InstanceOfDescriptor::LeftRegister())); | |
1384 DCHECK(function.is(InstanceOfDescriptor::RightRegister())); | |
1385 | |
1386 // Check if {object} is a smi. | |
1387 Label object_is_smi; | |
1388 __ JumpIfSmi(object, &object_is_smi); | |
1389 | |
1390 // Lookup the {function} and the {object} map in the global instanceof cache. | |
1391 // Note: This is safe because we clear the global instanceof cache whenever | |
1392 // we change the prototype of any object. | |
1393 Label fast_case, slow_case; | |
1394 __ LoadP(object_map, FieldMemOperand(object, HeapObject::kMapOffset)); | |
1395 __ CompareRoot(function, Heap::kInstanceofCacheFunctionRootIndex); | |
1396 __ bne(&fast_case); | |
1397 __ CompareRoot(object_map, Heap::kInstanceofCacheMapRootIndex); | |
1398 __ bne(&fast_case); | |
1399 __ LoadRoot(r3, Heap::kInstanceofCacheAnswerRootIndex); | |
1400 __ Ret(); | |
1401 | |
1402 // If {object} is a smi we can safely return false if {function} is a JS | |
1403 // function, otherwise we have to miss to the runtime and throw an exception. | |
1404 __ bind(&object_is_smi); | |
1405 __ JumpIfSmi(function, &slow_case); | |
1406 __ CompareObjectType(function, function_map, scratch, JS_FUNCTION_TYPE); | |
1407 __ bne(&slow_case); | |
1408 __ LoadRoot(r3, Heap::kFalseValueRootIndex); | |
1409 __ Ret(); | |
1410 | |
1411 // Fast-case: The {function} must be a valid JSFunction. | |
1412 __ bind(&fast_case); | |
1413 __ JumpIfSmi(function, &slow_case); | |
1414 __ CompareObjectType(function, function_map, scratch, JS_FUNCTION_TYPE); | |
1415 __ bne(&slow_case); | |
1416 | |
1417 // Go to the runtime if the function is not a constructor. | |
1418 __ lbz(scratch, FieldMemOperand(function_map, Map::kBitFieldOffset)); | |
1419 __ TestBit(scratch, Map::kIsConstructor, r0); | |
1420 __ beq(&slow_case, cr0); | |
1421 | |
1422 // Ensure that {function} has an instance prototype. | |
1423 __ TestBit(scratch, Map::kHasNonInstancePrototype, r0); | |
1424 __ bne(&slow_case, cr0); | |
1425 | |
1426 // Get the "prototype" (or initial map) of the {function}. | |
1427 __ LoadP(function_prototype, | |
1428 FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); | |
1429 __ AssertNotSmi(function_prototype); | |
1430 | |
1431 // Resolve the prototype if the {function} has an initial map. Afterwards the | |
1432 // {function_prototype} will be either the JSReceiver prototype object or the | |
1433 // hole value, which means that no instances of the {function} were created so | |
1434 // far and hence we should return false. | |
1435 Label function_prototype_valid; | |
1436 __ CompareObjectType(function_prototype, scratch, scratch, MAP_TYPE); | |
1437 __ bne(&function_prototype_valid); | |
1438 __ LoadP(function_prototype, | |
1439 FieldMemOperand(function_prototype, Map::kPrototypeOffset)); | |
1440 __ bind(&function_prototype_valid); | |
1441 __ AssertNotSmi(function_prototype); | |
1442 | |
1443 // Update the global instanceof cache with the current {object} map and | |
1444 // {function}. The cached answer will be set when it is known below. | |
1445 __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex); | |
1446 __ StoreRoot(object_map, Heap::kInstanceofCacheMapRootIndex); | |
1447 | |
1448 // Loop through the prototype chain looking for the {function} prototype. | |
1449 // Assume true, and change to false if not found. | |
1450 Register const object_instance_type = function_map; | |
1451 Register const map_bit_field = function_map; | |
1452 Register const null = scratch; | |
1453 Register const result = r3; | |
1454 | |
1455 Label done, loop, fast_runtime_fallback; | |
1456 __ LoadRoot(result, Heap::kTrueValueRootIndex); | |
1457 __ LoadRoot(null, Heap::kNullValueRootIndex); | |
1458 __ bind(&loop); | |
1459 | |
1460 // Check if the object needs to be access checked. | |
1461 __ lbz(map_bit_field, FieldMemOperand(object_map, Map::kBitFieldOffset)); | |
1462 __ TestBit(map_bit_field, Map::kIsAccessCheckNeeded, r0); | |
1463 __ bne(&fast_runtime_fallback, cr0); | |
1464 // Check if the current object is a Proxy. | |
1465 __ CompareInstanceType(object_map, object_instance_type, JS_PROXY_TYPE); | |
1466 __ beq(&fast_runtime_fallback); | |
1467 | |
1468 __ LoadP(object, FieldMemOperand(object_map, Map::kPrototypeOffset)); | |
1469 __ cmp(object, function_prototype); | |
1470 __ beq(&done); | |
1471 __ cmp(object, null); | |
1472 __ LoadP(object_map, FieldMemOperand(object, HeapObject::kMapOffset)); | |
1473 __ bne(&loop); | |
1474 __ LoadRoot(result, Heap::kFalseValueRootIndex); | |
1475 __ bind(&done); | |
1476 __ StoreRoot(result, Heap::kInstanceofCacheAnswerRootIndex); | |
1477 __ Ret(); | |
1478 | |
1479 // Found Proxy or access check needed: Call the runtime | |
1480 __ bind(&fast_runtime_fallback); | |
1481 __ Push(object, function_prototype); | |
1482 // Invalidate the instanceof cache. | |
1483 __ LoadSmiLiteral(scratch, Smi::FromInt(0)); | |
1484 __ StoreRoot(scratch, Heap::kInstanceofCacheFunctionRootIndex); | |
1485 __ TailCallRuntime(Runtime::kHasInPrototypeChain); | |
1486 | |
1487 // Slow-case: Call the %InstanceOf runtime function. | |
1488 __ bind(&slow_case); | |
1489 __ Push(object, function); | |
1490 __ TailCallRuntime(is_es6_instanceof() ? Runtime::kOrdinaryHasInstance | |
1491 : Runtime::kInstanceOf); | |
1492 } | |
1493 | |
1494 | |
1495 void FunctionPrototypeStub::Generate(MacroAssembler* masm) { | 1375 void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
1496 Label miss; | 1376 Label miss; |
1497 Register receiver = LoadDescriptor::ReceiverRegister(); | 1377 Register receiver = LoadDescriptor::ReceiverRegister(); |
1498 // Ensure that the vector and slot registers won't be clobbered before | 1378 // Ensure that the vector and slot registers won't be clobbered before |
1499 // calling the miss handler. | 1379 // calling the miss handler. |
1500 DCHECK(!AreAliased(r7, r8, LoadWithVectorDescriptor::VectorRegister(), | 1380 DCHECK(!AreAliased(r7, r8, LoadWithVectorDescriptor::VectorRegister(), |
1501 LoadWithVectorDescriptor::SlotRegister())); | 1381 LoadWithVectorDescriptor::SlotRegister())); |
1502 | 1382 |
1503 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, r7, | 1383 NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(masm, receiver, r7, |
1504 r8, &miss); | 1384 r8, &miss); |
(...skipping 4298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5803 fp, (PropertyCallbackArguments::kReturnValueOffset + 3) * kPointerSize); | 5683 fp, (PropertyCallbackArguments::kReturnValueOffset + 3) * kPointerSize); |
5804 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, | 5684 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, |
5805 kStackUnwindSpace, NULL, return_value_operand, NULL); | 5685 kStackUnwindSpace, NULL, return_value_operand, NULL); |
5806 } | 5686 } |
5807 | 5687 |
5808 #undef __ | 5688 #undef __ |
5809 } // namespace internal | 5689 } // namespace internal |
5810 } // namespace v8 | 5690 } // namespace v8 |
5811 | 5691 |
5812 #endif // V8_TARGET_ARCH_PPC | 5692 #endif // V8_TARGET_ARCH_PPC |
OLD | NEW |