OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 the V8 project authors. All rights reserved. | |
2 // Redistribution and use in source and binary forms, with or without | |
3 // modification, are permitted provided that the following conditions are | |
4 // met: | |
5 // | |
6 // * Redistributions of source code must retain the above copyright | |
7 // notice, this list of conditions and the following disclaimer. | |
8 // * Redistributions in binary form must reproduce the above | |
9 // copyright notice, this list of conditions and the following | |
10 // disclaimer in the documentation and/or other materials provided | |
11 // with the distribution. | |
12 // * Neither the name of Google Inc. nor the names of its | |
13 // contributors may be used to endorse or promote products derived | |
14 // from this software without specific prior written permission. | |
15 // | |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | |
28 #include <iostream> // NOLINT(readability/streams) | |
29 | |
30 #include "src/v8.h" | |
31 #include "test/cctest/cctest.h" | |
32 | |
33 #include "src/disassembler.h" | |
34 #include "src/factory.h" | |
35 #include "src/macro-assembler.h" | |
36 #include "src/mips/assembler-mips-inl.h" | |
37 #include "src/mips/macro-assembler-mips.h" | |
38 #include "src/mips/simulator-mips.h" | |
39 #include "src/ostreams.h" | |
40 #include "test/cctest/compiler/c-signature.h" | |
41 #include "test/cctest/compiler/call-tester.h" | |
42 | |
43 using namespace v8::base; | |
44 using namespace v8::internal; | |
45 using namespace v8::internal::compiler; | |
46 | |
47 #define __ assm. | |
48 | |
49 static int32_t DummyStaticFunction(Object* result) { return 1; } | |
50 | |
51 TEST(WasmRelocationMips) { | |
52 CcTest::InitializeVM(); | |
53 Isolate* isolate = CcTest::i_isolate(); | |
54 HandleScope scope(isolate); | |
55 v8::internal::byte buffer[4096]; | |
56 DummyStaticFunction(NULL); | |
57 int32_t imm = 1234567; | |
58 | |
59 MacroAssembler assm(isolate, buffer, sizeof buffer, | |
60 v8::internal::CodeObjectRequired::kYes); | |
61 | |
62 __ li(v0, Operand(imm, RelocInfo::WASM_MEMORY_REFERENCE)); | |
63 __ Jump(ra); | |
64 | |
65 CodeDesc desc; | |
66 assm.GetCode(&desc); | |
67 Handle<Code> code = isolate->factory()->NewCode( | |
68 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | |
69 | |
70 USE(code); | |
71 CSignature0<int32_t> csig; | |
72 CodeRunner<int32_t> runnable(isolate, code, &csig); | |
73 | |
74 int32_t ret_value = runnable.Call(); | |
75 CHECK_EQ(ret_value, imm); | |
76 | |
77 #ifdef DEBUG | |
78 OFStream os(stdout); | |
79 code->Print(os); | |
80 ::printf("f() = %d\n\n", ret_value); | |
81 #endif | |
82 size_t offset = 1234; | |
83 | |
84 // Relocating references by offset | |
85 int mode_mask = (1 << RelocInfo::WASM_MEMORY_REFERENCE); | |
86 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { | |
87 RelocInfo::Mode mode = it.rinfo()->rmode(); | |
88 if (RelocInfo::IsWasmMemoryReference(mode)) { | |
89 it.rinfo()->update_wasm_memory_reference( | |
balazs.kilvady
2016/03/09 11:00:20
Please update the parameters of this function (and
| |
90 it.rinfo()->wasm_memory_reference() + offset, SKIP_ICACHE_FLUSH); | |
91 } | |
92 } | |
93 | |
94 // Call into relocated code object | |
95 ret_value = runnable.Call(); | |
96 CHECK_EQ((imm + offset), ret_value); | |
97 | |
98 #ifdef DEBUG | |
99 code->Print(os); | |
100 ::printf("f() = %d\n\n", ret_value); | |
101 #endif | |
102 } | |
103 | |
104 #undef __ | |
OLD | NEW |