| 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 void MacroAssembler::CheckPageFlag( | |
| 37 Register object, | |
| 38 Register scratch, | |
| 39 MemoryChunk::MemoryChunkFlags flag, | |
| 40 Condition cc, | |
| 41 Label* condition_met, | |
| 42 Label::Distance condition_met_near) { | |
| 43 ASSERT(cc == zero || cc == not_zero); | |
| 44 if (scratch.is(object)) { | |
| 45 and_(scratch, Immediate(~Page::kPageAlignmentMask)); | |
| 46 } else { | |
| 47 mov(scratch, Immediate(~Page::kPageAlignmentMask)); | |
| 48 and_(scratch, Operand(object)); | |
| 49 } | |
| 50 if (flag < kBitsPerByte) { | |
| 51 test_b(Operand(scratch, MemoryChunk::kFlagsOffset), | |
| 52 static_cast<uint8_t>(1u << flag)); | |
| 53 } else { | |
| 54 test(Operand(scratch, MemoryChunk::kFlagsOffset), Immediate(1 << flag)); | |
| 55 } | |
| 56 j(cc, condition_met, condition_met_near); | |
| 57 } | |
| 58 | |
| 59 | |
| 60 void MacroAssembler::IsBlack(Register object, | |
| 61 Register scratch0, | |
| 62 Register scratch1, | |
| 63 Label* is_black, | |
| 64 Label::Distance is_black_near) { | |
| 65 HasColour(object, scratch0, scratch1, | |
| 66 is_black, is_black_near, | |
| 67 1, 0); // kBlackBitPattern. | |
| 68 ASSERT(strcmp(Marking::kBlackBitPattern, "10") == 0); | |
| 69 } | |
| 70 | |
| 71 | |
| 72 void MacroAssembler::HasColour(Register object, | |
| 73 Register bitmap_scratch, | |
| 74 Register mask_scratch, | |
| 75 Label* has_colour, | |
| 76 Label::Distance has_colour_distance, | |
| 77 int first_bit, | |
| 78 int second_bit) { | |
| 79 ASSERT(!Aliasing(object, bitmap_scratch, mask_scratch, ecx)); | |
| 80 | |
| 81 MarkBits(object, bitmap_scratch, mask_scratch); | |
| 82 | |
| 83 Label other_colour, word_boundary; | |
| 84 test(mask_scratch, Operand(bitmap_scratch, MemoryChunk::kHeaderSize)); | |
| 85 j(first_bit == 1 ? zero : not_zero, &other_colour, Label::kNear); | |
| 86 add(mask_scratch, Operand(mask_scratch)); // Shift left 1 by adding. | |
| 87 j(zero, &word_boundary, Label::kNear); | |
| 88 test(mask_scratch, Operand(bitmap_scratch, MemoryChunk::kHeaderSize)); | |
| 89 j(second_bit == 1 ? not_zero : zero, has_colour, has_colour_distance); | |
| 90 jmp(&other_colour, Label::kNear); | |
| 91 | |
| 92 bind(&word_boundary); | |
| 93 test_b(Operand(bitmap_scratch, MemoryChunk::kHeaderSize + kPointerSize), 1); | |
| 94 | |
| 95 j(second_bit == 1 ? not_zero : zero, has_colour, has_colour_distance); | |
| 96 bind(&other_colour); | |
| 97 } | |
| 98 | |
| 99 | |
| 100 void MacroAssembler::IsDataObject(Register value, | |
| 101 Register scratch, | |
| 102 Label* not_data_object, | |
| 103 Label::Distance not_data_object_distance, | |
| 104 bool in_new_space) { | |
| 105 if (in_new_space) { | |
| 106 Label is_data_object; | |
| 107 mov(scratch, FieldOperand(value, HeapObject::kMapOffset)); | |
| 108 cmp(scratch, FACTORY->heap_number_map()); | |
| 109 j(equal, &is_data_object, Label::kNear); | |
| 110 ASSERT(kConsStringTag == 1 && kIsConsStringMask == 1); | |
| 111 ASSERT(kNotStringTag == 0x80 && kIsNotStringMask == 0x80); | |
| 112 // If it's a string and it's not a cons string then it's an object that | |
| 113 // doesn't need scanning. | |
| 114 test_b(FieldOperand(scratch, Map::kInstanceTypeOffset), | |
| 115 kIsConsStringMask | kIsNotStringMask); | |
| 116 // Jump if we need to mark it grey and push it. | |
| 117 j(not_zero, not_data_object, not_data_object_distance); | |
| 118 bind(&is_data_object); | |
| 119 } else { | |
| 120 mov(scratch, Operand(value)); | |
| 121 and_(scratch, ~Page::kPageAlignmentMask); | |
| 122 test_b(Operand(scratch, MemoryChunk::kFlagsOffset), | |
| 123 1 << MemoryChunk::CONTAINS_ONLY_DATA); | |
| 124 // Jump if we need to mark it grey and push it. | |
| 125 j(zero, not_data_object, not_data_object_distance); | |
| 126 } | |
| 127 } | |
| 128 | |
| 129 | |
| 130 void MacroAssembler::MarkBits(Register addr_reg, | |
| 131 Register bitmap_reg, | |
| 132 Register mask_reg) { | |
| 133 ASSERT(!Aliasing(addr_reg, bitmap_reg, mask_reg, ecx)); | |
| 134 mov(bitmap_reg, Operand(addr_reg)); | |
| 135 and_(bitmap_reg, ~Page::kPageAlignmentMask); | |
| 136 mov(ecx, Operand(addr_reg)); | |
| 137 shr(ecx, Bitmap::kBitsPerCellLog2); | |
| 138 and_(ecx, | |
| 139 (Page::kPageAlignmentMask >> Bitmap::kBitsPerCellLog2) & | |
| 140 ~(kPointerSize - 1)); | |
| 141 | |
| 142 add(bitmap_reg, Operand(ecx)); | |
| 143 mov(ecx, Operand(addr_reg)); | |
| 144 shr(ecx, kPointerSizeLog2); | |
| 145 and_(ecx, (1 << Bitmap::kBitsPerCellLog2) - 1); | |
| 146 mov(mask_reg, Immediate(1)); | |
| 147 shl_cl(mask_reg); | |
| 148 } | |
| 149 | |
| 150 | |
| 151 void MacroAssembler::EnsureNotWhite( | |
| 152 Register value, | |
| 153 Register bitmap_scratch, | |
| 154 Register mask_scratch, | |
| 155 Label* value_is_white_and_not_data, | |
| 156 Label::Distance distance, | |
| 157 bool in_new_space) { | |
| 158 ASSERT(!Aliasing(value, bitmap_scratch, mask_scratch, ecx)); | |
| 159 MarkBits(value, bitmap_scratch, mask_scratch); | |
| 160 | |
| 161 // If the value is black or grey we don't need to do anything. | |
| 162 ASSERT(strcmp(Marking::kWhiteBitPattern, "00") == 0); | |
| 163 ASSERT(strcmp(Marking::kBlackBitPattern, "10") == 0); | |
| 164 ASSERT(strcmp(Marking::kGreyBitPattern, "11") == 0); | |
| 165 ASSERT(strcmp(Marking::kImpossibleBitPattern, "01") == 0); | |
| 166 | |
| 167 Label done; | |
| 168 | |
| 169 // Since both black and grey have a 1 in the first position and white does | |
| 170 // not have a 1 there we only need to check one bit. | |
| 171 test(mask_scratch, Operand(bitmap_scratch, MemoryChunk::kHeaderSize)); | |
| 172 j(not_zero, &done, Label::kNear); | |
| 173 | |
| 174 if (FLAG_debug_code) { | |
| 175 // Check for impossible bit pattern. | |
| 176 Label ok; | |
| 177 push(mask_scratch); | |
| 178 // shl. May overflow making the check conservative. | |
| 179 add(mask_scratch, Operand(mask_scratch)); | |
| 180 test(mask_scratch, Operand(bitmap_scratch, MemoryChunk::kHeaderSize)); | |
| 181 j(zero, &ok, Label::kNear); | |
| 182 int3(); | |
| 183 bind(&ok); | |
| 184 pop(mask_scratch); | |
| 185 } | |
| 186 | |
| 187 // Value is white. We check whether it is data that doesn't need scanning. | |
| 188 IsDataObject(value, ecx, value_is_white_and_not_data, distance, in_new_space); | |
| 189 | |
| 190 // Value is a data object, and it is white. Mark it black. Since we know | |
| 191 // that the object is white we can make it black by flipping one bit. | |
| 192 or_(Operand(bitmap_scratch, MemoryChunk::kHeaderSize), mask_scratch); | |
| 193 bind(&done); | |
| 194 } | |
| 195 | |
| 196 } } // namespace v8::internal | |
| 197 | |
| 198 #endif // V8_IA32_MACRO_ASSEMBLER_IA32_INL_H_ | |
| OLD | NEW |