summaryrefslogtreecommitdiffstats
path: root/runtime/utils.h
diff options
context:
space:
mode:
authorHiroshi Yamauchi <yamauchi@google.com>2013-11-05 11:34:03 -0800
committerHiroshi Yamauchi <yamauchi@google.com>2013-11-05 11:35:01 -0800
commit0941b0423537a6a5d7c1df6dd23e9864ea8f319c (patch)
tree096ced0f53465880a334d0150ef01e419db9a967 /runtime/utils.h
parent9780099e445884d8bc9444c8c1261b02d80a26c7 (diff)
downloadandroid_art-0941b0423537a6a5d7c1df6dd23e9864ea8f319c.tar.gz
android_art-0941b0423537a6a5d7c1df6dd23e9864ea8f319c.tar.bz2
android_art-0941b0423537a6a5d7c1df6dd23e9864ea8f319c.zip
Fix a DCHECK failure due to unmatching numbers of cards scanned.
- See the bug for details of the failure. - After a discussion, we decided to get rid of the DCHECK as a simple solution would not detect corner failure cases and a full solution would add undesired complexity, and left a comment that explains what situation had caused a DCHECK failure. - Fix a potential error of failing to scan the last card that the end of the image space falls on as a result of the image end being not necessarily aligned by the card size. - Remove dead/unused MarkSweep::ScanRoot(). - Add AlignUp and AlignDown for aligning pointers. Bug: 11465268 Change-Id: Iee3018a42c48a159feb0e9cf77b1a6b303f5d245
Diffstat (limited to 'runtime/utils.h')
-rw-r--r--runtime/utils.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/runtime/utils.h b/runtime/utils.h
index 0174b37dcc..51035b697f 100644
--- a/runtime/utils.h
+++ b/runtime/utils.h
@@ -119,6 +119,7 @@ struct TypeStaticIf<false, A, B> {
typedef B value;
};
+// For rounding integers.
template<typename T>
static inline T RoundDown(T x, int n) {
CHECK(IsPowerOfTwo(n));
@@ -130,6 +131,18 @@ static inline T RoundUp(T x, int n) {
return RoundDown(x + n - 1, n);
}
+// For aligning pointers.
+template<typename T>
+static inline T* AlignDown(T* x, int n) {
+ CHECK(IsPowerOfTwo(n));
+ return reinterpret_cast<T*>(reinterpret_cast<uintptr_t>(x) & -static_cast<uintptr_t>(n));
+}
+
+template<typename T>
+static inline T* AlignUp(T* x, int n) {
+ return AlignDown(reinterpret_cast<T*>(reinterpret_cast<uintptr_t>(x) + static_cast<uintptr_t>(n - 1)), n);
+}
+
// Implementation is from "Hacker's Delight" by Henry S. Warren, Jr.,
// figure 3-3, page 48, where the function is called clp2.
static inline uint32_t RoundUpToPowerOfTwo(uint32_t x) {