OLD | NEW |
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 <setjmp.h> | 8 #include <setjmp.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <stdlib.h> | 10 #include <stdlib.h> |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 instance->globals_start = global_data; | 91 instance->globals_start = global_data; |
92 module_.globals_size = kMaxGlobalsSize; | 92 module_.globals_size = kMaxGlobalsSize; |
93 instance->mem_start = nullptr; | 93 instance->mem_start = nullptr; |
94 instance->mem_size = 0; | 94 instance->mem_size = 0; |
95 memset(global_data, 0, sizeof(global_data)); | 95 memset(global_data, 0, sizeof(global_data)); |
96 instance_object_ = InitInstanceObject(); | 96 instance_object_ = InitInstanceObject(); |
97 } | 97 } |
98 | 98 |
99 ~TestingModule() { | 99 ~TestingModule() { |
100 if (instance->mem_start) { | 100 if (instance->mem_start) { |
101 if (EnableGuardRegions() && module_.origin == kWasmOrigin) { | 101 if (EnableGuardRegions() && module_.is_wasm()) { |
102 // See the corresponding code in AddMemory. We use a different | 102 // See the corresponding code in AddMemory. We use a different |
103 // allocation path when guard regions are enabled, which means we have | 103 // allocation path when guard regions are enabled, which means we have |
104 // to free it differently too. | 104 // to free it differently too. |
105 const size_t alloc_size = | 105 const size_t alloc_size = |
106 RoundUp(kWasmMaxHeapOffset, v8::base::OS::CommitPageSize()); | 106 RoundUp(kWasmMaxHeapOffset, v8::base::OS::CommitPageSize()); |
107 v8::base::OS::Free(instance->mem_start, alloc_size); | 107 v8::base::OS::Free(instance->mem_start, alloc_size); |
108 } else { | 108 } else { |
109 free(instance->mem_start); | 109 free(instance->mem_start); |
110 } | 110 } |
111 } | 111 } |
112 if (interpreter_) delete interpreter_; | 112 if (interpreter_) delete interpreter_; |
113 } | 113 } |
114 | 114 |
115 void ChangeOriginToAsmjs() { module_.origin = kAsmJsOrigin; } | 115 void ChangeOriginToAsmjs() { module_.set_origin(kAsmJsOrigin); } |
116 | 116 |
117 byte* AddMemory(uint32_t size) { | 117 byte* AddMemory(uint32_t size) { |
118 CHECK(!module_.has_memory); | 118 CHECK(!module_.has_memory); |
119 CHECK_NULL(instance->mem_start); | 119 CHECK_NULL(instance->mem_start); |
120 CHECK_EQ(0, instance->mem_size); | 120 CHECK_EQ(0, instance->mem_size); |
121 module_.has_memory = true; | 121 module_.has_memory = true; |
122 if (EnableGuardRegions() && module_.origin == kWasmOrigin) { | 122 if (EnableGuardRegions() && module_.is_wasm()) { |
123 const size_t alloc_size = | 123 const size_t alloc_size = |
124 RoundUp(kWasmMaxHeapOffset, v8::base::OS::CommitPageSize()); | 124 RoundUp(kWasmMaxHeapOffset, v8::base::OS::CommitPageSize()); |
125 instance->mem_start = reinterpret_cast<byte*>( | 125 instance->mem_start = reinterpret_cast<byte*>( |
126 v8::base::OS::AllocateGuarded(alloc_size * 2)); | 126 v8::base::OS::AllocateGuarded(alloc_size * 2)); |
127 instance->mem_start += alloc_size; | 127 instance->mem_start += alloc_size; |
128 const size_t guard_size = RoundUp(size, v8::base::OS::CommitPageSize()); | 128 const size_t guard_size = RoundUp(size, v8::base::OS::CommitPageSize()); |
129 v8::base::OS::Unprotect(instance->mem_start, guard_size); | 129 v8::base::OS::Unprotect(instance->mem_start, guard_size); |
130 } else { | 130 } else { |
131 instance->mem_start = reinterpret_cast<byte*>(malloc(size)); | 131 instance->mem_start = reinterpret_cast<byte*>(malloc(size)); |
132 } | 132 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 DCHECK_LT(index, kMaxFunctions); // limited for testing. | 228 DCHECK_LT(index, kMaxFunctions); // limited for testing. |
229 return index; | 229 return index; |
230 } | 230 } |
231 | 231 |
232 uint32_t AddJsFunction(FunctionSig* sig, const char* source) { | 232 uint32_t AddJsFunction(FunctionSig* sig, const char* source) { |
233 Handle<JSFunction> jsfunc = Handle<JSFunction>::cast(v8::Utils::OpenHandle( | 233 Handle<JSFunction> jsfunc = Handle<JSFunction>::cast(v8::Utils::OpenHandle( |
234 *v8::Local<v8::Function>::Cast(CompileRun(source)))); | 234 *v8::Local<v8::Function>::Cast(CompileRun(source)))); |
235 uint32_t index = AddFunction(sig, Handle<Code>::null(), nullptr); | 235 uint32_t index = AddFunction(sig, Handle<Code>::null(), nullptr); |
236 Handle<Code> code = CompileWasmToJSWrapper( | 236 Handle<Code> code = CompileWasmToJSWrapper( |
237 isolate_, jsfunc, sig, index, Handle<String>::null(), | 237 isolate_, jsfunc, sig, index, Handle<String>::null(), |
238 Handle<String>::null(), module->origin); | 238 Handle<String>::null(), module->get_origin()); |
239 instance->function_code[index] = code; | 239 instance->function_code[index] = code; |
240 return index; | 240 return index; |
241 } | 241 } |
242 | 242 |
243 Handle<JSFunction> WrapCode(uint32_t index) { | 243 Handle<JSFunction> WrapCode(uint32_t index) { |
244 // Wrap the code so it can be called as a JS function. | 244 // Wrap the code so it can be called as a JS function. |
245 Handle<Code> code = instance->function_code[index]; | 245 Handle<Code> code = instance->function_code[index]; |
246 Handle<Code> ret_code = | 246 Handle<Code> ret_code = |
247 compiler::CompileJSToWasmWrapper(isolate_, &module_, code, index); | 247 compiler::CompileJSToWasmWrapper(isolate_, &module_, code, index); |
248 Handle<JSFunction> ret = WasmExportedFunction::New( | 248 Handle<JSFunction> ret = WasmExportedFunction::New( |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 void RunWasm_##name(WasmExecutionMode execution_mode) | 862 void RunWasm_##name(WasmExecutionMode execution_mode) |
863 | 863 |
864 #define WASM_EXEC_COMPILED_TEST(name) \ | 864 #define WASM_EXEC_COMPILED_TEST(name) \ |
865 void RunWasm_##name(WasmExecutionMode execution_mode); \ | 865 void RunWasm_##name(WasmExecutionMode execution_mode); \ |
866 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ | 866 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ |
867 void RunWasm_##name(WasmExecutionMode execution_mode) | 867 void RunWasm_##name(WasmExecutionMode execution_mode) |
868 | 868 |
869 } // namespace | 869 } // namespace |
870 | 870 |
871 #endif | 871 #endif |
OLD | NEW |