Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/compiler/wasm-compiler.h" | 5 #include "src/compiler/wasm-compiler.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "src/assembler-inl.h" | 9 #include "src/assembler-inl.h" |
| 10 #include "src/base/platform/elapsed-timer.h" | 10 #include "src/base/platform/elapsed-timer.h" |
| (...skipping 3890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3901 DCHECK(name_len > 0 && name_len < name_vector.length()); | 3901 DCHECK(name_len > 0 && name_len < name_vector.length()); |
| 3902 | 3902 |
| 3903 char* index_name = zone->NewArray<char>(name_len); | 3903 char* index_name = zone->NewArray<char>(name_len); |
| 3904 memcpy(index_name, name_vector.start(), name_len); | 3904 memcpy(index_name, name_vector.start(), name_len); |
| 3905 return Vector<const char>(index_name, name_len); | 3905 return Vector<const char>(index_name, name_len); |
| 3906 } | 3906 } |
| 3907 } // namespace | 3907 } // namespace |
| 3908 | 3908 |
| 3909 WasmCompilationUnit::WasmCompilationUnit(Isolate* isolate, | 3909 WasmCompilationUnit::WasmCompilationUnit(Isolate* isolate, |
| 3910 wasm::ModuleBytesEnv* module_env, | 3910 wasm::ModuleBytesEnv* module_env, |
| 3911 const wasm::WasmFunction* function, | 3911 const wasm::WasmFunction* function) |
| 3912 bool is_sync) | |
| 3913 : WasmCompilationUnit( | 3912 : WasmCompilationUnit( |
| 3914 isolate, &module_env->module_env, | 3913 isolate, &module_env->module_env, |
| 3915 wasm::FunctionBody{ | 3914 wasm::FunctionBody{ |
| 3916 function->sig, module_env->wire_bytes.start(), | 3915 function->sig, module_env->wire_bytes.start(), |
| 3917 module_env->wire_bytes.start() + function->code_start_offset, | 3916 module_env->wire_bytes.start() + function->code_start_offset, |
| 3918 module_env->wire_bytes.start() + function->code_end_offset}, | 3917 module_env->wire_bytes.start() + function->code_end_offset}, |
| 3919 module_env->wire_bytes.GetNameOrNull(function), function->func_index, | 3918 module_env->wire_bytes.GetNameOrNull(function), |
| 3920 is_sync) {} | 3919 function->func_index) {} |
| 3921 | 3920 |
| 3922 WasmCompilationUnit::WasmCompilationUnit(Isolate* isolate, | 3921 WasmCompilationUnit::WasmCompilationUnit(Isolate* isolate, |
| 3923 wasm::ModuleEnv* module_env, | 3922 wasm::ModuleEnv* module_env, |
| 3924 wasm::FunctionBody body, | 3923 wasm::FunctionBody body, |
| 3925 wasm::WasmName name, int index, | 3924 wasm::WasmName name, int index) |
| 3926 bool is_sync) | |
| 3927 : isolate_(isolate), | 3925 : isolate_(isolate), |
| 3928 module_env_(module_env), | 3926 module_env_(module_env), |
| 3929 func_body_(body), | 3927 func_body_(body), |
| 3930 func_name_(name), | 3928 func_name_(name), |
| 3931 is_sync_(is_sync), | |
| 3932 graph_zone_(new Zone(isolate->allocator(), ZONE_NAME)), | 3929 graph_zone_(new Zone(isolate->allocator(), ZONE_NAME)), |
| 3933 jsgraph_(new (graph_zone()) JSGraph( | 3930 jsgraph_(new (graph_zone()) JSGraph( |
| 3934 isolate, new (graph_zone()) Graph(graph_zone()), | 3931 isolate, new (graph_zone()) Graph(graph_zone()), |
| 3935 new (graph_zone()) CommonOperatorBuilder(graph_zone()), nullptr, | 3932 new (graph_zone()) CommonOperatorBuilder(graph_zone()), nullptr, |
| 3936 nullptr, | 3933 nullptr, |
| 3937 new (graph_zone()) MachineOperatorBuilder( | 3934 new (graph_zone()) MachineOperatorBuilder( |
| 3938 graph_zone(), MachineType::PointerRepresentation(), | 3935 graph_zone(), MachineType::PointerRepresentation(), |
| 3939 InstructionSelector::SupportedMachineOperatorFlags(), | 3936 InstructionSelector::SupportedMachineOperatorFlags(), |
| 3940 InstructionSelector::AlignmentRequirements()))), | 3937 InstructionSelector::AlignmentRequirements()))), |
| 3941 compilation_zone_(isolate->allocator(), ZONE_NAME), | 3938 compilation_zone_(isolate->allocator(), ZONE_NAME), |
| 3942 info_(GetDebugName(&compilation_zone_, name, index), isolate, | 3939 info_(GetDebugName(&compilation_zone_, name, index), isolate, |
| 3943 &compilation_zone_, Code::ComputeFlags(Code::WASM_FUNCTION)), | 3940 &compilation_zone_, Code::ComputeFlags(Code::WASM_FUNCTION)), |
| 3944 func_index_(index), | 3941 func_index_(index), |
| 3945 protected_instructions_(&compilation_zone_) {} | 3942 protected_instructions_(&compilation_zone_) {} |
| 3946 | 3943 |
| 3947 void WasmCompilationUnit::InitializeHandles() { | 3944 void WasmCompilationUnit::InitializeHandles() { |
| 3948 // Create and cache this node in the main thread, which contains a handle to | 3945 // Create and cache this node in the main thread, which contains a handle to |
| 3949 // the code object of the c-entry stub. | 3946 // the code object of the c-entry stub. |
| 3950 jsgraph_->CEntryStubConstant(1); | 3947 jsgraph_->CEntryStubConstant(1); |
| 3951 DCHECK(!handles_initialized_); | 3948 DCHECK(!handles_initialized_); |
| 3952 #if DEBUG | 3949 #if DEBUG |
| 3953 handles_initialized_ = true; | 3950 handles_initialized_ = true; |
| 3954 #endif // DEBUG | 3951 #endif // DEBUG |
| 3955 } | 3952 } |
| 3956 | 3953 |
| 3957 void WasmCompilationUnit::ExecuteCompilation() { | 3954 void WasmCompilationUnit::ExecuteCompilation() { |
| 3958 DCHECK(handles_initialized_); | 3955 DCHECK(handles_initialized_); |
| 3959 if (is_sync_) { | 3956 HistogramTimerScope wasm_compile_function_time_scope( |
| 3960 // TODO(karlschimpf): Make this work when asynchronous. | 3957 isolate_->counters()->wasm_compile_function_time()); |
|
jochen (gone - plz use gerrit)
2017/06/12 09:18:34
no isolate_ deref on background threads
kschimpf
2017/06/12 16:47:04
It turns out that this step is not run in the back
| |
| 3961 // https://bugs.chromium.org/p/v8/issues/detail?id=6361 | |
| 3962 HistogramTimerScope wasm_compile_function_time_scope( | |
| 3963 isolate_->counters()->wasm_compile_function_time()); | |
| 3964 ExecuteCompilationInternal(); | |
| 3965 return; | |
| 3966 } | |
| 3967 ExecuteCompilationInternal(); | |
| 3968 } | |
| 3969 | |
| 3970 void WasmCompilationUnit::ExecuteCompilationInternal() { | |
| 3971 if (FLAG_trace_wasm_compiler) { | 3958 if (FLAG_trace_wasm_compiler) { |
| 3972 if (func_name_.start() != nullptr) { | 3959 if (func_name_.start() != nullptr) { |
| 3973 PrintF("Compiling wasm function %d:'%.*s'\n\n", func_index(), | 3960 PrintF("Compiling wasm function %d:'%.*s'\n\n", func_index(), |
| 3974 func_name_.length(), func_name_.start()); | 3961 func_name_.length(), func_name_.start()); |
| 3975 } else { | 3962 } else { |
| 3976 PrintF("Compiling wasm function %d:<unnamed>\n\n", func_index()); | 3963 PrintF("Compiling wasm function %d:<unnamed>\n\n", func_index()); |
| 3977 } | 3964 } |
| 3978 } | 3965 } |
| 3979 | 3966 |
| 3980 double decode_ms = 0; | 3967 double decode_ms = 0; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 3999 &compilation_zone_, func_body_.sig); | 3986 &compilation_zone_, func_body_.sig); |
| 4000 if (jsgraph_->machine()->Is32()) { | 3987 if (jsgraph_->machine()->Is32()) { |
| 4001 descriptor = | 3988 descriptor = |
| 4002 module_env_->GetI32WasmCallDescriptor(&compilation_zone_, descriptor); | 3989 module_env_->GetI32WasmCallDescriptor(&compilation_zone_, descriptor); |
| 4003 } | 3990 } |
| 4004 job_.reset(Pipeline::NewWasmCompilationJob( | 3991 job_.reset(Pipeline::NewWasmCompilationJob( |
| 4005 &info_, jsgraph_, descriptor, source_positions, &protected_instructions_, | 3992 &info_, jsgraph_, descriptor, source_positions, &protected_instructions_, |
| 4006 !module_env_->module->is_wasm())); | 3993 !module_env_->module->is_wasm())); |
| 4007 ok_ = job_->ExecuteJob() == CompilationJob::SUCCEEDED; | 3994 ok_ = job_->ExecuteJob() == CompilationJob::SUCCEEDED; |
| 4008 // TODO(bradnelson): Improve histogram handling of size_t. | 3995 // TODO(bradnelson): Improve histogram handling of size_t. |
| 4009 if (is_sync_) | 3996 isolate_->counters()->wasm_compile_function_peak_memory_bytes()->AddSample( |
| 4010 // TODO(karlschimpf): Make this work when asynchronous. | 3997 static_cast<int>(jsgraph_->graph()->zone()->allocation_size())); |
| 4011 // https://bugs.chromium.org/p/v8/issues/detail?id=6361 | |
| 4012 isolate_->counters()->wasm_compile_function_peak_memory_bytes()->AddSample( | |
| 4013 static_cast<int>(jsgraph_->graph()->zone()->allocation_size())); | |
| 4014 | 3998 |
| 4015 if (FLAG_trace_wasm_decode_time) { | 3999 if (FLAG_trace_wasm_decode_time) { |
| 4016 double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF(); | 4000 double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF(); |
| 4017 PrintF( | 4001 PrintF( |
| 4018 "wasm-compilation phase 1 ok: %u bytes, %0.3f ms decode, %zu nodes, " | 4002 "wasm-compilation phase 1 ok: %u bytes, %0.3f ms decode, %zu nodes, " |
| 4019 "%0.3f ms pipeline\n", | 4003 "%0.3f ms pipeline\n", |
| 4020 static_cast<unsigned>(func_body_.end - func_body_.start), decode_ms, | 4004 static_cast<unsigned>(func_body_.end - func_body_.start), decode_ms, |
| 4021 node_count, pipeline_ms); | 4005 node_count, pipeline_ms); |
| 4022 } | 4006 } |
| 4023 } | 4007 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4073 wasm::ModuleBytesEnv* module_env, const wasm::WasmFunction* function) { | 4057 wasm::ModuleBytesEnv* module_env, const wasm::WasmFunction* function) { |
| 4074 WasmCompilationUnit unit(isolate, module_env, function); | 4058 WasmCompilationUnit unit(isolate, module_env, function); |
| 4075 unit.InitializeHandles(); | 4059 unit.InitializeHandles(); |
| 4076 unit.ExecuteCompilation(); | 4060 unit.ExecuteCompilation(); |
| 4077 return unit.FinishCompilation(thrower); | 4061 return unit.FinishCompilation(thrower); |
| 4078 } | 4062 } |
| 4079 | 4063 |
| 4080 } // namespace compiler | 4064 } // namespace compiler |
| 4081 } // namespace internal | 4065 } // namespace internal |
| 4082 } // namespace v8 | 4066 } // namespace v8 |
| OLD | NEW |