OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/debug/debug.h" | 9 #include "src/debug/debug.h" |
10 #include "src/disasm.h" | 10 #include "src/disasm.h" |
11 #include "src/disassembler.h" | 11 #include "src/disassembler.h" |
12 #include "src/ic/ic.h" | 12 #include "src/ic/ic.h" |
13 #include "src/macro-assembler.h" | 13 #include "src/macro-assembler.h" |
14 #include "test/cctest/cctest.h" | 14 #include "test/cctest/cctest.h" |
15 #include "test/cctest/compiler/c-signature.h" | 15 #include "test/cctest/compiler/c-signature.h" |
16 #include "test/cctest/compiler/call-tester.h" | 16 #include "test/cctest/compiler/call-tester.h" |
17 | 17 |
18 using namespace v8::internal; | 18 using namespace v8::internal; |
19 using namespace v8::internal::compiler; | 19 using namespace v8::internal::compiler; |
20 | 20 |
21 #define __ assm. | 21 #define __ assm. |
22 | 22 |
23 static int32_t DummyStaticFunction(Object* result) { return 1; } | 23 static int32_t DummyStaticFunction(Object* result) { return 1; } |
24 | 24 |
25 TEST(WasmRelocationX64movq64) { | 25 TEST(WasmRelocationX64MemoryReference) { |
26 CcTest::InitializeVM(); | |
27 Isolate* isolate = CcTest::i_isolate(); | 26 Isolate* isolate = CcTest::i_isolate(); |
28 HandleScope scope(isolate); | 27 HandleScope scope(isolate); |
29 v8::internal::byte buffer[4096]; | 28 v8::internal::byte buffer[4096]; |
30 Assembler assm(isolate, buffer, sizeof buffer); | 29 Assembler assm(isolate, buffer, sizeof buffer); |
31 DummyStaticFunction(NULL); | 30 DummyStaticFunction(NULL); |
32 int64_t imm = 1234567; | 31 int64_t imm = 1234567; |
33 | 32 |
34 __ movq(rax, imm, RelocInfo::WASM_MEMORY_REFERENCE); | 33 __ movq(rax, imm, RelocInfo::WASM_MEMORY_REFERENCE); |
35 __ nop(); | 34 __ nop(); |
36 __ ret(0); | 35 __ ret(0); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 CHECK_EQ(ret_value, imm + offset); | 73 CHECK_EQ(ret_value, imm + offset); |
75 | 74 |
76 #ifdef OBJECT_PRINT | 75 #ifdef OBJECT_PRINT |
77 code->Print(os); | 76 code->Print(os); |
78 begin = code->instruction_start(); | 77 begin = code->instruction_start(); |
79 end = begin + code->instruction_size(); | 78 end = begin + code->instruction_size(); |
80 disasm::Disassembler::Disassemble(stdout, begin, end); | 79 disasm::Disassembler::Disassemble(stdout, begin, end); |
81 #endif | 80 #endif |
82 } | 81 } |
83 | 82 |
| 83 TEST(WasmRelocationX64WasmMemorySizeReference) { |
| 84 CcTest::InitializeVM(); |
| 85 Isolate* isolate = CcTest::i_isolate(); |
| 86 HandleScope scope(isolate); |
| 87 v8::internal::byte buffer[4096]; |
| 88 Assembler assm(isolate, buffer, sizeof buffer); |
| 89 DummyStaticFunction(NULL); |
| 90 int32_t size = 512; |
| 91 Label fail; |
| 92 |
| 93 __ movl(rax, Immediate(size, RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); |
| 94 __ cmpl(rax, Immediate(size, RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); |
| 95 __ j(not_equal, &fail); |
| 96 __ ret(0); |
| 97 __ bind(&fail); |
| 98 __ movl(rax, Immediate(0xdeadbeef)); |
| 99 __ ret(0); |
| 100 |
| 101 CodeDesc desc; |
| 102 assm.GetCode(&desc); |
| 103 Handle<Code> code = isolate->factory()->NewCode( |
| 104 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 105 USE(code); |
| 106 |
| 107 CSignature0<int64_t> csig; |
| 108 CodeRunner<int64_t> runnable(isolate, code, &csig); |
| 109 int64_t ret_value = runnable.Call(); |
| 110 CHECK_NE(ret_value, 0xdeadbeef); |
| 111 |
| 112 #ifdef OBJECT_PRINT |
| 113 OFStream os(stdout); |
| 114 code->Print(os); |
| 115 byte* begin = code->instruction_start(); |
| 116 byte* end = begin + code->instruction_size(); |
| 117 disasm::Disassembler::Disassemble(stdout, begin, end); |
| 118 #endif |
| 119 int32_t diff = 512; |
| 120 |
| 121 int mode_mask = (1 << RelocInfo::WASM_MEMORY_SIZE_REFERENCE); |
| 122 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { |
| 123 RelocInfo::Mode mode = it.rinfo()->rmode(); |
| 124 if (RelocInfo::IsWasmMemorySizeReference(mode)) { |
| 125 it.rinfo()->update_wasm_memory_reference( |
| 126 reinterpret_cast<Address>(1234), reinterpret_cast<Address>(1234), |
| 127 it.rinfo()->wasm_memory_size_reference(), |
| 128 it.rinfo()->wasm_memory_size_reference() + diff, SKIP_ICACHE_FLUSH); |
| 129 } |
| 130 } |
| 131 |
| 132 ret_value = runnable.Call(); |
| 133 CHECK_NE(ret_value, 0xdeadbeef); |
| 134 |
| 135 #ifdef OBJECT_PRINT |
| 136 code->Print(os); |
| 137 begin = code->instruction_start(); |
| 138 end = begin + code->instruction_size(); |
| 139 disasm::Disassembler::Disassemble(stdout, begin, end); |
| 140 #endif |
| 141 } |
84 #undef __ | 142 #undef __ |
OLD | NEW |