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