Commit 23f761d3 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Truncate function names for profiling events

And other cleanups to reuse computed function names, and use
EmbeddedVector instead of ScopedVector (stack allocated instead of heap
allocated).

R=titzer@chromium.org

Change-Id: Id293946dc9aa574e7d185ff23b87068bca74549f
Reviewed-on: https://chromium-review.googlesource.com/690474Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48332}
parent 192ebc34
......@@ -4225,38 +4225,27 @@ Handle<Code> CompileJSToWasmWrapper(Isolate* isolate, wasm::WasmModule* module,
static_cast<int>(module->functions[index].sig->parameter_count());
CallDescriptor* incoming = Linkage::GetJSCallDescriptor(
&zone, false, params + 1, CallDescriptor::kNoFlags);
bool debugging =
#if DEBUG
true;
#else
FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph;
#endif
Vector<const char> func_name = ArrayVector("js-to-wasm");
#ifdef DEBUG
EmbeddedVector<char, 32> func_name;
static unsigned id = 0;
Vector<char> buffer;
if (debugging) {
buffer = Vector<char>::New(128);
int chars = SNPrintF(buffer, "js-to-wasm#%d", id);
func_name = Vector<const char>::cast(buffer.SubVector(0, chars));
}
func_name.Truncate(SNPrintF(func_name, "js-to-wasm#%d", id++));
#else
Vector<const char> func_name = CStrVector("js-to-wasm");
#endif
CompilationInfo info(func_name, isolate, &zone, Code::JS_TO_WASM_FUNCTION);
Handle<Code> code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph);
#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_opt_code && !code.is_null()) {
OFStream os(stdout);
code->Disassemble(buffer.start(), os);
code->Disassemble(func_name.start(), os);
}
#endif
if (debugging) {
buffer.Dispose();
}
if (must_record_function_compilation(isolate)) {
RecordFunctionCompilation(CodeEventListener::FUNCTION_TAG, isolate, code,
"js-to-wasm#%d:%.*s", func->func_index,
func_name.length(), func_name.start());
"%.*s", func_name.length(), func_name.start());
}
return code;
......@@ -4332,8 +4321,6 @@ Handle<Code> CompileWasmToJSWrapper(
}
}
Handle<Code> code = Handle<Code>::null();
{
if (FLAG_trace_turbo_graph) { // Simple textual RPO.
OFStream os(stdout);
os << "-- Graph after change lowering -- " << std::endl;
......@@ -4345,24 +4332,18 @@ Handle<Code> CompileWasmToJSWrapper(
if (machine.Is32()) {
incoming = GetI32WasmCallDescriptor(&zone, incoming);
}
bool debugging =
#if DEBUG
true;
#ifdef DEBUG
EmbeddedVector<char, 32> func_name;
static unsigned id = 0;
func_name.Truncate(SNPrintF(func_name, "wasm-to-js#%d", id++));
#else
FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph;
Vector<const char> func_name = CStrVector("wasm-to-js");
#endif
Vector<const char> func_name = ArrayVector("wasm-to-js");
static unsigned id = 0;
Vector<char> buffer;
if (debugging) {
buffer = Vector<char>::New(128);
int chars = SNPrintF(buffer, "wasm-to-js#%d", id);
func_name = Vector<const char>::cast(buffer.SubVector(0, chars));
}
CompilationInfo info(func_name, isolate, &zone, Code::WASM_TO_JS_FUNCTION);
code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr,
source_position_table);
Handle<Code> code = Pipeline::GenerateCodeForTesting(
&info, incoming, &graph, nullptr, source_position_table);
ValidateImportWrapperReferencesImmovables(code);
Handle<FixedArray> deopt_data =
isolate->factory()->NewFixedArray(2, TENURED);
......@@ -4377,16 +4358,13 @@ Handle<Code> CompileWasmToJSWrapper(
#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_opt_code && !code.is_null()) {
OFStream os(stdout);
code->Disassemble(buffer.start(), os);
code->Disassemble(func_name.start(), os);
}
#endif
if (debugging) {
buffer.Dispose();
}
}
if (must_record_function_compilation(isolate)) {
RecordFunctionCompilation(CodeEventListener::FUNCTION_TAG, isolate, code,
"wasm-to-js#%d", index);
"%.*s", func_name.length(), func_name.start());
}
return code;
......@@ -4495,26 +4473,27 @@ Handle<Code> CompileWasmInterpreterEntry(Isolate* isolate, uint32_t func_index,
if (machine.Is32()) {
incoming = GetI32WasmCallDescriptor(&zone, incoming);
}
EmbeddedVector<char, 32> debug_name;
int name_len =
SNPrintF(debug_name, "wasm-interpreter-entry#%d", func_index);
DCHECK(name_len > 0 && name_len < debug_name.length());
debug_name.Truncate(name_len);
DCHECK_EQ('\0', debug_name.start()[debug_name.length()]);
CompilationInfo info(debug_name, isolate, &zone,
#ifdef DEBUG
EmbeddedVector<char, 32> func_name;
func_name.Truncate(
SNPrintF(func_name, "wasm-interpreter-entry#%d", func_index));
#else
Vector<const char> func_name = CStrVector("wasm-interpreter-entry");
#endif
CompilationInfo info(func_name, isolate, &zone,
Code::WASM_INTERPRETER_ENTRY);
code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr);
#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_opt_code && !code.is_null()) {
OFStream os(stdout);
code->Disassemble(debug_name.start(), os);
code->Disassemble(func_name.start(), os);
}
#endif
if (must_record_function_compilation(isolate)) {
RecordFunctionCompilation(CodeEventListener::FUNCTION_TAG, isolate, code,
"%s", debug_name.start());
"%.*s", func_name.length(), func_name.start());
}
}
......@@ -4756,15 +4735,16 @@ MaybeHandle<Code> WasmCompilationUnit::FinishCompilation(
wasm::ErrorThrower* thrower) {
if (!ok_) {
if (graph_construction_result_.failed()) {
// Add the function as another context for the exception
ScopedVector<char> buffer(128);
// Add the function as another context for the exception.
EmbeddedVector<char, 128> message;
if (func_name_.start() == nullptr) {
SNPrintF(buffer, "Compiling wasm function #%d failed", func_index_);
SNPrintF(message, "Compiling wasm function #%d failed", func_index_);
} else {
SNPrintF(buffer, "Compiling wasm function #%d:%.*s failed", func_index_,
func_name_.length(), func_name_.start());
wasm::TruncatedUserString<> trunc_name(func_name_);
SNPrintF(message, "Compiling wasm function #%d:%.*s failed",
func_index_, trunc_name.length(), trunc_name.start());
}
thrower->CompileFailed(buffer.start(), graph_construction_result_);
thrower->CompileFailed(message.start(), graph_construction_result_);
}
return {};
......@@ -4780,9 +4760,10 @@ MaybeHandle<Code> WasmCompilationUnit::FinishCompilation(
DCHECK(!code.is_null());
if (must_record_function_compilation(isolate_)) {
wasm::TruncatedUserString<> trunc_name(func_name_);
RecordFunctionCompilation(CodeEventListener::FUNCTION_TAG, isolate_, code,
"wasm_function#%d:%.*s", func_index_,
func_name_.length(), func_name_.start());
trunc_name.length(), trunc_name.start());
}
if (FLAG_trace_wasm_decode_time) {
......
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