Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: test/cctest/test-wasm-relocation-disasm-ia32.cc

Issue 1759873002: Assembler changes for enabling GrowHeap in Wasm (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Adding x64 test Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 <stdlib.h>
29
30 #include "src/v8.h"
31
32 #include "src/debug/debug.h"
33 #include "src/disasm.h"
34 #include "src/disassembler.h"
35 #include "src/ia32/frames-ia32.h"
36 #include "src/ic/ic.h"
37 #include "src/macro-assembler.h"
38 #include "test/cctest/cctest.h"
39 #include "test/cctest/compiler/c-signature.h"
40 #include "test/cctest/compiler/call-tester.h"
41
42 using namespace v8::internal;
43 using namespace v8::internal::compiler;
44
45 #define __ assm.
46
47 static int32_t DummyStaticFunction(Object* result) { return 1; }
48
49 TEST(WasmRelocationIa32) {
50 CcTest::InitializeVM();
51 Zone zone;
52 Isolate* isolate = CcTest::i_isolate();
53 HandleScope scope(isolate);
54 v8::internal::byte buffer[4096];
55 Assembler assm(isolate, buffer, sizeof buffer);
56 DummyStaticFunction(NULL);
57 int32_t imm = 1234567;
58
59 __ mov(eax, Immediate(imm, RelocInfo::WASM_HEAP_OBJECT));
60 __ nop();
61 __ ret(0);
62
63 CSignature0<int32_t> csig;
64 CodeDesc desc;
65 assm.GetCode(&desc);
66 Handle<Code> code = isolate->factory()->NewCode(
67 desc, Code::ComputeFlags(Code::STUB), Handle<Code>());
68 USE(code);
69
70 CodeRunner<int32_t> runnable(isolate, code, &csig);
71 int32_t ret_value = runnable.Call();
72 CHECK_EQ(ret_value, imm);
73
74 #ifdef OBJECT_PRINT
75 OFStream os(stdout);
76 code->Print(os);
77 byte* begin = code->instruction_start();
78 byte* end = begin + code->instruction_size();
79 disasm::Disassembler::Disassemble(stdout, begin, end);
80 #endif
81
82 // Initialize new buffer
83 v8::internal::byte new_buffer[4096];
84 size_t offset =
85 reinterpret_cast<byte*>(new_buffer) - reinterpret_cast<byte*>(buffer);
86
87 // Relocating code object
88 int mode_mask = (1 << RelocInfo::WASM_HEAP_OBJECT);
89 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) {
90 RelocInfo::Mode mode = it.rinfo()->rmode();
91 if (RelocInfo::IsWasmCodeEntry(mode)) {
92 it.rinfo()->set_target_address(it.rinfo()->target_address() + offset,
93 SKIP_WRITE_BARRIER, SKIP_ICACHE_FLUSH);
94 }
95 }
96
97 // Check if immediate is updated correctly
98 ret_value = runnable.Call();
99 CHECK_EQ(ret_value, imm + offset);
100
101 #ifdef OBJECT_PRINT
102 // OFStream os(stdout);
103 code->Print(os);
104 begin = code->instruction_start();
105 end = begin + code->instruction_size();
106 disasm::Disassembler::Disassemble(stdout, begin, end);
107 #endif
108 }
109
110 #undef __
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698