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 // Class for patching compiled code. | 4 // Class for patching compiled code. |
5 | 5 |
6 #ifndef VM_CODE_PATCHER_H_ | 6 #ifndef VM_CODE_PATCHER_H_ |
7 #define VM_CODE_PATCHER_H_ | 7 #define VM_CODE_PATCHER_H_ |
8 | 8 |
9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
10 #include "vm/native_entry.h" | 10 #include "vm/native_entry.h" |
11 | 11 |
12 namespace dart { | 12 namespace dart { |
13 | 13 |
14 // Forward declaration. | 14 // Forward declaration. |
15 class Array; | 15 class Array; |
16 class Code; | 16 class Code; |
17 class ExternalLabel; | 17 class ExternalLabel; |
18 class Function; | 18 class Function; |
19 class ICData; | 19 class ICData; |
20 class RawArray; | 20 class RawArray; |
21 class RawCode; | |
22 class RawFunction; | 21 class RawFunction; |
23 class RawICData; | 22 class RawICData; |
24 class RawObject; | 23 class RawObject; |
25 class String; | 24 class String; |
26 | 25 |
27 | 26 |
28 // Stack-allocated class to create a scope where the specified region | 27 // Stack-allocated class to create a scope where the specified region |
29 // [address, addresss + size] has write access enabled. This is used | 28 // [address, addresss + size] has write access enabled. This is used |
30 // when patching generated code. Access is reset to read-execute in | 29 // when patching generated code. Access is reset to read-execute in |
31 // the destructor of this scope. | 30 // the destructor of this scope. |
32 class WritableInstructionsScope : public ValueObject { | 31 class WritableInstructionsScope : public ValueObject { |
33 public: | 32 public: |
34 WritableInstructionsScope(uword address, intptr_t size); | 33 WritableInstructionsScope(uword address, intptr_t size); |
35 ~WritableInstructionsScope(); | 34 ~WritableInstructionsScope(); |
36 | 35 |
37 private: | 36 private: |
38 const uword address_; | 37 const uword address_; |
39 const intptr_t size_; | 38 const intptr_t size_; |
40 }; | 39 }; |
41 | 40 |
42 | 41 |
43 class CodePatcher : public AllStatic { | 42 class CodePatcher : public AllStatic { |
44 public: | 43 public: |
45 // Dart static calls have a distinct, machine-dependent code pattern. | 44 // Dart static calls have a distinct, machine-dependent code pattern. |
46 | 45 |
47 // Patch static call before return_address in given code to the new target. | 46 // Patch static call before return_address in given code to the new target. |
48 static void PatchStaticCallAt(uword return_address, | 47 static void PatchStaticCallAt(uword return_address, |
49 const Code& code, | 48 const Code& code, |
50 const Code& new_target); | 49 uword new_target_address); |
| 50 |
| 51 // Patch instance call before return_address in given code to the new target. |
| 52 static void PatchInstanceCallAt(uword return_address, |
| 53 const Code& code, |
| 54 uword new_target_address); |
51 | 55 |
52 // Patch entry point with a jump as specified in the code's patch region. | 56 // Patch entry point with a jump as specified in the code's patch region. |
53 static void PatchEntry(const Code& code, const Code& new_code); | 57 static void PatchEntry(const Code& code); |
54 | 58 |
55 // Restore entry point with original code (i.e., before patching). | 59 // Restore entry point with original code (i.e., before patching). |
56 static void RestoreEntry(const Code& code); | 60 static void RestoreEntry(const Code& code); |
57 | 61 |
58 // Has the entry been patched? | 62 // Has the entry been patched? |
59 static bool IsEntryPatched(const Code& code); | 63 static bool IsEntryPatched(const Code& code); |
60 | 64 |
| 65 // Returns true if the code can be patched with a jump at beginning (checks |
| 66 // that there are no conflicts with object pointers). Used in ASSERTs. |
| 67 static bool CodeIsPatchable(const Code& code); |
| 68 |
61 // Return the target address of the static call before return_address | 69 // Return the target address of the static call before return_address |
62 // in given code. | 70 // in given code. |
63 static RawCode* GetStaticCallTargetAt(uword return_address, const Code& code); | 71 static uword GetStaticCallTargetAt(uword return_address, const Code& code); |
64 | 72 |
65 // Get instance call information. Returns the call target and sets each | 73 // Get instance call information. Returns the call target and sets each |
66 // of the output parameters ic_data and arguments_descriptor if they are | 74 // of the output parameters ic_data and arguments_descriptor if they are |
67 // non-NULL. | 75 // non-NULL. |
68 static RawCode* GetInstanceCallAt(uword return_address, | 76 static uword GetInstanceCallAt(uword return_address, |
69 const Code& code, | 77 const Code& code, |
70 ICData* ic_data); | 78 ICData* ic_data); |
71 | 79 |
72 // Return target of an unoptimized static call and its ICData object | 80 // Return target of an unoptimized static call and its ICData object |
73 // (calls target via a stub). | 81 // (calls target via a stub). |
74 static RawFunction* GetUnoptimizedStaticCallAt(uword return_address, | 82 static RawFunction* GetUnoptimizedStaticCallAt(uword return_address, |
75 const Code& code, | 83 const Code& code, |
76 ICData* ic_data); | 84 ICData* ic_data); |
77 | 85 |
78 static intptr_t InstanceCallSizeInBytes(); | 86 static intptr_t InstanceCallSizeInBytes(); |
79 | 87 |
80 static void InsertDeoptimizationCallAt(uword start, uword target); | 88 static void InsertCallAt(uword start, uword target); |
81 | 89 |
82 static RawObject* GetEdgeCounterAt(uword pc, const Code& code); | 90 static RawObject* GetEdgeCounterAt(uword pc, const Code& code); |
83 | 91 |
84 static void PatchPoolPointerCallAt(uword return_address, | 92 static void PatchPoolPointerCallAt(uword return_address, |
85 const Code& code, | 93 const Code& code, |
86 const Code& new_target); | 94 uword new_target); |
87 | 95 |
88 static RawCode* GetNativeCallAt(uword return_address, | 96 static uword GetNativeCallAt(uword return_address, |
89 const Code& code, | 97 const Code& code, |
90 NativeFunction* target); | 98 NativeFunction* target); |
91 | 99 |
92 static void PatchNativeCallAt(uword return_address, | 100 static void PatchNativeCallAt(uword return_address, |
93 const Code& code, | 101 const Code& code, |
94 NativeFunction target, | 102 NativeFunction target, |
95 const Code& trampoline); | 103 const Code& trampoline); |
96 }; | 104 }; |
97 | 105 |
98 } // namespace dart | 106 } // namespace dart |
99 | 107 |
100 #endif // VM_CODE_PATCHER_H_ | 108 #endif // VM_CODE_PATCHER_H_ |
OLD | NEW |