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

Unified Diff: src/wasm/wasm-code-specialization.h

Issue 2696143006: [wasm] Refactor code specialization / patching (Closed)
Patch Set: Remove unused variables and add documentation Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/v8.gyp ('k') | src/wasm/wasm-code-specialization.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/wasm-code-specialization.h
diff --git a/src/wasm/wasm-code-specialization.h b/src/wasm/wasm-code-specialization.h
new file mode 100644
index 0000000000000000000000000000000000000000..716404d6b0dff3202f4b11a9d5aedbc3b1e3ed00
--- /dev/null
+++ b/src/wasm/wasm-code-specialization.h
@@ -0,0 +1,69 @@
+// Copyright 2017 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef V8_WASM_CODE_SPECIALIZATION_H_
+#define V8_WASM_CODE_SPECIALIZATION_H_
+
+#include <unordered_map>
+
+#include "src/assembler.h"
+#include "src/wasm/wasm-objects.h"
+
+namespace v8 {
+namespace internal {
+namespace wasm {
+
+// Helper class to specialize wasm code for a specific instance, or to update
+// code when memory / globals / tables change.
+// This class in unhandlified, and contains a DisallowHeapAllocation field to
+// ensure that no allocations happen while it is alive.
+//
+// Set up all relocations / patching that should be performed by the Relocate* /
+// Patch* methods, then apply all changes in one step using the Apply* methods.
+class CodeSpecialization {
+ public:
+ // Update memory references.
+ void RelocateMemoryReferences(Address old_start, uint32_t old_size,
+ Address new_start, uint32_t new_size);
+ // Update references to global variables.
+ void RelocateGlobals(Address old_start, Address new_start);
+ // Update function table size.
+ // TODO(wasm): Prepare this for more than one indirect function table.
+ void PatchTableSize(uint32_t old_size, uint32_t new_size);
+ // Update all direct call sites based on the code table in the given instance.
+ void RelocateDirectCalls(WasmInstanceObject* instance);
+ // Relocate an arbitrary object (e.g. function table).
+ void RelocateObject(Object* old_obj, Object* new_obj);
+
+ // Apply all relocations and patching to all code in the instance (wasm code
+ // and exported functions).
+ bool ApplyToWholeInstance(WasmInstanceObject* instance,
+ ICacheFlushMode = FLUSH_ICACHE_IF_NEEDED);
+ // Apply all relocations and patching to one wasm code object.
+ bool ApplyToWasmCode(Code* code, ICacheFlushMode = FLUSH_ICACHE_IF_NEEDED);
+
+ private:
+ DisallowHeapAllocation no_gc_during_specialization;
+
+ Address old_mem_start = 0;
+ uint32_t old_mem_size = 0;
+ Address new_mem_start = 0;
+ uint32_t new_mem_size = 0;
+
+ Address old_globals_start = 0;
+ Address new_globals_start = 0;
+
+ uint32_t old_function_table_size = 0;
+ uint32_t new_function_table_size = 0;
+
+ WasmInstanceObject* relocate_direct_calls_instance = nullptr;
+
+ 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.
+};
+
+} // namespace wasm
+} // namespace internal
+} // namespace v8
+
+#endif // V8_WASM_CODE_SPECIALIZATION_H_
« no previous file with comments | « src/v8.gyp ('k') | src/wasm/wasm-code-specialization.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698