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 #ifndef V8_WASM_MODULE_H_ | 5 #ifndef V8_WASM_MODULE_H_ |
6 #define V8_WASM_MODULE_H_ | 6 #define V8_WASM_MODULE_H_ |
7 | 7 |
| 8 #include <memory> |
| 9 |
8 #include "src/api.h" | 10 #include "src/api.h" |
9 #include "src/handles.h" | 11 #include "src/handles.h" |
10 #include "src/wasm/wasm-opcodes.h" | 12 #include "src/wasm/wasm-opcodes.h" |
11 #include "src/wasm/wasm-result.h" | 13 #include "src/wasm/wasm-result.h" |
12 | 14 |
13 namespace v8 { | 15 namespace v8 { |
14 namespace internal { | 16 namespace internal { |
15 | 17 |
16 namespace compiler { | 18 namespace compiler { |
17 class CallDescriptor; | 19 class CallDescriptor; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 std::vector<uint16_t> function_table; // function table. | 183 std::vector<uint16_t> function_table; // function table. |
182 std::vector<WasmImport> import_table; // import table. | 184 std::vector<WasmImport> import_table; // import table. |
183 std::vector<WasmExport> export_table; // export table. | 185 std::vector<WasmExport> export_table; // export table. |
184 // We store the semaphore here to extend its lifetime. In <libc-2.21, which we | 186 // We store the semaphore here to extend its lifetime. In <libc-2.21, which we |
185 // use on the try bots, semaphore::Wait() can return while some compilation | 187 // use on the try bots, semaphore::Wait() can return while some compilation |
186 // tasks are still executing semaphore::Signal(). If the semaphore is cleaned | 188 // tasks are still executing semaphore::Signal(). If the semaphore is cleaned |
187 // up right after semaphore::Wait() returns, then this can cause an | 189 // up right after semaphore::Wait() returns, then this can cause an |
188 // invalid-semaphore error in the compilation tasks. | 190 // invalid-semaphore error in the compilation tasks. |
189 // TODO(wasm): Move this semaphore back to CompileInParallel when the try bots | 191 // TODO(wasm): Move this semaphore back to CompileInParallel when the try bots |
190 // switch to libc-2.21 or higher. | 192 // switch to libc-2.21 or higher. |
191 base::SmartPointer<base::Semaphore> pending_tasks; | 193 std::unique_ptr<base::Semaphore> pending_tasks; |
192 | 194 |
193 WasmModule() : WasmModule(nullptr) {} | 195 WasmModule() : WasmModule(nullptr) {} |
194 explicit WasmModule(byte* module_start); | 196 explicit WasmModule(byte* module_start); |
195 | 197 |
196 // Get a string stored in the module bytes representing a name. | 198 // Get a string stored in the module bytes representing a name. |
197 WasmName GetName(uint32_t offset, uint32_t length) const { | 199 WasmName GetName(uint32_t offset, uint32_t length) const { |
198 if (length == 0) return {"<?>", 3}; // no name. | 200 if (length == 0) return {"<?>", 3}; // no name. |
199 CHECK(BoundsCheck(offset, offset + length)); | 201 CHECK(BoundsCheck(offset, offset + length)); |
200 DCHECK_GE(static_cast<int>(length), 0); | 202 DCHECK_GE(static_cast<int>(length), 0); |
201 return {reinterpret_cast<const char*>(module_start + offset), | 203 return {reinterpret_cast<const char*>(module_start + offset), |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 MaybeHandle<FixedArray> CompileFunctions(Isolate* isolate, | 238 MaybeHandle<FixedArray> CompileFunctions(Isolate* isolate, |
237 ErrorThrower* thrower) const; | 239 ErrorThrower* thrower) const; |
238 | 240 |
239 uint32_t FunctionTableSize() const { | 241 uint32_t FunctionTableSize() const { |
240 if (indirect_table_size > 0) { | 242 if (indirect_table_size > 0) { |
241 return indirect_table_size; | 243 return indirect_table_size; |
242 } | 244 } |
243 DCHECK_LE(function_table.size(), UINT32_MAX); | 245 DCHECK_LE(function_table.size(), UINT32_MAX); |
244 return static_cast<uint32_t>(function_table.size()); | 246 return static_cast<uint32_t>(function_table.size()); |
245 } | 247 } |
| 248 |
| 249 private: |
| 250 DISALLOW_COPY_AND_ASSIGN(WasmModule); |
246 }; | 251 }; |
247 | 252 |
248 // An instantiated WASM module, including memory, function table, etc. | 253 // An instantiated WASM module, including memory, function table, etc. |
249 struct WasmModuleInstance { | 254 struct WasmModuleInstance { |
250 const WasmModule* module; // static representation of the module. | 255 const WasmModule* module; // static representation of the module. |
251 // -- Heap allocated -------------------------------------------------------- | 256 // -- Heap allocated -------------------------------------------------------- |
252 Handle<JSObject> js_object; // JavaScript module object. | 257 Handle<JSObject> js_object; // JavaScript module object. |
253 Handle<Context> context; // JavaScript native context. | 258 Handle<Context> context; // JavaScript native context. |
254 Handle<JSArrayBuffer> mem_buffer; // Handle to array buffer of memory. | 259 Handle<JSArrayBuffer> mem_buffer; // Handle to array buffer of memory. |
255 Handle<JSArrayBuffer> globals_buffer; // Handle to array buffer of globals. | 260 Handle<JSArrayBuffer> globals_buffer; // Handle to array buffer of globals. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 // given encoded module. The module should have no imports. | 393 // given encoded module. The module should have no imports. |
389 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, | 394 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, |
390 const byte* module_end, bool asm_js = false); | 395 const byte* module_end, bool asm_js = false); |
391 | 396 |
392 } // namespace testing | 397 } // namespace testing |
393 } // namespace wasm | 398 } // namespace wasm |
394 } // namespace internal | 399 } // namespace internal |
395 } // namespace v8 | 400 } // namespace v8 |
396 | 401 |
397 #endif // V8_WASM_MODULE_H_ | 402 #endif // V8_WASM_MODULE_H_ |
OLD | NEW |