Commit 23a650ed authored by zhengxing.li's avatar zhengxing.li Committed by Commit bot

X87: Add new relocation type WASM_MEMORY_SIZE_REFERENCE, use relocatable...

X87: Add new relocation type WASM_MEMORY_SIZE_REFERENCE, use relocatable pointers to update wasm memory size references in generated code.

  port 117a56b7 (r36044)

  original commit message:
  - Add new RelocInfo mode WASM_MEMORY_SIZE_REFERENCE in the assembler and add relocation information to immediates in compare instructions.
  - Use relocatable constants for MemSize/BoundsCheck in the wasm compiler

BUG=

Review-Url: https://codereview.chromium.org/1947413003
Cr-Commit-Position: refs/heads/master@{#36058}
parent f68562ee
......@@ -60,7 +60,8 @@ class X87OperandConverter : public InstructionOperandConverter {
Immediate ToImmediate(InstructionOperand* operand) {
Constant constant = ToConstant(operand);
if (constant.type() == Constant::kInt32 &&
constant.rmode() == RelocInfo::WASM_MEMORY_REFERENCE) {
(constant.rmode() == RelocInfo::WASM_MEMORY_REFERENCE ||
constant.rmode() == RelocInfo::WASM_MEMORY_SIZE_REFERENCE)) {
return Immediate(reinterpret_cast<Address>(constant.ToInt32()),
constant.rmode());
}
......
......@@ -81,11 +81,6 @@ Address RelocInfo::target_address() {
return Assembler::target_address_at(pc_, host_);
}
Address RelocInfo::wasm_memory_reference() {
DCHECK(IsWasmMemoryReference(rmode_));
return Memory::Address_at(pc_);
}
Address RelocInfo::target_address_address() {
DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)
|| rmode_ == EMBEDDED_OBJECT
......@@ -120,21 +115,6 @@ void RelocInfo::set_target_address(Address target,
}
}
void RelocInfo::update_wasm_memory_reference(
Address old_base, Address new_base, size_t old_size, size_t new_size,
ICacheFlushMode icache_flush_mode) {
DCHECK(IsWasmMemoryReference(rmode_));
DCHECK(old_base <= wasm_memory_reference() &&
wasm_memory_reference() < old_base + old_size);
Address updated_reference = new_base + (wasm_memory_reference() - old_base);
DCHECK(new_base <= updated_reference &&
updated_reference < new_base + new_size);
Memory::Address_at(pc_) = updated_reference;
if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
Assembler::FlushICache(isolate_, pc_, sizeof(int32_t));
}
}
Object* RelocInfo::target_object() {
DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
return Memory::Object_at(pc_);
......
......@@ -101,6 +101,42 @@ bool RelocInfo::IsInConstantPool() {
return false;
}
Address RelocInfo::wasm_memory_reference() {
DCHECK(IsWasmMemoryReference(rmode_));
return Memory::Address_at(pc_);
}
uint32_t RelocInfo::wasm_memory_size_reference() {
DCHECK(IsWasmMemorySizeReference(rmode_));
return Memory::uint32_at(pc_);
}
void RelocInfo::update_wasm_memory_reference(
Address old_base, Address new_base, uint32_t old_size, uint32_t new_size,
ICacheFlushMode icache_flush_mode) {
DCHECK(IsWasmMemoryReference(rmode_) || IsWasmMemorySizeReference(rmode_));
if (IsWasmMemoryReference(rmode_)) {
Address updated_reference;
DCHECK(old_base <= wasm_memory_reference() &&
wasm_memory_reference() < old_base + old_size);
updated_reference = new_base + (wasm_memory_reference() - old_base);
DCHECK(new_base <= updated_reference &&
updated_reference < new_base + new_size);
Memory::Address_at(pc_) = updated_reference;
} else if (IsWasmMemorySizeReference(rmode_)) {
uint32_t updated_size_reference;
DCHECK(wasm_memory_size_reference() <= old_size);
updated_size_reference =
new_size + (wasm_memory_size_reference() - old_size);
DCHECK(updated_size_reference <= new_size);
Memory::uint32_at(pc_) = updated_size_reference;
} else {
UNREACHABLE();
}
if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
Assembler::FlushICache(isolate_, pc_, sizeof(int32_t));
}
}
// -----------------------------------------------------------------------------
// Implementation of Operand
......
......@@ -23,8 +23,7 @@ using namespace v8::internal::compiler;
static int32_t DummyStaticFunction(Object* result) { return 1; }
TEST(WasmRelocationIa32) {
CcTest::InitializeVM();
TEST(WasmRelocationX87MemoryReference) {
Isolate* isolate = CcTest::i_isolate();
Zone zone(isolate->allocator());
HandleScope scope(isolate);
......@@ -78,7 +77,6 @@ TEST(WasmRelocationIa32) {
CHECK_EQ(ret_value, imm + offset);
#ifdef OBJECT_PRINT
// OFStream os(stdout);
code->Print(os);
begin = code->instruction_start();
end = begin + code->instruction_size();
......@@ -86,4 +84,67 @@ TEST(WasmRelocationIa32) {
#endif
}
TEST(WasmRelocationX87MemorySizeReference) {
CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate();
Zone zone(isolate->allocator());
HandleScope scope(isolate);
v8::internal::byte buffer[4096];
Assembler assm(isolate, buffer, sizeof buffer);
DummyStaticFunction(NULL);
int32_t size = 80;
Label fail;
__ mov(eax, Immediate(reinterpret_cast<Address>(size),
RelocInfo::WASM_MEMORY_SIZE_REFERENCE));
__ cmp(eax, Immediate(reinterpret_cast<Address>(size),
RelocInfo::WASM_MEMORY_SIZE_REFERENCE));
__ j(not_equal, &fail);
__ ret(0);
__ bind(&fail);
__ mov(eax, 0xdeadbeef);
__ ret(0);
CSignature0<int32_t> csig;
CodeDesc desc;
assm.GetCode(&desc);
Handle<Code> code = isolate->factory()->NewCode(
desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
USE(code);
CodeRunner<int32_t> runnable(isolate, code, &csig);
int32_t ret_value = runnable.Call();
CHECK_NE(ret_value, 0xdeadbeef);
#ifdef OBJECT_PRINT
OFStream os(stdout);
code->Print(os);
byte* begin = code->instruction_start();
byte* end = begin + code->instruction_size();
disasm::Disassembler::Disassemble(stdout, begin, end);
#endif
size_t offset = 10;
int mode_mask = (1 << RelocInfo::WASM_MEMORY_SIZE_REFERENCE);
for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) {
RelocInfo::Mode mode = it.rinfo()->rmode();
if (RelocInfo::IsWasmMemorySizeReference(mode)) {
it.rinfo()->update_wasm_memory_reference(
reinterpret_cast<Address>(1234), reinterpret_cast<Address>(1234),
it.rinfo()->wasm_memory_size_reference(),
it.rinfo()->wasm_memory_size_reference() + offset, SKIP_ICACHE_FLUSH);
}
}
ret_value = runnable.Call();
CHECK_NE(ret_value, 0xdeadbeef);
#ifdef OBJECT_PRINT
code->Print(os);
begin = code->instruction_start();
end = begin + code->instruction_size();
disasm::Disassembler::Disassemble(stdout, begin, end);
#endif
}
#undef __
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