From 6a628573883d0e9f22e397379f112cd7c68856a7 Mon Sep 17 00:00:00 2001 From: ulan Date: Thu, 31 Mar 2016 10:17:26 -0700 Subject: [PATCH] Change store buffer overflow check to not rely on the store buffer being (2*Size) aligned. This reduces the reserved virtual memory size needed for the store buffer. BUG=chromium:578883 LOG=NO Review URL: https://codereview.chromium.org/1851473002 Cr-Commit-Position: refs/heads/master@{#35174} --- src/arm/macro-assembler-arm.cc | 6 +++--- src/arm64/macro-assembler-arm64.cc | 7 +++---- src/heap/store-buffer.cc | 9 +++------ src/heap/store-buffer.h | 5 ++--- src/ia32/macro-assembler-ia32.cc | 6 +++--- src/mips/macro-assembler-mips.cc | 6 +++--- src/mips64/macro-assembler-mips64.cc | 6 +++--- src/ppc/macro-assembler-ppc.cc | 6 +++--- src/s390/macro-assembler-s390.cc | 6 +++--- src/x64/macro-assembler-x64.cc | 6 +++--- src/x87/macro-assembler-x87.cc | 6 +++--- 11 files changed, 32 insertions(+), 37 deletions(-) diff --git a/src/arm/macro-assembler-arm.cc b/src/arm/macro-assembler-arm.cc index 3d7dba314a..6af3d6c20c 100644 --- a/src/arm/macro-assembler-arm.cc +++ b/src/arm/macro-assembler-arm.cc @@ -738,12 +738,12 @@ void MacroAssembler::RememberedSetHelper(Register object, // For debug tests. str(scratch, MemOperand(ip)); // Call stub on end of buffer. // Check for end of buffer. - tst(scratch, Operand(StoreBuffer::kStoreBufferOverflowBit)); + tst(scratch, Operand(StoreBuffer::kStoreBufferMask)); if (and_then == kFallThroughAtEnd) { - b(eq, &done); + b(ne, &done); } else { DCHECK(and_then == kReturnAtEnd); - Ret(eq); + Ret(ne); } push(lr); StoreBufferOverflowStub store_buffer_overflow(isolate(), fp_mode); diff --git a/src/arm64/macro-assembler-arm64.cc b/src/arm64/macro-assembler-arm64.cc index ee54590414..12ddd8145e 100644 --- a/src/arm64/macro-assembler-arm64.cc +++ b/src/arm64/macro-assembler-arm64.cc @@ -4032,13 +4032,12 @@ void MacroAssembler::RememberedSetHelper(Register object, // For debug tests. Str(scratch1, MemOperand(scratch2)); // Call stub on end of buffer. // Check for end of buffer. - DCHECK(StoreBuffer::kStoreBufferOverflowBit == - (1 << (14 + kPointerSizeLog2))); + Tst(scratch1, StoreBuffer::kStoreBufferMask); if (and_then == kFallThroughAtEnd) { - Tbz(scratch1, (14 + kPointerSizeLog2), &done); + B(ne, &done); } else { DCHECK(and_then == kReturnAtEnd); - Tbnz(scratch1, (14 + kPointerSizeLog2), &store_buffer_overflow); + B(eq, &store_buffer_overflow); Ret(); } diff --git a/src/heap/store-buffer.cc b/src/heap/store-buffer.cc index bd8ab1a1fb..a982eb3c40 100644 --- a/src/heap/store-buffer.cc +++ b/src/heap/store-buffer.cc @@ -26,11 +26,10 @@ void StoreBuffer::SetUp() { // Allocate 3x the buffer size, so that we can start the new store buffer // aligned to 2x the size. This lets us use a bit test to detect the end of // the area. - virtual_memory_ = new base::VirtualMemory(kStoreBufferSize * 3); + virtual_memory_ = new base::VirtualMemory(kStoreBufferSize * 2); uintptr_t start_as_int = reinterpret_cast(virtual_memory_->address()); - start_ = - reinterpret_cast(RoundUp(start_as_int, kStoreBufferSize * 2)); + start_ = reinterpret_cast(RoundUp(start_as_int, kStoreBufferSize)); limit_ = start_ + (kStoreBufferSize / kPointerSize); DCHECK(reinterpret_cast
(start_) >= virtual_memory_->address()); @@ -41,9 +40,7 @@ void StoreBuffer::SetUp() { DCHECK(start_ <= vm_limit); DCHECK(limit_ <= vm_limit); USE(vm_limit); - DCHECK((reinterpret_cast(limit_) & kStoreBufferOverflowBit) != 0); - DCHECK((reinterpret_cast(limit_ - 1) & kStoreBufferOverflowBit) == - 0); + DCHECK((reinterpret_cast(limit_) & kStoreBufferMask) == 0); if (!virtual_memory_->Commit(reinterpret_cast
(start_), kStoreBufferSize, diff --git a/src/heap/store-buffer.h b/src/heap/store-buffer.h index 9c6eac90b5..1b3fcb0a98 100644 --- a/src/heap/store-buffer.h +++ b/src/heap/store-buffer.h @@ -18,9 +18,8 @@ namespace internal { // code. On buffer overflow the slots are moved to the remembered set. class StoreBuffer { public: - static const int kStoreBufferOverflowBit = 1 << (14 + kPointerSizeLog2); - static const int kStoreBufferSize = kStoreBufferOverflowBit; - static const int kStoreBufferLength = kStoreBufferSize / sizeof(Address); + static const int kStoreBufferSize = 1 << (14 + kPointerSizeLog2); + static const int kStoreBufferMask = kStoreBufferSize - 1; static void StoreBufferOverflow(Isolate* isolate); diff --git a/src/ia32/macro-assembler-ia32.cc b/src/ia32/macro-assembler-ia32.cc index b1c16f2357..f9fd8d6a40 100644 --- a/src/ia32/macro-assembler-ia32.cc +++ b/src/ia32/macro-assembler-ia32.cc @@ -204,15 +204,15 @@ void MacroAssembler::RememberedSetHelper( mov(Operand::StaticVariable(store_buffer), scratch); // Call stub on end of buffer. // Check for end of buffer. - test(scratch, Immediate(StoreBuffer::kStoreBufferOverflowBit)); + test(scratch, Immediate(StoreBuffer::kStoreBufferMask)); if (and_then == kReturnAtEnd) { Label buffer_overflowed; - j(not_equal, &buffer_overflowed, Label::kNear); + j(equal, &buffer_overflowed, Label::kNear); ret(0); bind(&buffer_overflowed); } else { DCHECK(and_then == kFallThroughAtEnd); - j(equal, &done, Label::kNear); + j(not_equal, &done, Label::kNear); } StoreBufferOverflowStub store_buffer_overflow(isolate(), save_fp); CallStub(&store_buffer_overflow); diff --git a/src/mips/macro-assembler-mips.cc b/src/mips/macro-assembler-mips.cc index 2ddfa4aeec..5fdc0b64b7 100644 --- a/src/mips/macro-assembler-mips.cc +++ b/src/mips/macro-assembler-mips.cc @@ -482,12 +482,12 @@ void MacroAssembler::RememberedSetHelper(Register object, // For debug tests. sw(scratch, MemOperand(t8)); // Call stub on end of buffer. // Check for end of buffer. - And(t8, scratch, Operand(StoreBuffer::kStoreBufferOverflowBit)); + And(t8, scratch, Operand(StoreBuffer::kStoreBufferMask)); if (and_then == kFallThroughAtEnd) { - Branch(&done, eq, t8, Operand(zero_reg)); + Branch(&done, ne, t8, Operand(zero_reg)); } else { DCHECK(and_then == kReturnAtEnd); - Ret(eq, t8, Operand(zero_reg)); + Ret(ne, t8, Operand(zero_reg)); } push(ra); StoreBufferOverflowStub store_buffer_overflow(isolate(), fp_mode); diff --git a/src/mips64/macro-assembler-mips64.cc b/src/mips64/macro-assembler-mips64.cc index 9e49c47730..fb83fe9b76 100644 --- a/src/mips64/macro-assembler-mips64.cc +++ b/src/mips64/macro-assembler-mips64.cc @@ -485,13 +485,13 @@ void MacroAssembler::RememberedSetHelper(Register object, // For debug tests. sd(scratch, MemOperand(t8)); // Call stub on end of buffer. // Check for end of buffer. - And(t8, scratch, Operand(StoreBuffer::kStoreBufferOverflowBit)); + And(t8, scratch, Operand(StoreBuffer::kStoreBufferMask)); DCHECK(!scratch.is(t8)); if (and_then == kFallThroughAtEnd) { - Branch(&done, eq, t8, Operand(zero_reg)); + Branch(&done, ne, t8, Operand(zero_reg)); } else { DCHECK(and_then == kReturnAtEnd); - Ret(eq, t8, Operand(zero_reg)); + Ret(ne, t8, Operand(zero_reg)); } push(ra); StoreBufferOverflowStub store_buffer_overflow(isolate(), fp_mode); diff --git a/src/ppc/macro-assembler-ppc.cc b/src/ppc/macro-assembler-ppc.cc index 93a559895b..44cd948392 100644 --- a/src/ppc/macro-assembler-ppc.cc +++ b/src/ppc/macro-assembler-ppc.cc @@ -570,14 +570,14 @@ void MacroAssembler::RememberedSetHelper(Register object, // For debug tests. StoreP(scratch, MemOperand(ip)); // Call stub on end of buffer. // Check for end of buffer. - mov(r0, Operand(StoreBuffer::kStoreBufferOverflowBit)); + mov(r0, Operand(StoreBuffer::kStoreBufferMask)); and_(r0, scratch, r0, SetRC); if (and_then == kFallThroughAtEnd) { - beq(&done, cr0); + bne(&done, cr0); } else { DCHECK(and_then == kReturnAtEnd); - Ret(eq, cr0); + Ret(ne, cr0); } mflr(r0); push(r0); diff --git a/src/s390/macro-assembler-s390.cc b/src/s390/macro-assembler-s390.cc index c093935664..1884f54985 100644 --- a/src/s390/macro-assembler-s390.cc +++ b/src/s390/macro-assembler-s390.cc @@ -540,13 +540,13 @@ void MacroAssembler::RememberedSetHelper(Register object, // For debug tests. StoreP(scratch, MemOperand(ip)); // Call stub on end of buffer. // Check for end of buffer. - AndP(scratch, Operand(StoreBuffer::kStoreBufferOverflowBit)); + AndP(scratch, Operand(StoreBuffer::kStoreBufferMask)); if (and_then == kFallThroughAtEnd) { - beq(&done, Label::kNear); + bne(&done, Label::kNear); } else { DCHECK(and_then == kReturnAtEnd); - beq(&done, Label::kNear); + bne(&done, Label::kNear); } push(r14); StoreBufferOverflowStub store_buffer_overflow(isolate(), fp_mode); diff --git a/src/x64/macro-assembler-x64.cc b/src/x64/macro-assembler-x64.cc index b0a2603e31..566091df4e 100644 --- a/src/x64/macro-assembler-x64.cc +++ b/src/x64/macro-assembler-x64.cc @@ -227,15 +227,15 @@ void MacroAssembler::RememberedSetHelper(Register object, // For debug tests. // Call stub on end of buffer. Label done; // Check for end of buffer. - testp(scratch, Immediate(StoreBuffer::kStoreBufferOverflowBit)); + testp(scratch, Immediate(StoreBuffer::kStoreBufferMask)); if (and_then == kReturnAtEnd) { Label buffer_overflowed; - j(not_equal, &buffer_overflowed, Label::kNear); + j(equal, &buffer_overflowed, Label::kNear); ret(0); bind(&buffer_overflowed); } else { DCHECK(and_then == kFallThroughAtEnd); - j(equal, &done, Label::kNear); + j(not_equal, &done, Label::kNear); } StoreBufferOverflowStub store_buffer_overflow(isolate(), save_fp); CallStub(&store_buffer_overflow); diff --git a/src/x87/macro-assembler-x87.cc b/src/x87/macro-assembler-x87.cc index f8e43ac28a..b46167d1f9 100644 --- a/src/x87/macro-assembler-x87.cc +++ b/src/x87/macro-assembler-x87.cc @@ -196,15 +196,15 @@ void MacroAssembler::RememberedSetHelper( mov(Operand::StaticVariable(store_buffer), scratch); // Call stub on end of buffer. // Check for end of buffer. - test(scratch, Immediate(StoreBuffer::kStoreBufferOverflowBit)); + test(scratch, Immediate(StoreBuffer::kStoreBufferMask)); if (and_then == kReturnAtEnd) { Label buffer_overflowed; - j(not_equal, &buffer_overflowed, Label::kNear); + j(equal, &buffer_overflowed, Label::kNear); ret(0); bind(&buffer_overflowed); } else { DCHECK(and_then == kFallThroughAtEnd); - j(equal, &done, Label::kNear); + j(not_equal, &done, Label::kNear); } StoreBufferOverflowStub store_buffer_overflow(isolate(), save_fp); CallStub(&store_buffer_overflow);