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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 function_code()[index] = code; | 133 function_code()[index] = code; |
134 } | 134 } |
135 | 135 |
136 void Link(Handle<FixedArray> function_table, | 136 void Link(Handle<FixedArray> function_table, |
137 const std::vector<uint16_t>& functions) { | 137 const std::vector<uint16_t>& functions) { |
138 for (size_t i = 0; i < function_code().size(); i++) { | 138 for (size_t i = 0; i < function_code().size(); i++) { |
139 LinkFunction(function_code()[i]); | 139 LinkFunction(function_code()[i]); |
140 } | 140 } |
141 if (!function_table.is_null()) { | 141 if (!function_table.is_null()) { |
142 int table_size = static_cast<int>(functions.size()); | 142 int table_size = static_cast<int>(functions.size()); |
143 DCHECK_EQ(function_table->length(), table_size * 2); | 143 int indirect_table_size; |
144 if (FLAG_wasm_jit_prototype) { | |
145 indirect_table_size = 4 * table_size < kMinimumIndirectTableSize | |
bradn
2016/06/16 08:00:20
I'd thought we'd talked about adding a field to on
| |
146 ? kMinimumIndirectTableSize | |
147 : 4 * table_size; | |
148 DCHECK_EQ(function_table->length(), indirect_table_size); | |
149 } else { | |
150 indirect_table_size = 2 * table_size; | |
151 DCHECK_EQ(function_table->length(), indirect_table_size); | |
152 } | |
144 for (int i = 0; i < table_size; i++) { | 153 for (int i = 0; i < table_size; i++) { |
145 function_table->set(i + table_size, *function_code()[functions[i]]); | 154 function_table->set(i + indirect_table_size / 2, |
155 *function_code()[functions[i]]); | |
146 } | 156 } |
147 } | 157 } |
148 } | 158 } |
149 | 159 |
150 private: | 160 private: |
151 std::vector<Handle<Code>>& function_code() { return *function_code_; } | 161 std::vector<Handle<Code>>& function_code() { return *function_code_; } |
152 | 162 |
153 void CreatePlaceholder(uint32_t index) { | 163 void CreatePlaceholder(uint32_t index) { |
154 DCHECK(index < function_code().size()); | 164 DCHECK(index < function_code().size()); |
155 DCHECK(function_code()[index].is_null()); | 165 DCHECK(function_code()[index].is_null()); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 segment.source_size); | 235 segment.source_size); |
226 } | 236 } |
227 } | 237 } |
228 | 238 |
229 Handle<FixedArray> BuildFunctionTable(Isolate* isolate, | 239 Handle<FixedArray> BuildFunctionTable(Isolate* isolate, |
230 const WasmModule* module) { | 240 const WasmModule* module) { |
231 if (module->function_table.size() == 0) { | 241 if (module->function_table.size() == 0) { |
232 return Handle<FixedArray>::null(); | 242 return Handle<FixedArray>::null(); |
233 } | 243 } |
234 int table_size = static_cast<int>(module->function_table.size()); | 244 int table_size = static_cast<int>(module->function_table.size()); |
235 Handle<FixedArray> fixed = isolate->factory()->NewFixedArray(2 * table_size); | 245 int indirect_table_size; |
246 if (FLAG_wasm_jit_prototype) | |
247 indirect_table_size = 4 * table_size < kMinimumIndirectTableSize | |
bradn
2016/06/16 08:00:20
Definitely don't want to repeat this calculation a
| |
248 ? kMinimumIndirectTableSize | |
249 : 4 * table_size; | |
250 else | |
251 indirect_table_size = 2 * table_size; | |
252 | |
253 Handle<FixedArray> fixed = | |
254 isolate->factory()->NewFixedArray(indirect_table_size); | |
236 for (int i = 0; i < table_size; i++) { | 255 for (int i = 0; i < table_size; i++) { |
237 const WasmFunction* function = | 256 const WasmFunction* function = |
238 &module->functions[module->function_table[i]]; | 257 &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) { |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
728 } | 747 } |
729 if (!instance.globals_buffer.is_null()) { | 748 if (!instance.globals_buffer.is_null()) { |
730 instance.js_object->SetInternalField(kWasmGlobalsArrayBuffer, | 749 instance.js_object->SetInternalField(kWasmGlobalsArrayBuffer, |
731 *instance.globals_buffer); | 750 *instance.globals_buffer); |
732 } | 751 } |
733 | 752 |
734 HistogramTimerScope wasm_compile_module_time_scope( | 753 HistogramTimerScope wasm_compile_module_time_scope( |
735 isolate->counters()->wasm_compile_module_time()); | 754 isolate->counters()->wasm_compile_module_time()); |
736 | 755 |
737 instance.function_table = BuildFunctionTable(isolate, this); | 756 instance.function_table = BuildFunctionTable(isolate, this); |
757 instance.padded_entries = | |
758 static_cast<int>(instance.function_table->length() / 2) - | |
759 static_cast<int>(instance.module->function_table.size()); | |
738 WasmLinker linker(isolate, &instance.function_code); | 760 WasmLinker linker(isolate, &instance.function_code); |
739 ModuleEnv module_env; | 761 ModuleEnv module_env; |
740 module_env.module = this; | 762 module_env.module = this; |
741 module_env.instance = &instance; | 763 module_env.instance = &instance; |
742 module_env.linker = &linker; | 764 module_env.linker = &linker; |
743 module_env.origin = origin; | 765 module_env.origin = origin; |
744 | 766 |
745 //------------------------------------------------------------------------- | 767 //------------------------------------------------------------------------- |
746 // Compile wrappers to imported functions. | 768 // Compile wrappers to imported functions. |
747 //------------------------------------------------------------------------- | 769 //------------------------------------------------------------------------- |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
922 } | 944 } |
923 LoadDataSegments(module, instance.mem_start, instance.mem_size); | 945 LoadDataSegments(module, instance.mem_start, instance.mem_size); |
924 | 946 |
925 // Allocate the globals area if necessary. | 947 // Allocate the globals area if necessary. |
926 if (!AllocateGlobals(&thrower, isolate, &instance)) { | 948 if (!AllocateGlobals(&thrower, isolate, &instance)) { |
927 return -1; | 949 return -1; |
928 } | 950 } |
929 | 951 |
930 // Build the function table. | 952 // Build the function table. |
931 instance.function_table = BuildFunctionTable(isolate, module); | 953 instance.function_table = BuildFunctionTable(isolate, module); |
954 instance.padded_entries = | |
955 static_cast<int>(instance.function_table->length() / 2) - | |
956 static_cast<int>(module->function_table.size()); | |
932 | 957 |
933 // Create module environment. | 958 // Create module environment. |
934 WasmLinker linker(isolate, &instance.function_code); | 959 WasmLinker linker(isolate, &instance.function_code); |
935 ModuleEnv module_env; | 960 ModuleEnv module_env; |
936 module_env.module = module; | 961 module_env.module = module; |
937 module_env.instance = &instance; | 962 module_env.instance = &instance; |
938 module_env.linker = &linker; | 963 module_env.linker = &linker; |
939 module_env.origin = module->origin; | 964 module_env.origin = module->origin; |
940 | 965 |
941 if (module->export_table.size() == 0) { | 966 if (module->export_table.size() == 0) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
999 object->GetInternalField(kWasmModuleCodeTable)->IsFixedArray() && | 1024 object->GetInternalField(kWasmModuleCodeTable)->IsFixedArray() && |
1000 object->GetInternalField(kWasmMemArrayBuffer)->IsJSArrayBuffer() && | 1025 object->GetInternalField(kWasmMemArrayBuffer)->IsJSArrayBuffer() && |
1001 (object->GetInternalField(kWasmFunctionNamesArray)->IsByteArray() || | 1026 (object->GetInternalField(kWasmFunctionNamesArray)->IsByteArray() || |
1002 object->GetInternalField(kWasmFunctionNamesArray) | 1027 object->GetInternalField(kWasmFunctionNamesArray) |
1003 ->IsUndefined(object->GetIsolate())); | 1028 ->IsUndefined(object->GetIsolate())); |
1004 } | 1029 } |
1005 | 1030 |
1006 } // namespace wasm | 1031 } // namespace wasm |
1007 } // namespace internal | 1032 } // namespace internal |
1008 } // namespace v8 | 1033 } // namespace v8 |
OLD | NEW |