Commit 2dc9909c authored by titzer's avatar titzer Committed by Commit bot

[wasm] Make print_wasm_code_size into a regular V8 counter.

R=ahaas@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2130293002
Cr-Commit-Position: refs/heads/master@{#37611}
parent 91f63b2e
...@@ -1055,7 +1055,9 @@ class RuntimeCallTimerScope { ...@@ -1055,7 +1055,9 @@ class RuntimeCallTimerScope {
/* Total code size (including metadata) of baseline code or bytecode. */ \ /* Total code size (including metadata) of baseline code or bytecode. */ \
SC(total_baseline_code_size, V8.TotalBaselineCodeSize) \ SC(total_baseline_code_size, V8.TotalBaselineCodeSize) \
/* Total count of functions compiled using the baseline compiler. */ \ /* Total count of functions compiled using the baseline compiler. */ \
SC(total_baseline_compile_count, V8.TotalBaselineCompileCount) SC(total_baseline_compile_count, V8.TotalBaselineCompileCount) \
SC(wasm_generated_code_size, V8.WasmGeneratedCodeBytes) \
SC(wasm_reloc_size, V8.WasmRelocBytes)
// This file contains all the v8 counters that are in use. // This file contains all the v8 counters that are in use.
class Counters { class Counters {
......
...@@ -508,8 +508,6 @@ DEFINE_BOOL(enable_simd_asmjs, false, "enable SIMD.js in asm.js stdlib") ...@@ -508,8 +508,6 @@ DEFINE_BOOL(enable_simd_asmjs, false, "enable SIMD.js in asm.js stdlib")
DEFINE_BOOL(dump_wasm_module, false, "dump WASM module bytes") DEFINE_BOOL(dump_wasm_module, false, "dump WASM module bytes")
DEFINE_STRING(dump_wasm_module_path, NULL, "directory to dump wasm modules to") DEFINE_STRING(dump_wasm_module_path, NULL, "directory to dump wasm modules to")
DEFINE_BOOL(print_wasm_code_size, false,
"print the generated code size for each wasm module")
DEFINE_INT(typed_array_max_size_in_heap, 64, DEFINE_INT(typed_array_max_size_in_heap, 64,
"threshold for in-heap typed array") "threshold for in-heap typed array")
......
...@@ -546,43 +546,23 @@ class WasmCompilationTask : public CancelableTask { ...@@ -546,43 +546,23 @@ class WasmCompilationTask : public CancelableTask {
base::AtomicNumber<size_t>* next_unit_; base::AtomicNumber<size_t>* next_unit_;
}; };
// Records statistics on the code generated by compiling WASM functions. static void RecordStats(Isolate* isolate, Code* code) {
struct CodeStats { isolate->counters()->wasm_generated_code_size()->Increment(code->body_size());
size_t code_size; isolate->counters()->wasm_reloc_size()->Increment(
size_t reloc_size; code->relocation_info()->length());
}
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();
}
}
void Record(const std::vector<Handle<Code>>& functions) { static void RecordStats(Isolate* isolate,
if (FLAG_print_wasm_code_size) { const std::vector<Handle<Code>>& functions) {
for (Handle<Code> c : functions) Record(*c); for (Handle<Code> c : functions) RecordStats(isolate, *c);
} }
}
void Record(Handle<FixedArray> functions) { static void RecordStats(Isolate* isolate, Handle<FixedArray> functions) {
if (FLAG_print_wasm_code_size) {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
for (int i = 0; i < functions->length(); ++i) { for (int i = 0; i < functions->length(); ++i) {
Code* code = Code::cast(functions->get(i)); RecordStats(isolate, Code::cast(functions->get(i)));
Record(code);
}
} }
} }
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);
}
}
};
Handle<FixedArray> GetImportsMetadata(Factory* factory, Handle<FixedArray> GetImportsMetadata(Factory* factory,
const WasmModule* module) { const WasmModule* module) {
...@@ -914,7 +894,7 @@ bool SetupInstanceHeap(Isolate* isolate, Handle<FixedArray> compiled_module, ...@@ -914,7 +894,7 @@ bool SetupInstanceHeap(Isolate* isolate, Handle<FixedArray> compiled_module,
bool SetupImports(Isolate* isolate, Handle<FixedArray> compiled_module, bool SetupImports(Isolate* isolate, Handle<FixedArray> compiled_module,
Handle<JSObject> instance, ErrorThrower* thrower, Handle<JSObject> instance, ErrorThrower* thrower,
Handle<JSReceiver> ffi, CodeStats* stats) { Handle<JSReceiver> ffi) {
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// Compile wrappers to imported functions. // Compile wrappers to imported functions.
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
...@@ -929,7 +909,7 @@ bool SetupImports(Isolate* isolate, Handle<FixedArray> compiled_module, ...@@ -929,7 +909,7 @@ bool SetupImports(Isolate* isolate, Handle<FixedArray> compiled_module,
} }
} }
stats->Record(import_code); RecordStats(isolate, import_code);
Handle<FixedArray> code_table = Handle<FixedArray>( Handle<FixedArray> code_table = Handle<FixedArray>(
FixedArray::cast(instance->GetInternalField(kWasmModuleCodeTable))); FixedArray::cast(instance->GetInternalField(kWasmModuleCodeTable)));
...@@ -947,8 +927,7 @@ bool SetupImports(Isolate* isolate, Handle<FixedArray> compiled_module, ...@@ -947,8 +927,7 @@ bool SetupImports(Isolate* isolate, Handle<FixedArray> compiled_module,
} }
bool SetupExportsObject(Handle<FixedArray> compiled_module, Isolate* isolate, bool SetupExportsObject(Handle<FixedArray> compiled_module, Isolate* isolate,
Handle<JSObject> instance, ErrorThrower* thrower, Handle<JSObject> instance, ErrorThrower* thrower) {
CodeStats* stats) {
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
bool mem_export = bool mem_export =
static_cast<bool>(Smi::cast(compiled_module->get(kExportMem))->value()); static_cast<bool>(Smi::cast(compiled_module->get(kExportMem))->value());
...@@ -977,7 +956,7 @@ bool SetupExportsObject(Handle<FixedArray> compiled_module, Isolate* isolate, ...@@ -977,7 +956,7 @@ bool SetupExportsObject(Handle<FixedArray> compiled_module, Isolate* isolate,
for (int i = 0; i < exports_size; ++i) { for (int i = 0; i < exports_size; ++i) {
if (thrower->error()) return false; if (thrower->error()) return false;
Handle<JSFunction> function = exports->GetValueChecked<JSFunction>(i); Handle<JSFunction> function = exports->GetValueChecked<JSFunction>(i);
stats->Record(function->code()); RecordStats(isolate, function->code());
Handle<String> name = Handle<String> name =
Handle<String>(String::cast(function->shared()->name())); Handle<String>(String::cast(function->shared()->name()));
function->SetInternalField(0, *instance); function->SetInternalField(0, *instance);
...@@ -1143,12 +1122,11 @@ MaybeHandle<JSObject> WasmModule::Instantiate( ...@@ -1143,12 +1122,11 @@ MaybeHandle<JSObject> WasmModule::Instantiate(
ErrorThrower thrower(isolate, "WasmModule::Instantiate()"); ErrorThrower thrower(isolate, "WasmModule::Instantiate()");
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
CodeStats code_stats;
// These fields are compulsory. // These fields are compulsory.
Handle<FixedArray> code_table = Handle<FixedArray> code_table =
compiled_module->GetValueChecked<FixedArray>(kFunctions); compiled_module->GetValueChecked<FixedArray>(kFunctions);
code_stats.Record(code_table); RecordStats(isolate, code_table);
MaybeHandle<JSObject> nothing; MaybeHandle<JSObject> nothing;
...@@ -1161,10 +1139,8 @@ MaybeHandle<JSObject> WasmModule::Instantiate( ...@@ -1161,10 +1139,8 @@ MaybeHandle<JSObject> WasmModule::Instantiate(
if (!(SetupInstanceHeap(isolate, compiled_module, js_object, memory, if (!(SetupInstanceHeap(isolate, compiled_module, js_object, memory,
&thrower) && &thrower) &&
SetupGlobals(isolate, compiled_module, js_object, &thrower) && SetupGlobals(isolate, compiled_module, js_object, &thrower) &&
SetupImports(isolate, compiled_module, js_object, &thrower, ffi, SetupImports(isolate, compiled_module, js_object, &thrower, ffi) &&
&code_stats) && SetupExportsObject(compiled_module, isolate, js_object, &thrower))) {
SetupExportsObject(compiled_module, isolate, js_object, &thrower,
&code_stats))) {
return nothing; return nothing;
} }
...@@ -1176,7 +1152,7 @@ MaybeHandle<JSObject> WasmModule::Instantiate( ...@@ -1176,7 +1152,7 @@ MaybeHandle<JSObject> WasmModule::Instantiate(
if (!maybe_startup_fct.is_null()) { if (!maybe_startup_fct.is_null()) {
HandleScope scope(isolate); HandleScope scope(isolate);
Handle<JSFunction> startup_fct = maybe_startup_fct.ToHandleChecked(); Handle<JSFunction> startup_fct = maybe_startup_fct.ToHandleChecked();
code_stats.Record(startup_fct->code()); RecordStats(isolate, startup_fct->code());
startup_fct->SetInternalField(0, *js_object); startup_fct->SetInternalField(0, *js_object);
// Call the JS function. // Call the JS function.
Handle<Object> undefined = isolate->factory()->undefined_value(); Handle<Object> undefined = isolate->factory()->undefined_value();
...@@ -1189,8 +1165,6 @@ MaybeHandle<JSObject> WasmModule::Instantiate( ...@@ -1189,8 +1165,6 @@ MaybeHandle<JSObject> WasmModule::Instantiate(
} }
} }
code_stats.Report();
DCHECK(wasm::IsWasmObject(*js_object)); DCHECK(wasm::IsWasmObject(*js_object));
return js_object; return js_object;
} }
......
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