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

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

Issue 2696143006: [wasm] Refactor code specialization / patching (Closed)
Patch Set: Rebase 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..095a65cbbc158ecb1ee3e241db9000c6ea4f3271
--- /dev/null
+++ b/src/wasm/wasm-code-specialization.h
@@ -0,0 +1,70 @@
+// 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 "src/assembler.h"
+#include "src/identity-map.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:
+ CodeSpecialization(Isolate*, Zone*);
+ ~CodeSpecialization();
+
+ // 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(Handle<WasmInstanceObject> instance);
+ // Relocate an arbitrary object (e.g. function table).
+ void RelocateObject(Handle<Object> old_obj, Handle<Object> new_obj);
+
+ // Apply all relocations and patching to all code in the instance (wasm code
+ // and exported functions).
+ bool ApplyToWholeInstance(WasmInstanceObject*,
+ ICacheFlushMode = FLUSH_ICACHE_IF_NEEDED);
+ // Apply all relocations and patching to one wasm code object.
+ bool ApplyToWasmCode(Code*, ICacheFlushMode = FLUSH_ICACHE_IF_NEEDED);
+
+ private:
+ 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;
+
+ Handle<WasmInstanceObject> relocate_direct_calls_instance;
+
+ bool has_objects_to_relocate = false;
+ IdentityMap<Handle<Object>> objects_to_relocate;
+};
+
+} // 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