Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Side by Side Diff: src/x64/macro-assembler-x64.cc

Issue 2255004: Cardmarking writebarrier. (Closed)
Patch Set: Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/x64/macro-assembler-x64.h ('k') | src/x64/stub-cache-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 Register addr, 83 Register addr,
84 Register scratch) { 84 Register scratch) {
85 if (FLAG_debug_code) { 85 if (FLAG_debug_code) {
86 // Check that the object is not in new space. 86 // Check that the object is not in new space.
87 Label not_in_new_space; 87 Label not_in_new_space;
88 InNewSpace(object, scratch, not_equal, &not_in_new_space); 88 InNewSpace(object, scratch, not_equal, &not_in_new_space);
89 Abort("new-space object passed to RecordWriteHelper"); 89 Abort("new-space object passed to RecordWriteHelper");
90 bind(&not_in_new_space); 90 bind(&not_in_new_space);
91 } 91 }
92 92
93 Label fast;
94
95 // Compute the page start address from the heap object pointer, and reuse 93 // Compute the page start address from the heap object pointer, and reuse
96 // the 'object' register for it. 94 // the 'object' register for it.
97 ASSERT(is_int32(~Page::kPageAlignmentMask)); 95 and_(object, Immediate(~Page::kPageAlignmentMask));
98 and_(object,
99 Immediate(static_cast<int32_t>(~Page::kPageAlignmentMask)));
100 Register page_start = object;
101 96
102 // Compute the bit addr in the remembered set/index of the pointer in the 97 // Compute number of region covering addr. See Page::GetRegionNumberForAddress
103 // page. Reuse 'addr' as pointer_offset. 98 // method for more details.
104 subq(addr, page_start); 99 and_(addr, Immediate(Page::kPageAlignmentMask));
105 shr(addr, Immediate(kPointerSizeLog2)); 100 shrl(addr, Immediate(Page::kRegionSizeLog2));
106 Register pointer_offset = addr;
107 101
108 // If the bit offset lies beyond the normal remembered set range, it is in 102 // Set dirty mark for region.
109 // the extra remembered set area of a large object. 103 bts(Operand(object, Page::kDirtyFlagOffset), addr);
110 cmpq(pointer_offset, Immediate(Page::kPageSize / kPointerSize));
111 j(below, &fast);
112
113 // We have a large object containing pointers. It must be a FixedArray.
114
115 // Adjust 'page_start' so that addressing using 'pointer_offset' hits the
116 // extra remembered set after the large object.
117
118 // Load the array length into 'scratch'.
119 movl(scratch,
120 Operand(page_start,
121 Page::kObjectStartOffset + FixedArray::kLengthOffset));
122 Register array_length = scratch;
123
124 // Extra remembered set starts right after the large object (a FixedArray), at
125 // page_start + kObjectStartOffset + objectSize
126 // where objectSize is FixedArray::kHeaderSize + kPointerSize * array_length.
127 // Add the delta between the end of the normal RSet and the start of the
128 // extra RSet to 'page_start', so that addressing the bit using
129 // 'pointer_offset' hits the extra RSet words.
130 lea(page_start,
131 Operand(page_start, array_length, times_pointer_size,
132 Page::kObjectStartOffset + FixedArray::kHeaderSize
133 - Page::kRSetEndOffset));
134
135 // NOTE: For now, we use the bit-test-and-set (bts) x86 instruction
136 // to limit code size. We should probably evaluate this decision by
137 // measuring the performance of an equivalent implementation using
138 // "simpler" instructions
139 bind(&fast);
140 bts(Operand(page_start, Page::kRSetOffset), pointer_offset);
141 } 104 }
142 105
143 106
144 // Set the remembered set bit for [object+offset]. 107 // For page containing |object| mark region covering [object+offset] dirty.
145 // object is the object being stored into, value is the object being stored. 108 // object is the object being stored into, value is the object being stored.
146 // If offset is zero, then the smi_index register contains the array index into 109 // If offset is zero, then the smi_index register contains the array index into
147 // the elements array represented as a smi. Otherwise it can be used as a 110 // the elements array represented as a smi. Otherwise it can be used as a
148 // scratch register. 111 // scratch register.
149 // All registers are clobbered by the operation. 112 // All registers are clobbered by the operation.
150 void MacroAssembler::RecordWrite(Register object, 113 void MacroAssembler::RecordWrite(Register object,
151 int offset, 114 int offset,
152 Register value, 115 Register value,
153 Register smi_index) { 116 Register smi_index) {
154 // The compiled code assumes that record write doesn't change the 117 // The compiled code assumes that record write doesn't change the
155 // context register, so we check that none of the clobbered 118 // context register, so we check that none of the clobbered
156 // registers are rsi. 119 // registers are rsi.
157 ASSERT(!object.is(rsi) && !value.is(rsi) && !smi_index.is(rsi)); 120 ASSERT(!object.is(rsi) && !value.is(rsi) && !smi_index.is(rsi));
158 121
159 // First, check if a remembered set write is even needed. The tests below 122 // First, check if a write barrier is even needed. The tests below
160 // catch stores of Smis and stores into young gen (which does not have space 123 // catch stores of Smis and stores into young gen.
161 // for the remembered set bits).
162 Label done; 124 Label done;
163 JumpIfSmi(value, &done); 125 JumpIfSmi(value, &done);
164 126
165 RecordWriteNonSmi(object, offset, value, smi_index); 127 RecordWriteNonSmi(object, offset, value, smi_index);
166 bind(&done); 128 bind(&done);
167 129
168 // Clobber all input registers when running with the debug-code flag 130 // Clobber all input registers when running with the debug-code flag
169 // turned on to provoke errors. This clobbering repeats the 131 // turned on to provoke errors. This clobbering repeats the
170 // clobbering done inside RecordWriteNonSmi but it's necessary to 132 // clobbering done inside RecordWriteNonSmi but it's necessary to
171 // avoid having the fast case for smis leave the registers 133 // avoid having the fast case for smis leave the registers
(...skipping 12 matching lines...) Expand all
184 Register smi_index) { 146 Register smi_index) {
185 Label done; 147 Label done;
186 148
187 if (FLAG_debug_code) { 149 if (FLAG_debug_code) {
188 Label okay; 150 Label okay;
189 JumpIfNotSmi(object, &okay); 151 JumpIfNotSmi(object, &okay);
190 Abort("MacroAssembler::RecordWriteNonSmi cannot deal with smis"); 152 Abort("MacroAssembler::RecordWriteNonSmi cannot deal with smis");
191 bind(&okay); 153 bind(&okay);
192 } 154 }
193 155
194 // Test that the object address is not in the new space. We cannot 156 // Test that the object address is not in the new space. We cannot
195 // set remembered set bits in the new space. 157 // update page dirty marks for new space pages.
196 InNewSpace(object, scratch, equal, &done); 158 InNewSpace(object, scratch, equal, &done);
197 159
198 // The offset is relative to a tagged or untagged HeapObject pointer, 160 // The offset is relative to a tagged or untagged HeapObject pointer,
199 // so either offset or offset + kHeapObjectTag must be a 161 // so either offset or offset + kHeapObjectTag must be a
200 // multiple of kPointerSize. 162 // multiple of kPointerSize.
201 ASSERT(IsAligned(offset, kPointerSize) || 163 ASSERT(IsAligned(offset, kPointerSize) ||
202 IsAligned(offset + kHeapObjectTag, kPointerSize)); 164 IsAligned(offset + kHeapObjectTag, kPointerSize));
203 165
204 // We use optimized write barrier code if the word being written to is not in 166 Register dst = smi_index;
205 // a large object page, or is in the first "page" of a large object page. 167 if (offset != 0) {
206 // We make sure that an offset is inside the right limits whether it is 168 lea(dst, Operand(object, offset));
207 // tagged or untagged.
208 if ((offset > 0) && (offset < Page::kMaxHeapObjectSize - kHeapObjectTag)) {
209 // Compute the bit offset in the remembered set, leave it in 'scratch'.
210 lea(scratch, Operand(object, offset));
211 ASSERT(is_int32(Page::kPageAlignmentMask));
212 and_(scratch, Immediate(static_cast<int32_t>(Page::kPageAlignmentMask)));
213 shr(scratch, Immediate(kPointerSizeLog2));
214
215 // Compute the page address from the heap object pointer, leave it in
216 // 'object' (immediate value is sign extended).
217 and_(object, Immediate(~Page::kPageAlignmentMask));
218
219 // NOTE: For now, we use the bit-test-and-set (bts) x86 instruction
220 // to limit code size. We should probably evaluate this decision by
221 // measuring the performance of an equivalent implementation using
222 // "simpler" instructions
223 bts(Operand(object, Page::kRSetOffset), scratch);
224 } else { 169 } else {
225 Register dst = smi_index; 170 // array access: calculate the destination address in the same manner as
226 if (offset != 0) { 171 // KeyedStoreIC::GenerateGeneric.
227 lea(dst, Operand(object, offset)); 172 SmiIndex index = SmiToIndex(smi_index, smi_index, kPointerSizeLog2);
228 } else { 173 lea(dst, FieldOperand(object,
229 // array access: calculate the destination address in the same manner as 174 index.reg,
230 // KeyedStoreIC::GenerateGeneric. 175 index.scale,
231 SmiIndex index = SmiToIndex(smi_index, smi_index, kPointerSizeLog2); 176 FixedArray::kHeaderSize));
232 lea(dst, FieldOperand(object,
233 index.reg,
234 index.scale,
235 FixedArray::kHeaderSize));
236 }
237 // If we are already generating a shared stub, not inlining the
238 // record write code isn't going to save us any memory.
239 if (generating_stub()) {
240 RecordWriteHelper(object, dst, scratch);
241 } else {
242 RecordWriteStub stub(object, dst, scratch);
243 CallStub(&stub);
244 }
245 } 177 }
178 RecordWriteHelper(object, dst, scratch);
246 179
247 bind(&done); 180 bind(&done);
248 181
249 // Clobber all input registers when running with the debug-code flag 182 // Clobber all input registers when running with the debug-code flag
250 // turned on to provoke errors. 183 // turned on to provoke errors.
251 if (FLAG_debug_code) { 184 if (FLAG_debug_code) {
252 movq(object, BitCast<int64_t>(kZapValue), RelocInfo::NONE); 185 movq(object, BitCast<int64_t>(kZapValue), RelocInfo::NONE);
253 movq(scratch, BitCast<int64_t>(kZapValue), RelocInfo::NONE); 186 movq(scratch, BitCast<int64_t>(kZapValue), RelocInfo::NONE);
254 movq(smi_index, BitCast<int64_t>(kZapValue), RelocInfo::NONE); 187 movq(smi_index, BitCast<int64_t>(kZapValue), RelocInfo::NONE);
255 } 188 }
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 movq(dst, src); 569 movq(dst, src);
637 } 570 }
638 if (power < kSmiShift) { 571 if (power < kSmiShift) {
639 sar(dst, Immediate(kSmiShift - power)); 572 sar(dst, Immediate(kSmiShift - power));
640 } else if (power > kSmiShift) { 573 } else if (power > kSmiShift) {
641 shl(dst, Immediate(power - kSmiShift)); 574 shl(dst, Immediate(power - kSmiShift));
642 } 575 }
643 } 576 }
644 577
645 578
579 void MacroAssembler::PositiveSmiDivPowerOfTwoToInteger32(Register dst,
580 Register src,
581 int power) {
582 ASSERT((0 <= power) && (power < 32));
583 if (dst.is(src)) {
584 shr(dst, Immediate(power + kSmiShift));
585 } else {
586 UNIMPLEMENTED(); // Not used.
587 }
588 }
589
590
646 Condition MacroAssembler::CheckSmi(Register src) { 591 Condition MacroAssembler::CheckSmi(Register src) {
647 ASSERT_EQ(0, kSmiTag); 592 ASSERT_EQ(0, kSmiTag);
648 testb(src, Immediate(kSmiTagMask)); 593 testb(src, Immediate(kSmiTagMask));
649 return zero; 594 return zero;
650 } 595 }
651 596
652 597
653 Condition MacroAssembler::CheckPositiveSmi(Register src) { 598 Condition MacroAssembler::CheckPositiveSmi(Register src) {
654 ASSERT_EQ(0, kSmiTag); 599 ASSERT_EQ(0, kSmiTag);
655 movq(kScratchRegister, src); 600 movq(kScratchRegister, src);
(...skipping 1936 matching lines...) Expand 10 before | Expand all | Expand 10 after
2592 scratch2, 2537 scratch2,
2593 scratch3, 2538 scratch3,
2594 gc_required, 2539 gc_required,
2595 TAG_OBJECT); 2540 TAG_OBJECT);
2596 2541
2597 // Set the map, length and hash field. 2542 // Set the map, length and hash field.
2598 LoadRoot(kScratchRegister, Heap::kStringMapRootIndex); 2543 LoadRoot(kScratchRegister, Heap::kStringMapRootIndex);
2599 movq(FieldOperand(result, HeapObject::kMapOffset), kScratchRegister); 2544 movq(FieldOperand(result, HeapObject::kMapOffset), kScratchRegister);
2600 Integer32ToSmi(scratch1, length); 2545 Integer32ToSmi(scratch1, length);
2601 movq(FieldOperand(result, String::kLengthOffset), scratch1); 2546 movq(FieldOperand(result, String::kLengthOffset), scratch1);
2602 movl(FieldOperand(result, String::kHashFieldOffset), 2547 movq(FieldOperand(result, String::kHashFieldOffset),
2603 Immediate(String::kEmptyHashField)); 2548 Immediate(String::kEmptyHashField));
2604 } 2549 }
2605 2550
2606 2551
2607 void MacroAssembler::AllocateAsciiString(Register result, 2552 void MacroAssembler::AllocateAsciiString(Register result,
2608 Register length, 2553 Register length,
2609 Register scratch1, 2554 Register scratch1,
2610 Register scratch2, 2555 Register scratch2,
2611 Register scratch3, 2556 Register scratch3,
2612 Label* gc_required) { 2557 Label* gc_required) {
(...skipping 17 matching lines...) Expand all
2630 scratch2, 2575 scratch2,
2631 scratch3, 2576 scratch3,
2632 gc_required, 2577 gc_required,
2633 TAG_OBJECT); 2578 TAG_OBJECT);
2634 2579
2635 // Set the map, length and hash field. 2580 // Set the map, length and hash field.
2636 LoadRoot(kScratchRegister, Heap::kAsciiStringMapRootIndex); 2581 LoadRoot(kScratchRegister, Heap::kAsciiStringMapRootIndex);
2637 movq(FieldOperand(result, HeapObject::kMapOffset), kScratchRegister); 2582 movq(FieldOperand(result, HeapObject::kMapOffset), kScratchRegister);
2638 Integer32ToSmi(scratch1, length); 2583 Integer32ToSmi(scratch1, length);
2639 movq(FieldOperand(result, String::kLengthOffset), scratch1); 2584 movq(FieldOperand(result, String::kLengthOffset), scratch1);
2640 movl(FieldOperand(result, String::kHashFieldOffset), 2585 movq(FieldOperand(result, String::kHashFieldOffset),
2641 Immediate(String::kEmptyHashField)); 2586 Immediate(String::kEmptyHashField));
2642 } 2587 }
2643 2588
2644 2589
2645 void MacroAssembler::AllocateConsString(Register result, 2590 void MacroAssembler::AllocateConsString(Register result,
2646 Register scratch1, 2591 Register scratch1,
2647 Register scratch2, 2592 Register scratch2,
2648 Label* gc_required) { 2593 Label* gc_required) {
2649 // Allocate heap number in new space. 2594 // Allocate heap number in new space.
2650 AllocateInNewSpace(ConsString::kSize, 2595 AllocateInNewSpace(ConsString::kSize,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
2761 CPU::FlushICache(address_, size_); 2706 CPU::FlushICache(address_, size_);
2762 2707
2763 // Check that the code was patched as expected. 2708 // Check that the code was patched as expected.
2764 ASSERT(masm_.pc_ == address_ + size_); 2709 ASSERT(masm_.pc_ == address_ + size_);
2765 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); 2710 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap);
2766 } 2711 }
2767 2712
2768 } } // namespace v8::internal 2713 } } // namespace v8::internal
2769 2714
2770 #endif // V8_TARGET_ARCH_X64 2715 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/x64/macro-assembler-x64.h ('k') | src/x64/stub-cache-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698