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 4880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4891 | 4891 |
4892 #undef __ | 4892 #undef __ |
4893 | 4893 |
4894 | 4894 |
4895 static const byte kJnsInstruction = 0x79; | 4895 static const byte kJnsInstruction = 0x79; |
4896 static const byte kJnsOffset = 0x11; | 4896 static const byte kJnsOffset = 0x11; |
4897 static const byte kCallInstruction = 0xe8; | 4897 static const byte kCallInstruction = 0xe8; |
4898 static const byte kNopByteOne = 0x66; | 4898 static const byte kNopByteOne = 0x66; |
4899 static const byte kNopByteTwo = 0x90; | 4899 static const byte kNopByteTwo = 0x90; |
4900 | 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 | 4901 |
4916 void BackEdgeTable::PatchAt(Code* unoptimized_code, | 4902 void BackEdgeTable::PatchAt(Code* unoptimized_code, |
4917 Address pc, | 4903 Address pc, |
| 4904 BackEdgeState target_state, |
4918 Code* replacement_code) { | 4905 Code* replacement_code) { |
4919 // Turn the jump into nops. | |
4920 Address call_target_address = pc - kIntSize; | 4906 Address call_target_address = pc - kIntSize; |
4921 *(call_target_address - 3) = kNopByteOne; | 4907 Address jns_instr_address = call_target_address - 3; |
4922 *(call_target_address - 2) = kNopByteTwo; | 4908 Address jns_offset_address = call_target_address - 2; |
4923 // Replace the call address. | 4909 |
| 4910 switch (target_state) { |
| 4911 case INTERRUPT: |
| 4912 // sub <profiling_counter>, <delta> ;; Not changed |
| 4913 // jns ok |
| 4914 // call <interrupt stub> |
| 4915 // ok: |
| 4916 *jns_instr_address = kJnsInstruction; |
| 4917 *jns_offset_address = kJnsOffset; |
| 4918 break; |
| 4919 case ON_STACK_REPLACEMENT: |
| 4920 case OSR_AFTER_STACK_CHECK: |
| 4921 // sub <profiling_counter>, <delta> ;; Not changed |
| 4922 // nop |
| 4923 // nop |
| 4924 // call <on-stack replacment> |
| 4925 // ok: |
| 4926 *jns_instr_address = kNopByteOne; |
| 4927 *jns_offset_address = kNopByteTwo; |
| 4928 break; |
| 4929 } |
| 4930 |
4924 Assembler::set_target_address_at(call_target_address, | 4931 Assembler::set_target_address_at(call_target_address, |
4925 replacement_code->entry()); | 4932 replacement_code->entry()); |
4926 | |
4927 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( | 4933 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( |
4928 unoptimized_code, call_target_address, replacement_code); | 4934 unoptimized_code, call_target_address, replacement_code); |
4929 } | 4935 } |
4930 | 4936 |
4931 | 4937 |
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( | 4938 BackEdgeTable::BackEdgeState BackEdgeTable::GetBackEdgeState( |
4950 Isolate* isolate, | 4939 Isolate* isolate, |
4951 Code* unoptimized_code, | 4940 Code* unoptimized_code, |
4952 Address pc) { | 4941 Address pc) { |
4953 Address call_target_address = pc - kIntSize; | 4942 Address call_target_address = pc - kIntSize; |
| 4943 Address jns_instr_address = call_target_address - 3; |
4954 ASSERT_EQ(kCallInstruction, *(call_target_address - 1)); | 4944 ASSERT_EQ(kCallInstruction, *(call_target_address - 1)); |
4955 if (*(call_target_address - 3) == kNopByteOne) { | 4945 |
4956 ASSERT_EQ(kNopByteTwo, *(call_target_address - 2)); | 4946 if (*jns_instr_address == kJnsInstruction) { |
4957 Code* osr_builtin = | 4947 ASSERT_EQ(kJnsOffset, *(call_target_address - 2)); |
4958 isolate->builtins()->builtin(Builtins::kOnStackReplacement); | 4948 ASSERT_EQ(isolate->builtins()->InterruptCheck()->entry(), |
4959 ASSERT_EQ(osr_builtin->entry(), | |
4960 Assembler::target_address_at(call_target_address)); | 4949 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; | 4950 return INTERRUPT; |
4971 } | 4951 } |
| 4952 |
| 4953 ASSERT_EQ(kNopByteOne, *jns_instr_address); |
| 4954 ASSERT_EQ(kNopByteTwo, *(call_target_address - 2)); |
| 4955 |
| 4956 if (Assembler::target_address_at(call_target_address) == |
| 4957 isolate->builtins()->OnStackReplacement()->entry()) { |
| 4958 return ON_STACK_REPLACEMENT; |
| 4959 } |
| 4960 |
| 4961 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
| 4962 Assembler::target_address_at(call_target_address)); |
| 4963 return OSR_AFTER_STACK_CHECK; |
4972 } | 4964 } |
4973 #endif // DEBUG | |
4974 | 4965 |
4975 | 4966 |
4976 } } // namespace v8::internal | 4967 } } // namespace v8::internal |
4977 | 4968 |
4978 #endif // V8_TARGET_ARCH_IA32 | 4969 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |