| 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/base/atomic-utils.h" | 5 #include "src/base/atomic-utils.h" |
| 6 #include "src/macro-assembler.h" | 6 #include "src/macro-assembler.h" |
| 7 #include "src/objects.h" | 7 #include "src/objects.h" |
| 8 #include "src/property-descriptor.h" | 8 #include "src/property-descriptor.h" |
| 9 #include "src/v8.h" | 9 #include "src/v8.h" |
| 10 | 10 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 void* memory = isolate->array_buffer_allocator()->Allocate(size); | 171 void* memory = isolate->array_buffer_allocator()->Allocate(size); |
| 172 if (memory == nullptr) { | 172 if (memory == nullptr) { |
| 173 return Handle<JSArrayBuffer>::null(); | 173 return Handle<JSArrayBuffer>::null(); |
| 174 } | 174 } |
| 175 | 175 |
| 176 *backing_store = reinterpret_cast<byte*>(memory); | 176 *backing_store = reinterpret_cast<byte*>(memory); |
| 177 | 177 |
| 178 #if DEBUG | 178 #if DEBUG |
| 179 // Double check the API allocator actually zero-initialized the memory. | 179 // Double check the API allocator actually zero-initialized the memory. |
| 180 byte* bytes = reinterpret_cast<byte*>(*backing_store); | 180 byte* bytes = reinterpret_cast<byte*>(*backing_store); |
| 181 for (size_t i = 0; i < size; i++) { | 181 for (size_t i = 0; i < size; ++i) { |
| 182 DCHECK_EQ(0, bytes[i]); | 182 DCHECK_EQ(0, bytes[i]); |
| 183 } | 183 } |
| 184 #endif | 184 #endif |
| 185 | 185 |
| 186 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); | 186 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); |
| 187 JSArrayBuffer::Setup(buffer, isolate, false, memory, static_cast<int>(size)); | 187 JSArrayBuffer::Setup(buffer, isolate, false, memory, static_cast<int>(size)); |
| 188 buffer->set_is_neuterable(false); | 188 buffer->set_is_neuterable(false); |
| 189 return buffer; | 189 return buffer; |
| 190 } | 190 } |
| 191 | 191 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 modified = true; | 307 modified = true; |
| 308 } | 308 } |
| 309 } | 309 } |
| 310 } | 310 } |
| 311 } | 311 } |
| 312 return modified; | 312 return modified; |
| 313 } | 313 } |
| 314 | 314 |
| 315 void LinkModuleFunctions(Isolate* isolate, | 315 void LinkModuleFunctions(Isolate* isolate, |
| 316 std::vector<Handle<Code>>& functions) { | 316 std::vector<Handle<Code>>& functions) { |
| 317 for (size_t i = 0; i < functions.size(); i++) { | 317 for (size_t i = 0; i < functions.size(); ++i) { |
| 318 Handle<Code> code = functions[i]; | 318 Handle<Code> code = functions[i]; |
| 319 bool modified = LinkFunction(code, functions, Code::WASM_FUNCTION); | 319 bool modified = LinkFunction(code, functions, Code::WASM_FUNCTION); |
| 320 if (modified) { | 320 if (modified) { |
| 321 Assembler::FlushICache(isolate, code->instruction_start(), | 321 Assembler::FlushICache(isolate, code->instruction_start(), |
| 322 code->instruction_size()); | 322 code->instruction_size()); |
| 323 } | 323 } |
| 324 } | 324 } |
| 325 } | 325 } |
| 326 | 326 |
| 327 void LinkImports(Isolate* isolate, std::vector<Handle<Code>>& functions, | 327 void LinkImports(Isolate* isolate, std::vector<Handle<Code>>& functions, |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 instance->import_code[index] = code; | 514 instance->import_code[index] = code; |
| 515 } | 515 } |
| 516 } | 516 } |
| 517 return true; | 517 return true; |
| 518 } | 518 } |
| 519 | 519 |
| 520 void InitializeParallelCompilation( | 520 void InitializeParallelCompilation( |
| 521 Isolate* isolate, const std::vector<WasmFunction>& functions, | 521 Isolate* isolate, const std::vector<WasmFunction>& functions, |
| 522 std::vector<compiler::WasmCompilationUnit*>& compilation_units, | 522 std::vector<compiler::WasmCompilationUnit*>& compilation_units, |
| 523 ModuleEnv& module_env, ErrorThrower& thrower) { | 523 ModuleEnv& module_env, ErrorThrower& thrower) { |
| 524 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); i++) { | 524 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); ++i) { |
| 525 compilation_units[i] = new compiler::WasmCompilationUnit( | 525 compilation_units[i] = new compiler::WasmCompilationUnit( |
| 526 &thrower, isolate, &module_env, &functions[i], i); | 526 &thrower, isolate, &module_env, &functions[i], i); |
| 527 } | 527 } |
| 528 } | 528 } |
| 529 | 529 |
| 530 uint32_t* StartCompilationTasks( | 530 uint32_t* StartCompilationTasks( |
| 531 Isolate* isolate, | 531 Isolate* isolate, |
| 532 std::vector<compiler::WasmCompilationUnit*>& compilation_units, | 532 std::vector<compiler::WasmCompilationUnit*>& compilation_units, |
| 533 std::queue<compiler::WasmCompilationUnit*>& executed_units, | 533 std::queue<compiler::WasmCompilationUnit*>& executed_units, |
| 534 base::Semaphore* pending_tasks, base::Mutex& result_mutex, | 534 base::Semaphore* pending_tasks, base::Mutex& result_mutex, |
| 535 base::AtomicNumber<size_t>& next_unit) { | 535 base::AtomicNumber<size_t>& next_unit) { |
| 536 const size_t num_tasks = | 536 const size_t num_tasks = |
| 537 Min(static_cast<size_t>(FLAG_wasm_num_compilation_tasks), | 537 Min(static_cast<size_t>(FLAG_wasm_num_compilation_tasks), |
| 538 V8::GetCurrentPlatform()->NumberOfAvailableBackgroundThreads()); | 538 V8::GetCurrentPlatform()->NumberOfAvailableBackgroundThreads()); |
| 539 uint32_t* task_ids = new uint32_t[num_tasks]; | 539 uint32_t* task_ids = new uint32_t[num_tasks]; |
| 540 for (size_t i = 0; i < num_tasks; i++) { | 540 for (size_t i = 0; i < num_tasks; ++i) { |
| 541 WasmCompilationTask* task = | 541 WasmCompilationTask* task = |
| 542 new WasmCompilationTask(isolate, &compilation_units, &executed_units, | 542 new WasmCompilationTask(isolate, &compilation_units, &executed_units, |
| 543 pending_tasks, &result_mutex, &next_unit); | 543 pending_tasks, &result_mutex, &next_unit); |
| 544 task_ids[i] = task->id(); | 544 task_ids[i] = task->id(); |
| 545 V8::GetCurrentPlatform()->CallOnBackgroundThread( | 545 V8::GetCurrentPlatform()->CallOnBackgroundThread( |
| 546 task, v8::Platform::kShortRunningTask); | 546 task, v8::Platform::kShortRunningTask); |
| 547 } | 547 } |
| 548 return task_ids; | 548 return task_ids; |
| 549 } | 549 } |
| 550 | 550 |
| 551 void WaitForCompilationTasks(Isolate* isolate, uint32_t* task_ids, | 551 void WaitForCompilationTasks(Isolate* isolate, uint32_t* task_ids, |
| 552 base::Semaphore* pending_tasks) { | 552 base::Semaphore* pending_tasks) { |
| 553 const size_t num_tasks = | 553 const size_t num_tasks = |
| 554 Min(static_cast<size_t>(FLAG_wasm_num_compilation_tasks), | 554 Min(static_cast<size_t>(FLAG_wasm_num_compilation_tasks), |
| 555 V8::GetCurrentPlatform()->NumberOfAvailableBackgroundThreads()); | 555 V8::GetCurrentPlatform()->NumberOfAvailableBackgroundThreads()); |
| 556 for (size_t i = 0; i < num_tasks; i++) { | 556 for (size_t i = 0; i < num_tasks; ++i) { |
| 557 // If the task has not started yet, then we abort it. Otherwise we wait for | 557 // If the task has not started yet, then we abort it. Otherwise we wait for |
| 558 // it to finish. | 558 // it to finish. |
| 559 if (!isolate->cancelable_task_manager()->TryAbort(task_ids[i])) { | 559 if (!isolate->cancelable_task_manager()->TryAbort(task_ids[i])) { |
| 560 pending_tasks->Wait(); | 560 pending_tasks->Wait(); |
| 561 } | 561 } |
| 562 } | 562 } |
| 563 } | 563 } |
| 564 | 564 |
| 565 void FinishCompilationUnits( | 565 void FinishCompilationUnits( |
| 566 std::queue<compiler::WasmCompilationUnit*>& executed_units, | 566 std::queue<compiler::WasmCompilationUnit*>& executed_units, |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 // Finish the compilation of the remaining compilation units. | 644 // Finish the compilation of the remaining compilation units. |
| 645 FinishCompilationUnits(executed_units, functions, result_mutex); | 645 FinishCompilationUnits(executed_units, functions, result_mutex); |
| 646 } | 646 } |
| 647 | 647 |
| 648 void CompileSequentially(Isolate* isolate, const WasmModule* module, | 648 void CompileSequentially(Isolate* isolate, const WasmModule* module, |
| 649 std::vector<Handle<Code>>& functions, | 649 std::vector<Handle<Code>>& functions, |
| 650 ErrorThrower* thrower, ModuleEnv* module_env) { | 650 ErrorThrower* thrower, ModuleEnv* module_env) { |
| 651 DCHECK(!thrower->error()); | 651 DCHECK(!thrower->error()); |
| 652 | 652 |
| 653 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; | 653 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; |
| 654 i < module->functions.size(); i++) { | 654 i < module->functions.size(); ++i) { |
| 655 const WasmFunction& func = module->functions[i]; | 655 const WasmFunction& func = module->functions[i]; |
| 656 | 656 |
| 657 DCHECK_EQ(i, func.func_index); | 657 DCHECK_EQ(i, func.func_index); |
| 658 WasmName str = module->GetName(func.name_offset, func.name_length); | 658 WasmName str = module->GetName(func.name_offset, func.name_length); |
| 659 Handle<Code> code = Handle<Code>::null(); | 659 Handle<Code> code = Handle<Code>::null(); |
| 660 // Compile the function. | 660 // Compile the function. |
| 661 code = compiler::WasmCompilationUnit::CompileWasmFunction( | 661 code = compiler::WasmCompilationUnit::CompileWasmFunction( |
| 662 thrower, isolate, module_env, &func); | 662 thrower, isolate, module_env, &func); |
| 663 if (code.is_null()) { | 663 if (code.is_null()) { |
| 664 thrower->Error("Compilation of #%d:%.*s failed.", i, str.length(), | 664 thrower->Error("Compilation of #%d:%.*s failed.", i, str.length(), |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1122 Object* info = wasm->GetInternalField(kWasmDebugInfo); | 1122 Object* info = wasm->GetInternalField(kWasmDebugInfo); |
| 1123 if (!info->IsUndefined(wasm->GetIsolate())) return WasmDebugInfo::cast(info); | 1123 if (!info->IsUndefined(wasm->GetIsolate())) return WasmDebugInfo::cast(info); |
| 1124 Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(handle(wasm)); | 1124 Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(handle(wasm)); |
| 1125 wasm->SetInternalField(kWasmDebugInfo, *new_info); | 1125 wasm->SetInternalField(kWasmDebugInfo, *new_info); |
| 1126 return *new_info; | 1126 return *new_info; |
| 1127 } | 1127 } |
| 1128 | 1128 |
| 1129 } // namespace wasm | 1129 } // namespace wasm |
| 1130 } // namespace internal | 1130 } // namespace internal |
| 1131 } // namespace v8 | 1131 } // namespace v8 |
| OLD | NEW |