| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #if V8_TARGET_ARCH_X64 | 5 #if V8_TARGET_ARCH_X64 |
| 6 | 6 |
| 7 #include "src/base/bits.h" | 7 #include "src/base/bits.h" |
| 8 #include "src/base/division-by-constant.h" | 8 #include "src/base/division-by-constant.h" |
| 9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
| 10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
| (...skipping 5281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5292 // Make rcx into a mask that covers both marking bits using the operation | 5292 // Make rcx into a mask that covers both marking bits using the operation |
| 5293 // rcx = mask | (mask << 1). | 5293 // rcx = mask | (mask << 1). |
| 5294 leap(rcx, Operand(mask_scratch, mask_scratch, times_2, 0)); | 5294 leap(rcx, Operand(mask_scratch, mask_scratch, times_2, 0)); |
| 5295 // Note that we are using a 4-byte aligned 8-byte load. | 5295 // Note that we are using a 4-byte aligned 8-byte load. |
| 5296 andp(rcx, Operand(bitmap_scratch, MemoryChunk::kHeaderSize)); | 5296 andp(rcx, Operand(bitmap_scratch, MemoryChunk::kHeaderSize)); |
| 5297 cmpp(mask_scratch, rcx); | 5297 cmpp(mask_scratch, rcx); |
| 5298 j(equal, on_black, on_black_distance); | 5298 j(equal, on_black, on_black_distance); |
| 5299 } | 5299 } |
| 5300 | 5300 |
| 5301 | 5301 |
| 5302 // Detect some, but not all, common pointer-free objects. This is used by the | |
| 5303 // incremental write barrier which doesn't care about oddballs (they are always | |
| 5304 // marked black immediately so this code is not hit). | |
| 5305 void MacroAssembler::JumpIfDataObject( | |
| 5306 Register value, | |
| 5307 Register scratch, | |
| 5308 Label* not_data_object, | |
| 5309 Label::Distance not_data_object_distance) { | |
| 5310 Label is_data_object; | |
| 5311 movp(scratch, FieldOperand(value, HeapObject::kMapOffset)); | |
| 5312 CompareRoot(scratch, Heap::kHeapNumberMapRootIndex); | |
| 5313 j(equal, &is_data_object, Label::kNear); | |
| 5314 DCHECK(kIsIndirectStringTag == 1 && kIsIndirectStringMask == 1); | |
| 5315 DCHECK(kNotStringTag == 0x80 && kIsNotStringMask == 0x80); | |
| 5316 // If it's a string and it's not a cons string then it's an object containing | |
| 5317 // no GC pointers. | |
| 5318 testb(FieldOperand(scratch, Map::kInstanceTypeOffset), | |
| 5319 Immediate(kIsIndirectStringMask | kIsNotStringMask)); | |
| 5320 j(not_zero, not_data_object, not_data_object_distance); | |
| 5321 bind(&is_data_object); | |
| 5322 } | |
| 5323 | |
| 5324 | |
| 5325 void MacroAssembler::GetMarkBits(Register addr_reg, | 5302 void MacroAssembler::GetMarkBits(Register addr_reg, |
| 5326 Register bitmap_reg, | 5303 Register bitmap_reg, |
| 5327 Register mask_reg) { | 5304 Register mask_reg) { |
| 5328 DCHECK(!AreAliased(addr_reg, bitmap_reg, mask_reg, rcx)); | 5305 DCHECK(!AreAliased(addr_reg, bitmap_reg, mask_reg, rcx)); |
| 5329 movp(bitmap_reg, addr_reg); | 5306 movp(bitmap_reg, addr_reg); |
| 5330 // Sign extended 32 bit immediate. | 5307 // Sign extended 32 bit immediate. |
| 5331 andp(bitmap_reg, Immediate(~Page::kPageAlignmentMask)); | 5308 andp(bitmap_reg, Immediate(~Page::kPageAlignmentMask)); |
| 5332 movp(rcx, addr_reg); | 5309 movp(rcx, addr_reg); |
| 5333 int shift = | 5310 int shift = |
| 5334 Bitmap::kBitsPerCellLog2 + kPointerSizeLog2 - Bitmap::kBytesPerCellLog2; | 5311 Bitmap::kBitsPerCellLog2 + kPointerSizeLog2 - Bitmap::kBytesPerCellLog2; |
| 5335 shrl(rcx, Immediate(shift)); | 5312 shrl(rcx, Immediate(shift)); |
| 5336 andp(rcx, | 5313 andp(rcx, |
| 5337 Immediate((Page::kPageAlignmentMask >> shift) & | 5314 Immediate((Page::kPageAlignmentMask >> shift) & |
| 5338 ~(Bitmap::kBytesPerCell - 1))); | 5315 ~(Bitmap::kBytesPerCell - 1))); |
| 5339 | 5316 |
| 5340 addp(bitmap_reg, rcx); | 5317 addp(bitmap_reg, rcx); |
| 5341 movp(rcx, addr_reg); | 5318 movp(rcx, addr_reg); |
| 5342 shrl(rcx, Immediate(kPointerSizeLog2)); | 5319 shrl(rcx, Immediate(kPointerSizeLog2)); |
| 5343 andp(rcx, Immediate((1 << Bitmap::kBitsPerCellLog2) - 1)); | 5320 andp(rcx, Immediate((1 << Bitmap::kBitsPerCellLog2) - 1)); |
| 5344 movl(mask_reg, Immediate(1)); | 5321 movl(mask_reg, Immediate(1)); |
| 5345 shlp_cl(mask_reg); | 5322 shlp_cl(mask_reg); |
| 5346 } | 5323 } |
| 5347 | 5324 |
| 5348 | 5325 |
| 5349 void MacroAssembler::EnsureNotWhite( | 5326 void MacroAssembler::JumpIfWhite(Register value, Register bitmap_scratch, |
| 5350 Register value, | 5327 Register mask_scratch, Label* value_is_white, |
| 5351 Register bitmap_scratch, | 5328 Label::Distance distance) { |
| 5352 Register mask_scratch, | |
| 5353 Label* value_is_white_and_not_data, | |
| 5354 Label::Distance distance) { | |
| 5355 DCHECK(!AreAliased(value, bitmap_scratch, mask_scratch, rcx)); | 5329 DCHECK(!AreAliased(value, bitmap_scratch, mask_scratch, rcx)); |
| 5356 GetMarkBits(value, bitmap_scratch, mask_scratch); | 5330 GetMarkBits(value, bitmap_scratch, mask_scratch); |
| 5357 | 5331 |
| 5358 // If the value is black or grey we don't need to do anything. | 5332 // If the value is black or grey we don't need to do anything. |
| 5359 DCHECK(strcmp(Marking::kWhiteBitPattern, "00") == 0); | 5333 DCHECK(strcmp(Marking::kWhiteBitPattern, "00") == 0); |
| 5360 DCHECK(strcmp(Marking::kBlackBitPattern, "10") == 0); | 5334 DCHECK(strcmp(Marking::kBlackBitPattern, "10") == 0); |
| 5361 DCHECK(strcmp(Marking::kGreyBitPattern, "11") == 0); | 5335 DCHECK(strcmp(Marking::kGreyBitPattern, "11") == 0); |
| 5362 DCHECK(strcmp(Marking::kImpossibleBitPattern, "01") == 0); | 5336 DCHECK(strcmp(Marking::kImpossibleBitPattern, "01") == 0); |
| 5363 | 5337 |
| 5364 Label done; | |
| 5365 | |
| 5366 // Since both black and grey have a 1 in the first position and white does | 5338 // Since both black and grey have a 1 in the first position and white does |
| 5367 // not have a 1 there we only need to check one bit. | 5339 // not have a 1 there we only need to check one bit. |
| 5368 testp(Operand(bitmap_scratch, MemoryChunk::kHeaderSize), mask_scratch); | 5340 testp(Operand(bitmap_scratch, MemoryChunk::kHeaderSize), mask_scratch); |
| 5369 j(not_zero, &done, Label::kNear); | 5341 j(zero, value_is_white, distance); |
| 5370 | |
| 5371 if (emit_debug_code()) { | |
| 5372 // Check for impossible bit pattern. | |
| 5373 Label ok; | |
| 5374 Push(mask_scratch); | |
| 5375 // shl. May overflow making the check conservative. | |
| 5376 addp(mask_scratch, mask_scratch); | |
| 5377 testp(Operand(bitmap_scratch, MemoryChunk::kHeaderSize), mask_scratch); | |
| 5378 j(zero, &ok, Label::kNear); | |
| 5379 int3(); | |
| 5380 bind(&ok); | |
| 5381 Pop(mask_scratch); | |
| 5382 } | |
| 5383 | |
| 5384 // Value is white. We check whether it is data that doesn't need scanning. | |
| 5385 // Currently only checks for HeapNumber and non-cons strings. | |
| 5386 Register map = rcx; // Holds map while checking type. | |
| 5387 Register length = rcx; // Holds length of object after checking type. | |
| 5388 Label not_heap_number; | |
| 5389 Label is_data_object; | |
| 5390 | |
| 5391 // Check for heap-number | |
| 5392 movp(map, FieldOperand(value, HeapObject::kMapOffset)); | |
| 5393 CompareRoot(map, Heap::kHeapNumberMapRootIndex); | |
| 5394 j(not_equal, ¬_heap_number, Label::kNear); | |
| 5395 movp(length, Immediate(HeapNumber::kSize)); | |
| 5396 jmp(&is_data_object, Label::kNear); | |
| 5397 | |
| 5398 bind(¬_heap_number); | |
| 5399 // Check for strings. | |
| 5400 DCHECK(kIsIndirectStringTag == 1 && kIsIndirectStringMask == 1); | |
| 5401 DCHECK(kNotStringTag == 0x80 && kIsNotStringMask == 0x80); | |
| 5402 // If it's a string and it's not a cons string then it's an object containing | |
| 5403 // no GC pointers. | |
| 5404 Register instance_type = rcx; | |
| 5405 movzxbl(instance_type, FieldOperand(map, Map::kInstanceTypeOffset)); | |
| 5406 testb(instance_type, Immediate(kIsIndirectStringMask | kIsNotStringMask)); | |
| 5407 j(not_zero, value_is_white_and_not_data); | |
| 5408 // It's a non-indirect (non-cons and non-slice) string. | |
| 5409 // If it's external, the length is just ExternalString::kSize. | |
| 5410 // Otherwise it's String::kHeaderSize + string->length() * (1 or 2). | |
| 5411 Label not_external; | |
| 5412 // External strings are the only ones with the kExternalStringTag bit | |
| 5413 // set. | |
| 5414 DCHECK_EQ(0, kSeqStringTag & kExternalStringTag); | |
| 5415 DCHECK_EQ(0, kConsStringTag & kExternalStringTag); | |
| 5416 testb(instance_type, Immediate(kExternalStringTag)); | |
| 5417 j(zero, ¬_external, Label::kNear); | |
| 5418 movp(length, Immediate(ExternalString::kSize)); | |
| 5419 jmp(&is_data_object, Label::kNear); | |
| 5420 | |
| 5421 bind(¬_external); | |
| 5422 // Sequential string, either Latin1 or UC16. | |
| 5423 DCHECK(kOneByteStringTag == 0x04); | |
| 5424 andp(length, Immediate(kStringEncodingMask)); | |
| 5425 xorp(length, Immediate(kStringEncodingMask)); | |
| 5426 addp(length, Immediate(0x04)); | |
| 5427 // Value now either 4 (if Latin1) or 8 (if UC16), i.e. char-size shifted by 2. | |
| 5428 imulp(length, FieldOperand(value, String::kLengthOffset)); | |
| 5429 shrp(length, Immediate(2 + kSmiTagSize + kSmiShiftSize)); | |
| 5430 addp(length, Immediate(SeqString::kHeaderSize + kObjectAlignmentMask)); | |
| 5431 andp(length, Immediate(~kObjectAlignmentMask)); | |
| 5432 | |
| 5433 bind(&is_data_object); | |
| 5434 // Value is a data object, and it is white. Mark it black. Since we know | |
| 5435 // that the object is white we can make it black by flipping one bit. | |
| 5436 orp(Operand(bitmap_scratch, MemoryChunk::kHeaderSize), mask_scratch); | |
| 5437 | |
| 5438 andp(bitmap_scratch, Immediate(~Page::kPageAlignmentMask)); | |
| 5439 addl(Operand(bitmap_scratch, MemoryChunk::kLiveBytesOffset), length); | |
| 5440 | |
| 5441 bind(&done); | |
| 5442 } | 5342 } |
| 5443 | 5343 |
| 5444 | 5344 |
| 5445 void MacroAssembler::CheckEnumCache(Register null_value, Label* call_runtime) { | 5345 void MacroAssembler::CheckEnumCache(Register null_value, Label* call_runtime) { |
| 5446 Label next, start; | 5346 Label next, start; |
| 5447 Register empty_fixed_array_value = r8; | 5347 Register empty_fixed_array_value = r8; |
| 5448 LoadRoot(empty_fixed_array_value, Heap::kEmptyFixedArrayRootIndex); | 5348 LoadRoot(empty_fixed_array_value, Heap::kEmptyFixedArrayRootIndex); |
| 5449 movp(rcx, rax); | 5349 movp(rcx, rax); |
| 5450 | 5350 |
| 5451 // Check if the enum length field is properly initialized, indicating that | 5351 // Check if the enum length field is properly initialized, indicating that |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5557 movl(rax, dividend); | 5457 movl(rax, dividend); |
| 5558 shrl(rax, Immediate(31)); | 5458 shrl(rax, Immediate(31)); |
| 5559 addl(rdx, rax); | 5459 addl(rdx, rax); |
| 5560 } | 5460 } |
| 5561 | 5461 |
| 5562 | 5462 |
| 5563 } // namespace internal | 5463 } // namespace internal |
| 5564 } // namespace v8 | 5464 } // namespace v8 |
| 5565 | 5465 |
| 5566 #endif // V8_TARGET_ARCH_X64 | 5466 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |