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 <iostream> // NOLINT(readability/streams) | 5 #include <iostream> // NOLINT(readability/streams) |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 #include "test/cctest/cctest.h" | 8 #include "test/cctest/cctest.h" |
9 | 9 |
10 #include "src/arm/assembler-arm-inl.h" | 10 #include "src/arm/assembler-arm-inl.h" |
11 #include "src/arm/simulator-arm.h" | 11 #include "src/arm/simulator-arm.h" |
12 #include "src/disassembler.h" | 12 #include "src/disassembler.h" |
13 #include "src/factory.h" | 13 #include "src/factory.h" |
14 #include "src/ostreams.h" | 14 #include "src/ostreams.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::base; | 18 using namespace v8::base; |
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(WasmRelocationArm) { | 26 TEST(WasmRelocationArmMemoryReference) { |
27 CcTest::InitializeVM(); | |
28 Isolate* isolate = CcTest::i_isolate(); | 27 Isolate* isolate = CcTest::i_isolate(); |
29 HandleScope scope(isolate); | 28 HandleScope scope(isolate); |
30 v8::internal::byte buffer[4096]; | 29 v8::internal::byte buffer[4096]; |
31 DummyStaticFunction(NULL); | 30 DummyStaticFunction(NULL); |
32 int32_t imm = 1234567; | 31 int32_t imm = 1234567; |
33 | 32 |
34 Assembler assm(isolate, buffer, sizeof buffer); | 33 Assembler assm(isolate, buffer, sizeof buffer); |
35 | 34 |
36 __ mov(r0, Operand(imm, RelocInfo::WASM_MEMORY_REFERENCE)); | 35 __ mov(r0, Operand(imm, RelocInfo::WASM_MEMORY_REFERENCE)); |
37 __ mov(pc, Operand(lr)); | 36 __ mov(pc, Operand(lr)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 // Call into relocated code object | 69 // Call into relocated code object |
71 ret_value = runnable.Call(); | 70 ret_value = runnable.Call(); |
72 CHECK_EQ((imm + offset), ret_value); | 71 CHECK_EQ((imm + offset), ret_value); |
73 | 72 |
74 #ifdef DEBUG | 73 #ifdef DEBUG |
75 code->Print(os); | 74 code->Print(os); |
76 ::printf("f() = %d\n\n", ret_value); | 75 ::printf("f() = %d\n\n", ret_value); |
77 #endif | 76 #endif |
78 } | 77 } |
79 | 78 |
| 79 TEST(WasmRelocationArmMemorySizeReference) { |
| 80 CcTest::InitializeVM(); |
| 81 Isolate* isolate = CcTest::i_isolate(); |
| 82 HandleScope scope(isolate); |
| 83 v8::internal::byte buffer[4096]; |
| 84 DummyStaticFunction(NULL); |
| 85 int32_t size = 512; |
| 86 Label fail; |
| 87 |
| 88 Assembler assm(isolate, buffer, sizeof buffer); |
| 89 |
| 90 __ mov(r0, Operand(size, RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); |
| 91 __ cmp(r0, Operand(size, RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); |
| 92 __ b(ne, &fail); |
| 93 __ mov(pc, Operand(lr)); |
| 94 __ bind(&fail); |
| 95 __ mov(r0, Operand(0xdeadbeef)); |
| 96 __ mov(pc, Operand(lr)); |
| 97 |
| 98 CodeDesc desc; |
| 99 assm.GetCode(&desc); |
| 100 Handle<Code> code = isolate->factory()->NewCode( |
| 101 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 102 |
| 103 CSignature0<int32_t> csig; |
| 104 CodeRunner<int32_t> runnable(isolate, code, &csig); |
| 105 int32_t ret_value = runnable.Call(); |
| 106 CHECK_NE(ret_value, 0xdeadbeef); |
| 107 |
| 108 #ifdef DEBUG |
| 109 OFStream os(stdout); |
| 110 code->Print(os); |
| 111 ::printf("f() = %d\n\n", ret_value); |
| 112 #endif |
| 113 size_t diff = 512; |
| 114 |
| 115 int mode_mask = (1 << RelocInfo::WASM_MEMORY_SIZE_REFERENCE); |
| 116 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { |
| 117 RelocInfo::Mode mode = it.rinfo()->rmode(); |
| 118 if (RelocInfo::IsWasmMemorySizeReference(mode)) { |
| 119 it.rinfo()->update_wasm_memory_reference( |
| 120 reinterpret_cast<Address>(1234), reinterpret_cast<Address>(1234), |
| 121 it.rinfo()->wasm_memory_size_reference(), |
| 122 it.rinfo()->wasm_memory_size_reference() + diff, SKIP_ICACHE_FLUSH); |
| 123 } |
| 124 } |
| 125 |
| 126 ret_value = runnable.Call(); |
| 127 CHECK_NE(ret_value, 0xdeadbeef); |
| 128 |
| 129 #ifdef DEBUG |
| 130 code->Print(os); |
| 131 ::printf("f() = %d\n\n", ret_value); |
| 132 #endif |
| 133 } |
80 #undef __ | 134 #undef __ |
OLD | NEW |