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 |
51 // Patch instance call before return_address in given code to the new target. | 52 // Patch instance call before return_address in given code to the new target. |
52 static void PatchInstanceCallAt(uword return_address, | 53 static void PatchInstanceCallAt(uword return_address, |
53 const Code& code, | 54 const Code& code, |
54 uword new_target_address); | 55 const Code& new_target); |
55 | 56 |
56 // Patch entry point with a jump as specified in the code's patch region. | 57 // Patch entry point with a jump as specified in the code's patch region. |
57 static void PatchEntry(const Code& code); | 58 static void PatchEntry(const Code& code, const Code& new_code); |
58 | 59 |
59 // Restore entry point with original code (i.e., before patching). | 60 // Restore entry point with original code (i.e., before patching). |
60 static void RestoreEntry(const Code& code); | 61 static void RestoreEntry(const Code& code); |
61 | 62 |
62 // Has the entry been patched? | 63 // Has the entry been patched? |
63 static bool IsEntryPatched(const Code& code); | 64 static bool IsEntryPatched(const Code& code); |
64 | 65 |
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 | 66 // Return the target address of the static call before return_address |
70 // in given code. | 67 // in given code. |
71 static uword GetStaticCallTargetAt(uword return_address, const Code& code); | 68 static RawCode* GetStaticCallTargetAt(uword return_address, const Code& code); |
72 | 69 |
73 // Get instance call information. Returns the call target and sets each | 70 // Get instance call information. Returns the call target and sets each |
74 // of the output parameters ic_data and arguments_descriptor if they are | 71 // of the output parameters ic_data and arguments_descriptor if they are |
75 // non-NULL. | 72 // non-NULL. |
76 static uword GetInstanceCallAt(uword return_address, | 73 static RawCode* GetInstanceCallAt(uword return_address, |
77 const Code& code, | 74 const Code& code, |
78 ICData* ic_data); | 75 ICData* ic_data); |
79 | 76 |
80 // Return target of an unoptimized static call and its ICData object | 77 // Return target of an unoptimized static call and its ICData object |
81 // (calls target via a stub). | 78 // (calls target via a stub). |
82 static RawFunction* GetUnoptimizedStaticCallAt(uword return_address, | 79 static RawFunction* GetUnoptimizedStaticCallAt(uword return_address, |
83 const Code& code, | 80 const Code& code, |
84 ICData* ic_data); | 81 ICData* ic_data); |
85 | 82 |
86 static intptr_t InstanceCallSizeInBytes(); | 83 static intptr_t InstanceCallSizeInBytes(); |
87 | 84 |
88 static void InsertCallAt(uword start, uword target); | 85 // TODO(fschneider): Rename if inly used for lazy-deopt. |
| 86 static void InsertDeoptimizationCallAt(uword start, uword target); |
89 | 87 |
90 static RawObject* GetEdgeCounterAt(uword pc, const Code& code); | 88 static RawObject* GetEdgeCounterAt(uword pc, const Code& code); |
91 | 89 |
92 static void PatchPoolPointerCallAt(uword return_address, | 90 static void PatchPoolPointerCallAt(uword return_address, |
93 const Code& code, | 91 const Code& code, |
94 uword new_target); | 92 const Code& new_target); |
95 | 93 |
96 static uword GetNativeCallAt(uword return_address, | 94 static RawCode* GetNativeCallAt(uword return_address, |
97 const Code& code, | 95 const Code& code, |
98 NativeFunction* target); | 96 NativeFunction* target); |
99 | 97 |
100 static void PatchNativeCallAt(uword return_address, | 98 static void PatchNativeCallAt(uword return_address, |
101 const Code& code, | 99 const Code& code, |
102 NativeFunction target, | 100 NativeFunction target, |
103 const Code& trampoline); | 101 const Code& trampoline); |
104 }; | 102 }; |
105 | 103 |
106 } // namespace dart | 104 } // namespace dart |
107 | 105 |
108 #endif // VM_CODE_PATCHER_H_ | 106 #endif // VM_CODE_PATCHER_H_ |
OLD | NEW |