OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Check that we can traverse very deep stacks of ConsStrings using | 28 #include <iostream> // NOLINT(readability/streams) |
29 // StringCharacterStram. Check that Get(int) works on very deep stacks | |
30 // of ConsStrings. These operations may not be very fast, but they | |
31 // should be possible without getting errors due to too deep recursion. | |
32 | 29 |
33 #include "src/v8.h" | 30 #include "src/v8.h" |
34 | |
35 #include "src/objects.h" | |
36 #include "src/ostreams.h" | |
37 #include "test/cctest/cctest.h" | 31 #include "test/cctest/cctest.h" |
38 | 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; |
39 using namespace v8::internal; | 42 using namespace v8::internal; |
| 43 using namespace v8::internal::compiler; |
40 | 44 |
| 45 #define __ assm. |
41 | 46 |
42 TEST(Create) { | 47 static int32_t DummyStaticFunction(Object* result) { return 1; } |
| 48 |
| 49 TEST(WasmRelocationArm) { |
43 CcTest::InitializeVM(); | 50 CcTest::InitializeVM(); |
44 Isolate* isolate = CcTest::i_isolate(); | 51 Isolate* isolate = CcTest::i_isolate(); |
45 HandleScope scope(isolate); | 52 HandleScope scope(isolate); |
| 53 v8::internal::byte buffer[4096]; |
| 54 DummyStaticFunction(NULL); |
| 55 int32_t imm = 1234567; |
46 | 56 |
47 const int kNumSymbols = 30; | 57 Assembler assm(isolate, buffer, sizeof buffer); |
48 Handle<Symbol> symbols[kNumSymbols]; | |
49 | 58 |
| 59 __ mov(r0, Operand(imm, RelocInfo::WASM_MEMORY_REFERENCE)); |
| 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 |
50 OFStream os(stdout); | 73 OFStream os(stdout); |
51 for (int i = 0; i < kNumSymbols; ++i) { | 74 code->Print(os); |
52 symbols[i] = isolate->factory()->NewSymbol(); | 75 ::printf("f() = %d\n\n", ret_value); |
53 CHECK(symbols[i]->IsName()); | |
54 CHECK(symbols[i]->IsSymbol()); | |
55 CHECK(symbols[i]->HasHashCode()); | |
56 CHECK_GT(symbols[i]->Hash(), 0u); | |
57 os << Brief(*symbols[i]) << "\n"; | |
58 #if OBJECT_PRINT | |
59 symbols[i]->Print(os); | |
60 #endif | 76 #endif |
61 #if VERIFY_HEAP | 77 size_t offset = 1234; |
62 symbols[i]->ObjectVerify(); | 78 |
63 #endif | 79 // Relocating references by offset |
| 80 int mode_mask = (1 << RelocInfo::WASM_MEMORY_REFERENCE); |
| 81 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { |
| 82 RelocInfo::Mode mode = it.rinfo()->rmode(); |
| 83 if (RelocInfo::IsWasmMemoryReference(mode)) { |
| 84 it.rinfo()->update_wasm_memory_reference( |
| 85 it.rinfo()->wasm_memory_reference() + offset, SKIP_ICACHE_FLUSH); |
| 86 } |
64 } | 87 } |
65 | 88 |
66 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 89 // Call into relocated code object |
67 CcTest::heap()->CollectAllGarbage(); | 90 ret_value = runnable.Call(); |
| 91 CHECK_EQ((imm + offset), ret_value); |
68 | 92 |
69 // All symbols should be distinct. | 93 #ifdef DEBUG |
70 for (int i = 0; i < kNumSymbols; ++i) { | 94 code->Print(os); |
71 CHECK(symbols[i]->SameValue(*symbols[i])); | 95 ::printf("f() = %d\n\n", ret_value); |
72 for (int j = i + 1; j < kNumSymbols; ++j) { | 96 #endif |
73 CHECK(!symbols[i]->SameValue(*symbols[j])); | |
74 } | |
75 } | |
76 } | 97 } |
| 98 |
| 99 #undef __ |
OLD | NEW |