Chromium Code Reviews| 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/arm/assembler-arm-inl.h" | |
| 34 #include "src/arm/simulator-arm.h" | |
| 35 #include "src/disassembler.h" | |
| 36 #include "src/factory.h" | |
| 37 #include "src/ostreams.h" | |
| 38 #include "test/cctest/compiler/c-signature.h" | |
| 39 #include "test/cctest/compiler/call-tester.h" | |
| 40 | |
| 41 using namespace v8::base; | |
| 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(WasmRelocationArm) { | |
| 50 CcTest::InitializeVM(); | |
| 51 Isolate* isolate = CcTest::i_isolate(); | |
| 52 HandleScope scope(isolate); | |
| 53 v8::internal::byte buffer[4096]; | |
| 54 DummyStaticFunction(NULL); | |
| 55 int32_t imm = 1234567; | |
| 56 | |
| 57 Assembler assm(isolate, buffer, sizeof buffer); | |
| 58 | |
| 59 __ mov(r0, Operand(imm, RelocInfo::WASM_HEAP_OBJECT)); | |
| 60 __ mov(pc, Operand(lr)); | |
| 61 | |
| 62 CodeDesc desc; | |
| 63 assm.GetCode(&desc); | |
| 64 Handle<Code> code = isolate->factory()->NewCode( | |
| 65 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); | |
| 66 | |
| 67 CSignature0<int32_t> csig; | |
| 68 CodeRunner<int32_t> runnable(isolate, code, &csig); | |
| 69 int32_t ret_value = runnable.Call(); | |
| 70 CHECK_EQ(ret_value, imm); | |
| 71 | |
| 72 #ifdef DEBUG | |
| 73 OFStream os(stdout); | |
| 74 code->Print(os); | |
| 75 ::printf("f() = %d\n\n", ret_value); | |
| 76 #endif | |
| 77 | |
| 78 // Initialize new buffer | |
| 79 v8::internal::byte new_buffer[4096]; | |
| 80 size_t offset = | |
| 81 reinterpret_cast<byte*>(new_buffer) - reinterpret_cast<byte*>(buffer); | |
|
Yang
2016/03/03 06:21:56
I don't see why the offset between buffers matters
gdeepti1
2016/03/03 22:59:15
The context I guess is updating references by an o
| |
| 82 | |
| 83 // Relocating code object | |
| 84 int mode_mask = (1 << RelocInfo::WASM_HEAP_OBJECT); | |
| 85 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { | |
| 86 RelocInfo::Mode mode = it.rinfo()->rmode(); | |
| 87 if (RelocInfo::IsWasmCodeEntry(mode)) { | |
| 88 it.rinfo()->set_target_address(it.rinfo()->target_address() + offset, | |
|
Yang
2016/03/03 06:21:56
just write something new into here, like a imm_new
gdeepti1
2016/03/03 22:59:15
references updated by an offset for now.
| |
| 89 SKIP_WRITE_BARRIER, SKIP_ICACHE_FLUSH); | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 // Call into relocated code object | |
| 94 ret_value = runnable.Call(); | |
| 95 CHECK_EQ((imm + offset), ret_value); | |
| 96 | |
| 97 #ifdef DEBUG | |
| 98 code->Print(os); | |
| 99 ::printf("f() = %d\n\n", ret_value); | |
| 100 #endif | |
| 101 } | |
| 102 | |
| 103 #undef __ | |
| OLD | NEW |