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

Side by Side Diff: src/full-codegen/x64/full-codegen-x64.cc

Issue 1606273002: Implement [Generator].prototype.return. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix bug in old code; add more tests Created 4 years, 11 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
OLDNEW
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 1853 matching lines...) Expand 10 before | Expand all | Expand 10 after
1864 case Yield::kSuspend: 1864 case Yield::kSuspend:
1865 // Pop value from top-of-stack slot; box result into result register. 1865 // Pop value from top-of-stack slot; box result into result register.
1866 EmitCreateIteratorResult(false); 1866 EmitCreateIteratorResult(false);
1867 __ Push(result_register()); 1867 __ Push(result_register());
1868 // Fall through. 1868 // Fall through.
1869 case Yield::kInitial: { 1869 case Yield::kInitial: {
1870 Label suspend, continuation, post_runtime, resume; 1870 Label suspend, continuation, post_runtime, resume;
1871 1871
1872 __ jmp(&suspend); 1872 __ jmp(&suspend);
1873 __ bind(&continuation); 1873 __ bind(&continuation);
1874 // When we arrive here, the stack top is the resume mode and
1875 // result_register() holds the input value (the argument given to the
1876 // respective resume operation).
1874 __ RecordGeneratorContinuation(); 1877 __ RecordGeneratorContinuation();
1875 __ jmp(&resume); 1878 __ Pop(rbx);
1879 __ SmiCompare(rbx, Smi::FromInt(JSGeneratorObject::RETURN));
1880 __ j(not_equal, &resume);
1881 __ Push(result_register());
1882 EmitCreateIteratorResult(true);
1883 EmitUnwindBeforeReturn();
1884 EmitReturnSequence();
1876 1885
1877 __ bind(&suspend); 1886 __ bind(&suspend);
1878 VisitForAccumulatorValue(expr->generator_object()); 1887 VisitForAccumulatorValue(expr->generator_object());
1879 DCHECK(continuation.pos() > 0 && Smi::IsValid(continuation.pos())); 1888 DCHECK(continuation.pos() > 0 && Smi::IsValid(continuation.pos()));
1880 __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset), 1889 __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset),
1881 Smi::FromInt(continuation.pos())); 1890 Smi::FromInt(continuation.pos()));
1882 __ movp(FieldOperand(rax, JSGeneratorObject::kContextOffset), rsi); 1891 __ movp(FieldOperand(rax, JSGeneratorObject::kContextOffset), rsi);
1883 __ movp(rcx, rsi); 1892 __ movp(rcx, rsi);
1884 __ RecordWriteField(rax, JSGeneratorObject::kContextOffset, rcx, rdx, 1893 __ RecordWriteField(rax, JSGeneratorObject::kContextOffset, rcx, rdx,
1885 kDontSaveFPRegs); 1894 kDontSaveFPRegs);
1886 __ leap(rbx, Operand(rbp, StandardFrameConstants::kExpressionsOffset)); 1895 __ leap(rbx, Operand(rbp, StandardFrameConstants::kExpressionsOffset));
1887 __ cmpp(rsp, rbx); 1896 __ cmpp(rsp, rbx);
1888 __ j(equal, &post_runtime); 1897 __ j(equal, &post_runtime);
1889 __ Push(rax); // generator object 1898 __ Push(rax); // generator object
1890 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); 1899 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1);
1891 __ movp(context_register(), 1900 __ movp(context_register(),
1892 Operand(rbp, StandardFrameConstants::kContextOffset)); 1901 Operand(rbp, StandardFrameConstants::kContextOffset));
1893 __ bind(&post_runtime); 1902 __ bind(&post_runtime);
1894 1903
1895 __ Pop(result_register()); 1904 __ Pop(result_register());
1896 EmitReturnSequence(); 1905 EmitReturnSequence();
1897 1906
1898 __ bind(&resume); 1907 __ bind(&resume);
1899 context()->Plug(result_register()); 1908 context()->Plug(result_register());
1900 break; 1909 break;
1901 } 1910 }
1902 1911
1903 case Yield::kFinal: { 1912 case Yield::kFinal: {
1904 VisitForAccumulatorValue(expr->generator_object()); 1913 VisitForAccumulatorValue(expr->generator_object());
1905 __ Move(FieldOperand(result_register(),
1906 JSGeneratorObject::kContinuationOffset),
1907 Smi::FromInt(JSGeneratorObject::kGeneratorClosed));
1908 // Pop value from top-of-stack slot, box result into result register. 1914 // Pop value from top-of-stack slot, box result into result register.
1909 EmitCreateIteratorResult(true); 1915 EmitCreateIteratorResult(true);
1910 EmitUnwindBeforeReturn(); 1916 EmitUnwindBeforeReturn();
1911 EmitReturnSequence(); 1917 EmitReturnSequence();
1912 break; 1918 break;
1913 } 1919 }
1914 1920
1915 case Yield::kDelegating: { 1921 case Yield::kDelegating: {
1916 VisitForStackValue(expr->generator_object()); 1922 VisitForStackValue(expr->generator_object());
1917 1923
(...skipping 24 matching lines...) Expand all
1942 __ bind(&l_try); 1948 __ bind(&l_try);
1943 __ Pop(rax); // result 1949 __ Pop(rax); // result
1944 int handler_index = NewHandlerTableEntry(); 1950 int handler_index = NewHandlerTableEntry();
1945 EnterTryBlock(handler_index, &l_catch); 1951 EnterTryBlock(handler_index, &l_catch);
1946 const int try_block_size = TryCatch::kElementCount * kPointerSize; 1952 const int try_block_size = TryCatch::kElementCount * kPointerSize;
1947 __ Push(rax); // result 1953 __ Push(rax); // result
1948 1954
1949 __ jmp(&l_suspend); 1955 __ jmp(&l_suspend);
1950 __ bind(&l_continuation); 1956 __ bind(&l_continuation);
1951 __ RecordGeneratorContinuation(); 1957 __ RecordGeneratorContinuation();
1958 __ Pop(rbx);
1959 // Ignoring the resume mode here is clearly wrong. Currently, return is
Jarin 2016/01/22 13:42:48 TODO(neis), perhaps?
1960 // not supported for yield*. The planned desugaring of yield* using
1961 // do-expressions will naturally solve this.
1952 __ jmp(&l_resume); 1962 __ jmp(&l_resume);
1953 1963
1954 __ bind(&l_suspend); 1964 __ bind(&l_suspend);
1955 const int generator_object_depth = kPointerSize + try_block_size; 1965 const int generator_object_depth = kPointerSize + try_block_size;
1956 __ movp(rax, Operand(rsp, generator_object_depth)); 1966 __ movp(rax, Operand(rsp, generator_object_depth));
1957 __ Push(rax); // g 1967 __ Push(rax); // g
1958 __ Push(Smi::FromInt(handler_index)); // handler-index 1968 __ Push(Smi::FromInt(handler_index)); // handler-index
1959 DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos())); 1969 DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos()));
1960 __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset), 1970 __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset),
1961 Smi::FromInt(l_continuation.pos())); 1971 Smi::FromInt(l_continuation.pos()));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2017 __ Move(LoadDescriptor::SlotRegister(), 2027 __ Move(LoadDescriptor::SlotRegister(),
2018 SmiFromSlot(expr->ValueFeedbackSlot())); 2028 SmiFromSlot(expr->ValueFeedbackSlot()));
2019 CallLoadIC(NOT_INSIDE_TYPEOF); // result.value in rax 2029 CallLoadIC(NOT_INSIDE_TYPEOF); // result.value in rax
2020 context()->DropAndPlug(2, rax); // drop iter and g 2030 context()->DropAndPlug(2, rax); // drop iter and g
2021 break; 2031 break;
2022 } 2032 }
2023 } 2033 }
2024 } 2034 }
2025 2035
2026 2036
2027 void FullCodeGenerator::EmitGeneratorResume(Expression *generator, 2037 void FullCodeGenerator::EmitGeneratorResume(
2028 Expression *value, 2038 Expression* generator, Expression* value,
2029 JSGeneratorObject::ResumeMode resume_mode) { 2039 JSGeneratorObject::ResumeMode resume_mode) {
2030 // The value stays in rax, and is ultimately read by the resumed generator, as 2040 // The value stays in rax, and is ultimately read by the resumed generator, as
2031 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it 2041 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it
2032 // is read to throw the value when the resumed generator is already closed. 2042 // is read to throw the value when the resumed generator is already closed.
2033 // rbx will hold the generator object until the activation has been resumed. 2043 // rbx will hold the generator object until the activation has been resumed.
2034 VisitForStackValue(generator); 2044 VisitForStackValue(generator);
2035 VisitForAccumulatorValue(value); 2045 VisitForAccumulatorValue(value);
2036 __ Pop(rbx); 2046 __ Pop(rbx);
2037 2047
2038 // Load suspended function and context. 2048 // Load suspended function and context.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2076 if (resume_mode == JSGeneratorObject::NEXT) { 2086 if (resume_mode == JSGeneratorObject::NEXT) {
2077 Label slow_resume; 2087 Label slow_resume;
2078 __ cmpp(rdx, Immediate(0)); 2088 __ cmpp(rdx, Immediate(0));
2079 __ j(not_zero, &slow_resume); 2089 __ j(not_zero, &slow_resume);
2080 __ movp(rdx, FieldOperand(rdi, JSFunction::kCodeEntryOffset)); 2090 __ movp(rdx, FieldOperand(rdi, JSFunction::kCodeEntryOffset));
2081 __ SmiToInteger64(rcx, 2091 __ SmiToInteger64(rcx,
2082 FieldOperand(rbx, JSGeneratorObject::kContinuationOffset)); 2092 FieldOperand(rbx, JSGeneratorObject::kContinuationOffset));
2083 __ addp(rdx, rcx); 2093 __ addp(rdx, rcx);
2084 __ Move(FieldOperand(rbx, JSGeneratorObject::kContinuationOffset), 2094 __ Move(FieldOperand(rbx, JSGeneratorObject::kContinuationOffset),
2085 Smi::FromInt(JSGeneratorObject::kGeneratorExecuting)); 2095 Smi::FromInt(JSGeneratorObject::kGeneratorExecuting));
2096 __ Push(Smi::FromInt(resume_mode)); // Consumed in continuation.
2086 __ jmp(rdx); 2097 __ jmp(rdx);
2087 __ bind(&slow_resume); 2098 __ bind(&slow_resume);
2088 } 2099 }
2089 2100
2090 // Otherwise, we push holes for the operand stack and call the runtime to fix 2101 // Otherwise, we push holes for the operand stack and call the runtime to fix
2091 // up the stack and the handlers. 2102 // up the stack and the handlers.
2092 Label push_operand_holes, call_resume; 2103 Label push_operand_holes, call_resume;
2093 __ bind(&push_operand_holes); 2104 __ bind(&push_operand_holes);
2094 __ subp(rdx, Immediate(1)); 2105 __ subp(rdx, Immediate(1));
2095 __ j(carry, &call_resume); 2106 __ j(carry, &call_resume);
2096 __ Push(rcx); 2107 __ Push(rcx);
2097 __ jmp(&push_operand_holes); 2108 __ jmp(&push_operand_holes);
2098 __ bind(&call_resume); 2109 __ bind(&call_resume);
2110 __ Push(Smi::FromInt(resume_mode)); // Consumed in continuation.
2099 __ Push(rbx); 2111 __ Push(rbx);
2100 __ Push(result_register()); 2112 __ Push(result_register());
2101 __ Push(Smi::FromInt(resume_mode)); 2113 __ Push(Smi::FromInt(resume_mode));
2102 __ CallRuntime(Runtime::kResumeJSGeneratorObject); 2114 __ CallRuntime(Runtime::kResumeJSGeneratorObject);
2103 // Not reached: the runtime call returns elsewhere. 2115 // Not reached: the runtime call returns elsewhere.
2104 __ Abort(kGeneratorFailedToResume); 2116 __ Abort(kGeneratorFailedToResume);
2105 2117
2106 __ bind(&done); 2118 __ bind(&done);
2107 context()->Plug(result_register()); 2119 context()->Plug(result_register());
2108 } 2120 }
(...skipping 2642 matching lines...) Expand 10 before | Expand all | Expand 10 after
4751 Assembler::target_address_at(call_target_address, 4763 Assembler::target_address_at(call_target_address,
4752 unoptimized_code)); 4764 unoptimized_code));
4753 return OSR_AFTER_STACK_CHECK; 4765 return OSR_AFTER_STACK_CHECK;
4754 } 4766 }
4755 4767
4756 4768
4757 } // namespace internal 4769 } // namespace internal
4758 } // namespace v8 4770 } // namespace v8
4759 4771
4760 #endif // V8_TARGET_ARCH_X64 4772 #endif // V8_TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698