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 "src/x87/frames-x87.h" | 14 #include "src/x87/frames-x87.h" |
15 #include "test/cctest/cctest.h" | 15 #include "test/cctest/cctest.h" |
16 #include "test/cctest/compiler/c-signature.h" | 16 #include "test/cctest/compiler/c-signature.h" |
17 #include "test/cctest/compiler/call-tester.h" | 17 #include "test/cctest/compiler/call-tester.h" |
18 | 18 |
19 using namespace v8::internal; | 19 using namespace v8::internal; |
20 using namespace v8::internal::compiler; | 20 using namespace v8::internal::compiler; |
21 | 21 |
22 #define __ assm. | 22 #define __ assm. |
23 | 23 |
24 static int32_t DummyStaticFunction(Object* result) { return 1; } | 24 static int32_t DummyStaticFunction(Object* result) { return 1; } |
25 | 25 |
26 TEST(WasmRelocationIa32) { | 26 TEST(WasmRelocationX87MemoryReference) { |
27 CcTest::InitializeVM(); | |
28 Isolate* isolate = CcTest::i_isolate(); | 27 Isolate* isolate = CcTest::i_isolate(); |
29 Zone zone(isolate->allocator()); | 28 Zone zone(isolate->allocator()); |
30 HandleScope scope(isolate); | 29 HandleScope scope(isolate); |
31 v8::internal::byte buffer[4096]; | 30 v8::internal::byte buffer[4096]; |
32 Assembler assm(isolate, buffer, sizeof buffer); | 31 Assembler assm(isolate, buffer, sizeof buffer); |
33 DummyStaticFunction(NULL); | 32 DummyStaticFunction(NULL); |
34 int32_t imm = 1234567; | 33 int32_t imm = 1234567; |
35 | 34 |
36 __ mov(eax, Immediate(reinterpret_cast<Address>(imm), | 35 __ mov(eax, Immediate(reinterpret_cast<Address>(imm), |
37 RelocInfo::WASM_MEMORY_REFERENCE)); | 36 RelocInfo::WASM_MEMORY_REFERENCE)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 it.rinfo()->wasm_memory_reference() + offset, 1, 2, | 70 it.rinfo()->wasm_memory_reference() + offset, 1, 2, |
72 SKIP_ICACHE_FLUSH); | 71 SKIP_ICACHE_FLUSH); |
73 } | 72 } |
74 } | 73 } |
75 | 74 |
76 // Check if immediate is updated correctly | 75 // Check if immediate is updated correctly |
77 ret_value = runnable.Call(); | 76 ret_value = runnable.Call(); |
78 CHECK_EQ(ret_value, imm + offset); | 77 CHECK_EQ(ret_value, imm + offset); |
79 | 78 |
80 #ifdef OBJECT_PRINT | 79 #ifdef OBJECT_PRINT |
81 // OFStream os(stdout); | |
82 code->Print(os); | 80 code->Print(os); |
83 begin = code->instruction_start(); | 81 begin = code->instruction_start(); |
84 end = begin + code->instruction_size(); | 82 end = begin + code->instruction_size(); |
85 disasm::Disassembler::Disassemble(stdout, begin, end); | 83 disasm::Disassembler::Disassemble(stdout, begin, end); |
86 #endif | 84 #endif |
87 } | 85 } |
88 | 86 |
| 87 TEST(WasmRelocationX87MemorySizeReference) { |
| 88 CcTest::InitializeVM(); |
| 89 Isolate* isolate = CcTest::i_isolate(); |
| 90 Zone zone(isolate->allocator()); |
| 91 HandleScope scope(isolate); |
| 92 v8::internal::byte buffer[4096]; |
| 93 Assembler assm(isolate, buffer, sizeof buffer); |
| 94 DummyStaticFunction(NULL); |
| 95 int32_t size = 80; |
| 96 Label fail; |
| 97 |
| 98 __ mov(eax, Immediate(reinterpret_cast<Address>(size), |
| 99 RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); |
| 100 __ cmp(eax, Immediate(reinterpret_cast<Address>(size), |
| 101 RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); |
| 102 __ j(not_equal, &fail); |
| 103 __ ret(0); |
| 104 __ bind(&fail); |
| 105 __ mov(eax, 0xdeadbeef); |
| 106 __ ret(0); |
| 107 |
| 108 CSignature0<int32_t> csig; |
| 109 CodeDesc desc; |
| 110 assm.GetCode(&desc); |
| 111 Handle<Code> code = isolate->factory()->NewCode( |
| 112 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 113 USE(code); |
| 114 |
| 115 CodeRunner<int32_t> runnable(isolate, code, &csig); |
| 116 int32_t ret_value = runnable.Call(); |
| 117 CHECK_NE(ret_value, 0xdeadbeef); |
| 118 |
| 119 #ifdef OBJECT_PRINT |
| 120 OFStream os(stdout); |
| 121 code->Print(os); |
| 122 byte* begin = code->instruction_start(); |
| 123 byte* end = begin + code->instruction_size(); |
| 124 disasm::Disassembler::Disassemble(stdout, begin, end); |
| 125 #endif |
| 126 |
| 127 size_t offset = 10; |
| 128 |
| 129 int mode_mask = (1 << RelocInfo::WASM_MEMORY_SIZE_REFERENCE); |
| 130 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { |
| 131 RelocInfo::Mode mode = it.rinfo()->rmode(); |
| 132 if (RelocInfo::IsWasmMemorySizeReference(mode)) { |
| 133 it.rinfo()->update_wasm_memory_reference( |
| 134 reinterpret_cast<Address>(1234), reinterpret_cast<Address>(1234), |
| 135 it.rinfo()->wasm_memory_size_reference(), |
| 136 it.rinfo()->wasm_memory_size_reference() + offset, SKIP_ICACHE_FLUSH); |
| 137 } |
| 138 } |
| 139 |
| 140 ret_value = runnable.Call(); |
| 141 CHECK_NE(ret_value, 0xdeadbeef); |
| 142 |
| 143 #ifdef OBJECT_PRINT |
| 144 code->Print(os); |
| 145 begin = code->instruction_start(); |
| 146 end = begin + code->instruction_size(); |
| 147 disasm::Disassembler::Disassemble(stdout, begin, end); |
| 148 #endif |
| 149 } |
89 #undef __ | 150 #undef __ |
OLD | NEW |