OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/globals.h" | 5 #include "vm/globals.h" |
6 #if defined(TARGET_ARCH_ARM) | 6 #if defined(TARGET_ARCH_ARM) |
7 | 7 |
8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
9 #include "vm/cpu.h" | 9 #include "vm/cpu.h" |
10 #include "vm/instructions.h" | 10 #include "vm/instructions.h" |
11 #include "vm/stub_code.h" | 11 #include "vm/stub_code.h" |
12 #include "vm/unit_test.h" | 12 #include "vm/unit_test.h" |
13 | 13 |
14 namespace dart { | 14 namespace dart { |
15 | 15 |
16 #define __ assembler-> | 16 #define __ assembler-> |
17 | 17 |
18 ASSEMBLER_TEST_GENERATE(Call, assembler) { | 18 ASSEMBLER_TEST_GENERATE(Call, assembler) { |
19 __ BranchLinkPatchable(&StubCode::InvokeDartCodeLabel()); | 19 StubCode* stub_code = Isolate::Current()->stub_code(); |
| 20 __ BranchLinkPatchable(&stub_code->InvokeDartCodeLabel()); |
20 __ Ret(); | 21 __ Ret(); |
21 } | 22 } |
22 | 23 |
23 | 24 |
24 ASSEMBLER_TEST_RUN(Call, test) { | 25 ASSEMBLER_TEST_RUN(Call, test) { |
25 // The return address, which must be the address of an instruction contained | 26 // The return address, which must be the address of an instruction contained |
26 // in the code, points to the Ret instruction above, i.e. one instruction | 27 // in the code, points to the Ret instruction above, i.e. one instruction |
27 // before the end of the code buffer. | 28 // before the end of the code buffer. |
28 CallPattern call(test->entry() + test->code().Size() - Instr::kInstrSize, | 29 CallPattern call(test->entry() + test->code().Size() - Instr::kInstrSize, |
29 test->code()); | 30 test->code()); |
30 EXPECT_EQ(StubCode::InvokeDartCodeLabel().address(), | 31 StubCode* stub_code = Isolate::Current()->stub_code(); |
| 32 EXPECT_EQ(stub_code->InvokeDartCodeLabel().address(), |
31 call.TargetAddress()); | 33 call.TargetAddress()); |
32 } | 34 } |
33 | 35 |
34 | 36 |
35 ASSEMBLER_TEST_GENERATE(Jump, assembler) { | 37 ASSEMBLER_TEST_GENERATE(Jump, assembler) { |
36 __ BranchPatchable(&StubCode::InvokeDartCodeLabel()); | 38 StubCode* stub_code = Isolate::Current()->stub_code(); |
37 __ BranchPatchable(&StubCode::AllocateArrayLabel()); | 39 __ BranchPatchable(&stub_code->InvokeDartCodeLabel()); |
| 40 __ BranchPatchable(&stub_code->AllocateArrayLabel()); |
38 } | 41 } |
39 | 42 |
40 | 43 |
41 ASSEMBLER_TEST_RUN(Jump, test) { | 44 ASSEMBLER_TEST_RUN(Jump, test) { |
42 const Code& code = test->code(); | 45 const Code& code = test->code(); |
43 const Instructions& instrs = Instructions::Handle(code.instructions()); | 46 const Instructions& instrs = Instructions::Handle(code.instructions()); |
44 bool status = | 47 bool status = |
45 VirtualMemory::Protect(reinterpret_cast<void*>(instrs.EntryPoint()), | 48 VirtualMemory::Protect(reinterpret_cast<void*>(instrs.EntryPoint()), |
46 instrs.size(), | 49 instrs.size(), |
47 VirtualMemory::kReadWrite); | 50 VirtualMemory::kReadWrite); |
| 51 StubCode* stub_code = Isolate::Current()->stub_code(); |
48 EXPECT(status); | 52 EXPECT(status); |
49 JumpPattern jump1(test->entry(), test->code()); | 53 JumpPattern jump1(test->entry(), test->code()); |
50 EXPECT_EQ(StubCode::InvokeDartCodeLabel().address(), | 54 EXPECT_EQ(stub_code->InvokeDartCodeLabel().address(), |
51 jump1.TargetAddress()); | 55 jump1.TargetAddress()); |
52 JumpPattern jump2(test->entry() + jump1.pattern_length_in_bytes(), | 56 JumpPattern jump2(test->entry() + jump1.pattern_length_in_bytes(), |
53 test->code()); | 57 test->code()); |
54 EXPECT_EQ(StubCode::AllocateArrayLabel().address(), | 58 EXPECT_EQ(stub_code->AllocateArrayLabel().address(), |
55 jump2.TargetAddress()); | 59 jump2.TargetAddress()); |
56 uword target1 = jump1.TargetAddress(); | 60 uword target1 = jump1.TargetAddress(); |
57 uword target2 = jump2.TargetAddress(); | 61 uword target2 = jump2.TargetAddress(); |
58 jump1.SetTargetAddress(target2); | 62 jump1.SetTargetAddress(target2); |
59 jump2.SetTargetAddress(target1); | 63 jump2.SetTargetAddress(target1); |
60 EXPECT_EQ(StubCode::AllocateArrayLabel().address(), | 64 EXPECT_EQ(stub_code->AllocateArrayLabel().address(), |
61 jump1.TargetAddress()); | 65 jump1.TargetAddress()); |
62 EXPECT_EQ(StubCode::InvokeDartCodeLabel().address(), | 66 EXPECT_EQ(stub_code->InvokeDartCodeLabel().address(), |
63 jump2.TargetAddress()); | 67 jump2.TargetAddress()); |
64 } | 68 } |
65 | 69 |
66 | 70 |
67 #if defined(USING_SIMULATOR) | 71 #if defined(USING_SIMULATOR) |
68 ASSEMBLER_TEST_GENERATE(JumpARMv6, assembler) { | 72 ASSEMBLER_TEST_GENERATE(JumpARMv6, assembler) { |
69 // ARMv7 is the default. | 73 // ARMv7 is the default. |
| 74 StubCode* stub_code = Isolate::Current()->stub_code(); |
70 HostCPUFeatures::set_arm_version(ARMv6); | 75 HostCPUFeatures::set_arm_version(ARMv6); |
71 __ BranchPatchable(&StubCode::InvokeDartCodeLabel()); | 76 __ BranchPatchable(&stub_code->InvokeDartCodeLabel()); |
72 __ BranchPatchable(&StubCode::AllocateArrayLabel()); | 77 __ BranchPatchable(&stub_code->AllocateArrayLabel()); |
73 HostCPUFeatures::set_arm_version(ARMv7); | 78 HostCPUFeatures::set_arm_version(ARMv7); |
74 } | 79 } |
75 | 80 |
76 | 81 |
77 ASSEMBLER_TEST_RUN(JumpARMv6, test) { | 82 ASSEMBLER_TEST_RUN(JumpARMv6, test) { |
78 HostCPUFeatures::set_arm_version(ARMv6); | 83 HostCPUFeatures::set_arm_version(ARMv6); |
79 const Code& code = test->code(); | 84 const Code& code = test->code(); |
80 const Instructions& instrs = Instructions::Handle(code.instructions()); | 85 const Instructions& instrs = Instructions::Handle(code.instructions()); |
81 bool status = | 86 bool status = |
82 VirtualMemory::Protect(reinterpret_cast<void*>(instrs.EntryPoint()), | 87 VirtualMemory::Protect(reinterpret_cast<void*>(instrs.EntryPoint()), |
83 instrs.size(), | 88 instrs.size(), |
84 VirtualMemory::kReadWrite); | 89 VirtualMemory::kReadWrite); |
| 90 StubCode* stub_code = Isolate::Current()->stub_code(); |
85 EXPECT(status); | 91 EXPECT(status); |
86 JumpPattern jump1(test->entry(), test->code()); | 92 JumpPattern jump1(test->entry(), test->code()); |
87 EXPECT_EQ(StubCode::InvokeDartCodeLabel().address(), | 93 EXPECT_EQ(stub_code->InvokeDartCodeLabel().address(), |
88 jump1.TargetAddress()); | 94 jump1.TargetAddress()); |
89 JumpPattern jump2(test->entry() + jump1.pattern_length_in_bytes(), | 95 JumpPattern jump2(test->entry() + jump1.pattern_length_in_bytes(), |
90 test->code()); | 96 test->code()); |
91 EXPECT_EQ(StubCode::AllocateArrayLabel().address(), | 97 EXPECT_EQ(stub_code->AllocateArrayLabel().address(), |
92 jump2.TargetAddress()); | 98 jump2.TargetAddress()); |
93 uword target1 = jump1.TargetAddress(); | 99 uword target1 = jump1.TargetAddress(); |
94 uword target2 = jump2.TargetAddress(); | 100 uword target2 = jump2.TargetAddress(); |
95 jump1.SetTargetAddress(target2); | 101 jump1.SetTargetAddress(target2); |
96 jump2.SetTargetAddress(target1); | 102 jump2.SetTargetAddress(target1); |
97 EXPECT_EQ(StubCode::AllocateArrayLabel().address(), | 103 EXPECT_EQ(stub_code->AllocateArrayLabel().address(), |
98 jump1.TargetAddress()); | 104 jump1.TargetAddress()); |
99 EXPECT_EQ(StubCode::InvokeDartCodeLabel().address(), | 105 EXPECT_EQ(stub_code->InvokeDartCodeLabel().address(), |
100 jump2.TargetAddress()); | 106 jump2.TargetAddress()); |
101 HostCPUFeatures::set_arm_version(ARMv7); | 107 HostCPUFeatures::set_arm_version(ARMv7); |
102 } | 108 } |
103 #endif | 109 #endif |
104 | 110 |
105 } // namespace dart | 111 } // namespace dart |
106 | 112 |
107 #endif // defined TARGET_ARCH_ARM | 113 #endif // defined TARGET_ARCH_ARM |
OLD | NEW |