| OLD | NEW |
| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 status_ = GENERATING; | 72 status_ = GENERATING; |
| 73 CpuFeatures::Scope scope(SSE2); | 73 CpuFeatures::Scope scope(SSE2); |
| 74 | 74 |
| 75 CodeStub::GenerateFPStubs(); | 75 CodeStub::GenerateFPStubs(); |
| 76 | 76 |
| 77 // Open a frame scope to indicate that there is a frame on the stack. The | 77 // Open a frame scope to indicate that there is a frame on the stack. The |
| 78 // MANUAL indicates that the scope shouldn't actually generate code to set up | 78 // MANUAL indicates that the scope shouldn't actually generate code to set up |
| 79 // the frame (that is done in GeneratePrologue). | 79 // the frame (that is done in GeneratePrologue). |
| 80 FrameScope frame_scope(masm_, StackFrame::MANUAL); | 80 FrameScope frame_scope(masm_, StackFrame::MANUAL); |
| 81 | 81 |
| 82 dynamic_frame_alignment_ = chunk()->num_double_slots() > 2 || |
| 83 info()->osr_ast_id() != AstNode::kNoNumber; |
| 84 |
| 82 return GeneratePrologue() && | 85 return GeneratePrologue() && |
| 83 GenerateBody() && | 86 GenerateBody() && |
| 84 GenerateDeferredCode() && | 87 GenerateDeferredCode() && |
| 85 GenerateSafepointTable(); | 88 GenerateSafepointTable(); |
| 86 } | 89 } |
| 87 | 90 |
| 88 | 91 |
| 89 void LCodeGen::FinishCode(Handle<Code> code) { | 92 void LCodeGen::FinishCode(Handle<Code> code) { |
| 90 ASSERT(is_done()); | 93 ASSERT(is_done()); |
| 91 code->set_stack_slots(GetStackSlotCount()); | 94 code->set_stack_slots(GetStackSlotCount()); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 Label ok; | 149 Label ok; |
| 147 __ test(ecx, Operand(ecx)); | 150 __ test(ecx, Operand(ecx)); |
| 148 __ j(zero, &ok, Label::kNear); | 151 __ j(zero, &ok, Label::kNear); |
| 149 // +1 for return address. | 152 // +1 for return address. |
| 150 int receiver_offset = (scope()->num_parameters() + 1) * kPointerSize; | 153 int receiver_offset = (scope()->num_parameters() + 1) * kPointerSize; |
| 151 __ mov(Operand(esp, receiver_offset), | 154 __ mov(Operand(esp, receiver_offset), |
| 152 Immediate(isolate()->factory()->undefined_value())); | 155 Immediate(isolate()->factory()->undefined_value())); |
| 153 __ bind(&ok); | 156 __ bind(&ok); |
| 154 } | 157 } |
| 155 | 158 |
| 159 __ mov(edx, Immediate(0)); |
| 160 |
| 161 if (dynamic_frame_alignment_) { |
| 162 Label do_not_pad, align_loop; |
| 163 STATIC_ASSERT(kDoubleSize == 2 * kPointerSize); |
| 164 // Align esp to a multiple of 2 * kPointerSize. |
| 165 __ test(esp, Immediate(kPointerSize)); |
| 166 __ j(zero, &do_not_pad, Label::kNear); |
| 167 __ push(Immediate(0)); |
| 168 __ mov(ebx, esp); |
| 169 __ mov(edx, Immediate(2)); |
| 170 // Copy arguments, receiver, and return address. |
| 171 __ mov(ecx, Immediate(scope()->num_parameters() + 2)); |
| 172 |
| 173 __ bind(&align_loop); |
| 174 __ mov(eax, Operand(ebx, 1 * kPointerSize)); |
| 175 __ mov(Operand(ebx, 0), eax); |
| 176 __ add(Operand(ebx), Immediate(kPointerSize)); |
| 177 __ dec(ecx); |
| 178 __ j(not_zero, &align_loop, Label::kNear); |
| 179 __ mov(Operand(ebx, 0), |
| 180 Immediate(Smi::FromInt(0x12345))); |
| 181 __ bind(&do_not_pad); |
| 182 } |
| 183 |
| 156 __ push(ebp); // Caller's frame pointer. | 184 __ push(ebp); // Caller's frame pointer. |
| 157 __ mov(ebp, esp); | 185 __ mov(ebp, esp); |
| 158 __ push(esi); // Callee's context. | 186 __ push(esi); // Callee's context. |
| 159 __ push(edi); // Callee's JS function. | 187 __ push(edi); // Callee's JS function. |
| 160 | 188 |
| 161 // Reserve space for the stack slots needed by the code. | 189 // Reserve space for the stack slots needed by the code. |
| 162 int slots = GetStackSlotCount(); | 190 int slots = GetStackSlotCount(); |
| 191 CHECK(slots >= 1); |
| 163 if (slots > 0) { | 192 if (slots > 0) { |
| 164 if (FLAG_debug_code) { | 193 if (FLAG_debug_code) { |
| 165 __ mov(Operand(eax), Immediate(slots)); | 194 __ mov(Operand(eax), Immediate(slots)); |
| 166 Label loop; | 195 Label loop; |
| 167 __ bind(&loop); | 196 __ bind(&loop); |
| 168 __ push(Immediate(kSlotsZapValue)); | 197 __ push(Immediate(kSlotsZapValue)); |
| 169 __ dec(eax); | 198 __ dec(eax); |
| 170 __ j(not_zero, &loop); | 199 __ j(not_zero, &loop); |
| 171 } else { | 200 } else { |
| 172 __ sub(Operand(esp), Immediate(slots * kPointerSize)); | 201 __ sub(Operand(esp), Immediate(slots * kPointerSize)); |
| 173 #ifdef _MSC_VER | 202 #ifdef _MSC_VER |
| 174 // On windows, you may not access the stack more than one page below | 203 // On windows, you may not access the stack more than one page below |
| 175 // the most recently mapped page. To make the allocated area randomly | 204 // the most recently mapped page. To make the allocated area randomly |
| 176 // accessible, we write to each page in turn (the value is irrelevant). | 205 // accessible, we write to each page in turn (the value is irrelevant). |
| 177 const int kPageSize = 4 * KB; | 206 const int kPageSize = 4 * KB; |
| 178 for (int offset = slots * kPointerSize - kPageSize; | 207 for (int offset = slots * kPointerSize - kPageSize; |
| 179 offset > 0; | 208 offset > 0; |
| 180 offset -= kPageSize) { | 209 offset -= kPageSize) { |
| 181 __ mov(Operand(esp, offset), eax); | 210 __ mov(Operand(esp, offset), eax); |
| 182 } | 211 } |
| 183 #endif | 212 #endif |
| 184 } | 213 } |
| 185 } | 214 } |
| 215 __ mov(Operand(ebp, JavaScriptFrameConstants::kLocal0Offset), edx); |
| 186 | 216 |
| 187 // Possibly allocate a local context. | 217 // Possibly allocate a local context. |
| 188 int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; | 218 int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
| 189 if (heap_slots > 0) { | 219 if (heap_slots > 0) { |
| 190 Comment(";;; Allocate local context"); | 220 Comment(";;; Allocate local context"); |
| 191 // Argument to NewContext is the function, which is still in edi. | 221 // Argument to NewContext is the function, which is still in edi. |
| 192 __ push(edi); | 222 __ push(edi); |
| 193 if (heap_slots <= FastNewContextStub::kMaximumSlots) { | 223 if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
| 194 FastNewContextStub stub(heap_slots); | 224 FastNewContextStub stub(heap_slots); |
| 195 __ CallStub(&stub); | 225 __ CallStub(&stub); |
| (...skipping 1895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2091 void LCodeGen::DoReturn(LReturn* instr) { | 2121 void LCodeGen::DoReturn(LReturn* instr) { |
| 2092 if (FLAG_trace) { | 2122 if (FLAG_trace) { |
| 2093 // Preserve the return value on the stack and rely on the runtime call | 2123 // Preserve the return value on the stack and rely on the runtime call |
| 2094 // to return the value in the same register. We're leaving the code | 2124 // to return the value in the same register. We're leaving the code |
| 2095 // managed by the register allocator and tearing down the frame, it's | 2125 // managed by the register allocator and tearing down the frame, it's |
| 2096 // safe to write to the context register. | 2126 // safe to write to the context register. |
| 2097 __ push(eax); | 2127 __ push(eax); |
| 2098 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | 2128 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 2099 __ CallRuntime(Runtime::kTraceExit, 1); | 2129 __ CallRuntime(Runtime::kTraceExit, 1); |
| 2100 } | 2130 } |
| 2131 if (dynamic_frame_alignment_) { |
| 2132 __ mov(edx, Operand(ebp, JavaScriptFrameConstants::kLocal0Offset)); |
| 2133 } |
| 2101 __ mov(esp, ebp); | 2134 __ mov(esp, ebp); |
| 2102 __ pop(ebp); | 2135 __ pop(ebp); |
| 2136 if (dynamic_frame_alignment_) { |
| 2137 Label aligned; |
| 2138 __ cmp(edx, Immediate(0)); |
| 2139 __ j(equal, &aligned); |
| 2140 __ cmp(Operand(esp, (GetParameterCount() + 2) * kPointerSize), |
| 2141 Immediate(Smi::FromInt(0x12345))); |
| 2142 __ Assert(equal, "expected alignment marker"); |
| 2143 __ Ret((GetParameterCount() + 2) * kPointerSize, ecx); |
| 2144 __ bind(&aligned); |
| 2145 } |
| 2103 __ Ret((GetParameterCount() + 1) * kPointerSize, ecx); | 2146 __ Ret((GetParameterCount() + 1) * kPointerSize, ecx); |
| 2104 } | 2147 } |
| 2105 | 2148 |
| 2106 | 2149 |
| 2107 void LCodeGen::DoLoadGlobalCell(LLoadGlobalCell* instr) { | 2150 void LCodeGen::DoLoadGlobalCell(LLoadGlobalCell* instr) { |
| 2108 Register result = ToRegister(instr->result()); | 2151 Register result = ToRegister(instr->result()); |
| 2109 __ mov(result, Operand::Cell(instr->hydrogen()->cell())); | 2152 __ mov(result, Operand::Cell(instr->hydrogen()->cell())); |
| 2110 if (instr->hydrogen()->RequiresHoleCheck()) { | 2153 if (instr->hydrogen()->RequiresHoleCheck()) { |
| 2111 __ cmp(result, factory()->the_hole_value()); | 2154 __ cmp(result, factory()->the_hole_value()); |
| 2112 DeoptimizeIf(equal, instr->environment()); | 2155 DeoptimizeIf(equal, instr->environment()); |
| (...skipping 2991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5104 FixedArray::kHeaderSize - kPointerSize)); | 5147 FixedArray::kHeaderSize - kPointerSize)); |
| 5105 __ bind(&done); | 5148 __ bind(&done); |
| 5106 } | 5149 } |
| 5107 | 5150 |
| 5108 | 5151 |
| 5109 #undef __ | 5152 #undef __ |
| 5110 | 5153 |
| 5111 } } // namespace v8::internal | 5154 } } // namespace v8::internal |
| 5112 | 5155 |
| 5113 #endif // V8_TARGET_ARCH_IA32 | 5156 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |