Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Unified Diff: src/wasm/wasm-module.cc

Issue 2003383002: [wasm] Separate reloc info stats from code size stats. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/wasm-module.cc
diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc
index 97268a1364a617f790f4f7e958f033c4b286dbc3..bb4728ffa01c697a5a4a875ca0250cc9fb208b44 100644
--- a/src/wasm/wasm-module.cc
+++ b/src/wasm/wasm-module.cc
@@ -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) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698