OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 4873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4884 __ PopTryHandler(); | 4884 __ PopTryHandler(); |
4885 __ call(finally_entry_); | 4885 __ call(finally_entry_); |
4886 | 4886 |
4887 *stack_depth = 0; | 4887 *stack_depth = 0; |
4888 *context_length = 0; | 4888 *context_length = 0; |
4889 return previous_; | 4889 return previous_; |
4890 } | 4890 } |
4891 | 4891 |
4892 #undef __ | 4892 #undef __ |
4893 | 4893 |
| 4894 |
| 4895 static const byte kJnsInstruction = 0x79; |
| 4896 static const byte kJnsOffset = 0x11; |
| 4897 static const byte kCallInstruction = 0xe8; |
| 4898 static const byte kNopByteOne = 0x66; |
| 4899 static const byte kNopByteTwo = 0x90; |
| 4900 |
| 4901 // The back edge bookkeeping code matches the pattern: |
| 4902 // |
| 4903 // sub <profiling_counter>, <delta> |
| 4904 // jns ok |
| 4905 // call <interrupt stub> |
| 4906 // ok: |
| 4907 // |
| 4908 // The patched back edge looks like this: |
| 4909 // |
| 4910 // sub <profiling_counter>, <delta> ;; Not changed |
| 4911 // nop |
| 4912 // nop |
| 4913 // call <on-stack replacment> |
| 4914 // ok: |
| 4915 |
| 4916 void BackEdgeTable::PatchAt(Code* unoptimized_code, |
| 4917 Address pc, |
| 4918 Code* replacement_code) { |
| 4919 // Turn the jump into nops. |
| 4920 Address call_target_address = pc - kIntSize; |
| 4921 *(call_target_address - 3) = kNopByteOne; |
| 4922 *(call_target_address - 2) = kNopByteTwo; |
| 4923 // Replace the call address. |
| 4924 Assembler::set_target_address_at(call_target_address, |
| 4925 replacement_code->entry()); |
| 4926 |
| 4927 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( |
| 4928 unoptimized_code, call_target_address, replacement_code); |
| 4929 } |
| 4930 |
| 4931 |
| 4932 void BackEdgeTable::RevertAt(Code* unoptimized_code, |
| 4933 Address pc, |
| 4934 Code* interrupt_code) { |
| 4935 // Restore the original jump. |
| 4936 Address call_target_address = pc - kIntSize; |
| 4937 *(call_target_address - 3) = kJnsInstruction; |
| 4938 *(call_target_address - 2) = kJnsOffset; |
| 4939 // Restore the original call address. |
| 4940 Assembler::set_target_address_at(call_target_address, |
| 4941 interrupt_code->entry()); |
| 4942 |
| 4943 interrupt_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( |
| 4944 unoptimized_code, call_target_address, interrupt_code); |
| 4945 } |
| 4946 |
| 4947 |
| 4948 #ifdef DEBUG |
| 4949 BackEdgeTable::BackEdgeState BackEdgeTable::GetBackEdgeState( |
| 4950 Isolate* isolate, |
| 4951 Code* unoptimized_code, |
| 4952 Address pc) { |
| 4953 Address call_target_address = pc - kIntSize; |
| 4954 ASSERT_EQ(kCallInstruction, *(call_target_address - 1)); |
| 4955 if (*(call_target_address - 3) == kNopByteOne) { |
| 4956 ASSERT_EQ(kNopByteTwo, *(call_target_address - 2)); |
| 4957 Code* osr_builtin = |
| 4958 isolate->builtins()->builtin(Builtins::kOnStackReplacement); |
| 4959 ASSERT_EQ(osr_builtin->entry(), |
| 4960 Assembler::target_address_at(call_target_address)); |
| 4961 return ON_STACK_REPLACEMENT; |
| 4962 } else { |
| 4963 // Get the interrupt stub code object to match against from cache. |
| 4964 Code* interrupt_builtin = |
| 4965 isolate->builtins()->builtin(Builtins::kInterruptCheck); |
| 4966 ASSERT_EQ(interrupt_builtin->entry(), |
| 4967 Assembler::target_address_at(call_target_address)); |
| 4968 ASSERT_EQ(kJnsInstruction, *(call_target_address - 3)); |
| 4969 ASSERT_EQ(kJnsOffset, *(call_target_address - 2)); |
| 4970 return INTERRUPT; |
| 4971 } |
| 4972 } |
| 4973 #endif // DEBUG |
| 4974 |
| 4975 |
4894 } } // namespace v8::internal | 4976 } } // namespace v8::internal |
4895 | 4977 |
4896 #endif // V8_TARGET_ARCH_IA32 | 4978 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |