| 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_X64 | 7 #if V8_TARGET_ARCH_X64 | 
| 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 = rsp) { |  | 
| 84     Isolate* isolate = masm_->isolate(); |  | 
| 85     Label ok; |  | 
| 86     ASSERT(scratch.is(rsp) == (pointers == 0)); |  | 
| 87     Heap::RootListIndex index; |  | 
| 88     if (pointers != 0) { |  | 
| 89       __ movp(scratch, rsp); |  | 
| 90       __ subp(scratch, Immediate(pointers * kPointerSize)); |  | 
| 91       index = Heap::kRealStackLimitRootIndex; |  | 
| 92     } else { |  | 
| 93       index = Heap::kStackLimitRootIndex; |  | 
| 94     } |  | 
| 95     __ CompareRoot(scratch, index); |  | 
| 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 rdi: the JS function object being called (i.e. ourselves) | 87 //   o rdi: the JS function object being called (i.e. ourselves) | 
| 109 //   o rsi: our context | 88 //   o rsi: our context | 
| 110 //   o rbp: our caller's frame pointer | 89 //   o rbp: our caller's frame pointer | 
| 111 //   o rsp: stack pointer (pointing to return address) | 90 //   o rsp: 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       __ PushRoot(Heap::kUndefinedValueRootIndex); | 147       __ PushRoot(Heap::kUndefinedValueRootIndex); | 
| 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, rcx); | 150         Label ok; | 
|  | 151         __ movp(rcx, rsp); | 
|  | 152         __ subp(rcx, Immediate(locals_count * kPointerSize)); | 
|  | 153         __ CompareRoot(rcx, Heap::kRealStackLimitRootIndex); | 
|  | 154         __ j(above_equal, &ok, Label::kNear); | 
|  | 155         __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION); | 
|  | 156         __ bind(&ok); | 
| 172       } | 157       } | 
| 173       __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); | 158       __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); | 
| 174       const int kMaxPushes = 32; | 159       const int kMaxPushes = 32; | 
| 175       if (locals_count >= kMaxPushes) { | 160       if (locals_count >= kMaxPushes) { | 
| 176         int loop_iterations = locals_count / kMaxPushes; | 161         int loop_iterations = locals_count / kMaxPushes; | 
| 177         __ movp(rcx, Immediate(loop_iterations)); | 162         __ movp(rcx, Immediate(loop_iterations)); | 
| 178         Label loop_header; | 163         Label loop_header; | 
| 179         __ bind(&loop_header); | 164         __ bind(&loop_header); | 
| 180         // Do pushes. | 165         // Do pushes. | 
| 181         for (int i = 0; i < kMaxPushes; i++) { | 166         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 || | 287         ASSERT(function->proxy()->var()->mode() == CONST || | 
| 303                function->proxy()->var()->mode() == CONST_LEGACY); | 288                function->proxy()->var()->mode() == CONST_LEGACY); | 
| 304         ASSERT(function->proxy()->var()->location() != Variable::UNALLOCATED); | 289         ASSERT(function->proxy()->var()->location() != Variable::UNALLOCATED); | 
| 305         VisitVariableDeclaration(function); | 290         VisitVariableDeclaration(function); | 
| 306       } | 291       } | 
| 307       VisitDeclarations(scope()->declarations()); | 292       VisitDeclarations(scope()->declarations()); | 
| 308     } | 293     } | 
| 309 | 294 | 
| 310     { Comment cmnt(masm_, "[ Stack check"); | 295     { Comment cmnt(masm_, "[ Stack check"); | 
| 311       PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS); | 296       PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS); | 
| 312       EmitStackCheck(masm_); | 297        Label ok; | 
|  | 298        __ CompareRoot(rsp, Heap::kStackLimitRootIndex); | 
|  | 299        __ j(above_equal, &ok, Label::kNear); | 
|  | 300        __ call(isolate()->builtins()->StackCheck(), RelocInfo::CODE_TARGET); | 
|  | 301        __ bind(&ok); | 
| 313     } | 302     } | 
| 314 | 303 | 
| 315     { Comment cmnt(masm_, "[ Body"); | 304     { Comment cmnt(masm_, "[ Body"); | 
| 316       ASSERT(loop_depth() == 0); | 305       ASSERT(loop_depth() == 0); | 
| 317       VisitStatements(function()->body()); | 306       VisitStatements(function()->body()); | 
| 318       ASSERT(loop_depth() == 0); | 307       ASSERT(loop_depth() == 0); | 
| 319     } | 308     } | 
| 320   } | 309   } | 
| 321 | 310 | 
| 322   // Always emit a 'return undefined' in case control fell off the end of | 311   // Always emit a 'return undefined' in case control fell off the end of | 
| (...skipping 4480 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 4803   ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 4792   ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 
| 4804             Assembler::target_address_at(call_target_address, | 4793             Assembler::target_address_at(call_target_address, | 
| 4805                                          unoptimized_code)); | 4794                                          unoptimized_code)); | 
| 4806   return OSR_AFTER_STACK_CHECK; | 4795   return OSR_AFTER_STACK_CHECK; | 
| 4807 } | 4796 } | 
| 4808 | 4797 | 
| 4809 | 4798 | 
| 4810 } }  // namespace v8::internal | 4799 } }  // namespace v8::internal | 
| 4811 | 4800 | 
| 4812 #endif  // V8_TARGET_ARCH_X64 | 4801 #endif  // V8_TARGET_ARCH_X64 | 
| OLD | NEW | 
|---|