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

Side by Side Diff: src/runtime/runtime-generator.cc

Issue 1010883002: Switch full-codegen from StackHandlers to handler table. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@local_cleanup-isolate-dead-code
Patch Set: Fix debugger-pause-on-promise-rejection. Created 5 years, 9 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/runtime-debug.cc ('k') | src/x64/code-stubs-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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/frames-inl.h" 8 #include "src/frames-inl.h"
9 #include "src/runtime/runtime-utils.h" 9 #include "src/runtime/runtime-utils.h"
10 10
(...skipping 13 matching lines...) Expand all
24 if (frame->IsConstructor()) { 24 if (frame->IsConstructor()) {
25 generator = handle(JSGeneratorObject::cast(frame->receiver())); 25 generator = handle(JSGeneratorObject::cast(frame->receiver()));
26 } else { 26 } else {
27 generator = isolate->factory()->NewJSGeneratorObject(function); 27 generator = isolate->factory()->NewJSGeneratorObject(function);
28 } 28 }
29 generator->set_function(*function); 29 generator->set_function(*function);
30 generator->set_context(Context::cast(frame->context())); 30 generator->set_context(Context::cast(frame->context()));
31 generator->set_receiver(frame->receiver()); 31 generator->set_receiver(frame->receiver());
32 generator->set_continuation(0); 32 generator->set_continuation(0);
33 generator->set_operand_stack(isolate->heap()->empty_fixed_array()); 33 generator->set_operand_stack(isolate->heap()->empty_fixed_array());
34 generator->set_stack_handler_index(-1);
35 34
36 return *generator; 35 return *generator;
37 } 36 }
38 37
39 38
40 RUNTIME_FUNCTION(Runtime_SuspendJSGeneratorObject) { 39 RUNTIME_FUNCTION(Runtime_SuspendJSGeneratorObject) {
41 HandleScope handle_scope(isolate); 40 HandleScope handle_scope(isolate);
42 DCHECK(args.length() == 1); 41 DCHECK(args.length() == 1 || args.length() == 2);
43 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator_object, 0); 42 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator_object, 0);
44 43
45 JavaScriptFrameIterator stack_iterator(isolate); 44 JavaScriptFrameIterator stack_iterator(isolate);
46 JavaScriptFrame* frame = stack_iterator.frame(); 45 JavaScriptFrame* frame = stack_iterator.frame();
47 RUNTIME_ASSERT(frame->function()->shared()->is_generator()); 46 RUNTIME_ASSERT(frame->function()->shared()->is_generator());
48 DCHECK_EQ(frame->function(), generator_object->function()); 47 DCHECK_EQ(frame->function(), generator_object->function());
49 48
50 // The caller should have saved the context and continuation already. 49 // The caller should have saved the context and continuation already.
51 DCHECK_EQ(generator_object->context(), Context::cast(frame->context())); 50 DCHECK_EQ(generator_object->context(), Context::cast(frame->context()));
52 DCHECK_LT(0, generator_object->continuation()); 51 DCHECK_LT(0, generator_object->continuation());
53 52
54 // We expect there to be at least two values on the operand stack: the return 53 // We expect there to be at least two values on the operand stack: the return
55 // value of the yield expression, and the argument to this runtime call. 54 // value of the yield expression, and the arguments to this runtime call.
56 // Neither of those should be saved. 55 // Neither of those should be saved.
57 int operands_count = frame->ComputeOperandsCount(); 56 int operands_count = frame->ComputeOperandsCount();
58 DCHECK_GE(operands_count, 2); 57 DCHECK_GE(operands_count, 1 + args.length());
59 operands_count -= 2; 58 operands_count -= 1 + args.length();
59
60 // Second argument indicates that we need to patch the handler table because
61 // a delegating yield introduced a try-catch statement at expression level,
62 // hence the operand count was off when we statically computed it.
63 // TODO(mstarzinger): This special case disappears with do-expressions.
64 if (args.length() == 2) {
65 CONVERT_SMI_ARG_CHECKED(handler_index, 1);
66 Handle<Code> code(frame->unchecked_code());
67 Handle<HandlerTable> table(HandlerTable::cast(code->handler_table()));
68 int handler_depth = operands_count - TryBlockConstant::kElementCount;
69 table->SetRangeDepth(handler_index, handler_depth);
70 }
60 71
61 if (operands_count == 0) { 72 if (operands_count == 0) {
62 // Although it's semantically harmless to call this function with an 73 // Although it's semantically harmless to call this function with an
63 // operands_count of zero, it is also unnecessary. 74 // operands_count of zero, it is also unnecessary.
64 DCHECK_EQ(generator_object->operand_stack(), 75 DCHECK_EQ(generator_object->operand_stack(),
65 isolate->heap()->empty_fixed_array()); 76 isolate->heap()->empty_fixed_array());
66 DCHECK_EQ(generator_object->stack_handler_index(), -1);
67 // If there are no operands on the stack, there shouldn't be a handler
68 // active either.
69 DCHECK(!frame->HasHandler());
70 } else { 77 } else {
71 int stack_handler_index = -1;
72 Handle<FixedArray> operand_stack = 78 Handle<FixedArray> operand_stack =
73 isolate->factory()->NewFixedArray(operands_count); 79 isolate->factory()->NewFixedArray(operands_count);
74 frame->SaveOperandStack(*operand_stack, &stack_handler_index); 80 frame->SaveOperandStack(*operand_stack);
75 generator_object->set_operand_stack(*operand_stack); 81 generator_object->set_operand_stack(*operand_stack);
76 generator_object->set_stack_handler_index(stack_handler_index);
77 } 82 }
78 83
79 return isolate->heap()->undefined_value(); 84 return isolate->heap()->undefined_value();
80 } 85 }
81 86
82 87
83 // Note that this function is the slow path for resuming generators. It is only 88 // Note that this function is the slow path for resuming generators. It is only
84 // called if the suspended activation had operands on the stack, stack handlers 89 // called if the suspended activation had operands on the stack, stack handlers
85 // needing rewinding, or if the resume should throw an exception. The fast path 90 // needing rewinding, or if the resume should throw an exception. The fast path
86 // is handled directly in FullCodeGenerator::EmitGeneratorResume(), which is 91 // is handled directly in FullCodeGenerator::EmitGeneratorResume(), which is
(...skipping 21 matching lines...) Expand all
108 frame->set_pc(pc + offset); 113 frame->set_pc(pc + offset);
109 if (FLAG_enable_ool_constant_pool) { 114 if (FLAG_enable_ool_constant_pool) {
110 frame->set_constant_pool( 115 frame->set_constant_pool(
111 generator_object->function()->code()->constant_pool()); 116 generator_object->function()->code()->constant_pool());
112 } 117 }
113 generator_object->set_continuation(JSGeneratorObject::kGeneratorExecuting); 118 generator_object->set_continuation(JSGeneratorObject::kGeneratorExecuting);
114 119
115 FixedArray* operand_stack = generator_object->operand_stack(); 120 FixedArray* operand_stack = generator_object->operand_stack();
116 int operands_count = operand_stack->length(); 121 int operands_count = operand_stack->length();
117 if (operands_count != 0) { 122 if (operands_count != 0) {
118 frame->RestoreOperandStack(operand_stack, 123 frame->RestoreOperandStack(operand_stack);
119 generator_object->stack_handler_index());
120 generator_object->set_operand_stack(isolate->heap()->empty_fixed_array()); 124 generator_object->set_operand_stack(isolate->heap()->empty_fixed_array());
121 generator_object->set_stack_handler_index(-1);
122 } 125 }
123 126
124 JSGeneratorObject::ResumeMode resume_mode = 127 JSGeneratorObject::ResumeMode resume_mode =
125 static_cast<JSGeneratorObject::ResumeMode>(resume_mode_int); 128 static_cast<JSGeneratorObject::ResumeMode>(resume_mode_int);
126 switch (resume_mode) { 129 switch (resume_mode) {
127 case JSGeneratorObject::NEXT: 130 case JSGeneratorObject::NEXT:
128 return value; 131 return value;
129 case JSGeneratorObject::THROW: 132 case JSGeneratorObject::THROW:
130 return isolate->Throw(value); 133 return isolate->Throw(value);
131 } 134 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 return NULL; 221 return NULL;
219 } 222 }
220 223
221 224
222 RUNTIME_FUNCTION(Runtime_GeneratorThrow) { 225 RUNTIME_FUNCTION(Runtime_GeneratorThrow) {
223 UNREACHABLE(); // Optimization disabled in SetUpGenerators(). 226 UNREACHABLE(); // Optimization disabled in SetUpGenerators().
224 return NULL; 227 return NULL;
225 } 228 }
226 } 229 }
227 } // namespace v8::internal 230 } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime/runtime-debug.cc ('k') | src/x64/code-stubs-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698