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 {
/* Total code size (including metadata) of baseline code or bytecode. */ \
SC(total_baseline_code_size, V8.TotalBaselineCodeSize) \
/* 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.
class Counters {
......
......@@ -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_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,
"threshold for in-heap typed array")
......
......@@ -546,43 +546,23 @@ class WasmCompilationTask : public CancelableTask {
base::AtomicNumber<size_t>* next_unit_;
};
// 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();
}
}
void Record(const std::vector<Handle<Code>>& functions) {
if (FLAG_print_wasm_code_size) {
for (Handle<Code> c : functions) Record(*c);
}
}
static void RecordStats(Isolate* isolate, Code* code) {
isolate->counters()->wasm_generated_code_size()->Increment(code->body_size());
isolate->counters()->wasm_reloc_size()->Increment(
code->relocation_info()->length());
}
void Record(Handle<FixedArray> functions) {
if (FLAG_print_wasm_code_size) {
DisallowHeapAllocation no_gc;
for (int i = 0; i < functions->length(); ++i) {
Code* code = Code::cast(functions->get(i));
Record(code);
}
}
}
static void RecordStats(Isolate* isolate,
const std::vector<Handle<Code>>& functions) {
for (Handle<Code> c : functions) RecordStats(isolate, *c);
}
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);
}
static void RecordStats(Isolate* isolate, Handle<FixedArray> functions) {
DisallowHeapAllocation no_gc;
for (int i = 0; i < functions->length(); ++i) {
RecordStats(isolate, Code::cast(functions->get(i)));
}
};
}
Handle<FixedArray> GetImportsMetadata(Factory* factory,
const WasmModule* module) {
......@@ -914,7 +894,7 @@ bool SetupInstanceHeap(Isolate* isolate, Handle<FixedArray> compiled_module,
bool SetupImports(Isolate* isolate, Handle<FixedArray> compiled_module,
Handle<JSObject> instance, ErrorThrower* thrower,
Handle<JSReceiver> ffi, CodeStats* stats) {
Handle<JSReceiver> ffi) {
//-------------------------------------------------------------------------
// Compile wrappers to imported functions.
//-------------------------------------------------------------------------
......@@ -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>(
FixedArray::cast(instance->GetInternalField(kWasmModuleCodeTable)));
......@@ -947,8 +927,7 @@ bool SetupImports(Isolate* isolate, Handle<FixedArray> compiled_module,
}
bool SetupExportsObject(Handle<FixedArray> compiled_module, Isolate* isolate,
Handle<JSObject> instance, ErrorThrower* thrower,
CodeStats* stats) {
Handle<JSObject> instance, ErrorThrower* thrower) {
Factory* factory = isolate->factory();
bool mem_export =
static_cast<bool>(Smi::cast(compiled_module->get(kExportMem))->value());
......@@ -977,7 +956,7 @@ bool SetupExportsObject(Handle<FixedArray> compiled_module, Isolate* isolate,
for (int i = 0; i < exports_size; ++i) {
if (thrower->error()) return false;
Handle<JSFunction> function = exports->GetValueChecked<JSFunction>(i);
stats->Record(function->code());
RecordStats(isolate, function->code());
Handle<String> name =
Handle<String>(String::cast(function->shared()->name()));
function->SetInternalField(0, *instance);
......@@ -1143,12 +1122,11 @@ MaybeHandle<JSObject> WasmModule::Instantiate(
ErrorThrower thrower(isolate, "WasmModule::Instantiate()");
Factory* factory = isolate->factory();
CodeStats code_stats;
// These fields are compulsory.
Handle<FixedArray> code_table =
compiled_module->GetValueChecked<FixedArray>(kFunctions);
code_stats.Record(code_table);
RecordStats(isolate, code_table);
MaybeHandle<JSObject> nothing;
......@@ -1161,10 +1139,8 @@ MaybeHandle<JSObject> WasmModule::Instantiate(
if (!(SetupInstanceHeap(isolate, compiled_module, js_object, memory,
&thrower) &&
SetupGlobals(isolate, compiled_module, js_object, &thrower) &&
SetupImports(isolate, compiled_module, js_object, &thrower, ffi,
&code_stats) &&
SetupExportsObject(compiled_module, isolate, js_object, &thrower,
&code_stats))) {
SetupImports(isolate, compiled_module, js_object, &thrower, ffi) &&
SetupExportsObject(compiled_module, isolate, js_object, &thrower))) {
return nothing;
}
......@@ -1176,7 +1152,7 @@ MaybeHandle<JSObject> WasmModule::Instantiate(
if (!maybe_startup_fct.is_null()) {
HandleScope scope(isolate);
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);
// Call the JS function.
Handle<Object> undefined = isolate->factory()->undefined_value();
......@@ -1189,8 +1165,6 @@ MaybeHandle<JSObject> WasmModule::Instantiate(
}
}
code_stats.Report();
DCHECK(wasm::IsWasmObject(*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