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" // Needed here to get TARGET_ARCH_X64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. |
6 #if defined(TARGET_ARCH_X64) | 6 #if defined(TARGET_ARCH_X64) |
7 | 7 |
8 #include "vm/cpu.h" | 8 #include "vm/cpu.h" |
9 #include "vm/instructions.h" | 9 #include "vm/instructions.h" |
10 #include "vm/object.h" | 10 #include "vm/object.h" |
11 | 11 |
12 namespace dart { | 12 namespace dart { |
13 | 13 |
14 intptr_t InstructionPattern::IndexFromPPLoad(uword start) { | 14 intptr_t InstructionPattern::IndexFromPPLoad(uword start) { |
15 int32_t offset = *reinterpret_cast<int32_t*>(start); | 15 int32_t offset = *reinterpret_cast<int32_t*>(start); |
16 offset += kHeapObjectTag; | 16 return ObjectPool::IndexFromOffset(offset); |
17 return (offset - Array::data_offset()) / kWordSize; | |
18 } | 17 } |
19 | 18 |
20 | 19 |
21 intptr_t InstructionPattern::OffsetFromPPIndex(intptr_t index) { | 20 intptr_t InstructionPattern::OffsetFromPPIndex(intptr_t index) { |
22 intptr_t offset = Array::element_offset(index); | 21 intptr_t offset = ObjectPool::element_offset(index); |
23 return offset - kHeapObjectTag; | 22 return offset - kHeapObjectTag; |
24 } | 23 } |
25 | 24 |
26 | 25 |
27 bool InstructionPattern::TestBytesWith(const int* data, int num_bytes) const { | 26 bool InstructionPattern::TestBytesWith(const int* data, int num_bytes) const { |
28 ASSERT(data != NULL); | 27 ASSERT(data != NULL); |
29 const uint8_t* byte_array = reinterpret_cast<const uint8_t*>(start_); | 28 const uint8_t* byte_array = reinterpret_cast<const uint8_t*>(start_); |
30 for (int i = 0; i < num_bytes; i++) { | 29 for (int i = 0; i < num_bytes; i++) { |
31 // Skip comparison for data[i] < 0. | 30 // Skip comparison for data[i] < 0. |
32 if ((data[i] >= 0) && (byte_array[i] != (0xFF & data[i]))) { | 31 if ((data[i] >= 0) && (byte_array[i] != (0xFF & data[i]))) { |
33 return false; | 32 return false; |
34 } | 33 } |
35 } | 34 } |
36 return true; | 35 return true; |
37 } | 36 } |
38 | 37 |
39 | 38 |
40 uword JumpPattern::TargetAddress() const { | 39 uword JumpPattern::TargetAddress() const { |
41 ASSERT(IsValid()); | 40 ASSERT(IsValid()); |
42 int index = InstructionPattern::IndexFromPPLoad(start() + 3); | 41 int index = InstructionPattern::IndexFromPPLoad(start() + 3); |
43 return reinterpret_cast<uword>(object_pool_.At(index)); | 42 return object_pool_.RawValueAt(index); |
44 } | 43 } |
45 | 44 |
46 | 45 |
47 void JumpPattern::SetTargetAddress(uword target) const { | 46 void JumpPattern::SetTargetAddress(uword target) const { |
48 ASSERT(IsValid()); | 47 ASSERT(IsValid()); |
49 int index = InstructionPattern::IndexFromPPLoad(start() + 3); | 48 int index = InstructionPattern::IndexFromPPLoad(start() + 3); |
50 const Smi& smi = Smi::Handle(reinterpret_cast<RawSmi*>(target)); | 49 object_pool_.SetRawValueAt(index, target); |
51 object_pool_.SetAt(index, smi); | |
52 // No need to flush the instruction cache, since the code is not modified. | 50 // No need to flush the instruction cache, since the code is not modified. |
53 } | 51 } |
54 | 52 |
55 | 53 |
56 const int* JumpPattern::pattern() const { | 54 const int* JumpPattern::pattern() const { |
57 // 07: 41 ff a7 imm32 jmpq [reg + off] | 55 // 07: 41 ff a7 imm32 jmpq [reg + off] |
58 static const int kJumpPattern[kLengthInBytes] = | 56 static const int kJumpPattern[kLengthInBytes] = |
59 {0x41, 0xFF, -1, -1, -1, -1, -1}; | 57 {0x41, 0xFF, -1, -1, -1, -1, -1}; |
60 return kJumpPattern; | 58 return kJumpPattern; |
61 } | 59 } |
(...skipping 26 matching lines...) Expand all Loading... |
88 | 86 |
89 | 87 |
90 const int* SetFramePointerPattern::pattern() const { | 88 const int* SetFramePointerPattern::pattern() const { |
91 static const int kFramePointerPattern[kLengthInBytes] = { 0x48, 0x89, 0xe5 }; | 89 static const int kFramePointerPattern[kLengthInBytes] = { 0x48, 0x89, 0xe5 }; |
92 return kFramePointerPattern; | 90 return kFramePointerPattern; |
93 } | 91 } |
94 | 92 |
95 } // namespace dart | 93 } // namespace dart |
96 | 94 |
97 #endif // defined TARGET_ARCH_X64 | 95 #endif // defined TARGET_ARCH_X64 |
OLD | NEW |