Commit a690aa29 authored by clemensh's avatar clemensh Committed by Commit bot

[wasm] Refactor code specialization / patching

All patching logic is now bundled in one compilation unit.
The CodeSpecialization object is set up by all relocation and patching
that should be applied, and then be run on individual code objects or
the whole instance in one go. We hence only need to iterate all
relocation tables exactly once at instantiation.
Also, we do not patch contexts any more since we do not embed them in
generated code any more.

R=titzer@chromium.org
BUG=v8:5991

Review-Url: https://codereview.chromium.org/2696143006
Cr-Commit-Position: refs/heads/master@{#43324}
parent 67462272
......@@ -1808,6 +1808,8 @@ v8_source_set("v8_base") {
"src/wasm/module-decoder.h",
"src/wasm/signature-map.cc",
"src/wasm/signature-map.h",
"src/wasm/wasm-code-specialization.cc",
"src/wasm/wasm-code-specialization.h",
"src/wasm/wasm-debug.cc",
"src/wasm/wasm-external-refs.cc",
"src/wasm/wasm-external-refs.h",
......
......@@ -1315,6 +1315,8 @@
'wasm/module-decoder.h',
'wasm/signature-map.cc',
'wasm/signature-map.h',
'wasm/wasm-code-specialization.h',
'wasm/wasm-code-specialization.cc',
'wasm/wasm-debug.cc',
'wasm/wasm-external-refs.cc',
'wasm/wasm-external-refs.h',
......
This diff is collapsed.
// 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_
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment