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 // Classes that describe assembly patterns as used by inline caches. | 4 // Classes that describe assembly patterns as used by inline caches. |
5 | 5 |
6 #ifndef RUNTIME_VM_INSTRUCTIONS_X64_H_ | 6 #ifndef RUNTIME_VM_INSTRUCTIONS_X64_H_ |
7 #define RUNTIME_VM_INSTRUCTIONS_X64_H_ | 7 #define RUNTIME_VM_INSTRUCTIONS_X64_H_ |
8 | 8 |
9 #ifndef RUNTIME_VM_INSTRUCTIONS_H_ | 9 #ifndef RUNTIME_VM_INSTRUCTIONS_H_ |
10 #error Do not include instructions_ia32.h directly; use instructions.h instead. | 10 #error Do not include instructions_ia32.h directly; use instructions.h instead. |
11 #endif | 11 #endif |
12 | 12 |
13 #include "vm/allocation.h" | 13 #include "vm/allocation.h" |
14 #include "vm/object.h" | 14 #include "vm/object.h" |
15 | 15 |
16 namespace dart { | 16 namespace dart { |
17 | 17 |
18 // Forward declarations. | 18 // Forward declarations. |
19 class RawClass; | 19 class RawClass; |
20 class Immediate; | 20 class Immediate; |
21 class RawObject; | 21 class RawObject; |
22 | 22 |
23 | 23 |
24 intptr_t IndexFromPPLoad(uword start); | 24 intptr_t IndexFromPPLoad(uword start); |
25 intptr_t IndexFromPPLoadDisp8(uword start); | 25 intptr_t IndexFromPPLoadDisp8(uword start); |
26 | 26 |
27 | 27 |
28 // Template class for all instruction pattern classes. | 28 // Template class for all instruction pattern classes. |
29 // P has to specify a static pattern and a pattern length method. | 29 // P has to specify a static pattern and a pattern length method. |
30 template<class P> class InstructionPattern : public ValueObject { | 30 template <class P> |
| 31 class InstructionPattern : public ValueObject { |
31 public: | 32 public: |
32 explicit InstructionPattern(uword pc) : start_(pc) { | 33 explicit InstructionPattern(uword pc) : start_(pc) { ASSERT(pc != 0); } |
33 ASSERT(pc != 0); | |
34 } | |
35 | 34 |
36 // Call to check if the instruction pattern at 'pc' match the instruction. | 35 // Call to check if the instruction pattern at 'pc' match the instruction. |
37 // 'P::pattern()' returns the expected byte pattern in form of an integer | 36 // 'P::pattern()' returns the expected byte pattern in form of an integer |
38 // array with length of 'P::pattern_length_in_bytes()'. A '-1' element means | 37 // array with length of 'P::pattern_length_in_bytes()'. A '-1' element means |
39 // 'any byte'. | 38 // 'any byte'. |
40 bool IsValid() const { | 39 bool IsValid() const { |
41 return TestBytesWith(P::pattern(), P::pattern_length_in_bytes()); | 40 return TestBytesWith(P::pattern(), P::pattern_length_in_bytes()); |
42 } | 41 } |
43 | 42 |
44 protected: | 43 protected: |
(...skipping 19 matching lines...) Expand all Loading... |
64 | 63 |
65 DISALLOW_COPY_AND_ASSIGN(InstructionPattern); | 64 DISALLOW_COPY_AND_ASSIGN(InstructionPattern); |
66 }; | 65 }; |
67 | 66 |
68 | 67 |
69 class ReturnPattern : public InstructionPattern<ReturnPattern> { | 68 class ReturnPattern : public InstructionPattern<ReturnPattern> { |
70 public: | 69 public: |
71 explicit ReturnPattern(uword pc) : InstructionPattern(pc) {} | 70 explicit ReturnPattern(uword pc) : InstructionPattern(pc) {} |
72 | 71 |
73 static const int* pattern() { | 72 static const int* pattern() { |
74 static const int kReturnPattern[kLengthInBytes] = { 0xC3 }; | 73 static const int kReturnPattern[kLengthInBytes] = {0xC3}; |
75 return kReturnPattern; | 74 return kReturnPattern; |
76 } | 75 } |
77 | 76 |
78 static int pattern_length_in_bytes() { return kLengthInBytes; } | 77 static int pattern_length_in_bytes() { return kLengthInBytes; } |
79 | 78 |
80 private: | 79 private: |
81 static const int kLengthInBytes = 1; | 80 static const int kLengthInBytes = 1; |
82 }; | 81 }; |
83 | 82 |
84 | 83 |
85 // push rbp | 84 // push rbp |
86 // mov rbp, rsp | 85 // mov rbp, rsp |
87 class ProloguePattern : public InstructionPattern<ProloguePattern> { | 86 class ProloguePattern : public InstructionPattern<ProloguePattern> { |
88 public: | 87 public: |
89 explicit ProloguePattern(uword pc) : InstructionPattern(pc) {} | 88 explicit ProloguePattern(uword pc) : InstructionPattern(pc) {} |
90 | 89 |
91 static const int* pattern() { | 90 static const int* pattern() { |
92 static const int kProloguePattern[kLengthInBytes] = | 91 static const int kProloguePattern[kLengthInBytes] = {0x55, 0x48, 0x89, |
93 { 0x55, 0x48, 0x89, 0xe5 }; | 92 0xe5}; |
94 return kProloguePattern; | 93 return kProloguePattern; |
95 } | 94 } |
96 | 95 |
97 static int pattern_length_in_bytes() { return kLengthInBytes; } | 96 static int pattern_length_in_bytes() { return kLengthInBytes; } |
98 | 97 |
99 private: | 98 private: |
100 static const int kLengthInBytes = 4; | 99 static const int kLengthInBytes = 4; |
101 }; | 100 }; |
102 | 101 |
103 | 102 |
104 // mov rbp, rsp | 103 // mov rbp, rsp |
105 class SetFramePointerPattern : | 104 class SetFramePointerPattern |
106 public InstructionPattern<SetFramePointerPattern> { | 105 : public InstructionPattern<SetFramePointerPattern> { |
107 public: | 106 public: |
108 explicit SetFramePointerPattern(uword pc) : InstructionPattern(pc) {} | 107 explicit SetFramePointerPattern(uword pc) : InstructionPattern(pc) {} |
109 | 108 |
110 static const int* pattern() { | 109 static const int* pattern() { |
111 static const int kFramePointerPattern[kLengthInBytes] = | 110 static const int kFramePointerPattern[kLengthInBytes] = {0x48, 0x89, 0xe5}; |
112 { 0x48, 0x89, 0xe5 }; | |
113 return kFramePointerPattern; | 111 return kFramePointerPattern; |
114 } | 112 } |
115 | 113 |
116 static int pattern_length_in_bytes() { return kLengthInBytes; } | 114 static int pattern_length_in_bytes() { return kLengthInBytes; } |
117 | 115 |
118 private: | 116 private: |
119 static const int kLengthInBytes = 3; | 117 static const int kLengthInBytes = 3; |
120 }; | 118 }; |
121 | 119 |
122 } // namespace dart | 120 } // namespace dart |
123 | 121 |
124 #endif // RUNTIME_VM_INSTRUCTIONS_X64_H_ | 122 #endif // RUNTIME_VM_INSTRUCTIONS_X64_H_ |
OLD | NEW |