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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "src/base/atomic-utils.h" | 7 #include "src/base/atomic-utils.h" |
| 8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
| 9 | 9 |
| 10 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 // add another Internal Field as the function arity | 137 // add another Internal Field as the function arity |
| 138 function->SetInternalField(kInternalArity, Smi::FromInt(arity)); | 138 function->SetInternalField(kInternalArity, Smi::FromInt(arity)); |
| 139 // add another Internal Field as the signature of the foreign function | 139 // add another Internal Field as the signature of the foreign function |
| 140 Handle<ByteArray> signature; | 140 Handle<ByteArray> signature; |
| 141 if (maybe_signature.ToHandle(&signature)) { | 141 if (maybe_signature.ToHandle(&signature)) { |
| 142 function->SetInternalField(kInternalSignature, *signature); | 142 function->SetInternalField(kInternalSignature, *signature); |
| 143 } | 143 } |
| 144 return function; | 144 return function; |
| 145 } | 145 } |
| 146 | 146 |
| 147 Object* GetOwningWasmInstance(Object* undefined, Code* code) { | |
|
bradnelson
2016/08/29 19:09:48
Why pass undefined in instead of the isolate?
Mircea Trofin
2016/08/29 19:12:22
Because undefined is the only needed value, rather
| |
| 148 DCHECK(code->kind() == Code::WASM_FUNCTION); | |
| 149 DisallowHeapAllocation no_gc; | |
| 150 FixedArray* deopt_data = code->deoptimization_data(); | |
| 151 DCHECK_NOT_NULL(deopt_data); | |
| 152 DCHECK(deopt_data->length() == 2); | |
| 153 Object* weak_link = deopt_data->get(0); | |
| 154 if (weak_link == undefined) return undefined; | |
| 155 WeakCell* cell = WeakCell::cast(weak_link); | |
| 156 return cell->value(); | |
| 157 } | |
| 158 | |
| 147 namespace { | 159 namespace { |
| 148 // Internal constants for the layout of the module object. | 160 // Internal constants for the layout of the module object. |
| 149 const int kWasmModuleFunctionTable = 0; | 161 const int kWasmModuleFunctionTable = 0; |
| 150 const int kWasmModuleCodeTable = 1; | 162 const int kWasmModuleCodeTable = 1; |
| 151 const int kWasmMemArrayBuffer = 2; | 163 const int kWasmMemArrayBuffer = 2; |
| 152 const int kWasmGlobalsArrayBuffer = 3; | 164 const int kWasmGlobalsArrayBuffer = 3; |
| 153 // TODO(clemensh): Remove function name array, extract names from module bytes. | 165 // TODO(clemensh): Remove function name array, extract names from module bytes. |
| 154 const int kWasmFunctionNamesArray = 4; | 166 const int kWasmFunctionNamesArray = 4; |
| 155 const int kWasmModuleBytesString = 5; | 167 const int kWasmModuleBytesString = 5; |
| 156 const int kWasmDebugInfo = 6; | 168 const int kWasmDebugInfo = 6; |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 427 } | 439 } |
| 428 | 440 |
| 429 void FlushAssemblyCache(Isolate* isolate, Handle<FixedArray> functions) { | 441 void FlushAssemblyCache(Isolate* isolate, Handle<FixedArray> functions) { |
| 430 for (int i = 0; i < functions->length(); ++i) { | 442 for (int i = 0; i < functions->length(); ++i) { |
| 431 Handle<Code> code = functions->GetValueChecked<Code>(isolate, i); | 443 Handle<Code> code = functions->GetValueChecked<Code>(isolate, i); |
| 432 Assembler::FlushICache(isolate, code->instruction_start(), | 444 Assembler::FlushICache(isolate, code->instruction_start(), |
| 433 code->instruction_size()); | 445 code->instruction_size()); |
| 434 } | 446 } |
| 435 } | 447 } |
| 436 | 448 |
| 449 void SetRuntimeSupport(Isolate* isolate, Handle<JSObject> js_object) { | |
| 450 Handle<FixedArray> functions = Handle<FixedArray>( | |
| 451 FixedArray::cast(js_object->GetInternalField(kWasmModuleCodeTable))); | |
| 452 Handle<WeakCell> weak_link = isolate->factory()->NewWeakCell(js_object); | |
| 453 | |
| 454 for (int i = FLAG_skip_compiling_wasm_funcs; i < functions->length(); ++i) { | |
| 455 Handle<Code> code = functions->GetValueChecked<Code>(isolate, i); | |
| 456 DCHECK(code->deoptimization_data() == nullptr || | |
| 457 code->deoptimization_data()->length() == 0); | |
| 458 Handle<FixedArray> deopt_data = | |
| 459 isolate->factory()->NewFixedArray(2, TENURED); | |
| 460 deopt_data->set(0, *weak_link); | |
| 461 deopt_data->set(1, Smi::FromInt(static_cast<int>(i))); | |
| 462 deopt_data->set_length(2); | |
| 463 code->set_deoptimization_data(*deopt_data); | |
| 464 } | |
| 465 } | |
| 466 | |
| 437 } // namespace | 467 } // namespace |
| 438 | 468 |
| 439 WasmModule::WasmModule(byte* module_start) | 469 WasmModule::WasmModule(byte* module_start) |
| 440 : module_start(module_start), | 470 : module_start(module_start), |
| 441 module_end(nullptr), | 471 module_end(nullptr), |
| 442 min_mem_pages(0), | 472 min_mem_pages(0), |
| 443 max_mem_pages(0), | 473 max_mem_pages(0), |
| 444 mem_export(false), | 474 mem_export(false), |
| 445 mem_external(false), | 475 mem_external(false), |
| 446 start_function_index(-1), | 476 start_function_index(-1), |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 866 | 896 |
| 867 void SetDebugSupport(Factory* factory, Handle<FixedArray> compiled_module, | 897 void SetDebugSupport(Factory* factory, Handle<FixedArray> compiled_module, |
| 868 Handle<JSObject> js_object) { | 898 Handle<JSObject> js_object) { |
| 869 Isolate* isolate = compiled_module->GetIsolate(); | 899 Isolate* isolate = compiled_module->GetIsolate(); |
| 870 MaybeHandle<String> module_bytes_string = | 900 MaybeHandle<String> module_bytes_string = |
| 871 compiled_module->GetValue<String>(isolate, kModuleBytes); | 901 compiled_module->GetValue<String>(isolate, kModuleBytes); |
| 872 if (!module_bytes_string.is_null()) { | 902 if (!module_bytes_string.is_null()) { |
| 873 js_object->SetInternalField(kWasmModuleBytesString, | 903 js_object->SetInternalField(kWasmModuleBytesString, |
| 874 *module_bytes_string.ToHandleChecked()); | 904 *module_bytes_string.ToHandleChecked()); |
| 875 } | 905 } |
| 876 Handle<FixedArray> functions = Handle<FixedArray>( | |
| 877 FixedArray::cast(js_object->GetInternalField(kWasmModuleCodeTable))); | |
| 878 | |
| 879 for (int i = FLAG_skip_compiling_wasm_funcs; i < functions->length(); ++i) { | |
| 880 Handle<Code> code = functions->GetValueChecked<Code>(isolate, i); | |
| 881 DCHECK(code->deoptimization_data() == nullptr || | |
| 882 code->deoptimization_data()->length() == 0); | |
| 883 Handle<FixedArray> deopt_data = factory->NewFixedArray(2, TENURED); | |
| 884 if (!js_object.is_null()) { | |
| 885 deopt_data->set(0, *js_object); | |
| 886 } | |
| 887 deopt_data->set(1, Smi::FromInt(static_cast<int>(i))); | |
| 888 deopt_data->set_length(2); | |
| 889 code->set_deoptimization_data(*deopt_data); | |
| 890 } | |
| 891 | 906 |
| 892 MaybeHandle<ByteArray> function_name_table = | 907 MaybeHandle<ByteArray> function_name_table = |
| 893 compiled_module->GetValue<ByteArray>(isolate, kFunctionNameTable); | 908 compiled_module->GetValue<ByteArray>(isolate, kFunctionNameTable); |
| 894 if (!function_name_table.is_null()) { | 909 if (!function_name_table.is_null()) { |
| 895 js_object->SetInternalField(kWasmFunctionNamesArray, | 910 js_object->SetInternalField(kWasmFunctionNamesArray, |
| 896 *function_name_table.ToHandleChecked()); | 911 *function_name_table.ToHandleChecked()); |
| 897 } | 912 } |
| 898 } | 913 } |
| 899 | 914 |
| 900 bool SetupGlobals(Isolate* isolate, Handle<FixedArray> compiled_module, | 915 bool SetupGlobals(Isolate* isolate, Handle<FixedArray> compiled_module, |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1390 | 1405 |
| 1391 if (!(SetupInstanceHeap(isolate, compiled_module, js_object, memory, | 1406 if (!(SetupInstanceHeap(isolate, compiled_module, js_object, memory, |
| 1392 &thrower) && | 1407 &thrower) && |
| 1393 SetupGlobals(isolate, compiled_module, js_object, &thrower) && | 1408 SetupGlobals(isolate, compiled_module, js_object, &thrower) && |
| 1394 SetupImports(isolate, compiled_module, js_object, &thrower, ffi) && | 1409 SetupImports(isolate, compiled_module, js_object, &thrower, ffi) && |
| 1395 SetupExportsObject(compiled_module, isolate, js_object, &thrower))) { | 1410 SetupExportsObject(compiled_module, isolate, js_object, &thrower))) { |
| 1396 return nothing; | 1411 return nothing; |
| 1397 } | 1412 } |
| 1398 | 1413 |
| 1399 SetDebugSupport(factory, compiled_module, js_object); | 1414 SetDebugSupport(factory, compiled_module, js_object); |
| 1415 SetRuntimeSupport(isolate, js_object); | |
| 1400 | 1416 |
| 1401 FlushAssemblyCache(isolate, code_table); | 1417 FlushAssemblyCache(isolate, code_table); |
| 1402 | 1418 |
| 1403 MaybeHandle<FixedArray> maybe_indirect_tables = | 1419 MaybeHandle<FixedArray> maybe_indirect_tables = |
| 1404 compiled_module->GetValue<FixedArray>(isolate, | 1420 compiled_module->GetValue<FixedArray>(isolate, |
| 1405 kTableOfIndirectFunctionTables); | 1421 kTableOfIndirectFunctionTables); |
| 1406 Handle<FixedArray> indirect_tables_template; | 1422 Handle<FixedArray> indirect_tables_template; |
| 1407 if (maybe_indirect_tables.ToHandle(&indirect_tables_template)) { | 1423 if (maybe_indirect_tables.ToHandle(&indirect_tables_template)) { |
| 1408 Handle<FixedArray> indirect_tables = SetupIndirectFunctionTable( | 1424 Handle<FixedArray> indirect_tables = SetupIndirectFunctionTable( |
| 1409 isolate, code_table, indirect_tables_template); | 1425 isolate, code_table, indirect_tables_template); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1699 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); | 1715 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); |
| 1700 } | 1716 } |
| 1701 thrower->Error("WASM.compileRun() failed: Return value should be number"); | 1717 thrower->Error("WASM.compileRun() failed: Return value should be number"); |
| 1702 return -1; | 1718 return -1; |
| 1703 } | 1719 } |
| 1704 | 1720 |
| 1705 } // namespace testing | 1721 } // namespace testing |
| 1706 } // namespace wasm | 1722 } // namespace wasm |
| 1707 } // namespace internal | 1723 } // namespace internal |
| 1708 } // namespace v8 | 1724 } // namespace v8 |
| OLD | NEW |