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

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

Issue 15990004: Generators: Avoid calling into runtime if operand stack is empty (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add asserts to runtime.cc; clarify generated runtime call Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « src/ia32/code-stubs-ia32.cc ('k') | src/runtime.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1935 matching lines...) Expand 10 before | Expand all | Expand 10 after
1946 // this. It stays on the stack while we update the iterator. 1946 // this. It stays on the stack while we update the iterator.
1947 VisitForStackValue(expr->expression()); 1947 VisitForStackValue(expr->expression());
1948 1948
1949 switch (expr->yield_kind()) { 1949 switch (expr->yield_kind()) {
1950 case Yield::SUSPEND: 1950 case Yield::SUSPEND:
1951 // Pop value from top-of-stack slot; box result into result register. 1951 // Pop value from top-of-stack slot; box result into result register.
1952 EmitCreateIteratorResult(false); 1952 EmitCreateIteratorResult(false);
1953 __ push(result_register()); 1953 __ push(result_register());
1954 // Fall through. 1954 // Fall through.
1955 case Yield::INITIAL: { 1955 case Yield::INITIAL: {
1956 VisitForStackValue(expr->generator_object()); 1956 Label suspend, continuation, post_runtime, resume;
1957
1958 __ jmp(&suspend);
1959
1960 __ bind(&continuation);
1961 __ jmp(&resume);
1962
1963 __ bind(&suspend);
1964 VisitForAccumulatorValue(expr->generator_object());
1965 ASSERT(continuation.pos() > 0 && Smi::IsValid(continuation.pos()));
1966 __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset),
1967 Immediate(Smi::FromInt(continuation.pos())));
1968 __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi);
1969 __ mov(ecx, esi);
1970 __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx,
1971 kDontSaveFPRegs);
1972 __ lea(ebx, Operand(ebp, StandardFrameConstants::kExpressionsOffset));
1973 __ cmp(esp, ebx);
1974 __ j(equal, &post_runtime);
1975 __ push(eax); // generator object
1957 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); 1976 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1);
1958 __ mov(context_register(), 1977 __ mov(context_register(),
1959 Operand(ebp, StandardFrameConstants::kContextOffset)); 1978 Operand(ebp, StandardFrameConstants::kContextOffset));
1960 1979 __ bind(&post_runtime);
1961 Label resume;
1962 __ CompareRoot(result_register(), Heap::kTheHoleValueRootIndex);
1963 __ j(not_equal, &resume);
1964 __ pop(result_register()); 1980 __ pop(result_register());
1965 EmitReturnSequence(); 1981 EmitReturnSequence();
1966 1982
1967 __ bind(&resume); 1983 __ bind(&resume);
1968 context()->Plug(result_register()); 1984 context()->Plug(result_register());
1969 break; 1985 break;
1970 } 1986 }
1971 1987
1972 case Yield::FINAL: { 1988 case Yield::FINAL: {
1973 VisitForAccumulatorValue(expr->generator_object()); 1989 VisitForAccumulatorValue(expr->generator_object());
1974 __ mov(FieldOperand(result_register(), 1990 __ mov(FieldOperand(result_register(),
1975 JSGeneratorObject::kContinuationOffset), 1991 JSGeneratorObject::kContinuationOffset),
1976 Immediate(Smi::FromInt(JSGeneratorObject::kGeneratorClosed))); 1992 Immediate(Smi::FromInt(JSGeneratorObject::kGeneratorClosed)));
1977 // Pop value from top-of-stack slot, box result into result register. 1993 // Pop value from top-of-stack slot, box result into result register.
1978 EmitCreateIteratorResult(true); 1994 EmitCreateIteratorResult(true);
1979 EmitUnwindBeforeReturn(); 1995 EmitUnwindBeforeReturn();
1980 EmitReturnSequence(); 1996 EmitReturnSequence();
1981 break; 1997 break;
1982 } 1998 }
1983 1999
1984 case Yield::DELEGATING: { 2000 case Yield::DELEGATING: {
1985 VisitForStackValue(expr->generator_object()); 2001 VisitForStackValue(expr->generator_object());
1986 2002
1987 // Initial stack layout is as follows: 2003 // Initial stack layout is as follows:
1988 // [sp + 1 * kPointerSize] iter 2004 // [sp + 1 * kPointerSize] iter
1989 // [sp + 0 * kPointerSize] g 2005 // [sp + 0 * kPointerSize] g
1990 2006
1991 Label l_catch, l_try, l_resume, l_next, l_call, l_loop; 2007 Label l_catch, l_try, l_suspend, l_continuation, l_resume;
2008 Label l_next, l_call, l_loop;
1992 // Initial send value is undefined. 2009 // Initial send value is undefined.
1993 __ mov(eax, isolate()->factory()->undefined_value()); 2010 __ mov(eax, isolate()->factory()->undefined_value());
1994 __ jmp(&l_next); 2011 __ jmp(&l_next);
1995 2012
1996 // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; } 2013 // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; }
1997 __ bind(&l_catch); 2014 __ bind(&l_catch);
1998 handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos())); 2015 handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos()));
1999 __ mov(ecx, isolate()->factory()->throw_string()); // "throw" 2016 __ mov(ecx, isolate()->factory()->throw_string()); // "throw"
2000 __ push(ecx); // "throw" 2017 __ push(ecx); // "throw"
2001 __ push(Operand(esp, 2 * kPointerSize)); // iter 2018 __ push(Operand(esp, 2 * kPointerSize)); // iter
2002 __ push(eax); // exception 2019 __ push(eax); // exception
2003 __ jmp(&l_call); 2020 __ jmp(&l_call);
2004 2021
2005 // try { received = %yield result } 2022 // try { received = %yield result }
2006 // Shuffle the received result above a try handler and yield it without 2023 // Shuffle the received result above a try handler and yield it without
2007 // re-boxing. 2024 // re-boxing.
2008 __ bind(&l_try); 2025 __ bind(&l_try);
2009 __ pop(eax); // result 2026 __ pop(eax); // result
2010 __ PushTryHandler(StackHandler::CATCH, expr->index()); 2027 __ PushTryHandler(StackHandler::CATCH, expr->index());
2011 const int handler_size = StackHandlerConstants::kSize; 2028 const int handler_size = StackHandlerConstants::kSize;
2012 __ push(eax); // result 2029 __ push(eax); // result
2013 __ push(Operand(esp, (0 + 1) * kPointerSize + handler_size)); // g 2030 __ jmp(&l_suspend);
2031 __ bind(&l_continuation);
2032 __ jmp(&l_resume);
2033 __ bind(&l_suspend);
2034 const int generator_object_depth = kPointerSize + handler_size;
2035 __ mov(eax, Operand(esp, generator_object_depth));
2036 __ push(eax); // g
2037 ASSERT(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos()));
2038 __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset),
2039 Immediate(Smi::FromInt(l_continuation.pos())));
2040 __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi);
2041 __ mov(ecx, esi);
2042 __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx,
2043 kDontSaveFPRegs);
2014 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); 2044 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1);
2015 __ mov(context_register(), 2045 __ mov(context_register(),
2016 Operand(ebp, StandardFrameConstants::kContextOffset)); 2046 Operand(ebp, StandardFrameConstants::kContextOffset));
2017 __ CompareRoot(eax, Heap::kTheHoleValueRootIndex);
2018 __ j(not_equal, &l_resume);
2019 __ pop(eax); // result 2047 __ pop(eax); // result
2020 EmitReturnSequence(); 2048 EmitReturnSequence();
2021 __ bind(&l_resume); // received in eax 2049 __ bind(&l_resume); // received in eax
2022 __ PopTryHandler(); 2050 __ PopTryHandler();
2023 2051
2024 // receiver = iter; f = iter.next; arg = received; 2052 // receiver = iter; f = iter.next; arg = received;
2025 __ bind(&l_next); 2053 __ bind(&l_next);
2026 __ mov(ecx, isolate()->factory()->next_string()); // "next" 2054 __ mov(ecx, isolate()->factory()->next_string()); // "next"
2027 __ push(ecx); 2055 __ push(ecx);
2028 __ push(Operand(esp, 2 * kPointerSize)); // iter 2056 __ push(Operand(esp, 2 * kPointerSize)); // iter
(...skipping 2864 matching lines...) Expand 10 before | Expand all | Expand 10 after
4893 *stack_depth = 0; 4921 *stack_depth = 0;
4894 *context_length = 0; 4922 *context_length = 0;
4895 return previous_; 4923 return previous_;
4896 } 4924 }
4897 4925
4898 #undef __ 4926 #undef __
4899 4927
4900 } } // namespace v8::internal 4928 } } // namespace v8::internal
4901 4929
4902 #endif // V8_TARGET_ARCH_IA32 4930 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/ia32/code-stubs-ia32.cc ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698