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_X64 | 5 #if V8_TARGET_ARCH_X64 |
6 | 6 |
7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 1842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1853 case Yield::kSuspend: | 1853 case Yield::kSuspend: |
1854 // Pop value from top-of-stack slot; box result into result register. | 1854 // Pop value from top-of-stack slot; box result into result register. |
1855 EmitCreateIteratorResult(false); | 1855 EmitCreateIteratorResult(false); |
1856 __ Push(result_register()); | 1856 __ Push(result_register()); |
1857 // Fall through. | 1857 // Fall through. |
1858 case Yield::kInitial: { | 1858 case Yield::kInitial: { |
1859 Label suspend, continuation, post_runtime, resume; | 1859 Label suspend, continuation, post_runtime, resume; |
1860 | 1860 |
1861 __ jmp(&suspend); | 1861 __ jmp(&suspend); |
1862 __ bind(&continuation); | 1862 __ bind(&continuation); |
| 1863 // When we arrive here, the stack top is the resume mode and |
| 1864 // result_register() holds the input value (the argument given to the |
| 1865 // respective resume operation). |
1863 __ RecordGeneratorContinuation(); | 1866 __ RecordGeneratorContinuation(); |
1864 __ jmp(&resume); | 1867 __ Pop(rbx); |
| 1868 __ SmiCompare(rbx, Smi::FromInt(JSGeneratorObject::RETURN)); |
| 1869 __ j(not_equal, &resume); |
| 1870 __ Push(result_register()); |
| 1871 EmitCreateIteratorResult(true); |
| 1872 EmitUnwindBeforeReturn(); |
| 1873 EmitReturnSequence(); |
1865 | 1874 |
1866 __ bind(&suspend); | 1875 __ bind(&suspend); |
1867 VisitForAccumulatorValue(expr->generator_object()); | 1876 VisitForAccumulatorValue(expr->generator_object()); |
1868 DCHECK(continuation.pos() > 0 && Smi::IsValid(continuation.pos())); | 1877 DCHECK(continuation.pos() > 0 && Smi::IsValid(continuation.pos())); |
1869 __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset), | 1878 __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset), |
1870 Smi::FromInt(continuation.pos())); | 1879 Smi::FromInt(continuation.pos())); |
1871 __ movp(FieldOperand(rax, JSGeneratorObject::kContextOffset), rsi); | 1880 __ movp(FieldOperand(rax, JSGeneratorObject::kContextOffset), rsi); |
1872 __ movp(rcx, rsi); | 1881 __ movp(rcx, rsi); |
1873 __ RecordWriteField(rax, JSGeneratorObject::kContextOffset, rcx, rdx, | 1882 __ RecordWriteField(rax, JSGeneratorObject::kContextOffset, rcx, rdx, |
1874 kDontSaveFPRegs); | 1883 kDontSaveFPRegs); |
1875 __ leap(rbx, Operand(rbp, StandardFrameConstants::kExpressionsOffset)); | 1884 __ leap(rbx, Operand(rbp, StandardFrameConstants::kExpressionsOffset)); |
1876 __ cmpp(rsp, rbx); | 1885 __ cmpp(rsp, rbx); |
1877 __ j(equal, &post_runtime); | 1886 __ j(equal, &post_runtime); |
1878 __ Push(rax); // generator object | 1887 __ Push(rax); // generator object |
1879 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); | 1888 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
1880 __ movp(context_register(), | 1889 __ movp(context_register(), |
1881 Operand(rbp, StandardFrameConstants::kContextOffset)); | 1890 Operand(rbp, StandardFrameConstants::kContextOffset)); |
1882 __ bind(&post_runtime); | 1891 __ bind(&post_runtime); |
1883 | 1892 |
1884 __ Pop(result_register()); | 1893 __ Pop(result_register()); |
1885 EmitReturnSequence(); | 1894 EmitReturnSequence(); |
1886 | 1895 |
1887 __ bind(&resume); | 1896 __ bind(&resume); |
1888 context()->Plug(result_register()); | 1897 context()->Plug(result_register()); |
1889 break; | 1898 break; |
1890 } | 1899 } |
1891 | 1900 |
1892 case Yield::kFinal: { | 1901 case Yield::kFinal: { |
1893 VisitForAccumulatorValue(expr->generator_object()); | 1902 VisitForAccumulatorValue(expr->generator_object()); |
1894 __ Move(FieldOperand(result_register(), | |
1895 JSGeneratorObject::kContinuationOffset), | |
1896 Smi::FromInt(JSGeneratorObject::kGeneratorClosed)); | |
1897 // Pop value from top-of-stack slot, box result into result register. | 1903 // Pop value from top-of-stack slot, box result into result register. |
1898 EmitCreateIteratorResult(true); | 1904 EmitCreateIteratorResult(true); |
1899 EmitUnwindBeforeReturn(); | 1905 EmitUnwindBeforeReturn(); |
1900 EmitReturnSequence(); | 1906 EmitReturnSequence(); |
1901 break; | 1907 break; |
1902 } | 1908 } |
1903 | 1909 |
1904 case Yield::kDelegating: { | 1910 case Yield::kDelegating: { |
1905 VisitForStackValue(expr->generator_object()); | 1911 VisitForStackValue(expr->generator_object()); |
1906 | 1912 |
(...skipping 24 matching lines...) Expand all Loading... |
1931 __ bind(&l_try); | 1937 __ bind(&l_try); |
1932 __ Pop(rax); // result | 1938 __ Pop(rax); // result |
1933 int handler_index = NewHandlerTableEntry(); | 1939 int handler_index = NewHandlerTableEntry(); |
1934 EnterTryBlock(handler_index, &l_catch); | 1940 EnterTryBlock(handler_index, &l_catch); |
1935 const int try_block_size = TryCatch::kElementCount * kPointerSize; | 1941 const int try_block_size = TryCatch::kElementCount * kPointerSize; |
1936 __ Push(rax); // result | 1942 __ Push(rax); // result |
1937 | 1943 |
1938 __ jmp(&l_suspend); | 1944 __ jmp(&l_suspend); |
1939 __ bind(&l_continuation); | 1945 __ bind(&l_continuation); |
1940 __ RecordGeneratorContinuation(); | 1946 __ RecordGeneratorContinuation(); |
| 1947 __ Pop(rbx); |
| 1948 // TODO(neis): Ignoring the resume mode here is clearly wrong. Currently, |
| 1949 // return is not supported for yield*. The planned desugaring of yield* |
| 1950 // using do-expressions will naturally solve this. |
1941 __ jmp(&l_resume); | 1951 __ jmp(&l_resume); |
1942 | 1952 |
1943 __ bind(&l_suspend); | 1953 __ bind(&l_suspend); |
1944 const int generator_object_depth = kPointerSize + try_block_size; | 1954 const int generator_object_depth = kPointerSize + try_block_size; |
1945 __ movp(rax, Operand(rsp, generator_object_depth)); | 1955 __ movp(rax, Operand(rsp, generator_object_depth)); |
1946 __ Push(rax); // g | 1956 __ Push(rax); // g |
1947 __ Push(Smi::FromInt(handler_index)); // handler-index | 1957 __ Push(Smi::FromInt(handler_index)); // handler-index |
1948 DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos())); | 1958 DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos())); |
1949 __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset), | 1959 __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset), |
1950 Smi::FromInt(l_continuation.pos())); | 1960 Smi::FromInt(l_continuation.pos())); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2006 __ Move(LoadDescriptor::SlotRegister(), | 2016 __ Move(LoadDescriptor::SlotRegister(), |
2007 SmiFromSlot(expr->ValueFeedbackSlot())); | 2017 SmiFromSlot(expr->ValueFeedbackSlot())); |
2008 CallLoadIC(NOT_INSIDE_TYPEOF); // result.value in rax | 2018 CallLoadIC(NOT_INSIDE_TYPEOF); // result.value in rax |
2009 context()->DropAndPlug(2, rax); // drop iter and g | 2019 context()->DropAndPlug(2, rax); // drop iter and g |
2010 break; | 2020 break; |
2011 } | 2021 } |
2012 } | 2022 } |
2013 } | 2023 } |
2014 | 2024 |
2015 | 2025 |
2016 void FullCodeGenerator::EmitGeneratorResume(Expression *generator, | 2026 void FullCodeGenerator::EmitGeneratorResume( |
2017 Expression *value, | 2027 Expression* generator, Expression* value, |
2018 JSGeneratorObject::ResumeMode resume_mode) { | 2028 JSGeneratorObject::ResumeMode resume_mode) { |
2019 // The value stays in rax, and is ultimately read by the resumed generator, as | 2029 // The value stays in rax, and is ultimately read by the resumed generator, as |
2020 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it | 2030 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it |
2021 // is read to throw the value when the resumed generator is already closed. | 2031 // is read to throw the value when the resumed generator is already closed. |
2022 // rbx will hold the generator object until the activation has been resumed. | 2032 // rbx will hold the generator object until the activation has been resumed. |
2023 VisitForStackValue(generator); | 2033 VisitForStackValue(generator); |
2024 VisitForAccumulatorValue(value); | 2034 VisitForAccumulatorValue(value); |
2025 __ Pop(rbx); | 2035 __ Pop(rbx); |
2026 | 2036 |
2027 // Load suspended function and context. | 2037 // Load suspended function and context. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2065 if (resume_mode == JSGeneratorObject::NEXT) { | 2075 if (resume_mode == JSGeneratorObject::NEXT) { |
2066 Label slow_resume; | 2076 Label slow_resume; |
2067 __ cmpp(rdx, Immediate(0)); | 2077 __ cmpp(rdx, Immediate(0)); |
2068 __ j(not_zero, &slow_resume); | 2078 __ j(not_zero, &slow_resume); |
2069 __ movp(rdx, FieldOperand(rdi, JSFunction::kCodeEntryOffset)); | 2079 __ movp(rdx, FieldOperand(rdi, JSFunction::kCodeEntryOffset)); |
2070 __ SmiToInteger64(rcx, | 2080 __ SmiToInteger64(rcx, |
2071 FieldOperand(rbx, JSGeneratorObject::kContinuationOffset)); | 2081 FieldOperand(rbx, JSGeneratorObject::kContinuationOffset)); |
2072 __ addp(rdx, rcx); | 2082 __ addp(rdx, rcx); |
2073 __ Move(FieldOperand(rbx, JSGeneratorObject::kContinuationOffset), | 2083 __ Move(FieldOperand(rbx, JSGeneratorObject::kContinuationOffset), |
2074 Smi::FromInt(JSGeneratorObject::kGeneratorExecuting)); | 2084 Smi::FromInt(JSGeneratorObject::kGeneratorExecuting)); |
| 2085 __ Push(Smi::FromInt(resume_mode)); // Consumed in continuation. |
2075 __ jmp(rdx); | 2086 __ jmp(rdx); |
2076 __ bind(&slow_resume); | 2087 __ bind(&slow_resume); |
2077 } | 2088 } |
2078 | 2089 |
2079 // Otherwise, we push holes for the operand stack and call the runtime to fix | 2090 // Otherwise, we push holes for the operand stack and call the runtime to fix |
2080 // up the stack and the handlers. | 2091 // up the stack and the handlers. |
2081 Label push_operand_holes, call_resume; | 2092 Label push_operand_holes, call_resume; |
2082 __ bind(&push_operand_holes); | 2093 __ bind(&push_operand_holes); |
2083 __ subp(rdx, Immediate(1)); | 2094 __ subp(rdx, Immediate(1)); |
2084 __ j(carry, &call_resume); | 2095 __ j(carry, &call_resume); |
2085 __ Push(rcx); | 2096 __ Push(rcx); |
2086 __ jmp(&push_operand_holes); | 2097 __ jmp(&push_operand_holes); |
2087 __ bind(&call_resume); | 2098 __ bind(&call_resume); |
| 2099 __ Push(Smi::FromInt(resume_mode)); // Consumed in continuation. |
2088 __ Push(rbx); | 2100 __ Push(rbx); |
2089 __ Push(result_register()); | 2101 __ Push(result_register()); |
2090 __ Push(Smi::FromInt(resume_mode)); | 2102 __ Push(Smi::FromInt(resume_mode)); |
2091 __ CallRuntime(Runtime::kResumeJSGeneratorObject); | 2103 __ CallRuntime(Runtime::kResumeJSGeneratorObject); |
2092 // Not reached: the runtime call returns elsewhere. | 2104 // Not reached: the runtime call returns elsewhere. |
2093 __ Abort(kGeneratorFailedToResume); | 2105 __ Abort(kGeneratorFailedToResume); |
2094 | 2106 |
2095 __ bind(&done); | 2107 __ bind(&done); |
2096 context()->Plug(result_register()); | 2108 context()->Plug(result_register()); |
2097 } | 2109 } |
(...skipping 2621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4719 Assembler::target_address_at(call_target_address, | 4731 Assembler::target_address_at(call_target_address, |
4720 unoptimized_code)); | 4732 unoptimized_code)); |
4721 return OSR_AFTER_STACK_CHECK; | 4733 return OSR_AFTER_STACK_CHECK; |
4722 } | 4734 } |
4723 | 4735 |
4724 | 4736 |
4725 } // namespace internal | 4737 } // namespace internal |
4726 } // namespace v8 | 4738 } // namespace v8 |
4727 | 4739 |
4728 #endif // V8_TARGET_ARCH_X64 | 4740 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |