Commit 5b107848 authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

[deoptimizer] Refactor --trace-deopt

Deopt tracing is both verbose and hard to read. This CL splits verbose
tracing into a new --trace-deopt-verbose flag (s.t. --trace-deopt now
emits single-line events only), refactors tracing methods to all be on
the Deoptimizer class, and clarifies output.

Bug: v8:8888
Change-Id: I3cf8e6878e5e996ca9a2e276ab8ba2d5b18d91a7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2413252
Auto-Submit: Jakob Gruber <jgruber@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarMythri Alle <mythria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69941}
parent 505ed70d
This diff is collapsed.
...@@ -537,6 +537,11 @@ class Deoptimizer : public Malloced { ...@@ -537,6 +537,11 @@ class Deoptimizer : public Malloced {
static const int kNonLazyDeoptExitSize; static const int kNonLazyDeoptExitSize;
static const int kLazyDeoptExitSize; static const int kLazyDeoptExitSize;
// Tracing.
static void TraceMarkForDeoptimization(Code code, const char* reason);
static void TraceEvictFromOptimizedCodeCache(SharedFunctionInfo sfi,
const char* reason);
private: private:
friend class FrameWriter; friend class FrameWriter;
void QueueValueForMaterialization(Address output_address, Object obj, void QueueValueForMaterialization(Address output_address, Object obj,
...@@ -545,7 +550,6 @@ class Deoptimizer : public Malloced { ...@@ -545,7 +550,6 @@ class Deoptimizer : public Malloced {
Deoptimizer(Isolate* isolate, JSFunction function, DeoptimizeKind kind, Deoptimizer(Isolate* isolate, JSFunction function, DeoptimizeKind kind,
unsigned bailout_id, Address from, int fp_to_sp_delta); unsigned bailout_id, Address from, int fp_to_sp_delta);
Code FindOptimizedCode(); Code FindOptimizedCode();
void PrintFunctionName();
void DeleteFrameDescriptions(); void DeleteFrameDescriptions();
static bool IsDeoptimizationEntry(Isolate* isolate, Address addr, static bool IsDeoptimizationEntry(Isolate* isolate, Address addr,
...@@ -583,6 +587,23 @@ class Deoptimizer : public Malloced { ...@@ -583,6 +587,23 @@ class Deoptimizer : public Malloced {
// searching all code objects). // searching all code objects).
Code FindDeoptimizingCode(Address addr); Code FindDeoptimizingCode(Address addr);
// Tracing.
bool tracing_enabled() const { return static_cast<bool>(trace_scope_); }
bool verbose_tracing_enabled() const {
return FLAG_trace_deopt_verbose && trace_scope_;
}
CodeTracer::Scope* trace_scope() const { return trace_scope_.get(); }
CodeTracer::Scope* verbose_trace_scope() const {
return FLAG_trace_deopt_verbose ? trace_scope() : nullptr;
}
void TraceDeoptBegin(int optimization_id, int node_id);
void TraceDeoptEnd(double deopt_duration);
#ifdef DEBUG
static void TraceFoundActivation(Isolate* isolate, JSFunction function);
#endif
static void TraceDeoptAll(Isolate* isolate);
static void TraceDeoptMarked(Isolate* isolate);
Isolate* isolate_; Isolate* isolate_;
JSFunction function_; JSFunction function_;
Code compiled_code_; Code compiled_code_;
...@@ -625,7 +646,7 @@ class Deoptimizer : public Malloced { ...@@ -625,7 +646,7 @@ class Deoptimizer : public Malloced {
DisallowHeapAllocation* disallow_heap_allocation_; DisallowHeapAllocation* disallow_heap_allocation_;
#endif // DEBUG #endif // DEBUG
CodeTracer::Scope* trace_scope_; std::unique_ptr<CodeTracer::Scope> trace_scope_;
static const int table_entry_size_; static const int table_entry_size_;
......
...@@ -1223,11 +1223,14 @@ DEFINE_BOOL(trace_wasm, false, "trace wasm function calls") ...@@ -1223,11 +1223,14 @@ DEFINE_BOOL(trace_wasm, false, "trace wasm function calls")
DEFINE_BOOL(lazy, true, "use lazy compilation") DEFINE_BOOL(lazy, true, "use lazy compilation")
DEFINE_BOOL(max_lazy, false, "ignore eager compilation hints") DEFINE_BOOL(max_lazy, false, "ignore eager compilation hints")
DEFINE_IMPLICATION(max_lazy, lazy) DEFINE_IMPLICATION(max_lazy, lazy)
DEFINE_BOOL(trace_opt, false, "trace lazy optimization") DEFINE_BOOL(trace_opt, false, "trace optimized compilation")
DEFINE_BOOL(trace_opt_verbose, false, "extra verbose compilation tracing") DEFINE_BOOL(trace_opt_verbose, false,
"extra verbose optimized compilation tracing")
DEFINE_IMPLICATION(trace_opt_verbose, trace_opt) DEFINE_IMPLICATION(trace_opt_verbose, trace_opt)
DEFINE_BOOL(trace_opt_stats, false, "trace lazy optimization statistics") DEFINE_BOOL(trace_opt_stats, false, "trace optimized compilation statistics")
DEFINE_BOOL(trace_deopt, false, "trace optimize function deoptimization") DEFINE_BOOL(trace_deopt, false, "trace deoptimization")
DEFINE_BOOL(trace_deopt_verbose, false, "extra verbose deoptimization tracing")
DEFINE_IMPLICATION(trace_deopt_verbose, trace_deopt)
DEFINE_BOOL(trace_file_names, false, DEFINE_BOOL(trace_file_names, false,
"include file names in trace-opt/trace-deopt output") "include file names in trace-opt/trace-deopt output")
DEFINE_BOOL(always_opt, false, "always try to optimize functions") DEFINE_BOOL(always_opt, false, "always try to optimize functions")
......
...@@ -201,17 +201,6 @@ int AbstractCode::SourceStatementPosition(int offset) { ...@@ -201,17 +201,6 @@ int AbstractCode::SourceStatementPosition(int offset) {
return statement_position; return statement_position;
} }
void Code::PrintDeoptLocation(FILE* out, const char* str, Address pc) {
Deoptimizer::DeoptInfo info = Deoptimizer::GetDeoptInfo(*this, pc);
class SourcePosition pos = info.position;
if (info.deopt_reason != DeoptimizeReason::kUnknown || pos.IsKnown()) {
PrintF(out, "%s", str);
OFStream outstr(out);
pos.Print(outstr, *this);
PrintF(out, ", %s\n", DeoptimizeReasonToString(info.deopt_reason));
}
}
bool Code::CanDeoptAt(Address pc) { bool Code::CanDeoptAt(Address pc) {
DeoptimizationData deopt_data = DeoptimizationData deopt_data =
DeoptimizationData::cast(deoptimization_data()); DeoptimizationData::cast(deoptimization_data());
...@@ -1057,27 +1046,7 @@ void DependentCode::DeoptimizeDependentCodeGroup( ...@@ -1057,27 +1046,7 @@ void DependentCode::DeoptimizeDependentCodeGroup(
void Code::SetMarkedForDeoptimization(const char* reason) { void Code::SetMarkedForDeoptimization(const char* reason) {
set_marked_for_deoptimization(true); set_marked_for_deoptimization(true);
if (FLAG_trace_deopt && Deoptimizer::TraceMarkForDeoptimization(*this, reason);
(deoptimization_data() != GetReadOnlyRoots().empty_fixed_array())) {
DeoptimizationData deopt_data =
DeoptimizationData::cast(deoptimization_data());
auto isolate = GetIsolate();
CodeTracer::Scope scope(isolate->GetCodeTracer());
PrintF(scope.file(), "[marking dependent code " V8PRIxPTR_FMT " ", ptr());
deopt_data.SharedFunctionInfo().ShortPrint(scope.file());
PrintF(" (opt #%d) for deoptimization, reason: %s]\n",
deopt_data.OptimizationId().value(), reason);
{
HandleScope scope(isolate);
PROFILE(
isolate,
CodeDependencyChangeEvent(
handle(*this, isolate),
handle(SharedFunctionInfo::cast(deopt_data.SharedFunctionInfo()),
isolate),
reason));
}
}
} }
const char* DependentCode::DependencyGroupName(DependencyGroup group) { const char* DependentCode::DependencyGroupName(DependencyGroup group) {
......
...@@ -389,7 +389,6 @@ class Code : public HeapObject { ...@@ -389,7 +389,6 @@ class Code : public HeapObject {
DECL_PRINTER(Code) DECL_PRINTER(Code)
DECL_VERIFIER(Code) DECL_VERIFIER(Code)
void PrintDeoptLocation(FILE* out, const char* str, Address pc);
bool CanDeoptAt(Address pc); bool CanDeoptAt(Address pc);
void SetMarkedForDeoptimization(const char* reason); void SetMarkedForDeoptimization(const char* reason);
......
...@@ -413,14 +413,7 @@ void FeedbackVector::EvictOptimizedCodeMarkedForDeoptimization( ...@@ -413,14 +413,7 @@ void FeedbackVector::EvictOptimizedCodeMarkedForDeoptimization(
Code code = Code::cast(slot->GetHeapObject()); Code code = Code::cast(slot->GetHeapObject());
if (code.marked_for_deoptimization()) { if (code.marked_for_deoptimization()) {
if (FLAG_trace_deopt) { Deoptimizer::TraceEvictFromOptimizedCodeCache(shared, reason);
CodeTracer::Scope scope(GetIsolate()->GetCodeTracer());
PrintF(scope.file(),
"[evicting optimized code marked for deoptimization (%s) for ",
reason);
shared.ShortPrint(scope.file());
PrintF(scope.file(), "]\n");
}
if (!code.deopt_already_counted()) { if (!code.deopt_already_counted()) {
code.set_deopt_already_counted(true); code.set_deopt_already_counted(true);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment