Commit 796db52f authored by titzer's avatar titzer Committed by Commit bot

[wasm] Separate reloc info stats from code size stats.

R=ahaas@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2003383002
Cr-Commit-Position: refs/heads/master@{#36479}
parent fb8e0ab3
......@@ -451,18 +451,34 @@ class WasmCompilationTask : public CancelableTask {
base::AtomicNumber<size_t>* next_unit_;
};
void record_code_size(uint32_t& total_code_size, Code* code) {
if (FLAG_print_wasm_code_size) {
total_code_size += code->body_size() + code->relocation_info()->length();
// Records statistics on the code generated by compiling WASM functions.
struct CodeStats {
size_t code_size;
size_t reloc_size;
inline CodeStats() : code_size(0), reloc_size(0) {}
inline void Record(Code* code) {
if (FLAG_print_wasm_code_size) {
code_size += code->body_size();
reloc_size += code->relocation_info()->length();
}
}
}
inline void Report() {
if (FLAG_print_wasm_code_size) {
PrintF("Total generated wasm code: %zu bytes\n", code_size);
PrintF("Total generated wasm reloc: %zu bytes\n", reloc_size);
}
}
};
bool CompileWrappersToImportedFunctions(Isolate* isolate, WasmModule* module,
const Handle<JSReceiver> ffi,
WasmModuleInstance* instance,
ErrorThrower* thrower, Factory* factory,
ModuleEnv* module_env,
uint32_t& total_code_size) {
CodeStats& code_stats) {
uint32_t index = 0;
if (module->import_table.size() > 0) {
instance->import_code.reserve(module->import_table.size());
......@@ -479,7 +495,7 @@ bool CompileWrappersToImportedFunctions(Isolate* isolate, WasmModule* module,
isolate, module_env, function.ToHandleChecked(), import.sig,
module_name, function_name);
instance->import_code.push_back(code);
record_code_size(total_code_size, *code);
code_stats.Record(*code);
index++;
}
}
......@@ -564,7 +580,7 @@ bool FinishCompilation(Isolate* isolate, WasmModule* module,
const WasmModuleInstance& instance,
const Handle<FixedArray>& code_table,
ErrorThrower& thrower, Factory* factory,
ModuleEnv& module_env, uint32_t& total_code_size,
ModuleEnv& module_env, CodeStats& code_stats,
PropertyDescriptor& desc) {
for (uint32_t i = FLAG_skip_compiling_wasm_funcs;
i < module->functions.size(); i++) {
......@@ -592,13 +608,13 @@ bool FinishCompilation(Isolate* isolate, WasmModule* module,
function_name = factory->InternalizeUtf8String(str);
function = compiler::CompileJSToWasmWrapper(
isolate, &module_env, function_name, code, instance.js_object, i);
record_code_size(total_code_size, function->code());
code_stats.Record(function->code());
}
if (!code.is_null()) {
// Install the code into the linker table.
module_env.linker->Finish(i, code);
code_table->set(i, *code);
record_code_size(total_code_size, *code);
code_stats.Record(*code);
}
if (func.exported) {
// Exported functions are installed as read-only properties on the
......@@ -634,7 +650,7 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
// If FLAG_print_wasm_code_size is set, this aggregates the sum of all code
// objects created for this module.
// TODO(titzer): switch this to TRACE_EVENT
uint32_t total_code_size = 0;
CodeStats code_stats;
//-------------------------------------------------------------------------
// Allocate the instance and its JS counterpart.
......@@ -694,7 +710,7 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
//-------------------------------------------------------------------------
if (!CompileWrappersToImportedFunctions(isolate, this, ffi, &instance,
&thrower, factory, &module_env,
total_code_size)) {
code_stats)) {
return MaybeHandle<JSObject>();
}
//-------------------------------------------------------------------------
......@@ -769,8 +785,7 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
}
// 5) The main thread finishes the compilation.
if (!FinishCompilation(isolate, this, ffi, results, instance, code_table,
thrower, factory, module_env, total_code_size,
desc)) {
thrower, factory, module_env, code_stats, desc)) {
instance.js_object = Handle<JSObject>::null();
}
......@@ -801,7 +816,7 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
Handle<JSFunction> function = compiler::CompileJSToWasmWrapper(
isolate, &module_env, name, code, instance.js_object,
exp.func_index);
record_code_size(total_code_size, function->code());
code_stats.Record(function->code());
desc.set_value(function);
Maybe<bool> status = JSReceiver::DefineOwnProperty(
isolate, exports_object, name, &desc, Object::THROW_ON_ERROR);
......@@ -827,8 +842,7 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
instance.js_object->SetInternalField(kWasmFunctionNamesArray, *arr);
}
if (FLAG_print_wasm_code_size)
printf("Total generated wasm code: %u bytes\n", total_code_size);
code_stats.Report();
// Run the start function if one was specified.
if (this->start_function_index >= 0) {
......
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