OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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_IA32) | 6 #if defined(TARGET_ARCH_IA32) |
7 | 7 |
8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
9 #include "vm/instructions.h" | 9 #include "vm/instructions.h" |
| 10 #include "vm/object.h" |
10 #include "vm/stub_code.h" | 11 #include "vm/stub_code.h" |
11 #include "vm/unit_test.h" | 12 #include "vm/unit_test.h" |
| 13 #include "vm/virtual_memory.h" |
12 | 14 |
13 namespace dart { | 15 namespace dart { |
14 | 16 |
15 #define __ assembler-> | 17 #define __ assembler-> |
16 | 18 |
17 ASSEMBLER_TEST_GENERATE(Call, assembler) { | 19 ASSEMBLER_TEST_GENERATE(Call, assembler) { |
18 __ call(&StubCode::InstanceFunctionLookupLabel()); | 20 __ call(&StubCode::InstanceFunctionLookupLabel()); |
19 __ ret(); | 21 __ ret(); |
20 } | 22 } |
21 | 23 |
22 | 24 |
23 ASSEMBLER_TEST_RUN(Call, test) { | 25 ASSEMBLER_TEST_RUN(Call, test) { |
24 CallPattern call(test->entry()); | 26 CallPattern call(test->entry()); |
25 EXPECT_EQ(StubCode::InstanceFunctionLookupLabel().address(), | 27 EXPECT_EQ(StubCode::InstanceFunctionLookupLabel().address(), |
26 call.TargetAddress()); | 28 call.TargetAddress()); |
27 } | 29 } |
28 | 30 |
29 | 31 |
30 ASSEMBLER_TEST_GENERATE(Jump, assembler) { | 32 ASSEMBLER_TEST_GENERATE(Jump, assembler) { |
31 __ jmp(&StubCode::InstanceFunctionLookupLabel()); | 33 __ jmp(&StubCode::InstanceFunctionLookupLabel()); |
32 __ jmp(&StubCode::AllocateArrayLabel()); | 34 __ jmp(&StubCode::AllocateArrayLabel()); |
33 __ ret(); | 35 __ ret(); |
34 } | 36 } |
35 | 37 |
36 | 38 |
37 ASSEMBLER_TEST_RUN(Jump, test) { | 39 ASSEMBLER_TEST_RUN(Jump, test) { |
| 40 const Code& code = test->code(); |
| 41 const Instructions& instrs = Instructions::Handle(code.instructions()); |
| 42 bool status = |
| 43 VirtualMemory::Protect(reinterpret_cast<void*>(instrs.EntryPoint()), |
| 44 instrs.size(), |
| 45 VirtualMemory::kReadWriteExecute); |
| 46 EXPECT(status); |
38 JumpPattern jump1(test->entry(), test->code()); | 47 JumpPattern jump1(test->entry(), test->code()); |
39 EXPECT_EQ(StubCode::InstanceFunctionLookupLabel().address(), | 48 EXPECT_EQ(StubCode::InstanceFunctionLookupLabel().address(), |
40 jump1.TargetAddress()); | 49 jump1.TargetAddress()); |
41 JumpPattern jump2(test->entry() + jump1.pattern_length_in_bytes(), | 50 JumpPattern jump2(test->entry() + jump1.pattern_length_in_bytes(), |
42 test->code()); | 51 test->code()); |
43 EXPECT_EQ(StubCode::AllocateArrayLabel().address(), | 52 EXPECT_EQ(StubCode::AllocateArrayLabel().address(), |
44 jump2.TargetAddress()); | 53 jump2.TargetAddress()); |
45 uword target1 = jump1.TargetAddress(); | 54 uword target1 = jump1.TargetAddress(); |
46 uword target2 = jump2.TargetAddress(); | 55 uword target2 = jump2.TargetAddress(); |
47 jump1.SetTargetAddress(target2); | 56 jump1.SetTargetAddress(target2); |
48 jump2.SetTargetAddress(target1); | 57 jump2.SetTargetAddress(target1); |
49 EXPECT_EQ(StubCode::AllocateArrayLabel().address(), | 58 EXPECT_EQ(StubCode::AllocateArrayLabel().address(), |
50 jump1.TargetAddress()); | 59 jump1.TargetAddress()); |
51 EXPECT_EQ(StubCode::InstanceFunctionLookupLabel().address(), | 60 EXPECT_EQ(StubCode::InstanceFunctionLookupLabel().address(), |
52 jump2.TargetAddress()); | 61 jump2.TargetAddress()); |
53 } | 62 } |
54 | 63 |
55 } // namespace dart | 64 } // namespace dart |
56 | 65 |
57 #endif // defined TARGET_ARCH_IA32 | 66 #endif // defined TARGET_ARCH_IA32 |
OLD | NEW |