Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: test/cctest/wasm/wasm-run-utils.h

Issue 2134593002: [wasm] cloning compiled module before instantiation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: [wasm] cloning compiled module before instantiation Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 #ifndef WASM_RUN_UTILS_H 5 #ifndef WASM_RUN_UTILS_H
6 #define WASM_RUN_UTILS_H 6 #define WASM_RUN_UTILS_H
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 instance->function_code[index] = code; 200 instance->function_code[index] = code;
201 return index; 201 return index;
202 } 202 }
203 203
204 Handle<JSFunction> WrapCode(uint32_t index) { 204 Handle<JSFunction> WrapCode(uint32_t index) {
205 // Wrap the code so it can be called as a JS function. 205 // Wrap the code so it can be called as a JS function.
206 Handle<String> name = isolate_->factory()->NewStringFromStaticChars("main"); 206 Handle<String> name = isolate_->factory()->NewStringFromStaticChars("main");
207 Handle<JSObject> module_object = Handle<JSObject>(0, isolate_); 207 Handle<JSObject> module_object = Handle<JSObject>(0, isolate_);
208 Handle<Code> code = instance->function_code[index]; 208 Handle<Code> code = instance->function_code[index];
209 WasmJs::InstallWasmFunctionMap(isolate_, isolate_->native_context()); 209 WasmJs::InstallWasmFunctionMap(isolate_, isolate_->native_context());
210 Handle<JSFunction> ret = 210 Handle<Code> ret_code =
211 compiler::CompileJSToWasmWrapper(isolate_, this, name, code, index); 211 compiler::CompileJSToWasmWrapper(isolate_, this, code, index);
212 ret->SetInternalField(0, *module_object); 212 Handle<JSFunction> ret = WrapExportCodeAsJSFunction(
213 isolate_, ret_code, name,
214 static_cast<int>(this->module->functions[index].sig->parameter_count()),
215 module_object);
213 return ret; 216 return ret;
214 } 217 }
215 218
216 void SetFunctionCode(uint32_t index, Handle<Code> code) { 219 void SetFunctionCode(uint32_t index, Handle<Code> code) {
217 instance->function_code[index] = code; 220 instance->function_code[index] = code;
218 } 221 }
219 222
220 void AddIndirectFunctionTable(int* functions, int table_size) { 223 void AddIndirectFunctionTable(int* functions, int table_size) {
221 Handle<FixedArray> fixed = 224 Handle<FixedArray> fixed =
222 isolate_->factory()->NewFixedArray(2 * table_size); 225 isolate_->factory()->NewFixedArray(2 * table_size);
223 instance->function_table = fixed; 226 instance->function_table = fixed;
224 DCHECK_EQ(0u, module->function_table.size()); 227 DCHECK_EQ(0u, module->function_table.size());
225 for (int i = 0; i < table_size; i++) { 228 for (int i = 0; i < table_size; i++) {
226 module_.function_table.push_back(functions[i]); 229 module_.function_table.push_back(functions[i]);
227 } 230 }
228 } 231 }
229 232
230 void PopulateIndirectFunctionTable() { 233 void PopulateIndirectFunctionTable() {
231 if (instance->function_table.is_null()) return; 234 if (instance->function_table.is_null()) return;
232 int table_size = static_cast<int>(module->function_table.size()); 235 int table_size = static_cast<int>(module->function_table.size());
233 for (int i = 0; i < table_size; i++) { 236 for (int i = 0; i < table_size; i++) {
234 int function_index = module->function_table[i]; 237 int function_index = module->function_table[i];
235 const WasmFunction* function = &module->functions[function_index]; 238 const WasmFunction* function = &module->functions[function_index];
236 instance->function_table->set(i, Smi::FromInt(function->sig_index)); 239 instance->function_table->set(i, Smi::FromInt(function->sig_index));
237 instance->function_table->set(i + table_size, 240 instance->function_table->set(i + table_size,
238 *instance->function_code[function_index]); 241 *instance->function_code[function_index]);
239 } 242 }
240 } 243 }
244
241 WasmFunction* GetFunctionAt(int index) { return &module_.functions[index]; } 245 WasmFunction* GetFunctionAt(int index) { return &module_.functions[index]; }
242 246
243 WasmInterpreter* interpreter() { return interpreter_; } 247 WasmInterpreter* interpreter() { return interpreter_; }
244 WasmExecutionMode execution_mode() { return execution_mode_; } 248 WasmExecutionMode execution_mode() { return execution_mode_; }
245 249
246 private: 250 private:
247 WasmExecutionMode execution_mode_; 251 WasmExecutionMode execution_mode_;
248 WasmModule module_; 252 WasmModule module_;
249 WasmModuleInstance instance_; 253 WasmModuleInstance instance_;
250 Isolate* isolate_; 254 Isolate* isolate_;
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 // interpreter. 767 // interpreter.
764 #define WASM_EXEC_TEST(name) \ 768 #define WASM_EXEC_TEST(name) \
765 void RunWasm_##name(WasmExecutionMode execution_mode); \ 769 void RunWasm_##name(WasmExecutionMode execution_mode); \
766 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ 770 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \
767 TEST(RunWasmInterpreted_##name) { RunWasm_##name(kExecuteInterpreted); } \ 771 TEST(RunWasmInterpreted_##name) { RunWasm_##name(kExecuteInterpreted); } \
768 void RunWasm_##name(WasmExecutionMode execution_mode) 772 void RunWasm_##name(WasmExecutionMode execution_mode)
769 773
770 } // namespace 774 } // namespace
771 775
772 #endif 776 #endif
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698