| OLD | NEW |
| 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/compiler.h" | 8 #include "src/compiler.h" |
| 9 #include "src/deoptimizer.h" | 9 #include "src/deoptimizer.h" |
| 10 #include "src/frames-inl.h" | 10 #include "src/frames-inl.h" |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 241 |
| 242 BailoutId ast_id = caller_code->TranslatePcOffsetToAstId(pc_offset); | 242 BailoutId ast_id = caller_code->TranslatePcOffsetToAstId(pc_offset); |
| 243 DCHECK(!ast_id.IsNone()); | 243 DCHECK(!ast_id.IsNone()); |
| 244 | 244 |
| 245 // Disable concurrent OSR for asm.js, to enable frame specialization. | 245 // Disable concurrent OSR for asm.js, to enable frame specialization. |
| 246 Compiler::ConcurrencyMode mode = (isolate->concurrent_osr_enabled() && | 246 Compiler::ConcurrencyMode mode = (isolate->concurrent_osr_enabled() && |
| 247 !function->shared()->asm_function() && | 247 !function->shared()->asm_function() && |
| 248 function->shared()->ast_node_count() > 512) | 248 function->shared()->ast_node_count() > 512) |
| 249 ? Compiler::CONCURRENT | 249 ? Compiler::CONCURRENT |
| 250 : Compiler::NOT_CONCURRENT; | 250 : Compiler::NOT_CONCURRENT; |
| 251 Handle<Code> result = Handle<Code>::null(); | |
| 252 | 251 |
| 253 OptimizedCompileJob* job = NULL; | 252 OptimizedCompileJob* job = NULL; |
| 254 if (mode == Compiler::CONCURRENT) { | 253 if (mode == Compiler::CONCURRENT) { |
| 255 // Gate the OSR entry with a stack check. | 254 // Gate the OSR entry with a stack check. |
| 256 BackEdgeTable::AddStackCheck(caller_code, pc_offset); | 255 BackEdgeTable::AddStackCheck(caller_code, pc_offset); |
| 257 // Poll already queued compilation jobs. | 256 // Poll already queued compilation jobs. |
| 258 OptimizingCompileDispatcher* dispatcher = | 257 OptimizingCompileDispatcher* dispatcher = |
| 259 isolate->optimizing_compile_dispatcher(); | 258 isolate->optimizing_compile_dispatcher(); |
| 260 if (dispatcher->IsQueuedForOSR(function, ast_id)) { | 259 if (dispatcher->IsQueuedForOSR(function, ast_id)) { |
| 261 if (FLAG_trace_osr) { | 260 if (FLAG_trace_osr) { |
| 262 PrintF("[OSR - Still waiting for queued: "); | 261 PrintF("[OSR - Still waiting for queued: "); |
| 263 function->PrintName(); | 262 function->PrintName(); |
| 264 PrintF(" at AST id %d]\n", ast_id.ToInt()); | 263 PrintF(" at AST id %d]\n", ast_id.ToInt()); |
| 265 } | 264 } |
| 266 return NULL; | 265 return NULL; |
| 267 } | 266 } |
| 268 | 267 |
| 269 job = dispatcher->FindReadyOSRCandidate(function, ast_id); | 268 job = dispatcher->FindReadyOSRCandidate(function, ast_id); |
| 270 } | 269 } |
| 271 | 270 |
| 271 MaybeHandle<Code> maybe_result; |
| 272 if (job != NULL) { | 272 if (job != NULL) { |
| 273 if (FLAG_trace_osr) { | 273 if (FLAG_trace_osr) { |
| 274 PrintF("[OSR - Found ready: "); | 274 PrintF("[OSR - Found ready: "); |
| 275 function->PrintName(); | 275 function->PrintName(); |
| 276 PrintF(" at AST id %d]\n", ast_id.ToInt()); | 276 PrintF(" at AST id %d]\n", ast_id.ToInt()); |
| 277 } | 277 } |
| 278 result = Compiler::GetConcurrentlyOptimizedCode(job); | 278 maybe_result = Compiler::GetConcurrentlyOptimizedCode(job); |
| 279 } else if (IsSuitableForOnStackReplacement(isolate, function)) { | 279 } else if (IsSuitableForOnStackReplacement(isolate, function)) { |
| 280 if (FLAG_trace_osr) { | 280 if (FLAG_trace_osr) { |
| 281 PrintF("[OSR - Compiling: "); | 281 PrintF("[OSR - Compiling: "); |
| 282 function->PrintName(); | 282 function->PrintName(); |
| 283 PrintF(" at AST id %d]\n", ast_id.ToInt()); | 283 PrintF(" at AST id %d]\n", ast_id.ToInt()); |
| 284 } | 284 } |
| 285 MaybeHandle<Code> maybe_result = Compiler::GetOptimizedCode( | 285 maybe_result = Compiler::GetOptimizedCode( |
| 286 function, mode, ast_id, | 286 function, mode, ast_id, |
| 287 (mode == Compiler::NOT_CONCURRENT) ? frame : nullptr); | 287 (mode == Compiler::NOT_CONCURRENT) ? frame : nullptr); |
| 288 Handle<Code> result; |
| 288 if (maybe_result.ToHandle(&result) && | 289 if (maybe_result.ToHandle(&result) && |
| 289 result.is_identical_to(isolate->builtins()->InOptimizationQueue())) { | 290 result.is_identical_to(isolate->builtins()->InOptimizationQueue())) { |
| 290 // Optimization is queued. Return to check later. | 291 // Optimization is queued. Return to check later. |
| 291 return NULL; | 292 return NULL; |
| 292 } | 293 } |
| 293 } | 294 } |
| 294 | 295 |
| 295 // Revert the patched back edge table, regardless of whether OSR succeeds. | 296 // Revert the patched back edge table, regardless of whether OSR succeeds. |
| 296 BackEdgeTable::Revert(isolate, *caller_code); | 297 BackEdgeTable::Revert(isolate, *caller_code); |
| 297 | 298 |
| 298 // Check whether we ended up with usable optimized code. | 299 // Check whether we ended up with usable optimized code. |
| 299 if (!result.is_null() && result->kind() == Code::OPTIMIZED_FUNCTION) { | 300 Handle<Code> result; |
| 301 if (maybe_result.ToHandle(&result) && |
| 302 result->kind() == Code::OPTIMIZED_FUNCTION) { |
| 300 DeoptimizationInputData* data = | 303 DeoptimizationInputData* data = |
| 301 DeoptimizationInputData::cast(result->deoptimization_data()); | 304 DeoptimizationInputData::cast(result->deoptimization_data()); |
| 302 | 305 |
| 303 if (data->OsrPcOffset()->value() >= 0) { | 306 if (data->OsrPcOffset()->value() >= 0) { |
| 304 DCHECK(BailoutId(data->OsrAstId()->value()) == ast_id); | 307 DCHECK(BailoutId(data->OsrAstId()->value()) == ast_id); |
| 305 if (FLAG_trace_osr) { | 308 if (FLAG_trace_osr) { |
| 306 PrintF("[OSR - Entry at AST id %d, offset %d in optimized code]\n", | 309 PrintF("[OSR - Entry at AST id %d, offset %d in optimized code]\n", |
| 307 ast_id.ToInt(), data->OsrPcOffset()->value()); | 310 ast_id.ToInt(), data->OsrPcOffset()->value()); |
| 308 } | 311 } |
| 309 // TODO(titzer): this is a massive hack to make the deopt counts | 312 // TODO(titzer): this is a massive hack to make the deopt counts |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 DCHECK(is_valid_language_mode(args.smi_at(3))); | 428 DCHECK(is_valid_language_mode(args.smi_at(3))); |
| 426 LanguageMode language_mode = static_cast<LanguageMode>(args.smi_at(3)); | 429 LanguageMode language_mode = static_cast<LanguageMode>(args.smi_at(3)); |
| 427 DCHECK(args[4]->IsSmi()); | 430 DCHECK(args[4]->IsSmi()); |
| 428 Handle<SharedFunctionInfo> outer_info(args.at<JSFunction>(2)->shared(), | 431 Handle<SharedFunctionInfo> outer_info(args.at<JSFunction>(2)->shared(), |
| 429 isolate); | 432 isolate); |
| 430 return CompileGlobalEval(isolate, args.at<String>(1), outer_info, | 433 return CompileGlobalEval(isolate, args.at<String>(1), outer_info, |
| 431 language_mode, args.smi_at(4)); | 434 language_mode, args.smi_at(4)); |
| 432 } | 435 } |
| 433 } // namespace internal | 436 } // namespace internal |
| 434 } // namespace v8 | 437 } // namespace v8 |
| OLD | NEW |