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 VM_INSTRUCTIONS_X64_H_ | 6 #ifndef VM_INSTRUCTIONS_X64_H_ |
7 #define VM_INSTRUCTIONS_X64_H_ | 7 #define VM_INSTRUCTIONS_X64_H_ |
8 | 8 |
9 #ifndef VM_INSTRUCTIONS_H_ | 9 #ifndef 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 | 15 |
15 namespace dart { | 16 namespace dart { |
16 | 17 |
17 // Forward declarations. | 18 // Forward declarations. |
18 class RawClass; | 19 class RawClass; |
19 class Immediate; | 20 class Immediate; |
20 class RawObject; | 21 class RawObject; |
21 | 22 |
22 // Abstract class for all instruction pattern classes. | 23 // Abstract class for all instruction pattern classes. |
23 class InstructionPattern : public ValueObject { | 24 class InstructionPattern : public ValueObject { |
24 public: | 25 public: |
25 explicit InstructionPattern(uword pc) : start_(pc) { | 26 explicit InstructionPattern(uword pc) : start_(pc) { |
26 ASSERT(pc != 0); | 27 ASSERT(pc != 0); |
27 } | 28 } |
28 virtual ~InstructionPattern() {} | 29 virtual ~InstructionPattern() {} |
29 | 30 |
30 // Call to check if the instruction pattern at 'pc' match the instruction. | 31 // Call to check if the instruction pattern at 'pc' match the instruction. |
31 virtual bool IsValid() const { | 32 virtual bool IsValid() const { |
32 return TestBytesWith(pattern(), pattern_length_in_bytes()); | 33 return TestBytesWith(pattern(), pattern_length_in_bytes()); |
33 } | 34 } |
34 | 35 |
35 // 'pattern' returns the expected byte pattern in form of an integer array | 36 // 'pattern' returns the expected byte pattern in form of an integer array |
36 // with length of 'pattern_length_in_bytes'. A '-1' element means 'any byte'. | 37 // with length of 'pattern_length_in_bytes'. A '-1' element means 'any byte'. |
37 virtual const int* pattern() const = 0; | 38 virtual const int* pattern() const = 0; |
38 virtual int pattern_length_in_bytes() const = 0; | 39 virtual int pattern_length_in_bytes() const = 0; |
39 | 40 |
| 41 static intptr_t IndexFromPPLoad(uword start); |
| 42 |
40 protected: | 43 protected: |
41 uword start() const { return start_; } | 44 uword start() const { return start_; } |
42 | 45 |
43 private: | 46 private: |
44 // Returns true if the 'num_bytes' bytes at 'start_' correspond to | 47 // Returns true if the 'num_bytes' bytes at 'start_' correspond to |
45 // array of integers 'data'. 'data' elements are either a byte or -1, which | 48 // array of integers 'data'. 'data' elements are either a byte or -1, which |
46 // represents any byte. | 49 // represents any byte. |
47 bool TestBytesWith(const int* data, int num_bytes) const; | 50 bool TestBytesWith(const int* data, int num_bytes) const; |
48 | 51 |
49 const uword start_; | 52 const uword start_; |
50 | 53 |
51 DISALLOW_COPY_AND_ASSIGN(InstructionPattern); | 54 DISALLOW_COPY_AND_ASSIGN(InstructionPattern); |
52 }; | 55 }; |
53 | 56 |
54 | 57 |
55 class CallOrJumpPattern : public InstructionPattern { | 58 class CallPattern : public InstructionPattern { |
56 public: | 59 public: |
57 virtual int pattern_length_in_bytes() const { | 60 CallPattern(uword pc, const Code& code) |
| 61 : InstructionPattern(pc), |
| 62 code_(code) {} |
| 63 static int InstructionLength() { |
58 return kLengthInBytes; | 64 return kLengthInBytes; |
59 } | 65 } |
60 uword TargetAddress() const; | 66 uword TargetAddress() const; |
61 void SetTargetAddress(uword new_target) const; | 67 void SetTargetAddress(uword new_target) const; |
62 | 68 virtual int pattern_length_in_bytes() const { |
63 protected: | |
64 explicit CallOrJumpPattern(uword pc) : InstructionPattern(pc) {} | |
65 static const int kLengthInBytes = 13; | |
66 | |
67 private: | |
68 DISALLOW_COPY_AND_ASSIGN(CallOrJumpPattern); | |
69 }; | |
70 | |
71 | |
72 class CallPattern : public CallOrJumpPattern { | |
73 public: | |
74 explicit CallPattern(uword pc) : CallOrJumpPattern(pc) {} | |
75 static int InstructionLength() { | |
76 return kLengthInBytes; | 69 return kLengthInBytes; |
77 } | 70 } |
78 | 71 |
79 private: | 72 private: |
| 73 static const int kLengthInBytes = 13; |
80 virtual const int* pattern() const; | 74 virtual const int* pattern() const; |
| 75 const Code& code_; |
81 | 76 |
82 DISALLOW_COPY_AND_ASSIGN(CallPattern); | 77 DISALLOW_COPY_AND_ASSIGN(CallPattern); |
83 }; | 78 }; |
84 | 79 |
85 | 80 |
86 class JumpPattern : public CallOrJumpPattern { | 81 class JumpPattern : public InstructionPattern { |
87 public: | 82 public: |
88 explicit JumpPattern(uword pc) : CallOrJumpPattern(pc) {} | 83 JumpPattern(uword pc, const Code& code) |
| 84 : InstructionPattern(pc), |
| 85 object_pool_(Array::Handle(code.ObjectPool())) {} |
89 static int InstructionLength() { | 86 static int InstructionLength() { |
90 return kLengthInBytes; | 87 return kLengthInBytes; |
91 } | 88 } |
| 89 uword TargetAddress() const; |
| 90 void SetTargetAddress(uword new_target) const; |
| 91 virtual int pattern_length_in_bytes() const { |
| 92 return kLengthInBytes; |
| 93 } |
92 | 94 |
93 private: | 95 private: |
| 96 static const int kLengthInBytes = 10; |
94 virtual const int* pattern() const; | 97 virtual const int* pattern() const; |
| 98 const Array& object_pool_; |
95 | 99 |
96 DISALLOW_COPY_AND_ASSIGN(JumpPattern); | 100 DISALLOW_COPY_AND_ASSIGN(JumpPattern); |
97 }; | 101 }; |
98 | 102 |
99 | 103 |
100 // 5 byte call instruction. | 104 // 5 byte call instruction. |
101 class ShortCallPattern : public InstructionPattern { | 105 class ShortCallPattern : public InstructionPattern { |
102 public: | 106 public: |
103 explicit ShortCallPattern(uword pc) : InstructionPattern(pc) {} | 107 explicit ShortCallPattern(uword pc) : InstructionPattern(pc) {} |
104 static int InstructionLength() { | 108 static int InstructionLength() { |
(...skipping 10 matching lines...) Expand all Loading... |
115 static const int kLengthInBytes = 5; | 119 static const int kLengthInBytes = 5; |
116 virtual const int* pattern() const; | 120 virtual const int* pattern() const; |
117 | 121 |
118 DISALLOW_COPY_AND_ASSIGN(ShortCallPattern); | 122 DISALLOW_COPY_AND_ASSIGN(ShortCallPattern); |
119 }; | 123 }; |
120 | 124 |
121 | 125 |
122 } // namespace dart | 126 } // namespace dart |
123 | 127 |
124 #endif // VM_INSTRUCTIONS_X64_H_ | 128 #endif // VM_INSTRUCTIONS_X64_H_ |
OLD | NEW |