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

Unified Diff: runtime/vm/code_generator.cc

Issue 17233003: Reapply "Initial implementation of on-stack replacement (OSR)." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/assembler_x64.cc ('k') | runtime/vm/compiler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
« no previous file with comments | « runtime/vm/assembler_x64.cc ('k') | runtime/vm/compiler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698