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

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

Powered by Google App Engine
This is Rietveld 408576698