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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 if (FLAG_trace_deopt) { | 109 if (FLAG_trace_deopt) { |
110 PrintF("[forced deoptimization: "); | 110 PrintF("[forced deoptimization: "); |
111 function->PrintName(); | 111 function->PrintName(); |
112 PrintF(" / %" V8PRIxPTR "]\n", reinterpret_cast<intptr_t>(function)); | 112 PrintF(" / %" V8PRIxPTR "]\n", reinterpret_cast<intptr_t>(function)); |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 | 116 |
117 static const byte kJnsInstruction = 0x79; | 117 static const byte kJnsInstruction = 0x79; |
118 static const byte kJnsOffset = 0x1f; | 118 static const byte kJnsOffset = 0x1f; |
119 static const byte kJaeInstruction = 0x73; | |
120 static const byte kJaeOffset = 0x07; | |
121 static const byte kCallInstruction = 0xe8; | 119 static const byte kCallInstruction = 0xe8; |
122 static const byte kNopByteOne = 0x66; | 120 static const byte kNopByteOne = 0x66; |
123 static const byte kNopByteTwo = 0x90; | 121 static const byte kNopByteTwo = 0x90; |
124 | 122 |
125 void Deoptimizer::PatchStackCheckCodeAt(Code* unoptimized_code, | 123 void Deoptimizer::PatchStackCheckCodeAt(Code* unoptimized_code, |
126 Address pc_after, | 124 Address pc_after, |
127 Code* check_code, | 125 Code* check_code, |
128 Code* replacement_code) { | 126 Code* replacement_code) { |
129 Address call_target_address = pc_after - kIntSize; | 127 Address call_target_address = pc_after - kIntSize; |
130 ASSERT_EQ(check_code->entry(), | 128 ASSERT_EQ(check_code->entry(), |
131 Assembler::target_address_at(call_target_address)); | 129 Assembler::target_address_at(call_target_address)); |
132 // The stack check code matches the pattern: | 130 // The back edge bookkeeping code matches the pattern: |
133 // | 131 // |
134 // cmp rsp, <limit> | 132 // add <profiling_counter>, <-delta> |
135 // jae ok | 133 // jns ok |
136 // call <stack guard> | 134 // call <stack guard> |
137 // test rax, <loop nesting depth> | 135 // test rax, <loop nesting depth> |
138 // ok: ... | 136 // ok: ... |
139 // | 137 // |
140 // We will patch away the branch so the code is: | 138 // We will patch away the branch so the code is: |
141 // | 139 // |
142 // cmp rsp, <limit> ;; Not changed | 140 // add <profiling_counter>, <-delta> ;; Not changed |
143 // nop | 141 // nop |
144 // nop | 142 // nop |
145 // call <on-stack replacment> | 143 // call <on-stack replacment> |
146 // test rax, <loop nesting depth> | 144 // test rax, <loop nesting depth> |
147 // ok: | 145 // ok: |
148 // | 146 // |
149 if (FLAG_count_based_interrupts) { | 147 ASSERT_EQ(kJnsInstruction, *(call_target_address - 3)); |
150 ASSERT_EQ(kJnsInstruction, *(call_target_address - 3)); | 148 ASSERT_EQ(kJnsOffset, *(call_target_address - 2)); |
151 ASSERT_EQ(kJnsOffset, *(call_target_address - 2)); | 149 ASSERT_EQ(kCallInstruction, *(call_target_address - 1)); |
152 } else { | |
153 ASSERT_EQ(kJaeInstruction, *(call_target_address - 3)); | |
154 ASSERT_EQ(kJaeOffset, *(call_target_address - 2)); | |
155 } | |
156 ASSERT_EQ(kCallInstruction, *(call_target_address - 1)); | |
157 *(call_target_address - 3) = kNopByteOne; | 150 *(call_target_address - 3) = kNopByteOne; |
158 *(call_target_address - 2) = kNopByteTwo; | 151 *(call_target_address - 2) = kNopByteTwo; |
159 Assembler::set_target_address_at(call_target_address, | 152 Assembler::set_target_address_at(call_target_address, |
160 replacement_code->entry()); | 153 replacement_code->entry()); |
161 | 154 |
162 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( | 155 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( |
163 unoptimized_code, call_target_address, replacement_code); | 156 unoptimized_code, call_target_address, replacement_code); |
164 } | 157 } |
165 | 158 |
166 | 159 |
167 void Deoptimizer::RevertStackCheckCodeAt(Code* unoptimized_code, | 160 void Deoptimizer::RevertStackCheckCodeAt(Code* unoptimized_code, |
168 Address pc_after, | 161 Address pc_after, |
169 Code* check_code, | 162 Code* check_code, |
170 Code* replacement_code) { | 163 Code* replacement_code) { |
171 Address call_target_address = pc_after - kIntSize; | 164 Address call_target_address = pc_after - kIntSize; |
172 ASSERT(replacement_code->entry() == | 165 ASSERT(replacement_code->entry() == |
173 Assembler::target_address_at(call_target_address)); | 166 Assembler::target_address_at(call_target_address)); |
174 // Replace the nops from patching (Deoptimizer::PatchStackCheckCode) to | 167 // Replace the nops from patching (Deoptimizer::PatchStackCheckCode) to |
175 // restore the conditional branch. | 168 // restore the conditional branch. |
176 ASSERT_EQ(kNopByteOne, *(call_target_address - 3)); | 169 ASSERT_EQ(kNopByteOne, *(call_target_address - 3)); |
177 ASSERT_EQ(kNopByteTwo, *(call_target_address - 2)); | 170 ASSERT_EQ(kNopByteTwo, *(call_target_address - 2)); |
178 ASSERT_EQ(kCallInstruction, *(call_target_address - 1)); | 171 ASSERT_EQ(kCallInstruction, *(call_target_address - 1)); |
179 if (FLAG_count_based_interrupts) { | 172 *(call_target_address - 3) = kJnsInstruction; |
180 *(call_target_address - 3) = kJnsInstruction; | 173 *(call_target_address - 2) = kJnsOffset; |
181 *(call_target_address - 2) = kJnsOffset; | |
182 } else { | |
183 *(call_target_address - 3) = kJaeInstruction; | |
184 *(call_target_address - 2) = kJaeOffset; | |
185 } | |
186 Assembler::set_target_address_at(call_target_address, | 174 Assembler::set_target_address_at(call_target_address, |
187 check_code->entry()); | 175 check_code->entry()); |
188 | 176 |
189 check_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( | 177 check_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( |
190 unoptimized_code, call_target_address, check_code); | 178 unoptimized_code, call_target_address, check_code); |
191 } | 179 } |
192 | 180 |
193 | 181 |
194 static int LookupBailoutId(DeoptimizationInputData* data, BailoutId ast_id) { | 182 static int LookupBailoutId(DeoptimizationInputData* data, BailoutId ast_id) { |
195 ByteArray* translations = data->TranslationByteArray(); | 183 ByteArray* translations = data->TranslationByteArray(); |
(...skipping 981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 } | 1165 } |
1178 __ bind(&done); | 1166 __ bind(&done); |
1179 } | 1167 } |
1180 | 1168 |
1181 #undef __ | 1169 #undef __ |
1182 | 1170 |
1183 | 1171 |
1184 } } // namespace v8::internal | 1172 } } // namespace v8::internal |
1185 | 1173 |
1186 #endif // V8_TARGET_ARCH_X64 | 1174 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |