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

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

Issue 14066016: Generators can resume (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Use Abort() instead of int3() Created 7 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
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/fuzz-natives-part4.js » ('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 1943 matching lines...) Expand 10 before | Expand all | Expand 10 after
1954 EmitReturnSequence(); 1954 EmitReturnSequence();
1955 break; 1955 break;
1956 } 1956 }
1957 1957
1958 case Yield::DELEGATING: 1958 case Yield::DELEGATING:
1959 UNIMPLEMENTED(); 1959 UNIMPLEMENTED();
1960 } 1960 }
1961 } 1961 }
1962 1962
1963 1963
1964 void FullCodeGenerator::EmitGeneratorResume(Expression *generator,
1965 Expression *value,
1966 JSGeneratorObject::ResumeMode resume_mode) {
1967 // The value stays in rax, and is ultimately read by the resumed generator, as
1968 // if the CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. rbx
1969 // will hold the generator object until the activation has been resumed.
1970 VisitForStackValue(generator);
1971 VisitForAccumulatorValue(value);
1972 __ pop(rbx);
1973
1974 // Check generator state.
1975 Label wrong_state, done;
1976 STATIC_ASSERT(JSGeneratorObject::kGeneratorExecuting <= 0);
1977 STATIC_ASSERT(JSGeneratorObject::kGeneratorClosed <= 0);
1978 __ SmiCompare(FieldOperand(rbx, JSGeneratorObject::kContinuationOffset),
1979 Smi::FromInt(0));
1980 __ j(less_equal, &wrong_state);
1981
1982 // Load suspended function and context.
1983 __ movq(rsi, FieldOperand(rbx, JSGeneratorObject::kContextOffset));
1984 __ movq(rdi, FieldOperand(rbx, JSGeneratorObject::kFunctionOffset));
1985
1986 // Push holes for arguments to generator function.
1987 __ movq(rdx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
1988 __ movsxlq(rdx,
1989 FieldOperand(rdx,
1990 SharedFunctionInfo::kFormalParameterCountOffset));
1991 __ LoadRoot(rcx, Heap::kTheHoleValueRootIndex);
1992 Label push_argument_holes;
1993 __ bind(&push_argument_holes);
1994 __ push(rcx);
1995 __ subq(rdx, Immediate(1));
1996 __ j(not_carry, &push_argument_holes);
1997
1998 // Enter a new JavaScript frame, and initialize its slots as they were when
1999 // the generator was suspended.
2000 Label push_frame, resume_frame;
2001 __ bind(&push_frame);
2002 __ call(&resume_frame);
2003 __ jmp(&done);
2004 __ bind(&resume_frame);
2005 __ push(rbp); // Caller's frame pointer.
2006 __ movq(rbp, rsp);
2007 __ push(rsi); // Callee's context.
2008 __ push(rdi); // Callee's JS Function.
2009
2010 // Load the operand stack size.
2011 __ movq(rdx, FieldOperand(rbx, JSGeneratorObject::kOperandStackOffset));
2012 __ movq(rdx, FieldOperand(rdx, FixedArray::kLengthOffset));
2013 __ SmiToInteger32(rdx, rdx);
2014
2015 // If we are sending a value and there is no operand stack, we can jump back
2016 // in directly.
2017 if (resume_mode == JSGeneratorObject::SEND) {
2018 Label slow_resume;
2019 __ cmpq(rdx, Immediate(0));
2020 __ j(not_zero, &slow_resume);
2021 __ movq(rdx, FieldOperand(rdi, JSFunction::kCodeEntryOffset));
2022 __ SmiToInteger64(rcx,
2023 FieldOperand(rbx, JSGeneratorObject::kContinuationOffset));
2024 __ addq(rdx, rcx);
2025 __ Move(FieldOperand(rbx, JSGeneratorObject::kContinuationOffset),
2026 Smi::FromInt(JSGeneratorObject::kGeneratorExecuting));
2027 __ jmp(rdx);
2028 __ bind(&slow_resume);
2029 }
2030
2031 // Otherwise, we push holes for the operand stack and call the runtime to fix
2032 // up the stack and the handlers.
2033 Label push_operand_holes, call_resume;
2034 __ bind(&push_operand_holes);
2035 __ subq(rdx, Immediate(1));
2036 __ j(carry, &call_resume);
2037 __ push(rcx);
2038 __ jmp(&push_operand_holes);
2039 __ bind(&call_resume);
2040 __ push(rbx);
2041 __ push(result_register());
2042 __ Push(Smi::FromInt(resume_mode));
2043 __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3);
2044 // Not reached: the runtime call returns elsewhere.
2045 __ Abort("Generator failed to resume.");
2046
2047 // Throw error if we attempt to operate on a running generator.
2048 __ bind(&wrong_state);
2049 __ push(rbx);
2050 __ CallRuntime(Runtime::kThrowGeneratorStateError, 1);
2051
2052 __ bind(&done);
2053 context()->Plug(result_register());
2054 }
2055
2056
1964 void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { 2057 void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) {
1965 SetSourcePosition(prop->position()); 2058 SetSourcePosition(prop->position());
1966 Literal* key = prop->key()->AsLiteral(); 2059 Literal* key = prop->key()->AsLiteral();
1967 __ Move(rcx, key->handle()); 2060 __ Move(rcx, key->handle());
1968 Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); 2061 Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize();
1969 CallIC(ic, RelocInfo::CODE_TARGET, prop->PropertyFeedbackId()); 2062 CallIC(ic, RelocInfo::CODE_TARGET, prop->PropertyFeedbackId());
1970 } 2063 }
1971 2064
1972 2065
1973 void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) { 2066 void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) {
(...skipping 2627 matching lines...) Expand 10 before | Expand all | Expand 10 after
4601 *context_length = 0; 4694 *context_length = 0;
4602 return previous_; 4695 return previous_;
4603 } 4696 }
4604 4697
4605 4698
4606 #undef __ 4699 #undef __
4607 4700
4608 } } // namespace v8::internal 4701 } } // namespace v8::internal
4609 4702
4610 #endif // V8_TARGET_ARCH_X64 4703 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/fuzz-natives-part4.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698