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

Side by Side Diff: src/runtime.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/full-codegen-ia32.cc ('k') | src/x64/full-codegen-x64.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 2565 matching lines...) Expand 10 before | Expand all | Expand 10 after
2576 } 2576 }
2577 2577
2578 2578
2579 RUNTIME_FUNCTION(MaybeObject*, Runtime_SuspendJSGeneratorObject) { 2579 RUNTIME_FUNCTION(MaybeObject*, Runtime_SuspendJSGeneratorObject) {
2580 SealHandleScope shs(isolate); 2580 SealHandleScope shs(isolate);
2581 ASSERT(args.length() == 1); 2581 ASSERT(args.length() == 1);
2582 CONVERT_ARG_CHECKED(JSGeneratorObject, generator_object, 0); 2582 CONVERT_ARG_CHECKED(JSGeneratorObject, generator_object, 0);
2583 2583
2584 JavaScriptFrameIterator stack_iterator(isolate); 2584 JavaScriptFrameIterator stack_iterator(isolate);
2585 JavaScriptFrame* frame = stack_iterator.frame(); 2585 JavaScriptFrame* frame = stack_iterator.frame();
2586 JSFunction* function = JSFunction::cast(frame->function()); 2586 RUNTIME_ASSERT(JSFunction::cast(frame->function())->shared()->is_generator());
2587 RUNTIME_ASSERT(function->shared()->is_generator()); 2587 ASSERT_EQ(JSFunction::cast(frame->function()), generator_object->function());
2588 ASSERT_EQ(function, generator_object->function()); 2588
2589 // The caller should have saved the context and continuation already.
2590 ASSERT_EQ(generator_object->context(), Context::cast(frame->context()));
2591 ASSERT_LT(0, generator_object->continuation());
2589 2592
2590 // We expect there to be at least two values on the operand stack: the return 2593 // We expect there to be at least two values on the operand stack: the return
2591 // value of the yield expression, and the argument to this runtime call. 2594 // value of the yield expression, and the argument to this runtime call.
2592 // Neither of those should be saved. 2595 // Neither of those should be saved.
2593 int operands_count = frame->ComputeOperandsCount(); 2596 int operands_count = frame->ComputeOperandsCount();
2594 ASSERT(operands_count >= 2); 2597 ASSERT_GE(operands_count, 2);
2595 operands_count -= 2; 2598 operands_count -= 2;
2596 2599
2597 if (operands_count == 0) { 2600 if (operands_count == 0) {
2601 // Although it's semantically harmless to call this function with an
2602 // operands_count of zero, it is also unnecessary.
2598 ASSERT_EQ(generator_object->operand_stack(), 2603 ASSERT_EQ(generator_object->operand_stack(),
2599 isolate->heap()->empty_fixed_array()); 2604 isolate->heap()->empty_fixed_array());
2600 ASSERT_EQ(generator_object->stack_handler_index(), -1); 2605 ASSERT_EQ(generator_object->stack_handler_index(), -1);
2601 // If there are no operands on the stack, there shouldn't be a handler 2606 // If there are no operands on the stack, there shouldn't be a handler
2602 // active either. 2607 // active either.
2603 ASSERT(!frame->HasHandler()); 2608 ASSERT(!frame->HasHandler());
2604 } else { 2609 } else {
2605 int stack_handler_index = -1; 2610 int stack_handler_index = -1;
2606 MaybeObject* alloc = isolate->heap()->AllocateFixedArray(operands_count); 2611 MaybeObject* alloc = isolate->heap()->AllocateFixedArray(operands_count);
2607 FixedArray* operand_stack; 2612 FixedArray* operand_stack;
2608 if (!alloc->To(&operand_stack)) return alloc; 2613 if (!alloc->To(&operand_stack)) return alloc;
2609 frame->SaveOperandStack(operand_stack, &stack_handler_index); 2614 frame->SaveOperandStack(operand_stack, &stack_handler_index);
2610 generator_object->set_operand_stack(operand_stack); 2615 generator_object->set_operand_stack(operand_stack);
2611 generator_object->set_stack_handler_index(stack_handler_index); 2616 generator_object->set_stack_handler_index(stack_handler_index);
2612 } 2617 }
2613 2618
2614 // Set continuation down here to avoid side effects if the operand stack 2619 return isolate->heap()->undefined_value();
2615 // allocation fails.
2616 intptr_t offset = frame->pc() - function->code()->instruction_start();
2617 ASSERT(offset > 0 && Smi::IsValid(offset));
2618 generator_object->set_continuation(static_cast<int>(offset));
2619
2620 // It's possible for the context to be other than the initial context even if
2621 // there is no stack handler active. For example, this is the case in the
2622 // body of a "with" statement. Therefore we always save the context.
2623 generator_object->set_context(Context::cast(frame->context()));
2624
2625 // The return value is the hole for a suspend return, and anything else for a
2626 // resume return.
2627 return isolate->heap()->the_hole_value();
2628 } 2620 }
2629 2621
2630 2622
2631 // Note that this function is the slow path for resuming generators. It is only 2623 // Note that this function is the slow path for resuming generators. It is only
2632 // called if the suspended activation had operands on the stack, stack handlers 2624 // called if the suspended activation had operands on the stack, stack handlers
2633 // needing rewinding, or if the resume should throw an exception. The fast path 2625 // needing rewinding, or if the resume should throw an exception. The fast path
2634 // is handled directly in FullCodeGenerator::EmitGeneratorResume(), which is 2626 // is handled directly in FullCodeGenerator::EmitGeneratorResume(), which is
2635 // inlined into GeneratorNext and GeneratorThrow. EmitGeneratorResumeResume is 2627 // inlined into GeneratorNext and GeneratorThrow. EmitGeneratorResumeResume is
2636 // called in any case, as it needs to reconstruct the stack frame and make space 2628 // called in any case, as it needs to reconstruct the stack frame and make space
2637 // for arguments and operands. 2629 // for arguments and operands.
(...skipping 11005 matching lines...) Expand 10 before | Expand all | Expand 10 after
13643 // Handle last resort GC and make sure to allow future allocations 13635 // Handle last resort GC and make sure to allow future allocations
13644 // to grow the heap without causing GCs (if possible). 13636 // to grow the heap without causing GCs (if possible).
13645 isolate->counters()->gc_last_resort_from_js()->Increment(); 13637 isolate->counters()->gc_last_resort_from_js()->Increment();
13646 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13638 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13647 "Runtime::PerformGC"); 13639 "Runtime::PerformGC");
13648 } 13640 }
13649 } 13641 }
13650 13642
13651 13643
13652 } } // namespace v8::internal 13644 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ia32/full-codegen-ia32.cc ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698