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 1889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1900 } | 1900 } |
1901 | 1901 |
1902 case Yield::kFinal: { | 1902 case Yield::kFinal: { |
1903 // 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. |
1904 EmitCreateIteratorResult(true); | 1904 EmitCreateIteratorResult(true); |
1905 EmitUnwindBeforeReturn(); | 1905 EmitUnwindBeforeReturn(); |
1906 EmitReturnSequence(); | 1906 EmitReturnSequence(); |
1907 break; | 1907 break; |
1908 } | 1908 } |
1909 | 1909 |
1910 case Yield::kDelegating: { | 1910 case Yield::kDelegating: |
1911 VisitForStackValue(expr->generator_object()); | 1911 UNREACHABLE(); |
1912 | |
1913 // Initial stack layout is as follows: | |
1914 // [sp + 1 * kPointerSize] iter | |
1915 // [sp + 0 * kPointerSize] g | |
1916 | |
1917 Label l_catch, l_try, l_suspend, l_continuation, l_resume; | |
1918 Label l_next, l_call, l_loop; | |
1919 Register load_receiver = LoadDescriptor::ReceiverRegister(); | |
1920 Register load_name = LoadDescriptor::NameRegister(); | |
1921 | |
1922 // Initial send value is undefined. | |
1923 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); | |
1924 __ jmp(&l_next); | |
1925 | |
1926 // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; } | |
1927 __ bind(&l_catch); | |
1928 __ LoadRoot(load_name, Heap::kthrow_stringRootIndex); // "throw" | |
1929 __ Push(load_name); | |
1930 __ Push(Operand(rsp, 2 * kPointerSize)); // iter | |
1931 __ Push(rax); // exception | |
1932 __ jmp(&l_call); | |
1933 | |
1934 // try { received = %yield result } | |
1935 // Shuffle the received result above a try handler and yield it without | |
1936 // re-boxing. | |
1937 __ bind(&l_try); | |
1938 __ Pop(rax); // result | |
1939 int handler_index = NewHandlerTableEntry(); | |
1940 EnterTryBlock(handler_index, &l_catch); | |
1941 const int try_block_size = TryCatch::kElementCount * kPointerSize; | |
1942 __ Push(rax); // result | |
1943 | |
1944 __ jmp(&l_suspend); | |
1945 __ bind(&l_continuation); | |
1946 __ RecordGeneratorContinuation(); | |
1947 __ jmp(&l_resume); | |
1948 | |
1949 __ bind(&l_suspend); | |
1950 const int generator_object_depth = kPointerSize + try_block_size; | |
1951 __ movp(rax, Operand(rsp, generator_object_depth)); | |
1952 __ Push(rax); // g | |
1953 __ Push(Smi::FromInt(handler_index)); // handler-index | |
1954 DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos())); | |
1955 __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset), | |
1956 Smi::FromInt(l_continuation.pos())); | |
1957 __ movp(FieldOperand(rax, JSGeneratorObject::kContextOffset), rsi); | |
1958 __ movp(rcx, rsi); | |
1959 __ RecordWriteField(rax, JSGeneratorObject::kContextOffset, rcx, rdx, | |
1960 kDontSaveFPRegs); | |
1961 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 2); | |
1962 __ movp(context_register(), | |
1963 Operand(rbp, StandardFrameConstants::kContextOffset)); | |
1964 __ Pop(rax); // result | |
1965 EmitReturnSequence(); | |
1966 __ bind(&l_resume); // received in rax | |
1967 ExitTryBlock(handler_index); | |
1968 | |
1969 // receiver = iter; f = 'next'; arg = received; | |
1970 __ bind(&l_next); | |
1971 | |
1972 __ LoadRoot(load_name, Heap::knext_stringRootIndex); | |
1973 __ Push(load_name); // "next" | |
1974 __ Push(Operand(rsp, 2 * kPointerSize)); // iter | |
1975 __ Push(rax); // received | |
1976 | |
1977 // result = receiver[f](arg); | |
1978 __ bind(&l_call); | |
1979 __ movp(load_receiver, Operand(rsp, kPointerSize)); | |
1980 __ Move(LoadDescriptor::SlotRegister(), | |
1981 SmiFromSlot(expr->KeyedLoadFeedbackSlot())); | |
1982 Handle<Code> ic = CodeFactory::KeyedLoadIC(isolate(), SLOPPY).code(); | |
1983 CallIC(ic, TypeFeedbackId::None()); | |
1984 __ movp(rdi, rax); | |
1985 __ movp(Operand(rsp, 2 * kPointerSize), rdi); | |
1986 | |
1987 SetCallPosition(expr); | |
1988 __ Set(rax, 1); | |
1989 __ Call( | |
1990 isolate()->builtins()->Call(ConvertReceiverMode::kNotNullOrUndefined), | |
1991 RelocInfo::CODE_TARGET); | |
1992 | |
1993 __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | |
1994 __ Drop(1); // The function is still on the stack; drop it. | |
1995 | |
1996 // if (!result.done) goto l_try; | |
1997 __ bind(&l_loop); | |
1998 __ Move(load_receiver, rax); | |
1999 __ Push(load_receiver); // save result | |
2000 __ LoadRoot(load_name, Heap::kdone_stringRootIndex); // "done" | |
2001 __ Move(LoadDescriptor::SlotRegister(), | |
2002 SmiFromSlot(expr->DoneFeedbackSlot())); | |
2003 CallLoadIC(NOT_INSIDE_TYPEOF); // rax=result.done | |
2004 Handle<Code> bool_ic = ToBooleanStub::GetUninitialized(isolate()); | |
2005 CallIC(bool_ic); | |
2006 __ CompareRoot(result_register(), Heap::kTrueValueRootIndex); | |
2007 __ j(not_equal, &l_try); | |
2008 | |
2009 // result.value | |
2010 __ Pop(load_receiver); // result | |
2011 __ LoadRoot(load_name, Heap::kvalue_stringRootIndex); // "value" | |
2012 __ Move(LoadDescriptor::SlotRegister(), | |
2013 SmiFromSlot(expr->ValueFeedbackSlot())); | |
2014 CallLoadIC(NOT_INSIDE_TYPEOF); // result.value in rax | |
2015 context()->DropAndPlug(2, rax); // drop iter and g | |
2016 break; | |
2017 } | |
2018 } | 1912 } |
2019 } | 1913 } |
2020 | 1914 |
2021 | 1915 |
2022 void FullCodeGenerator::EmitGeneratorResume( | 1916 void FullCodeGenerator::EmitGeneratorResume( |
2023 Expression* generator, Expression* value, | 1917 Expression* generator, Expression* value, |
2024 JSGeneratorObject::ResumeMode resume_mode) { | 1918 JSGeneratorObject::ResumeMode resume_mode) { |
2025 // The value stays in rax, and is ultimately read by the resumed generator, as | 1919 // The value stays in rax, and is ultimately read by the resumed generator, as |
2026 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it | 1920 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it |
2027 // is read to throw the value when the resumed generator is already closed. | 1921 // is read to throw the value when the resumed generator is already closed. |
(...skipping 2708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4736 Assembler::target_address_at(call_target_address, | 4630 Assembler::target_address_at(call_target_address, |
4737 unoptimized_code)); | 4631 unoptimized_code)); |
4738 return OSR_AFTER_STACK_CHECK; | 4632 return OSR_AFTER_STACK_CHECK; |
4739 } | 4633 } |
4740 | 4634 |
4741 | 4635 |
4742 } // namespace internal | 4636 } // namespace internal |
4743 } // namespace v8 | 4637 } // namespace v8 |
4744 | 4638 |
4745 #endif // V8_TARGET_ARCH_X64 | 4639 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |