| Index: runtime/vm/code_generator.cc
|
| diff --git a/runtime/vm/code_generator.cc b/runtime/vm/code_generator.cc
|
| index 68e167f5b05af6a3dde3535e8a83d0fdc445945d..6eec38d7d73b54463ac3217e66c65ff6d68a53e0 100644
|
| --- a/runtime/vm/code_generator.cc
|
| +++ b/runtime/vm/code_generator.cc
|
| @@ -54,6 +54,13 @@ DEFINE_FLAG(int, reoptimization_counter_threshold, 2000,
|
| DEFINE_FLAG(int, max_subtype_cache_entries, 100,
|
| "Maximum number of subtype cache entries (number of checks cached).");
|
|
|
| +#if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64)
|
| +DEFINE_FLAG(bool, use_osr, true, "Use on-stack replacement.");
|
| +#else
|
| +DEFINE_FLAG(bool, use_osr, false, "Use on-stack replacement.");
|
| +#endif
|
| +DEFINE_FLAG(bool, trace_osr, false, "Trace attempts at on-stack replacement.");
|
| +
|
|
|
| DEFINE_RUNTIME_ENTRY(TraceFunctionEntry, 1) {
|
| ASSERT(arguments.ArgCount() ==
|
| @@ -1265,6 +1272,39 @@ DEFINE_RUNTIME_ENTRY(StackOverflow, 0) {
|
| (*callback)();
|
| }
|
| }
|
| +
|
| + if (FLAG_use_osr && (interrupt_bits == 0)) {
|
| + DartFrameIterator iterator;
|
| + StackFrame* frame = iterator.NextFrame();
|
| + const Function& function = Function::Handle(frame->LookupDartFunction());
|
| + ASSERT(!function.IsNull());
|
| + if (!function.is_optimizable()) return;
|
| + intptr_t osr_id =
|
| + Code::Handle(function.unoptimized_code()).GetDeoptIdForOsr(frame->pc());
|
| + if (FLAG_trace_osr) {
|
| + OS::Print("Attempting OSR for %s at id=%"Pd"\n",
|
| + function.ToFullyQualifiedCString(),
|
| + osr_id);
|
| + }
|
| +
|
| + const Code& original_code = Code::Handle(function.CurrentCode());
|
| + const Error& error =
|
| + Error::Handle(Compiler::CompileOptimizedFunction(function, osr_id));
|
| + if (!error.IsNull()) Exceptions::PropagateError(error);
|
| +
|
| + const Code& optimized_code = Code::Handle(function.CurrentCode());
|
| + // The current code will not be changed in the case that the compiler
|
| + // bailed out during OSR compilation.
|
| + if (optimized_code.raw() != original_code.raw()) {
|
| + // The OSR code does not work for calling the function, so restore the
|
| + // unoptimized code. Patch the stack frame to return into the OSR
|
| + // code.
|
| + uword optimized_entry =
|
| + Instructions::Handle(optimized_code.instructions()).EntryPoint();
|
| + function.SetCode(original_code);
|
| + frame->set_pc(optimized_entry);
|
| + }
|
| + }
|
| }
|
|
|
|
|
| @@ -1328,9 +1368,8 @@ DEFINE_RUNTIME_ENTRY(OptimizeInvokedFunction, 1) {
|
| }
|
| const Code& optimized_code = Code::Handle(function.CurrentCode());
|
| ASSERT(!optimized_code.IsNull());
|
| - // Set usage counter for reoptimization.
|
| - function.set_usage_counter(
|
| - function.usage_counter() - FLAG_reoptimization_counter_threshold);
|
| + // Reset usage counter for reoptimization.
|
| + function.set_usage_counter(0);
|
| } else {
|
| if (FLAG_trace_failed_optimization_attempts) {
|
| OS::PrintErr("Not Optimizable: %s\n", function.ToFullyQualifiedCString());
|
|
|