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/runtime-compiler.cc

Issue 2172233002: [interpreter] Add explicit OSR polling bytecode. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@local_interpreter-osr-1
Patch Set: Rebased. Created 4 years, 4 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/interpreter/interpreter-assembler.cc ('k') | test/mjsunit/ignition/osr-from-bytecode.js » ('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/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/asmjs/asm-js.h" 8 #include "src/asmjs/asm-js.h"
9 #include "src/compiler.h" 9 #include "src/compiler.h"
10 #include "src/deoptimizer.h" 10 #include "src/deoptimizer.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 // deoptimized so that we are currently in an unoptimized activation. 210 // deoptimized so that we are currently in an unoptimized activation.
211 // Check for optimized activations of this function. 211 // Check for optimized activations of this function.
212 for (JavaScriptFrameIterator it(isolate); !it.done(); it.Advance()) { 212 for (JavaScriptFrameIterator it(isolate); !it.done(); it.Advance()) {
213 JavaScriptFrame* frame = it.frame(); 213 JavaScriptFrame* frame = it.frame();
214 if (frame->is_optimized() && frame->function() == *function) return false; 214 if (frame->is_optimized() && frame->function() == *function) return false;
215 } 215 }
216 216
217 return true; 217 return true;
218 } 218 }
219 219
220 namespace {
220 221
221 RUNTIME_FUNCTION(Runtime_CompileForOnStackReplacement) { 222 BailoutId DetermineEntryAndDisarmOSRForBaseline(JavaScriptFrame* frame) {
222 HandleScope scope(isolate); 223 Handle<Code> caller_code(frame->function()->shared()->code());
223 DCHECK(args.length() == 1);
224 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
225 Handle<Code> caller_code(function->shared()->code());
226 224
227 // We're not prepared to handle a function with arguments object. 225 // Passing the PC in the JavaScript frame from the caller directly is
228 DCHECK(!function->shared()->uses_arguments());
229
230 CHECK(FLAG_use_osr);
231
232 // Passing the PC in the javascript frame from the caller directly is
233 // not GC safe, so we walk the stack to get it. 226 // not GC safe, so we walk the stack to get it.
234 JavaScriptFrameIterator it(isolate);
235 JavaScriptFrame* frame = it.frame();
236 if (!caller_code->contains(frame->pc())) { 227 if (!caller_code->contains(frame->pc())) {
237 // Code on the stack may not be the code object referenced by the shared 228 // Code on the stack may not be the code object referenced by the shared
238 // function info. It may have been replaced to include deoptimization data. 229 // function info. It may have been replaced to include deoptimization data.
239 caller_code = Handle<Code>(frame->LookupCode()); 230 caller_code = Handle<Code>(frame->LookupCode());
240 } 231 }
241 232
233 DCHECK_EQ(frame->LookupCode(), *caller_code);
234 DCHECK_EQ(Code::FUNCTION, caller_code->kind());
235 DCHECK(caller_code->contains(frame->pc()));
236
237 // Revert the patched back edge table, regardless of whether OSR succeeds.
238 BackEdgeTable::Revert(frame->isolate(), *caller_code);
239
242 uint32_t pc_offset = 240 uint32_t pc_offset =
243 static_cast<uint32_t>(frame->pc() - caller_code->instruction_start()); 241 static_cast<uint32_t>(frame->pc() - caller_code->instruction_start());
244 242
245 #ifdef DEBUG 243 return caller_code->TranslatePcOffsetToAstId(pc_offset);
244 }
245
246 BailoutId DetermineEntryAndDisarmOSRForInterpreter(JavaScriptFrame* frame) {
247 InterpretedFrame* iframe = reinterpret_cast<InterpretedFrame*>(frame);
248
249 // Note that the bytecode array active on the stack might be different from
250 // the one installed on the function (e.g. patched by debugger). This however
251 // is fine because we guarantee the layout to be in sync, hence any BailoutId
252 // representing the entry point will be valid for any copy of the bytecode.
253 Handle<BytecodeArray> bytecode(iframe->GetBytecodeArray());
254
255 DCHECK(frame->LookupCode()->is_interpreter_trampoline_builtin());
256 DCHECK(frame->function()->shared()->HasBytecodeArray());
257 DCHECK(frame->is_interpreted());
258 DCHECK(FLAG_ignition_osr);
259
260 // Reset the OSR loop nesting depth to disarm back edges.
261 bytecode->set_osr_loop_nesting_level(0);
262
263 return BailoutId(iframe->GetBytecodeOffset());
264 }
265
266 } // namespace
267
268 RUNTIME_FUNCTION(Runtime_CompileForOnStackReplacement) {
269 HandleScope scope(isolate);
270 DCHECK(args.length() == 1);
271 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
272
273 // We're not prepared to handle a function with arguments object.
274 DCHECK(!function->shared()->uses_arguments());
275
276 // Only reachable when OST is enabled.
277 CHECK(FLAG_use_osr);
278
279 // Determine frame triggering OSR request.
280 JavaScriptFrameIterator it(isolate);
281 JavaScriptFrame* frame = it.frame();
246 DCHECK_EQ(frame->function(), *function); 282 DCHECK_EQ(frame->function(), *function);
247 DCHECK_EQ(frame->LookupCode(), *caller_code);
248 DCHECK(caller_code->contains(frame->pc()));
249 #endif // DEBUG
250 283
251 BailoutId ast_id = caller_code->TranslatePcOffsetToAstId(pc_offset); 284 // Determine the entry point for which this OSR request has been fired and
285 // also disarm all back edges in the calling code to stop new requests.
286 BailoutId ast_id = frame->is_interpreted()
287 ? DetermineEntryAndDisarmOSRForInterpreter(frame)
288 : DetermineEntryAndDisarmOSRForBaseline(frame);
252 DCHECK(!ast_id.IsNone()); 289 DCHECK(!ast_id.IsNone());
253 290
254 MaybeHandle<Code> maybe_result; 291 MaybeHandle<Code> maybe_result;
255 if (IsSuitableForOnStackReplacement(isolate, function)) { 292 if (IsSuitableForOnStackReplacement(isolate, function)) {
256 if (FLAG_trace_osr) { 293 if (FLAG_trace_osr) {
257 PrintF("[OSR - Compiling: "); 294 PrintF("[OSR - Compiling: ");
258 function->PrintName(); 295 function->PrintName();
259 PrintF(" at AST id %d]\n", ast_id.ToInt()); 296 PrintF(" at AST id %d]\n", ast_id.ToInt());
260 } 297 }
261 maybe_result = Compiler::GetOptimizedCodeForOSR(function, ast_id, frame); 298 maybe_result = Compiler::GetOptimizedCodeForOSR(function, ast_id, frame);
262 } 299 }
263 300
264 // Revert the patched back edge table, regardless of whether OSR succeeds.
265 BackEdgeTable::Revert(isolate, *caller_code);
266
267 // Check whether we ended up with usable optimized code. 301 // Check whether we ended up with usable optimized code.
268 Handle<Code> result; 302 Handle<Code> result;
269 if (maybe_result.ToHandle(&result) && 303 if (maybe_result.ToHandle(&result) &&
270 result->kind() == Code::OPTIMIZED_FUNCTION) { 304 result->kind() == Code::OPTIMIZED_FUNCTION) {
271 DeoptimizationInputData* data = 305 DeoptimizationInputData* data =
272 DeoptimizationInputData::cast(result->deoptimization_data()); 306 DeoptimizationInputData::cast(result->deoptimization_data());
273 307
274 if (data->OsrPcOffset()->value() >= 0) { 308 if (data->OsrPcOffset()->value() >= 0) {
275 DCHECK(BailoutId(data->OsrAstId()->value()) == ast_id); 309 DCHECK(BailoutId(data->OsrAstId()->value()) == ast_id);
276 if (FLAG_trace_osr) { 310 if (FLAG_trace_osr) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 DCHECK(is_valid_language_mode(args.smi_at(3))); 429 DCHECK(is_valid_language_mode(args.smi_at(3)));
396 LanguageMode language_mode = static_cast<LanguageMode>(args.smi_at(3)); 430 LanguageMode language_mode = static_cast<LanguageMode>(args.smi_at(3));
397 DCHECK(args[4]->IsSmi()); 431 DCHECK(args[4]->IsSmi());
398 Handle<SharedFunctionInfo> outer_info(args.at<JSFunction>(2)->shared(), 432 Handle<SharedFunctionInfo> outer_info(args.at<JSFunction>(2)->shared(),
399 isolate); 433 isolate);
400 return CompileGlobalEval(isolate, args.at<String>(1), outer_info, 434 return CompileGlobalEval(isolate, args.at<String>(1), outer_info,
401 language_mode, args.smi_at(4), args.smi_at(5)); 435 language_mode, args.smi_at(4), args.smi_at(5));
402 } 436 }
403 } // namespace internal 437 } // namespace internal
404 } // namespace v8 438 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/interpreter-assembler.cc ('k') | test/mjsunit/ignition/osr-from-bytecode.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698