Commit c32b2020 authored by clemensh's avatar clemensh Committed by Commit bot

Pass debug name as Vector instead of const char*

This allows to also pass non-null-terminated values, and values containing null
characters. Both might happen in wasm.

R=titzer@chromium.org

Review URL: https://codereview.chromium.org/1911313002

Cr-Commit-Position: refs/heads/master@{#35795}
parent eee6ddb2
......@@ -278,8 +278,8 @@ static Handle<Code> DoGenerateCode(Stub* stub) {
timer.Start();
}
Zone zone(isolate->allocator());
CompilationInfo info(CodeStub::MajorName(stub->MajorKey()), isolate, &zone,
stub->GetCodeFlags());
CompilationInfo info(CStrVector(CodeStub::MajorName(stub->MajorKey())),
isolate, &zone, stub->GetCodeFlags());
// Parameter count is number of stack parameters.
int parameter_count = descriptor.GetStackParameterCount();
if (descriptor.function_mode() == NOT_JS_FUNCTION_STUB_MODE) {
......
......@@ -121,8 +121,8 @@ bool CompilationInfo::has_shared_info() const {
CompilationInfo::CompilationInfo(ParseInfo* parse_info,
Handle<JSFunction> closure)
: CompilationInfo(parse_info, nullptr, Code::ComputeFlags(Code::FUNCTION),
BASE, parse_info->isolate(), parse_info->zone()) {
: CompilationInfo(parse_info, {}, Code::ComputeFlags(Code::FUNCTION), BASE,
parse_info->isolate(), parse_info->zone()) {
closure_ = closure;
// Compiling for the snapshot typically results in different code than
......@@ -139,12 +139,13 @@ CompilationInfo::CompilationInfo(ParseInfo* parse_info,
if (FLAG_turbo_splitting) MarkAsSplittingEnabled();
}
CompilationInfo::CompilationInfo(const char* debug_name, Isolate* isolate,
Zone* zone, Code::Flags code_flags)
CompilationInfo::CompilationInfo(Vector<const char> debug_name,
Isolate* isolate, Zone* zone,
Code::Flags code_flags)
: CompilationInfo(nullptr, debug_name, code_flags, STUB, isolate, zone) {}
CompilationInfo::CompilationInfo(ParseInfo* parse_info, const char* debug_name,
CompilationInfo::CompilationInfo(ParseInfo* parse_info,
Vector<const char> debug_name,
Code::Flags code_flags, Mode mode,
Isolate* isolate, Zone* zone)
: parse_info_(parse_info),
......@@ -165,7 +166,6 @@ CompilationInfo::CompilationInfo(ParseInfo* parse_info, const char* debug_name,
osr_expr_stack_height_(0),
debug_name_(debug_name) {}
CompilationInfo::~CompilationInfo() {
DisableFutureOptimization();
delete deferred_handles_;
......@@ -268,10 +268,11 @@ base::SmartArrayPointer<char> CompilationInfo::GetDebugName() const {
if (parse_info() && !parse_info()->shared_info().is_null()) {
return parse_info()->shared_info()->DebugName()->ToCString();
}
const char* str = debug_name_ ? debug_name_ : "unknown";
size_t len = strlen(str) + 1;
base::SmartArrayPointer<char> name(new char[len]);
memcpy(name.get(), str, len);
Vector<const char> name_vec = debug_name_;
if (name_vec.is_empty()) name_vec = ArrayVector("unknown");
base::SmartArrayPointer<char> name(new char[name_vec.length() + 1]);
memcpy(name.get(), name_vec.start(), name_vec.length());
name[name_vec.length()] = '\0';
return name;
}
......
......@@ -165,7 +165,7 @@ class CompilationInfo {
};
CompilationInfo(ParseInfo* parse_info, Handle<JSFunction> closure);
CompilationInfo(const char* debug_name, Isolate* isolate, Zone* zone,
CompilationInfo(Vector<const char> debug_name, Isolate* isolate, Zone* zone,
Code::Flags code_flags = Code::ComputeFlags(Code::STUB));
virtual ~CompilationInfo();
......@@ -492,7 +492,7 @@ class CompilationInfo {
STUB
};
CompilationInfo(ParseInfo* parse_info, const char* debug_name,
CompilationInfo(ParseInfo* parse_info, Vector<const char> debug_name,
Code::Flags code_flags, Mode mode, Isolate* isolate,
Zone* zone);
......@@ -556,7 +556,7 @@ class CompilationInfo {
// The current OSR frame for specialization or {nullptr}.
JavaScriptFrame* osr_frame_ = nullptr;
const char* debug_name_;
Vector<const char> debug_name_;
DISALLOW_COPY_AND_ASSIGN(CompilationInfo);
};
......
......@@ -1299,7 +1299,7 @@ Handle<Code> Pipeline::GenerateCodeForCodeStub(Isolate* isolate,
Graph* graph, Schedule* schedule,
Code::Flags flags,
const char* debug_name) {
CompilationInfo info(debug_name, isolate, graph->zone(), flags);
CompilationInfo info(CStrVector(debug_name), isolate, graph->zone(), flags);
// Construct a pipeline for scheduling and code generation.
ZonePool zone_pool(isolate->allocator());
......@@ -1387,7 +1387,8 @@ OptimizedCompileJob* Pipeline::NewCompilationJob(CompilationInfo* info) {
bool Pipeline::AllocateRegistersForTesting(const RegisterConfiguration* config,
InstructionSequence* sequence,
bool run_verifier) {
CompilationInfo info("testing", sequence->isolate(), sequence->zone());
CompilationInfo info(ArrayVector("testing"), sequence->isolate(),
sequence->zone());
ZonePool zone_pool(sequence->isolate()->allocator());
PipelineData data(&zone_pool, &info, sequence);
Pipeline pipeline(&info);
......
......@@ -2752,14 +2752,14 @@ Handle<JSFunction> CompileJSToWasmWrapper(
#else
FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph;
#endif
const char* func_name = "js-to-wasm";
Vector<const char> func_name = ArrayVector("js-to-wasm");
static unsigned id = 0;
Vector<char> buffer;
if (debugging) {
buffer = Vector<char>::New(128);
SNPrintF(buffer, "js-to-wasm#%d", id);
func_name = buffer.start();
int chars = SNPrintF(buffer, "js-to-wasm#%d", id);
func_name = Vector<const char>::cast(buffer.SubVector(0, chars));
}
CompilationInfo info(func_name, isolate, &zone, flags);
......@@ -2828,13 +2828,13 @@ Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, wasm::ModuleEnv* module,
#else
FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph;
#endif
const char* func_name = "wasm-to-js";
Vector<const char> func_name = ArrayVector("wasm-to-js");
static unsigned id = 0;
Vector<char> buffer;
if (debugging) {
buffer = Vector<char>::New(128);
SNPrintF(buffer, "wasm-to-js#%d", id);
func_name = buffer.start();
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, flags);
......@@ -2955,15 +2955,19 @@ Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate,
#else
FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph;
#endif
const char* func_name = "wasm";
Vector<const char> func_name =
module_env->module
->GetNameOrNull(function.name_offset, function.name_length)
.toVec();
Vector<char> buffer;
if (debugging) {
buffer = Vector<char>::New(128);
wasm::WasmName name =
module_env->module->GetName(function.name_offset, function.name_length);
SNPrintF(buffer, "WASM_function_#%d:%.*s", function.func_index, name.length,
name.name);
func_name = buffer.start();
if (func_name.is_empty()) {
if (debugging) {
buffer = Vector<char>::New(128);
int chars = SNPrintF(buffer, "WASM_function_#%d", function.func_index);
func_name = Vector<const char>::cast(buffer.SubVector(0, chars));
} else {
func_name = ArrayVector("wasm");
}
}
CompilationInfo info(func_name, isolate, jsgraph->graph()->zone(), flags);
compiler::ZonePool::Scope pipeline_zone_scope(&zone_pool);
......@@ -2977,9 +2981,7 @@ Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate,
code = Handle<Code>::null();
}
if (debugging) {
buffer.Dispose();
}
buffer.Dispose();
if (!code.is_null()) {
RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "WASM_function",
function.func_index,
......
......@@ -24,6 +24,9 @@ class Vector {
DCHECK(length == 0 || (length > 0 && data != NULL));
}
template <int N>
explicit Vector(T (&arr)[N]) : start_(arr), length_(N) {}
static Vector<T> New(int length) {
return Vector<T>(NewArray<T>(length), length);
}
......@@ -201,6 +204,10 @@ inline Vector<char> MutableCStrVector(char* data, int max) {
return Vector<char>(data, (length < max) ? length : max);
}
template <typename T, int N>
inline Vector<T> ArrayVector(T (&arr)[N]) {
return Vector<T>(arr);
}
} // namespace internal
} // namespace v8
......
......@@ -52,6 +52,10 @@ std::ostream& operator<<(std::ostream& os, const FunctionSig& function);
struct WasmName {
const char* name;
uint32_t length;
// TODO(clemensh): Remove whole WasmName, replace by Vector<const char>
inline Vector<const char> toVec() const {
return Vector<const char>(name, length);
}
};
// TODO(titzer): Renumber all the opcodes to fill in holes.
......
......@@ -65,7 +65,7 @@ class RawMachineAssemblerTester : public HandleAndZoneScope,
Schedule* schedule = this->Export();
CallDescriptor* call_descriptor = this->call_descriptor();
Graph* graph = this->graph();
CompilationInfo info("testing", main_isolate(), main_zone());
CompilationInfo info(ArrayVector("testing"), main_isolate(), main_zone());
code_ = Pipeline::GenerateCodeForTesting(&info, call_descriptor, graph,
schedule);
}
......
......@@ -277,7 +277,7 @@ class GraphBuilderTester : public HandleAndZoneScope,
Zone* zone = graph()->zone();
CallDescriptor* desc =
Linkage::GetSimplifiedCDescriptor(zone, this->csig_);
CompilationInfo info("testing", main_isolate(), main_zone());
CompilationInfo info(ArrayVector("testing"), main_isolate(), main_zone());
code_ = Pipeline::GenerateCodeForTesting(&info, desc, graph());
#ifdef ENABLE_DISASSEMBLER
if (!code_.is_null() && FLAG_print_opt_code) {
......
......@@ -98,7 +98,8 @@ TEST(TestLinkageStubCall) {
Isolate* isolate = CcTest::InitIsolateOnce();
Zone zone(isolate->allocator());
ToNumberStub stub(isolate);
CompilationInfo info("test", isolate, &zone, Code::ComputeFlags(Code::STUB));
CompilationInfo info(ArrayVector("test"), isolate, &zone,
Code::ComputeFlags(Code::STUB));
CallInterfaceDescriptor interface_descriptor =
stub.GetCallInterfaceDescriptor();
CallDescriptor* descriptor = Linkage::GetStubCallDescriptor(
......
......@@ -85,7 +85,8 @@ TEST(ReturnThreeValues) {
Node* mul = m.Int32Mul(p0, p1);
m.Return(add, sub, mul);
CompilationInfo info("testing", handles.main_isolate(), handles.main_zone());
CompilationInfo info(ArrayVector("testing"), handles.main_isolate(),
handles.main_zone());
Handle<Code> code =
Pipeline::GenerateCodeForTesting(&info, desc, m.graph(), m.Export());
#ifdef ENABLE_DISASSEMBLER
......
......@@ -255,7 +255,7 @@ class Int32Signature : public MachineSignature {
Handle<Code> CompileGraph(const char* name, CallDescriptor* desc, Graph* graph,
Schedule* schedule = nullptr) {
Isolate* isolate = CcTest::InitIsolateOnce();
CompilationInfo info("testing", isolate, graph->zone());
CompilationInfo info(ArrayVector("testing"), isolate, graph->zone());
Handle<Code> code =
Pipeline::GenerateCodeForTesting(&info, desc, graph, schedule);
CHECK(!code.is_null());
......
......@@ -27,7 +27,7 @@ TEST(RunStringLengthStub) {
// Create code and an accompanying descriptor.
StringLengthStub stub(isolate);
Handle<Code> code = stub.GenerateCode();
CompilationInfo info("test", isolate, zone,
CompilationInfo info(ArrayVector("test"), isolate, zone,
Code::ComputeFlags(Code::HANDLER));
CallInterfaceDescriptor interface_descriptor =
stub.GetCallInterfaceDescriptor();
......
......@@ -589,7 +589,7 @@ static void TestGeneralizeRepresentation(
// Create new maps by generalizing representation of propX field.
Handle<Map> field_owner(map->FindFieldOwner(property_index), isolate);
CompilationInfo info("testing", isolate, &zone);
CompilationInfo info(ArrayVector("testing"), isolate, &zone);
CHECK(!info.dependencies()->HasAborted());
info.dependencies()->AssumeFieldType(field_owner);
......@@ -968,7 +968,7 @@ static void TestReconfigureDataFieldAttribute_GeneralizeRepresentation(
Zone zone(isolate->allocator());
Handle<Map> field_owner(map->FindFieldOwner(kSplitProp), isolate);
CompilationInfo info("testing", isolate, &zone);
CompilationInfo info(ArrayVector("testing"), isolate, &zone);
CHECK(!info.dependencies()->HasAborted());
info.dependencies()->AssumeFieldType(field_owner);
......@@ -1053,7 +1053,7 @@ static void TestReconfigureDataFieldAttribute_GeneralizeRepresentationTrivial(
Zone zone(isolate->allocator());
Handle<Map> field_owner(map->FindFieldOwner(kSplitProp), isolate);
CompilationInfo info("testing", isolate, &zone);
CompilationInfo info(ArrayVector("testing"), isolate, &zone);
CHECK(!info.dependencies()->HasAborted());
info.dependencies()->AssumeFieldType(field_owner);
......
......@@ -122,13 +122,15 @@ TEST(CollectDetailedWasmStack_WasmError) {
TestSignatures sigs;
TestingModule module;
WasmFunctionCompiler comp1(sigs.i_v(), &module, "exec_unreachable");
WasmFunctionCompiler comp1(sigs.i_v(), &module,
ArrayVector("exec_unreachable"));
// Set the execution context, such that a runtime error can be thrown.
comp1.SetModuleContext();
BUILD(comp1, WASM_UNREACHABLE);
uint32_t wasm_index = comp1.CompileAndAdd();
WasmFunctionCompiler comp2(sigs.i_v(), &module, "call_exec_unreachable");
WasmFunctionCompiler comp2(sigs.i_v(), &module,
ArrayVector("call_exec_unreachable"));
BUILD(comp2, WASM_CALL_FUNCTION0(wasm_index));
uint32_t wasm_index_2 = comp2.CompileAndAdd();
......
......@@ -382,7 +382,7 @@ class WasmFunctionWrapper : public HandleAndZoneScope,
r.LowerGraph();
}
CompilationInfo info("testing", isolate, graph()->zone());
CompilationInfo info(ArrayVector("testing"), isolate, graph()->zone());
code_ =
Pipeline::GenerateCodeForTesting(&info, descriptor, graph(), nullptr);
CHECK(!code_.is_null());
......@@ -412,8 +412,9 @@ class WasmFunctionWrapper : public HandleAndZoneScope,
class WasmFunctionCompiler : public HandleAndZoneScope,
private GraphAndBuilders {
public:
explicit WasmFunctionCompiler(FunctionSig* sig, TestingModule* module,
const char* debug_name = "<WASM UNNAMED>")
explicit WasmFunctionCompiler(
FunctionSig* sig, TestingModule* module,
Vector<const char> debug_name = ArrayVector("<WASM UNNAMED>"))
: GraphAndBuilders(main_zone()),
jsgraph(this->isolate(), this->graph(), this->common(), nullptr,
nullptr, this->machine()),
......@@ -443,7 +444,7 @@ class WasmFunctionCompiler : public HandleAndZoneScope,
// The call descriptor is initialized when the function is compiled.
CallDescriptor* descriptor_;
TestingModule* testing_module_;
const char* debug_name_;
Vector<const char> debug_name_;
WasmFunction* function_;
int function_index_;
LocalDeclEncoder local_decls;
......
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