| 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-factory.h" | 9 #include "src/code-factory.h" |
| 10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 __ j(above_equal, &ok); | 92 __ j(above_equal, &ok); |
| 93 | 93 |
| 94 CallRuntimePassFunction(masm, Runtime::kTryInstallOptimizedCode); | 94 CallRuntimePassFunction(masm, Runtime::kTryInstallOptimizedCode); |
| 95 GenerateTailCallToReturnedCode(masm); | 95 GenerateTailCallToReturnedCode(masm); |
| 96 | 96 |
| 97 __ bind(&ok); | 97 __ bind(&ok); |
| 98 GenerateTailCallToSharedCode(masm); | 98 GenerateTailCallToSharedCode(masm); |
| 99 } | 99 } |
| 100 | 100 |
| 101 | 101 |
| 102 static void Generate_Runtime_NewObject(MacroAssembler* masm, | |
| 103 bool create_memento, | |
| 104 Register original_constructor, | |
| 105 Label* count_incremented, | |
| 106 Label* allocated) { | |
| 107 int offset = kPointerSize; | |
| 108 if (create_memento) { | |
| 109 // Get the cell or allocation site. | |
| 110 __ movp(rdi, Operand(rsp, kPointerSize * 3)); | |
| 111 __ Push(rdi); | |
| 112 offset += kPointerSize; | |
| 113 } | |
| 114 | |
| 115 // Must restore rsi (context) and rdi (constructor) before calling runtime. | |
| 116 __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | |
| 117 __ movp(rdi, Operand(rsp, offset)); | |
| 118 __ Push(rdi); | |
| 119 __ Push(original_constructor); | |
| 120 if (create_memento) { | |
| 121 __ CallRuntime(Runtime::kNewObjectWithAllocationSite, 3); | |
| 122 } else { | |
| 123 __ CallRuntime(Runtime::kNewObject, 2); | |
| 124 } | |
| 125 __ movp(rbx, rax); // store result in rbx | |
| 126 | |
| 127 // Runtime_NewObjectWithAllocationSite increments allocation count. | |
| 128 // Skip the increment. | |
| 129 if (create_memento) { | |
| 130 __ jmp(count_incremented); | |
| 131 } else { | |
| 132 __ jmp(allocated); | |
| 133 } | |
| 134 } | |
| 135 | |
| 136 | |
| 137 static void Generate_JSConstructStubHelper(MacroAssembler* masm, | 102 static void Generate_JSConstructStubHelper(MacroAssembler* masm, |
| 138 bool is_api_function, | 103 bool is_api_function, |
| 139 bool create_memento) { | 104 bool create_memento) { |
| 140 // ----------- S t a t e ------------- | 105 // ----------- S t a t e ------------- |
| 141 // -- rax: number of arguments | 106 // -- rax: number of arguments |
| 142 // -- rdi: constructor function | 107 // -- rdi: constructor function |
| 143 // -- rbx: allocation site or undefined | 108 // -- rbx: allocation site or undefined |
| 144 // -- rdx: original constructor | 109 // -- rdx: original constructor |
| 145 // ----------------------------------- | 110 // ----------------------------------- |
| 146 | 111 |
| 147 // Should never create mementos for api functions. | 112 // Should never create mementos for api functions. |
| 148 DCHECK(!is_api_function || !create_memento); | 113 DCHECK(!is_api_function || !create_memento); |
| 149 | 114 |
| 150 // Enter a construct frame. | 115 // Enter a construct frame. |
| 151 { | 116 { |
| 152 FrameScope scope(masm, StackFrame::CONSTRUCT); | 117 FrameScope scope(masm, StackFrame::CONSTRUCT); |
| 153 | 118 |
| 154 if (create_memento) { | 119 if (create_memento) { |
| 155 __ AssertUndefinedOrAllocationSite(rbx); | 120 __ AssertUndefinedOrAllocationSite(rbx); |
| 156 __ Push(rbx); | 121 __ Push(rbx); |
| 157 } | 122 } |
| 158 | 123 |
| 159 // Preserve the incoming parameters on the stack. | 124 // Preserve the incoming parameters on the stack. |
| 160 __ Integer32ToSmi(rax, rax); | 125 __ Integer32ToSmi(rax, rax); |
| 161 __ Push(rax); | 126 __ Push(rax); |
| 162 __ Push(rdi); | 127 __ Push(rdi); |
| 163 __ Push(rdx); | 128 __ Push(rdx); |
| 164 | 129 |
| 165 Label rt_call, normal_new, allocated, count_incremented; | |
| 166 __ cmpp(rdx, rdi); | |
| 167 __ j(equal, &normal_new); | |
| 168 | |
| 169 Generate_Runtime_NewObject(masm, create_memento, rdx, &count_incremented, | |
| 170 &allocated); | |
| 171 | |
| 172 __ bind(&normal_new); | |
| 173 // Try to allocate the object without transitioning into C code. If any of | 130 // Try to allocate the object without transitioning into C code. If any of |
| 174 // the preconditions is not met, the code bails out to the runtime call. | 131 // the preconditions is not met, the code bails out to the runtime call. |
| 132 Label rt_call, allocated; |
| 175 if (FLAG_inline_new) { | 133 if (FLAG_inline_new) { |
| 176 ExternalReference debug_step_in_fp = | 134 ExternalReference debug_step_in_fp = |
| 177 ExternalReference::debug_step_in_fp_address(masm->isolate()); | 135 ExternalReference::debug_step_in_fp_address(masm->isolate()); |
| 178 __ Move(kScratchRegister, debug_step_in_fp); | 136 __ Move(kScratchRegister, debug_step_in_fp); |
| 179 __ cmpp(Operand(kScratchRegister, 0), Immediate(0)); | 137 __ cmpp(Operand(kScratchRegister, 0), Immediate(0)); |
| 180 __ j(not_equal, &rt_call); | 138 __ j(not_equal, &rt_call); |
| 181 | 139 |
| 140 // Fall back to runtime if the original constructor and function differ. |
| 141 __ cmpp(rdx, rdi); |
| 142 __ j(not_equal, &rt_call); |
| 143 |
| 182 // Verified that the constructor is a JSFunction. | 144 // Verified that the constructor is a JSFunction. |
| 183 // Load the initial map and verify that it is in fact a map. | 145 // Load the initial map and verify that it is in fact a map. |
| 184 // rdi: constructor | 146 // rdi: constructor |
| 185 __ movp(rax, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset)); | 147 __ movp(rax, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 186 // Will both indicate a NULL and a Smi | 148 // Will both indicate a NULL and a Smi |
| 187 DCHECK(kSmiTag == 0); | 149 DCHECK(kSmiTag == 0); |
| 188 __ JumpIfSmi(rax, &rt_call); | 150 __ JumpIfSmi(rax, &rt_call); |
| 189 // rdi: constructor | 151 // rdi: constructor |
| 190 // rax: initial map (if proven valid below) | 152 // rax: initial map (if proven valid below) |
| 191 __ CmpObjectType(rax, MAP_TYPE, rbx); | 153 __ CmpObjectType(rax, MAP_TYPE, rbx); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 208 __ cmpl(rsi, Immediate(Map::kSlackTrackingCounterEnd)); | 170 __ cmpl(rsi, Immediate(Map::kSlackTrackingCounterEnd)); |
| 209 __ j(less, &allocate); | 171 __ j(less, &allocate); |
| 210 // Decrease generous allocation count. | 172 // Decrease generous allocation count. |
| 211 __ subl(FieldOperand(rax, Map::kBitField3Offset), | 173 __ subl(FieldOperand(rax, Map::kBitField3Offset), |
| 212 Immediate(1 << Map::Counter::kShift)); | 174 Immediate(1 << Map::Counter::kShift)); |
| 213 | 175 |
| 214 __ cmpl(rsi, Immediate(Map::kSlackTrackingCounterEnd)); | 176 __ cmpl(rsi, Immediate(Map::kSlackTrackingCounterEnd)); |
| 215 __ j(not_equal, &allocate); | 177 __ j(not_equal, &allocate); |
| 216 | 178 |
| 217 __ Push(rax); | 179 __ Push(rax); |
| 180 __ Push(rdx); |
| 218 __ Push(rdi); | 181 __ Push(rdi); |
| 219 | 182 |
| 220 __ Push(rdi); // constructor | 183 __ Push(rdi); // constructor |
| 221 __ CallRuntime(Runtime::kFinalizeInstanceSize, 1); | 184 __ CallRuntime(Runtime::kFinalizeInstanceSize, 1); |
| 222 | 185 |
| 223 __ Pop(rdi); | 186 __ Pop(rdi); |
| 187 __ Pop(rdx); |
| 224 __ Pop(rax); | 188 __ Pop(rax); |
| 225 __ movl(rsi, Immediate(Map::kSlackTrackingCounterEnd - 1)); | 189 __ movl(rsi, Immediate(Map::kSlackTrackingCounterEnd - 1)); |
| 226 | 190 |
| 227 __ bind(&allocate); | 191 __ bind(&allocate); |
| 228 } | 192 } |
| 229 | 193 |
| 230 // Now allocate the JSObject on the heap. | 194 // Now allocate the JSObject on the heap. |
| 231 __ movzxbp(rdi, FieldOperand(rax, Map::kInstanceSizeOffset)); | 195 __ movzxbp(rdi, FieldOperand(rax, Map::kInstanceSizeOffset)); |
| 232 __ shlp(rdi, Immediate(kPointerSizeLog2)); | 196 __ shlp(rdi, Immediate(kPointerSizeLog2)); |
| 233 if (create_memento) { | 197 if (create_memento) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 // and jump into the continuation code at any time from now on. | 264 // and jump into the continuation code at any time from now on. |
| 301 // rbx: JSObject (untagged) | 265 // rbx: JSObject (untagged) |
| 302 __ orp(rbx, Immediate(kHeapObjectTag)); | 266 __ orp(rbx, Immediate(kHeapObjectTag)); |
| 303 | 267 |
| 304 // Continue with JSObject being successfully allocated | 268 // Continue with JSObject being successfully allocated |
| 305 // rbx: JSObject (tagged) | 269 // rbx: JSObject (tagged) |
| 306 __ jmp(&allocated); | 270 __ jmp(&allocated); |
| 307 } | 271 } |
| 308 | 272 |
| 309 // Allocate the new receiver object using the runtime call. | 273 // Allocate the new receiver object using the runtime call. |
| 310 // rdi: function (constructor) | 274 // rdx: original constructor |
| 311 __ bind(&rt_call); | 275 __ bind(&rt_call); |
| 312 Generate_Runtime_NewObject(masm, create_memento, rdi, &count_incremented, | 276 int offset = kPointerSize; |
| 313 &allocated); | 277 if (create_memento) { |
| 278 // Get the cell or allocation site. |
| 279 __ movp(rdi, Operand(rsp, kPointerSize * 3)); |
| 280 __ Push(rdi); // argument 1: allocation site |
| 281 offset += kPointerSize; |
| 282 } |
| 283 |
| 284 // Must restore rsi (context) and rdi (constructor) before calling runtime. |
| 285 __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 286 __ movp(rdi, Operand(rsp, offset)); |
| 287 __ Push(rdi); // argument 2/1: constructor function |
| 288 __ Push(rdx); // argument 3/2: original constructor |
| 289 if (create_memento) { |
| 290 __ CallRuntime(Runtime::kNewObjectWithAllocationSite, 3); |
| 291 } else { |
| 292 __ CallRuntime(Runtime::kNewObject, 2); |
| 293 } |
| 294 __ movp(rbx, rax); // store result in rbx |
| 295 |
| 296 // Runtime_NewObjectWithAllocationSite increments allocation count. |
| 297 // Skip the increment. |
| 298 Label count_incremented; |
| 299 if (create_memento) { |
| 300 __ jmp(&count_incremented); |
| 301 } |
| 314 | 302 |
| 315 // New object allocated. | 303 // New object allocated. |
| 316 // rbx: newly allocated object | 304 // rbx: newly allocated object |
| 317 __ bind(&allocated); | 305 __ bind(&allocated); |
| 318 | 306 |
| 319 if (create_memento) { | 307 if (create_memento) { |
| 320 __ movp(rcx, Operand(rsp, 3 * kPointerSize)); | 308 __ movp(rcx, Operand(rsp, 3 * kPointerSize)); |
| 321 __ Cmp(rcx, masm->isolate()->factory()->undefined_value()); | 309 __ Cmp(rcx, masm->isolate()->factory()->undefined_value()); |
| 322 __ j(equal, &count_incremented); | 310 __ j(equal, &count_incremented); |
| 323 // rcx is an AllocationSite. We are creating a memento from it, so we | 311 // rcx is an AllocationSite. We are creating a memento from it, so we |
| (...skipping 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1719 __ ret(0); | 1707 __ ret(0); |
| 1720 } | 1708 } |
| 1721 | 1709 |
| 1722 | 1710 |
| 1723 #undef __ | 1711 #undef __ |
| 1724 | 1712 |
| 1725 } // namespace internal | 1713 } // namespace internal |
| 1726 } // namespace v8 | 1714 } // namespace v8 |
| 1727 | 1715 |
| 1728 #endif // V8_TARGET_ARCH_X64 | 1716 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |