From f6f47981899db09e86d36a51234622df39eea1b2 Mon Sep 17 00:00:00 2001 From: "svenpanne@chromium.org" Date: Tue, 28 Aug 2012 07:18:06 +0000 Subject: [PATCH] Print reason for disabling optimization. Kill --trace-bailout flag. The reason for disabling optimization of a given function is carried around in CompilationInfo. The new mechanism is general enough that --trace-opt now subsumes everything --trace-bailout could print, so we nuked the latter flag. Review URL: https://chromiumcodereview.appspot.com/10868106 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12391 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/lithium-arm.cc | 13 ++----------- src/arm/lithium-arm.h | 2 +- src/arm/lithium-codegen-arm.cc | 13 ++----------- src/arm/lithium-codegen-arm.h | 2 +- src/compiler.cc | 23 +++++++++++++++++------ src/compiler.h | 8 +++++++- src/flag-definitions.h | 2 -- src/hydrogen.cc | 10 +++------- src/ia32/lithium-codegen-ia32.cc | 13 ++----------- src/ia32/lithium-codegen-ia32.h | 2 +- src/ia32/lithium-ia32.cc | 13 ++----------- src/ia32/lithium-ia32.h | 2 +- src/lithium.cc | 11 ++++------- src/mips/lithium-codegen-mips.cc | 15 +++------------ src/mips/lithium-codegen-mips.h | 2 +- src/mips/lithium-mips.cc | 13 ++----------- src/mips/lithium-mips.h | 2 +- src/objects.cc | 5 +++-- src/objects.h | 2 +- src/x64/lithium-codegen-x64.cc | 13 ++----------- src/x64/lithium-codegen-x64.h | 2 +- src/x64/lithium-x64.cc | 13 ++----------- src/x64/lithium-x64.h | 2 +- 23 files changed, 60 insertions(+), 123 deletions(-) diff --git a/src/arm/lithium-arm.cc b/src/arm/lithium-arm.cc index e4616c9..2ddabfc 100644 --- a/src/arm/lithium-arm.cc +++ b/src/arm/lithium-arm.cc @@ -441,17 +441,8 @@ LPlatformChunk* LChunkBuilder::Build() { } -void LChunkBuilder::Abort(const char* format, ...) { - if (FLAG_trace_bailout) { - SmartArrayPointer name( - info()->shared_info()->DebugName()->ToCString()); - PrintF("Aborting LPlatformChunk building in @\"%s\": ", *name); - va_list arguments; - va_start(arguments, format); - OS::VPrint(format, arguments); - va_end(arguments); - PrintF("\n"); - } +void LChunkBuilder::Abort(const char* reason) { + info()->set_bailout_reason(reason); status_ = ABORTED; } diff --git a/src/arm/lithium-arm.h b/src/arm/lithium-arm.h index 33d165e..782dd61 100644 --- a/src/arm/lithium-arm.h +++ b/src/arm/lithium-arm.h @@ -2322,7 +2322,7 @@ class LChunkBuilder BASE_EMBEDDED { bool is_done() const { return status_ == DONE; } bool is_aborted() const { return status_ == ABORTED; } - void Abort(const char* format, ...); + void Abort(const char* reason); // Methods for getting operands for Use / Define / Temp. LUnallocated* ToUnallocated(Register reg); diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc index 59a8804..e2aa254 100644 --- a/src/arm/lithium-codegen-arm.cc +++ b/src/arm/lithium-codegen-arm.cc @@ -91,17 +91,8 @@ void LCodeGen::FinishCode(Handle code) { } -void LCodeGen::Abort(const char* format, ...) { - if (FLAG_trace_bailout) { - SmartArrayPointer name( - info()->shared_info()->DebugName()->ToCString()); - PrintF("Aborting LCodeGen in @\"%s\": ", *name); - va_list arguments; - va_start(arguments, format); - OS::VPrint(format, arguments); - va_end(arguments); - PrintF("\n"); - } +void LCodeGen::Abort(const char* reason) { + info()->set_bailout_reason(reason); status_ = ABORTED; } diff --git a/src/arm/lithium-codegen-arm.h b/src/arm/lithium-codegen-arm.h index 7938b6d..fd4a2a5 100644 --- a/src/arm/lithium-codegen-arm.h +++ b/src/arm/lithium-codegen-arm.h @@ -191,7 +191,7 @@ class LCodeGen BASE_EMBEDDED { int GetStackSlotCount() const { return chunk()->spill_slot_count(); } int GetParameterCount() const { return scope()->num_parameters(); } - void Abort(const char* format, ...); + void Abort(const char* reason); void Comment(const char* format, ...); void AddDeferredCode(LDeferredCode* code) { deferred_.Add(code, zone()); } diff --git a/src/compiler.cc b/src/compiler.cc index 88510d5..1087d00 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -242,6 +242,7 @@ OptimizingCompiler::Status OptimizingCompiler::CreateGraph() { const int kMaxOptCount = FLAG_deopt_every_n_times == 0 ? FLAG_max_opt_count : 1000; if (info()->shared_info()->opt_count() > kMaxOptCount) { + info()->set_bailout_reason("optimized too many times"); return AbortOptimization(); } @@ -253,11 +254,16 @@ OptimizingCompiler::Status OptimizingCompiler::CreateGraph() { // The encoding is as a signed value, with parameters and receiver using // the negative indices and locals the non-negative ones. const int parameter_limit = -LUnallocated::kMinFixedIndex; - const int locals_limit = LUnallocated::kMaxFixedIndex; Scope* scope = info()->scope(); - if ((scope->num_parameters() + 1) > parameter_limit || - (!info()->osr_ast_id().IsNone() && - scope->num_parameters() + 1 + scope->num_stack_slots() > locals_limit)) { + if ((scope->num_parameters() + 1) > parameter_limit) { + info()->set_bailout_reason("too many parameters"); + return AbortOptimization(); + } + + const int locals_limit = LUnallocated::kMaxFixedIndex; + if (!info()->osr_ast_id().IsNone() && + scope->num_parameters() + 1 + scope->num_stack_slots() > locals_limit) { + info()->set_bailout_reason("too many parameters/locals"); return AbortOptimization(); } @@ -367,7 +373,10 @@ OptimizingCompiler::Status OptimizingCompiler::GenerateAndInstallCode() { ASSERT(chunk_ != NULL); ASSERT(graph_ != NULL); Handle optimized_code = chunk_->Codegen(); - if (optimized_code.is_null()) return AbortOptimization(); + if (optimized_code.is_null()) { + info()->set_bailout_reason("code generation failed"); + return AbortOptimization(); + } info()->SetCode(optimized_code); RecordOptimizationStats(); return SetLastStatus(SUCCEEDED); @@ -637,7 +646,7 @@ Handle Compiler::CompileEval(Handle source, if (!result.is_null()) { // Explicitly disable optimization for eval code. We're not yet prepared // to handle eval-code in the optimizing compiler. - result->DisableOptimization(); + result->DisableOptimization("eval"); // If caller is strict mode, the result must be in strict mode or // extended mode as well, but not the other way around. Consider: @@ -880,6 +889,8 @@ void Compiler::InstallOptimizedCode(OptimizingCompiler* optimizing_compiler) { // the unoptimized code. OptimizingCompiler::Status status = optimizing_compiler->last_status(); if (status != OptimizingCompiler::SUCCEEDED) { + optimizing_compiler->info()->set_bailout_reason( + "failed/bailed out last time"); status = optimizing_compiler->AbortOptimization(); } else { status = optimizing_compiler->GenerateAndInstallCode(); diff --git a/src/compiler.h b/src/compiler.h index 5d220d3..9396624 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -184,6 +184,9 @@ class CompilationInfo { SaveHandle(&script_); } + const char* bailout_reason() const { return bailout_reason_; } + void set_bailout_reason(const char* reason) { bailout_reason_ = reason; } + private: Isolate* isolate_; @@ -208,6 +211,7 @@ class CompilationInfo { ASSERT(language_mode() == CLASSIC_MODE); SetLanguageMode(shared_info_->language_mode()); } + set_bailout_reason("unknown"); } void SetMode(Mode mode) { @@ -280,6 +284,8 @@ class CompilationInfo { } } + const char* bailout_reason_; + DISALLOW_COPY_AND_ASSIGN(CompilationInfo); }; @@ -360,7 +366,7 @@ class OptimizingCompiler: public ZoneObject { MUST_USE_RESULT Status AbortOptimization() { info_->AbortOptimization(); - info_->shared_info()->DisableOptimization(); + info_->shared_info()->DisableOptimization(info_->bailout_reason()); return SetLastStatus(BAILED_OUT); } diff --git a/src/flag-definitions.h b/src/flag-definitions.h index b44246a..5eef12f 100644 --- a/src/flag-definitions.h +++ b/src/flag-definitions.h @@ -325,8 +325,6 @@ DEFINE_int(min_preparse_length, 1024, "minimum length for automatic enable preparsing") DEFINE_bool(always_full_compiler, false, "try to use the dedicated run-once backend for all code") -DEFINE_bool(trace_bailout, false, - "print reasons for falling back to using the classic V8 backend") DEFINE_int(max_opt_count, 10, "maximum number of optimization attempts before giving up.") diff --git a/src/hydrogen.cc b/src/hydrogen.cc index 66763d3..68cd89f 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -3199,11 +3199,7 @@ void TestContext::BuildBranch(HValue* value) { void HGraphBuilder::Bailout(const char* reason) { - if (FLAG_trace_bailout) { - SmartArrayPointer name( - info()->shared_info()->DebugName()->ToCString()); - PrintF("Bailout in HGraphBuilder: @\"%s\": %s\n", *name, reason); - } + info()->set_bailout_reason(reason); SetStackOverflow(); } @@ -6996,7 +6992,7 @@ bool HGraphBuilder::TryInline(CallKind call_kind, if (target_info.isolate()->has_pending_exception()) { // Parse or scope error, never optimize this function. SetStackOverflow(); - target_shared->DisableOptimization(); + target_shared->DisableOptimization("parse/scope error"); } TraceInline(target, caller, "parse failure"); return false; @@ -7151,7 +7147,7 @@ bool HGraphBuilder::TryInline(CallKind call_kind, // Bail out if the inline function did, as we cannot residualize a call // instead. TraceInline(target, caller, "inline graph construction failed"); - target_shared->DisableOptimization(); + target_shared->DisableOptimization("inlining bailed out"); inline_bailout_ = true; delete target_state; return true; diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc index da003de..5ef0739 100644 --- a/src/ia32/lithium-codegen-ia32.cc +++ b/src/ia32/lithium-codegen-ia32.cc @@ -99,17 +99,8 @@ void LCodeGen::FinishCode(Handle code) { } -void LCodeGen::Abort(const char* format, ...) { - if (FLAG_trace_bailout) { - SmartArrayPointer name( - info()->shared_info()->DebugName()->ToCString()); - PrintF("Aborting LCodeGen in @\"%s\": ", *name); - va_list arguments; - va_start(arguments, format); - OS::VPrint(format, arguments); - va_end(arguments); - PrintF("\n"); - } +void LCodeGen::Abort(const char* reason) { + info()->set_bailout_reason(reason); status_ = ABORTED; } diff --git a/src/ia32/lithium-codegen-ia32.h b/src/ia32/lithium-codegen-ia32.h index ab74cc7..9058ede 100644 --- a/src/ia32/lithium-codegen-ia32.h +++ b/src/ia32/lithium-codegen-ia32.h @@ -171,7 +171,7 @@ class LCodeGen BASE_EMBEDDED { int GetStackSlotCount() const { return chunk()->spill_slot_count(); } int GetParameterCount() const { return scope()->num_parameters(); } - void Abort(const char* format, ...); + void Abort(const char* reason); void Comment(const char* format, ...); void AddDeferredCode(LDeferredCode* code) { deferred_.Add(code, zone()); } diff --git a/src/ia32/lithium-ia32.cc b/src/ia32/lithium-ia32.cc index e5b69c1..3f72a9e 100644 --- a/src/ia32/lithium-ia32.cc +++ b/src/ia32/lithium-ia32.cc @@ -461,17 +461,8 @@ LPlatformChunk* LChunkBuilder::Build() { } -void LChunkBuilder::Abort(const char* format, ...) { - if (FLAG_trace_bailout) { - SmartArrayPointer name( - info()->shared_info()->DebugName()->ToCString()); - PrintF("Aborting LPlatformChunk building in @\"%s\": ", *name); - va_list arguments; - va_start(arguments, format); - OS::VPrint(format, arguments); - va_end(arguments); - PrintF("\n"); - } +void LChunkBuilder::Abort(const char* reason) { + info()->set_bailout_reason(reason); status_ = ABORTED; } diff --git a/src/ia32/lithium-ia32.h b/src/ia32/lithium-ia32.h index 8e500f4..be1940b 100644 --- a/src/ia32/lithium-ia32.h +++ b/src/ia32/lithium-ia32.h @@ -2437,7 +2437,7 @@ class LChunkBuilder BASE_EMBEDDED { bool is_done() const { return status_ == DONE; } bool is_aborted() const { return status_ == ABORTED; } - void Abort(const char* format, ...); + void Abort(const char* reason); // Methods for getting operands for Use / Define / Temp. LUnallocated* ToUnallocated(Register reg); diff --git a/src/lithium.cc b/src/lithium.cc index f19ba00..eb2198d 100644 --- a/src/lithium.cc +++ b/src/lithium.cc @@ -395,21 +395,18 @@ LChunk* LChunk::NewChunk(HGraph* graph) { AssertNoAllocation no_gc; int values = graph->GetMaximumValueID(); + CompilationInfo* info = graph->info(); if (values > LUnallocated::kMaxVirtualRegisters) { - if (FLAG_trace_bailout) { - PrintF("Not enough virtual registers for (values).\n"); - } + info->set_bailout_reason("not enough virtual registers for values"); return NULL; } LAllocator allocator(values, graph); - LChunkBuilder builder(graph->info(), graph, &allocator); + LChunkBuilder builder(info, graph, &allocator); LChunk* chunk = builder.Build(); if (chunk == NULL) return NULL; if (!allocator.Allocate(chunk)) { - if (FLAG_trace_bailout) { - PrintF("Not enough virtual registers (regalloc).\n"); - } + info->set_bailout_reason("not enough virtual registers (regalloc)"); return NULL; } diff --git a/src/mips/lithium-codegen-mips.cc b/src/mips/lithium-codegen-mips.cc index aaca69f..50fe4ac 100644 --- a/src/mips/lithium-codegen-mips.cc +++ b/src/mips/lithium-codegen-mips.cc @@ -89,17 +89,8 @@ void LCodeGen::FinishCode(Handle code) { } -void LCodeGen::Abort(const char* format, ...) { - if (FLAG_trace_bailout) { - SmartArrayPointer name( - info()->shared_info()->DebugName()->ToCString()); - PrintF("Aborting LCodeGen in @\"%s\": ", *name); - va_list arguments; - va_start(arguments, format); - OS::VPrint(format, arguments); - va_end(arguments); - PrintF("\n"); - } +void LChunkBuilder::Abort(const char* reason) { + info()->set_bailout_reason(reason); status_ = ABORTED; } @@ -261,7 +252,7 @@ bool LCodeGen::GenerateDeferredCode() { bool LCodeGen::GenerateDeoptJumpTable() { // TODO(plind): not clear that this will have advantage for MIPS. // Skipping it for now. Raised issue #100 for this. - Abort("Unimplemented: %s", "GenerateDeoptJumpTable"); + Abort("Unimplemented: GenerateDeoptJumpTable"); return false; } diff --git a/src/mips/lithium-codegen-mips.h b/src/mips/lithium-codegen-mips.h index 7b10d9f..b811ab6 100644 --- a/src/mips/lithium-codegen-mips.h +++ b/src/mips/lithium-codegen-mips.h @@ -183,7 +183,7 @@ class LCodeGen BASE_EMBEDDED { int GetStackSlotCount() const { return chunk()->spill_slot_count(); } int GetParameterCount() const { return scope()->num_parameters(); } - void Abort(const char* format, ...); + void Abort(const char* reason); void Comment(const char* format, ...); void AddDeferredCode(LDeferredCode* code) { deferred_.Add(code, zone()); } diff --git a/src/mips/lithium-mips.cc b/src/mips/lithium-mips.cc index 93100d0..c9a5064 100644 --- a/src/mips/lithium-mips.cc +++ b/src/mips/lithium-mips.cc @@ -441,17 +441,8 @@ LPlatformChunk* LChunkBuilder::Build() { } -void LChunkBuilder::Abort(const char* format, ...) { - if (FLAG_trace_bailout) { - SmartArrayPointer name( - info()->shared_info()->DebugName()->ToCString()); - PrintF("Aborting LPlatformChunk building in @\"%s\": ", *name); - va_list arguments; - va_start(arguments, format); - OS::VPrint(format, arguments); - va_end(arguments); - PrintF("\n"); - } +void LCodeGen::Abort(const char* reason) { + info()->set_bailout_reason(reason); status_ = ABORTED; } diff --git a/src/mips/lithium-mips.h b/src/mips/lithium-mips.h index d196ab9..8ea8da4 100644 --- a/src/mips/lithium-mips.h +++ b/src/mips/lithium-mips.h @@ -2262,7 +2262,7 @@ class LChunkBuilder BASE_EMBEDDED { bool is_done() const { return status_ == DONE; } bool is_aborted() const { return status_ == ABORTED; } - void Abort(const char* format, ...); + void Abort(const char* reason); // Methods for getting operands for Use / Define / Temp. LUnallocated* ToUnallocated(Register reg); diff --git a/src/objects.cc b/src/objects.cc index fbb73a7..d21ae8f 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -7791,7 +7791,7 @@ void SharedFunctionInfo::EnableDeoptimizationSupport(Code* recompiled) { } -void SharedFunctionInfo::DisableOptimization() { +void SharedFunctionInfo::DisableOptimization(const char* reason) { // Disable optimization for the shared function info and mark the // code as non-optimizable. The marker on the shared function info // is there because we flush non-optimized code thereby loosing the @@ -7807,7 +7807,8 @@ void SharedFunctionInfo::DisableOptimization() { code()->set_optimizable(false); } if (FLAG_trace_opt) { - PrintF("[disabled optimization for %s]\n", *DebugName()->ToCString()); + PrintF("[disabled optimization for %s, reason: %s]\n", + *DebugName()->ToCString(), reason); } } diff --git a/src/objects.h b/src/objects.h index a1c5047..bc133a8 100644 --- a/src/objects.h +++ b/src/objects.h @@ -5645,7 +5645,7 @@ class SharedFunctionInfo: public HeapObject { // Disable (further) attempted optimization of all functions sharing this // shared function info. - void DisableOptimization(); + void DisableOptimization(const char* reason); // Lookup the bailout ID and ASSERT that it exists in the non-optimized // code, returns whether it asserted (i.e., always true if assertions are diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc index 9d2b6aa..df2dd85 100644 --- a/src/x64/lithium-codegen-x64.cc +++ b/src/x64/lithium-codegen-x64.cc @@ -92,17 +92,8 @@ void LCodeGen::FinishCode(Handle code) { } -void LCodeGen::Abort(const char* format, ...) { - if (FLAG_trace_bailout) { - SmartArrayPointer name( - info()->shared_info()->DebugName()->ToCString()); - PrintF("Aborting LCodeGen in @\"%s\": ", *name); - va_list arguments; - va_start(arguments, format); - OS::VPrint(format, arguments); - va_end(arguments); - PrintF("\n"); - } +void LChunkBuilder::Abort(const char* reason) { + info()->set_bailout_reason(reason); status_ = ABORTED; } diff --git a/src/x64/lithium-codegen-x64.h b/src/x64/lithium-codegen-x64.h index bfa721a..c12f4e8 100644 --- a/src/x64/lithium-codegen-x64.h +++ b/src/x64/lithium-codegen-x64.h @@ -157,7 +157,7 @@ class LCodeGen BASE_EMBEDDED { int GetStackSlotCount() const { return chunk()->spill_slot_count(); } int GetParameterCount() const { return scope()->num_parameters(); } - void Abort(const char* format, ...); + void Abort(const char* reason); void Comment(const char* format, ...); void AddDeferredCode(LDeferredCode* code) { deferred_.Add(code, zone()); } diff --git a/src/x64/lithium-x64.cc b/src/x64/lithium-x64.cc index 6133bde..bc6eb3d 100644 --- a/src/x64/lithium-x64.cc +++ b/src/x64/lithium-x64.cc @@ -444,17 +444,8 @@ LPlatformChunk* LChunkBuilder::Build() { } -void LChunkBuilder::Abort(const char* format, ...) { - if (FLAG_trace_bailout) { - SmartArrayPointer name( - info()->shared_info()->DebugName()->ToCString()); - PrintF("Aborting LPlatformChunk building in @\"%s\": ", *name); - va_list arguments; - va_start(arguments, format); - OS::VPrint(format, arguments); - va_end(arguments); - PrintF("\n"); - } +void LCodeGen::Abort(const char* reason) { + info()->set_bailout_reason(reason); status_ = ABORTED; } diff --git a/src/x64/lithium-x64.h b/src/x64/lithium-x64.h index c6f06f5..449c2a1 100644 --- a/src/x64/lithium-x64.h +++ b/src/x64/lithium-x64.h @@ -2277,7 +2277,7 @@ class LChunkBuilder BASE_EMBEDDED { bool is_done() const { return status_ == DONE; } bool is_aborted() const { return status_ == ABORTED; } - void Abort(const char* format, ...); + void Abort(const char* reason); // Methods for getting operands for Use / Define / Temp. LUnallocated* ToUnallocated(Register reg); -- 2.7.4