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 4908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4919 | 4919 |
4920 *stack_depth = 0; | 4920 *stack_depth = 0; |
4921 *context_length = 0; | 4921 *context_length = 0; |
4922 return previous_; | 4922 return previous_; |
4923 } | 4923 } |
4924 | 4924 |
4925 | 4925 |
4926 #undef __ | 4926 #undef __ |
4927 | 4927 |
4928 | 4928 |
4929 // This structure comes from FullCodeGenerator::EmitBackEdgeBookkeeping. | |
4930 // The back edge bookkeeping code matches the pattern: | |
4931 // | |
4932 // sltu at, sp, t0 / slt at, a3, zero_reg (in case of count based interrupts) | |
4933 // beq at, zero_reg, ok | |
4934 // lui t9, <interrupt stub address> upper | |
4935 // ori t9, <interrupt stub address> lower | |
4936 // jalr t9 | |
4937 // nop | |
4938 // ok-label ----- pc_after points here | |
4939 // | |
4940 // We patch the code to the following form: | |
4941 // | |
4942 // addiu at, zero_reg, 1 | |
4943 // beq at, zero_reg, ok ;; Not changed | |
4944 // lui t9, <on-stack replacement address> upper | |
4945 // ori t9, <on-stack replacement address> lower | |
4946 // jalr t9 ;; Not changed | |
4947 // nop ;; Not changed | |
4948 // ok-label ----- pc_after points here | |
4949 | |
4950 void BackEdgeTable::PatchAt(Code* unoptimized_code, | 4929 void BackEdgeTable::PatchAt(Code* unoptimized_code, |
4951 Address pc_after, | 4930 Address pc, |
| 4931 BackEdgeState target_state, |
4952 Code* replacement_code) { | 4932 Code* replacement_code) { |
4953 static const int kInstrSize = Assembler::kInstrSize; | 4933 static const int kInstrSize = Assembler::kInstrSize; |
4954 // Replace the sltu instruction with load-imm 1 to at, so beq is not taken. | 4934 Address branch_address = pc - 6 * kInstrSize; |
4955 CodePatcher patcher(pc_after - 6 * kInstrSize, 1); | 4935 CodePatcher patcher(branch_address, 1); |
4956 patcher.masm()->addiu(at, zero_reg, 1); | 4936 |
| 4937 switch (target_state) { |
| 4938 case INTERRUPT: |
| 4939 // slt at, a3, zero_reg (in case of count based interrupts) |
| 4940 // beq at, zero_reg, ok |
| 4941 // lui t9, <interrupt stub address> upper |
| 4942 // ori t9, <interrupt stub address> lower |
| 4943 // jalr t9 |
| 4944 // nop |
| 4945 // ok-label ----- pc_after points here |
| 4946 patcher.masm()->slt(at, a3, zero_reg); |
| 4947 break; |
| 4948 case ON_STACK_REPLACEMENT: |
| 4949 case OSR_AFTER_STACK_CHECK: |
| 4950 // addiu at, zero_reg, 1 |
| 4951 // beq at, zero_reg, ok ;; Not changed |
| 4952 // lui t9, <on-stack replacement address> upper |
| 4953 // ori t9, <on-stack replacement address> lower |
| 4954 // jalr t9 ;; Not changed |
| 4955 // nop ;; Not changed |
| 4956 // ok-label ----- pc_after points here |
| 4957 patcher.masm()->addiu(at, zero_reg, 1); |
| 4958 break; |
| 4959 } |
| 4960 Address pc_immediate_load_address = pc - 4 * kInstrSize; |
4957 // Replace the stack check address in the load-immediate (lui/ori pair) | 4961 // Replace the stack check address in the load-immediate (lui/ori pair) |
4958 // with the entry address of the replacement code. | 4962 // with the entry address of the replacement code. |
4959 Assembler::set_target_address_at(pc_after - 4 * kInstrSize, | 4963 Assembler::set_target_address_at(pc_immediate_load_address, |
4960 replacement_code->entry()); | 4964 replacement_code->entry()); |
4961 | 4965 |
4962 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( | 4966 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( |
4963 unoptimized_code, pc_after - 4 * kInstrSize, replacement_code); | 4967 unoptimized_code, pc_immediate_load_address, replacement_code); |
4964 } | 4968 } |
4965 | 4969 |
4966 | 4970 |
4967 void BackEdgeTable::RevertAt(Code* unoptimized_code, | 4971 BackEdgeTable::BackEdgeState BackEdgeTable::GetBackEdgeState( |
4968 Address pc_after, | 4972 Isolate* isolate, |
4969 Code* interrupt_code) { | 4973 Code* unoptimized_code, |
| 4974 Address pc) { |
4970 static const int kInstrSize = Assembler::kInstrSize; | 4975 static const int kInstrSize = Assembler::kInstrSize; |
4971 // Restore the sltu instruction so beq can be taken again. | 4976 Address branch_address = pc - 6 * kInstrSize; |
4972 CodePatcher patcher(pc_after - 6 * kInstrSize, 1); | 4977 Address pc_immediate_load_address = pc - 4 * kInstrSize; |
4973 patcher.masm()->slt(at, a3, zero_reg); | |
4974 // Restore the original call address. | |
4975 Assembler::set_target_address_at(pc_after - 4 * kInstrSize, | |
4976 interrupt_code->entry()); | |
4977 | 4978 |
4978 interrupt_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( | 4979 ASSERT(Assembler::IsBeq(Assembler::instr_at(pc - 5 * kInstrSize))); |
4979 unoptimized_code, pc_after - 4 * kInstrSize, interrupt_code); | 4980 if (!Assembler::IsAddImmediate(Assembler::instr_at(branch_address))) { |
| 4981 ASSERT(reinterpret_cast<uint32_t>( |
| 4982 Assembler::target_address_at(pc_immediate_load_address)) == |
| 4983 reinterpret_cast<uint32_t>( |
| 4984 isolate->builtins()->InterruptCheck()->entry())); |
| 4985 return INTERRUPT; |
| 4986 } |
| 4987 |
| 4988 ASSERT(Assembler::IsAddImmediate(Assembler::instr_at(branch_address))); |
| 4989 |
| 4990 if (reinterpret_cast<uint32_t>( |
| 4991 Assembler::target_address_at(pc_immediate_load_address)) == |
| 4992 reinterpret_cast<uint32_t>( |
| 4993 isolate->builtins()->OnStackReplacement()->entry())) { |
| 4994 return ON_STACK_REPLACEMENT; |
| 4995 } |
| 4996 |
| 4997 ASSERT(reinterpret_cast<uint32_t>( |
| 4998 Assembler::target_address_at(pc_immediate_load_address)) == |
| 4999 reinterpret_cast<uint32_t>( |
| 5000 isolate->builtins()->OsrAfterStackCheck()->entry())); |
| 5001 return OSR_AFTER_STACK_CHECK; |
4980 } | 5002 } |
4981 | 5003 |
4982 | 5004 |
4983 #ifdef DEBUG | |
4984 BackEdgeTable::BackEdgeState BackEdgeTable::GetBackEdgeState( | |
4985 Isolate* isolate, | |
4986 Code* unoptimized_code, | |
4987 Address pc_after) { | |
4988 static const int kInstrSize = Assembler::kInstrSize; | |
4989 ASSERT(Assembler::IsBeq(Assembler::instr_at(pc_after - 5 * kInstrSize))); | |
4990 if (Assembler::IsAddImmediate( | |
4991 Assembler::instr_at(pc_after - 6 * kInstrSize))) { | |
4992 Code* osr_builtin = | |
4993 isolate->builtins()->builtin(Builtins::kOnStackReplacement); | |
4994 ASSERT(reinterpret_cast<uint32_t>( | |
4995 Assembler::target_address_at(pc_after - 4 * kInstrSize)) == | |
4996 reinterpret_cast<uint32_t>(osr_builtin->entry())); | |
4997 return ON_STACK_REPLACEMENT; | |
4998 } else { | |
4999 // Get the interrupt stub code object to match against from cache. | |
5000 Code* interrupt_builtin = | |
5001 isolate->builtins()->builtin(Builtins::kInterruptCheck); | |
5002 ASSERT(reinterpret_cast<uint32_t>( | |
5003 Assembler::target_address_at(pc_after - 4 * kInstrSize)) == | |
5004 reinterpret_cast<uint32_t>(interrupt_builtin->entry())); | |
5005 return INTERRUPT; | |
5006 } | |
5007 } | |
5008 #endif // DEBUG | |
5009 | |
5010 | |
5011 } } // namespace v8::internal | 5005 } } // namespace v8::internal |
5012 | 5006 |
5013 #endif // V8_TARGET_ARCH_MIPS | 5007 #endif // V8_TARGET_ARCH_MIPS |
OLD | NEW |