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

Side by Side Diff: src/arm/full-codegen-arm.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 | « no previous file | src/ia32/code-stubs-ia32.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 1976 matching lines...) Expand 10 before | Expand all | Expand 10 after
1987 // this. It stays on the stack while we update the iterator. 1987 // this. It stays on the stack while we update the iterator.
1988 VisitForStackValue(expr->expression()); 1988 VisitForStackValue(expr->expression());
1989 1989
1990 switch (expr->yield_kind()) { 1990 switch (expr->yield_kind()) {
1991 case Yield::SUSPEND: 1991 case Yield::SUSPEND:
1992 // Pop value from top-of-stack slot; box result into result register. 1992 // Pop value from top-of-stack slot; box result into result register.
1993 EmitCreateIteratorResult(false); 1993 EmitCreateIteratorResult(false);
1994 __ push(result_register()); 1994 __ push(result_register());
1995 // Fall through. 1995 // Fall through.
1996 case Yield::INITIAL: { 1996 case Yield::INITIAL: {
1997 VisitForStackValue(expr->generator_object()); 1997 Label suspend, continuation, post_runtime, resume;
1998
1999 __ jmp(&suspend);
2000
2001 __ bind(&continuation);
2002 __ jmp(&resume);
2003
2004 __ bind(&suspend);
2005 VisitForAccumulatorValue(expr->generator_object());
2006 ASSERT(continuation.pos() > 0 && Smi::IsValid(continuation.pos()));
2007 __ mov(r1, Operand(Smi::FromInt(continuation.pos())));
2008 __ str(r1, FieldMemOperand(r0, JSGeneratorObject::kContinuationOffset));
2009 __ str(cp, FieldMemOperand(r0, JSGeneratorObject::kContextOffset));
2010 __ mov(r1, cp);
2011 __ RecordWriteField(r0, JSGeneratorObject::kContextOffset, r1, r2,
2012 kLRHasBeenSaved, kDontSaveFPRegs);
2013 __ add(r1, fp, Operand(StandardFrameConstants::kExpressionsOffset));
2014 __ cmp(sp, r1);
2015 __ b(eq, &post_runtime);
2016 __ push(r0); // generator object
1998 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); 2017 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1);
1999 __ ldr(context_register(), 2018 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2000 MemOperand(fp, StandardFrameConstants::kContextOffset)); 2019 __ bind(&post_runtime);
2001
2002 Label resume;
2003 __ CompareRoot(result_register(), Heap::kTheHoleValueRootIndex);
2004 __ b(ne, &resume);
2005 __ pop(result_register()); 2020 __ pop(result_register());
2006 EmitReturnSequence(); 2021 EmitReturnSequence();
2007 2022
2008 __ bind(&resume); 2023 __ bind(&resume);
2009 context()->Plug(result_register()); 2024 context()->Plug(result_register());
2010 break; 2025 break;
2011 } 2026 }
2012 2027
2013 case Yield::FINAL: { 2028 case Yield::FINAL: {
2014 VisitForAccumulatorValue(expr->generator_object()); 2029 VisitForAccumulatorValue(expr->generator_object());
2015 __ mov(r1, Operand(Smi::FromInt(JSGeneratorObject::kGeneratorClosed))); 2030 __ mov(r1, Operand(Smi::FromInt(JSGeneratorObject::kGeneratorClosed)));
2016 __ str(r1, FieldMemOperand(result_register(), 2031 __ str(r1, FieldMemOperand(result_register(),
2017 JSGeneratorObject::kContinuationOffset)); 2032 JSGeneratorObject::kContinuationOffset));
2018 // Pop value from top-of-stack slot, box result into result register. 2033 // Pop value from top-of-stack slot, box result into result register.
2019 EmitCreateIteratorResult(true); 2034 EmitCreateIteratorResult(true);
2020 EmitUnwindBeforeReturn(); 2035 EmitUnwindBeforeReturn();
2021 EmitReturnSequence(); 2036 EmitReturnSequence();
2022 break; 2037 break;
2023 } 2038 }
2024 2039
2025 case Yield::DELEGATING: { 2040 case Yield::DELEGATING: {
2026 VisitForStackValue(expr->generator_object()); 2041 VisitForStackValue(expr->generator_object());
2027 2042
2028 // Initial stack layout is as follows: 2043 // Initial stack layout is as follows:
2029 // [sp + 1 * kPointerSize] iter 2044 // [sp + 1 * kPointerSize] iter
2030 // [sp + 0 * kPointerSize] g 2045 // [sp + 0 * kPointerSize] g
2031 2046
2032 Label l_catch, l_try, l_resume, l_next, l_call, l_loop; 2047 Label l_catch, l_try, l_suspend, l_continuation, l_resume;
2048 Label l_next, l_call, l_loop;
2033 // Initial send value is undefined. 2049 // Initial send value is undefined.
2034 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); 2050 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex);
2035 __ b(&l_next); 2051 __ b(&l_next);
2036 2052
2037 // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; } 2053 // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; }
2038 __ bind(&l_catch); 2054 __ bind(&l_catch);
2039 handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos())); 2055 handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos()));
2040 __ LoadRoot(r2, Heap::kthrow_stringRootIndex); // "throw" 2056 __ LoadRoot(r2, Heap::kthrow_stringRootIndex); // "throw"
2041 __ ldr(r3, MemOperand(sp, 1 * kPointerSize)); // iter 2057 __ ldr(r3, MemOperand(sp, 1 * kPointerSize)); // iter
2042 __ push(r3); // iter 2058 __ push(r3); // iter
2043 __ push(r0); // exception 2059 __ push(r0); // exception
2044 __ jmp(&l_call); 2060 __ jmp(&l_call);
2045 2061
2046 // try { received = %yield result } 2062 // try { received = %yield result }
2047 // Shuffle the received result above a try handler and yield it without 2063 // Shuffle the received result above a try handler and yield it without
2048 // re-boxing. 2064 // re-boxing.
2049 __ bind(&l_try); 2065 __ bind(&l_try);
2050 __ pop(r0); // result 2066 __ pop(r0); // result
2051 __ PushTryHandler(StackHandler::CATCH, expr->index()); 2067 __ PushTryHandler(StackHandler::CATCH, expr->index());
2052 const int handler_size = StackHandlerConstants::kSize; 2068 const int handler_size = StackHandlerConstants::kSize;
2053 __ push(r0); // result 2069 __ push(r0); // result
2054 __ ldr(r3, MemOperand(sp, (0 + 1) * kPointerSize + handler_size)); // g 2070 __ jmp(&l_suspend);
2055 __ push(r3); // g 2071 __ bind(&l_continuation);
2072 __ jmp(&l_resume);
2073 __ bind(&l_suspend);
2074 const int generator_object_depth = kPointerSize + handler_size;
2075 __ ldr(r0, MemOperand(sp, generator_object_depth));
2076 __ push(r0); // g
2077 ASSERT(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos()));
2078 __ mov(r1, Operand(Smi::FromInt(l_continuation.pos())));
2079 __ str(r1, FieldMemOperand(r0, JSGeneratorObject::kContinuationOffset));
2080 __ str(cp, FieldMemOperand(r0, JSGeneratorObject::kContextOffset));
2081 __ mov(r1, cp);
2082 __ RecordWriteField(r0, JSGeneratorObject::kContextOffset, r1, r2,
2083 kLRHasBeenSaved, kDontSaveFPRegs);
2056 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); 2084 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1);
2057 __ ldr(context_register(), 2085 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
2058 MemOperand(fp, StandardFrameConstants::kContextOffset));
2059 __ CompareRoot(r0, Heap::kTheHoleValueRootIndex);
2060 __ b(ne, &l_resume);
2061 __ pop(r0); // result 2086 __ pop(r0); // result
2062 EmitReturnSequence(); 2087 EmitReturnSequence();
2063 __ bind(&l_resume); // received in r0 2088 __ bind(&l_resume); // received in r0
2064 __ PopTryHandler(); 2089 __ PopTryHandler();
2065 2090
2066 // receiver = iter; f = 'next'; arg = received; 2091 // receiver = iter; f = 'next'; arg = received;
2067 __ bind(&l_next); 2092 __ bind(&l_next);
2068 __ LoadRoot(r2, Heap::knext_stringRootIndex); // "next" 2093 __ LoadRoot(r2, Heap::knext_stringRootIndex); // "next"
2069 __ ldr(r3, MemOperand(sp, 1 * kPointerSize)); // iter 2094 __ ldr(r3, MemOperand(sp, 1 * kPointerSize)); // iter
2070 __ push(r3); // iter 2095 __ push(r3); // iter
(...skipping 2822 matching lines...) Expand 10 before | Expand all | Expand 10 after
4893 *context_length = 0; 4918 *context_length = 0;
4894 return previous_; 4919 return previous_;
4895 } 4920 }
4896 4921
4897 4922
4898 #undef __ 4923 #undef __
4899 4924
4900 } } // namespace v8::internal 4925 } } // namespace v8::internal
4901 4926
4902 #endif // V8_TARGET_ARCH_ARM 4927 #endif // V8_TARGET_ARCH_ARM
OLDNEW
« no previous file with comments | « no previous file | src/ia32/code-stubs-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698