OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 frame_->Enter(); | 319 frame_->Enter(); |
320 | 320 |
321 // Allocate space for locals and initialize them. | 321 // Allocate space for locals and initialize them. |
322 frame_->AllocateStackSlots(); | 322 frame_->AllocateStackSlots(); |
323 // Initialize the function return target after the locals are set | 323 // Initialize the function return target after the locals are set |
324 // up, because it needs the expected frame height from the frame. | 324 // up, because it needs the expected frame height from the frame. |
325 function_return_.set_direction(JumpTarget::BIDIRECTIONAL); | 325 function_return_.set_direction(JumpTarget::BIDIRECTIONAL); |
326 function_return_is_shadowed_ = false; | 326 function_return_is_shadowed_ = false; |
327 | 327 |
328 // Allocate the local context if needed. | 328 // Allocate the local context if needed. |
329 if (scope_->num_heap_slots() > 0) { | 329 int heap_slots = scope_->num_heap_slots(); |
| 330 if (heap_slots > 0) { |
330 Comment cmnt(masm_, "[ allocate local context"); | 331 Comment cmnt(masm_, "[ allocate local context"); |
331 // Allocate local context. | 332 // Allocate local context. |
332 // Get outer context and create a new context based on it. | 333 // Get outer context and create a new context based on it. |
333 frame_->PushFunction(); | 334 frame_->PushFunction(); |
334 Result context = frame_->CallRuntime(Runtime::kNewContext, 1); | 335 Result context; |
| 336 if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
| 337 FastNewContextStub stub(heap_slots); |
| 338 context = frame_->CallStub(&stub, 1); |
| 339 } else { |
| 340 context = frame_->CallRuntime(Runtime::kNewContext, 1); |
| 341 } |
335 | 342 |
336 // Update context local. | 343 // Update context local. |
337 frame_->SaveContextRegister(); | 344 frame_->SaveContextRegister(); |
338 | 345 |
339 // Verify that the runtime call result and rsi agree. | 346 // Verify that the runtime call result and rsi agree. |
340 if (FLAG_debug_code) { | 347 if (FLAG_debug_code) { |
341 __ cmpq(context.reg(), rsi); | 348 __ cmpq(context.reg(), rsi); |
342 __ Assert(equal, "Runtime::NewContext should end up in rsi"); | 349 __ Assert(equal, "Runtime::NewContext should end up in rsi"); |
343 } | 350 } |
344 } | 351 } |
(...skipping 5758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6103 __ bind(&gc); | 6110 __ bind(&gc); |
6104 __ pop(rcx); // Temporarily remove return address. | 6111 __ pop(rcx); // Temporarily remove return address. |
6105 __ pop(rdx); | 6112 __ pop(rdx); |
6106 __ push(rsi); | 6113 __ push(rsi); |
6107 __ push(rdx); | 6114 __ push(rdx); |
6108 __ push(rcx); // Restore return address. | 6115 __ push(rcx); // Restore return address. |
6109 __ TailCallRuntime(ExternalReference(Runtime::kNewClosure), 2, 1); | 6116 __ TailCallRuntime(ExternalReference(Runtime::kNewClosure), 2, 1); |
6110 } | 6117 } |
6111 | 6118 |
6112 | 6119 |
| 6120 void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 6121 // Try to allocate the context in new space. |
| 6122 Label gc; |
| 6123 int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 6124 __ AllocateInNewSpace((length * kPointerSize) + FixedArray::kHeaderSize, |
| 6125 rax, rbx, rcx, &gc, TAG_OBJECT); |
| 6126 |
| 6127 // Get the function from the stack. |
| 6128 __ movq(rcx, Operand(rsp, 1 * kPointerSize)); |
| 6129 |
| 6130 // Setup the object header. |
| 6131 __ LoadRoot(kScratchRegister, Heap::kContextMapRootIndex); |
| 6132 __ movq(FieldOperand(rax, HeapObject::kMapOffset), kScratchRegister); |
| 6133 __ movl(FieldOperand(rax, Array::kLengthOffset), Immediate(length)); |
| 6134 |
| 6135 // Setup the fixed slots. |
| 6136 __ xor_(rbx, rbx); // Set to NULL. |
| 6137 __ movq(Operand(rax, Context::SlotOffset(Context::CLOSURE_INDEX)), rcx); |
| 6138 __ movq(Operand(rax, Context::SlotOffset(Context::FCONTEXT_INDEX)), rax); |
| 6139 __ movq(Operand(rax, Context::SlotOffset(Context::PREVIOUS_INDEX)), rbx); |
| 6140 __ movq(Operand(rax, Context::SlotOffset(Context::EXTENSION_INDEX)), rbx); |
| 6141 |
| 6142 // Copy the global object from the surrounding context. |
| 6143 __ movq(rbx, Operand(rsi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 6144 __ movq(Operand(rax, Context::SlotOffset(Context::GLOBAL_INDEX)), rbx); |
| 6145 |
| 6146 // Initialize the rest of the slots to undefined. |
| 6147 __ LoadRoot(rbx, Heap::kUndefinedValueRootIndex); |
| 6148 for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
| 6149 __ movq(Operand(rax, Context::SlotOffset(i)), rbx); |
| 6150 } |
| 6151 |
| 6152 // Return and remove the on-stack parameter. |
| 6153 __ movq(rsi, rax); |
| 6154 __ ret(1 * kPointerSize); |
| 6155 |
| 6156 // Need to collect. Call into runtime system. |
| 6157 __ bind(&gc); |
| 6158 __ TailCallRuntime(ExternalReference(Runtime::kNewContext), 1, 1); |
| 6159 } |
| 6160 |
| 6161 |
6113 void ToBooleanStub::Generate(MacroAssembler* masm) { | 6162 void ToBooleanStub::Generate(MacroAssembler* masm) { |
6114 Label false_result, true_result, not_string; | 6163 Label false_result, true_result, not_string; |
6115 __ movq(rax, Operand(rsp, 1 * kPointerSize)); | 6164 __ movq(rax, Operand(rsp, 1 * kPointerSize)); |
6116 | 6165 |
6117 // 'null' => false. | 6166 // 'null' => false. |
6118 __ CompareRoot(rax, Heap::kNullValueRootIndex); | 6167 __ CompareRoot(rax, Heap::kNullValueRootIndex); |
6119 __ j(equal, &false_result); | 6168 __ j(equal, &false_result); |
6120 | 6169 |
6121 // Get the map and type of the heap object. | 6170 // Get the map and type of the heap object. |
6122 // We don't use CmpObjectType because we manipulate the type field. | 6171 // We don't use CmpObjectType because we manipulate the type field. |
(...skipping 2044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8167 masm.GetCode(&desc); | 8216 masm.GetCode(&desc); |
8168 // Call the function from C++. | 8217 // Call the function from C++. |
8169 return FUNCTION_CAST<ModuloFunction>(buffer); | 8218 return FUNCTION_CAST<ModuloFunction>(buffer); |
8170 } | 8219 } |
8171 | 8220 |
8172 #endif | 8221 #endif |
8173 | 8222 |
8174 #undef __ | 8223 #undef __ |
8175 | 8224 |
8176 } } // namespace v8::internal | 8225 } } // namespace v8::internal |
OLD | NEW |