OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #if V8_TARGET_ARCH_IA32 | 7 #if V8_TARGET_ARCH_IA32 |
8 | 8 |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 } | 71 } |
72 | 72 |
73 MacroAssembler* masm_; | 73 MacroAssembler* masm_; |
74 Label patch_site_; | 74 Label patch_site_; |
75 #ifdef DEBUG | 75 #ifdef DEBUG |
76 bool info_emitted_; | 76 bool info_emitted_; |
77 #endif | 77 #endif |
78 }; | 78 }; |
79 | 79 |
80 | 80 |
81 static void EmitStackCheck(MacroAssembler* masm_, | |
82 int pointers = 0, | |
83 Register scratch = esp) { | |
84 Label ok; | |
85 Isolate* isolate = masm_->isolate(); | |
86 ASSERT(scratch.is(esp) == (pointers == 0)); | |
87 ExternalReference stack_limit; | |
88 if (pointers != 0) { | |
89 __ mov(scratch, esp); | |
90 __ sub(scratch, Immediate(pointers * kPointerSize)); | |
91 stack_limit = ExternalReference::address_of_real_stack_limit(isolate); | |
92 } else { | |
93 stack_limit = ExternalReference::address_of_stack_limit(isolate); | |
94 } | |
95 __ cmp(scratch, Operand::StaticVariable(stack_limit)); | |
96 __ j(above_equal, &ok, Label::kNear); | |
97 __ call(isolate->builtins()->StackCheck(), RelocInfo::CODE_TARGET); | |
98 __ bind(&ok); | |
99 } | |
100 | |
101 | |
102 // Generate code for a JS function. On entry to the function the receiver | 81 // Generate code for a JS function. On entry to the function the receiver |
103 // and arguments have been pushed on the stack left to right, with the | 82 // and arguments have been pushed on the stack left to right, with the |
104 // return address on top of them. The actual argument count matches the | 83 // return address on top of them. The actual argument count matches the |
105 // formal parameter count expected by the function. | 84 // formal parameter count expected by the function. |
106 // | 85 // |
107 // The live registers are: | 86 // The live registers are: |
108 // o edi: the JS function object being called (i.e. ourselves) | 87 // o edi: the JS function object being called (i.e. ourselves) |
109 // o esi: our context | 88 // o esi: our context |
110 // o ebp: our caller's frame pointer | 89 // o ebp: our caller's frame pointer |
111 // o esp: stack pointer (pointing to return address) | 90 // o esp: stack pointer (pointing to return address) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 info->AddNoFrameRange(0, masm_->pc_offset()); | 140 info->AddNoFrameRange(0, masm_->pc_offset()); |
162 | 141 |
163 { Comment cmnt(masm_, "[ Allocate locals"); | 142 { Comment cmnt(masm_, "[ Allocate locals"); |
164 int locals_count = info->scope()->num_stack_slots(); | 143 int locals_count = info->scope()->num_stack_slots(); |
165 // Generators allocate locals, if any, in context slots. | 144 // Generators allocate locals, if any, in context slots. |
166 ASSERT(!info->function()->is_generator() || locals_count == 0); | 145 ASSERT(!info->function()->is_generator() || locals_count == 0); |
167 if (locals_count == 1) { | 146 if (locals_count == 1) { |
168 __ push(Immediate(isolate()->factory()->undefined_value())); | 147 __ push(Immediate(isolate()->factory()->undefined_value())); |
169 } else if (locals_count > 1) { | 148 } else if (locals_count > 1) { |
170 if (locals_count >= 128) { | 149 if (locals_count >= 128) { |
171 EmitStackCheck(masm_, locals_count, ecx); | 150 Label ok; |
| 151 __ mov(ecx, esp); |
| 152 __ sub(ecx, Immediate(locals_count * kPointerSize)); |
| 153 ExternalReference stack_limit = |
| 154 ExternalReference::address_of_real_stack_limit(isolate()); |
| 155 __ cmp(ecx, Operand::StaticVariable(stack_limit)); |
| 156 __ j(above_equal, &ok, Label::kNear); |
| 157 __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION); |
| 158 __ bind(&ok); |
172 } | 159 } |
173 __ mov(eax, Immediate(isolate()->factory()->undefined_value())); | 160 __ mov(eax, Immediate(isolate()->factory()->undefined_value())); |
174 const int kMaxPushes = 32; | 161 const int kMaxPushes = 32; |
175 if (locals_count >= kMaxPushes) { | 162 if (locals_count >= kMaxPushes) { |
176 int loop_iterations = locals_count / kMaxPushes; | 163 int loop_iterations = locals_count / kMaxPushes; |
177 __ mov(ecx, loop_iterations); | 164 __ mov(ecx, loop_iterations); |
178 Label loop_header; | 165 Label loop_header; |
179 __ bind(&loop_header); | 166 __ bind(&loop_header); |
180 // Do pushes. | 167 // Do pushes. |
181 for (int i = 0; i < kMaxPushes; i++) { | 168 for (int i = 0; i < kMaxPushes; i++) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 ASSERT(function->proxy()->var()->mode() == CONST || | 289 ASSERT(function->proxy()->var()->mode() == CONST || |
303 function->proxy()->var()->mode() == CONST_LEGACY); | 290 function->proxy()->var()->mode() == CONST_LEGACY); |
304 ASSERT(function->proxy()->var()->location() != Variable::UNALLOCATED); | 291 ASSERT(function->proxy()->var()->location() != Variable::UNALLOCATED); |
305 VisitVariableDeclaration(function); | 292 VisitVariableDeclaration(function); |
306 } | 293 } |
307 VisitDeclarations(scope()->declarations()); | 294 VisitDeclarations(scope()->declarations()); |
308 } | 295 } |
309 | 296 |
310 { Comment cmnt(masm_, "[ Stack check"); | 297 { Comment cmnt(masm_, "[ Stack check"); |
311 PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS); | 298 PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS); |
312 EmitStackCheck(masm_); | 299 Label ok; |
| 300 ExternalReference stack_limit |
| 301 = ExternalReference::address_of_stack_limit(isolate()); |
| 302 __ cmp(esp, Operand::StaticVariable(stack_limit)); |
| 303 __ j(above_equal, &ok, Label::kNear); |
| 304 __ call(isolate()->builtins()->StackCheck(), RelocInfo::CODE_TARGET); |
| 305 __ bind(&ok); |
313 } | 306 } |
314 | 307 |
315 { Comment cmnt(masm_, "[ Body"); | 308 { Comment cmnt(masm_, "[ Body"); |
316 ASSERT(loop_depth() == 0); | 309 ASSERT(loop_depth() == 0); |
317 VisitStatements(function()->body()); | 310 VisitStatements(function()->body()); |
318 ASSERT(loop_depth() == 0); | 311 ASSERT(loop_depth() == 0); |
319 } | 312 } |
320 } | 313 } |
321 | 314 |
322 // Always emit a 'return undefined' in case control fell off the end of | 315 // Always emit a 'return undefined' in case control fell off the end of |
(...skipping 4473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4796 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 4789 ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
4797 Assembler::target_address_at(call_target_address, | 4790 Assembler::target_address_at(call_target_address, |
4798 unoptimized_code)); | 4791 unoptimized_code)); |
4799 return OSR_AFTER_STACK_CHECK; | 4792 return OSR_AFTER_STACK_CHECK; |
4800 } | 4793 } |
4801 | 4794 |
4802 | 4795 |
4803 } } // namespace v8::internal | 4796 } } // namespace v8::internal |
4804 | 4797 |
4805 #endif // V8_TARGET_ARCH_IA32 | 4798 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |