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_IA32 | 5 #if V8_TARGET_ARCH_IA32 |
6 | 6 |
7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
8 #include "src/codegen.h" | 8 #include "src/codegen.h" |
9 #include "src/deoptimizer.h" | 9 #include "src/deoptimizer.h" |
10 #include "src/full-codegen/full-codegen.h" | 10 #include "src/full-codegen/full-codegen.h" |
(...skipping 1781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1792 | 1792 |
1793 __ bind(&stack_overflow); | 1793 __ bind(&stack_overflow); |
1794 { | 1794 { |
1795 FrameScope frame(masm, StackFrame::MANUAL); | 1795 FrameScope frame(masm, StackFrame::MANUAL); |
1796 __ CallRuntime(Runtime::kThrowStackOverflow, 0); | 1796 __ CallRuntime(Runtime::kThrowStackOverflow, 0); |
1797 __ int3(); | 1797 __ int3(); |
1798 } | 1798 } |
1799 } | 1799 } |
1800 | 1800 |
1801 | 1801 |
| 1802 static void CompatibleReceiverCheck(MacroAssembler* masm, Register receiver, |
| 1803 Register function_template_info, |
| 1804 Register scratch0, Register scratch1, |
| 1805 Label* receiver_check_failed) { |
| 1806 // If receiver is not an object, jump to receiver_check_failed. |
| 1807 __ CmpObjectType(receiver, FIRST_JS_OBJECT_TYPE, scratch0); |
| 1808 __ j(below, receiver_check_failed); |
| 1809 |
| 1810 // If there is no signature, return the holder. |
| 1811 __ CompareRoot(FieldOperand(function_template_info, |
| 1812 FunctionTemplateInfo::kSignatureOffset), |
| 1813 Heap::kUndefinedValueRootIndex); |
| 1814 Label receiver_check_passed; |
| 1815 __ j(equal, &receiver_check_passed, Label::kNear); |
| 1816 |
| 1817 // Walk the prototype chain. |
| 1818 Label prototype_loop_start; |
| 1819 __ bind(&prototype_loop_start); |
| 1820 |
| 1821 // End if receiver is null or if it's a hidden prototype. |
| 1822 __ CompareRoot(receiver, Heap::kNullValueRootIndex); |
| 1823 __ j(equal, receiver_check_failed, Label::kNear); |
| 1824 __ mov(scratch0, FieldOperand(receiver, HeapObject::kMapOffset)); |
| 1825 __ test(FieldOperand(scratch0, Map::kBitField3Offset), |
| 1826 Immediate(Map::IsHiddenPrototype::kMask)); |
| 1827 __ j(not_zero, receiver_check_failed, Label::kNear); |
| 1828 |
| 1829 // Get the constructor, if any. |
| 1830 __ GetMapConstructor(scratch0, scratch0, scratch1); |
| 1831 __ CmpInstanceType(scratch1, JS_FUNCTION_TYPE); |
| 1832 Label next_prototype; |
| 1833 __ j(not_equal, &next_prototype, Label::kNear); |
| 1834 |
| 1835 // Get the constructor's signature. |
| 1836 __ mov(scratch0, |
| 1837 FieldOperand(scratch0, JSFunction::kSharedFunctionInfoOffset)); |
| 1838 __ mov(scratch0, |
| 1839 FieldOperand(scratch0, SharedFunctionInfo::kFunctionDataOffset)); |
| 1840 |
| 1841 // Loop through the chain of inheriting function templates. |
| 1842 Label function_template_loop; |
| 1843 __ bind(&function_template_loop); |
| 1844 |
| 1845 // If the signatures match, we have a compatible receiver. |
| 1846 __ cmp(scratch0, FieldOperand(function_template_info, |
| 1847 FunctionTemplateInfo::kSignatureOffset)); |
| 1848 __ j(equal, &receiver_check_passed, Label::kNear); |
| 1849 |
| 1850 // If the current type is not a FunctionTemplateInfo, load the next prototype |
| 1851 // in the chain. |
| 1852 __ JumpIfSmi(scratch0, &next_prototype, Label::kNear); |
| 1853 __ CmpObjectType(scratch0, FUNCTION_TEMPLATE_INFO_TYPE, scratch1); |
| 1854 __ j(not_equal, &next_prototype, Label::kNear); |
| 1855 |
| 1856 // Otherwise load the parent function template and iterate. |
| 1857 __ mov(scratch0, |
| 1858 FieldOperand(scratch0, FunctionTemplateInfo::kParentTemplateOffset)); |
| 1859 __ jmp(&function_template_loop, Label::kNear); |
| 1860 |
| 1861 // Load the next prototype and iterate. |
| 1862 __ bind(&next_prototype); |
| 1863 __ mov(receiver, FieldOperand(receiver, HeapObject::kMapOffset)); |
| 1864 __ mov(receiver, FieldOperand(receiver, Map::kPrototypeOffset)); |
| 1865 __ jmp(&prototype_loop_start, Label::kNear); |
| 1866 |
| 1867 __ bind(&receiver_check_passed); |
| 1868 } |
| 1869 |
| 1870 |
| 1871 void Builtins::Generate_HandleFastApiCall(MacroAssembler* masm) { |
| 1872 // ----------- S t a t e ------------- |
| 1873 // -- eax : number of arguments (not including the receiver) |
| 1874 // -- edi : callee |
| 1875 // -- esi : context |
| 1876 // -- esp[0] : return address |
| 1877 // -- esp[4] : last argument |
| 1878 // -- ... |
| 1879 // -- esp[eax * 4] : first argument |
| 1880 // -- esp[(eax + 1) * 4] : receiver |
| 1881 // ----------------------------------- |
| 1882 |
| 1883 // Load the receiver. |
| 1884 Operand receiver_operand(esp, eax, times_pointer_size, kPCOnStackSize); |
| 1885 __ mov(ecx, receiver_operand); |
| 1886 |
| 1887 // Update the receiver if this is a contextual call. |
| 1888 Label set_global_proxy, valid_receiver; |
| 1889 __ CompareRoot(ecx, Heap::kUndefinedValueRootIndex); |
| 1890 __ j(equal, &set_global_proxy); |
| 1891 __ bind(&valid_receiver); |
| 1892 |
| 1893 // Load the FunctionTemplateInfo. |
| 1894 __ mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 1895 __ mov(ebx, FieldOperand(ebx, SharedFunctionInfo::kFunctionDataOffset)); |
| 1896 |
| 1897 // Do the compatible receiver check. |
| 1898 Label receiver_check_failed; |
| 1899 __ Push(eax); |
| 1900 CompatibleReceiverCheck(masm, ecx, ebx, edx, eax, &receiver_check_failed); |
| 1901 __ Pop(eax); |
| 1902 // Get the callback offset from the FunctionTemplateInfo, and jump to the |
| 1903 // beginning of the code. |
| 1904 __ mov(edx, FieldOperand(ebx, FunctionTemplateInfo::kCallCodeOffset)); |
| 1905 __ mov(edx, FieldOperand(edx, CallHandlerInfo::kFastHandlerOffset)); |
| 1906 __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 1907 __ jmp(edx); |
| 1908 |
| 1909 __ bind(&set_global_proxy); |
| 1910 __ mov(ecx, GlobalObjectOperand()); |
| 1911 __ mov(ecx, FieldOperand(ecx, JSGlobalObject::kGlobalProxyOffset)); |
| 1912 __ mov(receiver_operand, ecx); |
| 1913 __ jmp(&valid_receiver, Label::kNear); |
| 1914 |
| 1915 // Compatible receiver check failed: pop return address, arguments and |
| 1916 // receiver and throw an Illegal Invocation exception. |
| 1917 __ bind(&receiver_check_failed); |
| 1918 __ Pop(eax); |
| 1919 __ PopReturnAddressTo(ebx); |
| 1920 __ lea(eax, Operand(eax, times_pointer_size, 1 * kPointerSize)); |
| 1921 __ add(esp, eax); |
| 1922 __ PushReturnAddressFrom(ebx); |
| 1923 { |
| 1924 FrameScope scope(masm, StackFrame::INTERNAL); |
| 1925 __ TailCallRuntime(Runtime::kThrowIllegalInvocation, 0, 1); |
| 1926 } |
| 1927 } |
| 1928 |
| 1929 |
1802 void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) { | 1930 void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) { |
1803 // Lookup the function in the JavaScript frame. | 1931 // Lookup the function in the JavaScript frame. |
1804 __ mov(eax, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 1932 __ mov(eax, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
1805 { | 1933 { |
1806 FrameScope scope(masm, StackFrame::INTERNAL); | 1934 FrameScope scope(masm, StackFrame::INTERNAL); |
1807 // Pass function as argument. | 1935 // Pass function as argument. |
1808 __ push(eax); | 1936 __ push(eax); |
1809 __ CallRuntime(Runtime::kCompileForOnStackReplacement, 1); | 1937 __ CallRuntime(Runtime::kCompileForOnStackReplacement, 1); |
1810 } | 1938 } |
1811 | 1939 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1852 | 1980 |
1853 __ bind(&ok); | 1981 __ bind(&ok); |
1854 __ ret(0); | 1982 __ ret(0); |
1855 } | 1983 } |
1856 | 1984 |
1857 #undef __ | 1985 #undef __ |
1858 } // namespace internal | 1986 } // namespace internal |
1859 } // namespace v8 | 1987 } // namespace v8 |
1860 | 1988 |
1861 #endif // V8_TARGET_ARCH_IA32 | 1989 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |