| 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 "v8.h" | 5 #include "v8.h" |
| 6 | 6 |
| 7 #if V8_TARGET_ARCH_X64 | 7 #if V8_TARGET_ARCH_X64 |
| 8 | 8 |
| 9 #include "codegen.h" | 9 #include "codegen.h" |
| 10 #include "deoptimizer.h" | 10 #include "deoptimizer.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 CallRuntimePassFunction(masm, Runtime::kHiddenTryInstallOptimizedCode); | 94 CallRuntimePassFunction(masm, Runtime::kHiddenTryInstallOptimizedCode); |
| 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_JSConstructStubHelper(MacroAssembler* masm, | 102 static void Generate_JSConstructStubHelper(MacroAssembler* masm, |
| 103 bool is_api_function, | 103 bool is_api_function, |
| 104 bool count_constructions, | |
| 105 bool create_memento) { | 104 bool create_memento) { |
| 106 // ----------- S t a t e ------------- | 105 // ----------- S t a t e ------------- |
| 107 // -- rax: number of arguments | 106 // -- rax: number of arguments |
| 108 // -- rdi: constructor function | 107 // -- rdi: constructor function |
| 109 // -- rbx: allocation site or undefined | 108 // -- rbx: allocation site or undefined |
| 110 // ----------------------------------- | 109 // ----------------------------------- |
| 111 | 110 |
| 112 // Should never count constructions for api objects. | |
| 113 ASSERT(!is_api_function || !count_constructions);\ | |
| 114 | |
| 115 // Should never create mementos for api functions. | 111 // Should never create mementos for api functions. |
| 116 ASSERT(!is_api_function || !create_memento); | 112 ASSERT(!is_api_function || !create_memento); |
| 117 | 113 |
| 118 // Should never create mementos before slack tracking is finished. | |
| 119 ASSERT(!count_constructions || !create_memento); | |
| 120 | |
| 121 // Enter a construct frame. | 114 // Enter a construct frame. |
| 122 { | 115 { |
| 123 FrameScope scope(masm, StackFrame::CONSTRUCT); | 116 FrameScope scope(masm, StackFrame::CONSTRUCT); |
| 124 | 117 |
| 125 if (create_memento) { | 118 if (create_memento) { |
| 126 __ AssertUndefinedOrAllocationSite(rbx); | 119 __ AssertUndefinedOrAllocationSite(rbx); |
| 127 __ Push(rbx); | 120 __ Push(rbx); |
| 128 } | 121 } |
| 129 | 122 |
| 130 // Store a smi-tagged arguments count on the stack. | 123 // Store a smi-tagged arguments count on the stack. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 159 __ j(not_equal, &rt_call); | 152 __ j(not_equal, &rt_call); |
| 160 | 153 |
| 161 // Check that the constructor is not constructing a JSFunction (see | 154 // Check that the constructor is not constructing a JSFunction (see |
| 162 // comments in Runtime_NewObject in runtime.cc). In which case the | 155 // comments in Runtime_NewObject in runtime.cc). In which case the |
| 163 // initial map's instance type would be JS_FUNCTION_TYPE. | 156 // initial map's instance type would be JS_FUNCTION_TYPE. |
| 164 // rdi: constructor | 157 // rdi: constructor |
| 165 // rax: initial map | 158 // rax: initial map |
| 166 __ CmpInstanceType(rax, JS_FUNCTION_TYPE); | 159 __ CmpInstanceType(rax, JS_FUNCTION_TYPE); |
| 167 __ j(equal, &rt_call); | 160 __ j(equal, &rt_call); |
| 168 | 161 |
| 169 if (count_constructions) { | 162 if (!is_api_function) { |
| 170 Label allocate; | 163 Label allocate; |
| 164 // The code below relies on these assumptions. |
| 165 STATIC_ASSERT(JSFunction::kNoSlackTracking == 0); |
| 166 STATIC_ASSERT(Map::ConstructionCount::kShift + |
| 167 Map::ConstructionCount::kSize == 32); |
| 168 // Check if slack tracking is enabled. |
| 169 __ movl(rsi, FieldOperand(rax, Map::kBitField3Offset)); |
| 170 __ shrl(rsi, Immediate(Map::ConstructionCount::kShift)); |
| 171 __ j(zero, &allocate); // JSFunction::kNoSlackTracking |
| 171 // Decrease generous allocation count. | 172 // Decrease generous allocation count. |
| 172 __ movp(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); | 173 __ subl(FieldOperand(rax, Map::kBitField3Offset), |
| 173 __ decb(FieldOperand(rcx, | 174 Immediate(1 << Map::ConstructionCount::kShift)); |
| 174 SharedFunctionInfo::kConstructionCountOffset)); | 175 |
| 175 __ j(not_zero, &allocate); | 176 __ cmpl(rsi, Immediate(JSFunction::kFinishSlackTracking)); |
| 177 __ j(not_equal, &allocate); |
| 176 | 178 |
| 177 __ Push(rax); | 179 __ Push(rax); |
| 178 __ Push(rdi); | 180 __ Push(rdi); |
| 179 | 181 |
| 180 __ Push(rdi); // constructor | 182 __ Push(rdi); // constructor |
| 181 // The call will replace the stub, so the countdown is only done once. | |
| 182 __ CallRuntime(Runtime::kHiddenFinalizeInstanceSize, 1); | 183 __ CallRuntime(Runtime::kHiddenFinalizeInstanceSize, 1); |
| 183 | 184 |
| 184 __ Pop(rdi); | 185 __ Pop(rdi); |
| 185 __ Pop(rax); | 186 __ Pop(rax); |
| 187 __ xorl(rsi, rsi); // JSFunction::kNoSlackTracking |
| 186 | 188 |
| 187 __ bind(&allocate); | 189 __ bind(&allocate); |
| 188 } | 190 } |
| 189 | 191 |
| 190 // Now allocate the JSObject on the heap. | 192 // Now allocate the JSObject on the heap. |
| 191 __ movzxbp(rdi, FieldOperand(rax, Map::kInstanceSizeOffset)); | 193 __ movzxbp(rdi, FieldOperand(rax, Map::kInstanceSizeOffset)); |
| 192 __ shlp(rdi, Immediate(kPointerSizeLog2)); | 194 __ shlp(rdi, Immediate(kPointerSizeLog2)); |
| 193 if (create_memento) { | 195 if (create_memento) { |
| 194 __ addp(rdi, Immediate(AllocationMemento::kSize)); | 196 __ addp(rdi, Immediate(AllocationMemento::kSize)); |
| 195 } | 197 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 206 // rbx: JSObject (not HeapObject tagged - the actual address). | 208 // rbx: JSObject (not HeapObject tagged - the actual address). |
| 207 // rdi: start of next object (including memento if create_memento) | 209 // rdi: start of next object (including memento if create_memento) |
| 208 __ movp(Operand(rbx, JSObject::kMapOffset), rax); | 210 __ movp(Operand(rbx, JSObject::kMapOffset), rax); |
| 209 __ LoadRoot(rcx, Heap::kEmptyFixedArrayRootIndex); | 211 __ LoadRoot(rcx, Heap::kEmptyFixedArrayRootIndex); |
| 210 __ movp(Operand(rbx, JSObject::kPropertiesOffset), rcx); | 212 __ movp(Operand(rbx, JSObject::kPropertiesOffset), rcx); |
| 211 __ movp(Operand(rbx, JSObject::kElementsOffset), rcx); | 213 __ movp(Operand(rbx, JSObject::kElementsOffset), rcx); |
| 212 // Set extra fields in the newly allocated object. | 214 // Set extra fields in the newly allocated object. |
| 213 // rax: initial map | 215 // rax: initial map |
| 214 // rbx: JSObject | 216 // rbx: JSObject |
| 215 // rdi: start of next object (including memento if create_memento) | 217 // rdi: start of next object (including memento if create_memento) |
| 218 // rsi: slack tracking counter (non-API function case) |
| 216 __ leap(rcx, Operand(rbx, JSObject::kHeaderSize)); | 219 __ leap(rcx, Operand(rbx, JSObject::kHeaderSize)); |
| 217 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); | 220 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); |
| 218 if (count_constructions) { | 221 if (!is_api_function) { |
| 222 Label no_inobject_slack_tracking; |
| 223 |
| 224 // Check if slack tracking is enabled. |
| 225 __ cmpl(rsi, Immediate(JSFunction::kNoSlackTracking)); |
| 226 __ j(equal, &no_inobject_slack_tracking); |
| 227 |
| 228 // Allocate object with a slack. |
| 219 __ movzxbp(rsi, | 229 __ movzxbp(rsi, |
| 220 FieldOperand(rax, Map::kPreAllocatedPropertyFieldsOffset)); | 230 FieldOperand(rax, Map::kPreAllocatedPropertyFieldsOffset)); |
| 221 __ leap(rsi, | 231 __ leap(rsi, |
| 222 Operand(rbx, rsi, times_pointer_size, JSObject::kHeaderSize)); | 232 Operand(rbx, rsi, times_pointer_size, JSObject::kHeaderSize)); |
| 223 // rsi: offset of first field after pre-allocated fields | 233 // rsi: offset of first field after pre-allocated fields |
| 224 if (FLAG_debug_code) { | 234 if (FLAG_debug_code) { |
| 225 __ cmpp(rsi, rdi); | 235 __ cmpp(rsi, rdi); |
| 226 __ Assert(less_equal, | 236 __ Assert(less_equal, |
| 227 kUnexpectedNumberOfPreAllocatedPropertyFields); | 237 kUnexpectedNumberOfPreAllocatedPropertyFields); |
| 228 } | 238 } |
| 229 __ InitializeFieldsWithFiller(rcx, rsi, rdx); | 239 __ InitializeFieldsWithFiller(rcx, rsi, rdx); |
| 230 __ LoadRoot(rdx, Heap::kOnePointerFillerMapRootIndex); | 240 __ LoadRoot(rdx, Heap::kOnePointerFillerMapRootIndex); |
| 231 __ InitializeFieldsWithFiller(rcx, rdi, rdx); | 241 // Fill the remaining fields with one pointer filler map. |
| 232 } else if (create_memento) { | 242 |
| 243 __ bind(&no_inobject_slack_tracking); |
| 244 } |
| 245 if (create_memento) { |
| 233 __ leap(rsi, Operand(rdi, -AllocationMemento::kSize)); | 246 __ leap(rsi, Operand(rdi, -AllocationMemento::kSize)); |
| 234 __ InitializeFieldsWithFiller(rcx, rsi, rdx); | 247 __ InitializeFieldsWithFiller(rcx, rsi, rdx); |
| 235 | 248 |
| 236 // Fill in memento fields if necessary. | 249 // Fill in memento fields if necessary. |
| 237 // rsi: points to the allocated but uninitialized memento. | 250 // rsi: points to the allocated but uninitialized memento. |
| 238 Handle<Map> allocation_memento_map = factory->allocation_memento_map(); | |
| 239 __ Move(Operand(rsi, AllocationMemento::kMapOffset), | 251 __ Move(Operand(rsi, AllocationMemento::kMapOffset), |
| 240 allocation_memento_map); | 252 factory->allocation_memento_map()); |
| 241 // Get the cell or undefined. | 253 // Get the cell or undefined. |
| 242 __ movp(rdx, Operand(rsp, kPointerSize*2)); | 254 __ movp(rdx, Operand(rsp, kPointerSize*2)); |
| 243 __ movp(Operand(rsi, AllocationMemento::kAllocationSiteOffset), | 255 __ movp(Operand(rsi, AllocationMemento::kAllocationSiteOffset), rdx); |
| 244 rdx); | |
| 245 } else { | 256 } else { |
| 246 __ InitializeFieldsWithFiller(rcx, rdi, rdx); | 257 __ InitializeFieldsWithFiller(rcx, rdi, rdx); |
| 247 } | 258 } |
| 248 | 259 |
| 249 // Add the object tag to make the JSObject real, so that we can continue | 260 // Add the object tag to make the JSObject real, so that we can continue |
| 250 // and jump into the continuation code at any time from now on. Any | 261 // and jump into the continuation code at any time from now on. Any |
| 251 // failures need to undo the allocation, so that the heap is in a | 262 // failures need to undo the allocation, so that the heap is in a |
| 252 // consistent state and verifiable. | 263 // consistent state and verifiable. |
| 253 // rax: initial map | 264 // rax: initial map |
| 254 // rbx: JSObject | 265 // rbx: JSObject |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 // rdi: function (constructor) | 348 // rdi: function (constructor) |
| 338 __ bind(&rt_call); | 349 __ bind(&rt_call); |
| 339 int offset = 0; | 350 int offset = 0; |
| 340 if (create_memento) { | 351 if (create_memento) { |
| 341 // Get the cell or allocation site. | 352 // Get the cell or allocation site. |
| 342 __ movp(rdi, Operand(rsp, kPointerSize*2)); | 353 __ movp(rdi, Operand(rsp, kPointerSize*2)); |
| 343 __ Push(rdi); | 354 __ Push(rdi); |
| 344 offset = kPointerSize; | 355 offset = kPointerSize; |
| 345 } | 356 } |
| 346 | 357 |
| 347 // Must restore rdi (constructor) before calling runtime. | 358 // Must restore rsi (context) and rdi (constructor) before calling runtime. |
| 359 __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 348 __ movp(rdi, Operand(rsp, offset)); | 360 __ movp(rdi, Operand(rsp, offset)); |
| 349 __ Push(rdi); | 361 __ Push(rdi); |
| 350 if (create_memento) { | 362 if (create_memento) { |
| 351 __ CallRuntime(Runtime::kHiddenNewObjectWithAllocationSite, 2); | 363 __ CallRuntime(Runtime::kHiddenNewObjectWithAllocationSite, 2); |
| 352 } else { | 364 } else { |
| 353 __ CallRuntime(Runtime::kHiddenNewObject, 1); | 365 __ CallRuntime(Runtime::kHiddenNewObject, 1); |
| 354 } | 366 } |
| 355 __ movp(rbx, rax); // store result in rbx | 367 __ movp(rbx, rax); // store result in rbx |
| 356 | 368 |
| 357 // If we ended up using the runtime, and we want a memento, then the | 369 // If we ended up using the runtime, and we want a memento, then the |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 __ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); | 421 __ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); |
| 410 Handle<Code> code = | 422 Handle<Code> code = |
| 411 masm->isolate()->builtins()->HandleApiCallConstruct(); | 423 masm->isolate()->builtins()->HandleApiCallConstruct(); |
| 412 __ Call(code, RelocInfo::CODE_TARGET); | 424 __ Call(code, RelocInfo::CODE_TARGET); |
| 413 } else { | 425 } else { |
| 414 ParameterCount actual(rax); | 426 ParameterCount actual(rax); |
| 415 __ InvokeFunction(rdi, actual, CALL_FUNCTION, NullCallWrapper()); | 427 __ InvokeFunction(rdi, actual, CALL_FUNCTION, NullCallWrapper()); |
| 416 } | 428 } |
| 417 | 429 |
| 418 // Store offset of return address for deoptimizer. | 430 // Store offset of return address for deoptimizer. |
| 419 if (!is_api_function && !count_constructions) { | 431 if (!is_api_function) { |
| 420 masm->isolate()->heap()->SetConstructStubDeoptPCOffset(masm->pc_offset()); | 432 masm->isolate()->heap()->SetConstructStubDeoptPCOffset(masm->pc_offset()); |
| 421 } | 433 } |
| 422 | 434 |
| 423 // Restore context from the frame. | 435 // Restore context from the frame. |
| 424 __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | 436 __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 425 | 437 |
| 426 // If the result is an object (in the ECMA sense), we should get rid | 438 // If the result is an object (in the ECMA sense), we should get rid |
| 427 // of the receiver and use the result; see ECMA-262 section 13.2.2-7 | 439 // of the receiver and use the result; see ECMA-262 section 13.2.2-7 |
| 428 // on page 74. | 440 // on page 74. |
| 429 Label use_receiver, exit; | 441 Label use_receiver, exit; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 452 __ PopReturnAddressTo(rcx); | 464 __ PopReturnAddressTo(rcx); |
| 453 SmiIndex index = masm->SmiToIndex(rbx, rbx, kPointerSizeLog2); | 465 SmiIndex index = masm->SmiToIndex(rbx, rbx, kPointerSizeLog2); |
| 454 __ leap(rsp, Operand(rsp, index.reg, index.scale, 1 * kPointerSize)); | 466 __ leap(rsp, Operand(rsp, index.reg, index.scale, 1 * kPointerSize)); |
| 455 __ PushReturnAddressFrom(rcx); | 467 __ PushReturnAddressFrom(rcx); |
| 456 Counters* counters = masm->isolate()->counters(); | 468 Counters* counters = masm->isolate()->counters(); |
| 457 __ IncrementCounter(counters->constructed_objects(), 1); | 469 __ IncrementCounter(counters->constructed_objects(), 1); |
| 458 __ ret(0); | 470 __ ret(0); |
| 459 } | 471 } |
| 460 | 472 |
| 461 | 473 |
| 462 void Builtins::Generate_JSConstructStubCountdown(MacroAssembler* masm) { | |
| 463 Generate_JSConstructStubHelper(masm, false, true, false); | |
| 464 } | |
| 465 | |
| 466 | |
| 467 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { | 474 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { |
| 468 Generate_JSConstructStubHelper(masm, false, false, FLAG_pretenuring_call_new); | 475 Generate_JSConstructStubHelper(masm, false, FLAG_pretenuring_call_new); |
| 469 } | 476 } |
| 470 | 477 |
| 471 | 478 |
| 472 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { | 479 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { |
| 473 Generate_JSConstructStubHelper(masm, true, false, false); | 480 Generate_JSConstructStubHelper(masm, true, false); |
| 474 } | 481 } |
| 475 | 482 |
| 476 | 483 |
| 477 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, | 484 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, |
| 478 bool is_construct) { | 485 bool is_construct) { |
| 479 ProfileEntryHookStub::MaybeCallEntryHook(masm); | 486 ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 480 | 487 |
| 481 // Expects five C++ function parameters. | 488 // Expects five C++ function parameters. |
| 482 // - Address entry (ignored) | 489 // - Address entry (ignored) |
| 483 // - JSFunction* function ( | 490 // - JSFunction* function ( |
| (...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1506 __ bind(&ok); | 1513 __ bind(&ok); |
| 1507 __ ret(0); | 1514 __ ret(0); |
| 1508 } | 1515 } |
| 1509 | 1516 |
| 1510 | 1517 |
| 1511 #undef __ | 1518 #undef __ |
| 1512 | 1519 |
| 1513 } } // namespace v8::internal | 1520 } } // namespace v8::internal |
| 1514 | 1521 |
| 1515 #endif // V8_TARGET_ARCH_X64 | 1522 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |