OLD | NEW |
---|---|
1 // Copyright 2016 the V8 project authors. All rights reserved. Use of this | 1 // Copyright 2016 the V8 project authors. All rights reserved. Use of this |
2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
3 // LICENSE file. | 3 // LICENSE file. |
4 | 4 |
5 #include <cmath> | 5 #include <cmath> |
6 #include <functional> | 6 #include <functional> |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/base/utils/random-number-generator.h" | 10 #include "src/base/utils/random-number-generator.h" |
11 #include "src/codegen.h" | 11 #include "src/codegen.h" |
12 #include "test/cctest/cctest.h" | 12 #include "test/cctest/cctest.h" |
13 #include "test/cctest/compiler/codegen-tester.h" | 13 #include "test/cctest/compiler/codegen-tester.h" |
14 #include "test/cctest/compiler/graph-builder-tester.h" | 14 #include "test/cctest/compiler/graph-builder-tester.h" |
15 #include "test/cctest/compiler/value-helper.h" | 15 #include "test/cctest/compiler/value-helper.h" |
16 | 16 |
17 using namespace v8::internal; | 17 using namespace v8::internal; |
18 using namespace v8::internal::compiler; | 18 using namespace v8::internal::compiler; |
19 | 19 |
20 static void UpdateMemoryReferences(Handle<Code> code, Address old_base, | 20 static void UpdateMemoryReferences(Handle<Code> code, Address old_base, |
21 Address new_base, uint32_t old_size, | 21 Address new_base, uint32_t old_size, |
22 uint32_t new_size) { | 22 uint32_t new_size) { |
23 Isolate* isolate = CcTest::i_isolate(); | 23 Isolate* isolate = CcTest::i_isolate(); |
24 bool modified = false; | 24 bool modified = false; |
25 int mode_mask = RelocInfo::ModeMask(RelocInfo::WASM_MEMORY_REFERENCE) | | 25 int mode_mask = |
26 RelocInfo::ModeMask(RelocInfo::WASM_MEMORY_SIZE_REFERENCE); | 26 RelocInfo::ModeMask(RelocInfo::WASM_MEMORY_REFERENCE) | |
27 RelocInfo::ModeMask(RelocInfo::WASM_MEMORY_DWORD_SIZE_REFERENCE); | |
bradn
2016/10/12 18:50:45
Test all the sizes.
gdeepti
2016/10/13 08:43:00
Got rid of additional RelocInfo modes, code remove
| |
27 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { | 28 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { |
28 RelocInfo::Mode mode = it.rinfo()->rmode(); | 29 RelocInfo::Mode mode = it.rinfo()->rmode(); |
29 if (RelocInfo::IsWasmMemoryReference(mode) || | 30 if (RelocInfo::IsWasmMemoryReference(mode) || |
30 RelocInfo::IsWasmMemorySizeReference(mode)) { | 31 RelocInfo::IsWasmMemorySizeReference(mode)) { |
31 // Patch addresses with change in memory start address | 32 // Patch addresses with change in memory start address |
32 it.rinfo()->update_wasm_memory_reference(old_base, new_base, old_size, | 33 it.rinfo()->update_wasm_memory_reference(old_base, new_base, old_size, |
33 new_size); | 34 new_size); |
34 modified = true; | 35 modified = true; |
35 } | 36 } |
36 } | 37 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 RunLoadStoreRelocationOffset<uint32_t>(MachineType::Uint32()); | 144 RunLoadStoreRelocationOffset<uint32_t>(MachineType::Uint32()); |
144 RunLoadStoreRelocationOffset<void*>(MachineType::AnyTagged()); | 145 RunLoadStoreRelocationOffset<void*>(MachineType::AnyTagged()); |
145 RunLoadStoreRelocationOffset<float>(MachineType::Float32()); | 146 RunLoadStoreRelocationOffset<float>(MachineType::Float32()); |
146 RunLoadStoreRelocationOffset<double>(MachineType::Float64()); | 147 RunLoadStoreRelocationOffset<double>(MachineType::Float64()); |
147 } | 148 } |
148 | 149 |
149 TEST(Uint32LessThanRelocation) { | 150 TEST(Uint32LessThanRelocation) { |
150 RawMachineAssemblerTester<uint32_t> m; | 151 RawMachineAssemblerTester<uint32_t> m; |
151 RawMachineLabel within_bounds, out_of_bounds; | 152 RawMachineLabel within_bounds, out_of_bounds; |
152 Node* index = m.Int32Constant(0x200); | 153 Node* index = m.Int32Constant(0x200); |
153 Node* limit = | 154 Node* limit = m.RelocatableInt32Constant( |
154 m.RelocatableInt32Constant(0x200, RelocInfo::WASM_MEMORY_SIZE_REFERENCE); | 155 0x200, RelocInfo::WASM_MEMORY_DWORD_SIZE_REFERENCE); |
155 Node* cond = m.AddNode(m.machine()->Uint32LessThan(), index, limit); | 156 Node* cond = m.AddNode(m.machine()->Uint32LessThan(), index, limit); |
156 m.Branch(cond, &within_bounds, &out_of_bounds); | 157 m.Branch(cond, &within_bounds, &out_of_bounds); |
157 m.Bind(&within_bounds); | 158 m.Bind(&within_bounds); |
158 m.Return(m.Int32Constant(0xaced)); | 159 m.Return(m.Int32Constant(0xaced)); |
159 m.Bind(&out_of_bounds); | 160 m.Bind(&out_of_bounds); |
160 m.Return(m.Int32Constant(0xdeadbeef)); | 161 m.Return(m.Int32Constant(0xdeadbeef)); |
161 // Check that index is out of bounds with current size | 162 // Check that index is out of bounds with current size |
162 CHECK_EQ(0xdeadbeef, m.Call()); | 163 CHECK_EQ(0xdeadbeef, m.Call()); |
163 m.GenerateCode(); | 164 m.GenerateCode(); |
164 | 165 |
165 Handle<Code> code = m.GetCode(); | 166 Handle<Code> code = m.GetCode(); |
166 UpdateMemoryReferences(code, reinterpret_cast<Address>(1234), | 167 UpdateMemoryReferences(code, reinterpret_cast<Address>(1234), |
167 reinterpret_cast<Address>(1234), 0x200, 0x400); | 168 reinterpret_cast<Address>(1234), 0x200, 0x400); |
168 // Check that after limit is increased, index is within bounds. | 169 // Check that after limit is increased, index is within bounds. |
169 CHECK_EQ(0xaced, m.Call()); | 170 CHECK_EQ(0xaced, m.Call()); |
170 } | 171 } |
OLD | NEW |