OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 function->ReplaceCode(function->shared()->code()); | 99 function->ReplaceCode(function->shared()->code()); |
100 | 100 |
101 if (FLAG_trace_deopt) { | 101 if (FLAG_trace_deopt) { |
102 PrintF("[forced deoptimization: "); | 102 PrintF("[forced deoptimization: "); |
103 function->PrintName(); | 103 function->PrintName(); |
104 PrintF(" / %x]\n", reinterpret_cast<uint32_t>(function)); | 104 PrintF(" / %x]\n", reinterpret_cast<uint32_t>(function)); |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 | 108 |
109 void Deoptimizer::PatchStackCheckCode(RelocInfo* rinfo, | 109 void Deoptimizer::PatchStackCheckCode(Code* unoptimized_code, |
| 110 Code* check_code, |
110 Code* replacement_code) { | 111 Code* replacement_code) { |
111 // The stack check code matches the pattern: | 112 // Iterate the unoptimized code and patch every stack check except at |
112 // | 113 // the function entry. This code assumes the function entry stack |
113 // cmp esp, <limit> | 114 // check appears first i.e., is not deferred or otherwise reordered. |
114 // jae ok | 115 ASSERT(unoptimized_code->kind() == Code::FUNCTION); |
115 // call <stack guard> | 116 bool first = true; |
116 // test eax, <loop nesting depth> | 117 for (RelocIterator it(unoptimized_code, RelocInfo::kCodeTargetMask); |
117 // ok: ... | 118 !it.done(); |
118 // | 119 it.next()) { |
119 // We will patch away the branch so the code is: | 120 RelocInfo* rinfo = it.rinfo(); |
120 // | 121 if (rinfo->target_address() == Code::cast(check_code)->entry()) { |
121 // cmp esp, <limit> ;; Not changed | 122 if (first) { |
122 // nop | 123 first = false; |
123 // nop | 124 } else { |
124 // call <on-stack replacment> | 125 // The stack check code matches the pattern: |
125 // test eax, <loop nesting depth> | 126 // |
126 // ok: | 127 // cmp esp, <limit> |
127 Address call_target_address = rinfo->pc(); | 128 // jae ok |
128 ASSERT(*(call_target_address - 3) == 0x73 && // jae | 129 // call <stack guard> |
129 *(call_target_address - 2) == 0x07 && // offset | 130 // test eax, <loop nesting depth> |
130 *(call_target_address - 1) == 0xe8); // call | 131 // ok: ... |
131 *(call_target_address - 3) = 0x90; // nop | 132 // |
132 *(call_target_address - 2) = 0x90; // nop | 133 // We will patch away the branch so the code is: |
133 rinfo->set_target_address(replacement_code->entry()); | 134 // |
| 135 // cmp esp, <limit> ;; Not changed |
| 136 // nop |
| 137 // nop |
| 138 // call <on-stack replacment> |
| 139 // test eax, <loop nesting depth> |
| 140 // ok: |
| 141 Address call_target_address = rinfo->pc(); |
| 142 ASSERT(*(call_target_address - 3) == 0x73 && // jae |
| 143 *(call_target_address - 2) == 0x07 && // offset |
| 144 *(call_target_address - 1) == 0xe8); // call |
| 145 *(call_target_address - 3) = 0x90; // nop |
| 146 *(call_target_address - 2) = 0x90; // nop |
| 147 rinfo->set_target_address(replacement_code->entry()); |
| 148 } |
| 149 } |
| 150 } |
134 } | 151 } |
135 | 152 |
136 | 153 |
137 void Deoptimizer::RevertStackCheckCode(RelocInfo* rinfo, Code* check_code) { | 154 void Deoptimizer::RevertStackCheckCode(Code* unoptimized_code, |
138 // Replace the nops from patching (Deoptimizer::PatchStackCheckCode) to | 155 Code* check_code, |
139 // restore the conditional branch. | 156 Code* replacement_code) { |
140 Address call_target_address = rinfo->pc(); | 157 // Iterate the unoptimized code and revert all the patched stack checks. |
141 ASSERT(*(call_target_address - 3) == 0x90 && // nop | 158 for (RelocIterator it(unoptimized_code, RelocInfo::kCodeTargetMask); |
142 *(call_target_address - 2) == 0x90 && // nop | 159 !it.done(); |
143 *(call_target_address - 1) == 0xe8); // call | 160 it.next()) { |
144 *(call_target_address - 3) = 0x73; // jae | 161 RelocInfo* rinfo = it.rinfo(); |
145 *(call_target_address - 2) = 0x07; // offset | 162 if (rinfo->target_address() == replacement_code->entry()) { |
146 rinfo->set_target_address(check_code->entry()); | 163 // Replace the nops from patching (Deoptimizer::PatchStackCheckCode) to |
| 164 // restore the conditional branch. |
| 165 Address call_target_address = rinfo->pc(); |
| 166 ASSERT(*(call_target_address - 3) == 0x90 && // nop |
| 167 *(call_target_address - 2) == 0x90 && // nop |
| 168 *(call_target_address - 1) == 0xe8); // call |
| 169 *(call_target_address - 3) = 0x73; // jae |
| 170 *(call_target_address - 2) = 0x07; // offset |
| 171 rinfo->set_target_address(check_code->entry()); |
| 172 } |
| 173 } |
147 } | 174 } |
148 | 175 |
149 | 176 |
150 static int LookupBailoutId(DeoptimizationInputData* data, unsigned ast_id) { | 177 static int LookupBailoutId(DeoptimizationInputData* data, unsigned ast_id) { |
151 ByteArray* translations = data->TranslationByteArray(); | 178 ByteArray* translations = data->TranslationByteArray(); |
152 int length = data->DeoptCount(); | 179 int length = data->DeoptCount(); |
153 for (int i = 0; i < length; i++) { | 180 for (int i = 0; i < length; i++) { |
154 if (static_cast<unsigned>(data->AstId(i)->value()) == ast_id) { | 181 if (static_cast<unsigned>(data->AstId(i)->value()) == ast_id) { |
155 TranslationIterator it(translations, data->TranslationIndex(i)->value()); | 182 TranslationIterator it(translations, data->TranslationIndex(i)->value()); |
156 int value = it.Next(); | 183 int value = it.Next(); |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 } | 642 } |
616 __ bind(&done); | 643 __ bind(&done); |
617 } | 644 } |
618 | 645 |
619 #undef __ | 646 #undef __ |
620 | 647 |
621 | 648 |
622 } } // namespace v8::internal | 649 } } // namespace v8::internal |
623 | 650 |
624 #endif // V8_TARGET_ARCH_IA32 | 651 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |