| Index: src/wasm/wasm-module.cc
|
| diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc
|
| index 151770bc2e1cfe7cde7db7cdee44a7aa6f3d64d4..f8e27d78b22400140889b954e9e74b03cceb33f6 100644
|
| --- a/src/wasm/wasm-module.cc
|
| +++ b/src/wasm/wasm-module.cc
|
| @@ -55,22 +55,16 @@ byte* raw_buffer_ptr(MaybeHandle<JSArrayBuffer> buffer, int offset) {
|
| return static_cast<byte*>(buffer.ToHandleChecked()->backing_store()) + offset;
|
| }
|
|
|
| -static void RecordStats(Isolate* isolate, Code* code, bool is_sync) {
|
| - if (is_sync) {
|
| - // TODO(karlschimpf): Make this work when asynchronous.
|
| - // https://bugs.chromium.org/p/v8/issues/detail?id=6361
|
| - isolate->counters()->wasm_generated_code_size()->Increment(
|
| - code->body_size());
|
| - isolate->counters()->wasm_reloc_size()->Increment(
|
| - code->relocation_info()->length());
|
| - }
|
| +static void RecordStats(Isolate* isolate, Code* code, Counters* counters) {
|
| + counters->wasm_generated_code_size()->Increment(code->body_size());
|
| + counters->wasm_reloc_size()->Increment(code->relocation_info()->length());
|
| }
|
|
|
| static void RecordStats(Isolate* isolate, Handle<FixedArray> functions,
|
| - bool is_sync) {
|
| + Counters* counters) {
|
| DisallowHeapAllocation no_gc;
|
| for (int i = 0; i < functions->length(); ++i) {
|
| - RecordStats(isolate, Code::cast(functions->get(i)), is_sync);
|
| + RecordStats(isolate, Code::cast(functions->get(i)), counters);
|
| }
|
| }
|
|
|
| @@ -299,7 +293,12 @@ class CompilationHelper {
|
| // reclaimed by explicitely releasing the {module_} field.
|
| CompilationHelper(Isolate* isolate, std::unique_ptr<WasmModule> module,
|
| bool is_sync)
|
| - : isolate_(isolate), module_(std::move(module)), is_sync_(is_sync) {}
|
| + : isolate_(isolate),
|
| + module_(std::move(module)),
|
| + counters_shared_(isolate->counters_shared()),
|
| + is_sync_(is_sync) {
|
| + counters_ = counters_shared_.get();
|
| + }
|
|
|
| // The actual runnable task that performs compilations in the background.
|
| class CompilationTask : public CancelableTask {
|
| @@ -317,6 +316,8 @@ class CompilationHelper {
|
|
|
| Isolate* isolate_;
|
| std::unique_ptr<WasmModule> module_;
|
| + std::shared_ptr<Counters> counters_shared_;
|
| + Counters* counters_;
|
| bool is_sync_;
|
| std::vector<std::unique_ptr<compiler::WasmCompilationUnit>>
|
| compilation_units_;
|
| @@ -620,7 +621,7 @@ class CompilationHelper {
|
| i < temp_instance->function_code.size(); ++i) {
|
| Code* code = *temp_instance->function_code[i];
|
| code_table->set(static_cast<int>(i), code);
|
| - RecordStats(isolate_, code, is_sync_);
|
| + RecordStats(isolate_, code, counters_);
|
| }
|
|
|
| // Create heap objects for script, module bytes and asm.js offset table to
|
| @@ -688,7 +689,7 @@ class CompilationHelper {
|
| int export_index =
|
| static_cast<int>(module->functions.size() + func_index);
|
| code_table->set(export_index, *wrapper_code);
|
| - RecordStats(isolate_, *wrapper_code, is_sync_);
|
| + RecordStats(isolate_, *wrapper_code, counters_);
|
| func_index++;
|
| }
|
|
|
| @@ -842,11 +843,10 @@ int ExtractDirectCallIndex(wasm::Decoder& decoder, const byte* pc) {
|
| return static_cast<int>(call_idx);
|
| }
|
|
|
| -void RecordLazyCodeStats(Isolate* isolate, Code* code) {
|
| - isolate->counters()->wasm_lazily_compiled_functions()->Increment();
|
| - isolate->counters()->wasm_generated_code_size()->Increment(code->body_size());
|
| - isolate->counters()->wasm_reloc_size()->Increment(
|
| - code->relocation_info()->length());
|
| +void RecordLazyCodeStats(Isolate* isolate, Code* code, Counters* counters_) {
|
| + counters_->wasm_lazily_compiled_functions()->Increment();
|
| + counters_->wasm_generated_code_size()->Increment(code->body_size());
|
| + counters_->wasm_reloc_size()->Increment(code->relocation_info()->length());
|
| }
|
|
|
| } // namespace
|
| @@ -1081,12 +1081,15 @@ class InstantiationHelper {
|
| MaybeHandle<JSArrayBuffer> memory)
|
| : isolate_(isolate),
|
| module_(module_object->compiled_module()->module()),
|
| + counters_shared_(isolate->counters_shared()),
|
| thrower_(thrower),
|
| module_object_(module_object),
|
| ffi_(ffi.is_null() ? Handle<JSReceiver>::null()
|
| : ffi.ToHandleChecked()),
|
| memory_(memory.is_null() ? Handle<JSArrayBuffer>::null()
|
| - : memory.ToHandleChecked()) {}
|
| + : memory.ToHandleChecked()) {
|
| + counters_ = counters_shared_.get();
|
| + }
|
|
|
| // Build an instance, in all of its glory.
|
| MaybeHandle<WasmInstanceObject> Build() {
|
| @@ -1176,7 +1179,7 @@ class InstantiationHelper {
|
| UNREACHABLE();
|
| }
|
| }
|
| - RecordStats(isolate_, code_table, is_sync_);
|
| + RecordStats(isolate_, code_table, counters_);
|
| } else {
|
| // There was no owner, so we can reuse the original.
|
| compiled_module_ = original;
|
| @@ -1453,7 +1456,7 @@ class InstantiationHelper {
|
| Handle<WasmExportedFunction> startup_fct = WasmExportedFunction::New(
|
| isolate_, instance, MaybeHandle<String>(), start_index,
|
| static_cast<int>(sig->parameter_count()), wrapper_code);
|
| - RecordStats(isolate_, *startup_code, is_sync_);
|
| + RecordStats(isolate_, *startup_code, counters_);
|
| // Call the JS function.
|
| Handle<Object> undefined = factory->undefined_value();
|
| MaybeHandle<Object> retval =
|
| @@ -1487,7 +1490,8 @@ class InstantiationHelper {
|
|
|
| Isolate* isolate_;
|
| WasmModule* const module_;
|
| - constexpr static bool is_sync_ = true;
|
| + std::shared_ptr<Counters> counters_shared_;
|
| + Counters* counters_;
|
| ErrorThrower* thrower_;
|
| Handle<WasmModuleObject> module_object_;
|
| Handle<JSReceiver> ffi_; // TODO(titzer): Use MaybeHandle
|
| @@ -1658,7 +1662,7 @@ class InstantiationHelper {
|
| return -1;
|
| }
|
| code_table->set(num_imported_functions, *import_wrapper);
|
| - RecordStats(isolate_, *import_wrapper, is_sync_);
|
| + RecordStats(isolate_, *import_wrapper, counters_);
|
| num_imported_functions++;
|
| break;
|
| }
|
| @@ -2631,6 +2635,7 @@ class AsyncCompileJob {
|
| size_t length, Handle<Context> context,
|
| Handle<JSPromise> promise)
|
| : isolate_(isolate),
|
| + counters_shared_(isolate->counters_shared()),
|
| bytes_copy_(std::move(bytes_copy)),
|
| wire_bytes_(bytes_copy_.get(), bytes_copy_.get() + length) {
|
| // The handles for the context and promise must be deferred.
|
| @@ -2638,6 +2643,7 @@ class AsyncCompileJob {
|
| context_ = Handle<Context>(*context);
|
| module_promise_ = Handle<JSPromise>(*promise);
|
| deferred_handles_.push_back(deferred.Detach());
|
| + counters_ = counters_shared_.get();
|
| }
|
|
|
| void Start() {
|
| @@ -2650,6 +2656,8 @@ class AsyncCompileJob {
|
|
|
| private:
|
| Isolate* isolate_;
|
| + std::shared_ptr<Counters> counters_shared_;
|
| + Counters* counters_;
|
| std::unique_ptr<byte[]> bytes_copy_;
|
| ModuleWireBytes wire_bytes_;
|
| Handle<Context> context_;
|
| @@ -3016,11 +3024,10 @@ class AsyncCompileJob {
|
| TRACE_COMPILE("(5b) Finish compile...\n");
|
| HandleScope scope(job_->isolate_);
|
| // At this point, compilation has completed. Update the code table.
|
| - constexpr bool is_sync = true;
|
| for (size_t i = FLAG_skip_compiling_wasm_funcs;
|
| i < job_->temp_instance_->function_code.size(); ++i) {
|
| Code* code = Code::cast(job_->code_table_->get(static_cast<int>(i)));
|
| - RecordStats(job_->isolate_, code, !is_sync);
|
| + RecordStats(job_->isolate_, code, job_->counters_);
|
| }
|
|
|
| // Create heap objects for script and module bytes to be stored in the
|
| @@ -3086,7 +3093,6 @@ class AsyncCompileJob {
|
| HandleScope scope(job_->isolate_);
|
| JSToWasmWrapperCache js_to_wasm_cache;
|
| int func_index = 0;
|
| - constexpr bool is_sync = true;
|
| WasmModule* module = job_->compiled_module_->module();
|
| for (auto exp : module->export_table) {
|
| if (exp.kind != kExternalFunction) continue;
|
| @@ -3098,7 +3104,7 @@ class AsyncCompileJob {
|
| int export_index =
|
| static_cast<int>(module->functions.size() + func_index);
|
| job_->code_table_->set(export_index, *wrapper_code);
|
| - RecordStats(job_->isolate_, *wrapper_code, !is_sync);
|
| + RecordStats(job_->isolate_, *wrapper_code, job_->counters_);
|
| func_index++;
|
| }
|
|
|
| @@ -3222,7 +3228,8 @@ Handle<Code> wasm::CompileLazy(Isolate* isolate) {
|
| }
|
|
|
| void LazyCompilationOrchestrator::CompileFunction(
|
| - Isolate* isolate, Handle<WasmInstanceObject> instance, int func_index) {
|
| + Isolate* isolate, Handle<WasmInstanceObject> instance, int func_index,
|
| + Counters* counters_) {
|
| Handle<WasmCompiledModule> compiled_module(instance->compiled_module(),
|
| isolate);
|
| if (Code::cast(compiled_module->code_table()->get(func_index))->kind() ==
|
| @@ -3308,7 +3315,7 @@ void LazyCompilationOrchestrator::CompileFunction(
|
| code_specialization.ApplyToWasmCode(*code, SKIP_ICACHE_FLUSH);
|
| Assembler::FlushICache(isolate, code->instruction_start(),
|
| code->instruction_size());
|
| - RecordLazyCodeStats(isolate, *code);
|
| + RecordLazyCodeStats(isolate, *code, counters_);
|
| }
|
|
|
| Handle<Code> LazyCompilationOrchestrator::CompileLazy(
|
| @@ -3318,6 +3325,8 @@ Handle<Code> LazyCompilationOrchestrator::CompileLazy(
|
| int offset;
|
| int func_index;
|
| };
|
| + std::shared_ptr<Counters> counters_shared = isolate->counters_shared();
|
| + Counters* counters = counters_shared.get();
|
| std::vector<NonCompiledFunction> non_compiled_functions;
|
| int func_to_return_idx = exported_func_index;
|
| wasm::Decoder decoder(nullptr, nullptr);
|
| @@ -3362,7 +3371,7 @@ Handle<Code> LazyCompilationOrchestrator::CompileLazy(
|
|
|
| // TODO(clemensh): compile all functions in non_compiled_functions in
|
| // background, wait for func_to_return_idx.
|
| - CompileFunction(isolate, instance, func_to_return_idx);
|
| + CompileFunction(isolate, instance, func_to_return_idx, counters);
|
|
|
| if (is_js_to_wasm || patch_caller) {
|
| DisallowHeapAllocation no_gc;
|
|
|