Chromium Code Reviews| 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 Label undo_allocation; | 134 Label undo_allocation; |
| 177 | 135 |
| 136 __ cmpp(rdx, rdi); | |
| 137 __ j(not_equal, &rt_call); | |
| 138 | |
| 178 ExternalReference debug_step_in_fp = | 139 ExternalReference debug_step_in_fp = |
| 179 ExternalReference::debug_step_in_fp_address(masm->isolate()); | 140 ExternalReference::debug_step_in_fp_address(masm->isolate()); |
| 180 __ Move(kScratchRegister, debug_step_in_fp); | 141 __ Move(kScratchRegister, debug_step_in_fp); |
| 181 __ cmpp(Operand(kScratchRegister, 0), Immediate(0)); | 142 __ cmpp(Operand(kScratchRegister, 0), Immediate(0)); |
| 182 __ j(not_equal, &rt_call); | 143 __ j(not_equal, &rt_call); |
| 183 | 144 |
| 184 // Verified that the constructor is a JSFunction. | 145 // Verified that the constructor is a JSFunction. |
| 185 // Load the initial map and verify that it is in fact a map. | 146 // Load the initial map and verify that it is in fact a map. |
| 186 // rdi: constructor | 147 // rdi: constructor |
| 187 __ movp(rax, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset)); | 148 __ movp(rax, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset)); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 210 __ cmpl(rsi, Immediate(Map::kSlackTrackingCounterEnd)); | 171 __ cmpl(rsi, Immediate(Map::kSlackTrackingCounterEnd)); |
| 211 __ j(less, &allocate); | 172 __ j(less, &allocate); |
| 212 // Decrease generous allocation count. | 173 // Decrease generous allocation count. |
| 213 __ subl(FieldOperand(rax, Map::kBitField3Offset), | 174 __ subl(FieldOperand(rax, Map::kBitField3Offset), |
| 214 Immediate(1 << Map::Counter::kShift)); | 175 Immediate(1 << Map::Counter::kShift)); |
| 215 | 176 |
| 216 __ cmpl(rsi, Immediate(Map::kSlackTrackingCounterEnd)); | 177 __ cmpl(rsi, Immediate(Map::kSlackTrackingCounterEnd)); |
| 217 __ j(not_equal, &allocate); | 178 __ j(not_equal, &allocate); |
| 218 | 179 |
| 219 __ Push(rax); | 180 __ Push(rax); |
| 181 __ Push(rdx); | |
|
arv (Not doing code reviews)
2015/07/10 16:21:51
Do we care about the extra cost of the push/pop he
Michael Starzinger
2015/07/10 16:39:54
The push/pop is right before and after a runtime c
| |
| 220 __ Push(rdi); | 182 __ Push(rdi); |
| 221 | 183 |
| 222 __ Push(rdi); // constructor | 184 __ Push(rdi); // constructor |
| 223 __ CallRuntime(Runtime::kFinalizeInstanceSize, 1); | 185 __ CallRuntime(Runtime::kFinalizeInstanceSize, 1); |
| 224 | 186 |
| 225 __ Pop(rdi); | 187 __ Pop(rdi); |
| 188 __ Pop(rdx); | |
| 226 __ Pop(rax); | 189 __ Pop(rax); |
| 227 __ movl(rsi, Immediate(Map::kSlackTrackingCounterEnd - 1)); | 190 __ movl(rsi, Immediate(Map::kSlackTrackingCounterEnd - 1)); |
| 228 | 191 |
| 229 __ bind(&allocate); | 192 __ bind(&allocate); |
| 230 } | 193 } |
| 231 | 194 |
| 232 // Now allocate the JSObject on the heap. | 195 // Now allocate the JSObject on the heap. |
| 233 __ movzxbp(rdi, FieldOperand(rax, Map::kInstanceSizeOffset)); | 196 __ movzxbp(rdi, FieldOperand(rax, Map::kInstanceSizeOffset)); |
| 234 __ shlp(rdi, Immediate(kPointerSizeLog2)); | 197 __ shlp(rdi, Immediate(kPointerSizeLog2)); |
| 235 if (create_memento) { | 198 if (create_memento) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 370 | 333 |
| 371 // Undo the setting of the new top so that the heap is verifiable. For | 334 // Undo the setting of the new top so that the heap is verifiable. For |
| 372 // example, the map's unused properties potentially do not match the | 335 // example, the map's unused properties potentially do not match the |
| 373 // allocated objects unused properties. | 336 // allocated objects unused properties. |
| 374 // rbx: JSObject (previous new top) | 337 // rbx: JSObject (previous new top) |
| 375 __ bind(&undo_allocation); | 338 __ bind(&undo_allocation); |
| 376 __ UndoAllocationInNewSpace(rbx); | 339 __ UndoAllocationInNewSpace(rbx); |
| 377 } | 340 } |
| 378 | 341 |
| 379 // Allocate the new receiver object using the runtime call. | 342 // Allocate the new receiver object using the runtime call. |
| 380 // rdi: function (constructor) | 343 // rdx: original constructor |
| 381 __ bind(&rt_call); | 344 __ bind(&rt_call); |
| 382 Generate_Runtime_NewObject(masm, create_memento, rdi, &count_incremented, | 345 int offset = kPointerSize; |
| 383 &allocated); | 346 if (create_memento) { |
| 347 // Get the cell or allocation site. | |
| 348 __ movp(rdi, Operand(rsp, kPointerSize * 3)); | |
| 349 __ Push(rdi); | |
| 350 offset += kPointerSize; | |
| 351 } | |
| 352 | |
| 353 // Must restore rsi (context) and rdi (constructor) before calling runtime. | |
| 354 __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | |
| 355 __ movp(rdi, Operand(rsp, offset)); | |
| 356 __ Push(rdi); | |
| 357 __ Push(rdx); | |
| 358 if (create_memento) { | |
| 359 __ CallRuntime(Runtime::kNewObjectWithAllocationSite, 3); | |
| 360 } else { | |
| 361 __ CallRuntime(Runtime::kNewObject, 2); | |
| 362 } | |
| 363 __ movp(rbx, rax); // store result in rbx | |
| 364 | |
| 365 // Runtime_NewObjectWithAllocationSite increments allocation count. | |
| 366 // Skip the increment. | |
| 367 Label count_incremented; | |
| 368 if (create_memento) { | |
| 369 __ jmp(&count_incremented); | |
| 370 } else { | |
| 371 __ jmp(&allocated); | |
| 372 } | |
| 384 | 373 |
| 385 // New object allocated. | 374 // New object allocated. |
| 386 // rbx: newly allocated object | 375 // rbx: newly allocated object |
| 387 __ bind(&allocated); | 376 __ bind(&allocated); |
| 388 | 377 |
| 389 if (create_memento) { | 378 if (create_memento) { |
| 390 __ movp(rcx, Operand(rsp, 3 * kPointerSize)); | 379 __ movp(rcx, Operand(rsp, 3 * kPointerSize)); |
| 391 __ Cmp(rcx, masm->isolate()->factory()->undefined_value()); | 380 __ Cmp(rcx, masm->isolate()->factory()->undefined_value()); |
| 392 __ j(equal, &count_incremented); | 381 __ j(equal, &count_incremented); |
| 393 // rcx is an AllocationSite. We are creating a memento from it, so we | 382 // 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... | |
| 1789 __ ret(0); | 1778 __ ret(0); |
| 1790 } | 1779 } |
| 1791 | 1780 |
| 1792 | 1781 |
| 1793 #undef __ | 1782 #undef __ |
| 1794 | 1783 |
| 1795 } // namespace internal | 1784 } // namespace internal |
| 1796 } // namespace v8 | 1785 } // namespace v8 |
| 1797 | 1786 |
| 1798 #endif // V8_TARGET_ARCH_X64 | 1787 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |