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

Side by Side Diff: runtime/vm/stub_code_ia32.cc

Issue 203523011: Introduce a lazy-compile stub for functions. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: rebased Created 6 years, 8 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 | « runtime/vm/stub_code_arm.cc ('k') | runtime/vm/stub_code_mips.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 (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/globals.h" 5 #include "vm/globals.h"
6 #if defined(TARGET_ARCH_IA32) 6 #if defined(TARGET_ARCH_IA32)
7 7
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 __ j(ZERO, &not_closure, Assembler::kNearJump); // Not a closure, but a smi. 766 __ j(ZERO, &not_closure, Assembler::kNearJump); // Not a closure, but a smi.
767 // Verify that the class of the object is a closure class by checking that 767 // Verify that the class of the object is a closure class by checking that
768 // class.signature_function() is not null. 768 // class.signature_function() is not null.
769 __ LoadClass(EAX, EDI, ECX); 769 __ LoadClass(EAX, EDI, ECX);
770 __ movl(EAX, FieldAddress(EAX, Class::signature_function_offset())); 770 __ movl(EAX, FieldAddress(EAX, Class::signature_function_offset()));
771 __ cmpl(EAX, raw_null); 771 __ cmpl(EAX, raw_null);
772 // Actual class is not a closure class. 772 // Actual class is not a closure class.
773 __ j(EQUAL, &not_closure, Assembler::kNearJump); 773 __ j(EQUAL, &not_closure, Assembler::kNearJump);
774 774
775 // EAX is just the signature function. Load the actual closure function. 775 // EAX is just the signature function. Load the actual closure function.
776 __ movl(ECX, FieldAddress(EDI, Closure::function_offset())); 776 __ movl(EAX, FieldAddress(EDI, Closure::function_offset()));
777 777
778 // Load closure context in CTX; note that CTX has already been preserved. 778 // Load closure context in CTX; note that CTX has already been preserved.
779 __ movl(CTX, FieldAddress(EDI, Closure::context_offset())); 779 __ movl(CTX, FieldAddress(EDI, Closure::context_offset()));
780 780
781 // Load closure function code in EAX. 781 // EBX: Code (compiled code or lazy compile stub).
782 __ movl(EAX, FieldAddress(ECX, Function::code_offset())); 782 __ movl(EBX, FieldAddress(EAX, Function::code_offset()));
783 __ cmpl(EAX, raw_null);
784 Label function_compiled;
785 __ j(NOT_EQUAL, &function_compiled, Assembler::kNearJump);
786 783
787 // Create a stub frame as we are pushing some objects on the stack before 784 // EAX: Function.
788 // calling into the runtime.
789 __ EnterStubFrame();
790
791 __ pushl(EDX); // Preserve arguments descriptor array.
792 __ pushl(ECX); // Preserve read-only function object argument.
793 __ CallRuntime(kCompileFunctionRuntimeEntry, 1);
794 __ popl(ECX); // Restore read-only function object argument in ECX.
795 __ popl(EDX); // Restore arguments descriptor array.
796 // Restore EAX.
797 __ movl(EAX, FieldAddress(ECX, Function::code_offset()));
798
799 // Remove the stub frame as we are about to jump to the closure function.
800 __ LeaveFrame();
801
802 __ Bind(&function_compiled);
803 // EAX: Code.
804 // ECX: Function.
805 // EDX: Arguments descriptor array. 785 // EDX: Arguments descriptor array.
806 786 __ movl(ECX, FieldAddress(EBX, Code::instructions_offset()));
807 __ movl(ECX, FieldAddress(EAX, Code::instructions_offset()));
808 __ addl(ECX, Immediate(Instructions::HeaderSize() - kHeapObjectTag)); 787 __ addl(ECX, Immediate(Instructions::HeaderSize() - kHeapObjectTag));
809 __ jmp(ECX); 788 __ jmp(ECX);
810 789
811 __ Bind(&not_closure); 790 __ Bind(&not_closure);
812 // Call runtime to attempt to resolve and invoke a call method on a 791 // Call runtime to attempt to resolve and invoke a call method on a
813 // non-closure object, passing the non-closure object and its arguments array, 792 // non-closure object, passing the non-closure object and its arguments array,
814 // returning here. 793 // returning here.
815 // If no call method exists, throw a NoSuchMethodError. 794 // If no call method exists, throw a NoSuchMethodError.
816 // EDI: non-closure object. 795 // EDI: non-closure object.
817 // EDX: arguments descriptor array. 796 // EDX: arguments descriptor array.
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 const intptr_t target_offset = ICData::TargetIndexFor(num_args) * kWordSize; 1480 const intptr_t target_offset = ICData::TargetIndexFor(num_args) * kWordSize;
1502 const intptr_t count_offset = ICData::CountIndexFor(num_args) * kWordSize; 1481 const intptr_t count_offset = ICData::CountIndexFor(num_args) * kWordSize;
1503 __ movl(EAX, Address(EBX, target_offset)); 1482 __ movl(EAX, Address(EBX, target_offset));
1504 __ addl(Address(EBX, count_offset), Immediate(Smi::RawValue(1))); 1483 __ addl(Address(EBX, count_offset), Immediate(Smi::RawValue(1)));
1505 __ j(NO_OVERFLOW, &call_target_function, Assembler::kNearJump); 1484 __ j(NO_OVERFLOW, &call_target_function, Assembler::kNearJump);
1506 __ movl(Address(EBX, count_offset), 1485 __ movl(Address(EBX, count_offset),
1507 Immediate(Smi::RawValue(Smi::kMaxValue))); 1486 Immediate(Smi::RawValue(Smi::kMaxValue)));
1508 1487
1509 __ Bind(&call_target_function); 1488 __ Bind(&call_target_function);
1510 // EAX: Target function. 1489 // EAX: Target function.
1511 Label is_compiled;
1512 __ movl(EBX, FieldAddress(EAX, Function::code_offset())); 1490 __ movl(EBX, FieldAddress(EAX, Function::code_offset()));
1513 if (FLAG_collect_code) { 1491 __ movl(EBX, FieldAddress(EBX, Code::instructions_offset()));
1514 // If code might be GC'd, then EBX might be null. If it is, recompile. 1492 __ addl(EBX, Immediate(Instructions::HeaderSize() - kHeapObjectTag));
1515 __ cmpl(EBX, raw_null); 1493 __ jmp(EBX);
1516 __ j(NOT_EQUAL, &is_compiled, Assembler::kNearJump);
1517 __ EnterStubFrame();
1518 __ pushl(EDX); // Preserve arguments descriptor array.
1519 __ pushl(ECX); // Preserve IC data object.
1520 __ pushl(EAX); // Pass function.
1521 __ CallRuntime(kCompileFunctionRuntimeEntry, 1);
1522 __ popl(EAX); // Restore function.
1523 __ popl(ECX); // Restore IC data array.
1524 __ popl(EDX); // Restore arguments descriptor array.
1525 __ LeaveFrame();
1526 __ movl(EBX, FieldAddress(EAX, Function::code_offset()));
1527 __ Bind(&is_compiled);
1528 }
1529 __ movl(EAX, FieldAddress(EBX, Code::instructions_offset()));
1530 __ addl(EAX, Immediate(Instructions::HeaderSize() - kHeapObjectTag));
1531 __ jmp(EAX);
1532 1494
1533 // Instance in EAX, return its class-id in EAX as Smi. 1495 // Instance in EAX, return its class-id in EAX as Smi.
1534 __ Bind(&get_class_id_as_smi); 1496 __ Bind(&get_class_id_as_smi);
1535 Label not_smi; 1497 Label not_smi;
1536 // Test if Smi -> load Smi class for comparison. 1498 // Test if Smi -> load Smi class for comparison.
1537 __ testl(EAX, Immediate(kSmiTagMask)); 1499 __ testl(EAX, Immediate(kSmiTagMask));
1538 __ j(NOT_ZERO, &not_smi, Assembler::kNearJump); 1500 __ j(NOT_ZERO, &not_smi, Assembler::kNearJump);
1539 __ movl(EAX, Immediate(Smi::RawValue(kSmiCid))); 1501 __ movl(EAX, Immediate(Smi::RawValue(kSmiCid)));
1540 __ ret(); 1502 __ ret();
1541 1503
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 const intptr_t target_offset = ICData::TargetIndexFor(0) * kWordSize; 1627 const intptr_t target_offset = ICData::TargetIndexFor(0) * kWordSize;
1666 const intptr_t count_offset = ICData::CountIndexFor(0) * kWordSize; 1628 const intptr_t count_offset = ICData::CountIndexFor(0) * kWordSize;
1667 1629
1668 // Increment count for this call. 1630 // Increment count for this call.
1669 Label increment_done; 1631 Label increment_done;
1670 __ addl(Address(EBX, count_offset), Immediate(Smi::RawValue(1))); 1632 __ addl(Address(EBX, count_offset), Immediate(Smi::RawValue(1)));
1671 __ j(NO_OVERFLOW, &increment_done, Assembler::kNearJump); 1633 __ j(NO_OVERFLOW, &increment_done, Assembler::kNearJump);
1672 __ movl(Address(EBX, count_offset), Immediate(Smi::RawValue(Smi::kMaxValue))); 1634 __ movl(Address(EBX, count_offset), Immediate(Smi::RawValue(Smi::kMaxValue)));
1673 __ Bind(&increment_done); 1635 __ Bind(&increment_done);
1674 1636
1675 const Immediate& raw_null =
1676 Immediate(reinterpret_cast<intptr_t>(Object::null()));
1677 Label target_is_compiled;
1678 // Get function and call it, if possible.
1679 __ movl(EDI, Address(EBX, target_offset));
1680 __ movl(EAX, FieldAddress(EDI, Function::code_offset()));
1681 __ cmpl(EAX, raw_null);
1682 __ j(NOT_EQUAL, &target_is_compiled, Assembler::kNearJump);
1683 __ EnterStubFrame();
1684 __ pushl(EDI); // Preserve target function.
1685 __ pushl(ECX); // Preserve IC data object.
1686 __ pushl(EDI); // Pass function.
1687 __ CallRuntime(kCompileFunctionRuntimeEntry, 1);
1688 __ popl(EAX); // Discard argument.
1689 __ popl(ECX); // Restore IC data object.
1690 __ popl(EDI); // Restore target function.
1691 __ LeaveFrame();
1692 __ movl(EAX, FieldAddress(EDI, Function::code_offset()));
1693
1694 __ Bind(&target_is_compiled);
1695 // EAX: Target code.
1696 __ movl(EAX, FieldAddress(EAX, Code::instructions_offset()));
1697 __ addl(EAX, Immediate(Instructions::HeaderSize() - kHeapObjectTag));
1698 // Load arguments descriptor into EDX. 1637 // Load arguments descriptor into EDX.
1699 __ movl(EDX, FieldAddress(ECX, ICData::arguments_descriptor_offset())); 1638 __ movl(EDX, FieldAddress(ECX, ICData::arguments_descriptor_offset()));
1700 __ jmp(EAX); 1639
1640 // Get function and call it, if possible.
1641 __ movl(EAX, Address(EBX, target_offset));
1642 __ movl(EBX, FieldAddress(EAX, Function::code_offset()));
1643
1644 // EBX: Target code.
1645 __ movl(EBX, FieldAddress(EBX, Code::instructions_offset()));
1646 __ addl(EBX, Immediate(Instructions::HeaderSize() - kHeapObjectTag));
1647 __ jmp(EBX);
1701 } 1648 }
1702 1649
1703 1650
1704 void StubCode::GenerateTwoArgsUnoptimizedStaticCallStub(Assembler* assembler) { 1651 void StubCode::GenerateTwoArgsUnoptimizedStaticCallStub(Assembler* assembler) {
1705 GenerateUsageCounterIncrement(assembler, EBX); 1652 GenerateUsageCounterIncrement(assembler, EBX);
1706 GenerateNArgsCheckInlineCacheStub( 1653 GenerateNArgsCheckInlineCacheStub(
1707 assembler, 2, kStaticCallMissHandlerTwoArgsRuntimeEntry); 1654 assembler, 2, kStaticCallMissHandlerTwoArgsRuntimeEntry);
1708 } 1655 }
1709 1656
1710 1657
1711 // Stub for calling the CompileFunction runtime call. 1658 // Stub for compiling a function and jumping to the compiled code.
1712 // ECX: IC-Data. 1659 // ECX: IC-Data (for methods).
1713 // EDX: Arguments descriptor. 1660 // EDX: Arguments descriptor.
1714 // EAX: Function. 1661 // EAX: Function.
1715 void StubCode::GenerateCompileFunctionRuntimeCallStub(Assembler* assembler) { 1662 void StubCode::GenerateLazyCompileStub(Assembler* assembler) {
1716 __ EnterStubFrame(); 1663 __ EnterStubFrame();
1717 __ pushl(EDX); // Preserve arguments descriptor array. 1664 __ pushl(EDX); // Preserve arguments descriptor array.
1718 __ pushl(ECX); // Preserve IC data object. 1665 __ pushl(ECX); // Preserve IC data object.
1719 __ pushl(EAX); // Pass function. 1666 __ pushl(EAX); // Pass function.
1720 __ CallRuntime(kCompileFunctionRuntimeEntry, 1); 1667 __ CallRuntime(kCompileFunctionRuntimeEntry, 1);
1721 __ popl(EAX); // Restore function. 1668 __ popl(EAX); // Restore function.
1722 __ popl(ECX); // Restore IC data array. 1669 __ popl(ECX); // Restore IC data array.
1723 __ popl(EDX); // Restore arguments descriptor array. 1670 __ popl(EDX); // Restore arguments descriptor array.
1724 __ LeaveFrame(); 1671 __ LeaveFrame();
1725 __ ret(); 1672
1673 __ movl(EAX, FieldAddress(EAX, Function::code_offset()));
1674 __ movl(EAX, FieldAddress(EAX, Code::instructions_offset()));
1675 __ addl(EAX, Immediate(Instructions::HeaderSize() - kHeapObjectTag));
1676 __ jmp(EAX);
1726 } 1677 }
1727 1678
1728 1679
1729 // EDX, ECX: May contain arguments to runtime stub. 1680 // EDX, ECX: May contain arguments to runtime stub.
1730 void StubCode::GenerateBreakpointRuntimeStub(Assembler* assembler) { 1681 void StubCode::GenerateBreakpointRuntimeStub(Assembler* assembler) {
1731 __ EnterStubFrame(); 1682 __ EnterStubFrame();
1732 // Save runtime args. 1683 // Save runtime args.
1733 __ pushl(ECX); 1684 __ pushl(ECX);
1734 __ pushl(EDX); 1685 __ pushl(EDX);
1735 // Room for result. Debugger stub returns address of the 1686 // Room for result. Debugger stub returns address of the
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
2035 const Register temp = ECX; 1986 const Register temp = ECX;
2036 __ movl(left, Address(ESP, 2 * kWordSize)); 1987 __ movl(left, Address(ESP, 2 * kWordSize));
2037 __ movl(right, Address(ESP, 1 * kWordSize)); 1988 __ movl(right, Address(ESP, 1 * kWordSize));
2038 GenerateIdenticalWithNumberCheckStub(assembler, left, right, temp); 1989 GenerateIdenticalWithNumberCheckStub(assembler, left, right, temp);
2039 __ ret(); 1990 __ ret();
2040 } 1991 }
2041 1992
2042 } // namespace dart 1993 } // namespace dart
2043 1994
2044 #endif // defined TARGET_ARCH_IA32 1995 #endif // defined TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « runtime/vm/stub_code_arm.cc ('k') | runtime/vm/stub_code_mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698