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. |
Søren Thygesen Gjesse
2011/01/24 14:47:06
Assert unpotimized_code is not optimized?
Mads Ager (chromium)
2011/01/24 14:54:30
Done.
| |
114 // jae ok | 115 bool first = true; |
115 // call <stack guard> | 116 for (RelocIterator it(unoptimized_code, RelocInfo::kCodeTargetMask); |
116 // test eax, <loop nesting depth> | 117 !it.done(); |
117 // ok: ... | 118 it.next()) { |
118 // | 119 RelocInfo* rinfo = it.rinfo(); |
119 // We will patch away the branch so the code is: | 120 if (rinfo->target_address() == Code::cast(check_code)->entry()) { |
120 // | 121 if (first) { |
121 // cmp esp, <limit> ;; Not changed | 122 first = false; |
122 // nop | 123 } else { |
123 // nop | 124 // The stack check code matches the pattern: |
124 // call <on-stack replacment> | 125 // |
125 // test eax, <loop nesting depth> | 126 // cmp esp, <limit> |
126 // ok: | 127 // jae ok |
127 Address call_target_address = rinfo->pc(); | 128 // call <stack guard> |
128 ASSERT(*(call_target_address - 3) == 0x73 && // jae | 129 // test eax, <loop nesting depth> |
129 *(call_target_address - 2) == 0x07 && // offset | 130 // ok: ... |
130 *(call_target_address - 1) == 0xe8); // call | 131 // |
131 *(call_target_address - 3) = 0x90; // nop | 132 // We will patch away the branch so the code is: |
132 *(call_target_address - 2) = 0x90; // nop | 133 // |
133 rinfo->set_target_address(replacement_code->entry()); | 134 // cmp esp, <limit> ;; Not changed |
135 // nop | |
136 // nop | |
137 // call <on-stack replacment> | |
138 // test eax, <loop nesting depth> | |
139 // ok: | |
140 Address call_target_address = rinfo->pc(); | |
141 ASSERT(*(call_target_address - 3) == 0x73 && // jae | |
142 *(call_target_address - 2) == 0x07 && // offset | |
143 *(call_target_address - 1) == 0xe8); // call | |
144 *(call_target_address - 3) = 0x90; // nop | |
145 *(call_target_address - 2) = 0x90; // nop | |
146 rinfo->set_target_address(replacement_code->entry()); | |
147 } | |
148 } | |
149 } | |
134 } | 150 } |
135 | 151 |
136 | 152 |
137 void Deoptimizer::RevertStackCheckCode(RelocInfo* rinfo, Code* check_code) { | 153 void Deoptimizer::RevertStackCheckCode(Code* unoptimized_code, |
138 // Replace the nops from patching (Deoptimizer::PatchStackCheckCode) to | 154 Code* check_code, |
139 // restore the conditional branch. | 155 Code* replacement_code) { |
140 Address call_target_address = rinfo->pc(); | 156 // Iterate the unoptimized code and revert all the patched stack checks. |
141 ASSERT(*(call_target_address - 3) == 0x90 && // nop | 157 for (RelocIterator it(unoptimized_code, RelocInfo::kCodeTargetMask); |
142 *(call_target_address - 2) == 0x90 && // nop | 158 !it.done(); |
143 *(call_target_address - 1) == 0xe8); // call | 159 it.next()) { |
144 *(call_target_address - 3) = 0x73; // jae | 160 RelocInfo* rinfo = it.rinfo(); |
145 *(call_target_address - 2) = 0x07; // offset | 161 if (rinfo->target_address() == replacement_code->entry()) { |
146 rinfo->set_target_address(check_code->entry()); | 162 // Replace the nops from patching (Deoptimizer::PatchStackCheckCode) to |
163 // restore the conditional branch. | |
164 Address call_target_address = rinfo->pc(); | |
165 ASSERT(*(call_target_address - 3) == 0x90 && // nop | |
166 *(call_target_address - 2) == 0x90 && // nop | |
167 *(call_target_address - 1) == 0xe8); // call | |
168 *(call_target_address - 3) = 0x73; // jae | |
169 *(call_target_address - 2) = 0x07; // offset | |
170 rinfo->set_target_address(check_code->entry()); | |
171 } | |
172 } | |
147 } | 173 } |
148 | 174 |
149 | 175 |
150 static int LookupBailoutId(DeoptimizationInputData* data, unsigned ast_id) { | 176 static int LookupBailoutId(DeoptimizationInputData* data, unsigned ast_id) { |
151 ByteArray* translations = data->TranslationByteArray(); | 177 ByteArray* translations = data->TranslationByteArray(); |
152 int length = data->DeoptCount(); | 178 int length = data->DeoptCount(); |
153 for (int i = 0; i < length; i++) { | 179 for (int i = 0; i < length; i++) { |
154 if (static_cast<unsigned>(data->AstId(i)->value()) == ast_id) { | 180 if (static_cast<unsigned>(data->AstId(i)->value()) == ast_id) { |
155 TranslationIterator it(translations, data->TranslationIndex(i)->value()); | 181 TranslationIterator it(translations, data->TranslationIndex(i)->value()); |
156 int value = it.Next(); | 182 int value = it.Next(); |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
615 } | 641 } |
616 __ bind(&done); | 642 __ bind(&done); |
617 } | 643 } |
618 | 644 |
619 #undef __ | 645 #undef __ |
620 | 646 |
621 | 647 |
622 } } // namespace v8::internal | 648 } } // namespace v8::internal |
623 | 649 |
624 #endif // V8_TARGET_ARCH_IA32 | 650 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |