Index: src/ia32/deoptimizer-ia32.cc |
diff --git a/src/ia32/deoptimizer-ia32.cc b/src/ia32/deoptimizer-ia32.cc |
index e9e3fcfb7f3c6ac5f879f05d4183a16615b1b267..b41dacea7d4645dd2b35b8a22cf03362b1ad37bf 100644 |
--- a/src/ia32/deoptimizer-ia32.cc |
+++ b/src/ia32/deoptimizer-ia32.cc |
@@ -106,48 +106,35 @@ void Deoptimizer::DeoptimizeFunction(JSFunction* function) { |
} |
-void Deoptimizer::PatchStackCheckCode(Code* unoptimized_code, |
- Code* check_code, |
- Code* replacement_code) { |
- // Iterate the unoptimized code and patch every stack check except at |
- // the function entry. This code assumes the function entry stack |
- // check appears first i.e., is not deferred or otherwise reordered. |
- ASSERT(unoptimized_code->kind() == Code::FUNCTION); |
- bool first = true; |
- for (RelocIterator it(unoptimized_code, RelocInfo::kCodeTargetMask); |
- !it.done(); |
- it.next()) { |
- RelocInfo* rinfo = it.rinfo(); |
- if (rinfo->target_address() == Code::cast(check_code)->entry()) { |
- if (first) { |
- first = false; |
- } else { |
- // The stack check code matches the pattern: |
- // |
- // cmp esp, <limit> |
- // jae ok |
- // call <stack guard> |
- // test eax, <loop nesting depth> |
- // ok: ... |
- // |
- // We will patch away the branch so the code is: |
- // |
- // cmp esp, <limit> ;; Not changed |
- // nop |
- // nop |
- // call <on-stack replacment> |
- // test eax, <loop nesting depth> |
- // ok: |
- Address call_target_address = rinfo->pc(); |
- ASSERT(*(call_target_address - 3) == 0x73 && // jae |
- *(call_target_address - 2) == 0x07 && // offset |
- *(call_target_address - 1) == 0xe8); // call |
- *(call_target_address - 3) = 0x90; // nop |
- *(call_target_address - 2) = 0x90; // nop |
- rinfo->set_target_address(replacement_code->entry()); |
- } |
- } |
- } |
+void Deoptimizer::PatchStackCheckAt(Address pc_after, |
+ Code* check_code, |
+ Code* replacement_code) { |
+ Address call_target_address = pc_after - kPointerSize; |
+ ASSERT(check_code->entry() == |
+ Assembler::target_address_at(call_target_address)); |
+ // The stack check code matches the pattern: |
+ // |
+ // cmp esp, <limit> |
+ // jae ok |
+ // call <stack guard> |
+ // test eax, <loop nesting depth> |
+ // ok: ... |
+ // |
+ // We will patch away the branch so the code is: |
+ // |
+ // cmp esp, <limit> ;; Not changed |
+ // nop |
+ // nop |
+ // call <on-stack replacment> |
+ // test eax, <loop nesting depth> |
+ // ok: |
+ ASSERT(*(call_target_address - 3) == 0x73 && // jae |
+ *(call_target_address - 2) == 0x07 && // offset |
+ *(call_target_address - 1) == 0xe8); // call |
+ *(call_target_address - 3) = 0x90; // nop |
+ *(call_target_address - 2) = 0x90; // nop |
+ Assembler::set_target_address_at(call_target_address, |
+ replacement_code->entry()); |
} |