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 #if V8_TARGET_ARCH_X64 | 5 #if V8_TARGET_ARCH_X64 |
6 | 6 |
7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
8 #include "src/codegen.h" | 8 #include "src/codegen.h" |
9 #include "src/deoptimizer.h" | 9 #include "src/deoptimizer.h" |
10 #include "src/full-codegen/full-codegen.h" | 10 #include "src/full-codegen/full-codegen.h" |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 } | 270 } |
271 | 271 |
272 // Allocate the new receiver object using the runtime call. | 272 // Allocate the new receiver object using the runtime call. |
273 // rdx: original constructor | 273 // rdx: original constructor |
274 __ bind(&rt_call); | 274 __ bind(&rt_call); |
275 int offset = kPointerSize; | 275 int offset = kPointerSize; |
276 | 276 |
277 // Must restore rsi (context) and rdi (constructor) before calling runtime. | 277 // Must restore rsi (context) and rdi (constructor) before calling runtime. |
278 __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | 278 __ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
279 __ movp(rdi, Operand(rsp, offset)); | 279 __ movp(rdi, Operand(rsp, offset)); |
280 __ Push(rdi); // constructor function | 280 __ Push(rdi); // argument 2/1: constructor function |
281 __ Push(rdx); // original constructor | 281 __ Push(rdx); // argument 3/2: original constructor |
282 __ CallRuntime(Runtime::kNewObject, 2); | 282 __ CallRuntime(Runtime::kNewObject, 2); |
283 __ movp(rbx, rax); // store result in rbx | 283 __ movp(rbx, rax); // store result in rbx |
284 | 284 |
285 // New object allocated. | 285 // New object allocated. |
286 // rbx: newly allocated object | 286 // rbx: newly allocated object |
287 __ bind(&allocated); | 287 __ bind(&allocated); |
288 | 288 |
289 // Restore the parameters. | 289 // Restore the parameters. |
290 __ Pop(rdx); | 290 __ Pop(rdx); |
291 __ Pop(rdi); | 291 __ Pop(rdi); |
(...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1414 __ TailCallRuntime(Runtime::kSymbolDescriptiveString, 1, 1); | 1414 __ TailCallRuntime(Runtime::kSymbolDescriptiveString, 1, 1); |
1415 } | 1415 } |
1416 } | 1416 } |
1417 | 1417 |
1418 | 1418 |
1419 // static | 1419 // static |
1420 void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) { | 1420 void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) { |
1421 // ----------- S t a t e ------------- | 1421 // ----------- S t a t e ------------- |
1422 // -- rax : number of arguments | 1422 // -- rax : number of arguments |
1423 // -- rdi : constructor function | 1423 // -- rdi : constructor function |
1424 // -- rdx : original constructor | |
1425 // -- rsp[0] : return address | 1424 // -- rsp[0] : return address |
1426 // -- rsp[(argc - n) * 8] : arg[n] (zero-based) | 1425 // -- rsp[(argc - n) * 8] : arg[n] (zero-based) |
1427 // -- rsp[(argc + 1) * 8] : receiver | 1426 // -- rsp[(argc + 1) * 8] : receiver |
1428 // ----------------------------------- | 1427 // ----------------------------------- |
1429 | 1428 |
1430 // 1. Load the first argument into rbx and get rid of the rest (including the | 1429 // 1. Load the first argument into rbx and get rid of the rest (including the |
1431 // receiver). | 1430 // receiver). |
1432 { | 1431 { |
1433 StackArgumentsAccessor args(rsp, rax); | 1432 StackArgumentsAccessor args(rsp, rax); |
1434 Label no_arguments, done; | 1433 Label no_arguments, done; |
1435 __ testp(rax, rax); | 1434 __ testp(rax, rax); |
1436 __ j(zero, &no_arguments, Label::kNear); | 1435 __ j(zero, &no_arguments, Label::kNear); |
1437 __ movp(rbx, args.GetArgumentOperand(1)); | 1436 __ movp(rbx, args.GetArgumentOperand(1)); |
1438 __ jmp(&done, Label::kNear); | 1437 __ jmp(&done, Label::kNear); |
1439 __ bind(&no_arguments); | 1438 __ bind(&no_arguments); |
1440 __ LoadRoot(rbx, Heap::kempty_stringRootIndex); | 1439 __ LoadRoot(rbx, Heap::kempty_stringRootIndex); |
1441 __ bind(&done); | 1440 __ bind(&done); |
1442 __ PopReturnAddressTo(rcx); | 1441 __ PopReturnAddressTo(rcx); |
1443 __ leap(rsp, Operand(rsp, rax, times_pointer_size, kPointerSize)); | 1442 __ leap(rsp, Operand(rsp, rax, times_pointer_size, kPointerSize)); |
1444 __ PushReturnAddressFrom(rcx); | 1443 __ PushReturnAddressFrom(rcx); |
1445 } | 1444 } |
1446 | 1445 |
1447 // 2. Make sure rbx is a string. | 1446 // 2. Make sure rbx is a string. |
1448 { | 1447 { |
1449 Label convert, done_convert; | 1448 Label convert, done_convert; |
1450 __ JumpIfSmi(rbx, &convert, Label::kNear); | 1449 __ JumpIfSmi(rbx, &convert, Label::kNear); |
1451 __ CmpObjectType(rbx, FIRST_NONSTRING_TYPE, rcx); | 1450 __ CmpObjectType(rbx, FIRST_NONSTRING_TYPE, rdx); |
1452 __ j(below, &done_convert); | 1451 __ j(below, &done_convert); |
1453 __ bind(&convert); | 1452 __ bind(&convert); |
1454 { | 1453 { |
1455 FrameScope scope(masm, StackFrame::INTERNAL); | 1454 FrameScope scope(masm, StackFrame::INTERNAL); |
1456 ToStringStub stub(masm->isolate()); | 1455 ToStringStub stub(masm->isolate()); |
1457 __ Push(rdx); | |
1458 __ Push(rdi); | 1456 __ Push(rdi); |
1459 __ Move(rax, rbx); | 1457 __ Move(rax, rbx); |
1460 __ CallStub(&stub); | 1458 __ CallStub(&stub); |
1461 __ Move(rbx, rax); | 1459 __ Move(rbx, rax); |
1462 __ Pop(rdi); | 1460 __ Pop(rdi); |
1463 __ Pop(rdx); | |
1464 } | 1461 } |
1465 __ bind(&done_convert); | 1462 __ bind(&done_convert); |
1466 } | 1463 } |
1467 | 1464 |
1468 // 3. Allocate a JSValue wrapper for the string. | 1465 // 3. Allocate a JSValue wrapper for the string. |
1469 { | 1466 { |
1470 // ----------- S t a t e ------------- | 1467 // ----------- S t a t e ------------- |
1471 // -- rbx : the first argument | 1468 // -- rbx : the first argument |
1472 // -- rdi : constructor function | 1469 // -- rdi : constructor function |
1473 // -- rdx : original constructor | |
1474 // ----------------------------------- | 1470 // ----------------------------------- |
1475 Label allocate, done_allocate, rt_call; | |
1476 | 1471 |
1477 // Fall back to runtime if the original constructor and constructor differ. | 1472 Label allocate, done_allocate; |
1478 __ cmpp(rdx, rdi); | |
1479 __ j(not_equal, &rt_call); | |
1480 | |
1481 __ Allocate(JSValue::kSize, rax, rcx, no_reg, &allocate, TAG_OBJECT); | 1473 __ Allocate(JSValue::kSize, rax, rcx, no_reg, &allocate, TAG_OBJECT); |
1482 __ bind(&done_allocate); | 1474 __ bind(&done_allocate); |
1483 | 1475 |
1484 // Initialize the JSValue in rax. | 1476 // Initialize the JSValue in rax. |
1485 __ LoadGlobalFunctionInitialMap(rdi, rcx); | 1477 __ LoadGlobalFunctionInitialMap(rdi, rcx); |
1486 __ movp(FieldOperand(rax, HeapObject::kMapOffset), rcx); | 1478 __ movp(FieldOperand(rax, HeapObject::kMapOffset), rcx); |
1487 __ LoadRoot(rcx, Heap::kEmptyFixedArrayRootIndex); | 1479 __ LoadRoot(rcx, Heap::kEmptyFixedArrayRootIndex); |
1488 __ movp(FieldOperand(rax, JSObject::kPropertiesOffset), rcx); | 1480 __ movp(FieldOperand(rax, JSObject::kPropertiesOffset), rcx); |
1489 __ movp(FieldOperand(rax, JSObject::kElementsOffset), rcx); | 1481 __ movp(FieldOperand(rax, JSObject::kElementsOffset), rcx); |
1490 __ movp(FieldOperand(rax, JSValue::kValueOffset), rbx); | 1482 __ movp(FieldOperand(rax, JSValue::kValueOffset), rbx); |
1491 STATIC_ASSERT(JSValue::kSize == 4 * kPointerSize); | 1483 STATIC_ASSERT(JSValue::kSize == 4 * kPointerSize); |
1492 __ Ret(); | 1484 __ Ret(); |
1493 | 1485 |
1494 // Fallback to the runtime to allocate in new space. | 1486 // Fallback to the runtime to allocate in new space. |
1495 __ bind(&allocate); | 1487 __ bind(&allocate); |
1496 { | 1488 { |
1497 FrameScope scope(masm, StackFrame::INTERNAL); | 1489 FrameScope scope(masm, StackFrame::INTERNAL); |
1498 __ Push(rbx); | 1490 __ Push(rbx); |
1499 __ Push(rdi); | 1491 __ Push(rdi); |
1500 __ Push(Smi::FromInt(JSValue::kSize)); | 1492 __ Push(Smi::FromInt(JSValue::kSize)); |
1501 __ CallRuntime(Runtime::kAllocateInNewSpace, 1); | 1493 __ CallRuntime(Runtime::kAllocateInNewSpace, 1); |
1502 __ Pop(rdi); | 1494 __ Pop(rdi); |
1503 __ Pop(rbx); | 1495 __ Pop(rbx); |
1504 } | 1496 } |
1505 __ jmp(&done_allocate); | 1497 __ jmp(&done_allocate); |
1506 | |
1507 // Fallback to the runtime to create new object. | |
1508 __ bind(&rt_call); | |
1509 { | |
1510 FrameScope scope(masm, StackFrame::INTERNAL); | |
1511 __ Push(rbx); | |
1512 __ Push(rdi); | |
1513 __ Push(rdi); // constructor function | |
1514 __ Push(rdx); // original constructor | |
1515 __ CallRuntime(Runtime::kNewObject, 2); | |
1516 __ Pop(rdi); | |
1517 __ Pop(rbx); | |
1518 } | |
1519 __ movp(FieldOperand(rax, JSValue::kValueOffset), rbx); | |
1520 __ Ret(); | |
1521 } | 1498 } |
1522 } | 1499 } |
1523 | 1500 |
1524 | 1501 |
1525 static void ArgumentsAdaptorStackCheck(MacroAssembler* masm, | 1502 static void ArgumentsAdaptorStackCheck(MacroAssembler* masm, |
1526 Label* stack_overflow) { | 1503 Label* stack_overflow) { |
1527 // ----------- S t a t e ------------- | 1504 // ----------- S t a t e ------------- |
1528 // -- rax : actual number of arguments | 1505 // -- rax : actual number of arguments |
1529 // -- rbx : expected number of arguments | 1506 // -- rbx : expected number of arguments |
1530 // -- rdi: function (passed through to callee) | 1507 // -- rdi: function (passed through to callee) |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1990 __ ret(0); | 1967 __ ret(0); |
1991 } | 1968 } |
1992 | 1969 |
1993 | 1970 |
1994 #undef __ | 1971 #undef __ |
1995 | 1972 |
1996 } // namespace internal | 1973 } // namespace internal |
1997 } // namespace v8 | 1974 } // namespace v8 |
1998 | 1975 |
1999 #endif // V8_TARGET_ARCH_X64 | 1976 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |