| 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_X64) | 6 #if defined(TARGET_ARCH_X64) |
| 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/stub_code.h" | 10 #include "vm/stub_code.h" |
| 11 #include "vm/unit_test.h" | 11 #include "vm/unit_test.h" |
| 12 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 | 14 |
| 15 #define __ assembler-> | 15 #define __ assembler-> |
| 16 | 16 |
| 17 ASSEMBLER_TEST_GENERATE(Call, assembler) { | 17 ASSEMBLER_TEST_GENERATE(Call, assembler) { |
| 18 StubCode* stub_code = Isolate::Current()->stub_code(); | 18 __ call(&StubCode::InvokeDartCodeLabel()); |
| 19 __ call(&stub_code->InvokeDartCodeLabel()); | |
| 20 __ ret(); | 19 __ ret(); |
| 21 } | 20 } |
| 22 | 21 |
| 23 | 22 |
| 24 static intptr_t prologue_code_size = -1; | 23 static intptr_t prologue_code_size = -1; |
| 25 | 24 |
| 26 | 25 |
| 27 ASSEMBLER_TEST_GENERATE(Jump, assembler) { | 26 ASSEMBLER_TEST_GENERATE(Jump, assembler) { |
| 28 ASSERT(assembler->CodeSize() == 0); | 27 ASSERT(assembler->CodeSize() == 0); |
| 29 __ pushq(PP); | 28 __ pushq(PP); |
| 30 __ LoadPoolPointer(PP); | 29 __ LoadPoolPointer(PP); |
| 31 prologue_code_size = assembler->CodeSize(); | 30 prologue_code_size = assembler->CodeSize(); |
| 32 StubCode* stub_code = Isolate::Current()->stub_code(); | 31 __ JmpPatchable(&StubCode::InvokeDartCodeLabel(), PP); |
| 33 __ JmpPatchable(&stub_code->InvokeDartCodeLabel(), PP); | 32 const ExternalLabel array_label(StubCode::AllocateArrayEntryPoint()); |
| 34 const Code& array_stub = Code::Handle(stub_code->GetAllocateArrayStub()); | |
| 35 const ExternalLabel array_label(array_stub.EntryPoint()); | |
| 36 __ JmpPatchable(&array_label, PP); | 33 __ JmpPatchable(&array_label, PP); |
| 37 __ popq(PP); | 34 __ popq(PP); |
| 38 __ ret(); | 35 __ ret(); |
| 39 } | 36 } |
| 40 | 37 |
| 41 | 38 |
| 42 ASSEMBLER_TEST_RUN(Jump, test) { | 39 ASSEMBLER_TEST_RUN(Jump, test) { |
| 43 ASSERT(prologue_code_size != -1); | 40 ASSERT(prologue_code_size != -1); |
| 44 const Code& code = test->code(); | 41 const Code& code = test->code(); |
| 45 const Instructions& instrs = Instructions::Handle(code.instructions()); | 42 const Instructions& instrs = Instructions::Handle(code.instructions()); |
| 46 StubCode* stub_code = Isolate::Current()->stub_code(); | |
| 47 bool status = | 43 bool status = |
| 48 VirtualMemory::Protect(reinterpret_cast<void*>(instrs.EntryPoint()), | 44 VirtualMemory::Protect(reinterpret_cast<void*>(instrs.EntryPoint()), |
| 49 instrs.size(), | 45 instrs.size(), |
| 50 VirtualMemory::kReadWrite); | 46 VirtualMemory::kReadWrite); |
| 51 EXPECT(status); | 47 EXPECT(status); |
| 52 JumpPattern jump1(test->entry() + prologue_code_size, test->code()); | 48 JumpPattern jump1(test->entry() + prologue_code_size, test->code()); |
| 53 jump1.IsValid(); | 49 jump1.IsValid(); |
| 54 EXPECT_EQ(stub_code->InvokeDartCodeLabel().address(), | 50 EXPECT_EQ(StubCode::InvokeDartCodeLabel().address(), |
| 55 jump1.TargetAddress()); | 51 jump1.TargetAddress()); |
| 56 JumpPattern jump2((test->entry() + | 52 JumpPattern jump2((test->entry() + |
| 57 jump1.pattern_length_in_bytes() + prologue_code_size), | 53 jump1.pattern_length_in_bytes() + prologue_code_size), |
| 58 test->code()); | 54 test->code()); |
| 59 const Code& array_stub = Code::Handle(stub_code->GetAllocateArrayStub()); | 55 const Code& array_stub = |
| 56 Code::Handle(StubCode::AllocateArray_entry()->code()); |
| 60 EXPECT_EQ(array_stub.EntryPoint(), jump2.TargetAddress()); | 57 EXPECT_EQ(array_stub.EntryPoint(), jump2.TargetAddress()); |
| 61 uword target1 = jump1.TargetAddress(); | 58 uword target1 = jump1.TargetAddress(); |
| 62 uword target2 = jump2.TargetAddress(); | 59 uword target2 = jump2.TargetAddress(); |
| 63 jump1.SetTargetAddress(target2); | 60 jump1.SetTargetAddress(target2); |
| 64 jump2.SetTargetAddress(target1); | 61 jump2.SetTargetAddress(target1); |
| 65 EXPECT_EQ(array_stub.EntryPoint(), jump1.TargetAddress()); | 62 EXPECT_EQ(array_stub.EntryPoint(), jump1.TargetAddress()); |
| 66 EXPECT_EQ(stub_code->InvokeDartCodeLabel().address(), | 63 EXPECT_EQ(StubCode::InvokeDartCodeLabel().address(), |
| 67 jump2.TargetAddress()); | 64 jump2.TargetAddress()); |
| 68 } | 65 } |
| 69 | 66 |
| 70 } // namespace dart | 67 } // namespace dart |
| 71 | 68 |
| 72 #endif // defined TARGET_ARCH_X64 | 69 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |