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