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

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: rebase 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 | « src/arm64/simulator-arm64.cc ('k') | src/x64/full-codegen-x64.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 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 int pointers = 0,
106 Register scratch = esp) {
107 Label ok;
108 Isolate* isolate = masm_->isolate();
109 ExternalReference stack_limit =
110 ExternalReference::address_of_stack_limit(isolate);
111 ASSERT(scratch.is(esp) == (pointers == 0));
112 if (pointers != 0) {
113 __ mov(scratch, esp);
114 __ sub(scratch, Immediate(pointers * kPointerSize));
115 }
116 __ cmp(scratch, Operand::StaticVariable(stack_limit));
117 __ j(above_equal, &ok, Label::kNear);
118 __ call(isolate->builtins()->StackCheck(), RelocInfo::CODE_TARGET);
119 __ bind(&ok);
120 }
121
122
104 // Generate code for a JS function. On entry to the function the receiver 123 // 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 124 // 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 125 // return address on top of them. The actual argument count matches the
107 // formal parameter count expected by the function. 126 // formal parameter count expected by the function.
108 // 127 //
109 // The live registers are: 128 // The live registers are:
110 // o edi: the JS function object being called (i.e. ourselves) 129 // o edi: the JS function object being called (i.e. ourselves)
111 // o esi: our context 130 // o esi: our context
112 // o ebp: our caller's frame pointer 131 // o ebp: our caller's frame pointer
113 // o esp: stack pointer (pointing to return address) 132 // o esp: stack pointer (pointing to return address)
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 __ Prologue(BUILD_FUNCTION_FRAME); 183 __ Prologue(BUILD_FUNCTION_FRAME);
165 info->AddNoFrameRange(0, masm_->pc_offset()); 184 info->AddNoFrameRange(0, masm_->pc_offset());
166 185
167 { Comment cmnt(masm_, "[ Allocate locals"); 186 { Comment cmnt(masm_, "[ Allocate locals");
168 int locals_count = info->scope()->num_stack_slots(); 187 int locals_count = info->scope()->num_stack_slots();
169 // Generators allocate locals, if any, in context slots. 188 // Generators allocate locals, if any, in context slots.
170 ASSERT(!info->function()->is_generator() || locals_count == 0); 189 ASSERT(!info->function()->is_generator() || locals_count == 0);
171 if (locals_count == 1) { 190 if (locals_count == 1) {
172 __ push(Immediate(isolate()->factory()->undefined_value())); 191 __ push(Immediate(isolate()->factory()->undefined_value()));
173 } else if (locals_count > 1) { 192 } else if (locals_count > 1) {
193 if (locals_count >= 128) {
194 EmitStackCheck(masm_, locals_count, ecx);
195 }
174 __ mov(eax, Immediate(isolate()->factory()->undefined_value())); 196 __ mov(eax, Immediate(isolate()->factory()->undefined_value()));
175 for (int i = 0; i < locals_count; i++) { 197 const int kMaxPushes = 32;
198 if (locals_count >= kMaxPushes) {
199 int loop_iterations = locals_count / kMaxPushes;
200 __ mov(ecx, loop_iterations);
201 Label loop_header;
202 __ bind(&loop_header);
203 // Do pushes.
204 for (int i = 0; i < kMaxPushes; i++) {
205 __ push(eax);
206 }
207 __ dec(ecx);
208 __ j(not_zero, &loop_header, Label::kNear);
209 }
210 int remaining = locals_count % kMaxPushes;
211 // Emit the remaining pushes.
212 for (int i = 0; i < remaining; i++) {
176 __ push(eax); 213 __ push(eax);
177 } 214 }
178 } 215 }
179 } 216 }
180 217
181 bool function_in_register = true; 218 bool function_in_register = true;
182 219
183 // Possibly allocate a local context. 220 // Possibly allocate a local context.
184 int heap_slots = info->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; 221 int heap_slots = info->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
185 if (heap_slots > 0) { 222 if (heap_slots > 0) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 ASSERT(function->proxy()->var()->mode() == CONST || 315 ASSERT(function->proxy()->var()->mode() == CONST ||
279 function->proxy()->var()->mode() == CONST_LEGACY); 316 function->proxy()->var()->mode() == CONST_LEGACY);
280 ASSERT(function->proxy()->var()->location() != Variable::UNALLOCATED); 317 ASSERT(function->proxy()->var()->location() != Variable::UNALLOCATED);
281 VisitVariableDeclaration(function); 318 VisitVariableDeclaration(function);
282 } 319 }
283 VisitDeclarations(scope()->declarations()); 320 VisitDeclarations(scope()->declarations());
284 } 321 }
285 322
286 { Comment cmnt(masm_, "[ Stack check"); 323 { Comment cmnt(masm_, "[ Stack check");
287 PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS); 324 PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS);
288 Label ok; 325 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 } 326 }
296 327
297 { Comment cmnt(masm_, "[ Body"); 328 { Comment cmnt(masm_, "[ Body");
298 ASSERT(loop_depth() == 0); 329 ASSERT(loop_depth() == 0);
299 VisitStatements(function()->body()); 330 VisitStatements(function()->body());
300 ASSERT(loop_depth() == 0); 331 ASSERT(loop_depth() == 0);
301 } 332 }
302 } 333 }
303 334
304 // Always emit a 'return undefined' in case control fell off the end of 335 // 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(), 4934 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(),
4904 Assembler::target_address_at(call_target_address, 4935 Assembler::target_address_at(call_target_address,
4905 unoptimized_code)); 4936 unoptimized_code));
4906 return OSR_AFTER_STACK_CHECK; 4937 return OSR_AFTER_STACK_CHECK;
4907 } 4938 }
4908 4939
4909 4940
4910 } } // namespace v8::internal 4941 } } // namespace v8::internal
4911 4942
4912 #endif // V8_TARGET_ARCH_IA32 4943 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/arm64/simulator-arm64.cc ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698