| 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" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 static intptr_t prologue_code_size = -1; | 32 static intptr_t prologue_code_size = -1; |
| 33 | 33 |
| 34 | 34 |
| 35 ASSEMBLER_TEST_GENERATE(Jump, assembler) { | 35 ASSEMBLER_TEST_GENERATE(Jump, assembler) { |
| 36 ASSERT(assembler->CodeSize() == 0); | 36 ASSERT(assembler->CodeSize() == 0); |
| 37 __ pushq(PP); | 37 __ pushq(PP); |
| 38 __ LoadPoolPointer(PP); | 38 __ LoadPoolPointer(PP); |
| 39 prologue_code_size = assembler->CodeSize(); | 39 prologue_code_size = assembler->CodeSize(); |
| 40 StubCode* stub_code = Isolate::Current()->stub_code(); | 40 StubCode* stub_code = Isolate::Current()->stub_code(); |
| 41 __ JmpPatchable(&stub_code->InvokeDartCodeLabel(), PP); | 41 __ JmpPatchable(&stub_code->InvokeDartCodeLabel(), PP); |
| 42 __ JmpPatchable(&stub_code->AllocateArrayLabel(), PP); | 42 const Code& array_stub = Code::Handle(stub_code->GetAllocateArrayStub()); |
| 43 const ExternalLabel array_label(array_stub.EntryPoint()); |
| 44 __ JmpPatchable(&array_label, PP); |
| 43 __ popq(PP); | 45 __ popq(PP); |
| 44 __ ret(); | 46 __ ret(); |
| 45 } | 47 } |
| 46 | 48 |
| 47 | 49 |
| 48 ASSEMBLER_TEST_RUN(Jump, test) { | 50 ASSEMBLER_TEST_RUN(Jump, test) { |
| 49 ASSERT(prologue_code_size != -1); | 51 ASSERT(prologue_code_size != -1); |
| 50 const Code& code = test->code(); | 52 const Code& code = test->code(); |
| 51 const Instructions& instrs = Instructions::Handle(code.instructions()); | 53 const Instructions& instrs = Instructions::Handle(code.instructions()); |
| 52 StubCode* stub_code = Isolate::Current()->stub_code(); | 54 StubCode* stub_code = Isolate::Current()->stub_code(); |
| 53 bool status = | 55 bool status = |
| 54 VirtualMemory::Protect(reinterpret_cast<void*>(instrs.EntryPoint()), | 56 VirtualMemory::Protect(reinterpret_cast<void*>(instrs.EntryPoint()), |
| 55 instrs.size(), | 57 instrs.size(), |
| 56 VirtualMemory::kReadWrite); | 58 VirtualMemory::kReadWrite); |
| 57 EXPECT(status); | 59 EXPECT(status); |
| 58 JumpPattern jump1(test->entry() + prologue_code_size, test->code()); | 60 JumpPattern jump1(test->entry() + prologue_code_size, test->code()); |
| 59 jump1.IsValid(); | 61 jump1.IsValid(); |
| 60 EXPECT_EQ(stub_code->InvokeDartCodeLabel().address(), | 62 EXPECT_EQ(stub_code->InvokeDartCodeLabel().address(), |
| 61 jump1.TargetAddress()); | 63 jump1.TargetAddress()); |
| 62 JumpPattern jump2((test->entry() + | 64 JumpPattern jump2((test->entry() + |
| 63 jump1.pattern_length_in_bytes() + prologue_code_size), | 65 jump1.pattern_length_in_bytes() + prologue_code_size), |
| 64 test->code()); | 66 test->code()); |
| 65 EXPECT_EQ(stub_code->AllocateArrayLabel().address(), | 67 const Code& array_stub = Code::Handle(stub_code->GetAllocateArrayStub()); |
| 66 jump2.TargetAddress()); | 68 EXPECT_EQ(array_stub.EntryPoint(), jump2.TargetAddress()); |
| 67 uword target1 = jump1.TargetAddress(); | 69 uword target1 = jump1.TargetAddress(); |
| 68 uword target2 = jump2.TargetAddress(); | 70 uword target2 = jump2.TargetAddress(); |
| 69 jump1.SetTargetAddress(target2); | 71 jump1.SetTargetAddress(target2); |
| 70 jump2.SetTargetAddress(target1); | 72 jump2.SetTargetAddress(target1); |
| 71 EXPECT_EQ(stub_code->AllocateArrayLabel().address(), | 73 EXPECT_EQ(array_stub.EntryPoint(), jump1.TargetAddress()); |
| 72 jump1.TargetAddress()); | |
| 73 EXPECT_EQ(stub_code->InvokeDartCodeLabel().address(), | 74 EXPECT_EQ(stub_code->InvokeDartCodeLabel().address(), |
| 74 jump2.TargetAddress()); | 75 jump2.TargetAddress()); |
| 75 } | 76 } |
| 76 | 77 |
| 77 } // namespace dart | 78 } // namespace dart |
| 78 | 79 |
| 79 #endif // defined TARGET_ARCH_X64 | 80 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |