Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(687)

Side by Side Diff: src/heap/heap.cc

Issue 1150593003: Clean up aligned allocation code in preparation for SIMD alignments. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Only check for unaligned double case. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api.h" 8 #include "src/api.h"
9 #include "src/base/bits.h" 9 #include "src/base/bits.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
(...skipping 1964 matching lines...) Expand 10 before | Expand all | Expand 10 after
1975 STATIC_ASSERT((ConstantPoolArray::kExtendedFirstOffset & 1975 STATIC_ASSERT((ConstantPoolArray::kExtendedFirstOffset &
1976 kDoubleAlignmentMask) == 0); // NOLINT 1976 kDoubleAlignmentMask) == 0); // NOLINT
1977 STATIC_ASSERT((FixedTypedArrayBase::kDataOffset & kDoubleAlignmentMask) == 1977 STATIC_ASSERT((FixedTypedArrayBase::kDataOffset & kDoubleAlignmentMask) ==
1978 0); // NOLINT 1978 0); // NOLINT
1979 #ifdef V8_HOST_ARCH_32_BIT 1979 #ifdef V8_HOST_ARCH_32_BIT
1980 STATIC_ASSERT((HeapNumber::kValueOffset & kDoubleAlignmentMask) != 1980 STATIC_ASSERT((HeapNumber::kValueOffset & kDoubleAlignmentMask) !=
1981 0); // NOLINT 1981 0); // NOLINT
1982 #endif 1982 #endif
1983 1983
1984 1984
1985 HeapObject* Heap::EnsureAligned(HeapObject* object, int size, 1985 int Heap::GetMaximumFillToAlign(AllocationAlignment alignment) {
1986 AllocationAlignment alignment) { 1986 switch (alignment) {
1987 if (alignment == kDoubleAligned && 1987 case kWordAligned:
1988 (OffsetFrom(object->address()) & kDoubleAlignmentMask) != 0) { 1988 return 0;
1989 CreateFillerObjectAt(object->address(), kPointerSize); 1989 case kDoubleAligned:
1990 return HeapObject::FromAddress(object->address() + kPointerSize); 1990 case kDoubleUnaligned:
1991 } else if (alignment == kDoubleUnaligned && 1991 return kDoubleSize - kPointerSize;
1992 (OffsetFrom(object->address()) & kDoubleAlignmentMask) == 0) { 1992 default:
1993 CreateFillerObjectAt(object->address(), kPointerSize); 1993 UNREACHABLE();
1994 return HeapObject::FromAddress(object->address() + kPointerSize);
1995 } else {
1996 CreateFillerObjectAt(object->address() + size - kPointerSize, kPointerSize);
1997 return object;
1998 } 1994 }
1995 return 0;
1999 } 1996 }
2000 1997
2001 1998
2002 HeapObject* Heap::PrecedeWithFiller(HeapObject* object) { 1999 int Heap::GetFillToAlign(Address address, AllocationAlignment alignment) {
2003 CreateFillerObjectAt(object->address(), kPointerSize); 2000 intptr_t offset = OffsetFrom(address);
2004 return HeapObject::FromAddress(object->address() + kPointerSize); 2001 if (alignment == kDoubleAligned && (offset & kDoubleAlignmentMask) != 0)
2002 return kPointerSize;
2003 if (alignment == kDoubleUnaligned && (offset & kDoubleAlignmentMask) == 0)
2004 return kDoubleSize - kPointerSize; // No fill if double is always aligned.
2005 return 0;
2006 }
2007
2008
2009 HeapObject* Heap::PrecedeWithFiller(HeapObject* object, int filler_size) {
2010 CreateFillerObjectAt(object->address(), filler_size);
2011 return HeapObject::FromAddress(object->address() + filler_size);
2012 }
2013
2014
2015 HeapObject* Heap::AlignWithFiller(HeapObject* object, int object_size,
2016 int allocation_size,
2017 AllocationAlignment alignment) {
2018 int filler_size = allocation_size - object_size;
2019 DCHECK(filler_size > 0);
2020 int pre_filler = GetFillToAlign(object->address(), alignment);
2021 if (pre_filler) {
2022 object = PrecedeWithFiller(object, pre_filler);
2023 filler_size -= pre_filler;
2024 }
2025 if (filler_size)
2026 CreateFillerObjectAt(object->address() + object_size, filler_size);
2027 return object;
2005 } 2028 }
2006 2029
2007 2030
2008 HeapObject* Heap::DoubleAlignForDeserialization(HeapObject* object, int size) { 2031 HeapObject* Heap::DoubleAlignForDeserialization(HeapObject* object, int size) {
2009 return EnsureAligned(object, size, kDoubleAligned); 2032 return AlignWithFiller(object, size, size + kPointerSize, kDoubleAligned);
2010 } 2033 }
2011 2034
2012 2035
2013 enum LoggingAndProfiling { 2036 enum LoggingAndProfiling {
2014 LOGGING_AND_PROFILING_ENABLED, 2037 LOGGING_AND_PROFILING_ENABLED,
2015 LOGGING_AND_PROFILING_DISABLED 2038 LOGGING_AND_PROFILING_DISABLED
2016 }; 2039 };
2017 2040
2018 2041
2019 enum MarksHandling { TRANSFER_MARKS, IGNORE_MARKS }; 2042 enum MarksHandling { TRANSFER_MARKS, IGNORE_MARKS };
(...skipping 4570 matching lines...) Expand 10 before | Expand all | Expand 10 after
6590 *object_type = "CODE_TYPE"; \ 6613 *object_type = "CODE_TYPE"; \
6591 *object_sub_type = "CODE_AGE/" #name; \ 6614 *object_sub_type = "CODE_AGE/" #name; \
6592 return true; 6615 return true;
6593 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME) 6616 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME)
6594 #undef COMPARE_AND_RETURN_NAME 6617 #undef COMPARE_AND_RETURN_NAME
6595 } 6618 }
6596 return false; 6619 return false;
6597 } 6620 }
6598 } 6621 }
6599 } // namespace v8::internal 6622 } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698