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

Side by Side Diff: src/wasm/wasm-module.cc

Issue 1933513003: [wasm] Add a flag to output the generated code size (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: add TODO and switch to uint32_t 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 unified diff | Download patch
« no previous file with comments | « src/flag-definitions.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/macro-assembler.h" 5 #include "src/macro-assembler.h"
6 #include "src/objects.h" 6 #include "src/objects.h"
7 #include "src/property-descriptor.h" 7 #include "src/property-descriptor.h"
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/simulator.h" 10 #include "src/simulator.h"
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 Handle<JSArrayBuffer> memory) { 406 Handle<JSArrayBuffer> memory) {
407 HistogramTimerScope wasm_instantiate_module_time_scope( 407 HistogramTimerScope wasm_instantiate_module_time_scope(
408 isolate->counters()->wasm_instantiate_module_time()); 408 isolate->counters()->wasm_instantiate_module_time());
409 this->shared_isolate = isolate; // TODO(titzer): have a real shared isolate. 409 this->shared_isolate = isolate; // TODO(titzer): have a real shared isolate.
410 ErrorThrower thrower(isolate, "WasmModule::Instantiate()"); 410 ErrorThrower thrower(isolate, "WasmModule::Instantiate()");
411 Factory* factory = isolate->factory(); 411 Factory* factory = isolate->factory();
412 412
413 PropertyDescriptor desc; 413 PropertyDescriptor desc;
414 desc.set_writable(false); 414 desc.set_writable(false);
415 415
416 // If FLAG_print_wasm_code_size is set, this aggregates the sum of all code
417 // objects created for this module.
418 // TODO(titzer): switch this to TRACE_EVENT
419 uint32_t total_code_size = 0;
420 auto record_code_size = [&total_code_size](Code* code) {
421 if (FLAG_print_wasm_code_size)
422 total_code_size += code->body_size() + code->relocation_info()->length();
423 };
424
416 //------------------------------------------------------------------------- 425 //-------------------------------------------------------------------------
417 // Allocate the instance and its JS counterpart. 426 // Allocate the instance and its JS counterpart.
418 //------------------------------------------------------------------------- 427 //-------------------------------------------------------------------------
419 Handle<Map> map = factory->NewMap( 428 Handle<Map> map = factory->NewMap(
420 JS_OBJECT_TYPE, 429 JS_OBJECT_TYPE,
421 JSObject::kHeaderSize + kWasmModuleInternalFieldCount * kPointerSize); 430 JSObject::kHeaderSize + kWasmModuleInternalFieldCount * kPointerSize);
422 WasmModuleInstance instance(this); 431 WasmModuleInstance instance(this);
423 instance.context = isolate->native_context(); 432 instance.context = isolate->native_context();
424 instance.js_object = factory->NewJSObjectFromMap(map, TENURED); 433 instance.js_object = factory->NewJSObjectFromMap(map, TENURED);
425 Handle<FixedArray> code_table = 434 Handle<FixedArray> code_table =
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 GetNameOrNull(import.module_name_offset, import.module_name_length); 486 GetNameOrNull(import.module_name_offset, import.module_name_length);
478 WasmName function_name = GetNameOrNull(import.function_name_offset, 487 WasmName function_name = GetNameOrNull(import.function_name_offset,
479 import.function_name_length); 488 import.function_name_length);
480 MaybeHandle<JSFunction> function = LookupFunction( 489 MaybeHandle<JSFunction> function = LookupFunction(
481 thrower, factory, ffi, index, module_name, function_name); 490 thrower, factory, ffi, index, module_name, function_name);
482 if (function.is_null()) return MaybeHandle<JSObject>(); 491 if (function.is_null()) return MaybeHandle<JSObject>();
483 Handle<Code> code = compiler::CompileWasmToJSWrapper( 492 Handle<Code> code = compiler::CompileWasmToJSWrapper(
484 isolate, &module_env, function.ToHandleChecked(), import.sig, 493 isolate, &module_env, function.ToHandleChecked(), import.sig,
485 module_name, function_name); 494 module_name, function_name);
486 instance.import_code.push_back(code); 495 instance.import_code.push_back(code);
496 record_code_size(*code);
487 index++; 497 index++;
488 } 498 }
489 } 499 }
490 500
491 //------------------------------------------------------------------------- 501 //-------------------------------------------------------------------------
492 // Compile all functions in the module. 502 // Compile all functions in the module.
493 //------------------------------------------------------------------------- 503 //-------------------------------------------------------------------------
494 { 504 {
495 isolate->counters()->wasm_functions_per_module()->AddSample( 505 isolate->counters()->wasm_functions_per_module()->AddSample(
496 static_cast<int>(functions.size())); 506 static_cast<int>(functions.size()));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 &func); 559 &func);
550 } 560 }
551 if (code.is_null()) { 561 if (code.is_null()) {
552 thrower.Error("Compilation of #%d:%.*s failed.", i, str.length(), 562 thrower.Error("Compilation of #%d:%.*s failed.", i, str.length(),
553 str.start()); 563 str.start());
554 return MaybeHandle<JSObject>(); 564 return MaybeHandle<JSObject>();
555 } 565 }
556 if (func.exported) { 566 if (func.exported) {
557 function = compiler::CompileJSToWasmWrapper( 567 function = compiler::CompileJSToWasmWrapper(
558 isolate, &module_env, name, code, instance.js_object, i); 568 isolate, &module_env, name, code, instance.js_object, i);
569 record_code_size(function->code());
559 } 570 }
560 } 571 }
561 if (!code.is_null()) { 572 if (!code.is_null()) {
562 // Install the code into the linker table. 573 // Install the code into the linker table.
563 linker.Finish(i, code); 574 linker.Finish(i, code);
564 code_table->set(i, *code); 575 code_table->set(i, *code);
576 record_code_size(*code);
565 } 577 }
566 if (func.exported) { 578 if (func.exported) {
567 // Exported functions are installed as read-only properties on the 579 // Exported functions are installed as read-only properties on the
568 // module. 580 // module.
569 desc.set_value(function); 581 desc.set_value(function);
570 Maybe<bool> status = JSReceiver::DefineOwnProperty( 582 Maybe<bool> status = JSReceiver::DefineOwnProperty(
571 isolate, instance.js_object, name, &desc, Object::THROW_ON_ERROR); 583 isolate, instance.js_object, name, &desc, Object::THROW_ON_ERROR);
572 if (!status.IsJust()) 584 if (!status.IsJust())
573 thrower.Error("export of %.*s failed.", str.length(), str.start()); 585 thrower.Error("export of %.*s failed.", str.length(), str.start());
574 } 586 }
(...skipping 19 matching lines...) Expand all
594 606
595 // Compile wrappers and add them to the exports object. 607 // Compile wrappers and add them to the exports object.
596 for (const WasmExport& exp : export_table) { 608 for (const WasmExport& exp : export_table) {
597 if (thrower.error()) break; 609 if (thrower.error()) break;
598 WasmName str = GetName(exp.name_offset, exp.name_length); 610 WasmName str = GetName(exp.name_offset, exp.name_length);
599 Handle<String> name = factory->InternalizeUtf8String(str); 611 Handle<String> name = factory->InternalizeUtf8String(str);
600 Handle<Code> code = linker.GetFunctionCode(exp.func_index); 612 Handle<Code> code = linker.GetFunctionCode(exp.func_index);
601 Handle<JSFunction> function = compiler::CompileJSToWasmWrapper( 613 Handle<JSFunction> function = compiler::CompileJSToWasmWrapper(
602 isolate, &module_env, name, code, instance.js_object, 614 isolate, &module_env, name, code, instance.js_object,
603 exp.func_index); 615 exp.func_index);
616 record_code_size(function->code());
604 desc.set_value(function); 617 desc.set_value(function);
605 Maybe<bool> status = JSReceiver::DefineOwnProperty( 618 Maybe<bool> status = JSReceiver::DefineOwnProperty(
606 isolate, exports_object, name, &desc, Object::THROW_ON_ERROR); 619 isolate, exports_object, name, &desc, Object::THROW_ON_ERROR);
607 if (!status.IsJust()) 620 if (!status.IsJust())
608 thrower.Error("export of %.*s failed.", str.length(), str.start()); 621 thrower.Error("export of %.*s failed.", str.length(), str.start());
609 } 622 }
610 623
611 if (mem_export) { 624 if (mem_export) {
612 // Export the memory as a named property. 625 // Export the memory as a named property.
613 Handle<String> name = factory->InternalizeUtf8String("memory"); 626 Handle<String> name = factory->InternalizeUtf8String("memory");
614 JSObject::AddProperty(exports_object, name, instance.mem_buffer, 627 JSObject::AddProperty(exports_object, name, instance.mem_buffer,
615 READ_ONLY); 628 READ_ONLY);
616 } 629 }
617 } 630 }
618 } 631 }
619 632
633 if (FLAG_print_wasm_code_size)
634 printf("Total generated wasm code: %u bytes\n", total_code_size);
635
620 // Run the start function if one was specified. 636 // Run the start function if one was specified.
621 if (this->start_function_index >= 0) { 637 if (this->start_function_index >= 0) {
622 HandleScope scope(isolate); 638 HandleScope scope(isolate);
623 uint32_t index = static_cast<uint32_t>(this->start_function_index); 639 uint32_t index = static_cast<uint32_t>(this->start_function_index);
624 Handle<String> name = isolate->factory()->NewStringFromStaticChars("start"); 640 Handle<String> name = isolate->factory()->NewStringFromStaticChars("start");
625 Handle<Code> code = linker.GetFunctionCode(index); 641 Handle<Code> code = linker.GetFunctionCode(index);
626 Handle<JSFunction> jsfunc = compiler::CompileJSToWasmWrapper( 642 Handle<JSFunction> jsfunc = compiler::CompileJSToWasmWrapper(
627 isolate, &module_env, name, code, instance.js_object, index); 643 isolate, &module_env, name, code, instance.js_object, index);
628 644
629 // Call the JS function. 645 // Call the JS function.
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 } 779 }
764 if (result->IsHeapNumber()) { 780 if (result->IsHeapNumber()) {
765 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); 781 return static_cast<int32_t>(HeapNumber::cast(*result)->value());
766 } 782 }
767 thrower.Error("WASM.compileRun() failed: Return value should be number"); 783 thrower.Error("WASM.compileRun() failed: Return value should be number");
768 return -1; 784 return -1;
769 } 785 }
770 } // namespace wasm 786 } // namespace wasm
771 } // namespace internal 787 } // namespace internal
772 } // namespace v8 788 } // namespace v8
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698