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

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

Issue 2184553003: Revert of [interpreter] Add explicit OSR polling bytecode. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@local_interpreter-osr-1
Patch Set: 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 {
221 220
222 BailoutId DetermineEntryAndDisarmOSRForBaseline(JavaScriptFrame* frame) { 221 RUNTIME_FUNCTION(Runtime_CompileForOnStackReplacement) {
223 Handle<Code> caller_code(frame->function()->shared()->code()); 222 HandleScope scope(isolate);
223 DCHECK(args.length() == 1);
224 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
225 Handle<Code> caller_code(function->shared()->code());
224 226
225 // Passing the PC in the JavaScript frame from the caller directly is 227 // We're not prepared to handle a function with arguments object.
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
226 // not GC safe, so we walk the stack to get it. 233 // not GC safe, so we walk the stack to get it.
234 JavaScriptFrameIterator it(isolate);
235 JavaScriptFrame* frame = it.frame();
227 if (!caller_code->contains(frame->pc())) { 236 if (!caller_code->contains(frame->pc())) {
228 // Code on the stack may not be the code object referenced by the shared 237 // Code on the stack may not be the code object referenced by the shared
229 // function info. It may have been replaced to include deoptimization data. 238 // function info. It may have been replaced to include deoptimization data.
230 caller_code = Handle<Code>(frame->LookupCode()); 239 caller_code = Handle<Code>(frame->LookupCode());
231 } 240 }
232 241
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
240 uint32_t pc_offset = 242 uint32_t pc_offset =
241 static_cast<uint32_t>(frame->pc() - caller_code->instruction_start()); 243 static_cast<uint32_t>(frame->pc() - caller_code->instruction_start());
242 244
243 return caller_code->TranslatePcOffsetToAstId(pc_offset); 245 #ifdef DEBUG
244 } 246 DCHECK_EQ(frame->function(), *function);
247 DCHECK_EQ(frame->LookupCode(), *caller_code);
248 DCHECK(caller_code->contains(frame->pc()));
249 #endif // DEBUG
245 250
246 BailoutId DetermineEntryAndDisarmOSRForInterpreter(JavaScriptFrame* frame) { 251 BailoutId ast_id = caller_code->TranslatePcOffsetToAstId(pc_offset);
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();
282 DCHECK_EQ(frame->function(), *function);
283
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);
289 DCHECK(!ast_id.IsNone()); 252 DCHECK(!ast_id.IsNone());
290 253
291 MaybeHandle<Code> maybe_result; 254 MaybeHandle<Code> maybe_result;
292 if (IsSuitableForOnStackReplacement(isolate, function)) { 255 if (IsSuitableForOnStackReplacement(isolate, function)) {
293 if (FLAG_trace_osr) { 256 if (FLAG_trace_osr) {
294 PrintF("[OSR - Compiling: "); 257 PrintF("[OSR - Compiling: ");
295 function->PrintName(); 258 function->PrintName();
296 PrintF(" at AST id %d]\n", ast_id.ToInt()); 259 PrintF(" at AST id %d]\n", ast_id.ToInt());
297 } 260 }
298 maybe_result = Compiler::GetOptimizedCodeForOSR(function, ast_id, frame); 261 maybe_result = Compiler::GetOptimizedCodeForOSR(function, ast_id, frame);
299 } 262 }
300 263
264 // Revert the patched back edge table, regardless of whether OSR succeeds.
265 BackEdgeTable::Revert(isolate, *caller_code);
266
301 // Check whether we ended up with usable optimized code. 267 // Check whether we ended up with usable optimized code.
302 Handle<Code> result; 268 Handle<Code> result;
303 if (maybe_result.ToHandle(&result) && 269 if (maybe_result.ToHandle(&result) &&
304 result->kind() == Code::OPTIMIZED_FUNCTION) { 270 result->kind() == Code::OPTIMIZED_FUNCTION) {
305 DeoptimizationInputData* data = 271 DeoptimizationInputData* data =
306 DeoptimizationInputData::cast(result->deoptimization_data()); 272 DeoptimizationInputData::cast(result->deoptimization_data());
307 273
308 if (data->OsrPcOffset()->value() >= 0) { 274 if (data->OsrPcOffset()->value() >= 0) {
309 DCHECK(BailoutId(data->OsrAstId()->value()) == ast_id); 275 DCHECK(BailoutId(data->OsrAstId()->value()) == ast_id);
310 if (FLAG_trace_osr) { 276 if (FLAG_trace_osr) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 DCHECK(is_valid_language_mode(args.smi_at(3))); 395 DCHECK(is_valid_language_mode(args.smi_at(3)));
430 LanguageMode language_mode = static_cast<LanguageMode>(args.smi_at(3)); 396 LanguageMode language_mode = static_cast<LanguageMode>(args.smi_at(3));
431 DCHECK(args[4]->IsSmi()); 397 DCHECK(args[4]->IsSmi());
432 Handle<SharedFunctionInfo> outer_info(args.at<JSFunction>(2)->shared(), 398 Handle<SharedFunctionInfo> outer_info(args.at<JSFunction>(2)->shared(),
433 isolate); 399 isolate);
434 return CompileGlobalEval(isolate, args.at<String>(1), outer_info, 400 return CompileGlobalEval(isolate, args.at<String>(1), outer_info,
435 language_mode, args.smi_at(4), args.smi_at(5)); 401 language_mode, args.smi_at(4), args.smi_at(5));
436 } 402 }
437 } // namespace internal 403 } // namespace internal
438 } // namespace v8 404 } // 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