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

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

Issue 1904933002: Introduce bytecodes for assisting generator suspend and resume. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 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
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/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/factory.h" 8 #include "src/factory.h"
9 #include "src/frames-inl.h" 9 #include "src/frames-inl.h"
10 #include "src/objects-inl.h" 10 #include "src/objects-inl.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 if (generator->is_suspended()) { 138 if (generator->is_suspended()) {
139 Handle<Code> code(generator->function()->code(), isolate); 139 Handle<Code> code(generator->function()->code(), isolate);
140 int offset = generator->continuation(); 140 int offset = generator->continuation();
141 RUNTIME_ASSERT(0 <= offset && offset < code->instruction_size()); 141 RUNTIME_ASSERT(0 <= offset && offset < code->instruction_size());
142 return Smi::FromInt(code->SourcePosition(offset)); 142 return Smi::FromInt(code->SourcePosition(offset));
143 } 143 }
144 144
145 return isolate->heap()->undefined_value(); 145 return isolate->heap()->undefined_value();
146 } 146 }
147 147
148
149 RUNTIME_FUNCTION(Runtime_SuspendIgnitionGenerator) {
150 HandleScope scope(isolate);
151 DCHECK(args.length() == 2);
152 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0);
153 CONVERT_ARG_HANDLE_CHECKED(Smi, state, 1);
154
155 JavaScriptFrameIterator it(isolate);
156 JavaScriptFrame* frame = it.frame();
157 Handle<JSFunction> function(frame->function());
158 CHECK(function->shared()->is_generator());
159 CHECK_EQ(frame->type(), StackFrame::INTERPRETED);
160
161 // Save register file.
162 int size = function->shared()->bytecode_array()->register_count();
163 Handle<FixedArray> register_file = isolate->factory()->NewFixedArray(size);
164 for (int i = 0; i < size; ++i) {
165 Object* value =
166 static_cast<InterpretedFrame*>(frame)->ReadInterpreterRegister(i);
167 register_file->set(i, value);
168 }
169
170 generator->set_operand_stack(*register_file);
171 generator->set_context(Context::cast(frame->context()));
172 generator->set_continuation(state->value());
173
174 return isolate->heap()->undefined_value();
175 }
176
177
178 RUNTIME_FUNCTION(Runtime_ResumeIgnitionGenerator) {
179 HandleScope scope(isolate);
180 DCHECK(args.length() == 1);
181 CONVERT_ARG_HANDLE_CHECKED(JSGeneratorObject, generator, 0);
182
183 JavaScriptFrameIterator it(isolate);
184 JavaScriptFrame* frame = it.frame();
185 Handle<JSFunction> function(frame->function());
186 CHECK(function->shared()->is_generator());
187 CHECK_EQ(frame->type(), StackFrame::INTERPRETED);
188
189 // Restore register file.
190 int size = function->shared()->bytecode_array()->register_count();
191 DCHECK_EQ(size, generator->operand_stack()->length());
192 for (int i = 0; i < size; ++i) {
193 Object* value = generator->operand_stack()->get(i);
194 static_cast<InterpretedFrame*>(frame)->WriteInterpreterRegister(i, value);
195 }
196 generator->set_operand_stack(isolate->heap()->empty_fixed_array());
197
198 int state = generator->continuation();
199 generator->set_continuation(JSGeneratorObject::kGeneratorExecuting);
200 return Smi::FromInt(state);
201 }
202
203 } // namespace internal 148 } // namespace internal
204 } // namespace v8 149 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698