| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 // Restore context from the frame. | 349 // Restore context from the frame. |
| 350 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | 350 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 351 | 351 |
| 352 // If the result is an object (in the ECMA sense), we should get rid | 352 // If the result is an object (in the ECMA sense), we should get rid |
| 353 // of the receiver and use the result; see ECMA-262 section 13.2.2-7 | 353 // of the receiver and use the result; see ECMA-262 section 13.2.2-7 |
| 354 // on page 74. | 354 // on page 74. |
| 355 Label use_receiver, exit; | 355 Label use_receiver, exit; |
| 356 | 356 |
| 357 // If the result is a smi, it is *not* an object in the ECMA sense. | 357 // If the result is a smi, it is *not* an object in the ECMA sense. |
| 358 __ test(eax, Immediate(kSmiTagMask)); | 358 __ test(eax, Immediate(kSmiTagMask)); |
| 359 __ j(zero, &use_receiver, not_taken); | 359 __ j(zero, &use_receiver, Label::kFar, not_taken); |
| 360 | 360 |
| 361 // If the type of the result (stored in its map) is less than | 361 // If the type of the result (stored in its map) is less than |
| 362 // FIRST_JS_OBJECT_TYPE, it is not an object in the ECMA sense. | 362 // FIRST_JS_OBJECT_TYPE, it is not an object in the ECMA sense. |
| 363 __ CmpObjectType(eax, FIRST_JS_OBJECT_TYPE, ecx); | 363 __ CmpObjectType(eax, FIRST_JS_OBJECT_TYPE, ecx); |
| 364 __ j(above_equal, &exit, not_taken); | 364 __ j(above_equal, &exit, Label::kFar, not_taken); |
| 365 | 365 |
| 366 // Throw away the result of the constructor invocation and use the | 366 // Throw away the result of the constructor invocation and use the |
| 367 // on-stack receiver as the result. | 367 // on-stack receiver as the result. |
| 368 __ bind(&use_receiver); | 368 __ bind(&use_receiver); |
| 369 __ mov(eax, Operand(esp, 0)); | 369 __ mov(eax, Operand(esp, 0)); |
| 370 | 370 |
| 371 // Restore the arguments count and leave the construct frame. | 371 // Restore the arguments count and leave the construct frame. |
| 372 __ bind(&exit); | 372 __ bind(&exit); |
| 373 __ mov(ebx, Operand(esp, kPointerSize)); // get arguments count | 373 __ mov(ebx, Operand(esp, kPointerSize)); // get arguments count |
| 374 __ LeaveConstructFrame(); | 374 __ LeaveConstructFrame(); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 __ CallRuntime(Runtime::kNotifyDeoptimized, 1); | 513 __ CallRuntime(Runtime::kNotifyDeoptimized, 1); |
| 514 | 514 |
| 515 // Tear down temporary frame. | 515 // Tear down temporary frame. |
| 516 __ LeaveInternalFrame(); | 516 __ LeaveInternalFrame(); |
| 517 | 517 |
| 518 // Get the full codegen state from the stack and untag it. | 518 // Get the full codegen state from the stack and untag it. |
| 519 __ mov(ecx, Operand(esp, 1 * kPointerSize)); | 519 __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 520 __ SmiUntag(ecx); | 520 __ SmiUntag(ecx); |
| 521 | 521 |
| 522 // Switch on the state. | 522 // Switch on the state. |
| 523 NearLabel not_no_registers, not_tos_eax; | 523 Label not_no_registers, not_tos_eax; |
| 524 __ cmp(ecx, FullCodeGenerator::NO_REGISTERS); | 524 __ cmp(ecx, FullCodeGenerator::NO_REGISTERS); |
| 525 __ j(not_equal, ¬_no_registers); | 525 __ j(not_equal, ¬_no_registers, Label::kNear); |
| 526 __ ret(1 * kPointerSize); // Remove state. | 526 __ ret(1 * kPointerSize); // Remove state. |
| 527 | 527 |
| 528 __ bind(¬_no_registers); | 528 __ bind(¬_no_registers); |
| 529 __ mov(eax, Operand(esp, 2 * kPointerSize)); | 529 __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 530 __ cmp(ecx, FullCodeGenerator::TOS_REG); | 530 __ cmp(ecx, FullCodeGenerator::TOS_REG); |
| 531 __ j(not_equal, ¬_tos_eax); | 531 __ j(not_equal, ¬_tos_eax, Label::kNear); |
| 532 __ ret(2 * kPointerSize); // Remove state, eax. | 532 __ ret(2 * kPointerSize); // Remove state, eax. |
| 533 | 533 |
| 534 __ bind(¬_tos_eax); | 534 __ bind(¬_tos_eax); |
| 535 __ Abort("no cases left"); | 535 __ Abort("no cases left"); |
| 536 } | 536 } |
| 537 | 537 |
| 538 | 538 |
| 539 void Builtins::Generate_NotifyDeoptimized(MacroAssembler* masm) { | 539 void Builtins::Generate_NotifyDeoptimized(MacroAssembler* masm) { |
| 540 Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::EAGER); | 540 Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::EAGER); |
| 541 } | 541 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 561 __ ret(0); | 561 __ ret(0); |
| 562 } | 562 } |
| 563 | 563 |
| 564 | 564 |
| 565 void Builtins::Generate_FunctionCall(MacroAssembler* masm) { | 565 void Builtins::Generate_FunctionCall(MacroAssembler* masm) { |
| 566 Factory* factory = masm->isolate()->factory(); | 566 Factory* factory = masm->isolate()->factory(); |
| 567 | 567 |
| 568 // 1. Make sure we have at least one argument. | 568 // 1. Make sure we have at least one argument. |
| 569 { Label done; | 569 { Label done; |
| 570 __ test(eax, Operand(eax)); | 570 __ test(eax, Operand(eax)); |
| 571 __ j(not_zero, &done, taken); | 571 __ j(not_zero, &done, Label::kFar, taken); |
| 572 __ pop(ebx); | 572 __ pop(ebx); |
| 573 __ push(Immediate(factory->undefined_value())); | 573 __ push(Immediate(factory->undefined_value())); |
| 574 __ push(ebx); | 574 __ push(ebx); |
| 575 __ inc(eax); | 575 __ inc(eax); |
| 576 __ bind(&done); | 576 __ bind(&done); |
| 577 } | 577 } |
| 578 | 578 |
| 579 // 2. Get the function to call (passed as receiver) from the stack, check | 579 // 2. Get the function to call (passed as receiver) from the stack, check |
| 580 // if it is a function. | 580 // if it is a function. |
| 581 Label non_function; | 581 Label non_function; |
| 582 // 1 ~ return address. | 582 // 1 ~ return address. |
| 583 __ mov(edi, Operand(esp, eax, times_4, 1 * kPointerSize)); | 583 __ mov(edi, Operand(esp, eax, times_4, 1 * kPointerSize)); |
| 584 __ test(edi, Immediate(kSmiTagMask)); | 584 __ test(edi, Immediate(kSmiTagMask)); |
| 585 __ j(zero, &non_function, not_taken); | 585 __ j(zero, &non_function, Label::kFar, not_taken); |
| 586 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); | 586 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 587 __ j(not_equal, &non_function, not_taken); | 587 __ j(not_equal, &non_function, Label::kFar, not_taken); |
| 588 | 588 |
| 589 | 589 |
| 590 // 3a. Patch the first argument if necessary when calling a function. | 590 // 3a. Patch the first argument if necessary when calling a function. |
| 591 Label shift_arguments; | 591 Label shift_arguments; |
| 592 { Label convert_to_object, use_global_receiver, patch_receiver; | 592 { Label convert_to_object, use_global_receiver, patch_receiver; |
| 593 // Change context eagerly in case we need the global receiver. | 593 // Change context eagerly in case we need the global receiver. |
| 594 __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); | 594 __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); |
| 595 | 595 |
| 596 // Do not transform the receiver for strict mode functions. | 596 // Do not transform the receiver for strict mode functions. |
| 597 __ mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); | 597 __ mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 __ mov(Operand(esp, ecx, times_4, kPointerSize), ebx); | 677 __ mov(Operand(esp, ecx, times_4, kPointerSize), ebx); |
| 678 __ dec(ecx); | 678 __ dec(ecx); |
| 679 __ j(not_sign, &loop); // While non-negative (to copy return address). | 679 __ j(not_sign, &loop); // While non-negative (to copy return address). |
| 680 __ pop(ebx); // Discard copy of return address. | 680 __ pop(ebx); // Discard copy of return address. |
| 681 __ dec(eax); // One fewer argument (first argument is new receiver). | 681 __ dec(eax); // One fewer argument (first argument is new receiver). |
| 682 } | 682 } |
| 683 | 683 |
| 684 // 5a. Call non-function via tail call to CALL_NON_FUNCTION builtin. | 684 // 5a. Call non-function via tail call to CALL_NON_FUNCTION builtin. |
| 685 { Label function; | 685 { Label function; |
| 686 __ test(edi, Operand(edi)); | 686 __ test(edi, Operand(edi)); |
| 687 __ j(not_zero, &function, taken); | 687 __ j(not_zero, &function, Label::kFar, taken); |
| 688 __ Set(ebx, Immediate(0)); | 688 __ Set(ebx, Immediate(0)); |
| 689 __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); | 689 __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
| 690 __ jmp(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), | 690 __ jmp(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), |
| 691 RelocInfo::CODE_TARGET); | 691 RelocInfo::CODE_TARGET); |
| 692 __ bind(&function); | 692 __ bind(&function); |
| 693 } | 693 } |
| 694 | 694 |
| 695 // 5b. Get the code to call from the function and check that the number of | 695 // 5b. Get the code to call from the function and check that the number of |
| 696 // expected arguments matches what we're providing. If so, jump | 696 // expected arguments matches what we're providing. If so, jump |
| 697 // (tail-call) to the code in register edx without checking arguments. | 697 // (tail-call) to the code in register edx without checking arguments. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 726 // Make ecx the space we have left. The stack might already be overflowed | 726 // Make ecx the space we have left. The stack might already be overflowed |
| 727 // here which will cause ecx to become negative. | 727 // here which will cause ecx to become negative. |
| 728 __ mov(ecx, Operand(esp)); | 728 __ mov(ecx, Operand(esp)); |
| 729 __ sub(ecx, Operand(edi)); | 729 __ sub(ecx, Operand(edi)); |
| 730 // Make edx the space we need for the array when it is unrolled onto the | 730 // Make edx the space we need for the array when it is unrolled onto the |
| 731 // stack. | 731 // stack. |
| 732 __ mov(edx, Operand(eax)); | 732 __ mov(edx, Operand(eax)); |
| 733 __ shl(edx, kPointerSizeLog2 - kSmiTagSize); | 733 __ shl(edx, kPointerSizeLog2 - kSmiTagSize); |
| 734 // Check if the arguments will overflow the stack. | 734 // Check if the arguments will overflow the stack. |
| 735 __ cmp(ecx, Operand(edx)); | 735 __ cmp(ecx, Operand(edx)); |
| 736 __ j(greater, &okay, taken); // Signed comparison. | 736 __ j(greater, &okay, Label::kFar, taken); // Signed comparison. |
| 737 | 737 |
| 738 // Out of stack space. | 738 // Out of stack space. |
| 739 __ push(Operand(ebp, 4 * kPointerSize)); // push this | 739 __ push(Operand(ebp, 4 * kPointerSize)); // push this |
| 740 __ push(eax); | 740 __ push(eax); |
| 741 __ InvokeBuiltin(Builtins::APPLY_OVERFLOW, CALL_FUNCTION); | 741 __ InvokeBuiltin(Builtins::APPLY_OVERFLOW, CALL_FUNCTION); |
| 742 __ bind(&okay); | 742 __ bind(&okay); |
| 743 // End of stack check. | 743 // End of stack check. |
| 744 | 744 |
| 745 // Push current index and limit. | 745 // Push current index and limit. |
| 746 const int kLimitOffset = | 746 const int kLimitOffset = |
| (...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1570 | 1570 |
| 1571 // Pass the function to optimize as the argument to the on-stack | 1571 // Pass the function to optimize as the argument to the on-stack |
| 1572 // replacement runtime function. | 1572 // replacement runtime function. |
| 1573 __ EnterInternalFrame(); | 1573 __ EnterInternalFrame(); |
| 1574 __ push(eax); | 1574 __ push(eax); |
| 1575 __ CallRuntime(Runtime::kCompileForOnStackReplacement, 1); | 1575 __ CallRuntime(Runtime::kCompileForOnStackReplacement, 1); |
| 1576 __ LeaveInternalFrame(); | 1576 __ LeaveInternalFrame(); |
| 1577 | 1577 |
| 1578 // If the result was -1 it means that we couldn't optimize the | 1578 // If the result was -1 it means that we couldn't optimize the |
| 1579 // function. Just return and continue in the unoptimized version. | 1579 // function. Just return and continue in the unoptimized version. |
| 1580 NearLabel skip; | 1580 Label skip; |
| 1581 __ cmp(Operand(eax), Immediate(Smi::FromInt(-1))); | 1581 __ cmp(Operand(eax), Immediate(Smi::FromInt(-1))); |
| 1582 __ j(not_equal, &skip); | 1582 __ j(not_equal, &skip, Label::kNear); |
| 1583 __ ret(0); | 1583 __ ret(0); |
| 1584 | 1584 |
| 1585 // If we decide not to perform on-stack replacement we perform a | 1585 // If we decide not to perform on-stack replacement we perform a |
| 1586 // stack guard check to enable interrupts. | 1586 // stack guard check to enable interrupts. |
| 1587 __ bind(&stack_check); | 1587 __ bind(&stack_check); |
| 1588 NearLabel ok; | 1588 Label ok; |
| 1589 ExternalReference stack_limit = | 1589 ExternalReference stack_limit = |
| 1590 ExternalReference::address_of_stack_limit(masm->isolate()); | 1590 ExternalReference::address_of_stack_limit(masm->isolate()); |
| 1591 __ cmp(esp, Operand::StaticVariable(stack_limit)); | 1591 __ cmp(esp, Operand::StaticVariable(stack_limit)); |
| 1592 __ j(above_equal, &ok, taken); | 1592 __ j(above_equal, &ok, Label::kNear, taken); |
| 1593 StackCheckStub stub; | 1593 StackCheckStub stub; |
| 1594 __ TailCallStub(&stub); | 1594 __ TailCallStub(&stub); |
| 1595 __ Abort("Unreachable code: returned from tail call."); | 1595 __ Abort("Unreachable code: returned from tail call."); |
| 1596 __ bind(&ok); | 1596 __ bind(&ok); |
| 1597 __ ret(0); | 1597 __ ret(0); |
| 1598 | 1598 |
| 1599 __ bind(&skip); | 1599 __ bind(&skip); |
| 1600 // Untag the AST id and push it on the stack. | 1600 // Untag the AST id and push it on the stack. |
| 1601 __ SmiUntag(eax); | 1601 __ SmiUntag(eax); |
| 1602 __ push(eax); | 1602 __ push(eax); |
| 1603 | 1603 |
| 1604 // Generate the code for doing the frame-to-frame translation using | 1604 // Generate the code for doing the frame-to-frame translation using |
| 1605 // the deoptimizer infrastructure. | 1605 // the deoptimizer infrastructure. |
| 1606 Deoptimizer::EntryGenerator generator(masm, Deoptimizer::OSR); | 1606 Deoptimizer::EntryGenerator generator(masm, Deoptimizer::OSR); |
| 1607 generator.Generate(); | 1607 generator.Generate(); |
| 1608 } | 1608 } |
| 1609 | 1609 |
| 1610 | 1610 |
| 1611 #undef __ | 1611 #undef __ |
| 1612 } | 1612 } |
| 1613 } // namespace v8::internal | 1613 } // namespace v8::internal |
| 1614 | 1614 |
| 1615 #endif // V8_TARGET_ARCH_IA32 | 1615 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |