Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 1379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1390 Call(stub->GetCode(), RelocInfo::CODE_TARGET, cond); | 1390 Call(stub->GetCode(), RelocInfo::CODE_TARGET, cond); |
| 1391 } | 1391 } |
| 1392 | 1392 |
| 1393 | 1393 |
| 1394 void MacroAssembler::TailCallStub(CodeStub* stub, Condition cond) { | 1394 void MacroAssembler::TailCallStub(CodeStub* stub, Condition cond) { |
| 1395 ASSERT(allow_stub_calls()); // stub calls are not allowed in some stubs | 1395 ASSERT(allow_stub_calls()); // stub calls are not allowed in some stubs |
| 1396 Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond); | 1396 Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond); |
| 1397 } | 1397 } |
| 1398 | 1398 |
| 1399 | 1399 |
| 1400 MaybeObject* MacroAssembler::TryTailCallStub(CodeStub* stub, Condition cond) { | |
| 1401 ASSERT(allow_stub_calls()); // stub calls are not allowed in some stubs | |
| 1402 Object* result; | |
| 1403 { MaybeObject* maybe_result = stub->TryGetCode(); | |
| 1404 if (!maybe_result->ToObject(&result)) return maybe_result; | |
| 1405 } | |
| 1406 Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond); | |
| 1407 return result; | |
| 1408 } | |
| 1409 | |
| 1410 void MacroAssembler::EnterExitFramePrologue(int unwind_space) { | |
| 1411 add(ip, sp, Operand(unwind_space * kPointerSize)); | |
| 1412 stm(db_w, sp, fp.bit() | ip.bit() | lr.bit()); | |
| 1413 mov(fp, Operand(sp)); | |
| 1414 | |
| 1415 mov(ip, Operand(CodeObject())); | |
| 1416 push(ip); | |
| 1417 push(ip); // Exit Frame pc patched before call | |
| 1418 | |
| 1419 mov(ip, Operand(ExternalReference(Top::k_c_entry_fp_address))); | |
| 1420 str(fp, MemOperand(ip)); | |
| 1421 mov(ip, Operand(ExternalReference(Top::k_context_address))); | |
| 1422 str(cp, MemOperand(ip)); | |
| 1423 } | |
| 1424 | |
| 1425 void MacroAssembler::EnterExitFrameEpilogue(int arg_stack_space) { | |
| 1426 // Create space for the args | |
| 1427 sub(sp, sp, Operand(arg_stack_space * kPointerSize)); | |
| 1428 | |
| 1429 int frame_alignment = ActivationFrameAlignment(); | |
| 1430 int frame_alignment_mask = frame_alignment - 1; | |
| 1431 if (frame_alignment > kPointerSize) { | |
| 1432 ASSERT(frame_alignment == 2 * kPointerSize); | |
| 1433 tst(sp, Operand(frame_alignment_mask)); | |
| 1434 push(ip, nz); | |
| 1435 } | |
| 1436 } | |
| 1437 | |
| 1438 void MacroAssembler::PrepareCallApiFunction(int arg_stack_space, | |
| 1439 int unwind_space) { | |
| 1440 EnterExitFramePrologue(unwind_space); | |
| 1441 EnterExitFrameEpilogue(arg_stack_space); | |
| 1442 } | |
| 1443 | |
| 1444 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) { | |
| 1445 int64_t offset = (ref0.address() - ref1.address()); | |
| 1446 // Check that fits into int. | |
| 1447 ASSERT(static_cast<int>(offset) == offset); | |
| 1448 return static_cast<int>(offset); | |
| 1449 } | |
| 1450 | |
| 1451 MaybeObject* MacroAssembler::TryCallApiFunctionAndReturn( | |
| 1452 ApiFunction* function) { | |
| 1453 ExternalReference next_address = | |
| 1454 ExternalReference::handle_scope_next_address(); | |
| 1455 const int kNextOffset = 0; | |
| 1456 const int kLimitOffset = AddressOffset( | |
| 1457 ExternalReference::handle_scope_limit_address(), | |
| 1458 next_address); | |
| 1459 const int kLevelOffset = AddressOffset( | |
| 1460 ExternalReference::handle_scope_level_address(), | |
| 1461 next_address); | |
| 1462 | |
| 1463 // Allocate HandleScope in callee-save registers. | |
| 1464 mov(r7, Operand(next_address)); | |
| 1465 ldr(r4, MemOperand(r7, kNextOffset)); | |
| 1466 ldr(r5, MemOperand(r7, kLimitOffset)); | |
| 1467 ldr(r6, MemOperand(r7, kLevelOffset)); | |
| 1468 add(r6, r6, Operand(1)); | |
| 1469 str(r6, MemOperand(r7, kLevelOffset)); | |
| 1470 | |
| 1471 // patch the exit frame pc and Call the api function! | |
| 1472 add(ip, pc, Operand(8)); | |
| 1473 str(ip, MemOperand(fp, -2 * kPointerSize)); | |
| 1474 Call(function->address(), RelocInfo::RUNTIME_ENTRY); | |
| 1475 | |
| 1476 Label promote_scheduled_exception; | |
| 1477 Label delete_allocated_handles; | |
| 1478 Label leave_exit_frame; | |
| 1479 | |
| 1480 // If result is non-zero, dereference to get the result value | |
| 1481 // otherwise set it to undefined | |
| 1482 LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); | |
| 1483 ldr(r0, MemOperand(r0), ne); | |
| 1484 | |
| 1485 // No more valid handles (the result handle was the last one). Restore | |
| 1486 // previous handle scope. | |
| 1487 str(r4, MemOperand(r7, kNextOffset)); | |
| 1488 if (FLAG_debug_code) { | |
| 1489 ldr(r1, MemOperand(r7, kLevelOffset)); | |
| 1490 cmp(r1, r6); | |
| 1491 Check(eq, "Unexpected level after return from api call"); | |
| 1492 } | |
| 1493 ldr(r6, MemOperand(r7, kLevelOffset)); | |
|
SeRya
2011/01/13 09:36:21
You've just checked that r6 does contain the same
| |
| 1494 sub(r6, r6, Operand(1)); | |
| 1495 str(r6, MemOperand(r7, kLevelOffset)); | |
| 1496 ldr(ip, MemOperand(r7, kLimitOffset)); | |
| 1497 cmp(r5, ip); | |
| 1498 b(ne, &delete_allocated_handles); | |
| 1499 | |
| 1500 // Check if the function scheduled an exception. | |
| 1501 bind(&leave_exit_frame); | |
| 1502 mov(ip, Operand(ExternalReference::the_hole_value_location())); | |
| 1503 ldr(r4, MemOperand(ip)); | |
| 1504 mov(ip, Operand(ExternalReference(Top::k_pending_exception_address))); | |
| 1505 ldr(r5, MemOperand(ip)); | |
| 1506 cmp(r4, r5); | |
| 1507 b(ne, &promote_scheduled_exception); | |
| 1508 LeaveExitFrame(false); | |
| 1509 | |
| 1510 bind(&promote_scheduled_exception); | |
| 1511 MaybeObject* result = TryTailCallExternalReference( | |
| 1512 ExternalReference(Runtime::kPromoteScheduledException), 0, 1); | |
| 1513 if (result->IsFailure()) { | |
| 1514 return result; | |
| 1515 } | |
| 1516 | |
| 1517 // HandleScope limit has changed. Delete allocated extensions. | |
| 1518 bind(&delete_allocated_handles); | |
| 1519 str(r5, MemOperand(r7, kLimitOffset)); | |
| 1520 mov(r4, r0); | |
| 1521 PrepareCallCFunction(0, r5); | |
| 1522 CallCFunction(ExternalReference::delete_handle_scope_extensions(), 0); | |
| 1523 mov(r0, r4); | |
| 1524 jmp(&leave_exit_frame); | |
| 1525 | |
| 1526 return result; | |
| 1527 } | |
| 1528 | |
| 1529 | |
| 1400 void MacroAssembler::IllegalOperation(int num_arguments) { | 1530 void MacroAssembler::IllegalOperation(int num_arguments) { |
| 1401 if (num_arguments > 0) { | 1531 if (num_arguments > 0) { |
| 1402 add(sp, sp, Operand(num_arguments * kPointerSize)); | 1532 add(sp, sp, Operand(num_arguments * kPointerSize)); |
| 1403 } | 1533 } |
| 1404 LoadRoot(r0, Heap::kUndefinedValueRootIndex); | 1534 LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
| 1405 } | 1535 } |
| 1406 | 1536 |
| 1407 | 1537 |
| 1408 void MacroAssembler::IndexFromHash(Register hash, Register index) { | 1538 void MacroAssembler::IndexFromHash(Register hash, Register index) { |
| 1409 // If the hash field contains an array index pick it out. The assert checks | 1539 // If the hash field contains an array index pick it out. The assert checks |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1642 int num_arguments, | 1772 int num_arguments, |
| 1643 int result_size) { | 1773 int result_size) { |
| 1644 // TODO(1236192): Most runtime routines don't need the number of | 1774 // TODO(1236192): Most runtime routines don't need the number of |
| 1645 // arguments passed in because it is constant. At some point we | 1775 // arguments passed in because it is constant. At some point we |
| 1646 // should remove this need and make the runtime routine entry code | 1776 // should remove this need and make the runtime routine entry code |
| 1647 // smarter. | 1777 // smarter. |
| 1648 mov(r0, Operand(num_arguments)); | 1778 mov(r0, Operand(num_arguments)); |
| 1649 JumpToExternalReference(ext); | 1779 JumpToExternalReference(ext); |
| 1650 } | 1780 } |
| 1651 | 1781 |
| 1782 MaybeObject* MacroAssembler::TryTailCallExternalReference( | |
| 1783 const ExternalReference& ext, int num_arguments, int result_size) { | |
| 1784 // TODO(1236192): Most runtime routines don't need the number of | |
| 1785 // arguments passed in because it is constant. At some point we | |
| 1786 // should remove this need and make the runtime routine entry code | |
| 1787 // smarter. | |
| 1788 mov(r0, Operand(num_arguments)); | |
| 1789 return TryJumpToExternalReference(ext); | |
| 1790 } | |
| 1652 | 1791 |
| 1653 void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, | 1792 void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, |
| 1654 int num_arguments, | 1793 int num_arguments, |
| 1655 int result_size) { | 1794 int result_size) { |
| 1656 TailCallExternalReference(ExternalReference(fid), num_arguments, result_size); | 1795 TailCallExternalReference(ExternalReference(fid), num_arguments, result_size); |
| 1657 } | 1796 } |
| 1658 | 1797 |
| 1659 | 1798 |
| 1660 void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin) { | 1799 void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin) { |
| 1661 #if defined(__thumb__) | 1800 #if defined(__thumb__) |
| 1662 // Thumb mode builtin. | 1801 // Thumb mode builtin. |
| 1663 ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); | 1802 ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); |
| 1664 #endif | 1803 #endif |
| 1665 mov(r1, Operand(builtin)); | 1804 mov(r1, Operand(builtin)); |
| 1666 CEntryStub stub(1); | 1805 CEntryStub stub(1); |
| 1667 Jump(stub.GetCode(), RelocInfo::CODE_TARGET); | 1806 Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 1668 } | 1807 } |
| 1669 | 1808 |
| 1809 MaybeObject* MacroAssembler::TryJumpToExternalReference( | |
| 1810 const ExternalReference& builtin) { | |
| 1811 #if defined(__thumb__) | |
| 1812 // Thumb mode builtin. | |
| 1813 ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); | |
| 1814 #endif | |
| 1815 mov(r1, Operand(builtin)); | |
| 1816 CEntryStub stub(1); | |
| 1817 return TryTailCallStub(&stub); | |
| 1818 } | |
| 1670 | 1819 |
| 1671 void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, | 1820 void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, |
| 1672 InvokeJSFlags flags) { | 1821 InvokeJSFlags flags) { |
| 1673 GetBuiltinEntry(r2, id); | 1822 GetBuiltinEntry(r2, id); |
| 1674 if (flags == CALL_JS) { | 1823 if (flags == CALL_JS) { |
| 1675 Call(r2); | 1824 Call(r2); |
| 1676 } else { | 1825 } else { |
| 1677 ASSERT(flags == JUMP_JS); | 1826 ASSERT(flags == JUMP_JS); |
| 1678 Jump(r2); | 1827 Jump(r2); |
| 1679 } | 1828 } |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2145 | 2294 |
| 2146 void CodePatcher::Emit(Address addr) { | 2295 void CodePatcher::Emit(Address addr) { |
| 2147 masm()->emit(reinterpret_cast<Instr>(addr)); | 2296 masm()->emit(reinterpret_cast<Instr>(addr)); |
| 2148 } | 2297 } |
| 2149 #endif // ENABLE_DEBUGGER_SUPPORT | 2298 #endif // ENABLE_DEBUGGER_SUPPORT |
| 2150 | 2299 |
| 2151 | 2300 |
| 2152 } } // namespace v8::internal | 2301 } } // namespace v8::internal |
| 2153 | 2302 |
| 2154 #endif // V8_TARGET_ARCH_ARM | 2303 #endif // V8_TARGET_ARCH_ARM |
| OLD | NEW |