Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | |
| 2 // Redistribution and use in source and binary forms, with or without | |
| 3 // modification, are permitted provided that the following conditions are | |
| 4 // met: | |
| 5 // | |
| 6 // * Redistributions of source code must retain the above copyright | |
| 7 // notice, this list of conditions and the following disclaimer. | |
| 8 // * Redistributions in binary form must reproduce the above | |
| 9 // copyright notice, this list of conditions and the following | |
| 10 // disclaimer in the documentation and/or other materials provided | |
| 11 // with the distribution. | |
| 12 // * Neither the name of Google Inc. nor the names of its | |
| 13 // contributors may be used to endorse or promote products derived | |
| 14 // from this software without specific prior written permission. | |
| 15 // | |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 27 | |
| 28 #ifndef V8_IA32_MACRO_ASSEMBLER_IA32_INL_H_ | |
| 29 #define V8_IA32_MACRO_ASSEMBLER_IA32_INL_H_ | |
| 30 | |
| 31 #include "macro-assembler.h" | |
| 32 | |
| 33 namespace v8 { | |
| 34 namespace internal { | |
| 35 | |
| 36 template<typename LabelType> | |
| 37 void MacroAssembler::HasScanOnScavenge(Register object, | |
| 38 Register scratch, | |
| 39 LabelType* scan_on_scavenge) { | |
| 40 Move(scratch, object); | |
| 41 and_(scratch, ~Page::kPageAlignmentMask); | |
| 42 cmpb(Operand(scratch, MemoryChunk::kScanOnScavengeOffset), 0); | |
| 43 j(not_equal, scan_on_scavenge); | |
| 44 } | |
| 45 | |
| 46 | |
| 47 template<typename LabelType> | |
| 48 void MacroAssembler::InOldSpaceIsBlack(Register object, | |
| 49 Register scratch0, | |
| 50 Register scratch1, | |
| 51 LabelType* is_black) { | |
| 52 HasColour(object, scratch0, scratch1, | |
| 53 is_black, | |
| 54 Page::kPageAlignmentMask, | |
| 55 MemoryChunk::kHeaderSize, | |
| 56 1, 0, // kBlackBitPattern. | |
| 57 false); // In old space. | |
| 58 ASSERT(strcmp(IncrementalMarking::kBlackBitPattern, "10") == 0); | |
| 59 } | |
| 60 | |
| 61 | |
| 62 template<typename LabelType> | |
| 63 void MacroAssembler::InNewSpaceIsBlack(Register object, | |
| 64 Register scratch0, | |
| 65 Register scratch1, | |
| 66 LabelType* is_black) { | |
| 67 HasColour(object, scratch0, scratch1, | |
| 68 is_black, | |
| 69 ~Heap::new_space()->mask(), | |
| 70 0, | |
| 71 1, 0, // kBlackBitPattern. | |
| 72 true); // In new space. | |
| 73 ASSERT(strcmp(IncrementalMarking::kBlackBitPattern, "10") == 0); | |
| 74 } | |
| 75 | |
| 76 | |
| 77 static inline bool Aliasing(Register r1, | |
| 78 Register r2, | |
| 79 Register r3, | |
| 80 Register r4) { | |
| 81 if (r1.is(r2)) return true; | |
| 82 if (r1.is(r3)) return true; | |
| 83 if (r1.is(r4)) return true; | |
| 84 if (r2.is(r3)) return true; | |
| 85 if (r2.is(r4)) return true; | |
| 86 if (r3.is(r4)) return true; | |
| 87 return false; | |
| 88 } | |
| 89 | |
| 90 | |
| 91 template<typename LabelType> | |
| 92 void MacroAssembler::HasColour(Register object, | |
| 93 Register bitmap_scratch, | |
| 94 Register mask_scratch, | |
| 95 LabelType* has_colour, | |
| 96 uint32_t mask, | |
| 97 int header_size, | |
| 98 int first_bit, | |
| 99 int second_bit, | |
| 100 bool in_new_space) { | |
| 101 ASSERT(!Aliasing(object, bitmap_scratch, mask_scratch, ecx)); | |
| 102 int32_t high_mask = ~mask; | |
| 103 | |
| 104 if (in_new_space) { | |
| 105 mov(bitmap_scratch, Immediate(ExternalReference::new_space_mark_bits())); | |
| 106 } else { | |
| 107 mov(bitmap_scratch, Operand(object)); | |
| 108 and_(bitmap_scratch, high_mask); | |
| 109 } | |
| 110 static const int kBitsPerCellLog2 = | |
| 111 Bitmap<MemoryChunk::BitmapStorageDescriptor>::kBitsPerCellLog2; | |
| 112 mov(ecx, Operand(object)); | |
| 113 shr(ecx, kBitsPerCellLog2); | |
| 114 and_(ecx, ~((high_mask >> kBitsPerCellLog2) | (kPointerSize - 1))); | |
| 115 add(bitmap_scratch, Operand(ecx)); | |
| 116 mov(ecx, Operand(object)); | |
| 117 shr(ecx, kPointerSizeLog2); | |
| 118 and_(ecx, (1 << kBitsPerCellLog2) - 1); | |
| 119 mov(mask_scratch, Immediate(1)); | |
| 120 shl_cl(mask_scratch); | |
|
Vyacheslav Egorov (Chromium)
2011/04/16 17:50:36
What about using bt based code for this operations
Erik Corry
2011/04/23 17:00:11
I don't think it's a win.
Vyacheslav Egorov (Chromium)
2011/04/24 12:16:47
I did performance measurements. I should some irre
| |
| 121 NearLabel other_colour, word_boundary; | |
| 122 test(mask_scratch, Operand(bitmap_scratch, header_size)); | |
| 123 j(first_bit == 1 ? zero : not_zero, &other_colour); | |
| 124 add(mask_scratch, Operand(mask_scratch)); // Shift left 1 by adding. | |
| 125 j(zero, &word_boundary); | |
|
Vyacheslav Egorov (Chromium)
2011/04/16 17:50:36
shl(mask_scratch, 1);
j(carry, &word_boundary);
?
Erik Corry
2011/04/23 17:00:11
At least on the p4, add is faster than shift, so t
Vyacheslav Egorov (Chromium)
2011/04/24 12:16:47
Ok
| |
| 126 test(mask_scratch, Operand(bitmap_scratch, header_size)); | |
| 127 j(second_bit == 1 ? not_zero : zero, has_colour); | |
| 128 jmp(&other_colour); | |
| 129 | |
| 130 bind(&word_boundary); | |
| 131 test_b(Operand(bitmap_scratch, header_size + kPointerSize), 1); | |
| 132 | |
| 133 j(second_bit == 1 ? not_zero : zero, has_colour); | |
| 134 bind(&other_colour); | |
| 135 } | |
| 136 | |
| 137 | |
| 138 template<typename LabelType> | |
| 139 void MacroAssembler::IsDataObject(Register value, | |
| 140 Register scratch, | |
| 141 LabelType* not_data_object, | |
| 142 bool in_new_space) { | |
| 143 if (in_new_space) { | |
| 144 NearLabel is_data_object; | |
| 145 mov(scratch, FieldOperand(value, HeapObject::kMapOffset)); | |
| 146 cmp(scratch, Factory::heap_number_map()); | |
| 147 j(equal, &is_data_object); | |
| 148 ASSERT(kConsStringTag == 1 && kIsConsStringMask == 1); | |
| 149 ASSERT(kNotStringTag == 0x80 && kIsNotStringMask == 0x80); | |
| 150 // If it's a string and it's not a cons string then it's an object that | |
| 151 // doesn't need scanning. | |
| 152 test_b(FieldOperand(scratch, Map::kInstanceTypeOffset), | |
| 153 kIsConsStringMask | kIsNotStringMask); | |
| 154 // Jump if we need to mark it grey and push it. | |
| 155 j(not_zero, not_data_object); | |
| 156 bind(&is_data_object); | |
| 157 } else { | |
| 158 mov(scratch, Operand(value)); | |
| 159 and_(scratch, ~Page::kPageAlignmentMask); | |
| 160 test_b(Operand(scratch, MemoryChunk::kFlagsOffset), | |
| 161 1 << MemoryChunk::CONTAINS_ONLY_DATA); | |
| 162 // Jump if we need to mark it grey and push it. | |
| 163 j(zero, not_data_object); | |
| 164 } | |
| 165 } | |
| 166 | |
| 167 | |
| 168 template<typename LabelType> | |
| 169 void MacroAssembler::MarkBlack( | |
| 170 Register value, | |
| 171 Register bitmap_scratch, | |
| 172 Register mask_scratch, | |
| 173 LabelType* value_is_white_and_not_data, | |
| 174 bool in_new_space) { | |
| 175 ASSERT(!Aliasing(value, bitmap_scratch, mask_scratch, ecx)); | |
| 176 int32_t high_mask = in_new_space ? | |
| 177 Heap::new_space()->mask() : | |
| 178 ~Page::kPageAlignmentMask; | |
| 179 int header_size = in_new_space ? 0 : MemoryChunk::kHeaderSize; | |
| 180 if (in_new_space) { | |
| 181 mov(bitmap_scratch, Immediate(ExternalReference::new_space_mark_bits())); | |
| 182 } else { | |
| 183 mov(bitmap_scratch, Operand(value)); | |
| 184 and_(bitmap_scratch, high_mask); | |
| 185 } | |
| 186 mov(ecx, Operand(value)); | |
| 187 static const int kBitsPerCellLog2 = | |
| 188 Bitmap<MemoryChunk::BitmapStorageDescriptor>::kBitsPerCellLog2; | |
| 189 shr(ecx, kBitsPerCellLog2); | |
| 190 and_(ecx, ~((high_mask >> kBitsPerCellLog2) | (kPointerSize - 1))); | |
| 191 | |
| 192 add(bitmap_scratch, Operand(ecx)); | |
| 193 mov(ecx, Operand(value)); | |
| 194 shr(ecx, kPointerSizeLog2); | |
| 195 and_(ecx, (1 << kBitsPerCellLog2) - 1); | |
| 196 mov(mask_scratch, Immediate(1)); | |
| 197 shl_cl(mask_scratch); | |
|
Vyacheslav Egorov (Chromium)
2011/04/16 17:50:36
code for cell address and mask computation can be
Erik Corry
2011/04/23 17:00:11
Done.
| |
| 198 | |
| 199 // If the value is black or grey we don't need to do anything. | |
| 200 ASSERT(strcmp(IncrementalMarking::kWhiteBitPattern, "00") == 0); | |
| 201 ASSERT(strcmp(IncrementalMarking::kBlackBitPattern, "10") == 0); | |
| 202 ASSERT(strcmp(IncrementalMarking::kGreyBitPattern, "11") == 0); | |
| 203 ASSERT(strcmp(IncrementalMarking::kImpossibleBitPattern, "01") == 0); | |
| 204 | |
| 205 NearLabel done; | |
| 206 | |
| 207 // Since both black and grey have a 1 in the first position and white does | |
| 208 // not have a 1 there we only need to check one bit. | |
| 209 test(mask_scratch, Operand(bitmap_scratch, header_size)); | |
| 210 j(not_zero, &done); | |
| 211 | |
| 212 if (FLAG_debug_code) { | |
| 213 // Check for impossible bit pattern. | |
| 214 NearLabel ok; | |
| 215 push(mask_scratch); | |
| 216 // shl. May overflow making the check conservative. | |
| 217 add(mask_scratch, Operand(mask_scratch)); | |
| 218 test(mask_scratch, Operand(bitmap_scratch, header_size)); | |
| 219 j(zero, &ok); | |
| 220 int3(); | |
| 221 bind(&ok); | |
| 222 pop(mask_scratch); | |
| 223 } | |
| 224 | |
| 225 // Value is white. We check whether it is data that doesn't need scanning. | |
| 226 IsDataObject(value, ecx, value_is_white_and_not_data, in_new_space); | |
| 227 | |
| 228 // Value is a data object, and it is white. Mark it black. Since we know | |
| 229 // that the object is white we can make it black by flipping one bit. | |
| 230 or_(Operand(bitmap_scratch, header_size), mask_scratch); | |
| 231 bind(&done); | |
| 232 } | |
| 233 | |
| 234 | |
| 235 | |
| 236 } } // namespace v8::internal | |
| 237 | |
| 238 #endif // V8_IA32_MACRO_ASSEMBLER_IA32_INL_H_ | |
| OLD | NEW |