| 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 14 matching lines...) Expand all Loading... |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #if defined(V8_TARGET_ARCH_IA32) | 30 #if defined(V8_TARGET_ARCH_IA32) |
| 31 | 31 |
| 32 #include "code-stubs.h" | 32 #include "code-stubs.h" |
| 33 #include "bootstrapper.h" | 33 #include "bootstrapper.h" |
| 34 #include "jsregexp.h" | 34 #include "jsregexp.h" |
| 35 #include "macro-assembler-ia32-inl.h" |
| 35 #include "regexp-macro-assembler.h" | 36 #include "regexp-macro-assembler.h" |
| 36 | 37 |
| 37 namespace v8 { | 38 namespace v8 { |
| 38 namespace internal { | 39 namespace internal { |
| 39 | 40 |
| 40 #define __ ACCESS_MASM(masm) | 41 #define __ ACCESS_MASM(masm) |
| 41 | 42 |
| 42 void ToNumberStub::Generate(MacroAssembler* masm) { | 43 void ToNumberStub::Generate(MacroAssembler* masm) { |
| 43 // The ToNumber stub takes one argument in eax. | 44 // The ToNumber stub takes one argument in eax. |
| 44 NearLabel check_heap_number, call_builtin; | 45 NearLabel check_heap_number, call_builtin; |
| (...skipping 3993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4038 // ebx: last_match_info backing store (FixedArray) | 4039 // ebx: last_match_info backing store (FixedArray) |
| 4039 // edx: number of capture registers | 4040 // edx: number of capture registers |
| 4040 // Store the capture count. | 4041 // Store the capture count. |
| 4041 __ SmiTag(edx); // Number of capture registers to smi. | 4042 __ SmiTag(edx); // Number of capture registers to smi. |
| 4042 __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); | 4043 __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 4043 __ SmiUntag(edx); // Number of capture registers back from smi. | 4044 __ SmiUntag(edx); // Number of capture registers back from smi. |
| 4044 // Store last subject and last input. | 4045 // Store last subject and last input. |
| 4045 __ mov(eax, Operand(esp, kSubjectOffset)); | 4046 __ mov(eax, Operand(esp, kSubjectOffset)); |
| 4046 __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); | 4047 __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
| 4047 __ mov(ecx, ebx); | 4048 __ mov(ecx, ebx); |
| 4048 __ RecordWrite(ecx, | 4049 __ RecordWriteField(ecx, |
| 4049 RegExpImpl::kLastSubjectOffset, | 4050 RegExpImpl::kLastSubjectOffset, |
| 4050 eax, | 4051 eax, |
| 4051 edi, | 4052 edi, |
| 4052 kDontSaveFPRegs); | 4053 kDontSaveFPRegs); |
| 4053 __ mov(eax, Operand(esp, kSubjectOffset)); | 4054 __ mov(eax, Operand(esp, kSubjectOffset)); |
| 4054 __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); | 4055 __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
| 4055 __ mov(ecx, ebx); | 4056 __ mov(ecx, ebx); |
| 4056 __ RecordWrite(ecx, RegExpImpl::kLastInputOffset, eax, edi, kDontSaveFPRegs); | 4057 __ RecordWriteField(ecx, |
| 4058 RegExpImpl::kLastInputOffset, |
| 4059 eax, |
| 4060 edi, |
| 4061 kDontSaveFPRegs); |
| 4057 | 4062 |
| 4058 // Get the static offsets vector filled by the native regexp code. | 4063 // Get the static offsets vector filled by the native regexp code. |
| 4059 ExternalReference address_of_static_offsets_vector = | 4064 ExternalReference address_of_static_offsets_vector = |
| 4060 ExternalReference::address_of_static_offsets_vector(); | 4065 ExternalReference::address_of_static_offsets_vector(); |
| 4061 __ mov(ecx, Immediate(address_of_static_offsets_vector)); | 4066 __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 4062 | 4067 |
| 4063 // ebx: last_match_info backing store (FixedArray) | 4068 // ebx: last_match_info backing store (FixedArray) |
| 4064 // ecx: offsets vector | 4069 // ecx: offsets vector |
| 4065 // edx: number of capture registers | 4070 // edx: number of capture registers |
| 4066 NearLabel next_capture, done; | 4071 NearLabel next_capture, done; |
| (...skipping 2401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6468 __ pop(ecx); | 6473 __ pop(ecx); |
| 6469 __ pop(eax); | 6474 __ pop(eax); |
| 6470 __ pop(edx); | 6475 __ pop(edx); |
| 6471 __ push(ecx); | 6476 __ push(ecx); |
| 6472 | 6477 |
| 6473 // Do a tail call to the rewritten stub. | 6478 // Do a tail call to the rewritten stub. |
| 6474 __ jmp(Operand(edi)); | 6479 __ jmp(Operand(edi)); |
| 6475 } | 6480 } |
| 6476 | 6481 |
| 6477 | 6482 |
| 6483 // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 6484 // the value has just been written into the object, now this stub makes sure |
| 6485 // we keep the GC informed. The word in the object where the value has been |
| 6486 // written is in the address register. |
| 6478 void RecordWriteStub::Generate(MacroAssembler* masm) { | 6487 void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 6479 NearLabel skip_incremental_part; | 6488 NearLabel skip_non_incremental_part; |
| 6480 __ jmp(&skip_incremental_part); | 6489 __ jmp(&skip_non_incremental_part); |
| 6481 if (!IncrementalMarking::IsStopped()) { | 6490 if (IncrementalMarking::IsStopped()) { |
| 6482 ASSERT(masm->get_opcode(-2) == kSkipIncrementalPartInstruction); | 6491 ASSERT(masm->get_opcode(-2) == kSkipNonIncrementalPartInstruction); |
| 6483 masm->set_opcode(-2, kTwoByteNopInstruction); | 6492 masm->set_opcode(-2, kTwoByteNopInstruction); |
| 6484 } | 6493 } |
| 6485 | 6494 |
| 6486 // If we are also emitting the remembered set code in this stub then we have | 6495 if (emit_remembered_set_ == EMIT_REMEMBERED_SET) { |
| 6487 // the object we are writing into in the 'object' register and the slot in | 6496 NearLabel skip; |
| 6488 // the 'address' register. We insert a primitive test here to ensure that | 6497 __ InNewSpace(address_, value_, equal, &skip); |
| 6489 // this is the case. Otherwise the 'address' register is merely a scratch | 6498 __ HasScanOnScavenge(object_, value_, &skip); |
| 6490 // register. | 6499 __ RememberedSetHelper(address_, value_, save_fp_regs_mode_); |
| 6491 if (FLAG_debug_code && emit_remembered_set_ == EMIT_REMEMBERED_SET) { | 6500 __ bind(&skip); |
| 6501 } |
| 6502 __ ret(0); |
| 6503 |
| 6504 __ bind(&skip_non_incremental_part); |
| 6505 |
| 6506 GenerateIncremental(masm); |
| 6507 } |
| 6508 |
| 6509 |
| 6510 void RecordWriteStub::GenerateIncremental(MacroAssembler* masm) { |
| 6511 RegisterAllocation regs(masm, |
| 6512 object_, // An input reg. |
| 6513 address_, // An input reg. |
| 6514 value_); // One scratch reg. |
| 6515 regs_ = ®s; |
| 6516 if (FLAG_debug_code) { |
| 6492 NearLabel ok; | 6517 NearLabel ok; |
| 6493 __ cmp(address_, Operand(object_)); | 6518 __ cmp(value_, Operand(address_, 0)); |
| 6494 __ j(above_equal, &ok); | 6519 __ j(equal, &ok); |
| 6495 __ int3(); | 6520 __ int3(); |
| 6496 __ bind(&ok); | 6521 __ bind(&ok); |
| 6497 } | 6522 } |
| 6498 | 6523 |
| 6499 __ IncrementalMarkingRecordWriteHelper(object_, value_, address_); | 6524 regs.Save(); |
| 6500 | 6525 |
| 6501 __ bind(&skip_incremental_part); | 6526 Label increment_marker_slow_case; |
| 6502 | 6527 slow_ = &increment_marker_slow_case; |
| 6528 Label value_in_old_space; |
| 6529 |
| 6530 __ InNewSpace(value_, regs.scratch0(), not_equal, &value_in_old_space); |
| 6531 // After this point the value_ register may have been overwritten since it is |
| 6532 // also one of the scratch registers. |
| 6533 |
| 6534 GenerateIncrementalValueIsInNewSpace(masm); |
| 6535 |
| 6536 __ bind(&value_in_old_space); |
| 6537 GenerateIncrementalValueIsInOldSpace(masm); |
| 6538 |
| 6539 __ bind(slow_); |
| 6540 // Inform the incremental marker, but don't bother with the remembered set. |
| 6541 regs.SaveCallerSaveRegisters(); |
| 6542 // TODO(gc) we are assuming that xmm registers are not modified by |
| 6543 // the C function we are calling. |
| 6544 __ PrepareCallCFunction(2, regs.scratch0()); |
| 6545 __ mov(Operand(esp, 0 * kPointerSize), regs.object()); |
| 6546 __ mov(regs.scratch0(), Operand(regs.address(), 0)); |
| 6547 __ mov(Operand(esp, 1 * kPointerSize), regs.scratch0()); // Value. |
| 6548 // TODO(gc): Create a fast version of this C function that does not duplicate |
| 6549 // the checks done in the stub. |
| 6550 __ CallCFunction( |
| 6551 ExternalReference::incremental_marking_record_write_function(), 2); |
| 6552 regs.RestoreCallerSaveRegisters(); |
| 6553 regs.Restore(); |
| 6554 __ ret(0); |
| 6555 } |
| 6556 |
| 6557 |
| 6558 void RecordWriteStub::GenerateIncrementalValueIsInNewSpace( |
| 6559 MacroAssembler* masm) { |
| 6560 Label both_in_new_space; |
| 6561 Label value_in_new_space_object_is_black_no_remembered_set; |
| 6562 |
| 6563 // The value is in new space. Check the object. |
| 6564 __ InNewSpace(regs_->object(), regs_->scratch0(), equal, &both_in_new_space); |
| 6565 |
| 6566 // Value is in new space, object is in old space. Could we be lucky and find |
| 6567 // the scan_on_scavenge flag on the object's page? |
| 6503 if (emit_remembered_set_ == EMIT_REMEMBERED_SET) { | 6568 if (emit_remembered_set_ == EMIT_REMEMBERED_SET) { |
| 6504 Register scratch = value_; | 6569 Label scan_on_scavenge; |
| 6505 NearLabel done; | 6570 __ HasScanOnScavenge(object_, value_, &scan_on_scavenge); |
| 6506 __ InNewSpace(object_, scratch, equal, &done); | 6571 GenerateIncrementalValueIsInNewSpaceObjectIsInOldSpaceRememberedSet(masm); |
| 6507 __ RememberedSetHelper(object_, address_, scratch, save_fp_regs_mode_); | 6572 __ bind(&scan_on_scavenge); |
| 6508 __ bind(&done); | 6573 } |
| 6509 } | 6574 // This function will also bind the label. |
| 6575 GenerateIncrementalValueIsInNewSpaceObjectIsInOldSpaceNoRememberedSet( |
| 6576 masm, &value_in_new_space_object_is_black_no_remembered_set); |
| 6577 |
| 6578 __ bind(&both_in_new_space); |
| 6579 __ InNewSpaceIsBlack(regs_->object(), |
| 6580 regs_->scratch0(), |
| 6581 regs_->scratch1(), |
| 6582 &value_in_new_space_object_is_black_no_remembered_set); |
| 6583 regs_->Restore(); |
| 6584 __ ret(0); |
| 6585 } |
| 6586 |
| 6587 |
| 6588 void RecordWriteStub:: |
| 6589 GenerateIncrementalValueIsInNewSpaceObjectIsInOldSpaceRememberedSet( |
| 6590 MacroAssembler* masm) { |
| 6591 NearLabel object_is_black, must_inform_both; |
| 6592 |
| 6593 // Lets look at the colour of the object: If it is not black we don't have to |
| 6594 // inform the incremental marker. |
| 6595 __ InOldSpaceIsBlack(regs_->object(), |
| 6596 regs_->scratch0(), |
| 6597 regs_->scratch1(), |
| 6598 &object_is_black); |
| 6599 regs_->Restore(); |
| 6600 __ RememberedSetHelper(address_, value_, save_fp_regs_mode_); |
| 6601 __ ret(0); |
| 6602 |
| 6603 __ bind(&object_is_black); |
| 6604 |
| 6605 __ mov(regs_->scratch0(), Operand(regs_->address(), 0)); |
| 6606 __ push(regs_->object()); |
| 6607 __ EnsureNotWhite(regs_->scratch0(), // The value. |
| 6608 regs_->scratch1(), // Scratch. |
| 6609 regs_->object(), // Scratch. |
| 6610 &must_inform_both, |
| 6611 true); // In new space. |
| 6612 __ pop(regs_->object()); |
| 6613 regs_->Restore(); |
| 6614 __ RememberedSetHelper(address_, value_, save_fp_regs_mode_); |
| 6615 __ ret(0); |
| 6616 |
| 6617 __ bind(&must_inform_both); |
| 6618 // Both the incremental marker and the the remembered set have to be informed. |
| 6619 __ pop(regs_->object()); |
| 6620 regs_->SaveCallerSaveRegisters(); |
| 6621 // TODO(gc) we are assuming that xmm registers are not modified by |
| 6622 // the C function we are calling. |
| 6623 __ PrepareCallCFunction(2, regs_->scratch0()); |
| 6624 __ mov(Operand(esp, 0 * kPointerSize), regs_->object()); |
| 6625 __ mov(regs_->scratch0(), Operand(regs_->address(), 0)); |
| 6626 __ mov(Operand(esp, 1 * kPointerSize), regs_->scratch0()); // Value. |
| 6627 __ CallCFunction( |
| 6628 ExternalReference::incremental_marking_record_write_function(), 2); |
| 6629 regs_->RestoreCallerSaveRegisters(); |
| 6630 regs_->Restore(); |
| 6631 __ RememberedSetHelper(address_, value_, save_fp_regs_mode_); |
| 6632 __ ret(0); |
| 6633 } |
| 6634 |
| 6635 |
| 6636 void RecordWriteStub:: |
| 6637 GenerateIncrementalValueIsInNewSpaceObjectIsInOldSpaceNoRememberedSet( |
| 6638 MacroAssembler* masm, |
| 6639 Label* value_in_new_space_object_is_black_no_remembered_set) { |
| 6640 NearLabel object_is_black, inform_incremental_marker; |
| 6641 |
| 6642 __ InOldSpaceIsBlack(regs_->object(), |
| 6643 regs_->scratch0(), |
| 6644 regs_->scratch1(), |
| 6645 &object_is_black); |
| 6646 regs_->Restore(); |
| 6647 __ ret(0); |
| 6648 |
| 6649 __ bind(&object_is_black); |
| 6650 __ bind(value_in_new_space_object_is_black_no_remembered_set); |
| 6651 |
| 6652 // Reload the value from the word in the object. |
| 6653 __ mov(regs_->scratch0(), Operand(regs_->address(), 0)); |
| 6654 |
| 6655 // We need one more scratch register in this case. Use the object register. |
| 6656 __ push(regs_->object()); |
| 6657 |
| 6658 // Make sure the value is not white. If we can't do that, jump to the label. |
| 6659 __ EnsureNotWhite(regs_->scratch0(), // The value. |
| 6660 regs_->scratch1(), // Scratch. |
| 6661 regs_->object(), // Scratch. |
| 6662 &inform_incremental_marker, |
| 6663 true); // In new space. |
| 6664 __ pop(regs_->object()); |
| 6665 regs_->Restore(); |
| 6666 __ ret(0); |
| 6667 |
| 6668 __ bind(&inform_incremental_marker); |
| 6669 __ pop(regs_->object()); |
| 6670 |
| 6671 __ jmp(slow_); |
| 6672 } |
| 6673 |
| 6674 |
| 6675 void RecordWriteStub::GenerateIncrementalValueIsInOldSpace( |
| 6676 MacroAssembler* masm) { |
| 6677 NearLabel value_is_white; |
| 6678 Label value_in_old_space_and_white_object_in_new_space; |
| 6679 // If the value is in old space then the remembered set doesn't care. We may |
| 6680 // be able to avoid logging anything if the incremental marker doesn't care |
| 6681 // either. |
| 6682 __ mov(regs_->scratch0(), Operand(regs_->address(), 0)); |
| 6683 __ push(regs_->object()); |
| 6684 __ EnsureNotWhite(regs_->scratch0(), // The value. |
| 6685 regs_->scratch1(), // Scratch. |
| 6686 regs_->object(), // Scratch. |
| 6687 &value_is_white, |
| 6688 false); // In old space. |
| 6689 __ pop(regs_->object()); |
| 6690 regs_->Restore(); |
| 6691 __ ret(0); |
| 6692 |
| 6693 // The value is in old space and white. We have to find out which space the |
| 6694 // object is in in order to find its colour. |
| 6695 __ bind(&value_is_white); |
| 6696 __ pop(regs_->object()); |
| 6697 __ InNewSpace(regs_->object(), |
| 6698 regs_->scratch0(), |
| 6699 equal, |
| 6700 &value_in_old_space_and_white_object_in_new_space); |
| 6701 |
| 6702 // Both in old space, value is white and can't be marked. |
| 6703 __ InOldSpaceIsBlack(regs_->object(), |
| 6704 regs_->scratch0(), |
| 6705 regs_->scratch1(), |
| 6706 slow_); |
| 6707 regs_->Restore(); |
| 6708 __ ret(0); |
| 6709 |
| 6710 // Object in new space, value in old space and white and can't be marked. |
| 6711 __ bind(&value_in_old_space_and_white_object_in_new_space); |
| 6712 __ InNewSpaceIsBlack(regs_->object(), |
| 6713 regs_->scratch0(), |
| 6714 regs_->scratch1(), |
| 6715 slow_); |
| 6716 regs_->Restore(); |
| 6510 __ ret(0); | 6717 __ ret(0); |
| 6511 } | 6718 } |
| 6512 | 6719 |
| 6513 | 6720 |
| 6514 #undef __ | 6721 #undef __ |
| 6515 | 6722 |
| 6516 } } // namespace v8::internal | 6723 } } // namespace v8::internal |
| 6517 | 6724 |
| 6518 #endif // V8_TARGET_ARCH_IA32 | 6725 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |