Commit 1d1567a3 authored by Mike Stanton's avatar Mike Stanton Committed by Commit Bot

[turbofan] Make serializer environment tracing more readable

Also, when --trace-heap-broker-verbose is on, we trace
bytecode-by-bytecode alterations to the environment.

Change-Id: I535a063cefd57f055711fdd7d7473cb63c963c7f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1622851Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Commit-Queue: Michael Stanton <mvstanton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61733}
parent 1aac6a43
...@@ -166,26 +166,6 @@ void JSHeapBroker::IncrementTracingIndentation() { ++trace_indentation_; } ...@@ -166,26 +166,6 @@ void JSHeapBroker::IncrementTracingIndentation() { ++trace_indentation_; }
void JSHeapBroker::DecrementTracingIndentation() { --trace_indentation_; } void JSHeapBroker::DecrementTracingIndentation() { --trace_indentation_; }
class TraceScope {
public:
TraceScope(JSHeapBroker* broker, const char* label)
: TraceScope(broker, static_cast<void*>(broker), label) {}
TraceScope(JSHeapBroker* broker, ObjectData* data, const char* label)
: TraceScope(broker, static_cast<void*>(data), label) {}
~TraceScope() { broker_->DecrementTracingIndentation(); }
private:
JSHeapBroker* const broker_;
TraceScope(JSHeapBroker* broker, void* self, const char* label)
: broker_(broker) {
TRACE(broker_, "Running " << label << " on " << self);
broker_->IncrementTracingIndentation();
}
};
PropertyCellData::PropertyCellData(JSHeapBroker* broker, ObjectData** storage, PropertyCellData::PropertyCellData(JSHeapBroker* broker, ObjectData** storage,
Handle<PropertyCell> object) Handle<PropertyCell> object)
: HeapObjectData(broker, storage, object), : HeapObjectData(broker, storage, object),
......
...@@ -820,6 +820,17 @@ struct FeedbackSource { ...@@ -820,6 +820,17 @@ struct FeedbackSource {
}; };
}; };
#define TRACE_BROKER(broker, x) \
do { \
if (FLAG_trace_heap_broker_verbose) broker->Trace() << x << '\n'; \
} while (false)
#define TRACE_BROKER_MISSING(broker, x) \
do { \
if (FLAG_trace_heap_broker) \
broker->Trace() << __FUNCTION__ << ": missing " << x << '\n'; \
} while (false)
class V8_EXPORT_PRIVATE JSHeapBroker { class V8_EXPORT_PRIVATE JSHeapBroker {
public: public:
JSHeapBroker(Isolate* isolate, Zone* broker_zone); JSHeapBroker(Isolate* isolate, Zone* broker_zone);
...@@ -901,6 +912,26 @@ class V8_EXPORT_PRIVATE JSHeapBroker { ...@@ -901,6 +912,26 @@ class V8_EXPORT_PRIVATE JSHeapBroker {
static const size_t kInitialRefsBucketCount = 1024; // must be power of 2 static const size_t kInitialRefsBucketCount = 1024; // must be power of 2
}; };
class TraceScope {
public:
TraceScope(JSHeapBroker* broker, const char* label)
: TraceScope(broker, static_cast<void*>(broker), label) {}
TraceScope(JSHeapBroker* broker, ObjectData* data, const char* label)
: TraceScope(broker, static_cast<void*>(data), label) {}
TraceScope(JSHeapBroker* broker, void* subject, const char* label)
: broker_(broker) {
TRACE_BROKER(broker_, "Running " << label << " on " << subject);
broker_->IncrementTracingIndentation();
}
~TraceScope() { broker_->DecrementTracingIndentation(); }
private:
JSHeapBroker* const broker_;
};
#define ASSIGN_RETURN_NO_CHANGE_IF_DATA_MISSING(something_var, \ #define ASSIGN_RETURN_NO_CHANGE_IF_DATA_MISSING(something_var, \
optionally_something) \ optionally_something) \
auto optionally_something_ = optionally_something; \ auto optionally_something_ = optionally_something; \
...@@ -916,17 +947,6 @@ Reduction NoChangeBecauseOfMissingData(JSHeapBroker* broker, ...@@ -916,17 +947,6 @@ Reduction NoChangeBecauseOfMissingData(JSHeapBroker* broker,
// compilation is finished. // compilation is finished.
bool CanInlineElementAccess(MapRef const& map); bool CanInlineElementAccess(MapRef const& map);
#define TRACE_BROKER(broker, x) \
do { \
if (FLAG_trace_heap_broker_verbose) broker->Trace() << x << '\n'; \
} while (false)
#define TRACE_BROKER_MISSING(broker, x) \
do { \
if (FLAG_trace_heap_broker) \
broker->Trace() << __FUNCTION__ << ": missing " << x << '\n'; \
} while (false)
} // namespace compiler } // namespace compiler
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
...@@ -67,16 +67,15 @@ std::ostream& operator<<(std::ostream& out, ...@@ -67,16 +67,15 @@ std::ostream& operator<<(std::ostream& out,
} }
std::ostream& operator<<(std::ostream& out, const Hints& hints) { std::ostream& operator<<(std::ostream& out, const Hints& hints) {
!hints.constants().empty() && for (Handle<Object> constant : hints.constants()) {
out << "\t\tConstants (" << hints.constants().size() << "):" << std::endl; out << " constant " << Brief(*constant) << std::endl;
for (auto x : hints.constants()) out << Brief(*x) << std::endl; }
!hints.maps().empty() && out << "\t\tMaps (" << hints.maps().size() for (Handle<Map> map : hints.maps()) {
<< "):" << std::endl; out << " map " << Brief(*map) << std::endl;
for (auto x : hints.maps()) out << Brief(*x) << std::endl; }
!hints.function_blueprints().empty() && for (FunctionBlueprint const& blueprint : hints.function_blueprints()) {
out << "\t\tBlueprints (" << hints.function_blueprints().size() out << " blueprint " << blueprint << std::endl;
<< "):" << std::endl; }
for (auto x : hints.function_blueprints()) out << x;
return out; return out;
} }
...@@ -214,21 +213,43 @@ std::ostream& operator<<( ...@@ -214,21 +213,43 @@ std::ostream& operator<<(
std::ostream& out, std::ostream& out,
const SerializerForBackgroundCompilation::Environment& env) { const SerializerForBackgroundCompilation::Environment& env) {
std::ostringstream output_stream; std::ostringstream output_stream;
output_stream << "Function ";
env.function_.shared->Name()->Print(output_stream);
output_stream << "Parameter count: " << env.parameter_count() << std::endl;
output_stream << "Register count: " << env.register_count() << std::endl;
output_stream << "Hints (" << env.environment_hints_.size() << "):\n"; for (size_t i = 0; i << env.parameter_count(); ++i) {
for (size_t i = 0; i < env.environment_hints_.size(); ++i) { Hints const& hints = env.environment_hints_[i];
if (env.environment_hints_[i].IsEmpty()) continue; if (!hints.IsEmpty()) {
output_stream << "Hints for a" << i << ":\n" << hints;
output_stream << "\tSlot " << i << std::endl; }
output_stream << env.environment_hints_[i]; }
for (size_t i = 0; i << env.register_count(); ++i) {
Hints const& hints = env.environment_hints_[env.parameter_count() + i];
if (!hints.IsEmpty()) {
output_stream << "Hints for r" << i << ":\n" << hints;
}
}
{
Hints const& hints = env.environment_hints_[env.accumulator_index()];
if (!hints.IsEmpty()) {
output_stream << "Hints for <accumulator>:\n" << hints;
}
}
{
Hints const& hints = env.environment_hints_[env.function_closure_index()];
if (!hints.IsEmpty()) {
output_stream << "Hints for <closure>:\n" << hints;
}
}
{
Hints const& hints = env.environment_hints_[env.current_context_index()];
if (!hints.IsEmpty()) {
output_stream << "Hints for <context>:\n" << hints;
}
}
{
Hints const& hints = env.return_value_hints_;
if (!hints.IsEmpty()) {
output_stream << "Hints for {return value}:\n" << hints;
}
} }
output_stream << "Return value:\n";
output_stream << env.return_value_hints_
<< "===========================================\n";
out << output_stream.str(); out << output_stream.str();
return out; return out;
...@@ -269,6 +290,10 @@ SerializerForBackgroundCompilation::SerializerForBackgroundCompilation( ...@@ -269,6 +290,10 @@ SerializerForBackgroundCompilation::SerializerForBackgroundCompilation(
environment_(new (zone) Environment(zone, broker_->isolate(), function, environment_(new (zone) Environment(zone, broker_->isolate(), function,
new_target, arguments)), new_target, arguments)),
stashed_environments_(zone) { stashed_environments_(zone) {
TraceScope tracer(
broker_, this,
"SerializerForBackgroundCompilation::SerializerForBackgroundCompilation");
TRACE_BROKER(broker_, "Initial environment:\n" << *environment_);
Handle<JSFunction> closure; Handle<JSFunction> closure;
if (function.closure().ToHandle(&closure)) { if (function.closure().ToHandle(&closure)) {
JSFunctionRef(broker, closure).Serialize(); JSFunctionRef(broker, closure).Serialize();
...@@ -276,10 +301,14 @@ SerializerForBackgroundCompilation::SerializerForBackgroundCompilation( ...@@ -276,10 +301,14 @@ SerializerForBackgroundCompilation::SerializerForBackgroundCompilation(
} }
Hints SerializerForBackgroundCompilation::Run() { Hints SerializerForBackgroundCompilation::Run() {
TraceScope tracer(broker(), this, "SerializerForBackgroundCompilation::Run");
SharedFunctionInfoRef shared(broker(), environment()->function().shared); SharedFunctionInfoRef shared(broker(), environment()->function().shared);
FeedbackVectorRef feedback_vector(broker(), FeedbackVectorRef feedback_vector(broker(),
environment()->function().feedback_vector); environment()->function().feedback_vector);
if (shared.IsSerializedForCompilation(feedback_vector)) { if (shared.IsSerializedForCompilation(feedback_vector)) {
TRACE_BROKER(broker(), "Already ran serializer for SharedFunctionInfo "
<< Brief(*shared.object())
<< ", bailing out.\n");
return Hints(zone()); return Hints(zone());
} }
shared.SetSerializedForCompilation(feedback_vector); shared.SetSerializedForCompilation(feedback_vector);
...@@ -305,6 +334,12 @@ void SerializerForBackgroundCompilation::TraverseBytecode() { ...@@ -305,6 +334,12 @@ void SerializerForBackgroundCompilation::TraverseBytecode() {
for (; !iterator.done(); iterator.Advance()) { for (; !iterator.done(); iterator.Advance()) {
MergeAfterJump(&iterator); MergeAfterJump(&iterator);
TRACE_BROKER(broker(),
"Handling bytecode: " << iterator.current_offset() << " "
<< iterator.current_bytecode());
TRACE_BROKER(broker(), "Current environment:\n" << *environment());
switch (iterator.current_bytecode()) { switch (iterator.current_bytecode()) {
#define DEFINE_BYTECODE_CASE(name) \ #define DEFINE_BYTECODE_CASE(name) \
case interpreter::Bytecode::k##name: \ case interpreter::Bytecode::k##name: \
...@@ -578,9 +613,6 @@ Hints SerializerForBackgroundCompilation::RunChildSerializer( ...@@ -578,9 +613,6 @@ Hints SerializerForBackgroundCompilation::RunChildSerializer(
return RunChildSerializer(function, new_target, padded, false); return RunChildSerializer(function, new_target, padded, false);
} }
TRACE_BROKER(broker(), "Will run child serializer with environment:\n"
<< *environment());
SerializerForBackgroundCompilation child_serializer( SerializerForBackgroundCompilation child_serializer(
broker(), dependencies(), zone(), function, new_target, arguments, broker(), dependencies(), zone(), function, new_target, arguments,
collect_source_positions()); collect_source_positions());
......
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