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

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 unit test 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
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 Address prev_reloc_address = code->instruction_start();
66 Address code_start_address = code->instruction_start(); 56 Address code_start_address = code->instruction_start();
67 SafepointTable table(*code); 57 DeoptimizationInputData* deopt_data =
68 for (unsigned i = 0; i < table.length(); ++i) { 58 DeoptimizationInputData::cast(code->deoptimization_data());
69 Address curr_reloc_address = code_start_address + table.GetPcOffset(i); 59 for (int i = 0; i < deopt_data->DeoptCount(); i++) {
60 int pc_offset = deopt_data->Pc(i)->value();
61 if (pc_offset == -1) continue;
62 Address curr_reloc_address = code_start_address + pc_offset;
Vyacheslav Egorov (Chromium) 2011/11/10 15:50:54 You can just use prev_pc_offset instead calculatin
fschneider 2011/11/11 14:09:08 Done.
70 ASSERT_GE(curr_reloc_address, prev_reloc_address); 63 ASSERT_GE(curr_reloc_address, prev_reloc_address);
71 SafepointEntry safepoint_entry = table.GetEntry(i); 64 int pc_delta = curr_reloc_address - prev_reloc_address;
72 int deoptimization_index = safepoint_entry.deoptimization_index(); 65 // We use RUNTIME_ENTRY reloc info which has a size of 2 bytes
73 if (deoptimization_index != Safepoint::kNoDeoptimizationIndex) { 66 // if encodable with small pc delta encoding and up to 6 bytes
74 // The gap code is needed to get to the state expected at the 67 // otherwise.
75 // bailout and we need to skip the call opcode to get to the 68 if (pc_delta <= RelocInfo::kMaxSmallPCDelta) {
76 // address that needs reloc. 69 min_reloc_size += 2;
77 curr_reloc_address += safepoint_entry.gap_code_size() + 1; 70 } else {
78 int pc_delta = curr_reloc_address - prev_reloc_address; 71 min_reloc_size += 6;
79 // We use RUNTIME_ENTRY reloc info which has a size of 2 bytes
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 } 72 }
73 prev_reloc_address = curr_reloc_address;
89 } 74 }
90 75
91 // If the relocation information is not big enough we create a new 76 // If the relocation information is not big enough we create a new
92 // relocation info object that is padded with comments to make it 77 // relocation info object that is padded with comments to make it
93 // big enough for lazy doptimization. 78 // big enough for lazy doptimization.
94 int reloc_length = code->relocation_info()->length(); 79 int reloc_length = code->relocation_info()->length();
95 if (min_reloc_size > reloc_length) { 80 if (min_reloc_size > reloc_length) {
96 int comment_reloc_size = RelocInfo::kMinRelocCommentSize; 81 int comment_reloc_size = RelocInfo::kMinRelocCommentSize;
97 // Padding needed. 82 // Padding needed.
98 int min_padding = min_reloc_size - reloc_length; 83 int min_padding = min_reloc_size - reloc_length;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 129
145 // We will overwrite the code's relocation info in-place. Relocation info 130 // 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 131 // 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 132 // array. Later on we will slide this to the start of the byte array and
148 // create a filler object in the remaining space. 133 // create a filler object in the remaining space.
149 ByteArray* reloc_info = code->relocation_info(); 134 ByteArray* reloc_info = code->relocation_info();
150 Address reloc_end_address = reloc_info->address() + reloc_info->Size(); 135 Address reloc_end_address = reloc_info->address() + reloc_info->Size();
151 RelocInfoWriter reloc_info_writer(reloc_end_address, code_start_address); 136 RelocInfoWriter reloc_info_writer(reloc_end_address, code_start_address);
152 137
153 // For each return after a safepoint insert a call to the corresponding 138 // For each return after a safepoint insert a call to the corresponding
154 // deoptimization entry. Since the call is a relative encoding, write new 139 // deoptimization entry at the following lazy-bailout point.
140
141 // Since the call is a relative encoding, write new
155 // reloc info. We do not need any of the existing reloc info because the 142 // 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). 143 // existing code will not be used again (we zap it in debug builds).
157 SafepointTable table(code); 144 //
158 Address prev_address = code_start_address; 145 // Emit call to lazy deoptimization at all lazy deopt points.
159 for (unsigned i = 0; i < table.length(); ++i) { 146 DeoptimizationInputData* deopt_data =
160 Address curr_address = code_start_address + table.GetPcOffset(i); 147 DeoptimizationInputData::cast(code->deoptimization_data());
161 ASSERT_GE(curr_address, prev_address); 148 for (int i = 0; i < deopt_data->DeoptCount(); i++) {
162 ZapCodeRange(prev_address, curr_address); 149 if (deopt_data->Pc(i)->value() == -1) continue;
163 150 // Patch lazy deoptimization entry.
164 SafepointEntry safepoint_entry = table.GetEntry(i); 151 Address curr_address = code_start_address + deopt_data->Pc(i)->value();
165 int deoptimization_index = safepoint_entry.deoptimization_index(); 152 CodePatcher patcher(curr_address, patch_size());
166 if (deoptimization_index != Safepoint::kNoDeoptimizationIndex) { 153 Address deopt_entry = GetDeoptimizationEntry(i, LAZY);
167 // The gap code is needed to get to the state expected at the bailout. 154 patcher.masm()->call(deopt_entry, RelocInfo::NONE);
168 curr_address += safepoint_entry.gap_code_size(); 155 // We use RUNTIME_ENTRY for deoptimization bailouts.
169 156 RelocInfo rinfo(curr_address + 1, // 1 after the call opcode.
Vyacheslav Egorov (Chromium) 2011/11/10 15:50:54 relocation info is not used? I think this is not G
fschneider 2011/11/11 14:09:08 Good catch. Done.
170 CodePatcher patcher(curr_address, patch_size()); 157 RelocInfo::RUNTIME_ENTRY,
171 Address deopt_entry = GetDeoptimizationEntry(deoptimization_index, LAZY); 158 reinterpret_cast<intptr_t>(deopt_entry),
172 patcher.masm()->call(deopt_entry, RelocInfo::NONE); 159 NULL);
173
174 // We use RUNTIME_ENTRY for deoptimization bailouts.
175 RelocInfo rinfo(curr_address + 1, // 1 after the call opcode.
176 RelocInfo::RUNTIME_ENTRY,
177 reinterpret_cast<intptr_t>(deopt_entry),
178 NULL);
179 reloc_info_writer.Write(&rinfo);
180 ASSERT_GE(reloc_info_writer.pos(),
181 reloc_info->address() + ByteArray::kHeaderSize);
182 curr_address += patch_size();
183 }
184 prev_address = curr_address;
185 } 160 }
186 ZapCodeRange(prev_address,
187 code_start_address + code->safepoint_table_offset());
188 161
189 // Move the relocation info to the beginning of the byte array. 162 // Move the relocation info to the beginning of the byte array.
190 int new_reloc_size = reloc_end_address - reloc_info_writer.pos(); 163 int new_reloc_size = reloc_end_address - reloc_info_writer.pos();
191 memmove(code->relocation_start(), reloc_info_writer.pos(), new_reloc_size); 164 memmove(code->relocation_start(), reloc_info_writer.pos(), new_reloc_size);
192 165
193 // The relocation info is in place, update the size. 166 // The relocation info is in place, update the size.
194 reloc_info->set_length(new_reloc_size); 167 reloc_info->set_length(new_reloc_size);
195 168
196 // Handle the junk part after the new relocation info. We will create 169 // 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. 170 // 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. 184 // ignore all slots that might have been recorded on it.
212 isolate->heap()->mark_compact_collector()->InvalidateCode(code); 185 isolate->heap()->mark_compact_collector()->InvalidateCode(code);
213 186
214 // Set the code for the function to non-optimized version. 187 // Set the code for the function to non-optimized version.
215 function->ReplaceCode(function->shared()->code()); 188 function->ReplaceCode(function->shared()->code());
216 189
217 if (FLAG_trace_deopt) { 190 if (FLAG_trace_deopt) {
218 PrintF("[forced deoptimization: "); 191 PrintF("[forced deoptimization: ");
219 function->PrintName(); 192 function->PrintName();
220 PrintF(" / %x]\n", reinterpret_cast<uint32_t>(function)); 193 PrintF(" / %x]\n", reinterpret_cast<uint32_t>(function));
221 #ifdef DEBUG
222 if (FLAG_print_code) {
223 code->PrintLn();
224 }
225 #endif
226 } 194 }
227 } 195 }
228 196
229 197
230 void Deoptimizer::PatchStackCheckCodeAt(Code* unoptimized_code, 198 void Deoptimizer::PatchStackCheckCodeAt(Code* unoptimized_code,
231 Address pc_after, 199 Address pc_after,
232 Code* check_code, 200 Code* check_code,
233 Code* replacement_code) { 201 Code* replacement_code) {
234 Address call_target_address = pc_after - kIntSize; 202 Address call_target_address = pc_after - kIntSize;
235 ASSERT(check_code->entry() == 203 ASSERT(check_code->entry() ==
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 } 811 }
844 __ bind(&done); 812 __ bind(&done);
845 } 813 }
846 814
847 #undef __ 815 #undef __
848 816
849 817
850 } } // namespace v8::internal 818 } } // namespace v8::internal
851 819
852 #endif // V8_TARGET_ARCH_IA32 820 #endif // V8_TARGET_ARCH_IA32
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698