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

Side by Side Diff: src/wasm/wasm-module.h

Issue 2771803005: Hide WasmModule.origin field behind readable accessors. (Closed)
Patch Set: Fix merge conflict with master. Created 3 years, 9 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
OLDNEW
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> 8 #include <memory>
9 9
10 #include "src/api.h" 10 #include "src/api.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 Zone* owned_zone; 147 Zone* owned_zone;
148 uint32_t min_mem_pages = 0; // minimum size of the memory in 64k pages 148 uint32_t min_mem_pages = 0; // minimum size of the memory in 64k pages
149 uint32_t max_mem_pages = 0; // maximum size of the memory in 64k pages 149 uint32_t max_mem_pages = 0; // maximum size of the memory in 64k pages
150 bool has_max_mem = false; // try if a maximum memory size exists 150 bool has_max_mem = false; // try if a maximum memory size exists
151 bool has_memory = false; // true if the memory was defined or imported 151 bool has_memory = false; // true if the memory was defined or imported
152 bool mem_export = false; // true if the memory is exported 152 bool mem_export = false; // true if the memory is exported
153 // TODO(wasm): reconcile start function index being an int with 153 // TODO(wasm): reconcile start function index being an int with
154 // the fact that we index on uint32_t, so we may technically not be 154 // the fact that we index on uint32_t, so we may technically not be
155 // able to represent some start_function_index -es. 155 // able to represent some start_function_index -es.
156 int start_function_index = -1; // start function, if any 156 int start_function_index = -1; // start function, if any
157 ModuleOrigin origin = kWasmOrigin; // origin of the module
158 157
159 std::vector<WasmGlobal> globals; // globals in this module. 158 std::vector<WasmGlobal> globals; // globals in this module.
160 uint32_t globals_size = 0; // size of globals table. 159 uint32_t globals_size = 0; // size of globals table.
161 uint32_t num_imported_functions = 0; // number of imported functions. 160 uint32_t num_imported_functions = 0; // number of imported functions.
162 uint32_t num_declared_functions = 0; // number of declared functions. 161 uint32_t num_declared_functions = 0; // number of declared functions.
163 uint32_t num_exported_functions = 0; // number of exported functions. 162 uint32_t num_exported_functions = 0; // number of exported functions.
164 std::vector<FunctionSig*> signatures; // signatures in this module. 163 std::vector<FunctionSig*> signatures; // signatures in this module.
165 std::vector<WasmFunction> functions; // functions in this module. 164 std::vector<WasmFunction> functions; // functions in this module.
166 std::vector<WasmDataSegment> data_segments; // data segments in this module. 165 std::vector<WasmDataSegment> data_segments; // data segments in this module.
167 std::vector<WasmIndirectFunctionTable> function_tables; // function tables. 166 std::vector<WasmIndirectFunctionTable> function_tables; // function tables.
168 std::vector<WasmImport> import_table; // import table. 167 std::vector<WasmImport> import_table; // import table.
169 std::vector<WasmExport> export_table; // export table. 168 std::vector<WasmExport> export_table; // export table.
170 std::vector<WasmTableInit> table_inits; // initializations of tables 169 std::vector<WasmTableInit> table_inits; // initializations of tables
171 // We store the semaphore here to extend its lifetime. In <libc-2.21, which we 170 // We store the semaphore here to extend its lifetime. In <libc-2.21, which we
172 // use on the try bots, semaphore::Wait() can return while some compilation 171 // use on the try bots, semaphore::Wait() can return while some compilation
173 // tasks are still executing semaphore::Signal(). If the semaphore is cleaned 172 // tasks are still executing semaphore::Signal(). If the semaphore is cleaned
174 // up right after semaphore::Wait() returns, then this can cause an 173 // up right after semaphore::Wait() returns, then this can cause an
175 // invalid-semaphore error in the compilation tasks. 174 // invalid-semaphore error in the compilation tasks.
176 // TODO(wasm): Move this semaphore back to CompileInParallel when the try bots 175 // TODO(wasm): Move this semaphore back to CompileInParallel when the try bots
177 // switch to libc-2.21 or higher. 176 // switch to libc-2.21 or higher.
178 std::unique_ptr<base::Semaphore> pending_tasks; 177 std::unique_ptr<base::Semaphore> pending_tasks;
179 178
180 WasmModule() : WasmModule(nullptr) {} 179 WasmModule() : WasmModule(nullptr) {}
181 WasmModule(Zone* owned_zone); 180 WasmModule(Zone* owned_zone);
182 ~WasmModule() { 181 ~WasmModule() {
183 if (owned_zone) delete owned_zone; 182 if (owned_zone) delete owned_zone;
184 } 183 }
184
185 ModuleOrigin get_origin() const { return origin; }
186 void set_origin(ModuleOrigin new_value) { origin = new_value; }
187 bool is_wasm() const { return origin == kWasmOrigin; }
188 bool is_asm_js() const { return origin == kAsmJsOrigin; }
189
190 private:
191 // TODO(kschimpf) - Encapsulate more fields.
192 ModuleOrigin origin = kWasmOrigin; // origin of the module
Mircea Trofin 2017/03/24 22:25:14 the naming style in V8 for fields would be "origin
Karl 2017/03/24 22:41:40 I'm a bit nervous about changing the field name fr
185 }; 193 };
186 194
187 typedef Managed<WasmModule> WasmModuleWrapper; 195 typedef Managed<WasmModule> WasmModuleWrapper;
188 196
189 // An instantiated WASM module, including memory, function table, etc. 197 // An instantiated WASM module, including memory, function table, etc.
190 struct WasmInstance { 198 struct WasmInstance {
191 const WasmModule* module; // static representation of the module. 199 const WasmModule* module; // static representation of the module.
192 // -- Heap allocated -------------------------------------------------------- 200 // -- Heap allocated --------------------------------------------------------
193 Handle<Context> context; // JavaScript native context. 201 Handle<Context> context; // JavaScript native context.
194 std::vector<Handle<FixedArray>> function_tables; // indirect function tables. 202 std::vector<Handle<FixedArray>> function_tables; // indirect function tables.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 } 319 }
312 FunctionSig* GetSignature(uint32_t index) { 320 FunctionSig* GetSignature(uint32_t index) {
313 DCHECK(IsValidSignature(index)); 321 DCHECK(IsValidSignature(index));
314 return module->signatures[index]; 322 return module->signatures[index];
315 } 323 }
316 const WasmIndirectFunctionTable* GetTable(uint32_t index) const { 324 const WasmIndirectFunctionTable* GetTable(uint32_t index) const {
317 DCHECK(IsValidTable(index)); 325 DCHECK(IsValidTable(index));
318 return &module->function_tables[index]; 326 return &module->function_tables[index];
319 } 327 }
320 328
321 bool asm_js() { return module->origin == kAsmJsOrigin; } 329 bool asm_js() { return module->is_asm_js(); }
322 330
323 // Only used for testing. 331 // Only used for testing.
324 Handle<Code> GetFunctionCode(uint32_t index) { 332 Handle<Code> GetFunctionCode(uint32_t index) {
325 DCHECK_NOT_NULL(instance); 333 DCHECK_NOT_NULL(instance);
326 return instance->function_code[index]; 334 return instance->function_code[index];
327 } 335 }
328 336
329 // TODO(titzer): move these into src/compiler/wasm-compiler.cc 337 // TODO(titzer): move these into src/compiler/wasm-compiler.cc
330 static compiler::CallDescriptor* GetWasmCallDescriptor(Zone* zone, 338 static compiler::CallDescriptor* GetWasmCallDescriptor(Zone* zone,
331 FunctionSig* sig); 339 FunctionSig* sig);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 int instance_count); 512 int instance_count);
505 void ValidateModuleState(Isolate* isolate, Handle<WasmModuleObject> module_obj); 513 void ValidateModuleState(Isolate* isolate, Handle<WasmModuleObject> module_obj);
506 void ValidateOrphanedInstance(Isolate* isolate, 514 void ValidateOrphanedInstance(Isolate* isolate,
507 Handle<WasmInstanceObject> instance); 515 Handle<WasmInstanceObject> instance);
508 } // namespace testing 516 } // namespace testing
509 } // namespace wasm 517 } // namespace wasm
510 } // namespace internal 518 } // namespace internal
511 } // namespace v8 519 } // namespace v8
512 520
513 #endif // V8_WASM_MODULE_H_ 521 #endif // V8_WASM_MODULE_H_
OLDNEW
« no previous file with comments | « src/wasm/module-decoder.cc ('k') | src/wasm/wasm-module.cc » ('j') | src/wasm/wasm-objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698