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

Unified Diff: src/compiler.cc

Issue 23842004: Pass PC offset into runtime when compiling for OSR. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments. Created 7 years, 3 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
Index: src/compiler.cc
diff --git a/src/compiler.cc b/src/compiler.cc
index b6de99c343f142540beff1436f77214c99d3f758..8b7e65ac96c6c1517f2993f1e57a7abfa4b4e896 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -1120,166 +1120,6 @@ Handle<Code> Compiler::InstallOptimizedCode(
}
-static uint32_t CurrentPcOffset(Isolate* isolate,
- Handle<JSFunction> function,
- Handle<Code> unoptimized) {
- JavaScriptFrameIterator it(isolate);
- JavaScriptFrame* frame = it.frame();
- ASSERT(frame->function() == *function);
- ASSERT(frame->LookupCode() == *unoptimized);
- ASSERT(unoptimized->contains(frame->pc()));
-
- // Use linear search of the unoptimized code's back edge table to find
- // the AST id matching the PC.
- return static_cast<uint32_t>(frame->pc() - unoptimized->instruction_start());
-}
-
-
-static bool IsSuitableForOnStackReplacement(Isolate* isolate,
- Handle<JSFunction> function,
- Handle<Code> unoptimized) {
- // Keep track of whether we've succeeded in optimizing.
- if (!unoptimized->optimizable()) return false;
- // If we are trying to do OSR when there are already optimized
- // activations of the function, it means (a) the function is directly or
- // indirectly recursive and (b) an optimized invocation has been
- // deoptimized so that we are currently in an unoptimized activation.
- // Check for optimized activations of this function.
- for (JavaScriptFrameIterator it(isolate); !it.done(); it.Advance()) {
- JavaScriptFrame* frame = it.frame();
- if (frame->is_optimized() && frame->function() == *function) return false;
- }
-
- return true;
-}
-
-
-Handle<Code> Compiler::CompileForOnStackReplacement(
- Handle<JSFunction> function) {
- Isolate* isolate = function->GetIsolate();
- Handle<Code> unoptimized(function->shared()->code(), isolate);
-
- Deoptimizer::RevertInterruptCode(isolate, *unoptimized);
- if (FLAG_trace_osr) {
- PrintF("[OSR - restored original interrupt calls in ");
- function->PrintName();
- PrintF("]\n");
- }
-
- if (IsSuitableForOnStackReplacement(isolate, function, unoptimized)) {
- // Find the PC offset in unoptimized code and translate to an AST id.
- uint32_t pc_offset = CurrentPcOffset(isolate, function, unoptimized);
- BailoutId ast_id = unoptimized->TranslatePcOffsetToAstId(pc_offset);
- ASSERT(!ast_id.IsNone());
- if (FLAG_trace_osr) {
- PrintF("[OSR - replacing at AST id %d in ", ast_id.ToInt());
- function->PrintName();
- PrintF("]\n");
- }
-
- // Attempt OSR compilation.
- Handle<Code> result = JSFunction::CompileOsr(
- function, ast_id, CLEAR_EXCEPTION);
-
- if (!result.is_null() && result->kind() == Code::OPTIMIZED_FUNCTION) {
- // OSR compilation succeeded.
- DeoptimizationInputData* data =
- DeoptimizationInputData::cast(result->deoptimization_data());
- if (FLAG_trace_osr) {
- PrintF("[OSR - entry, offset %d in optimized code]\n",
- data->OsrPcOffset()->value());
- }
- ASSERT(BailoutId(data->OsrAstId()->value()) == ast_id);
- return result;
- }
- }
-
- if (FLAG_trace_osr) {
- PrintF("[OSR - attempt failed for ");
- function->PrintName();
- PrintF("]\n");
- }
- return Handle<Code>::null();
-}
-
-
-Handle<Code> Compiler::CompileForConcurrentOSR(Handle<JSFunction> function) {
- Isolate* isolate = function->GetIsolate();
- Handle<Code> unoptimized(function->shared()->code(), isolate);
-
- uint32_t pc_offset = CurrentPcOffset(isolate, function, unoptimized);
-
- if (isolate->optimizing_compiler_thread()->
- IsQueuedForOSR(function, pc_offset)) {
- // Still waiting for the optimizing compiler thread to finish. Carry on.
- if (FLAG_trace_osr) {
- PrintF("[COSR - polling recompile tasks for ");
- function->PrintName();
- PrintF("]\n");
- }
- return Handle<Code>::null();
- }
-
- OptimizingCompiler* compiler = isolate->optimizing_compiler_thread()->
- FindReadyOSRCandidate(function, pc_offset);
-
- if (compiler != NULL) {
- BailoutId ast_id = compiler->info()->osr_ast_id();
-
- if (FLAG_trace_osr) {
- PrintF("[COSR - optimization complete for ");
- function->PrintName();
- PrintF(", restoring interrupt calls]\n");
- }
- Deoptimizer::RevertInterruptCode(isolate, *unoptimized);
-
- // TODO(titzer): don't install the OSR code into the function.
- Handle<Code> result = InstallOptimizedCode(compiler);
-
- isolate->optimizing_compiler_thread()->RemoveStaleOSRCandidates();
-
- if (result.is_null()) {
- if (FLAG_trace_osr) {
- PrintF("[COSR - optimization failed for ");
- function->PrintName();
- PrintF("]\n");
- }
- return Handle<Code>::null();
- }
- // Check the result matches our expectations, and don't use it otherwise.
- if (result->kind() == Code::OPTIMIZED_FUNCTION) {
- DeoptimizationInputData* data =
- DeoptimizationInputData::cast(result->deoptimization_data());
-
- if (data->OsrPcOffset()->value() >= 0) {
- ASSERT(BailoutId(data->OsrAstId()->value()) == ast_id);
- if (FLAG_trace_osr) {
- PrintF("[COSR - entry at AST id %d, offset %d in optimized code]\n",
- ast_id.ToInt(), data->OsrPcOffset()->value());
- }
- return result;
- }
- }
- return Handle<Code>::null();
- }
-
- if (!IsSuitableForOnStackReplacement(isolate, function, unoptimized)) {
- if (FLAG_trace_osr) {
- PrintF("[COSR - ");
- function->PrintName();
- PrintF(" is unsuitable, restoring interrupt calls]\n");
- }
- Deoptimizer::RevertInterruptCode(isolate, *unoptimized);
- return Handle<Code>::null();
- }
-
- if (!RecompileConcurrent(function, pc_offset)) {
- Deoptimizer::RevertInterruptCode(isolate, *unoptimized);
- }
- return Handle<Code>::null();
-}
-
-
Handle<SharedFunctionInfo> Compiler::BuildFunctionInfo(FunctionLiteral* literal,
Handle<Script> script) {
// Precondition: code has been parsed and scopes have been analyzed.
« no previous file with comments | « src/compiler.h ('k') | src/ia32/builtins-ia32.cc » ('j') | src/runtime-profiler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698