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