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

Side by Side Diff: src/ia32/full-codegen-ia32.cc

Issue 207543003: Do stack checks while pushing locals (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 months 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 94 }
95 95
96 MacroAssembler* masm_; 96 MacroAssembler* masm_;
97 Label patch_site_; 97 Label patch_site_;
98 #ifdef DEBUG 98 #ifdef DEBUG
99 bool info_emitted_; 99 bool info_emitted_;
100 #endif 100 #endif
101 }; 101 };
102 102
103 103
104 static void EmitStackCheck(MacroAssembler* masm_) {
105 Label ok;
106 Isolate* isolate = masm_->isolate();
107 ExternalReference stack_limit =
108 ExternalReference::address_of_stack_limit(isolate);
109 __ cmp(esp, Operand::StaticVariable(stack_limit));
110 __ j(above_equal, &ok, Label::kNear);
111 __ call(isolate->builtins()->StackCheck(), RelocInfo::CODE_TARGET);
112 __ bind(&ok);
113 }
114
115
104 // Generate code for a JS function. On entry to the function the receiver 116 // Generate code for a JS function. On entry to the function the receiver
105 // and arguments have been pushed on the stack left to right, with the 117 // and arguments have been pushed on the stack left to right, with the
106 // return address on top of them. The actual argument count matches the 118 // return address on top of them. The actual argument count matches the
107 // formal parameter count expected by the function. 119 // formal parameter count expected by the function.
108 // 120 //
109 // The live registers are: 121 // The live registers are:
110 // o edi: the JS function object being called (i.e. ourselves) 122 // o edi: the JS function object being called (i.e. ourselves)
111 // o esi: our context 123 // o esi: our context
112 // o ebp: our caller's frame pointer 124 // o ebp: our caller's frame pointer
113 // o esp: stack pointer (pointing to return address) 125 // o esp: stack pointer (pointing to return address)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 info->AddNoFrameRange(0, masm_->pc_offset()); 177 info->AddNoFrameRange(0, masm_->pc_offset());
166 178
167 { Comment cmnt(masm_, "[ Allocate locals"); 179 { Comment cmnt(masm_, "[ Allocate locals");
168 int locals_count = info->scope()->num_stack_slots(); 180 int locals_count = info->scope()->num_stack_slots();
169 // Generators allocate locals, if any, in context slots. 181 // Generators allocate locals, if any, in context slots.
170 ASSERT(!info->function()->is_generator() || locals_count == 0); 182 ASSERT(!info->function()->is_generator() || locals_count == 0);
171 if (locals_count == 1) { 183 if (locals_count == 1) {
172 __ push(Immediate(isolate()->factory()->undefined_value())); 184 __ push(Immediate(isolate()->factory()->undefined_value()));
173 } else if (locals_count > 1) { 185 } else if (locals_count > 1) {
174 __ mov(eax, Immediate(isolate()->factory()->undefined_value())); 186 __ mov(eax, Immediate(isolate()->factory()->undefined_value()));
175 for (int i = 0; i < locals_count; i++) { 187 const int kTriggerStackLimitCheckCount = 128;
188 // Create a loop that pushes kTriggerStackLimitCheckCount undefines
189 // and performs a stack check.
190 if (locals_count >= kTriggerStackLimitCheckCount) {
191 PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS);
dcarney 2014/03/21 09:43:28 no idea what this does, whether it's the right bai
Yang 2014/03/21 09:52:22 I don't think we need this. I don't expect optimiz
192 int loop_iterations = locals_count / kTriggerStackLimitCheckCount;
193 __ mov(ecx, loop_iterations);
194 Label loop_header;
195 __ bind(&loop_header);
196 // Do pushes.
197 for (int i = 0; i < kTriggerStackLimitCheckCount; i++) {
198 __ push(eax);
199 }
200 // Do stack check.
201 EmitStackCheck(masm_);
202 // Continue loop if not done.
203 __ dec(ecx);
204 __ cmp(ecx, Immediate(Smi::FromInt(0)));
Yang 2014/03/21 09:52:22 No need for this cmp. dec also sets the flags. Jus
205 __ j(not_equal, &loop_header, Label::kNear);
206 }
207 int remaining = locals_count % kTriggerStackLimitCheckCount;
208 // Emit the remaining pushes.
209 for (int i = 0; i < remaining; i++) {
176 __ push(eax); 210 __ push(eax);
177 } 211 }
178 } 212 }
179 } 213 }
180 214
181 bool function_in_register = true; 215 bool function_in_register = true;
182 216
183 // Possibly allocate a local context. 217 // Possibly allocate a local context.
184 int heap_slots = info->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; 218 int heap_slots = info->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
185 if (heap_slots > 0) { 219 if (heap_slots > 0) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 ASSERT(function->proxy()->var()->mode() == CONST || 312 ASSERT(function->proxy()->var()->mode() == CONST ||
279 function->proxy()->var()->mode() == CONST_LEGACY); 313 function->proxy()->var()->mode() == CONST_LEGACY);
280 ASSERT(function->proxy()->var()->location() != Variable::UNALLOCATED); 314 ASSERT(function->proxy()->var()->location() != Variable::UNALLOCATED);
281 VisitVariableDeclaration(function); 315 VisitVariableDeclaration(function);
282 } 316 }
283 VisitDeclarations(scope()->declarations()); 317 VisitDeclarations(scope()->declarations());
284 } 318 }
285 319
286 { Comment cmnt(masm_, "[ Stack check"); 320 { Comment cmnt(masm_, "[ Stack check");
287 PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS); 321 PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS);
288 Label ok; 322 EmitStackCheck(masm_);
289 ExternalReference stack_limit =
290 ExternalReference::address_of_stack_limit(isolate());
291 __ cmp(esp, Operand::StaticVariable(stack_limit));
292 __ j(above_equal, &ok, Label::kNear);
293 __ call(isolate()->builtins()->StackCheck(), RelocInfo::CODE_TARGET);
294 __ bind(&ok);
295 } 323 }
296 324
297 { Comment cmnt(masm_, "[ Body"); 325 { Comment cmnt(masm_, "[ Body");
298 ASSERT(loop_depth() == 0); 326 ASSERT(loop_depth() == 0);
299 VisitStatements(function()->body()); 327 VisitStatements(function()->body());
300 ASSERT(loop_depth() == 0); 328 ASSERT(loop_depth() == 0);
301 } 329 }
302 } 330 }
303 331
304 // Always emit a 'return undefined' in case control fell off the end of 332 // Always emit a 'return undefined' in case control fell off the end of
(...skipping 4598 matching lines...) Expand 10 before | Expand all | Expand 10 after
4903 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), 4931 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(),
4904 Assembler::target_address_at(call_target_address, 4932 Assembler::target_address_at(call_target_address,
4905 unoptimized_code)); 4933 unoptimized_code));
4906 return OSR_AFTER_STACK_CHECK; 4934 return OSR_AFTER_STACK_CHECK;
4907 } 4935 }
4908 4936
4909 4937
4910 } } // namespace v8::internal 4938 } } // namespace v8::internal
4911 4939
4912 #endif // V8_TARGET_ARCH_IA32 4940 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698