OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 } | 515 } |
516 | 516 |
517 | 517 |
518 void Builtins::Generate_FunctionApply(MacroAssembler* masm) { | 518 void Builtins::Generate_FunctionApply(MacroAssembler* masm) { |
519 __ EnterInternalFrame(); | 519 __ EnterInternalFrame(); |
520 | 520 |
521 __ push(Operand(ebp, 4 * kPointerSize)); // push this | 521 __ push(Operand(ebp, 4 * kPointerSize)); // push this |
522 __ push(Operand(ebp, 2 * kPointerSize)); // push arguments | 522 __ push(Operand(ebp, 2 * kPointerSize)); // push arguments |
523 __ InvokeBuiltin(Builtins::APPLY_PREPARE, CALL_FUNCTION); | 523 __ InvokeBuiltin(Builtins::APPLY_PREPARE, CALL_FUNCTION); |
524 | 524 |
525 // Check the stack for overflow or a break request. | 525 // Check the stack for overflow. We are not trying need to catch |
526 // We need to catch preemptions right here, otherwise an unlucky preemption | 526 // interruptions (e.g. debug break and preemption) here, so the "real stack |
527 // could show up as a failed apply. | 527 // limit" is checked. |
528 ExternalReference stack_guard_limit = | |
529 ExternalReference::address_of_stack_guard_limit(); | |
530 Label retry_preemption; | |
531 Label no_preemption; | |
532 __ bind(&retry_preemption); | |
533 __ mov(edi, Operand::StaticVariable(stack_guard_limit)); | |
534 __ cmp(esp, Operand(edi)); | |
535 __ j(above, &no_preemption, taken); | |
536 | |
537 // Preemption! | |
538 // Because builtins always remove the receiver from the stack, we | |
539 // have to fake one to avoid underflowing the stack. | |
540 __ push(eax); | |
541 __ push(Immediate(Smi::FromInt(0))); | |
542 | |
543 // Do call to runtime routine. | |
544 __ CallRuntime(Runtime::kStackGuard, 1); | |
545 __ pop(eax); | |
546 __ jmp(&retry_preemption); | |
547 | |
548 __ bind(&no_preemption); | |
549 | |
550 Label okay; | 528 Label okay; |
551 // Make ecx the space we have left. | 529 ExternalReference real_stack_limit = |
| 530 ExternalReference::address_of_real_stack_limit(); |
| 531 __ mov(edi, Operand::StaticVariable(real_stack_limit)); |
| 532 // Make ecx the space we have left. The stack might already be overflowed |
| 533 // here which will cause ecx to become negative. |
552 __ mov(ecx, Operand(esp)); | 534 __ mov(ecx, Operand(esp)); |
553 __ sub(ecx, Operand(edi)); | 535 __ sub(ecx, Operand(edi)); |
554 // Make edx the space we need for the array when it is unrolled onto the | 536 // Make edx the space we need for the array when it is unrolled onto the |
555 // stack. | 537 // stack. |
556 __ mov(edx, Operand(eax)); | 538 __ mov(edx, Operand(eax)); |
557 __ shl(edx, kPointerSizeLog2 - kSmiTagSize); | 539 __ shl(edx, kPointerSizeLog2 - kSmiTagSize); |
| 540 // Check if the arguments will overflow the stack. |
558 __ cmp(ecx, Operand(edx)); | 541 __ cmp(ecx, Operand(edx)); |
559 __ j(greater, &okay, taken); | 542 __ j(greater, &okay, taken); // Signed comparison. |
560 | 543 |
561 // Too bad: Out of stack space. | 544 // Out of stack space. |
562 __ push(Operand(ebp, 4 * kPointerSize)); // push this | 545 __ push(Operand(ebp, 4 * kPointerSize)); // push this |
563 __ push(eax); | 546 __ push(eax); |
564 __ InvokeBuiltin(Builtins::APPLY_OVERFLOW, CALL_FUNCTION); | 547 __ InvokeBuiltin(Builtins::APPLY_OVERFLOW, CALL_FUNCTION); |
565 __ bind(&okay); | 548 __ bind(&okay); |
566 // End of stack check. | 549 // End of stack check. |
567 | 550 |
568 // Push current index and limit. | 551 // Push current index and limit. |
569 const int kLimitOffset = | 552 const int kLimitOffset = |
570 StandardFrameConstants::kExpressionsOffset - 1 * kPointerSize; | 553 StandardFrameConstants::kExpressionsOffset - 1 * kPointerSize; |
571 const int kIndexOffset = kLimitOffset - 1 * kPointerSize; | 554 const int kIndexOffset = kLimitOffset - 1 * kPointerSize; |
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1228 // Dont adapt arguments. | 1211 // Dont adapt arguments. |
1229 // ------------------------------------------- | 1212 // ------------------------------------------- |
1230 __ bind(&dont_adapt_arguments); | 1213 __ bind(&dont_adapt_arguments); |
1231 __ jmp(Operand(edx)); | 1214 __ jmp(Operand(edx)); |
1232 } | 1215 } |
1233 | 1216 |
1234 | 1217 |
1235 #undef __ | 1218 #undef __ |
1236 | 1219 |
1237 } } // namespace v8::internal | 1220 } } // namespace v8::internal |
OLD | NEW |