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

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

Issue 1895603002: [esnext] prototype runtime implementation for async functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@AsyncFunction
Patch Set: Partially fix `throw` completions (resumption works, but no resumption doesn't) Created 4 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
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 1756 matching lines...) Expand 10 before | Expand all | Expand 10 after
1767 context()->Plug(rax); 1767 context()->Plug(rax);
1768 break; 1768 break;
1769 case KEYED_PROPERTY: 1769 case KEYED_PROPERTY:
1770 EmitKeyedPropertyAssignment(expr); 1770 EmitKeyedPropertyAssignment(expr);
1771 break; 1771 break;
1772 } 1772 }
1773 } 1773 }
1774 1774
1775 1775
1776 void FullCodeGenerator::VisitYield(Yield* expr) { 1776 void FullCodeGenerator::VisitYield(Yield* expr) {
1777 Comment cmnt(masm_, "[ Yield"); 1777 Comment cmnt(masm_, expr->is_async_function_start() ? "[ AsyncFunction start"
1778 : "[ Yield");
1778 SetExpressionPosition(expr); 1779 SetExpressionPosition(expr);
1779 1780
1781 Label eval, suspend, continuation, post_runtime, resume, exception;
1782
1780 // Evaluate yielded value first; the initial iterator definition depends on 1783 // Evaluate yielded value first; the initial iterator definition depends on
1781 // this. It stays on the stack while we update the iterator. 1784 // this. It stays on the stack while we update the iterator.
1782 VisitForStackValue(expr->expression()); 1785 if (!expr->is_async_function_start()) {
1783 1786 VisitForStackValue(expr->expression());
1784 Label suspend, continuation, post_runtime, resume, exception; 1787 }
1785 1788
1786 __ jmp(&suspend); 1789 __ jmp(&suspend);
1787 __ bind(&continuation); 1790 __ bind(&continuation);
1788 // When we arrive here, rax holds the generator object. 1791 // When we arrive here, rax holds the generator object.
1789 __ RecordGeneratorContinuation(); 1792 __ RecordGeneratorContinuation();
1790 __ movp(rbx, FieldOperand(rax, JSGeneratorObject::kResumeModeOffset)); 1793 __ movp(rbx, FieldOperand(rax, JSGeneratorObject::kResumeModeOffset));
1791 __ movp(rax, FieldOperand(rax, JSGeneratorObject::kInputOffset)); 1794 __ movp(rax, FieldOperand(rax, JSGeneratorObject::kInputOffset));
1792 STATIC_ASSERT(JSGeneratorObject::kNext < JSGeneratorObject::kReturn); 1795 STATIC_ASSERT(JSGeneratorObject::kNext < JSGeneratorObject::kReturn);
1793 STATIC_ASSERT(JSGeneratorObject::kThrow > JSGeneratorObject::kReturn); 1796 STATIC_ASSERT(JSGeneratorObject::kThrow > JSGeneratorObject::kReturn);
1794 __ SmiCompare(rbx, Smi::FromInt(JSGeneratorObject::kReturn)); 1797 __ SmiCompare(rbx, Smi::FromInt(JSGeneratorObject::kReturn));
1795 __ j(less, &resume); 1798 __ j(less, &resume);
1796 __ Push(result_register()); 1799 __ Push(result_register());
1797 __ j(greater, &exception); 1800 __ j(greater, &exception);
1798 EmitCreateIteratorResult(true); 1801 if (!expr->is_async_function_start()) {
1799 EmitUnwindAndReturn(); 1802 EmitCreateIteratorResult(true);
1803 EmitUnwindAndReturn();
1804 } else {
1805 // AsyncFunction never resumed with `return` mode, should be unreachable.
1806 }
1800 1807
1801 __ bind(&exception); 1808 __ bind(&exception);
1802 __ CallRuntime(Runtime::kThrow); 1809 __ CallRuntime(Runtime::kThrow);
1803 1810
1804 __ bind(&suspend); 1811 __ bind(&suspend);
1805 OperandStackDepthIncrement(1); // Not popped on this path. 1812
1813 if (!expr->is_async_function_start()) {
1814 OperandStackDepthIncrement(1); // Not popped on this path.
1815 }
1806 VisitForAccumulatorValue(expr->generator_object()); 1816 VisitForAccumulatorValue(expr->generator_object());
1807 DCHECK(continuation.pos() > 0 && Smi::IsValid(continuation.pos())); 1817 DCHECK(continuation.pos() > 0 && Smi::IsValid(continuation.pos()));
1808 __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset), 1818 __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset),
1809 Smi::FromInt(continuation.pos())); 1819 Smi::FromInt(continuation.pos()));
1810 __ movp(FieldOperand(rax, JSGeneratorObject::kContextOffset), rsi); 1820 __ movp(FieldOperand(rax, JSGeneratorObject::kContextOffset), rsi);
1811 __ movp(rcx, rsi); 1821 __ movp(rcx, rsi);
1812 __ RecordWriteField(rax, JSGeneratorObject::kContextOffset, rcx, rdx, 1822 __ RecordWriteField(rax, JSGeneratorObject::kContextOffset, rcx, rdx,
1813 kDontSaveFPRegs); 1823 kDontSaveFPRegs);
1814 __ leap(rbx, Operand(rbp, StandardFrameConstants::kExpressionsOffset)); 1824 if (!expr->is_async_function_start()) {
1815 __ cmpp(rsp, rbx); 1825 // AsyncFunction start always occurs with an empty operand stack
1816 __ j(equal, &post_runtime); 1826 __ leap(rbx, Operand(rbp, StandardFrameConstants::kExpressionsOffset));
1817 __ Push(rax); // generator object 1827 __ cmpp(rsp, rbx);
1818 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); 1828 __ j(equal, &post_runtime);
1819 __ movp(context_register(), 1829 __ Push(rax); // generator object
1820 Operand(rbp, StandardFrameConstants::kContextOffset)); 1830 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1);
1821 __ bind(&post_runtime); 1831 __ movp(context_register(),
1832 Operand(rbp, StandardFrameConstants::kContextOffset));
1833 __ bind(&post_runtime);
1822 1834
1823 PopOperand(result_register()); 1835 PopOperand(result_register());
1824 EmitReturnSequence(); 1836 EmitReturnSequence();
1837 } else {
1838 VisitForAccumulatorValue(expr->expression());
1839 DCHECK_EQ(result_register().code(), rax.code());
caitp (gmail) 2016/04/16 18:33:03 Not sure if this really adds anything, I guess it'
1840 EmitReturnSequence();
1841 }
1825 1842
1826 __ bind(&resume); 1843 __ bind(&resume);
1827 context()->Plug(result_register()); 1844 context()->Plug(result_register());
1828 } 1845 }
1829 1846
1830 void FullCodeGenerator::PushOperand(MemOperand operand) { 1847 void FullCodeGenerator::PushOperand(MemOperand operand) {
1831 OperandStackDepthIncrement(1); 1848 OperandStackDepthIncrement(1);
1832 __ Push(operand); 1849 __ Push(operand);
1833 } 1850 }
1834 1851
(...skipping 2045 matching lines...) Expand 10 before | Expand all | Expand 10 after
3880 DCHECK_EQ( 3897 DCHECK_EQ(
3881 isolate->builtins()->OnStackReplacement()->entry(), 3898 isolate->builtins()->OnStackReplacement()->entry(),
3882 Assembler::target_address_at(call_target_address, unoptimized_code)); 3899 Assembler::target_address_at(call_target_address, unoptimized_code));
3883 return ON_STACK_REPLACEMENT; 3900 return ON_STACK_REPLACEMENT;
3884 } 3901 }
3885 3902
3886 } // namespace internal 3903 } // namespace internal
3887 } // namespace v8 3904 } // namespace v8
3888 3905
3889 #endif // V8_TARGET_ARCH_X64 3906 #endif // V8_TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698