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/arm64/simulator-arm64.h" | 10 #include "src/arm64/simulator-arm64.h" |
11 #include "src/arm64/utils-arm64.h" | 11 #include "src/arm64/utils-arm64.h" |
12 #include "src/disassembler.h" | 12 #include "src/disassembler.h" |
13 #include "src/factory.h" | 13 #include "src/factory.h" |
14 #include "src/macro-assembler.h" | 14 #include "src/macro-assembler.h" |
15 #include "src/ostreams.h" | 15 #include "src/ostreams.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::base; | 19 using namespace v8::base; |
20 using namespace v8::internal; | 20 using namespace v8::internal; |
21 using namespace v8::internal::compiler; | 21 using namespace v8::internal::compiler; |
22 | 22 |
23 #define __ masm. | 23 #define __ masm. |
24 | 24 |
25 static int64_t DummyStaticFunction(Object* result) { return 1; } | 25 static int64_t DummyStaticFunction(Object* result) { return 1; } |
26 | 26 |
27 TEST(WasmRelocationArm64) { | 27 TEST(WasmRelocationArm64MemoryReference) { |
28 CcTest::InitializeVM(); | |
29 Isolate* isolate = CcTest::i_isolate(); | 28 Isolate* isolate = CcTest::i_isolate(); |
30 HandleScope scope(isolate); | 29 HandleScope scope(isolate); |
31 v8::internal::byte buffer[4096]; | 30 v8::internal::byte buffer[4096]; |
32 DummyStaticFunction(NULL); | 31 DummyStaticFunction(NULL); |
33 int64_t imm = 1234567; | 32 int64_t imm = 1234567; |
34 | 33 |
35 MacroAssembler masm(isolate, buffer, sizeof buffer, | 34 MacroAssembler masm(isolate, buffer, sizeof buffer, |
36 v8::internal::CodeObjectRequired::kYes); | 35 v8::internal::CodeObjectRequired::kYes); |
37 | 36 |
38 __ Mov(x0, Immediate(imm, RelocInfo::WASM_MEMORY_REFERENCE)); | 37 __ Mov(x0, Immediate(imm, RelocInfo::WASM_MEMORY_REFERENCE)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 // Call into relocated code object | 71 // Call into relocated code object |
73 ret_value = runnable.Call(); | 72 ret_value = runnable.Call(); |
74 CHECK_EQ((imm + offset), ret_value); | 73 CHECK_EQ((imm + offset), ret_value); |
75 | 74 |
76 #ifdef DEBUG | 75 #ifdef DEBUG |
77 code->Print(os); | 76 code->Print(os); |
78 ::printf("f() = %ld\n\n", ret_value); | 77 ::printf("f() = %ld\n\n", ret_value); |
79 #endif | 78 #endif |
80 } | 79 } |
81 | 80 |
| 81 TEST(WasmRelocationArm64MemorySizeReference) { |
| 82 CcTest::InitializeVM(); |
| 83 Isolate* isolate = CcTest::i_isolate(); |
| 84 HandleScope scope(isolate); |
| 85 v8::internal::byte buffer[4096]; |
| 86 DummyStaticFunction(NULL); |
| 87 Immediate size = Immediate(512, RelocInfo::WASM_MEMORY_SIZE_REFERENCE); |
| 88 Label fail; |
| 89 |
| 90 MacroAssembler masm(isolate, buffer, sizeof buffer, |
| 91 v8::internal::CodeObjectRequired::kYes); |
| 92 |
| 93 __ Mov(x0, size); |
| 94 __ Cmp(x0, size); |
| 95 __ B(ne, &fail); |
| 96 __ Ret(); |
| 97 __ Bind(&fail); |
| 98 __ Mov(x0, Immediate(0xdeadbeef)); |
| 99 __ Ret(); |
| 100 |
| 101 CodeDesc desc; |
| 102 masm.GetCode(&desc); |
| 103 Handle<Code> code = isolate->factory()->NewCode( |
| 104 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 105 |
| 106 CSignature0<int64_t> csig; |
| 107 CodeRunner<int64_t> runnable(isolate, code, &csig); |
| 108 int64_t ret_value = runnable.Call(); |
| 109 CHECK_NE(ret_value, 0xdeadbeef); |
| 110 |
| 111 #ifdef DEBUG |
| 112 OFStream os(stdout); |
| 113 code->Print(os); |
| 114 ::printf("f() = %ld\n\n", ret_value); |
| 115 #endif |
| 116 int32_t diff = 512; |
| 117 |
| 118 int mode_mask = (1 << RelocInfo::WASM_MEMORY_SIZE_REFERENCE); |
| 119 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { |
| 120 RelocInfo::Mode mode = it.rinfo()->rmode(); |
| 121 if (RelocInfo::IsWasmMemorySizeReference(mode)) { |
| 122 it.rinfo()->update_wasm_memory_reference( |
| 123 reinterpret_cast<Address>(0x1234), reinterpret_cast<Address>(0x1234), |
| 124 it.rinfo()->wasm_memory_size_reference(), |
| 125 it.rinfo()->wasm_memory_size_reference() + diff, SKIP_ICACHE_FLUSH); |
| 126 } |
| 127 } |
| 128 |
| 129 ret_value = runnable.Call(); |
| 130 CHECK_NE(ret_value, 0xdeadbeef); |
| 131 |
| 132 #ifdef DEBUG |
| 133 code->Print(os); |
| 134 ::printf("f() = %ld\n\n", ret_value); |
| 135 #endif |
| 136 } |
| 137 |
82 #undef __ | 138 #undef __ |
OLD | NEW |