| 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "src/assembler-inl.h" | 7 #include "src/assembler-inl.h" |
| 8 #include "src/base/adapters.h" | 8 #include "src/base/adapters.h" |
| 9 #include "src/base/atomic-utils.h" | 9 #include "src/base/atomic-utils.h" |
| 10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 } | 314 } |
| 315 int j = unit->index(); | 315 int j = unit->index(); |
| 316 results[j] = unit->FinishCompilation(); | 316 results[j] = unit->FinishCompilation(); |
| 317 delete unit; | 317 delete unit; |
| 318 } | 318 } |
| 319 } | 319 } |
| 320 | 320 |
| 321 void CompileInParallel(Isolate* isolate, ModuleBytesEnv* module_env, | 321 void CompileInParallel(Isolate* isolate, ModuleBytesEnv* module_env, |
| 322 std::vector<Handle<Code>>& functions, | 322 std::vector<Handle<Code>>& functions, |
| 323 ErrorThrower* thrower) { | 323 ErrorThrower* thrower) { |
| 324 const WasmModule* module = module_env->module; | 324 const WasmModule* module = module_env->module_env.module; |
| 325 // Data structures for the parallel compilation. | 325 // Data structures for the parallel compilation. |
| 326 std::vector<compiler::WasmCompilationUnit*> compilation_units( | 326 std::vector<compiler::WasmCompilationUnit*> compilation_units( |
| 327 module->functions.size()); | 327 module->functions.size()); |
| 328 std::queue<compiler::WasmCompilationUnit*> executed_units; | 328 std::queue<compiler::WasmCompilationUnit*> executed_units; |
| 329 | 329 |
| 330 //----------------------------------------------------------------------- | 330 //----------------------------------------------------------------------- |
| 331 // For parallel compilation: | 331 // For parallel compilation: |
| 332 // 1) The main thread allocates a compilation unit for each wasm function | 332 // 1) The main thread allocates a compilation unit for each wasm function |
| 333 // and stores them in the vector {compilation_units}. | 333 // and stores them in the vector {compilation_units}. |
| 334 // 2) The main thread spawns {WasmCompilationTask} instances which run on | 334 // 2) The main thread spawns {WasmCompilationTask} instances which run on |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 WaitForCompilationTasks(isolate, task_ids.get(), module->pending_tasks.get()); | 381 WaitForCompilationTasks(isolate, task_ids.get(), module->pending_tasks.get()); |
| 382 // Finish the compilation of the remaining compilation units. | 382 // Finish the compilation of the remaining compilation units. |
| 383 FinishCompilationUnits(executed_units, functions, result_mutex); | 383 FinishCompilationUnits(executed_units, functions, result_mutex); |
| 384 } | 384 } |
| 385 | 385 |
| 386 void CompileSequentially(Isolate* isolate, ModuleBytesEnv* module_env, | 386 void CompileSequentially(Isolate* isolate, ModuleBytesEnv* module_env, |
| 387 std::vector<Handle<Code>>& functions, | 387 std::vector<Handle<Code>>& functions, |
| 388 ErrorThrower* thrower) { | 388 ErrorThrower* thrower) { |
| 389 DCHECK(!thrower->error()); | 389 DCHECK(!thrower->error()); |
| 390 | 390 |
| 391 const WasmModule* module = module_env->module; | 391 const WasmModule* module = module_env->module_env.module; |
| 392 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; | 392 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; |
| 393 i < module->functions.size(); ++i) { | 393 i < module->functions.size(); ++i) { |
| 394 const WasmFunction& func = module->functions[i]; | 394 const WasmFunction& func = module->functions[i]; |
| 395 if (func.imported) continue; // Imports are compiled at instantiation time. | 395 if (func.imported) continue; // Imports are compiled at instantiation time. |
| 396 | 396 |
| 397 Handle<Code> code = Handle<Code>::null(); | 397 Handle<Code> code = Handle<Code>::null(); |
| 398 // Compile the function. | 398 // Compile the function. |
| 399 code = compiler::WasmCompilationUnit::CompileWasmFunction( | 399 code = compiler::WasmCompilationUnit::CompileWasmFunction( |
| 400 thrower, isolate, module_env, &func); | 400 thrower, isolate, module_env, &func); |
| 401 if (code.is_null()) { | 401 if (code.is_null()) { |
| 402 WasmName str = module_env->GetName(&func); | 402 WasmName str = module_env->wire_bytes.GetName(&func); |
| 403 thrower->CompileError("Compilation of #%d:%.*s failed.", i, str.length(), | 403 thrower->CompileError("Compilation of #%d:%.*s failed.", i, str.length(), |
| 404 str.start()); | 404 str.start()); |
| 405 break; | 405 break; |
| 406 } | 406 } |
| 407 // Install the code into the linker table. | 407 // Install the code into the linker table. |
| 408 functions[i] = code; | 408 functions[i] = code; |
| 409 } | 409 } |
| 410 } | 410 } |
| 411 | 411 |
| 412 int ExtractDirectCallIndex(wasm::Decoder& decoder, const byte* pc) { | 412 int ExtractDirectCallIndex(wasm::Decoder& decoder, const byte* pc) { |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 | 723 |
| 724 Handle<Script> CreateWasmScript(Isolate* isolate, | 724 Handle<Script> CreateWasmScript(Isolate* isolate, |
| 725 const ModuleWireBytes& wire_bytes) { | 725 const ModuleWireBytes& wire_bytes) { |
| 726 Handle<Script> script = | 726 Handle<Script> script = |
| 727 isolate->factory()->NewScript(isolate->factory()->empty_string()); | 727 isolate->factory()->NewScript(isolate->factory()->empty_string()); |
| 728 FixedArray* array = isolate->native_context()->embedder_data(); | 728 FixedArray* array = isolate->native_context()->embedder_data(); |
| 729 script->set_context_data(array->get(v8::Context::kDebugIdIndex)); | 729 script->set_context_data(array->get(v8::Context::kDebugIdIndex)); |
| 730 script->set_type(Script::TYPE_WASM); | 730 script->set_type(Script::TYPE_WASM); |
| 731 | 731 |
| 732 int hash = StringHasher::HashSequentialString( | 732 int hash = StringHasher::HashSequentialString( |
| 733 reinterpret_cast<const char*>(wire_bytes.module_bytes.start()), | 733 reinterpret_cast<const char*>(wire_bytes.start()), wire_bytes.length(), |
| 734 wire_bytes.module_bytes.length(), kZeroHashSeed); | 734 kZeroHashSeed); |
| 735 | 735 |
| 736 const int kBufferSize = 50; | 736 const int kBufferSize = 50; |
| 737 char buffer[kBufferSize]; | 737 char buffer[kBufferSize]; |
| 738 int url_chars = SNPrintF(ArrayVector(buffer), "wasm://wasm/%08x", hash); | 738 int url_chars = SNPrintF(ArrayVector(buffer), "wasm://wasm/%08x", hash); |
| 739 DCHECK(url_chars >= 0 && url_chars < kBufferSize); | 739 DCHECK(url_chars >= 0 && url_chars < kBufferSize); |
| 740 MaybeHandle<String> url_str = isolate->factory()->NewStringFromOneByte( | 740 MaybeHandle<String> url_str = isolate->factory()->NewStringFromOneByte( |
| 741 Vector<const uint8_t>(reinterpret_cast<uint8_t*>(buffer), url_chars), | 741 Vector<const uint8_t>(reinterpret_cast<uint8_t*>(buffer), url_chars), |
| 742 TENURED); | 742 TENURED); |
| 743 script->set_source_url(*url_str.ToHandleChecked()); | 743 script->set_source_url(*url_str.ToHandleChecked()); |
| 744 | 744 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 } else { | 963 } else { |
| 964 script = asm_js_script; | 964 script = asm_js_script; |
| 965 asm_js_offset_table = | 965 asm_js_offset_table = |
| 966 isolate->factory()->NewByteArray(asm_js_offset_table_bytes.length()); | 966 isolate->factory()->NewByteArray(asm_js_offset_table_bytes.length()); |
| 967 asm_js_offset_table->copy_in(0, asm_js_offset_table_bytes.start(), | 967 asm_js_offset_table->copy_in(0, asm_js_offset_table_bytes.start(), |
| 968 asm_js_offset_table_bytes.length()); | 968 asm_js_offset_table_bytes.length()); |
| 969 } | 969 } |
| 970 // TODO(wasm): only save the sections necessary to deserialize a | 970 // TODO(wasm): only save the sections necessary to deserialize a |
| 971 // {WasmModule}. E.g. function bodies could be omitted. | 971 // {WasmModule}. E.g. function bodies could be omitted. |
| 972 Handle<String> module_bytes = | 972 Handle<String> module_bytes = |
| 973 factory->NewStringFromOneByte(wire_bytes.module_bytes, TENURED) | 973 factory |
| 974 ->NewStringFromOneByte({wire_bytes.start(), wire_bytes.length()}, |
| 975 TENURED) |
| 974 .ToHandleChecked(); | 976 .ToHandleChecked(); |
| 975 DCHECK(module_bytes->IsSeqOneByteString()); | 977 DCHECK(module_bytes->IsSeqOneByteString()); |
| 976 | 978 |
| 977 // Create the shared module data. | 979 // Create the shared module data. |
| 978 // TODO(clemensh): For the same module (same bytes / same hash), we should | 980 // TODO(clemensh): For the same module (same bytes / same hash), we should |
| 979 // only have one WasmSharedModuleData. Otherwise, we might only set | 981 // only have one WasmSharedModuleData. Otherwise, we might only set |
| 980 // breakpoints on a (potentially empty) subset of the instances. | 982 // breakpoints on a (potentially empty) subset of the instances. |
| 981 | 983 |
| 982 Handle<WasmSharedModuleData> shared = WasmSharedModuleData::New( | 984 Handle<WasmSharedModuleData> shared = WasmSharedModuleData::New( |
| 983 isolate, module_wrapper, Handle<SeqOneByteString>::cast(module_bytes), | 985 isolate, module_wrapper, Handle<SeqOneByteString>::cast(module_bytes), |
| (...skipping 1697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2681 | 2683 |
| 2682 JSObject::AddProperty(entry, name_string, export_name.ToHandleChecked(), | 2684 JSObject::AddProperty(entry, name_string, export_name.ToHandleChecked(), |
| 2683 NONE); | 2685 NONE); |
| 2684 JSObject::AddProperty(entry, kind_string, export_kind, NONE); | 2686 JSObject::AddProperty(entry, kind_string, export_kind, NONE); |
| 2685 | 2687 |
| 2686 storage->set(index, *entry); | 2688 storage->set(index, *entry); |
| 2687 } | 2689 } |
| 2688 | 2690 |
| 2689 return array_object; | 2691 return array_object; |
| 2690 } | 2692 } |
| OLD | NEW |