Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: src/ia32/deoptimizer-ia32.cc

Issue 8492004: Fix lazy deoptimization at HInvokeFunction and enable target-recording call-function stub. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: added nop-padding and assertions on all platforms Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/hydrogen-instructions.h ('k') | src/ia32/full-codegen-ia32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 27 matching lines...) Expand all
38 namespace internal { 38 namespace internal {
39 39
40 const int Deoptimizer::table_entry_size_ = 10; 40 const int Deoptimizer::table_entry_size_ = 10;
41 41
42 42
43 int Deoptimizer::patch_size() { 43 int Deoptimizer::patch_size() {
44 return Assembler::kCallInstructionLength; 44 return Assembler::kCallInstructionLength;
45 } 45 }
46 46
47 47
48 static void ZapCodeRange(Address start, Address end) {
49 #ifdef DEBUG
50 ASSERT(start <= end);
51 int size = end - start;
52 CodePatcher destroyer(start, size);
53 while (size-- > 0) destroyer.masm()->int3();
54 #endif
55 }
56
57
58 void Deoptimizer::EnsureRelocSpaceForLazyDeoptimization(Handle<Code> code) { 48 void Deoptimizer::EnsureRelocSpaceForLazyDeoptimization(Handle<Code> code) {
59 Isolate* isolate = code->GetIsolate(); 49 Isolate* isolate = code->GetIsolate();
60 HandleScope scope(isolate); 50 HandleScope scope(isolate);
61 51
62 // Compute the size of relocation information needed for the code 52 // Compute the size of relocation information needed for the code
63 // patching in Deoptimizer::DeoptimizeFunction. 53 // patching in Deoptimizer::DeoptimizeFunction.
64 int min_reloc_size = 0; 54 int min_reloc_size = 0;
65 Address prev_reloc_address = code->instruction_start(); 55 int prev_pc_offset = 0;
66 Address code_start_address = code->instruction_start(); 56 DeoptimizationInputData* deopt_data =
67 SafepointTable table(*code); 57 DeoptimizationInputData::cast(code->deoptimization_data());
68 for (unsigned i = 0; i < table.length(); ++i) { 58 for (int i = 0; i < deopt_data->DeoptCount(); i++) {
69 Address curr_reloc_address = code_start_address + table.GetPcOffset(i); 59 int pc_offset = deopt_data->Pc(i)->value();
70 ASSERT_GE(curr_reloc_address, prev_reloc_address); 60 if (pc_offset == -1) continue;
71 SafepointEntry safepoint_entry = table.GetEntry(i); 61 ASSERT_GE(pc_offset, prev_pc_offset);
72 int deoptimization_index = safepoint_entry.deoptimization_index(); 62 int pc_delta = pc_offset - prev_pc_offset;
73 if (deoptimization_index != Safepoint::kNoDeoptimizationIndex) { 63 // We use RUNTIME_ENTRY reloc info which has a size of 2 bytes
74 // The gap code is needed to get to the state expected at the 64 // if encodable with small pc delta encoding and up to 6 bytes
75 // bailout and we need to skip the call opcode to get to the 65 // otherwise.
76 // address that needs reloc. 66 if (pc_delta <= RelocInfo::kMaxSmallPCDelta) {
77 curr_reloc_address += safepoint_entry.gap_code_size() + 1; 67 min_reloc_size += 2;
78 int pc_delta = curr_reloc_address - prev_reloc_address; 68 } else {
79 // We use RUNTIME_ENTRY reloc info which has a size of 2 bytes 69 min_reloc_size += 6;
80 // if encodable with small pc delta encoding and up to 6 bytes
81 // otherwise.
82 if (pc_delta <= RelocInfo::kMaxSmallPCDelta) {
83 min_reloc_size += 2;
84 } else {
85 min_reloc_size += 6;
86 }
87 prev_reloc_address = curr_reloc_address;
88 } 70 }
71 prev_pc_offset = pc_offset;
89 } 72 }
90 73
91 // If the relocation information is not big enough we create a new 74 // If the relocation information is not big enough we create a new
92 // relocation info object that is padded with comments to make it 75 // relocation info object that is padded with comments to make it
93 // big enough for lazy doptimization. 76 // big enough for lazy doptimization.
94 int reloc_length = code->relocation_info()->length(); 77 int reloc_length = code->relocation_info()->length();
95 if (min_reloc_size > reloc_length) { 78 if (min_reloc_size > reloc_length) {
96 int comment_reloc_size = RelocInfo::kMinRelocCommentSize; 79 int comment_reloc_size = RelocInfo::kMinRelocCommentSize;
97 // Padding needed. 80 // Padding needed.
98 int min_padding = min_reloc_size - reloc_length; 81 int min_padding = min_reloc_size - reloc_length;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 Address code_start_address = code->instruction_start(); 126 Address code_start_address = code->instruction_start();
144 127
145 // We will overwrite the code's relocation info in-place. Relocation info 128 // We will overwrite the code's relocation info in-place. Relocation info
146 // is written backward. The relocation info is the payload of a byte 129 // is written backward. The relocation info is the payload of a byte
147 // array. Later on we will slide this to the start of the byte array and 130 // array. Later on we will slide this to the start of the byte array and
148 // create a filler object in the remaining space. 131 // create a filler object in the remaining space.
149 ByteArray* reloc_info = code->relocation_info(); 132 ByteArray* reloc_info = code->relocation_info();
150 Address reloc_end_address = reloc_info->address() + reloc_info->Size(); 133 Address reloc_end_address = reloc_info->address() + reloc_info->Size();
151 RelocInfoWriter reloc_info_writer(reloc_end_address, code_start_address); 134 RelocInfoWriter reloc_info_writer(reloc_end_address, code_start_address);
152 135
153 // For each return after a safepoint insert a call to the corresponding 136 // For each LLazyBailout instruction insert a call to the corresponding
154 // deoptimization entry. Since the call is a relative encoding, write new 137 // deoptimization entry.
138
139 // Since the call is a relative encoding, write new
155 // reloc info. We do not need any of the existing reloc info because the 140 // reloc info. We do not need any of the existing reloc info because the
156 // existing code will not be used again (we zap it in debug builds). 141 // existing code will not be used again (we zap it in debug builds).
157 SafepointTable table(code); 142 //
158 Address prev_address = code_start_address; 143 // Emit call to lazy deoptimization at all lazy deopt points.
159 for (unsigned i = 0; i < table.length(); ++i) { 144 DeoptimizationInputData* deopt_data =
160 Address curr_address = code_start_address + table.GetPcOffset(i); 145 DeoptimizationInputData::cast(code->deoptimization_data());
161 ASSERT_GE(curr_address, prev_address); 146 #ifdef DEBUG
162 ZapCodeRange(prev_address, curr_address); 147 Address prev_call_address = NULL;
163 148 #endif
164 SafepointEntry safepoint_entry = table.GetEntry(i); 149 for (int i = 0; i < deopt_data->DeoptCount(); i++) {
165 int deoptimization_index = safepoint_entry.deoptimization_index(); 150 if (deopt_data->Pc(i)->value() == -1) continue;
166 if (deoptimization_index != Safepoint::kNoDeoptimizationIndex) { 151 // Patch lazy deoptimization entry.
167 // The gap code is needed to get to the state expected at the bailout. 152 Address call_address = code_start_address + deopt_data->Pc(i)->value();
168 curr_address += safepoint_entry.gap_code_size(); 153 CodePatcher patcher(call_address, patch_size());
169 154 Address deopt_entry = GetDeoptimizationEntry(i, LAZY);
170 CodePatcher patcher(curr_address, patch_size()); 155 patcher.masm()->call(deopt_entry, RelocInfo::NONE);
171 Address deopt_entry = GetDeoptimizationEntry(deoptimization_index, LAZY); 156 // We use RUNTIME_ENTRY for deoptimization bailouts.
172 patcher.masm()->call(deopt_entry, RelocInfo::NONE); 157 RelocInfo rinfo(call_address + 1, // 1 after the call opcode.
173 158 RelocInfo::RUNTIME_ENTRY,
174 // We use RUNTIME_ENTRY for deoptimization bailouts. 159 reinterpret_cast<intptr_t>(deopt_entry),
175 RelocInfo rinfo(curr_address + 1, // 1 after the call opcode. 160 NULL);
176 RelocInfo::RUNTIME_ENTRY, 161 reloc_info_writer.Write(&rinfo);
177 reinterpret_cast<intptr_t>(deopt_entry), 162 ASSERT_GE(reloc_info_writer.pos(),
178 NULL); 163 reloc_info->address() + ByteArray::kHeaderSize);
179 reloc_info_writer.Write(&rinfo); 164 ASSERT(prev_call_address == NULL ||
180 ASSERT_GE(reloc_info_writer.pos(), 165 call_address >= prev_call_address + patch_size());
181 reloc_info->address() + ByteArray::kHeaderSize); 166 ASSERT(call_address + patch_size() <= code->instruction_end());
182 curr_address += patch_size(); 167 #ifdef DEBUG
183 } 168 prev_call_address = call_address;
184 prev_address = curr_address; 169 #endif
185 } 170 }
186 ZapCodeRange(prev_address,
187 code_start_address + code->safepoint_table_offset());
188 171
189 // Move the relocation info to the beginning of the byte array. 172 // Move the relocation info to the beginning of the byte array.
190 int new_reloc_size = reloc_end_address - reloc_info_writer.pos(); 173 int new_reloc_size = reloc_end_address - reloc_info_writer.pos();
191 memmove(code->relocation_start(), reloc_info_writer.pos(), new_reloc_size); 174 memmove(code->relocation_start(), reloc_info_writer.pos(), new_reloc_size);
192 175
193 // The relocation info is in place, update the size. 176 // The relocation info is in place, update the size.
194 reloc_info->set_length(new_reloc_size); 177 reloc_info->set_length(new_reloc_size);
195 178
196 // Handle the junk part after the new relocation info. We will create 179 // Handle the junk part after the new relocation info. We will create
197 // a non-live object in the extra space at the end of the former reloc info. 180 // a non-live object in the extra space at the end of the former reloc info.
(...skipping 13 matching lines...) Expand all
211 // ignore all slots that might have been recorded on it. 194 // ignore all slots that might have been recorded on it.
212 isolate->heap()->mark_compact_collector()->InvalidateCode(code); 195 isolate->heap()->mark_compact_collector()->InvalidateCode(code);
213 196
214 // Set the code for the function to non-optimized version. 197 // Set the code for the function to non-optimized version.
215 function->ReplaceCode(function->shared()->code()); 198 function->ReplaceCode(function->shared()->code());
216 199
217 if (FLAG_trace_deopt) { 200 if (FLAG_trace_deopt) {
218 PrintF("[forced deoptimization: "); 201 PrintF("[forced deoptimization: ");
219 function->PrintName(); 202 function->PrintName();
220 PrintF(" / %x]\n", reinterpret_cast<uint32_t>(function)); 203 PrintF(" / %x]\n", reinterpret_cast<uint32_t>(function));
221 #ifdef DEBUG
222 if (FLAG_print_code) {
223 code->PrintLn();
224 }
225 #endif
226 } 204 }
227 } 205 }
228 206
229 207
230 void Deoptimizer::PatchStackCheckCodeAt(Code* unoptimized_code, 208 void Deoptimizer::PatchStackCheckCodeAt(Code* unoptimized_code,
231 Address pc_after, 209 Address pc_after,
232 Code* check_code, 210 Code* check_code,
233 Code* replacement_code) { 211 Code* replacement_code) {
234 Address call_target_address = pc_after - kIntSize; 212 Address call_target_address = pc_after - kIntSize;
235 ASSERT(check_code->entry() == 213 ASSERT(check_code->entry() ==
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 } 821 }
844 __ bind(&done); 822 __ bind(&done);
845 } 823 }
846 824
847 #undef __ 825 #undef __
848 826
849 827
850 } } // namespace v8::internal 828 } } // namespace v8::internal
851 829
852 #endif // V8_TARGET_ARCH_IA32 830 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/hydrogen-instructions.h ('k') | src/ia32/full-codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698