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 1722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1733 GenerateLoadFunctionPrototype(masm(), ecx, edx, ebx, &miss); | 1733 GenerateLoadFunctionPrototype(masm(), ecx, edx, ebx, &miss); |
1734 __ bind(&miss); | 1734 __ bind(&miss); |
1735 __ DecrementCounter(&Counters::keyed_load_function_prototype, 1); | 1735 __ DecrementCounter(&Counters::keyed_load_function_prototype, 1); |
1736 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); | 1736 GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
1737 | 1737 |
1738 // Return the generated code. | 1738 // Return the generated code. |
1739 return GetCode(CALLBACKS, name); | 1739 return GetCode(CALLBACKS, name); |
1740 } | 1740 } |
1741 | 1741 |
1742 | 1742 |
| 1743 // Specialized stub for constructing objects from functions which only have only |
| 1744 // simple assignments of the form this.x = ...; in their body. |
| 1745 Object* ConstructStubCompiler::CompileConstructStub( |
| 1746 SharedFunctionInfo* shared) { |
| 1747 // ----------- S t a t e ------------- |
| 1748 // -- eax : argc |
| 1749 // -- edi : constructor |
| 1750 // -- esp[0] : return address |
| 1751 // -- esp[4] : last argument |
| 1752 // ----------------------------------- |
| 1753 Label generic_stub_call; |
| 1754 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1755 // Check to see whether there are any break points in the function code. If |
| 1756 // there are jump to the generic constructor stub which calls the actual |
| 1757 // code for the function thereby hitting the break points. |
| 1758 __ mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 1759 __ mov(ebx, FieldOperand(ebx, SharedFunctionInfo::kDebugInfoOffset)); |
| 1760 __ cmp(ebx, Factory::undefined_value()); |
| 1761 __ j(not_equal, &generic_stub_call, not_taken); |
| 1762 #endif |
| 1763 |
| 1764 // Load the initial map and verify that it is in fact a map. |
| 1765 __ mov(ebx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 1766 // Will both indicate a NULL and a Smi. |
| 1767 __ test(ebx, Immediate(kSmiTagMask)); |
| 1768 __ j(zero, &generic_stub_call); |
| 1769 __ CmpObjectType(ebx, MAP_TYPE, ecx); |
| 1770 __ j(not_equal, &generic_stub_call); |
| 1771 |
| 1772 #ifdef DEBUG |
| 1773 // Cannot construct functions this way. |
| 1774 // edi: constructor |
| 1775 // ebx: initial map |
| 1776 __ CmpInstanceType(ebx, JS_FUNCTION_TYPE); |
| 1777 __ Assert(not_equal, "Function constructed by construct stub."); |
| 1778 #endif |
| 1779 |
| 1780 // Now allocate the JSObject on the heap by moving the new space allocation |
| 1781 // top forward. |
| 1782 // edi: constructor |
| 1783 // ebx: initial map |
| 1784 __ movzx_b(ecx, FieldOperand(ebx, Map::kInstanceSizeOffset)); |
| 1785 __ shl(ecx, kPointerSizeLog2); |
| 1786 // Make sure that the maximum heap object size will never cause us |
| 1787 // problems here. |
| 1788 ASSERT(Heap::MaxObjectSizeInPagedSpace() >= JSObject::kMaxInstanceSize); |
| 1789 ExternalReference new_space_allocation_top = |
| 1790 ExternalReference::new_space_allocation_top_address(); |
| 1791 __ mov(edx, Operand::StaticVariable(new_space_allocation_top)); |
| 1792 __ add(ecx, Operand(edx)); // Calculate new top. |
| 1793 ExternalReference new_space_allocation_limit = |
| 1794 ExternalReference::new_space_allocation_limit_address(); |
| 1795 __ cmp(ecx, Operand::StaticVariable(new_space_allocation_limit)); |
| 1796 __ j(above_equal, &generic_stub_call); |
| 1797 |
| 1798 // Update new space top. |
| 1799 __ mov(Operand::StaticVariable(new_space_allocation_top), ecx); |
| 1800 |
| 1801 // Allocated the JSObject, now initialize the fields and add the heap tag. |
| 1802 // ebx: initial map |
| 1803 // edx: JSObject |
| 1804 __ mov(Operand(edx, JSObject::kMapOffset), ebx); |
| 1805 __ mov(ebx, Factory::empty_fixed_array()); |
| 1806 __ mov(Operand(edx, JSObject::kPropertiesOffset), ebx); |
| 1807 __ mov(Operand(edx, JSObject::kElementsOffset), ebx); |
| 1808 __ or_(Operand(edx), Immediate(kHeapObjectTag)); |
| 1809 |
| 1810 // Push the allocated object to the stack. This is the object that will be |
| 1811 // returned. |
| 1812 __ push(edx); |
| 1813 |
| 1814 // eax: argc |
| 1815 // edx: JSObject |
| 1816 // Load the address of the first in-object property into edx. |
| 1817 __ lea(edx, Operand(edx, JSObject::kHeaderSize)); |
| 1818 __ xor_(Operand(edx), Immediate(kHeapObjectTag)); // Clear heap object tag. |
| 1819 // Calculate the location of the first argument. The stack contains the |
| 1820 // allocated object and the return address on top of the argc arguments. |
| 1821 __ lea(ecx, Operand(esp, eax, times_4, 1 * kPointerSize)); |
| 1822 |
| 1823 // Use edi for holding undefined which is used in several places below. |
| 1824 __ mov(edi, Factory::undefined_value()); |
| 1825 |
| 1826 // eax: argc |
| 1827 // ecx: first argument |
| 1828 // edx: first in-object property of the JSObject |
| 1829 // edi: undefined |
| 1830 // Fill the initialized properties with a constant value or a passed argument |
| 1831 // depending on the this.x = ...; assignment in the function. |
| 1832 for (int i = 0; i < shared->this_property_assignments_count(); i++) { |
| 1833 if (shared->IsThisPropertyAssignmentArgument(i)) { |
| 1834 Label not_passed; |
| 1835 // Set the property to undefined. |
| 1836 __ mov(Operand(edx, i * kPointerSize), edi); |
| 1837 // Check if the argument assigned to the property is actually passed. |
| 1838 int arg_number = shared->GetThisPropertyAssignmentArgument(i); |
| 1839 __ cmp(eax, arg_number); |
| 1840 __ j(below_equal, ¬_passed); |
| 1841 // Argument passed - find it on the stack. |
| 1842 __ mov(ebx, Operand(ecx, arg_number * -kPointerSize)); |
| 1843 __ mov(Operand(edx, i * kPointerSize), ebx); |
| 1844 __ bind(¬_passed); |
| 1845 } else { |
| 1846 // Set the property to the constant value. |
| 1847 Handle<Object> constant(shared->GetThisPropertyAssignmentConstant(i)); |
| 1848 __ mov(Operand(edx, i * kPointerSize), Immediate(constant)); |
| 1849 } |
| 1850 } |
| 1851 |
| 1852 // Fill the unused in-object property fields with undefined. |
| 1853 for (int i = shared->this_property_assignments_count(); |
| 1854 i < shared->CalculateInObjectProperties(); |
| 1855 i++) { |
| 1856 __ mov(Operand(edx, i * kPointerSize), edi); |
| 1857 } |
| 1858 |
| 1859 // Move argc to ebx and retreive the JSObject to return. |
| 1860 __ mov(ebx, eax); |
| 1861 __ pop(eax); |
| 1862 |
| 1863 // Remove caller arguments from the stack and return. |
| 1864 __ pop(ecx); |
| 1865 __ lea(esp, Operand(esp, ebx, times_4, 1 * kPointerSize)); // 1 ~ receiver |
| 1866 __ push(ecx); |
| 1867 __ IncrementCounter(&Counters::constructed_objects, 1); |
| 1868 __ IncrementCounter(&Counters::constructed_objects_stub, 1); |
| 1869 __ ret(0); |
| 1870 |
| 1871 // Jump to the generic stub in case the specialized code cannot handle the |
| 1872 // construction. |
| 1873 __ bind(&generic_stub_call); |
| 1874 Code* code = Builtins::builtin(Builtins::JSConstructStubGeneric); |
| 1875 Handle<Code> generic_construct_stub(code); |
| 1876 __ jmp(generic_construct_stub, RelocInfo::CODE_TARGET); |
| 1877 |
| 1878 // Return the generated code. |
| 1879 return GetCode(); |
| 1880 } |
| 1881 |
| 1882 |
1743 #undef __ | 1883 #undef __ |
1744 | 1884 |
1745 } } // namespace v8::internal | 1885 } } // namespace v8::internal |
OLD | NEW |