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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 function_code_[index] = code; | 141 function_code_[index] = code; |
142 } | 142 } |
143 | 143 |
144 void Link(Handle<FixedArray> function_table, | 144 void Link(Handle<FixedArray> function_table, |
145 std::vector<uint16_t>& functions) { | 145 std::vector<uint16_t>& functions) { |
146 for (size_t i = 0; i < function_code_.size(); i++) { | 146 for (size_t i = 0; i < function_code_.size(); i++) { |
147 LinkFunction(function_code_[i]); | 147 LinkFunction(function_code_[i]); |
148 } | 148 } |
149 if (!function_table.is_null()) { | 149 if (!function_table.is_null()) { |
150 int table_size = static_cast<int>(functions.size()); | 150 int table_size = static_cast<int>(functions.size()); |
151 DCHECK_EQ(function_table->length(), table_size * 2); | 151 int indirect_table_size; |
| 152 if (FLAG_wasm_jit_prototype) { |
| 153 indirect_table_size = 4 * table_size < kMinimumIndirectTableSize |
| 154 ? kMinimumIndirectTableSize |
| 155 : 4 * table_size; |
| 156 DCHECK_EQ(function_table->length(), indirect_table_size); |
| 157 } else { |
| 158 indirect_table_size = 2 * table_size; |
| 159 DCHECK_EQ(function_table->length(), indirect_table_size); |
| 160 } |
152 for (int i = 0; i < table_size; i++) { | 161 for (int i = 0; i < table_size; i++) { |
153 function_table->set(i + table_size, *function_code_[functions[i]]); | 162 function_table->set(i + indirect_table_size / 2, |
| 163 *function_code_[functions[i]]); |
154 } | 164 } |
155 } | 165 } |
156 } | 166 } |
157 | 167 |
158 private: | 168 private: |
159 static const int kPlaceholderMarker = 1000000000; | 169 static const int kPlaceholderMarker = 1000000000; |
160 | 170 |
161 Isolate* isolate_; | 171 Isolate* isolate_; |
162 std::vector<Handle<Code>> placeholder_code_; | 172 std::vector<Handle<Code>> placeholder_code_; |
163 std::vector<Handle<Code>> function_code_; | 173 std::vector<Handle<Code>> function_code_; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 memcpy(addr, module->module_start + segment.source_offset, | 236 memcpy(addr, module->module_start + segment.source_offset, |
227 segment.source_size); | 237 segment.source_size); |
228 } | 238 } |
229 } | 239 } |
230 | 240 |
231 Handle<FixedArray> BuildFunctionTable(Isolate* isolate, WasmModule* module) { | 241 Handle<FixedArray> BuildFunctionTable(Isolate* isolate, WasmModule* module) { |
232 if (module->function_table.size() == 0) { | 242 if (module->function_table.size() == 0) { |
233 return Handle<FixedArray>::null(); | 243 return Handle<FixedArray>::null(); |
234 } | 244 } |
235 int table_size = static_cast<int>(module->function_table.size()); | 245 int table_size = static_cast<int>(module->function_table.size()); |
236 Handle<FixedArray> fixed = isolate->factory()->NewFixedArray(2 * table_size); | 246 int indirect_table_size; |
| 247 if (FLAG_wasm_jit_prototype) |
| 248 indirect_table_size = 4 * table_size < kMinimumIndirectTableSize |
| 249 ? kMinimumIndirectTableSize |
| 250 : 4 * table_size; |
| 251 else |
| 252 indirect_table_size = 2 * table_size; |
| 253 |
| 254 Handle<FixedArray> fixed = |
| 255 isolate->factory()->NewFixedArray(indirect_table_size); |
237 for (int i = 0; i < table_size; i++) { | 256 for (int i = 0; i < table_size; i++) { |
238 WasmFunction* function = &module->functions[module->function_table[i]]; | 257 WasmFunction* function = &module->functions[module->function_table[i]]; |
239 fixed->set(i, Smi::FromInt(function->sig_index)); | 258 fixed->set(i, Smi::FromInt(function->sig_index)); |
240 } | 259 } |
241 return fixed; | 260 return fixed; |
242 } | 261 } |
243 | 262 |
244 Handle<JSArrayBuffer> NewArrayBuffer(Isolate* isolate, size_t size, | 263 Handle<JSArrayBuffer> NewArrayBuffer(Isolate* isolate, size_t size, |
245 byte** backing_store) { | 264 byte** backing_store) { |
246 if (size > (WasmModule::kMaxMemPages * WasmModule::kPageSize)) { | 265 if (size > (WasmModule::kMaxMemPages * WasmModule::kPageSize)) { |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 } | 695 } |
677 if (!instance.globals_buffer.is_null()) { | 696 if (!instance.globals_buffer.is_null()) { |
678 instance.js_object->SetInternalField(kWasmGlobalsArrayBuffer, | 697 instance.js_object->SetInternalField(kWasmGlobalsArrayBuffer, |
679 *instance.globals_buffer); | 698 *instance.globals_buffer); |
680 } | 699 } |
681 | 700 |
682 HistogramTimerScope wasm_compile_module_time_scope( | 701 HistogramTimerScope wasm_compile_module_time_scope( |
683 isolate->counters()->wasm_compile_module_time()); | 702 isolate->counters()->wasm_compile_module_time()); |
684 | 703 |
685 instance.function_table = BuildFunctionTable(isolate, this); | 704 instance.function_table = BuildFunctionTable(isolate, this); |
| 705 instance.padded_entries = |
| 706 static_cast<int>(instance.function_table->length() / 2) - |
| 707 static_cast<int>(instance.module->function_table.size()); |
686 WasmLinker linker(isolate, functions.size()); | 708 WasmLinker linker(isolate, functions.size()); |
687 ModuleEnv module_env; | 709 ModuleEnv module_env; |
688 module_env.module = this; | 710 module_env.module = this; |
689 module_env.instance = &instance; | 711 module_env.instance = &instance; |
690 module_env.linker = &linker; | 712 module_env.linker = &linker; |
691 module_env.origin = origin; | 713 module_env.origin = origin; |
692 | 714 |
693 //------------------------------------------------------------------------- | 715 //------------------------------------------------------------------------- |
694 // Compile wrappers to imported functions. | 716 // Compile wrappers to imported functions. |
695 //------------------------------------------------------------------------- | 717 //------------------------------------------------------------------------- |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 } | 929 } |
908 LoadDataSegments(module, instance.mem_start, instance.mem_size); | 930 LoadDataSegments(module, instance.mem_start, instance.mem_size); |
909 | 931 |
910 // Allocate the globals area if necessary. | 932 // Allocate the globals area if necessary. |
911 if (!AllocateGlobals(&thrower, isolate, &instance)) { | 933 if (!AllocateGlobals(&thrower, isolate, &instance)) { |
912 return -1; | 934 return -1; |
913 } | 935 } |
914 | 936 |
915 // Build the function table. | 937 // Build the function table. |
916 instance.function_table = BuildFunctionTable(isolate, module); | 938 instance.function_table = BuildFunctionTable(isolate, module); |
| 939 instance.padded_entries = |
| 940 static_cast<int>(instance.function_table->length() / 2) - |
| 941 static_cast<int>(module->function_table.size()); |
917 | 942 |
918 // Create module environment. | 943 // Create module environment. |
919 WasmLinker linker(isolate, module->functions.size()); | 944 WasmLinker linker(isolate, module->functions.size()); |
920 ModuleEnv module_env; | 945 ModuleEnv module_env; |
921 module_env.module = module; | 946 module_env.module = module; |
922 module_env.instance = &instance; | 947 module_env.instance = &instance; |
923 module_env.linker = &linker; | 948 module_env.linker = &linker; |
924 module_env.origin = module->origin; | 949 module_env.origin = module->origin; |
925 | 950 |
926 // Compile all functions. | 951 // Compile all functions. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 wasm->GetInternalField(kWasmFunctionNamesArray), wasm->GetIsolate()); | 1007 wasm->GetInternalField(kWasmFunctionNamesArray), wasm->GetIsolate()); |
983 if (func_names_arr_obj->IsUndefined()) | 1008 if (func_names_arr_obj->IsUndefined()) |
984 return func_names_arr_obj; // Return undefined. | 1009 return func_names_arr_obj; // Return undefined. |
985 return GetWasmFunctionNameFromTable( | 1010 return GetWasmFunctionNameFromTable( |
986 Handle<ByteArray>::cast(func_names_arr_obj), func_index); | 1011 Handle<ByteArray>::cast(func_names_arr_obj), func_index); |
987 } | 1012 } |
988 | 1013 |
989 } // namespace wasm | 1014 } // namespace wasm |
990 } // namespace internal | 1015 } // namespace internal |
991 } // namespace v8 | 1016 } // namespace v8 |
OLD | NEW |