Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef V8_WASM_CODE_SPECIALIZATION_H_ | |
| 6 #define V8_WASM_CODE_SPECIALIZATION_H_ | |
| 7 | |
| 8 #include <unordered_map> | |
| 9 | |
| 10 #include "src/assembler.h" | |
| 11 #include "src/wasm/wasm-objects.h" | |
| 12 | |
| 13 namespace v8 { | |
| 14 namespace internal { | |
| 15 namespace wasm { | |
| 16 | |
| 17 // Helper class to specialize wasm code for a specific instance, or to update | |
| 18 // code when memory / globals / tables change. | |
| 19 // This class in unhandlified, and contains a DisallowHeapAllocation field to | |
| 20 // ensure that no allocations happen while it is alive. | |
| 21 // | |
| 22 // Set up all relocations / patching that should be performed by the Relocate* / | |
| 23 // Patch* methods, then apply all changes in one step using the Apply* methods. | |
| 24 class CodeSpecialization { | |
| 25 public: | |
| 26 // Update memory references. | |
| 27 void RelocateMemoryReferences(Address old_start, uint32_t old_size, | |
| 28 Address new_start, uint32_t new_size); | |
| 29 // Update references to global variables. | |
| 30 void RelocateGlobals(Address old_start, Address new_start); | |
| 31 // Update function table size. | |
| 32 // TODO(wasm): Prepare this for more than one indirect function table. | |
| 33 void PatchTableSize(uint32_t old_size, uint32_t new_size); | |
| 34 // Update all direct call sites based on the code table in the given instance. | |
| 35 void RelocateDirectCalls(WasmInstanceObject* instance); | |
| 36 // Relocate an arbitrary object (e.g. function table). | |
| 37 void RelocateObject(Object* old_obj, Object* new_obj); | |
| 38 | |
| 39 // Apply all relocations and patching to all code in the instance (wasm code | |
| 40 // and exported functions). | |
| 41 bool ApplyToWholeInstance(WasmInstanceObject* instance, | |
| 42 ICacheFlushMode = FLUSH_ICACHE_IF_NEEDED); | |
| 43 // Apply all relocations and patching to one wasm code object. | |
| 44 bool ApplyToWasmCode(Code* code, ICacheFlushMode = FLUSH_ICACHE_IF_NEEDED); | |
| 45 | |
| 46 private: | |
| 47 DisallowHeapAllocation no_gc_during_specialization; | |
| 48 | |
| 49 Address old_mem_start = 0; | |
| 50 uint32_t old_mem_size = 0; | |
| 51 Address new_mem_start = 0; | |
| 52 uint32_t new_mem_size = 0; | |
| 53 | |
| 54 Address old_globals_start = 0; | |
| 55 Address new_globals_start = 0; | |
| 56 | |
| 57 uint32_t old_function_table_size = 0; | |
| 58 uint32_t new_function_table_size = 0; | |
| 59 | |
| 60 WasmInstanceObject* relocate_direct_calls_instance = nullptr; | |
| 61 | |
| 62 std::unordered_map<Object*, Object*> objects_to_relocate; | |
|
titzer
2017/02/17 13:38:16
I think we can replace this with an IdentityMap, w
Clemens Hammacher
2017/02/20 11:05:57
Also note that I am already using a hash map here.
| |
| 63 }; | |
| 64 | |
| 65 } // namespace wasm | |
| 66 } // namespace internal | |
| 67 } // namespace v8 | |
| 68 | |
| 69 #endif // V8_WASM_CODE_SPECIALIZATION_H_ | |
| OLD | NEW |