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 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #if V8_TARGET_ARCH_X64 | 7 #if V8_TARGET_ARCH_X64 |
8 | 8 |
9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 2178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2189 Expression *value, | 2189 Expression *value, |
2190 JSGeneratorObject::ResumeMode resume_mode) { | 2190 JSGeneratorObject::ResumeMode resume_mode) { |
2191 // The value stays in rax, and is ultimately read by the resumed generator, as | 2191 // The value stays in rax, and is ultimately read by the resumed generator, as |
2192 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it | 2192 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it |
2193 // is read to throw the value when the resumed generator is already closed. | 2193 // is read to throw the value when the resumed generator is already closed. |
2194 // rbx will hold the generator object until the activation has been resumed. | 2194 // rbx will hold the generator object until the activation has been resumed. |
2195 VisitForStackValue(generator); | 2195 VisitForStackValue(generator); |
2196 VisitForAccumulatorValue(value); | 2196 VisitForAccumulatorValue(value); |
2197 __ Pop(rbx); | 2197 __ Pop(rbx); |
2198 | 2198 |
2199 // Check generator state. | |
2200 Label wrong_state, closed_state, done; | |
2201 STATIC_ASSERT(JSGeneratorObject::kGeneratorExecuting < 0); | |
2202 STATIC_ASSERT(JSGeneratorObject::kGeneratorClosed == 0); | |
2203 __ SmiCompare(FieldOperand(rbx, JSGeneratorObject::kContinuationOffset), | |
2204 Smi::FromInt(0)); | |
2205 __ j(equal, &closed_state); | |
2206 __ j(less, &wrong_state); | |
2207 | |
2208 // Load suspended function and context. | 2199 // Load suspended function and context. |
2209 __ movp(rsi, FieldOperand(rbx, JSGeneratorObject::kContextOffset)); | 2200 __ movp(rsi, FieldOperand(rbx, JSGeneratorObject::kContextOffset)); |
2210 __ movp(rdi, FieldOperand(rbx, JSGeneratorObject::kFunctionOffset)); | 2201 __ movp(rdi, FieldOperand(rbx, JSGeneratorObject::kFunctionOffset)); |
2211 | 2202 |
2212 // Push receiver. | 2203 // Push receiver. |
2213 __ Push(FieldOperand(rbx, JSGeneratorObject::kReceiverOffset)); | 2204 __ Push(FieldOperand(rbx, JSGeneratorObject::kReceiverOffset)); |
2214 | 2205 |
2215 // Push holes for arguments to generator function. | 2206 // Push holes for arguments to generator function. |
2216 __ movp(rdx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); | 2207 __ movp(rdx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); |
2217 __ LoadSharedFunctionInfoSpecialField(rdx, rdx, | 2208 __ LoadSharedFunctionInfoSpecialField(rdx, rdx, |
2218 SharedFunctionInfo::kFormalParameterCountOffset); | 2209 SharedFunctionInfo::kFormalParameterCountOffset); |
2219 __ LoadRoot(rcx, Heap::kTheHoleValueRootIndex); | 2210 __ LoadRoot(rcx, Heap::kTheHoleValueRootIndex); |
2220 Label push_argument_holes, push_frame; | 2211 Label push_argument_holes, push_frame; |
2221 __ bind(&push_argument_holes); | 2212 __ bind(&push_argument_holes); |
2222 __ subp(rdx, Immediate(1)); | 2213 __ subp(rdx, Immediate(1)); |
2223 __ j(carry, &push_frame); | 2214 __ j(carry, &push_frame); |
2224 __ Push(rcx); | 2215 __ Push(rcx); |
2225 __ jmp(&push_argument_holes); | 2216 __ jmp(&push_argument_holes); |
2226 | 2217 |
2227 // Enter a new JavaScript frame, and initialize its slots as they were when | 2218 // Enter a new JavaScript frame, and initialize its slots as they were when |
2228 // the generator was suspended. | 2219 // the generator was suspended. |
2229 Label resume_frame; | 2220 Label resume_frame, done; |
2230 __ bind(&push_frame); | 2221 __ bind(&push_frame); |
2231 __ call(&resume_frame); | 2222 __ call(&resume_frame); |
2232 __ jmp(&done); | 2223 __ jmp(&done); |
2233 __ bind(&resume_frame); | 2224 __ bind(&resume_frame); |
2234 __ pushq(rbp); // Caller's frame pointer. | 2225 __ pushq(rbp); // Caller's frame pointer. |
2235 __ movp(rbp, rsp); | 2226 __ movp(rbp, rsp); |
2236 __ Push(rsi); // Callee's context. | 2227 __ Push(rsi); // Callee's context. |
2237 __ Push(rdi); // Callee's JS Function. | 2228 __ Push(rdi); // Callee's JS Function. |
2238 | 2229 |
2239 // Load the operand stack size. | 2230 // Load the operand stack size. |
(...skipping 26 matching lines...) Expand all Loading... |
2266 __ Push(rcx); | 2257 __ Push(rcx); |
2267 __ jmp(&push_operand_holes); | 2258 __ jmp(&push_operand_holes); |
2268 __ bind(&call_resume); | 2259 __ bind(&call_resume); |
2269 __ Push(rbx); | 2260 __ Push(rbx); |
2270 __ Push(result_register()); | 2261 __ Push(result_register()); |
2271 __ Push(Smi::FromInt(resume_mode)); | 2262 __ Push(Smi::FromInt(resume_mode)); |
2272 __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3); | 2263 __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3); |
2273 // Not reached: the runtime call returns elsewhere. | 2264 // Not reached: the runtime call returns elsewhere. |
2274 __ Abort(kGeneratorFailedToResume); | 2265 __ Abort(kGeneratorFailedToResume); |
2275 | 2266 |
2276 // Reach here when generator is closed. | |
2277 __ bind(&closed_state); | |
2278 if (resume_mode == JSGeneratorObject::NEXT) { | |
2279 // Return completed iterator result when generator is closed. | |
2280 __ PushRoot(Heap::kUndefinedValueRootIndex); | |
2281 // Pop value from top-of-stack slot; box result into result register. | |
2282 EmitCreateIteratorResult(true); | |
2283 } else { | |
2284 // Throw the provided value. | |
2285 __ Push(rax); | |
2286 __ CallRuntime(Runtime::kThrow, 1); | |
2287 } | |
2288 __ jmp(&done); | |
2289 | |
2290 // Throw error if we attempt to operate on a running generator. | |
2291 __ bind(&wrong_state); | |
2292 __ Push(rbx); | |
2293 __ CallRuntime(Runtime::kThrowGeneratorStateError, 1); | |
2294 | |
2295 __ bind(&done); | 2267 __ bind(&done); |
2296 context()->Plug(result_register()); | 2268 context()->Plug(result_register()); |
2297 } | 2269 } |
2298 | 2270 |
2299 | 2271 |
2300 void FullCodeGenerator::EmitCreateIteratorResult(bool done) { | 2272 void FullCodeGenerator::EmitCreateIteratorResult(bool done) { |
2301 Label gc_required; | 2273 Label gc_required; |
2302 Label allocated; | 2274 Label allocated; |
2303 | 2275 |
2304 const int instance_size = 5 * kPointerSize; | 2276 const int instance_size = 5 * kPointerSize; |
(...skipping 2954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5259 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 5231 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
5260 Assembler::target_address_at(call_target_address, | 5232 Assembler::target_address_at(call_target_address, |
5261 unoptimized_code)); | 5233 unoptimized_code)); |
5262 return OSR_AFTER_STACK_CHECK; | 5234 return OSR_AFTER_STACK_CHECK; |
5263 } | 5235 } |
5264 | 5236 |
5265 | 5237 |
5266 } } // namespace v8::internal | 5238 } } // namespace v8::internal |
5267 | 5239 |
5268 #endif // V8_TARGET_ARCH_X64 | 5240 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |