Chromium Code Reviews| Index: src/ia32/code-stubs-ia32.cc |
| =================================================================== |
| --- src/ia32/code-stubs-ia32.cc (revision 7619) |
| +++ src/ia32/code-stubs-ia32.cc (working copy) |
| @@ -32,6 +32,7 @@ |
| #include "code-stubs.h" |
| #include "bootstrapper.h" |
| #include "jsregexp.h" |
| +#include "macro-assembler-ia32-inl.h" |
| #include "regexp-macro-assembler.h" |
| namespace v8 { |
| @@ -4045,15 +4046,19 @@ |
| __ mov(eax, Operand(esp, kSubjectOffset)); |
| __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
| __ mov(ecx, ebx); |
| - __ RecordWrite(ecx, |
| - RegExpImpl::kLastSubjectOffset, |
| - eax, |
| - edi, |
| - kDontSaveFPRegs); |
| + __ RecordWriteField(ecx, |
| + RegExpImpl::kLastSubjectOffset, |
| + eax, |
| + edi, |
| + kDontSaveFPRegs); |
| __ mov(eax, Operand(esp, kSubjectOffset)); |
| __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
| __ mov(ecx, ebx); |
| - __ RecordWrite(ecx, RegExpImpl::kLastInputOffset, eax, edi, kDontSaveFPRegs); |
| + __ RecordWriteField(ecx, |
| + RegExpImpl::kLastInputOffset, |
| + eax, |
| + edi, |
| + kDontSaveFPRegs); |
| // Get the static offsets vector filled by the native regexp code. |
| ExternalReference address_of_static_offsets_vector = |
| @@ -6475,39 +6480,326 @@ |
| } |
| +// This is a helper class for freeing up 3 scratch registers, where the third |
| +// is always ecx (needed for shift operations). The input is two registers |
| +// that must be preserved and one scratch register provided by the caller. |
| +class ThreeScratchRegisters { |
| + public: |
| + ThreeScratchRegisters(MacroAssembler* masm, |
| + Register object, |
| + Register address, |
| + Register scratch0) |
| + : masm_(masm), |
| + object_orig_(object), |
| + address_orig_(address), |
| + scratch0_orig_(scratch0), |
| + object_(object), |
| + address_(address), |
| + scratch0_(scratch0) { |
| + ASSERT(!Aliasing(scratch0, object, address, no_reg)); |
| + if (object.is(ecx)) { |
| + object_ = GetRegThatIsNotEcxOr(address_, scratch0_, no_reg); |
| + } |
| + if (address.is(ecx)) { |
| + address_ = GetRegThatIsNotEcxOr(object_, scratch0_, no_reg); |
| + } |
| + if (scratch0.is(ecx)) { |
| + scratch0_ = GetRegThatIsNotEcxOr(object_, address_, no_reg); |
| + } |
| + ASSERT(!Aliasing(scratch0_, object_, address_, ecx)); |
| + scratch1_ = GetRegThatIsNotEcxOr(object_, address_, scratch0_); |
| + } |
| + |
| + void Save() { |
| + // We don't have to save scratch0_orig_ because it was given to us as |
| + // a scratch register. But if we had to switch to a different reg then |
| + // we should save the new scratch0_. |
| + if (!scratch0_.is(scratch0_orig_)) masm_->push(scratch0_); |
| + masm_->push(scratch1_); |
| + ASSERT(!address_orig_.is(object_)); |
| + ASSERT(object_.is(object_orig_) || address_.is(address_orig_)); |
| + masm_->Move(object_, object_orig_); |
| + masm_->Move(address_, address_orig_); |
| + // We have to save ecx, because we are going to need it for the bit |
| + // twiddling, but if we were given ecx as scratch0_orig_ then we don't |
| + // need to save it because the caller is expecting it to be trashed. |
| + if (!ecx.is(scratch0_orig_)) masm_->push(ecx); |
| + } |
| + |
| + void Restore() { |
| + // Do this first because ecx may be one of the orig_ registers. |
| + if (!ecx.is(scratch0_orig_)) masm_->pop(ecx); |
| + // These will have been preserved the entire time, so we just need to move |
| + // them back. Only in one case is the orig_ reg different from the plain |
| + // one, since only one of them can alias with ecx. |
| + ASSERT(object_.is(object_orig_) || address_.is(address_orig_)); |
| + masm_->Move(address_orig_, address_); |
| + masm_->Move(object_orig_, object_); |
| + ASSERT(!Aliasing(object_, address_, scratch1_, scratch0_)); |
| + ASSERT(!Aliasing(object_orig_, address_, scratch1_, scratch0_)); |
| + ASSERT(!Aliasing(object_, address_orig_, scratch1_, scratch0_)); |
| + masm_->pop(scratch1_); |
| + if (!scratch0_.is(scratch0_orig_)) masm_->pop(scratch0_); |
| + } |
| + |
| + // If we have to call into C then we need to save and restore all registers |
| + // that were not already preserved. The three scratch registers will be |
| + // restored by other means so we don't bother pushing them here. |
| + void SaveTheRest() { |
|
Vyacheslav Egorov (Chromium)
2011/04/16 17:50:36
When calling into C you need to save only eax, ecx
Erik Corry
2011/04/23 17:00:11
Done.
|
| + for (int i = 0; i < Register::kNumRegisters; i++) { |
| + Register candidate = Register::from_code(i); |
| + if (candidate.is(ecx)) continue; |
| + if (candidate.is(esp)) continue; |
| + if (candidate.is(scratch0_)) continue; |
| + if (candidate.is(scratch1_)) continue; |
| + masm_->push(candidate); |
| + } |
| + } |
| + |
| + void RestoreTheRest() { |
| + for (int i = Register::kNumRegisters - 1; i >= 0; i--) { |
| + Register candidate = Register::from_code(i); |
| + if (candidate.is(ecx)) continue; |
| + if (candidate.is(esp)) continue; |
| + if (candidate.is(scratch0_)) continue; |
| + if (candidate.is(scratch1_)) continue; |
| + masm_->pop(candidate); |
| + } |
| + } |
| + |
| + Register object() { return object_; } |
| + Register address() { return address_; } |
| + Register scratch0() { return scratch0_; } |
| + Register scratch1() { return scratch1_; } |
| + |
| + private: |
| + MacroAssembler* masm_; |
| + Register object_orig_; |
| + Register address_orig_; |
| + Register scratch0_orig_; |
| + Register object_; |
| + Register address_; |
| + Register scratch0_; |
| + Register scratch1_; |
| + // Third scratch register is always ecx. |
| + |
| + Register GetRegThatIsNotEcxOr(Register r1, |
| + Register r2, |
| + Register r3) { |
| + for (int i = 0; i < Register::kNumAllocatableRegisters; i++) { |
| + Register candidate = Register::FromAllocationIndex(i); |
| + if (candidate.is(ecx)) continue; |
| + if (candidate.is(r1)) continue; |
| + if (candidate.is(r2)) continue; |
| + if (candidate.is(r3)) continue; |
| + return candidate; |
| + } |
| + UNREACHABLE(); |
| + return no_reg; |
| + } |
| +}; |
| + |
| + |
| +// Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| +// the value has just been written into the object, now this stub makes sure |
| +// we keep the GC informed. The word in the object where the value has been |
| +// written is in the address register. |
| void RecordWriteStub::Generate(MacroAssembler* masm) { |
| - NearLabel skip_incremental_part; |
| - __ jmp(&skip_incremental_part); |
| - if (!IncrementalMarking::IsStopped()) { |
| - ASSERT(masm->get_opcode(-2) == kSkipIncrementalPartInstruction); |
| + NearLabel skip_non_incremental_part; |
| + __ jmp(&skip_non_incremental_part); |
| + if (IncrementalMarking::IsStopped()) { |
| + ASSERT(masm->get_opcode(-2) == kSkipNonIncrementalPartInstruction); |
| masm->set_opcode(-2, kTwoByteNopInstruction); |
| } |
| - // If we are also emitting the remembered set code in this stub then we have |
| - // the object we are writing into in the 'object' register and the slot in |
| - // the 'address' register. We insert a primitive test here to ensure that |
| - // this is the case. Otherwise the 'address' register is merely a scratch |
| - // register. |
| - if (FLAG_debug_code && emit_remembered_set_ == EMIT_REMEMBERED_SET) { |
| + if (emit_remembered_set_ == EMIT_REMEMBERED_SET) { |
| + NearLabel skip; |
| + __ InNewSpace(address_, value_, equal, &skip); |
| + __ HasScanOnScavenge(object_, value_, &skip); |
| + __ RememberedSetHelper(address_, value_, save_fp_regs_mode_); |
| + __ bind(&skip); |
| + } |
| + __ ret(0); |
| + |
| + __ bind(&skip_non_incremental_part); |
| + |
| + ThreeScratchRegisters regs(masm, |
| + object_, // An input reg. |
| + address_, // An input reg. |
| + value_); // One scratch reg. |
| + if (FLAG_debug_code) { |
| NearLabel ok; |
| - __ cmp(address_, Operand(object_)); |
| - __ j(above_equal, &ok); |
| + __ cmp(value_, Operand(address_, 0)); |
| + __ j(equal, &ok); |
| __ int3(); |
| __ bind(&ok); |
| } |
| - __ IncrementalMarkingRecordWriteHelper(object_, value_, address_); |
| + regs.Save(); |
| - __ bind(&skip_incremental_part); |
| + NearLabel scan_on_scavenge, must_inform_both, value_in_old_space_and_white; |
| + NearLabel pop_object_then_must_inform_incremental_marker; |
| + Label object_is_black_remembered_set_needed; |
| + Label value_in_old_space, both_in_new_space, must_inform_incremental_marker; |
| + NearLabel value_in_old_space_and_white_object_in_new_space; |
| + Label object_is_black_remembered_set_not_needed; |
| + NearLabel near_object_is_black_remembered_set_not_needed; |
| + __ InNewSpace(value_, regs.scratch0(), not_equal, &value_in_old_space); |
| + |
| + // After this point the value_ register may have been overwritten since it is |
| + // also one of the scratch registers. |
| + |
| + // The value is in new space. Check the object. |
| + __ InNewSpace(regs.object(), regs.scratch0(), equal, &both_in_new_space); |
| + |
| + // Value is in new space, object is in old space. Could we be lucky and find |
| + // the scan_on_scavenge flag on the object's page? |
| if (emit_remembered_set_ == EMIT_REMEMBERED_SET) { |
| - Register scratch = value_; |
| - NearLabel done; |
| - __ InNewSpace(object_, scratch, equal, &done); |
| - __ RememberedSetHelper(object_, address_, scratch, save_fp_regs_mode_); |
| - __ bind(&done); |
| + __ HasScanOnScavenge(object_, value_, &scan_on_scavenge); |
|
Vyacheslav Egorov (Chromium)
2011/04/16 17:50:36
I think it is uber confusing that sometimes regs.o
Erik Corry
2011/04/23 17:00:11
No they are not always the same register.
Vyacheslav Egorov (Chromium)
2011/04/24 12:16:47
If they are not the same it does not matter in thi
|
| + } else { |
| + __ jmp(&scan_on_scavenge); |
| } |
| + |
| + // There's no getting around the fact that we need to record something because |
| + // of the remembered set, and we will also record the data for the incremental |
| + // marker. Lets look at the colour of the object: If it is not black we |
| + // don't have to inform the incremental marker. |
| + __ InOldSpaceIsBlack(regs.object(), regs.scratch0(), regs.scratch1(), |
|
Vyacheslav Egorov (Chromium)
2011/04/16 17:50:36
argument per line
Erik Corry
2011/04/23 17:00:11
Done.
|
| + &object_is_black_remembered_set_needed); |
| + regs.Restore(); |
| + if (emit_remembered_set_ == EMIT_REMEMBERED_SET) { |
| + // We know the address is in old space and the value is in new space. |
| + __ RememberedSetHelper(address_, value_, save_fp_regs_mode_); |
| + } |
| __ ret(0); |
| + |
| + // Object in old space, value in new space, but we don't need to maintain the |
| + // remembered set for this page. |
| + __ bind(&scan_on_scavenge); |
| + __ InOldSpaceIsBlack(regs.object(), regs.scratch0(), regs.scratch1(), |
|
Vyacheslav Egorov (Chromium)
2011/04/16 17:50:36
argument per line
Erik Corry
2011/04/23 17:00:11
Done.
|
| + &near_object_is_black_remembered_set_not_needed); |
| + regs.Restore(); |
| + __ ret(0); |
| + |
| + // Value in new, object is black, no need to record write for remembered set. |
| + __ bind(&object_is_black_remembered_set_not_needed); |
| + __ bind(&near_object_is_black_remembered_set_not_needed); |
| + |
| + // Reload the value from the word in the object. |
| + __ mov(regs.scratch0(), Operand(regs.address(), 0)); |
| + |
| + // We need one more scratch register in this case. Use the object register. |
| + __ push(regs.object()); |
| + |
| + // Make sure the object is not white. If we can't do that, jump to the label. |
| + __ MarkBlack(regs.scratch0(), // The value. |
|
Vyacheslav Egorov (Chromium)
2011/04/16 17:50:36
MarkBlack is a confusing name for the function tha
Erik Corry
2011/04/23 17:00:11
Changed to EnsureNotWhite
|
| + regs.scratch1(), // Scratch. |
| + regs.object(), // Scratch. |
| + &pop_object_then_must_inform_incremental_marker, |
| + true); // In new space. |
| + __ pop(regs.object()); |
| + regs.Restore(); |
| + __ ret(0); |
| + |
| + __ bind(&pop_object_then_must_inform_incremental_marker); |
| + __ pop(regs.object()); |
| + |
| + // Inform the incremental marker, but don't bother with the remembered set. |
| + __ bind(&must_inform_incremental_marker); |
| + regs.SaveTheRest(); |
| + // TODO(gc) we are assuming that xmm registers are not modified by |
| + // the C function we are calling. |
| + __ PrepareCallCFunction(2, regs.scratch0()); |
| + __ mov(Operand(esp, 0 * kPointerSize), regs.object()); |
| + __ mov(regs.scratch0(), Operand(regs.address(), 0)); |
| + __ mov(Operand(esp, 1 * kPointerSize), regs.scratch0()); // Value. |
| + __ CallCFunction( |
| + ExternalReference::incremental_marking_record_write_function(), 2); |
|
Vyacheslav Egorov (Chromium)
2011/04/16 17:50:36
you can have stripped version of C function that d
Erik Corry
2011/04/23 17:00:11
TODO added for this
|
| + regs.RestoreTheRest(); |
| + regs.Restore(); |
| + __ ret(0); |
| + |
| + __ bind(&object_is_black_remembered_set_needed); |
| + |
| + __ mov(regs.scratch0(), Operand(regs.address(), 0)); |
| + __ push(regs.object()); |
| + __ MarkBlack(regs.scratch0(), // The value. |
| + regs.scratch1(), // Scratch. |
| + regs.object(), // Scratch. |
| + &must_inform_both, |
| + true); // In new space. |
| + __ pop(regs.object()); |
| + regs.Restore(); |
| + __ RememberedSetHelper(address_, value_, save_fp_regs_mode_); |
| + __ ret(0); |
| + |
| + __ bind(&must_inform_both); |
| + // Both the incremental marker and the the remembered set have to be informed. |
| + __ pop(regs.object()); |
| + regs.SaveTheRest(); |
| + // TODO(gc) we are assuming that xmm registers are not modified by |
| + // the C function we are calling. |
| + __ PrepareCallCFunction(2, regs.scratch0()); |
| + __ mov(Operand(esp, 0 * kPointerSize), regs.object()); |
| + __ mov(regs.scratch0(), Operand(regs.address(), 0)); |
| + __ mov(Operand(esp, 1 * kPointerSize), regs.scratch0()); // Value. |
| + __ CallCFunction( |
| + ExternalReference::incremental_marking_record_write_function(), 2); |
| + regs.RestoreTheRest(); |
| + regs.Restore(); |
| + __ RememberedSetHelper(address_, value_, save_fp_regs_mode_); |
| + __ ret(0); |
| + |
| + __ bind(&both_in_new_space); |
| + // Both are in new space. If we can avoid recording the incremental marking |
| + // info then we don't have to record anything at all, since the remembered set |
| + // doesn't care. Given that we are in new space and we lost the value we |
| + // will start by checking the object. If it is not black we don't need to do |
| + // anything. |
| + __ InNewSpaceIsBlack(regs.object(), |
| + regs.scratch0(), |
| + regs.scratch1(), |
| + &object_is_black_remembered_set_not_needed); |
| + regs.Restore(); |
| + __ ret(0); |
| + |
| + __ bind(&value_in_old_space); |
| + // If the value is in old space then the remembered set doesn't care. We may |
| + // be able to avoid logging anything if the incremental marker doesn't care |
| + // either. |
| + __ mov(regs.scratch0(), Operand(regs.address(), 0)); |
| + __ push(regs.object()); |
| + __ MarkBlack(regs.scratch0(), // The value. |
| + regs.scratch1(), // Scratch. |
| + regs.object(), // Scratch. |
| + &value_in_old_space_and_white, |
| + false); // In old space. |
| + __ pop(regs.object()); |
| + regs.Restore(); |
| + __ ret(0); |
| + |
| + // The value is in old space and white. We have to find out which space the |
| + // object is in in order to find its colour. |
| + __ bind(&value_in_old_space_and_white); |
| + __ pop(regs.object()); |
| + __ InNewSpace(regs.object(), |
| + regs.scratch0(), |
| + equal, |
| + &value_in_old_space_and_white_object_in_new_space); |
| + |
| + // Both in old space, value is white and can't be marked. |
| + __ InOldSpaceIsBlack(regs.object(), regs.scratch0(), regs.scratch1(), |
| + &must_inform_incremental_marker); |
| + regs.Restore(); |
| + __ ret(0); |
| + |
| + // Object in new space, value in old space and white and can't be marked. |
| + __ bind(&value_in_old_space_and_white_object_in_new_space); |
| + __ InNewSpaceIsBlack(regs.object(), regs.scratch0(), regs.scratch1(), |
| + &must_inform_incremental_marker); |
| + regs.Restore(); |
| + __ ret(0); |
| } |