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

Side by Side Diff: src/runtime.cc

Issue 14031028: Generators save and restore stack handlers (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Rebased before commit Created 7 years, 7 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/objects-inl.h ('k') | src/v8memory.h » ('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 2559 matching lines...) Expand 10 before | Expand all | Expand 10 after
2570 } else { 2570 } else {
2571 MaybeObject* maybe_generator = 2571 MaybeObject* maybe_generator =
2572 isolate->heap()->AllocateJSGeneratorObject(function); 2572 isolate->heap()->AllocateJSGeneratorObject(function);
2573 if (!maybe_generator->To(&generator)) return maybe_generator; 2573 if (!maybe_generator->To(&generator)) return maybe_generator;
2574 } 2574 }
2575 generator->set_function(function); 2575 generator->set_function(function);
2576 generator->set_context(Context::cast(frame->context())); 2576 generator->set_context(Context::cast(frame->context()));
2577 generator->set_receiver(frame->receiver()); 2577 generator->set_receiver(frame->receiver());
2578 generator->set_continuation(0); 2578 generator->set_continuation(0);
2579 generator->set_operand_stack(isolate->heap()->empty_fixed_array()); 2579 generator->set_operand_stack(isolate->heap()->empty_fixed_array());
2580 generator->set_stack_handler_index(-1);
2580 2581
2581 return generator; 2582 return generator;
2582 } 2583 }
2583 2584
2584 2585
2585 RUNTIME_FUNCTION(MaybeObject*, Runtime_SuspendJSGeneratorObject) { 2586 RUNTIME_FUNCTION(MaybeObject*, Runtime_SuspendJSGeneratorObject) {
2586 NoHandleAllocation ha(isolate); 2587 NoHandleAllocation ha(isolate);
2587 ASSERT(args.length() == 1); 2588 ASSERT(args.length() == 1);
2588 CONVERT_ARG_CHECKED(JSGeneratorObject, generator_object, 0); 2589 CONVERT_ARG_CHECKED(JSGeneratorObject, generator_object, 0);
2589 2590
2590 JavaScriptFrameIterator stack_iterator(isolate); 2591 JavaScriptFrameIterator stack_iterator(isolate);
2591 JavaScriptFrame* frame = stack_iterator.frame(); 2592 JavaScriptFrame* frame = stack_iterator.frame();
2592 JSFunction* function = JSFunction::cast(frame->function()); 2593 JSFunction* function = JSFunction::cast(frame->function());
2593 RUNTIME_ASSERT(function->shared()->is_generator()); 2594 RUNTIME_ASSERT(function->shared()->is_generator());
2594 ASSERT_EQ(function, generator_object->function()); 2595 ASSERT_EQ(function, generator_object->function());
2595 2596
2596 // We expect there to be at least two values on the operand stack: the return 2597 // We expect there to be at least two values on the operand stack: the return
2597 // value of the yield expression, and the argument to this runtime call. 2598 // value of the yield expression, and the argument to this runtime call.
2598 // Neither of those should be saved. 2599 // Neither of those should be saved.
2599 int operands_count = frame->ComputeOperandsCount(); 2600 int operands_count = frame->ComputeOperandsCount();
2600 ASSERT(operands_count >= 2); 2601 ASSERT(operands_count >= 2);
2601 operands_count -= 2; 2602 operands_count -= 2;
2602 2603
2603 if (operands_count == 0) { 2604 if (operands_count == 0) {
2604 ASSERT_EQ(generator_object->operand_stack(), 2605 ASSERT_EQ(generator_object->operand_stack(),
2605 isolate->heap()->empty_fixed_array()); 2606 isolate->heap()->empty_fixed_array());
2607 ASSERT_EQ(generator_object->stack_handler_index(), -1);
2606 // If there are no operands on the stack, there shouldn't be a handler 2608 // If there are no operands on the stack, there shouldn't be a handler
2607 // active either. 2609 // active either.
2608 ASSERT(!frame->HasHandler()); 2610 ASSERT(!frame->HasHandler());
2609 } else { 2611 } else {
2610 if (frame->HasHandler()) { 2612 int stack_handler_index = -1;
2611 // TODO(wingo): Unwind the stack handlers. 2613 MaybeObject* alloc = isolate->heap()->AllocateFixedArray(operands_count);
2612 UNIMPLEMENTED();
2613 }
2614
2615 FixedArray* operand_stack; 2614 FixedArray* operand_stack;
2616 MaybeObject* alloc = isolate->heap()->AllocateFixedArray(operands_count);
2617 if (!alloc->To(&operand_stack)) return alloc; 2615 if (!alloc->To(&operand_stack)) return alloc;
2618 2616 frame->SaveOperandStack(operand_stack, &stack_handler_index);
2619 for (int i = 0; i < operands_count; i++) {
2620 operand_stack->set(i, frame->GetOperand(i));
2621 }
2622 generator_object->set_operand_stack(operand_stack); 2617 generator_object->set_operand_stack(operand_stack);
2618 generator_object->set_stack_handler_index(stack_handler_index);
2623 } 2619 }
2624 2620
2625 // Set continuation down here to avoid side effects if the operand stack 2621 // Set continuation down here to avoid side effects if the operand stack
2626 // allocation fails. 2622 // allocation fails.
2627 intptr_t offset = frame->pc() - function->code()->instruction_start(); 2623 intptr_t offset = frame->pc() - function->code()->instruction_start();
2628 ASSERT(offset > 0 && Smi::IsValid(offset)); 2624 ASSERT(offset > 0 && Smi::IsValid(offset));
2629 generator_object->set_continuation(static_cast<int>(offset)); 2625 generator_object->set_continuation(static_cast<int>(offset));
2630 2626
2631 // It's possible for the context to be other than the initial context even if 2627 // It's possible for the context to be other than the initial context even if
2632 // there is no stack handler active. For example, this is the case in the 2628 // there is no stack handler active. For example, this is the case in the
(...skipping 29 matching lines...) Expand all
2662 2658
2663 Address pc = generator_object->function()->code()->instruction_start(); 2659 Address pc = generator_object->function()->code()->instruction_start();
2664 int offset = generator_object->continuation(); 2660 int offset = generator_object->continuation();
2665 ASSERT(offset > 0); 2661 ASSERT(offset > 0);
2666 frame->set_pc(pc + offset); 2662 frame->set_pc(pc + offset);
2667 generator_object->set_continuation(JSGeneratorObject::kGeneratorExecuting); 2663 generator_object->set_continuation(JSGeneratorObject::kGeneratorExecuting);
2668 2664
2669 FixedArray* operand_stack = generator_object->operand_stack(); 2665 FixedArray* operand_stack = generator_object->operand_stack();
2670 int operands_count = operand_stack->length(); 2666 int operands_count = operand_stack->length();
2671 if (operands_count != 0) { 2667 if (operands_count != 0) {
2672 // TODO(wingo): Rewind stack handlers. However until 2668 frame->RestoreOperandStack(operand_stack,
2673 // SuspendJSGeneratorObject unwinds them, we won't see frames with stack 2669 generator_object->stack_handler_index());
2674 // handlers here.
2675 for (int i = 0; i < operands_count; i++) {
2676 ASSERT_EQ(frame->GetOperand(i), isolate->heap()->the_hole_value());
2677 Memory::Object_at(frame->GetOperandSlot(i)) = operand_stack->get(i);
2678 }
2679 generator_object->set_operand_stack(isolate->heap()->empty_fixed_array()); 2670 generator_object->set_operand_stack(isolate->heap()->empty_fixed_array());
2671 generator_object->set_stack_handler_index(-1);
2680 } 2672 }
2681 2673
2682 JSGeneratorObject::ResumeMode resume_mode = 2674 JSGeneratorObject::ResumeMode resume_mode =
2683 static_cast<JSGeneratorObject::ResumeMode>(resume_mode_int); 2675 static_cast<JSGeneratorObject::ResumeMode>(resume_mode_int);
2684 switch (resume_mode) { 2676 switch (resume_mode) {
2685 case JSGeneratorObject::SEND: 2677 case JSGeneratorObject::SEND:
2686 return value; 2678 return value;
2687 case JSGeneratorObject::THROW: 2679 case JSGeneratorObject::THROW:
2688 return isolate->Throw(value); 2680 return isolate->Throw(value);
2689 } 2681 }
(...skipping 10824 matching lines...) Expand 10 before | Expand all | Expand 10 after
13514 // Handle last resort GC and make sure to allow future allocations 13506 // Handle last resort GC and make sure to allow future allocations
13515 // to grow the heap without causing GCs (if possible). 13507 // to grow the heap without causing GCs (if possible).
13516 isolate->counters()->gc_last_resort_from_js()->Increment(); 13508 isolate->counters()->gc_last_resort_from_js()->Increment();
13517 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13509 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13518 "Runtime::PerformGC"); 13510 "Runtime::PerformGC");
13519 } 13511 }
13520 } 13512 }
13521 13513
13522 13514
13523 } } // namespace v8::internal 13515 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | src/v8memory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698